Skip to content

Commit 5805f0a

Browse files
committed
don't print invalid labels with r#
1 parent a6bd272 commit 5805f0a

File tree

11 files changed

+22
-16
lines changed

11 files changed

+22
-16
lines changed

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ pub(crate) struct KeywordLifetime {
21912191
pub(crate) struct InvalidLabel {
21922192
#[primary_span]
21932193
pub span: Span,
2194-
pub name: Symbol,
2194+
pub name: String,
21952195
}
21962196

21972197
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,13 @@ impl<'a> Parser<'a> {
30833083
if let Some((ident, is_raw)) = self.token.lifetime() {
30843084
// Disallow `'fn`, but with a better error message than `expect_lifetime`.
30853085
if matches!(is_raw, IdentIsRaw::No) && ident.without_first_quote().is_reserved() {
3086-
self.dcx().emit_err(errors::InvalidLabel { span: ident.span, name: ident.name });
3086+
self.dcx().emit_err(errors::InvalidLabel {
3087+
span: ident.span,
3088+
// `IntoDiagArg` prints the symbol as if it was an ident,
3089+
// so `'break` is printed as `r#break`. We don't want that
3090+
// here so convert to string eagerly.
3091+
name: ident.without_first_quote().name.to_string(),
3092+
});
30873093
}
30883094

30893095
self.bump();

tests/ui/closures/issue-52437.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
[(); &(&'static: loop { |x| {}; }) as *const _ as usize]
3-
//~^ ERROR: invalid label name `'static`
3+
//~^ ERROR: invalid label name `static`
44
//~| ERROR: type annotations needed
55
}

tests/ui/closures/issue-52437.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: invalid label name `'static`
1+
error: invalid label name `static`
22
--> $DIR/issue-52437.rs:2:13
33
|
44
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]

tests/ui/issues/issue-46311.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
2-
'break: loop { //~ ERROR invalid label name `'break`
2+
'break: loop { //~ ERROR invalid label name `break`
33
}
44
}

tests/ui/issues/issue-46311.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: invalid label name `'break`
1+
error: invalid label name `break`
22
--> $DIR/issue-46311.rs:2:5
33
|
44
LL | 'break: loop {

tests/ui/label/label-static.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
'static: loop { //~ ERROR invalid label name `'static`
3-
break 'static //~ ERROR invalid label name `'static`
2+
'static: loop { //~ ERROR invalid label name `static`
3+
break 'static //~ ERROR invalid label name `static`
44
}
55
}

tests/ui/label/label-static.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: invalid label name `'static`
1+
error: invalid label name `static`
22
--> $DIR/label-static.rs:2:5
33
|
44
LL | 'static: loop {
55
| ^^^^^^^
66

7-
error: invalid label name `'static`
7+
error: invalid label name `static`
88
--> $DIR/label-static.rs:3:15
99
|
1010
LL | break 'static

tests/ui/label/label-underscore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
'_: loop { //~ ERROR invalid label name `'_`
3-
break '_ //~ ERROR invalid label name `'_`
2+
'_: loop { //~ ERROR invalid label name `_`
3+
break '_ //~ ERROR invalid label name `_`
44
}
55
}

tests/ui/label/label-underscore.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: invalid label name `'_`
1+
error: invalid label name `_`
22
--> $DIR/label-underscore.rs:2:5
33
|
44
LL | '_: loop {
55
| ^^
66

7-
error: invalid label name `'_`
7+
error: invalid label name `_`
88
--> $DIR/label-underscore.rs:3:15
99
|
1010
LL | break '_

0 commit comments

Comments
 (0)