diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-11-28 12:06:04 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-28 12:06:04 +0100 | 
| commit | ca71c8fe5e12704bd2f58081375a9c9d27bd8399 (patch) | |
| tree | 3763c6b8753b5993fc8a90235c89a9a3387c1090 /compiler/rustc_parse/src/lexer/mod.rs | |
| parent | 23bab15d732ea34af6537f08f24c7be319ec1161 (diff) | |
| parent | 44f4f67f460a3b3c9bb34851d3d812fbdba81936 (diff) | |
| download | rust-ca71c8fe5e12704bd2f58081375a9c9d27bd8399.tar.gz rust-ca71c8fe5e12704bd2f58081375a9c9d27bd8399.zip  | |
Rollup merge of #133487 - pitaj:reserve-guarded-strings, r=fee1-dead
fix confusing diagnostic for reserved `##` Closes #131615
Diffstat (limited to 'compiler/rustc_parse/src/lexer/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/lexer/mod.rs | 16 | 
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 8db3b174a89..8a42cf388f9 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -816,7 +816,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { let mut cursor = Cursor::new(str_before); - let (span, unterminated) = match cursor.guarded_double_quoted_string() { + let (is_string, span, unterminated) = match cursor.guarded_double_quoted_string() { Some(rustc_lexer::GuardedStr { n_hashes, terminated, token_len }) => { let end = start + BytePos(token_len); let span = self.mk_sp(start, end); @@ -829,13 +829,13 @@ impl<'psess, 'src> Lexer<'psess, 'src> { let unterminated = if terminated { None } else { Some(str_start) }; - (span, unterminated) + (true, span, unterminated) } - _ => { + None => { // We should only get here in the `##+` case. debug_assert_eq!(self.str_from_to(start, start + BytePos(2)), "##"); - (span, None) + (false, span, None) } }; if edition2024 { @@ -857,7 +857,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> { }; // In Edition 2024 and later, emit a hard error. - let err = self.dcx().emit_err(errors::ReservedString { span, sugg }); + let err = if is_string { + self.dcx().emit_err(errors::ReservedString { span, sugg }) + } else { + self.dcx().emit_err(errors::ReservedMultihash { span, sugg }) + }; token::Literal(token::Lit { kind: token::Err(err), @@ -870,7 +874,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX, span, ast::CRATE_NODE_ID, - BuiltinLintDiag::ReservedString(space_span), + BuiltinLintDiag::ReservedString { is_string, suggestion: space_span }, ); // For backwards compatibility, roll back to after just the first `#`  | 
