mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
Fix ICE in EarlyAttribtues lints
This commit is contained in:
parent
bb01aca86f
commit
006282964f
3 changed files with 23 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
10
tests/ui/crashes/ice-96721.rs
Normal file
10
tests/ui/crashes/ice-96721.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
macro_rules! foo {
|
||||
() => {
|
||||
"bar.rs"
|
||||
};
|
||||
}
|
||||
|
||||
#[path = foo!()] //~ ERROR malformed `path` attribute
|
||||
mod abc {}
|
||||
|
||||
fn main() {}
|
8
tests/ui/crashes/ice-96721.stderr
Normal file
8
tests/ui/crashes/ice-96721.stderr
Normal 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
|
||||
|
Loading…
Reference in a new issue