Skip to content

Commit 9b46146

Browse files
committed
Remove silencing logic for unknown prefix
This logic is tricky to get right. At some point, revisit using the stash mechanism.
1 parent 3d499ce commit 9b46146

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
701701
let expn_data = prefix_span.ctxt().outer_expn_data();
702702

703703
if expn_data.edition >= Edition::Edition2021 {
704-
let mut silence = false;
705704
// In Rust 2021, this is a hard error.
706705
let sugg = if prefix == "rb" {
707706
Some(errors::UnknownPrefixSugg::UseBr(prefix_span))
@@ -710,8 +709,9 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
710709
&& let Some(start) = self.last_lifetime
711710
&& self.cursor.third() != '\''
712711
{
713-
// An "unclosed `char`" error will be emitted already, silence redundant error.
714-
silence = true;
712+
// FIXME: An "unclosed `char`" error will be emitted already in some cases,
713+
// but it's hard to silence this error while not also silencing important cases
714+
// too. We should use the error stashing machinery instead.
715715
Some(errors::UnknownPrefixSugg::MeantStr {
716716
start,
717717
end: self.mk_sp(self.pos, self.pos + BytePos(1)),
@@ -722,12 +722,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
722722
} else {
723723
None
724724
};
725-
let err = errors::UnknownPrefix { span: prefix_span, prefix, sugg };
726-
if silence {
727-
self.dcx().create_err(err).delay_as_bug();
728-
} else {
729-
self.dcx().emit_err(err);
730-
}
725+
self.dcx().emit_err(errors::UnknownPrefix { span: prefix_span, prefix, sugg });
731726
} else {
732727
// Before Rust 2021, only emit a lint for migration.
733728
self.psess.buffer_lint_with_diagnostic(

tests/ui/lexer/lex-bad-str-literal-as-char-3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
fn main() {
55
println!('hello world');
66
//~^ ERROR unterminated character literal
7+
//[rust2021]~| ERROR prefix `world` is unknown
78
}

tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2021.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error: prefix `world` is unknown
2+
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:21
3+
|
4+
LL | println!('hello world');
5+
| ^^^^^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: if you meant to write a string literal, use double quotes
9+
|
10+
LL | println!("hello world");
11+
| ~ ~
12+
113
error[E0762]: unterminated character literal
214
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
315
|
@@ -9,6 +21,6 @@ help: if you meant to write a string literal, use double quotes
921
LL | println!("hello world");
1022
| ~ ~
1123

12-
error: aborting due to 1 previous error
24+
error: aborting due to 2 previous errors
1325

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

tests/ui/lexer/lex-bad-str-literal-as-char-4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ macro_rules! foo {
33
() => {
44
println!('hello world');
55
//~^ ERROR unterminated character literal
6+
//~| ERROR prefix `world` is unknown
67
}
78
}
89
fn main() {}

tests/ui/lexer/lex-bad-str-literal-as-char-4.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error: prefix `world` is unknown
2+
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:25
3+
|
4+
LL | println!('hello world');
5+
| ^^^^^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: if you meant to write a string literal, use double quotes
9+
|
10+
LL | println!("hello world");
11+
| ~ ~
12+
113
error[E0762]: unterminated character literal
214
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:30
315
|
@@ -9,6 +21,6 @@ help: if you meant to write a string literal, use double quotes
921
LL | println!("hello world");
1022
| ~ ~
1123

12-
error: aborting due to 1 previous error
24+
error: aborting due to 2 previous errors
1325

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

0 commit comments

Comments
 (0)