]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_parse/src/lexer/mod.rs
Auto merge of #104522 - RalfJung:try_normalize_after_erasing_regions, r=oli-obk
[rust.git] / compiler / rustc_parse / src / lexer / mod.rs
index 645262bd2f1d37dcf5d714b618457e94e3a3f81b..f027843e6b43d469ab5483494543ee9d89b42d98 100644 (file)
@@ -661,6 +661,7 @@ fn cook_quoted(
         prefix_len: u32,
         postfix_len: u32,
     ) -> (token::LitKind, Symbol) {
+        let mut has_fatal_err = false;
         let content_start = start + BytePos(prefix_len);
         let content_end = end - BytePos(postfix_len);
         let lit_content = self.str_from_to(content_start, content_end);
@@ -672,6 +673,9 @@ fn cook_quoted(
                 let lo = content_start + BytePos(start);
                 let hi = lo + BytePos(end - start);
                 let span = self.mk_sp(lo, hi);
+                if err.is_fatal() {
+                    has_fatal_err = true;
+                }
                 emit_unescape_error(
                     &self.sess.span_diagnostic,
                     lit_content,
@@ -683,7 +687,14 @@ fn cook_quoted(
                 );
             }
         });
-        (kind, Symbol::intern(lit_content))
+
+        // We normally exclude the quotes for the symbol, but for errors we
+        // include it because it results in clearer error messages.
+        if !has_fatal_err {
+            (kind, Symbol::intern(lit_content))
+        } else {
+            (token::Err, self.symbol_from_to(start, end))
+        }
     }
 }