@@ -19,7 +19,7 @@ use rustc_errors::{
1919use rustc_hir as hir;
2020use rustc_hir:: def:: Namespace :: { self , * } ;
2121use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind } ;
22- use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID , LOCAL_CRATE } ;
22+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
2323use rustc_hir:: PrimTy ;
2424use rustc_session:: lint;
2525use rustc_session:: parse:: feature_err;
@@ -166,13 +166,6 @@ impl TypoCandidate {
166166}
167167
168168impl < ' a : ' ast , ' ast , ' tcx > LateResolutionVisitor < ' a , ' _ , ' ast , ' tcx > {
169- fn def_span ( & self , def_id : DefId ) -> Option < Span > {
170- match def_id. krate {
171- LOCAL_CRATE => self . r . opt_span ( def_id) ,
172- _ => Some ( self . r . cstore ( ) . get_span_untracked ( def_id, self . r . tcx . sess ) ) ,
173- }
174- }
175-
176169 fn make_base_error (
177170 & mut self ,
178171 path : & [ Segment ] ,
@@ -191,7 +184,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
191184 span,
192185 span_label : match res {
193186 Res :: Def ( kind, def_id) if kind == DefKind :: TyParam => {
194- self . def_span ( def_id) . map ( |span| ( span , "found this type parameter" ) )
187+ Some ( ( self . r . def_span ( def_id) , "found this type parameter" ) )
195188 }
196189 _ => None ,
197190 } ,
@@ -1295,9 +1288,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
12951288 }
12961289 PathSource :: Expr ( _) | PathSource :: TupleStruct ( ..) | PathSource :: Pat => {
12971290 let span = find_span ( & source, err) ;
1298- if let Some ( span) = self . def_span ( def_id) {
1299- err. span_label ( span, & format ! ( "`{}` defined here" , path_str) ) ;
1300- }
1291+ err. span_label ( self . r . def_span ( def_id) , & format ! ( "`{path_str}` defined here" ) ) ;
13011292 let ( tail, descr, applicability) = match source {
13021293 PathSource :: Pat | PathSource :: TupleStruct ( ..) => {
13031294 ( "" , "pattern" , Applicability :: MachineApplicable )
@@ -1359,17 +1350,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
13591350 if self . r . tcx . sess . is_nightly_build ( ) {
13601351 let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
13611352 `type` alias";
1362- if let Some ( span) = self . def_span ( def_id) {
1363- if let Ok ( snip) = self . r . tcx . sess . source_map ( ) . span_to_snippet ( span) {
1364- // The span contains a type alias so we should be able to
1365- // replace `type` with `trait`.
1366- let snip = snip. replacen ( "type" , "trait" , 1 ) ;
1367- err. span_suggestion ( span, msg, snip, Applicability :: MaybeIncorrect ) ;
1368- } else {
1369- err. span_help ( span, msg) ;
1370- }
1353+ let span = self . r . def_span ( def_id) ;
1354+ if let Ok ( snip) = self . r . tcx . sess . source_map ( ) . span_to_snippet ( span) {
1355+ // The span contains a type alias so we should be able to
1356+ // replace `type` with `trait`.
1357+ let snip = snip. replacen ( "type" , "trait" , 1 ) ;
1358+ err. span_suggestion ( span, msg, snip, Applicability :: MaybeIncorrect ) ;
13711359 } else {
1372- err. help ( msg) ;
1360+ err. span_help ( span , msg) ;
13731361 }
13741362 }
13751363 }
@@ -1512,9 +1500,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
15121500 match source {
15131501 PathSource :: Expr ( _) | PathSource :: TupleStruct ( ..) | PathSource :: Pat => {
15141502 let span = find_span ( & source, err) ;
1515- if let Some ( span) = self . def_span ( def_id) {
1516- err. span_label ( span, & format ! ( "`{}` defined here" , path_str) ) ;
1517- }
1503+ err. span_label (
1504+ self . r . def_span ( def_id) ,
1505+ & format ! ( "`{path_str}` defined here" ) ,
1506+ ) ;
15181507 err. span_suggestion (
15191508 span,
15201509 "use this syntax instead" ,
@@ -1527,9 +1516,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
15271516 }
15281517 ( Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_def_id) , _) if ns == ValueNS => {
15291518 let def_id = self . r . tcx . parent ( ctor_def_id) ;
1530- if let Some ( span) = self . def_span ( def_id) {
1531- err. span_label ( span, & format ! ( "`{}` defined here" , path_str) ) ;
1532- }
1519+ err. span_label ( self . r . def_span ( def_id) , & format ! ( "`{path_str}` defined here" ) ) ;
15331520 let fields = self . r . field_names . get ( & def_id) . map_or_else (
15341521 || "/* fields */" . to_string ( ) ,
15351522 |fields| vec ! [ "_" ; fields. len( ) ] . join ( ", " ) ,
@@ -2093,9 +2080,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
20932080 } ;
20942081
20952082 if def_id. is_local ( ) {
2096- if let Some ( span) = self . def_span ( def_id) {
2097- err. span_note ( span, "the enum is defined here" ) ;
2098- }
2083+ err. span_note ( self . r . def_span ( def_id) , "the enum is defined here" ) ;
20992084 }
21002085 }
21012086
0 commit comments