Fix ICE in EarlyAttribtues lints

This commit is contained in:
flip1995 2022-05-05 14:10:06 +01:00
parent bb01aca86f
commit 006282964f
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
3 changed files with 23 additions and 1 deletions

View file

@ -6,7 +6,7 @@ use clippy_utils::msrvs;
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
use clippy_utils::{extract_msrv_attr, meets_msrv};
use if_chain::if_chain;
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MacArgs, MacArgsEq, MetaItemKind, NestedMetaItem};
use rustc_errors::Applicability;
use rustc_hir::{
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
};
if attr.style == AttrStyle::Outer {
if let MacArgs::Eq(_, MacArgsEq::Ast(expr)) = &attr_item.args
&& !matches!(expr.kind, rustc_ast::ExprKind::Lit(..)) {
return;
}
if attr_item.args.inner_tokens().is_empty() || !is_present_in_source(cx, attr.span) {
return;
}

View file

@ -0,0 +1,10 @@
macro_rules! foo {
() => {
"bar.rs"
};
}
#[path = foo!()] //~ ERROR malformed `path` attribute
mod abc {}
fn main() {}

View file

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