Skip to content

Commit 5d7b68c

Browse files
authored
Rollup merge of rust-lang#104751 - nnethercote:fix-104620, r=petrochenkov
Fix an ICE parsing a malformed attribute. Fixes rust-lang#104620. r? `@petrochenkov`
2 parents a39ed5c + 7c3f631 commit 5d7b68c

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

compiler/rustc_ast/src/attr/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,12 @@ impl MetaItemKind {
618618
}) => MetaItemKind::list_from_tokens(tokens.clone()),
619619
AttrArgs::Delimited(..) => None,
620620
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind {
621-
ast::ExprKind::Lit(token_lit) => Some(MetaItemKind::NameValue(
622-
Lit::from_token_lit(token_lit, expr.span).expect("token_lit in from_attr_args"),
623-
)),
621+
ast::ExprKind::Lit(token_lit) => {
622+
// Turn failures to `None`, we'll get parse errors elsewhere.
623+
Lit::from_token_lit(token_lit, expr.span)
624+
.ok()
625+
.map(|lit| MetaItemKind::NameValue(lit))
626+
}
624627
_ => None,
625628
},
626629
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())),

src/test/ui/parser/issue-104620.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(rustc_attrs)]
2+
3+
#![rustc_dummy=5z] //~ ERROR unexpected expression: `5z`
4+
fn main() {}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected expression: `5z`
2+
--> $DIR/issue-104620.rs:3:16
3+
|
4+
LL | #![rustc_dummy=5z]
5+
| ^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)