-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Exit when there are unmatched delims to avoid noisy diagnostics #108297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f01d0c0
65ad5f8
9ce7472
88de2e1
f808877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ pub const MACRO_ARGUMENTS: Option<&str> = Some("macro arguments"); | |
|
||
#[macro_use] | ||
pub mod parser; | ||
use parser::{emit_unclosed_delims, make_unclosed_delims_error, Parser}; | ||
use parser::{make_unclosed_delims_error, Parser}; | ||
pub mod lexer; | ||
pub mod validate_attr; | ||
|
||
|
@@ -96,10 +96,7 @@ pub fn parse_stream_from_source_str( | |
sess: &ParseSess, | ||
override_span: Option<Span>, | ||
) -> TokenStream { | ||
let (stream, mut errors) = | ||
source_file_to_stream(sess, sess.source_map().new_source_file(name, source), override_span); | ||
emit_unclosed_delims(&mut errors, &sess); | ||
stream | ||
source_file_to_stream(sess, sess.source_map().new_source_file(name, source), override_span) | ||
} | ||
|
||
/// Creates a new parser from a source string. | ||
|
@@ -135,9 +132,8 @@ fn maybe_source_file_to_parser( | |
source_file: Lrc<SourceFile>, | ||
) -> Result<Parser<'_>, Vec<Diagnostic>> { | ||
let end_pos = source_file.end_pos; | ||
let (stream, unclosed_delims) = maybe_file_to_stream(sess, source_file, None)?; | ||
let stream = maybe_file_to_stream(sess, source_file, None)?; | ||
let mut parser = stream_to_parser(sess, stream, None); | ||
parser.unclosed_delims = unclosed_delims; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but this field is used in parser itself, I found that we could have more cleanup on |
||
if parser.token == token::Eof { | ||
parser.token.span = Span::new(end_pos, end_pos, parser.token.span.ctxt(), None); | ||
} | ||
|
@@ -182,7 +178,7 @@ pub fn source_file_to_stream( | |
sess: &ParseSess, | ||
source_file: Lrc<SourceFile>, | ||
override_span: Option<Span>, | ||
) -> (TokenStream, Vec<lexer::UnmatchedBrace>) { | ||
) -> TokenStream { | ||
panictry_buffer!(&sess.span_diagnostic, maybe_file_to_stream(sess, source_file, override_span)) | ||
} | ||
|
||
|
@@ -192,31 +188,15 @@ pub fn maybe_file_to_stream( | |
sess: &ParseSess, | ||
source_file: Lrc<SourceFile>, | ||
override_span: Option<Span>, | ||
) -> Result<(TokenStream, Vec<lexer::UnmatchedBrace>), Vec<Diagnostic>> { | ||
) -> Result<TokenStream, Vec<Diagnostic>> { | ||
let src = source_file.src.as_ref().unwrap_or_else(|| { | ||
sess.span_diagnostic.bug(&format!( | ||
"cannot lex `source_file` without source: {}", | ||
sess.source_map().filename_for_diagnostics(&source_file.name) | ||
)); | ||
}); | ||
|
||
let (token_trees, unmatched_braces) = | ||
lexer::parse_token_trees(sess, src.as_str(), source_file.start_pos, override_span); | ||
|
||
match token_trees { | ||
Ok(stream) => Ok((stream, unmatched_braces)), | ||
Err(err) => { | ||
let mut buffer = Vec::with_capacity(1); | ||
err.buffer(&mut buffer); | ||
// Not using `emit_unclosed_delims` to use `db.buffer` | ||
for unmatched in unmatched_braces { | ||
if let Some(err) = make_unclosed_delims_error(unmatched, &sess) { | ||
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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// error-pattern: this file contains an unclosed delimiter | ||
// error-pattern: this file contains an unclosed delimiter | ||
// error-pattern: this file contains an unclosed delimiter | ||
// error-pattern: format argument must be a string literal | ||
|
||
fn f(){(print!(á |
Uh oh!
There was an error while loading. Please reload this page.