@@ -15,9 +15,9 @@ use rustc_hir::OwnerId;
1515use rustc_middle:: ty:: query:: Providers ;
1616use rustc_middle:: ty:: TyCtxt ;
1717use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
18- use rustc_span:: symbol:: { kw :: Empty , sym, Symbol } ;
18+ use rustc_span:: symbol:: { sym, Symbol } ;
1919
20- use crate :: errors:: { DuplicateDiagnosticItem , DuplicateDiagnosticItemInCrate } ;
20+ use crate :: errors:: DuplicateDiagnosticItemInCrate ;
2121
2222fn observe_item < ' tcx > ( tcx : TyCtxt < ' tcx > , diagnostic_items : & mut DiagnosticItems , owner : OwnerId ) {
2323 let attrs = tcx. hir ( ) . attrs ( owner. into ( ) ) ;
@@ -42,20 +42,16 @@ fn report_duplicate_item(
4242 original_def_id : DefId ,
4343 item_def_id : DefId ,
4444) {
45- let ( orig_span, orig_crate_name, have_orig_crate_name) = match original_def_id. as_local ( ) {
46- Some ( local_original) => ( Some ( tcx. def_span ( local_original) ) , Empty , None ) ,
47- None => ( None , tcx. crate_name ( original_def_id. krate ) , Some ( ( ) ) ) ,
48- } ;
49- match tcx. hir ( ) . span_if_local ( item_def_id) {
50- Some ( span) => tcx. sess . emit_err ( DuplicateDiagnosticItem { span, name } ) ,
51- None => tcx. sess . emit_err ( DuplicateDiagnosticItemInCrate {
52- span : orig_span,
53- orig_crate_name,
54- have_orig_crate_name,
55- crate_name : tcx. crate_name ( item_def_id. krate ) ,
56- name,
57- } ) ,
58- } ;
45+ let orig_span = tcx. hir ( ) . span_if_local ( original_def_id) ;
46+ let duplicate_span = tcx. hir ( ) . span_if_local ( item_def_id) ;
47+ tcx. sess . emit_err ( DuplicateDiagnosticItemInCrate {
48+ duplicate_span,
49+ orig_span,
50+ crate_name : tcx. crate_name ( item_def_id. krate ) ,
51+ orig_crate_name : tcx. crate_name ( original_def_id. krate ) ,
52+ different_crates : ( item_def_id. krate != original_def_id. krate ) . then_some ( ( ) ) ,
53+ name,
54+ } ) ;
5955}
6056
6157/// Extract the first `rustc_diagnostic_item = "$name"` out of a list of attributes.
0 commit comments