From: kennytm Date: Mon, 1 Oct 2018 08:12:56 +0000 (+0800) Subject: Rollup merge of #54488 - zackmdavis:and_the_case_of_the_unused_crate, r=estebank X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b18821201f526a66617558f33c63854ab67a87f7;p=rust.git Rollup merge of #54488 - zackmdavis:and_the_case_of_the_unused_crate, r=estebank in which we include attributes in unused `extern crate` suggestion spans ![unused_extern](https://user-images.githubusercontent.com/1076988/45921698-50243e80-be6f-11e8-930a-7b2a33b4935c.png) Resolves #54400. r? @estebank --- b18821201f526a66617558f33c63854ab67a87f7 diff --cc src/librustc_typeck/check_unused.rs index de4ab527e15,3dbd5f2017e..62ffffab076 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@@ -137,10 -136,19 +137,16 @@@ fn unused_crates_lint<'tcx>(tcx: TyCtxt // We do this in any edition. if extern_crate.warn_if_unused { if let Some(&span) = unused_extern_crates.get(&extern_crate.def_id) { - assert_eq!(extern_crate.def_id.krate, LOCAL_CRATE); - let hir_id = tcx.hir.definitions().def_index_to_hir_id(extern_crate.def_id.index); - let id = tcx.hir.hir_to_node_id(hir_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)