]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check_unused.rs
Rollup merge of #54488 - zackmdavis:and_the_case_of_the_unused_crate, r=estebank
[rust.git] / src / librustc_typeck / check_unused.rs
index de4ab527e1559c155702bf5057bf312b8fa8b78d..62ffffab07661304f48df4af1bdd9a0baa587413 100644 (file)
@@ -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)