diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-11-23 20:32:38 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-23 20:32:38 +0530 |
| commit | 5d7b68c82bf4e6b4ba1171b01da2d11a0886f751 (patch) | |
| tree | 18e66af5ee7909c21e933c1cf4edd9915d2223eb | |
| parent | a39ed5c3f6629a227dee608bfa65e2d909eb7017 (diff) | |
| parent | 7c3f631ddf59b86b88b0e72ea3cb279e15f2bf07 (diff) | |
| download | rust-5d7b68c82bf4e6b4ba1171b01da2d11a0886f751.tar.gz rust-5d7b68c82bf4e6b4ba1171b01da2d11a0886f751.zip | |
Rollup merge of #104751 - nnethercote:fix-104620, r=petrochenkov
Fix an ICE parsing a malformed attribute. Fixes #104620. r? `@petrochenkov`
| -rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-104620.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-104620.stderr | 8 |
3 files changed, 18 insertions, 3 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 2f7c7a29492..3e012953115 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -618,9 +618,12 @@ impl MetaItemKind { }) => MetaItemKind::list_from_tokens(tokens.clone()), AttrArgs::Delimited(..) => None, AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind { - ast::ExprKind::Lit(token_lit) => Some(MetaItemKind::NameValue( - Lit::from_token_lit(token_lit, expr.span).expect("token_lit in from_attr_args"), - )), + ast::ExprKind::Lit(token_lit) => { + // Turn failures to `None`, we'll get parse errors elsewhere. + Lit::from_token_lit(token_lit, expr.span) + .ok() + .map(|lit| MetaItemKind::NameValue(lit)) + } _ => None, }, AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())), diff --git a/src/test/ui/parser/issue-104620.rs b/src/test/ui/parser/issue-104620.rs new file mode 100644 index 00000000000..f49476c4408 --- /dev/null +++ b/src/test/ui/parser/issue-104620.rs @@ -0,0 +1,4 @@ +#![feature(rustc_attrs)] + +#![rustc_dummy=5z] //~ ERROR unexpected expression: `5z` +fn main() {} diff --git a/src/test/ui/parser/issue-104620.stderr b/src/test/ui/parser/issue-104620.stderr new file mode 100644 index 00000000000..d06a6b2554b --- /dev/null +++ b/src/test/ui/parser/issue-104620.stderr @@ -0,0 +1,8 @@ +error: unexpected expression: `5z` + --> $DIR/issue-104620.rs:3:16 + | +LL | #![rustc_dummy=5z] + | ^^ + +error: aborting due to previous error + |
