@@ -227,10 +227,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
227
227
let ( name, span) =
228
228
( ident. name , self . tcx . sess . source_map ( ) . guess_head_span ( new_binding. span ) ) ;
229
229
230
- if let Some ( s) = self . name_already_seen . get ( & name) {
231
- if s == & span {
232
- return ;
233
- }
230
+ if let Some ( s) = self . name_already_seen . get ( & name)
231
+ && s == & span
232
+ {
233
+ return ;
234
234
}
235
235
236
236
let old_kind = match ( ns, old_binding. module ( ) ) {
@@ -382,20 +382,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
382
382
suggestion = Some ( format ! ( "self as {suggested_name}" ) )
383
383
}
384
384
ImportKind :: Single { source, .. } => {
385
- if let Some ( pos) =
386
- source. span . hi ( ) . 0 . checked_sub ( binding_span. lo ( ) . 0 ) . map ( |pos| pos as usize )
385
+ if let Some ( pos) = source. span . hi ( ) . 0 . checked_sub ( binding_span. lo ( ) . 0 )
386
+ && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( binding_span)
387
+ && pos as usize <= snippet. len ( )
387
388
{
388
- if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( binding_span) {
389
- if pos <= snippet. len ( ) {
390
- span = binding_span
391
- . with_lo ( binding_span. lo ( ) + BytePos ( pos as u32 ) )
392
- . with_hi (
393
- binding_span. hi ( )
394
- - BytePos ( if snippet. ends_with ( ';' ) { 1 } else { 0 } ) ,
395
- ) ;
396
- suggestion = Some ( format ! ( " as {suggested_name}" ) ) ;
397
- }
398
- }
389
+ span = binding_span. with_lo ( binding_span. lo ( ) + BytePos ( pos) ) . with_hi (
390
+ binding_span. hi ( ) - BytePos ( if snippet. ends_with ( ';' ) { 1 } else { 0 } ) ,
391
+ ) ;
392
+ suggestion = Some ( format ! ( " as {suggested_name}" ) ) ;
399
393
}
400
394
}
401
395
ImportKind :: ExternCrate { source, target, .. } => {
@@ -512,13 +506,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
512
506
// If the first element of our path was actually resolved to an
513
507
// `ExternCrate` (also used for `crate::...`) then no need to issue a
514
508
// warning, this looks all good!
515
- if let Some ( binding) = second_binding {
516
- if let NameBindingKind :: Import { import, .. } = binding. kind {
517
- // Careful: we still want to rewrite paths from renamed extern crates.
518
- if let ImportKind :: ExternCrate { source : None , .. } = import. kind {
519
- return ;
520
- }
521
- }
509
+ if let Some ( binding) = second_binding
510
+ && let NameBindingKind :: Import { import, .. } = binding. kind
511
+ // Careful: we still want to rewrite paths from renamed extern crates.
512
+ && let ImportKind :: ExternCrate { source : None , .. } = import. kind
513
+ {
514
+ return ;
522
515
}
523
516
524
517
let diag = BuiltinLintDiag :: AbsPathWithModule ( root_span) ;
@@ -1217,12 +1210,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1217
1210
}
1218
1211
1219
1212
// #90113: Do not count an inaccessible reexported item as a candidate.
1220
- if let NameBindingKind :: Import { binding, .. } = name_binding. kind {
1221
- if this. is_accessible_from ( binding. vis , parent_scope. module )
1222
- && !this. is_accessible_from ( name_binding. vis , parent_scope. module )
1223
- {
1224
- return ;
1225
- }
1213
+ if let NameBindingKind :: Import { binding, .. } = name_binding. kind
1214
+ && this. is_accessible_from ( binding. vis , parent_scope. module )
1215
+ && !this. is_accessible_from ( name_binding. vis , parent_scope. module )
1216
+ {
1217
+ return ;
1226
1218
}
1227
1219
1228
1220
let res = name_binding. res ( ) ;
@@ -1255,14 +1247,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1255
1247
segms. push ( ast:: PathSegment :: from_ident ( ident) ) ;
1256
1248
let path = Path { span : name_binding. span , segments : segms, tokens : None } ;
1257
1249
1258
- if child_accessible {
1250
+ if child_accessible
1259
1251
// Remove invisible match if exists
1260
- if let Some ( idx) = candidates
1252
+ && let Some ( idx) = candidates
1261
1253
. iter ( )
1262
1254
. position ( |v : & ImportSuggestion | v. did == did && !v. accessible )
1263
- {
1264
- candidates. remove ( idx) ;
1265
- }
1255
+ {
1256
+ candidates. remove ( idx) ;
1266
1257
}
1267
1258
1268
1259
if candidates. iter ( ) . all ( |v : & ImportSuggestion | v. did != did) {
@@ -1319,12 +1310,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1319
1310
let is_extern_crate_that_also_appears_in_prelude =
1320
1311
name_binding. is_extern_crate ( ) && lookup_ident. span . at_least_rust_2018 ( ) ;
1321
1312
1322
- if !is_extern_crate_that_also_appears_in_prelude || alias_import {
1313
+ if ( !is_extern_crate_that_also_appears_in_prelude || alias_import)
1323
1314
// add the module to the lookup
1324
- if seen_modules. insert ( module. def_id ( ) ) {
1325
- if via_import { & mut worklist_via_import } else { & mut worklist }
1326
- . push ( ( module, path_segments, child_accessible, child_doc_visible) ) ;
1327
- }
1315
+ && seen_modules. insert ( module. def_id ( ) )
1316
+ {
1317
+ if via_import { & mut worklist_via_import } else { & mut worklist } . push ( (
1318
+ module,
1319
+ path_segments,
1320
+ child_accessible,
1321
+ child_doc_visible,
1322
+ ) ) ;
1328
1323
}
1329
1324
}
1330
1325
} )
@@ -1547,19 +1542,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1547
1542
macro_kind. descr_expected( ) ,
1548
1543
) ,
1549
1544
} ;
1550
- if let crate :: NameBindingKind :: Import { import, .. } = binding. kind {
1551
- if !import. span . is_dummy ( ) {
1552
- let note = errors :: IdentImporterHereButItIsDesc {
1553
- span : import . span ,
1554
- imported_ident : ident ,
1555
- imported_ident_desc : & desc ,
1556
- } ;
1557
- err . subdiagnostic ( note ) ;
1558
- // Silence the 'unused import' warning we might get,
1559
- // since this diagnostic already covers that import.
1560
- self . record_use ( ident , binding , Used :: Other ) ;
1561
- return ;
1562
- }
1545
+ if let crate :: NameBindingKind :: Import { import, .. } = binding. kind
1546
+ && !import. span . is_dummy ( )
1547
+ {
1548
+ let note = errors :: IdentImporterHereButItIsDesc {
1549
+ span : import . span ,
1550
+ imported_ident : ident ,
1551
+ imported_ident_desc : & desc ,
1552
+ } ;
1553
+ err . subdiagnostic ( note ) ;
1554
+ // Silence the 'unused import' warning we might get,
1555
+ // since this diagnostic already covers that import.
1556
+ self . record_use ( ident , binding , Used :: Other ) ;
1557
+ return ;
1563
1558
}
1564
1559
let note = errors:: IdentInScopeButItIsDesc {
1565
1560
imported_ident : ident,
@@ -2441,20 +2436,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2441
2436
) ;
2442
2437
2443
2438
let mut removal_span = binding_span;
2444
- if found_closing_brace {
2445
- // If the binding span ended with a closing brace, as in the below example:
2446
- // ie. `use a::b::{c, d};`
2447
- // ^
2448
- // Then expand the span of characters to remove to include the previous
2449
- // binding's trailing comma.
2450
- // ie. `use a::b::{c, d};`
2451
- // ^^^
2452
- if let Some ( previous_span) =
2439
+
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 found_closing_brace
2448
+ && let Some ( previous_span) =
2453
2449
extend_span_to_previous_binding ( self . tcx . sess , binding_span)
2454
- {
2455
- debug ! ( "check_for_module_export_macro: previous_span={:?}" , previous_span) ;
2456
- removal_span = removal_span. with_lo ( previous_span. lo ( ) ) ;
2457
- }
2450
+ {
2451
+ debug ! ( "check_for_module_export_macro: previous_span={:?}" , previous_span) ;
2452
+ removal_span = removal_span. with_lo ( previous_span. lo ( ) ) ;
2458
2453
}
2459
2454
debug ! ( "check_for_module_export_macro: removal_span={:?}" , removal_span) ;
2460
2455
0 commit comments