Skip to content

Commit 0062829

Browse files
committed
Fix ICE in EarlyAttribtues lints
1 parent bb01aca commit 0062829

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clippy_lints/src/attrs.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::msrvs;
66
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
77
use clippy_utils::{extract_msrv_attr, meets_msrv};
88
use if_chain::if_chain;
9-
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
9+
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MacArgs, MacArgsEq, MetaItemKind, NestedMetaItem};
1010
use rustc_errors::Applicability;
1111
use rustc_hir::{
1212
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
@@ -593,6 +593,10 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
593593
};
594594

595595
if attr.style == AttrStyle::Outer {
596+
if let MacArgs::Eq(_, MacArgsEq::Ast(expr)) = &attr_item.args
597+
&& !matches!(expr.kind, rustc_ast::ExprKind::Lit(..)) {
598+
return;
599+
}
596600
if attr_item.args.inner_tokens().is_empty() || !is_present_in_source(cx, attr.span) {
597601
return;
598602
}

tests/ui/crashes/ice-96721.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
macro_rules! foo {
2+
() => {
3+
"bar.rs"
4+
};
5+
}
6+
7+
#[path = foo!()] //~ ERROR malformed `path` attribute
8+
mod abc {}
9+
10+
fn main() {}

tests/ui/crashes/ice-96721.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: malformed `path` attribute input
2+
--> $DIR/ice-96721.rs:7:1
3+
|
4+
LL | #[path = foo!()] //~ ERROR malformed `path` attribute
5+
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]`
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)