X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_typeck%2Fcheck_unused.rs;h=62ffffab07661304f48df4af1bdd9a0baa587413;hb=b18821201f526a66617558f33c63854ab67a87f7;hp=de4ab527e1559c155702bf5057bf312b8fa8b78d;hpb=a1f3b0fe7424af1dc05a7853b9ef3d8ff8ffe28e;p=rust.git diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index de4ab527e15..62ffffab076 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -138,9 +138,15 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) { if extern_crate.warn_if_unused { if let Some(&span) = unused_extern_crates.get(&extern_crate.def_id) { let msg = "unused extern crate"; + + // Removal suggestion span needs to include attributes (Issue #54400) + let span_with_attrs = tcx.get_attrs(extern_crate.def_id).iter() + .map(|attr| attr.span) + .fold(span, |acc, attr_span| acc.to(attr_span)); + tcx.struct_span_lint_node(lint, id, span, msg) .span_suggestion_short_with_applicability( - span, + span_with_attrs, "remove it", String::new(), Applicability::MachineApplicable)