diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-01-27 21:04:50 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-02-07 01:41:30 -0800 |
| commit | 7451cd8dc0b20c012fad1886b321c3dee2052577 (patch) | |
| tree | 564bb3390199f080413ec319481f3f37fa345054 /src/libsyntax/parse/token.rs | |
| parent | 825f355c7483746f3a17166f34dfabe3b2df1741 (diff) | |
| download | rust-7451cd8dc0b20c012fad1886b321c3dee2052577.tar.gz rust-7451cd8dc0b20c012fad1886b321c3dee2052577.zip | |
Deduplicate mismatched delimiter errors
Delay unmatched delimiter errors until after the parser has run to deduplicate them when parsing and attempt recovering intelligently.
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 3b1fa5ea01f..a0f3113a1cb 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -487,8 +487,8 @@ impl Token { /// Enables better error recovery when the wrong token is found. crate fn similar_tokens(&self) -> Option<Vec<Token>> { match *self { - Comma => Some(vec![Dot, Lt]), - Semi => Some(vec![Colon]), + Comma => Some(vec![Dot, Lt, Semi]), + Semi => Some(vec![Colon, Comma]), _ => None } } @@ -545,7 +545,15 @@ impl Token { // FIXME(#43081): Avoid this pretty-print + reparse hack let source = pprust::token_to_string(self); let filename = FileName::macro_expansion_source_code(&source); - parse_stream_from_source_str(filename, source, sess, Some(span)) + let (tokens, errors) = parse_stream_from_source_str( + filename, source, sess, Some(span)); + for err in errors { + sess.span_diagnostic.struct_span_err( + err.found_span, + "unclosed delimiter for_real", + ).emit(); + } + tokens }); // During early phases of the compiler the AST could get modified @@ -786,12 +794,18 @@ fn prepend_attrs(sess: &ParseSess, let source = pprust::attr_to_string(attr); let macro_filename = FileName::macro_expansion_source_code(&source); if attr.is_sugared_doc { - let stream = parse_stream_from_source_str( + let (stream, errors) = parse_stream_from_source_str( macro_filename, source, sess, Some(span), ); + for err in errors { + sess.span_diagnostic.struct_span_err( + err.found_span, + "unclosed delimiter attrs", + ).emit(); + } builder.push(stream); continue } @@ -808,12 +822,18 @@ fn prepend_attrs(sess: &ParseSess, // ... and for more complicated paths, fall back to a reparse hack that // should eventually be removed. } else { - let stream = parse_stream_from_source_str( + let (stream, errors) = parse_stream_from_source_str( macro_filename, source, sess, Some(span), ); + for err in errors { + sess.span_diagnostic.struct_span_err( + err.found_span, + "unclosed delimiter attrs 2", + ).emit(); + } brackets.push(stream); } |
