@@ -225,10 +225,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
225
225
let ( name, span) =
226
226
( ident. name , self . tcx . sess . source_map ( ) . guess_head_span ( new_binding. span ) ) ;
227
227
228
- if let Some ( s) = self . name_already_seen . get ( & name) {
229
- if s == & span {
230
- return ;
231
- }
228
+ if self . name_already_seen . get ( & name) == Some ( & span) {
229
+ return ;
232
230
}
233
231
234
232
let old_kind = match ( ns, old_binding. module ( ) ) {
@@ -380,20 +378,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
380
378
suggestion = Some ( format ! ( "self as {suggested_name}" ) )
381
379
}
382
380
ImportKind :: Single { source, .. } => {
383
- if let Some ( pos) =
384
- source. span . hi ( ) . 0 . checked_sub ( binding_span. lo ( ) . 0 ) . map ( |pos| pos as usize )
381
+ if let Some ( pos) = source. span . hi ( ) . 0 . checked_sub ( binding_span. lo ( ) . 0 )
382
+ && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( binding_span)
383
+ && pos as usize <= snippet. len ( )
385
384
{
386
- if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( binding_span) {
387
- if pos <= snippet. len ( ) {
388
- span = binding_span
389
- . with_lo ( binding_span. lo ( ) + BytePos ( pos as u32 ) )
390
- . with_hi (
391
- binding_span. hi ( )
392
- - BytePos ( if snippet. ends_with ( ';' ) { 1 } else { 0 } ) ,
393
- ) ;
394
- suggestion = Some ( format ! ( " as {suggested_name}" ) ) ;
395
- }
396
- }
385
+ span = binding_span. with_lo ( binding_span. lo ( ) + BytePos ( pos) ) . with_hi (
386
+ binding_span. hi ( ) - BytePos ( if snippet. ends_with ( ';' ) { 1 } else { 0 } ) ,
387
+ ) ;
388
+ suggestion = Some ( format ! ( " as {suggested_name}" ) ) ;
397
389
}
398
390
}
399
391
ImportKind :: ExternCrate { source, target, .. } => {
@@ -510,13 +502,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
510
502
// If the first element of our path was actually resolved to an
511
503
// `ExternCrate` (also used for `crate::...`) then no need to issue a
512
504
// warning, this looks all good!
513
- if let Some ( binding) = second_binding {
514
- if let NameBindingKind :: Import { import, .. } = binding. kind {
515
- // Careful: we still want to rewrite paths from renamed extern crates.
516
- if let ImportKind :: ExternCrate { source : None , .. } = import. kind {
517
- return ;
518
- }
519
- }
505
+ if let Some ( binding) = second_binding
506
+ && let NameBindingKind :: Import { import, .. } = binding. kind
507
+ // Careful: we still want to rewrite paths from renamed extern crates.
508
+ && let ImportKind :: ExternCrate { source : None , .. } = import. kind
509
+ {
510
+ return ;
520
511
}
521
512
522
513
let diag = BuiltinLintDiag :: AbsPathWithModule ( root_span) ;
@@ -1215,12 +1206,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1215
1206
}
1216
1207
1217
1208
// #90113: Do not count an inaccessible reexported item as a candidate.
1218
- if let NameBindingKind :: Import { binding, .. } = name_binding. kind {
1219
- if this. is_accessible_from ( binding. vis , parent_scope. module )
1220
- && !this. is_accessible_from ( name_binding. vis , parent_scope. module )
1221
- {
1222
- return ;
1223
- }
1209
+ if let NameBindingKind :: Import { binding, .. } = name_binding. kind
1210
+ && this. is_accessible_from ( binding. vis , parent_scope. module )
1211
+ && !this. is_accessible_from ( name_binding. vis , parent_scope. module )
1212
+ {
1213
+ return ;
1224
1214
}
1225
1215
1226
1216
let res = name_binding. res ( ) ;
@@ -1253,14 +1243,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1253
1243
segms. push ( ast:: PathSegment :: from_ident ( ident) ) ;
1254
1244
let path = Path { span : name_binding. span , segments : segms, tokens : None } ;
1255
1245
1256
- if child_accessible {
1246
+ if child_accessible
1257
1247
// Remove invisible match if exists
1258
- if let Some ( idx) = candidates
1248
+ && let Some ( idx) = candidates
1259
1249
. iter ( )
1260
1250
. position ( |v : & ImportSuggestion | v. did == did && !v. accessible )
1261
- {
1262
- candidates. remove ( idx) ;
1263
- }
1251
+ {
1252
+ candidates. remove ( idx) ;
1264
1253
}
1265
1254
1266
1255
if candidates. iter ( ) . all ( |v : & ImportSuggestion | v. did != did) {
@@ -1545,19 +1534,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1545
1534
macro_kind. descr_expected( ) ,
1546
1535
) ,
1547
1536
} ;
1548
- if let crate :: NameBindingKind :: Import { import, .. } = binding. kind {
1549
- if !import. span . is_dummy ( ) {
1550
- let note = errors :: IdentImporterHereButItIsDesc {
1551
- span : import . span ,
1552
- imported_ident : ident ,
1553
- imported_ident_desc : & desc ,
1554
- } ;
1555
- err . subdiagnostic ( note ) ;
1556
- // Silence the 'unused import' warning we might get,
1557
- // since this diagnostic already covers that import.
1558
- self . record_use ( ident , binding , Used :: Other ) ;
1559
- return ;
1560
- }
1537
+ if let crate :: NameBindingKind :: Import { import, .. } = binding. kind
1538
+ && !import. span . is_dummy ( )
1539
+ {
1540
+ let note = errors :: IdentImporterHereButItIsDesc {
1541
+ span : import . span ,
1542
+ imported_ident : ident ,
1543
+ imported_ident_desc : & desc ,
1544
+ } ;
1545
+ err . subdiagnostic ( note ) ;
1546
+ // Silence the 'unused import' warning we might get,
1547
+ // since this diagnostic already covers that import.
1548
+ self . record_use ( ident , binding , Used :: Other ) ;
1549
+ return ;
1561
1550
}
1562
1551
let note = errors:: IdentInScopeButItIsDesc {
1563
1552
imported_ident : ident,
@@ -2436,20 +2425,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2436
2425
debug ! ( found_closing_brace, ?binding_span) ;
2437
2426
2438
2427
let mut removal_span = binding_span;
2439
- if found_closing_brace {
2440
- // If the binding span ended with a closing brace, as in the below example:
2441
- // ie. `use a::b::{c, d};`
2442
- // ^
2443
- // Then expand the span of characters to remove to include the previous
2444
- // binding's trailing comma.
2445
- // ie. `use a::b::{c, d};`
2446
- // ^^^
2447
- if let Some ( previous_span) =
2428
+
2429
+ // If the binding span ended with a closing brace, as in the below example:
2430
+ // ie. `use a::b::{c, d};`
2431
+ // ^
2432
+ // Then expand the span of characters to remove to include the previous
2433
+ // binding's trailing comma.
2434
+ // ie. `use a::b::{c, d};`
2435
+ // ^^^
2436
+ if found_closing_brace
2437
+ && let Some ( previous_span) =
2448
2438
extend_span_to_previous_binding ( self . tcx . sess , binding_span)
2449
- {
2450
- debug ! ( ?previous_span) ;
2451
- removal_span = removal_span. with_lo ( previous_span. lo ( ) ) ;
2452
- }
2439
+ {
2440
+ debug ! ( ?previous_span) ;
2441
+ removal_span = removal_span. with_lo ( previous_span. lo ( ) ) ;
2453
2442
}
2454
2443
debug ! ( ?removal_span) ;
2455
2444
@@ -3064,16 +3053,16 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
3064
3053
3065
3054
fn search_for_any_use_in_items ( items : & [ P < ast:: Item > ] ) -> Option < Span > {
3066
3055
for item in items {
3067
- if let ItemKind :: Use ( ..) = item. kind {
3068
- if is_span_suitable_for_use_injection ( item. span ) {
3069
- let mut lo = item . span . lo ( ) ;
3070
- for attr in & item. attrs {
3071
- if attr . span . eq_ctxt ( item. span ) {
3072
- lo = std :: cmp :: min ( lo , attr. span . lo ( ) ) ;
3073
- }
3056
+ if let ItemKind :: Use ( ..) = item. kind
3057
+ && is_span_suitable_for_use_injection ( item. span )
3058
+ {
3059
+ let mut lo = item. span . lo ( ) ;
3060
+ for attr in & item. attrs {
3061
+ if attr. span . eq_ctxt ( item . span ) {
3062
+ lo = std :: cmp :: min ( lo , attr . span . lo ( ) ) ;
3074
3063
}
3075
- return Some ( Span :: new ( lo, lo, item. span . ctxt ( ) , item. span . parent ( ) ) ) ;
3076
3064
}
3065
+ return Some ( Span :: new ( lo, lo, item. span . ctxt ( ) , item. span . parent ( ) ) ) ;
3077
3066
}
3078
3067
}
3079
3068
None
0 commit comments