diff options
| author | Russell Cohen <russell.r.cohen@gmail.com> | 2020-03-29 11:12:48 -0400 |
|---|---|---|
| committer | Russell Cohen <russell.r.cohen@gmail.com> | 2020-03-29 11:12:48 -0400 |
| commit | c15f86b4b35a260b105dc472fc6e3556af8a8db0 (patch) | |
| tree | e443a3ca5dcb215a8ff27887c5cb19da2b83201d /src/librustc_parse | |
| parent | 629e97a5a02edb3d8dc63c5157962c093217d441 (diff) | |
Cleanup error messages, improve docstrings
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/lexer/mod.rs | 9 | ||||
| -rw-r--r-- | src/librustc_parse/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_parse/parser/diagnostics.rs | 11 |
3 files changed, 12 insertions, 9 deletions
diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 2f720d95c6d..a367131b3f3 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -533,13 +533,12 @@ impl<'a> StringReader<'a> { } if let Some(possible_offset) = possible_offset { - let span = self.mk_sp( - start + BytePos(possible_offset as u32), - start + BytePos(possible_offset as u32) + BytePos(found_terminators as u32), - ); + let lo = start + BytePos(possible_offset as u32); + let hi = lo + BytePos(found_terminators as u32); + let span = self.mk_sp(lo, hi); err.span_suggestion( span, - "you might have intended to terminate the string here", + "consider terminating the string here", "#".repeat(n_hashes), Applicability::MaybeIncorrect, ); diff --git a/src/librustc_parse/lib.rs b/src/librustc_parse/lib.rs index 13fb85db847..8e2a9513d6b 100644 --- a/src/librustc_parse/lib.rs +++ b/src/librustc_parse/lib.rs @@ -4,6 +4,7 @@ #![feature(crate_visibility_modifier)] #![feature(bindings_after_at)] #![feature(try_blocks)] +#![feature(or_patterns)] use rustc_ast::ast; use rustc_ast::token::{self, Nonterminal}; diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index 7b6840307cb..2fc20e15c5a 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -288,9 +288,12 @@ impl<'a> Parser<'a> { fn check_too_many_raw_str_terminators(&mut self, err: &mut DiagnosticBuilder<'_>) -> bool { let prev_token_raw_str = match self.prev_token { - Token { kind: TokenKind::Literal(Lit { kind: LitKind::StrRaw(n), .. }), .. } => Some(n), Token { - kind: TokenKind::Literal(Lit { kind: LitKind::ByteStrRaw(n), .. }), .. + kind: + TokenKind::Literal(Lit { + kind: LitKind::StrRaw(n) | LitKind::ByteStrRaw(n), .. + }), + .. } => Some(n), _ => None, }; @@ -300,11 +303,11 @@ impl<'a> Parser<'a> { err.set_primary_message("too many `#` when terminating raw string"); err.span_suggestion( self.token.span, - "Remove the extra `#`", + "remove the extra `#`", String::new(), Applicability::MachineApplicable, ); - err.note(&format!("The raw string started with {} `#`s", n_hashes)); + err.note(&format!("the raw string started with {} `#`s", n_hashes)); return true; } } |
