1
- use std:: ptr;
2
-
3
1
use rustc_ast:: expand:: StrippedCfgItem ;
4
2
use rustc_ast:: ptr:: P ;
5
3
use rustc_ast:: visit:: { self , Visitor } ;
@@ -182,13 +180,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
182
180
}
183
181
}
184
182
185
- pub ( crate ) fn report_conflict < ' b > (
183
+ pub ( crate ) fn report_conflict (
186
184
& mut self ,
187
185
parent : Module < ' _ > ,
188
186
ident : Ident ,
189
187
ns : Namespace ,
190
- new_binding : & NameBinding < ' b > ,
191
- old_binding : & NameBinding < ' b > ,
188
+ new_binding : NameBinding < ' a > ,
189
+ old_binding : NameBinding < ' a > ,
192
190
) {
193
191
// Error on the second of two conflicting names
194
192
if old_binding. span . lo ( ) > new_binding. span . lo ( ) {
@@ -262,7 +260,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
262
260
263
261
// See https://github.com/rust-lang/rust/issues/32354
264
262
use NameBindingKind :: Import ;
265
- let can_suggest = |binding : & NameBinding < ' _ > , import : & self :: Import < ' _ > | {
263
+ let can_suggest = |binding : NameBinding < ' _ > , import : self :: Import < ' _ > | {
266
264
!binding. span . is_dummy ( )
267
265
&& !matches ! ( import. kind, ImportKind :: MacroUse | ImportKind :: MacroExport )
268
266
} ;
@@ -272,22 +270,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
272
270
( Import { import : new, .. } , Import { import : old, .. } )
273
271
if {
274
272
( new. has_attributes || old. has_attributes )
275
- && can_suggest ( old_binding, old)
276
- && can_suggest ( new_binding, new)
273
+ && can_suggest ( old_binding, * old)
274
+ && can_suggest ( new_binding, * new)
277
275
} =>
278
276
{
279
277
if old. has_attributes {
280
- Some ( ( new, new_binding. span , true ) )
278
+ Some ( ( * new, new_binding. span , true ) )
281
279
} else {
282
- Some ( ( old, old_binding. span , true ) )
280
+ Some ( ( * old, old_binding. span , true ) )
283
281
}
284
282
}
285
283
// Otherwise prioritize the new binding.
286
- ( Import { import, .. } , other) if can_suggest ( new_binding, import) => {
287
- Some ( ( import, new_binding. span , other. is_import ( ) ) )
284
+ ( Import { import, .. } , other) if can_suggest ( new_binding, * import) => {
285
+ Some ( ( * import, new_binding. span , other. is_import ( ) ) )
288
286
}
289
- ( other, Import { import, .. } ) if can_suggest ( old_binding, import) => {
290
- Some ( ( import, old_binding. span , other. is_import ( ) ) )
287
+ ( other, Import { import, .. } ) if can_suggest ( old_binding, * import) => {
288
+ Some ( ( * import, old_binding. span , other. is_import ( ) ) )
291
289
}
292
290
_ => None ,
293
291
} ;
@@ -341,7 +339,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
341
339
& self ,
342
340
err : & mut Diagnostic ,
343
341
name : Symbol ,
344
- import : & Import < ' _ > ,
342
+ import : Import < ' _ > ,
345
343
binding_span : Span ,
346
344
) {
347
345
let suggested_name = if name. as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) {
@@ -413,7 +411,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
413
411
fn add_suggestion_for_duplicate_nested_use (
414
412
& self ,
415
413
err : & mut Diagnostic ,
416
- import : & Import < ' _ > ,
414
+ import : Import < ' _ > ,
417
415
binding_span : Span ,
418
416
) {
419
417
assert ! ( import. is_nested( ) ) ;
@@ -455,7 +453,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
455
453
& mut self ,
456
454
finalize : Option < Finalize > ,
457
455
path : & [ Segment ] ,
458
- second_binding : Option < & NameBinding < ' _ > > ,
456
+ second_binding : Option < NameBinding < ' _ > > ,
459
457
) {
460
458
let Some ( Finalize { node_id, root_span, .. } ) = finalize else {
461
459
return ;
@@ -1198,7 +1196,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1198
1196
// avoid suggesting anything with a hygienic name
1199
1197
if ident. name == lookup_ident. name
1200
1198
&& ns == namespace
1201
- && !ptr :: eq ( in_module, parent_scope. module )
1199
+ && in_module != parent_scope. module
1202
1200
&& !ident. span . normalize_to_macros_2_0 ( ) . from_expansion ( )
1203
1201
{
1204
1202
let res = name_binding. res ( ) ;
@@ -1515,7 +1513,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1515
1513
true
1516
1514
}
1517
1515
1518
- fn binding_description ( & self , b : & NameBinding < ' _ > , ident : Ident , from_prelude : bool ) -> String {
1516
+ fn binding_description ( & self , b : NameBinding < ' _ > , ident : Ident , from_prelude : bool ) -> String {
1519
1517
let res = b. res ( ) ;
1520
1518
if b. span . is_dummy ( ) || !self . tcx . sess . source_map ( ) . is_span_accessible ( b. span ) {
1521
1519
// These already contain the "built-in" prefix or look bad with it.
@@ -1555,7 +1553,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1555
1553
err. span_label ( ident. span , "ambiguous name" ) ;
1556
1554
err. note ( format ! ( "ambiguous because of {}" , kind. descr( ) ) ) ;
1557
1555
1558
- let mut could_refer_to = |b : & NameBinding < ' _ > , misc : AmbiguityErrorMisc , also : & str | {
1556
+ let mut could_refer_to = |b : NameBinding < ' _ > , misc : AmbiguityErrorMisc , also : & str | {
1559
1557
let what = self . binding_description ( b, ident, misc == AmbiguityErrorMisc :: FromPrelude ) ;
1560
1558
let note_msg = format ! ( "`{ident}` could{also} refer to {what}" ) ;
1561
1559
@@ -1595,7 +1593,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1595
1593
1596
1594
/// If the binding refers to a tuple struct constructor with fields,
1597
1595
/// returns the span of its fields.
1598
- fn ctor_fields_span ( & self , binding : & NameBinding < ' _ > ) -> Option < Span > {
1596
+ fn ctor_fields_span ( & self , binding : NameBinding < ' _ > ) -> Option < Span > {
1599
1597
if let NameBindingKind :: Res ( Res :: Def (
1600
1598
DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) ,
1601
1599
ctor_def_id,
@@ -1622,7 +1620,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1622
1620
if ctor_fields_span. is_some ( ) { plain_descr + " constructor" } else { plain_descr } ;
1623
1621
let import_descr = nonimport_descr. clone ( ) + " import" ;
1624
1622
let get_descr =
1625
- |b : & NameBinding < ' _ > | if b. is_import ( ) { & import_descr } else { & nonimport_descr } ;
1623
+ |b : NameBinding < ' _ > | if b. is_import ( ) { & import_descr } else { & nonimport_descr } ;
1626
1624
1627
1625
// Print the primary message.
1628
1626
let descr = get_descr ( binding) ;
@@ -1702,7 +1700,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1702
1700
_ => None ,
1703
1701
} ;
1704
1702
1705
- let first = ptr :: eq ( binding, first_binding) ;
1703
+ let first = binding == first_binding;
1706
1704
let msg = format ! (
1707
1705
"{and_refers_to}the {item} `{name}`{which} is defined here{dots}" ,
1708
1706
and_refers_to = if first { "" } else { "...and refers to " } ,
@@ -1732,7 +1730,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1732
1730
pub ( crate ) fn find_similarly_named_module_or_crate (
1733
1731
& mut self ,
1734
1732
ident : Symbol ,
1735
- current_module : & Module < ' a > ,
1733
+ current_module : Module < ' a > ,
1736
1734
) -> Option < Symbol > {
1737
1735
let mut candidates = self
1738
1736
. extern_prelude
@@ -1742,7 +1740,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1742
1740
self . module_map
1743
1741
. iter ( )
1744
1742
. filter ( |( _, module) | {
1745
- current_module. is_ancestor_of ( module) && !ptr :: eq ( current_module, * module)
1743
+ current_module. is_ancestor_of ( * * module) && current_module != * * module
1746
1744
} )
1747
1745
. flat_map ( |( _, module) | module. kind . name ( ) ) ,
1748
1746
)
@@ -1762,7 +1760,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1762
1760
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1763
1761
parent_scope : & ParentScope < ' a > ,
1764
1762
ribs : Option < & PerNS < Vec < Rib < ' a > > > > ,
1765
- ignore_binding : Option < & ' a NameBinding < ' a > > ,
1763
+ ignore_binding : Option < NameBinding < ' a > > ,
1766
1764
module : Option < ModuleOrUniformRoot < ' a > > ,
1767
1765
failed_segment_idx : usize ,
1768
1766
ident : Ident ,
@@ -1945,7 +1943,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1945
1943
}
1946
1944
1947
1945
suggestion = suggestion. or_else ( || {
1948
- self . find_similarly_named_module_or_crate ( ident. name , & parent_scope. module ) . map (
1946
+ self . find_similarly_named_module_or_crate ( ident. name , parent_scope. module ) . map (
1949
1947
|sugg| {
1950
1948
(
1951
1949
vec ! [ ( ident. span, sugg. to_string( ) ) ] ,
@@ -2114,7 +2112,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2114
2112
/// ```
2115
2113
pub ( crate ) fn check_for_module_export_macro (
2116
2114
& mut self ,
2117
- import : & ' a Import < ' a > ,
2115
+ import : Import < ' a > ,
2118
2116
module : ModuleOrUniformRoot < ' a > ,
2119
2117
ident : Ident ,
2120
2118
) -> Option < ( Option < Suggestion > , Option < String > ) > {
@@ -2126,9 +2124,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2126
2124
crate_module = parent;
2127
2125
}
2128
2126
2129
- if ModuleOrUniformRoot :: same_def ( ModuleOrUniformRoot :: Module ( crate_module) , module) {
2130
- // Don't make a suggestion if the import was already from the root of the
2131
- // crate.
2127
+ if module == ModuleOrUniformRoot :: Module ( crate_module) {
2128
+ // Don't make a suggestion if the import was already from the root of the crate.
2132
2129
return None ;
2133
2130
}
2134
2131
0 commit comments