Skip to content

Commit

Permalink
Remove silencing logic for unknown prefix
Browse files Browse the repository at this point in the history
This logic is tricky to get right. At some point, revisit using the stash mechanism.
  • Loading branch information
estebank committed Mar 30, 2024
1 parent 3d499ce commit 9b46146
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
13 changes: 4 additions & 9 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
let expn_data = prefix_span.ctxt().outer_expn_data();

if expn_data.edition >= Edition::Edition2021 {
let mut silence = false;
// In Rust 2021, this is a hard error.
let sugg = if prefix == "rb" {
Some(errors::UnknownPrefixSugg::UseBr(prefix_span))
Expand All @@ -710,8 +709,9 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
&& let Some(start) = self.last_lifetime
&& self.cursor.third() != '\''
{
// An "unclosed `char`" error will be emitted already, silence redundant error.
silence = true;
// FIXME: An "unclosed `char`" error will be emitted already in some cases,
// but it's hard to silence this error while not also silencing important cases
// too. We should use the error stashing machinery instead.
Some(errors::UnknownPrefixSugg::MeantStr {
start,
end: self.mk_sp(self.pos, self.pos + BytePos(1)),
Expand All @@ -722,12 +722,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
} else {
None
};
let err = errors::UnknownPrefix { span: prefix_span, prefix, sugg };
if silence {
self.dcx().create_err(err).delay_as_bug();
} else {
self.dcx().emit_err(err);
}
self.dcx().emit_err(errors::UnknownPrefix { span: prefix_span, prefix, sugg });
} else {
// Before Rust 2021, only emit a lint for migration.
self.psess.buffer_lint_with_diagnostic(
Expand Down
1 change: 1 addition & 0 deletions tests/ui/lexer/lex-bad-str-literal-as-char-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
fn main() {
println!('hello world');
//~^ ERROR unterminated character literal
//[rust2021]~| ERROR prefix `world` is unknown
}
14 changes: 13 additions & 1 deletion tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2021.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
error: prefix `world` is unknown
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:21
|
LL | println!('hello world');
| ^^^^^ unknown prefix
|
= note: prefixed identifiers and literals are reserved since Rust 2021
help: if you meant to write a string literal, use double quotes
|
LL | println!("hello world");
| ~ ~

error[E0762]: unterminated character literal
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
|
Expand All @@ -9,6 +21,6 @@ help: if you meant to write a string literal, use double quotes
LL | println!("hello world");
| ~ ~

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0762`.
1 change: 1 addition & 0 deletions tests/ui/lexer/lex-bad-str-literal-as-char-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ macro_rules! foo {
() => {
println!('hello world');
//~^ ERROR unterminated character literal
//~| ERROR prefix `world` is unknown
}
}
fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/lexer/lex-bad-str-literal-as-char-4.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
error: prefix `world` is unknown
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:25
|
LL | println!('hello world');
| ^^^^^ unknown prefix
|
= note: prefixed identifiers and literals are reserved since Rust 2021
help: if you meant to write a string literal, use double quotes
|
LL | println!("hello world");
| ~ ~

error[E0762]: unterminated character literal
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:30
|
Expand All @@ -9,6 +21,6 @@ help: if you meant to write a string literal, use double quotes
LL | println!("hello world");
| ~ ~

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0762`.

0 comments on commit 9b46146

Please sign in to comment.