about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-07-31 15:37:36 +0200
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-07-31 15:37:36 +0200
commitf2c9654dcd53184eb5b585f117e856b87f9404c1 (patch)
tree0cf03ea6d0046c616f00f0f86fe30bcf0c30bb5a /compiler/rustc_parse/src
parentfc24bcead1d401ae061538d011e4a319c4195b56 (diff)
downloadrust-f2c9654dcd53184eb5b585f117e856b87f9404c1.tar.gz
rust-f2c9654dcd53184eb5b585f117e856b87f9404c1.zip
Suggest `br` if the unknown string prefix `rb` is found
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index 98befe4066b..1e65cc27154 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -505,7 +505,8 @@ impl<'a> StringReader<'a> {
     // identifier tokens.
     fn report_unknown_prefix(&self, start: BytePos) {
         let prefix_span = self.mk_sp(start, self.pos);
-        let msg = format!("prefix `{}` is unknown", self.str_from_to(start, self.pos));
+        let prefix_str = self.str_from_to(start, self.pos);
+        let msg = format!("prefix `{}` is unknown", prefix_str);
 
         let expn_data = prefix_span.ctxt().outer_expn_data();
 
@@ -513,12 +514,19 @@ impl<'a> StringReader<'a> {
             // In Rust 2021, this is a hard error.
             let mut err = self.sess.span_diagnostic.struct_span_err(prefix_span, &msg);
             err.span_label(prefix_span, "unknown prefix");
-            if expn_data.is_root() {
+            if prefix_str == "rb" {
+                err.span_suggestion_verbose(
+                    prefix_span,
+                    "use `br` for a raw byte string",
+                    "br".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
+            } else if expn_data.is_root() {
                 err.span_suggestion_verbose(
                     prefix_span.shrink_to_hi(),
                     "consider inserting whitespace here",
                     " ".into(),
-                    Applicability::MachineApplicable,
+                    Applicability::MaybeIncorrect,
                 );
             }
             err.note("prefixed identifiers and literals are reserved since Rust 2021");