Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dc97326
Update docs to show [expr; N] can repeat const expr
Coca162 Feb 27, 2023
22b65fc
Clarify that Copy is a trait in array docs
Coca162 Feb 27, 2023
48af38f
Bump rust-installer
Mark-Simulacrum Feb 27, 2023
8732fcd
Update books
rustbot Feb 27, 2023
f83ce99
Remove the `capture_disjoint_fields` feature
clubby789 Feb 28, 2023
ecac8fd
Descriptive error when users try to combine RPITIT/AFIT with speciali…
compiler-errors Feb 28, 2023
f851a8a
Only look for param in generics if it actually comes from generics
compiler-errors Feb 28, 2023
10b08e3
Fix a race in the query system
Zoxc Feb 8, 2023
f01d0c0
Exit when there are unmatched delims to avoid noisy diagnostics
chenyukang Feb 28, 2023
65ad5f8
remove duplicated diagnostic for unclosed delimiter
chenyukang Feb 28, 2023
9ce7472
rename unmatched_braces to unmatched_delims
chenyukang Feb 21, 2023
88de2e1
no need to return unmatched_delims from tokentrees
chenyukang Feb 22, 2023
f808877
refactor parse_token_trees to not return unmatched_delims
chenyukang Feb 22, 2023
229aef1
add missing feature in core/tests
RalfJung Feb 28, 2023
d33bbfd
Rollup merge of #108297 - chenyukang:yukang/delim-error-exit, r=petro…
matthiaskrgr Feb 28, 2023
62e6286
Rollup merge of #108531 - Coca162:rustdoc-repeat-const-array, r=thomcc
matthiaskrgr Feb 28, 2023
68b86f7
Rollup merge of #108534 - Mark-Simulacrum:compression, r=pietroalbini
matthiaskrgr Feb 28, 2023
70357cb
Rollup merge of #108536 - rustbot:docs-update, r=ehuss
matthiaskrgr Feb 28, 2023
5ed4614
Rollup merge of #108550 - clubby789:remove-disjoint, r=compiler-errors
matthiaskrgr Feb 28, 2023
a91bda5
Rollup merge of #108551 - compiler-errors:rpitit-bad-spec, r=oli-obk
matthiaskrgr Feb 28, 2023
38aa943
Rollup merge of #108554 - compiler-errors:late-bound-object-default, …
matthiaskrgr Feb 28, 2023
0beb3a1
Rollup merge of #108555 - Zoxc:par-fix, r=cjgillot
matthiaskrgr Feb 28, 2023
415258f
Rollup merge of #108558 - RalfJung:core-tests, r=thomcc
matthiaskrgr Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor parse_token_trees to not return unmatched_delims
  • Loading branch information
chenyukang committed Feb 28, 2023
commit f808877bbf8643cb9ea54a59cb5a61a631f545dd
29 changes: 26 additions & 3 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::errors;
use crate::lexer::unicode_chars::UNICODE_ARRAY;
use crate::make_unclosed_delims_error;
use rustc_ast::ast::{self, AttrStyle};
use rustc_ast::token::{self, CommentKind, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::unicode::contains_text_flow_control_chars;
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, PResult, StashKey};
use rustc_errors::{error_code, Applicability, Diagnostic, DiagnosticBuilder, StashKey};
use rustc_lexer::unescape::{self, Mode};
use rustc_lexer::Cursor;
use rustc_lexer::{Base, DocStyle, RawStrError};
Expand Down Expand Up @@ -44,7 +45,7 @@ pub(crate) fn parse_token_trees<'a>(
mut src: &'a str,
mut start_pos: BytePos,
override_span: Option<Span>,
) -> (PResult<'a, TokenStream>, Vec<UnmatchedDelim>) {
) -> Result<TokenStream, Vec<Diagnostic>> {
// Skip `#!`, if present.
if let Some(shebang_len) = rustc_lexer::strip_shebang(src) {
src = &src[shebang_len..];
Expand All @@ -61,7 +62,29 @@ pub(crate) fn parse_token_trees<'a>(
override_span,
nbsp_is_whitespace: false,
};
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader)
let (token_trees, unmatched_delims) =
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
match token_trees {
Ok(stream) if unmatched_delims.is_empty() => Ok(stream),
_ => {
// Return error if there are unmatched delimiters or unclosng delimiters.
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
// because the delimiter mismatch is more likely to be the root cause of error

let mut buffer = Vec::with_capacity(1);
// Not using `emit_unclosed_delims` to use `db.buffer`
for unmatched in unmatched_delims {
if let Some(err) = make_unclosed_delims_error(unmatched, &sess) {
err.buffer(&mut buffer);
}
}
if let Err(err) = token_trees {
// Add unclosing delimiter error
err.buffer(&mut buffer);
}
Err(buffer)
}
}
}

struct StringReader<'a> {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ impl<'a> TokenTreesReader<'a> {
}
}
let (tok, _) = self.diag_info.open_braces.pop().unwrap();
debug!("anan now: open {:#?} close {:#?}", open_delim, close_delim);
self.diag_info.unmatched_delims.push(UnmatchedDelim {
expected_delim: tok,
found_delim: Some(close_delim),
Expand Down
25 changes: 1 addition & 24 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,7 @@ pub fn maybe_file_to_stream(
));
});

let (token_trees, unmatched_delims) =
lexer::parse_token_trees(sess, src.as_str(), source_file.start_pos, override_span);

match token_trees {
Ok(stream) if unmatched_delims.is_empty() => Ok(stream),
_ => {
// Return error if there are unmatched delimiters or unclosng delimiters.
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
// because the delimiter mismatch is more likely to be the root cause of the

let mut buffer = Vec::with_capacity(1);
// Not using `emit_unclosed_delims` to use `db.buffer`
for unmatched in unmatched_delims {
if let Some(err) = make_unclosed_delims_error(unmatched, &sess) {
err.buffer(&mut buffer);
}
}
if let Err(err) = token_trees {
// Add unclosing delimiter error
err.buffer(&mut buffer);
}
Err(buffer)
}
}
lexer::parse_token_trees(sess, src.as_str(), source_file.start_pos, override_span)
}

/// Given a stream and the `ParseSess`, produces a parser.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use crate::errors::{
};

use crate::fluent_generated as fluent;
use rustc_ast as ast;
use crate::parser;
use crate::lexer::UnmatchedDelim;
use crate::parser;
use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Lit, LitKind, TokenKind};
use rustc_ast::util::parser::AssocOp;
Expand Down