@@ -19,7 +19,7 @@ use rustc_errors::{
19
19
use rustc_hir as hir;
20
20
use rustc_hir:: def:: Namespace :: { self , * } ;
21
21
use 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 } ;
23
23
use rustc_hir:: PrimTy ;
24
24
use rustc_session:: lint;
25
25
use rustc_session:: parse:: feature_err;
@@ -166,13 +166,6 @@ impl TypoCandidate {
166
166
}
167
167
168
168
impl < ' 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
-
176
169
fn make_base_error (
177
170
& mut self ,
178
171
path : & [ Segment ] ,
@@ -191,7 +184,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
191
184
span,
192
185
span_label : match res {
193
186
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" ) )
195
188
}
196
189
_ => None ,
197
190
} ,
@@ -1295,9 +1288,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1295
1288
}
1296
1289
PathSource :: Expr ( _) | PathSource :: TupleStruct ( ..) | PathSource :: Pat => {
1297
1290
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" ) ) ;
1301
1292
let ( tail, descr, applicability) = match source {
1302
1293
PathSource :: Pat | PathSource :: TupleStruct ( ..) => {
1303
1294
( "" , "pattern" , Applicability :: MachineApplicable )
@@ -1359,17 +1350,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1359
1350
if self . r . tcx . sess . is_nightly_build ( ) {
1360
1351
let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
1361
1352
`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 ) ;
1371
1359
} else {
1372
- err. help ( msg) ;
1360
+ err. span_help ( span , msg) ;
1373
1361
}
1374
1362
}
1375
1363
}
@@ -1512,9 +1500,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1512
1500
match source {
1513
1501
PathSource :: Expr ( _) | PathSource :: TupleStruct ( ..) | PathSource :: Pat => {
1514
1502
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
+ ) ;
1518
1507
err. span_suggestion (
1519
1508
span,
1520
1509
"use this syntax instead" ,
@@ -1527,9 +1516,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1527
1516
}
1528
1517
( Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_def_id) , _) if ns == ValueNS => {
1529
1518
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" ) ) ;
1533
1520
let fields = self . r . field_names . get ( & def_id) . map_or_else (
1534
1521
|| "/* fields */" . to_string ( ) ,
1535
1522
|fields| vec ! [ "_" ; fields. len( ) ] . join ( ", " ) ,
@@ -2093,9 +2080,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2093
2080
} ;
2094
2081
2095
2082
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" ) ;
2099
2084
}
2100
2085
}
2101
2086
0 commit comments