@@ -225,10 +225,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
225225 let ( name, span) =
226226 ( ident. name , self . tcx . sess . source_map ( ) . guess_head_span ( new_binding. span ) ) ;
227227
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 ;
232230 }
233231
234232 let old_kind = match ( ns, old_binding. module ( ) ) {
@@ -380,20 +378,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
380378 suggestion = Some ( format ! ( "self as {suggested_name}" ) )
381379 }
382380 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 ( )
385384 {
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}" ) ) ;
397389 }
398390 }
399391 ImportKind :: ExternCrate { source, target, .. } => {
@@ -510,13 +502,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
510502 // If the first element of our path was actually resolved to an
511503 // `ExternCrate` (also used for `crate::...`) then no need to issue a
512504 // 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 ;
520511 }
521512
522513 let diag = BuiltinLintDiag :: AbsPathWithModule ( root_span) ;
@@ -1215,12 +1206,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12151206 }
12161207
12171208 // #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 ;
12241214 }
12251215
12261216 let res = name_binding. res ( ) ;
@@ -1253,14 +1243,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12531243 segms. push ( ast:: PathSegment :: from_ident ( ident) ) ;
12541244 let path = Path { span : name_binding. span , segments : segms, tokens : None } ;
12551245
1256- if child_accessible {
1246+ if child_accessible
12571247 // Remove invisible match if exists
1258- if let Some ( idx) = candidates
1248+ && let Some ( idx) = candidates
12591249 . iter ( )
12601250 . position ( |v : & ImportSuggestion | v. did == did && !v. accessible )
1261- {
1262- candidates. remove ( idx) ;
1263- }
1251+ {
1252+ candidates. remove ( idx) ;
12641253 }
12651254
12661255 if candidates. iter ( ) . all ( |v : & ImportSuggestion | v. did != did) {
@@ -1545,19 +1534,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15451534 macro_kind. descr_expected( ) ,
15461535 ) ,
15471536 } ;
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 ;
15611550 }
15621551 let note = errors:: IdentInScopeButItIsDesc {
15631552 imported_ident : ident,
@@ -2436,20 +2425,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24362425 debug ! ( found_closing_brace, ?binding_span) ;
24372426
24382427 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) =
24482438 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 ( ) ) ;
24532442 }
24542443 debug ! ( ?removal_span) ;
24552444
@@ -3064,16 +3053,16 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
30643053
30653054fn search_for_any_use_in_items ( items : & [ P < ast:: Item > ] ) -> Option < Span > {
30663055 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 ( ) ) ;
30743063 }
3075- return Some ( Span :: new ( lo, lo, item. span . ctxt ( ) , item. span . parent ( ) ) ) ;
30763064 }
3065+ return Some ( Span :: new ( lo, lo, item. span . ctxt ( ) , item. span . parent ( ) ) ) ;
30773066 }
30783067 }
30793068 None
0 commit comments