Skip to content

Commit 260090f

Browse files
Rollup merge of #166157 - JonathanBrouwer:recover-invalid-lit, r=panstromek
Don't recover invalid literals in attribute parsing The attempt at parser recovery creates duplicate diagnostics, where the non-recovered diagnostic is better, so we should remove it. This is also blocking for #164898
2 parents c8fe62f + 2a94a9f commit 260090f

4 files changed

Lines changed: 7 additions & 43 deletions

File tree

‎compiler/rustc_attr_parsing/src/parser.rs‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
1515

1616
use rustc_ast::token::{self, Delimiter, MetaVarKind};
1717
use rustc_ast::tokenstream::TokenStream;
18-
use rustc_ast::{
19-
AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp,
20-
};
18+
use rustc_ast::{AttrArgs, Expr, ExprKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp};
2119
use rustc_ast_pretty::pprust;
2220
use rustc_attr_ir::AttrPath;
2321
use rustc_errors::{Applicability, Diag, PResult};
@@ -424,23 +422,7 @@ fn expr_to_lit<'sess>(
424422
Err(psess.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span }))
425423
}
426424
}
427-
Err(err) => {
428-
let err = create_lit_error(psess, err, token_lit, expr.span);
429-
if matches!(
430-
should_emit,
431-
ShouldEmit::ErrorsAndLints { recovery: Recovery::Forbidden }
432-
) {
433-
Err(err)
434-
} else {
435-
let lit = MetaItemLit {
436-
symbol: token_lit.symbol,
437-
suffix: token_lit.suffix,
438-
kind: LitKind::Err(err.emit_err()),
439-
span: expr.span,
440-
};
441-
Ok(Some(lit))
442-
}
443-
}
425+
Err(err) => Err(create_lit_error(psess, err, token_lit, expr.span)),
444426
}
445427
} else {
446428
if matches!(should_emit, ShouldEmit::Nothing) || matches!(expr.kind, ExprKind::Err(_)) {

‎tests/ui/lint/pre-expansion-parsing.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
#[expect(expect(expect))] //~ ERROR malformed
77
#[deny(({!}))] // OK
88
#[expect[helix::<ub>]] // OK
9+
#[allow = 1u7] // OK
10+
#[allow = "x"suffix] // OK
911
#[cfg(false)]
1012
const _: () = ();

‎tests/ui/parser/bad-lit-suffixes.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ fn f() {}
3333

3434
#[must_use = "string"suffix]
3535
//~^ ERROR suffixes on string literals are invalid
36-
//~| ERROR malformed `must_use` attribute input
3736
fn g() {}
3837

3938
#[link(name = "string"suffix)]

‎tests/ui/parser/bad-lit-suffixes.stderr‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,17 @@ error: suffixes on string literals are invalid
136136
LL | #[must_use = "string"suffix]
137137
| ^^^^^^^^^^^^^^ invalid suffix `suffix`
138138

139-
error[E0539]: malformed `must_use` attribute input
140-
--> $DIR/bad-lit-suffixes.rs:34:3
141-
|
142-
LL | #[must_use = "string"suffix]
143-
| ^^^^^^^^^^^--------------
144-
| |
145-
| expected a string literal here
146-
|
147-
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute>
148-
help: try changing it to one of the following valid forms of the attribute
149-
|
150-
LL - #[must_use = "string"suffix]
151-
LL + #[must_use]
152-
|
153-
LL - #[must_use = "string"suffix]
154-
LL + #[must_use = "reason"]
155-
|
156-
157139
error: suffixes on string literals are invalid
158-
--> $DIR/bad-lit-suffixes.rs:39:15
140+
--> $DIR/bad-lit-suffixes.rs:38:15
159141
|
160142
LL | #[link(name = "string"suffix)]
161143
| ^^^^^^^^^^^^^^ invalid suffix `suffix`
162144

163145
error: suffixes on string literals are invalid
164-
--> $DIR/bad-lit-suffixes.rs:46:25
146+
--> $DIR/bad-lit-suffixes.rs:45:25
165147
|
166148
LL | #[rustc_confusables("blah"suffix)]
167149
| ^^^^^^^^^^^^ invalid suffix `suffix`
168150

169-
error: aborting due to 21 previous errors; 2 warnings emitted
151+
error: aborting due to 20 previous errors; 2 warnings emitted
170152

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

0 commit comments

Comments
 (0)