@@ -33,39 +33,42 @@ use crate::imports::{ImportData, ImportKind};
33
33
use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
34
34
use crate :: {
35
35
BindingKey , ExternPreludeEntry , Finalize , MacroData , Module , ModuleKind , ModuleOrUniformRoot ,
36
- NameBinding , NameBindingData , NameBindingKind , ParentScope , PathResult , ResolutionError ,
37
- Resolver , ResolverArenas , Segment , ToNameBinding , Used , VisResolutionError , errors,
36
+ NameBinding , ParentScope , PathResult , ResolutionError , Resolver , Segment , Used ,
37
+ VisResolutionError , errors,
38
38
} ;
39
39
40
40
type Res = def:: Res < NodeId > ;
41
41
42
- impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId ) {
43
- fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
44
- arenas. alloc_name_binding ( NameBindingData {
45
- kind : NameBindingKind :: Res ( self . 0 ) ,
46
- ambiguity : None ,
47
- warn_ambiguity : false ,
48
- vis : self . 1 . to_def_id ( ) ,
49
- span : self . 2 ,
50
- expansion : self . 3 ,
51
- } )
52
- }
53
- }
54
-
55
42
impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
56
43
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
57
44
/// otherwise, reports an error.
58
- pub ( crate ) fn define < T > ( & mut self , parent : Module < ' ra > , ident : Ident , ns : Namespace , def : T )
59
- where
60
- T : ToNameBinding < ' ra > ,
61
- {
62
- let binding = def. to_name_binding ( self . arenas ) ;
45
+ pub ( crate ) fn define_binding (
46
+ & mut self ,
47
+ parent : Module < ' ra > ,
48
+ ident : Ident ,
49
+ ns : Namespace ,
50
+ binding : NameBinding < ' ra > ,
51
+ ) {
63
52
let key = self . new_disambiguated_key ( ident, ns) ;
64
53
if let Err ( old_binding) = self . try_define ( parent, key, binding, false ) {
65
54
self . report_conflict ( parent, ident, ns, old_binding, binding) ;
66
55
}
67
56
}
68
57
58
+ fn define (
59
+ & mut self ,
60
+ parent : Module < ' ra > ,
61
+ ident : Ident ,
62
+ ns : Namespace ,
63
+ res : Res ,
64
+ vis : ty:: Visibility < impl Into < DefId > > ,
65
+ span : Span ,
66
+ expn_id : LocalExpnId ,
67
+ ) {
68
+ let binding = self . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expn_id) ;
69
+ self . define_binding ( parent, ident, ns, binding)
70
+ }
71
+
69
72
/// Walks up the tree of definitions starting at `def_id`,
70
73
/// stopping at the first encountered module.
71
74
/// Parent block modules for arbitrary def-ids are not recorded for the local crate,
@@ -223,7 +226,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
223
226
_,
224
227
)
225
228
| Res :: PrimTy ( ..)
226
- | Res :: ToolMod => self . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
229
+ | Res :: ToolMod => self . define ( parent, ident, TypeNS , res, vis, span, expansion) ,
227
230
Res :: Def (
228
231
DefKind :: Fn
229
232
| DefKind :: AssocFn
@@ -232,9 +235,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
232
235
| DefKind :: AssocConst
233
236
| DefKind :: Ctor ( ..) ,
234
237
_,
235
- ) => self . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
238
+ ) => self . define ( parent, ident, ValueNS , res, vis, span, expansion) ,
236
239
Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
237
- self . define ( parent, ident, MacroNS , ( res, vis, span, expansion) )
240
+ self . define ( parent, ident, MacroNS , res, vis, span, expansion)
238
241
}
239
242
Res :: Def (
240
243
DefKind :: TyParam
@@ -698,7 +701,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
698
701
let expansion = parent_scope. expansion ;
699
702
700
703
// Define a name in the type namespace if it is not anonymous.
701
- self . r . define ( parent, ident, TypeNS , ( adt_res, adt_vis, adt_span, expansion) ) ;
704
+ self . r . define ( parent, ident, TypeNS , adt_res, adt_vis, adt_span, expansion) ;
702
705
self . r . feed_visibility ( feed, adt_vis) ;
703
706
let def_id = feed. key ( ) ;
704
707
@@ -750,7 +753,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
750
753
}
751
754
752
755
ItemKind :: Mod ( _, ident, ref mod_kind) => {
753
- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
756
+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
754
757
755
758
if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
756
759
self . r . mods_with_parse_errors . insert ( def_id) ;
@@ -769,10 +772,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
769
772
ItemKind :: Const ( box ConstItem { ident, .. } )
770
773
| ItemKind :: Delegation ( box Delegation { ident, .. } )
771
774
| ItemKind :: Static ( box StaticItem { ident, .. } ) => {
772
- self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
775
+ self . r . define ( parent, ident, ValueNS , res, vis, sp, expansion) ;
773
776
}
774
777
ItemKind :: Fn ( box Fn { ident, .. } ) => {
775
- self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
778
+ self . r . define ( parent, ident, ValueNS , res, vis, sp, expansion) ;
776
779
777
780
// Functions introducing procedural macros reserve a slot
778
781
// in the macro namespace as well (see #52225).
@@ -781,11 +784,11 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
781
784
782
785
// These items live in the type namespace.
783
786
ItemKind :: TyAlias ( box TyAlias { ident, .. } ) | ItemKind :: TraitAlias ( ident, ..) => {
784
- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
787
+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
785
788
}
786
789
787
790
ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
788
- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
791
+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
789
792
790
793
self . parent_scope . module = self . r . new_module (
791
794
Some ( parent) ,
@@ -837,7 +840,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
837
840
let feed = self . r . feed ( ctor_node_id) ;
838
841
let ctor_def_id = feed. key ( ) ;
839
842
let ctor_res = self . res ( ctor_def_id) ;
840
- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
843
+ self . r . define ( parent, ident, ValueNS , ctor_res, ctor_vis, sp, expansion) ;
841
844
self . r . feed_visibility ( feed, ctor_vis) ;
842
845
// We need the field visibility spans also for the constructor for E0603.
843
846
self . insert_field_visibilities_local ( ctor_def_id. to_def_id ( ) , vdata. fields ( ) ) ;
@@ -901,9 +904,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
901
904
}
902
905
. map ( |module| {
903
906
let used = self . process_macro_use_imports ( item, module) ;
904
- let res = module. res ( ) . unwrap ( ) ;
905
- let vis = ty:: Visibility :: < LocalDefId > :: Public ;
906
- let binding = ( res, vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
907
+ let binding = self . r . arenas . new_pub_res_binding ( module. res ( ) . unwrap ( ) , sp, expansion) ;
907
908
( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
908
909
} )
909
910
. unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
@@ -960,7 +961,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
960
961
) ;
961
962
}
962
963
}
963
- self . r . define ( parent, ident, TypeNS , imported_binding) ;
964
+ self . r . define_binding ( parent, ident, TypeNS , imported_binding) ;
964
965
}
965
966
966
967
/// Constructs the reduced graph for one foreign item.
@@ -977,7 +978,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
977
978
let parent = self . parent_scope . module ;
978
979
let expansion = self . parent_scope . expansion ;
979
980
let vis = self . resolve_visibility ( & item. vis ) ;
980
- self . r . define ( parent, ident, ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
981
+ self . r . define ( parent, ident, ns, self . res ( def_id) , vis, item. span , expansion) ;
981
982
self . r . feed_visibility ( feed, vis) ;
982
983
}
983
984
@@ -1217,7 +1218,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1217
1218
} else {
1218
1219
ty:: Visibility :: Restricted ( CRATE_DEF_ID )
1219
1220
} ;
1220
- let binding = ( res, vis, span, expansion) . to_name_binding ( self . r . arenas ) ;
1221
+ let binding = self . r . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expansion) ;
1221
1222
self . r . set_binding_parent_module ( binding, parent_scope. module ) ;
1222
1223
self . r . all_macro_rules . insert ( ident. name ) ;
1223
1224
if is_macro_export {
@@ -1236,7 +1237,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1236
1237
} ) ;
1237
1238
self . r . import_use_map . insert ( import, Used :: Other ) ;
1238
1239
let import_binding = self . r . import ( binding, import) ;
1239
- self . r . define ( self . r . graph_root , ident, MacroNS , import_binding) ;
1240
+ self . r . define_binding ( self . r . graph_root , ident, MacroNS , import_binding) ;
1240
1241
} else {
1241
1242
self . r . check_reserved_macro_name ( ident, res) ;
1242
1243
self . insert_unused_macro ( ident, def_id, item. id ) ;
@@ -1264,7 +1265,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1264
1265
if !vis. is_public ( ) {
1265
1266
self . insert_unused_macro ( ident, def_id, item. id ) ;
1266
1267
}
1267
- self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1268
+ self . r . define ( module, ident, MacroNS , res, vis, span, expansion) ;
1268
1269
self . r . feed_visibility ( feed, vis) ;
1269
1270
self . parent_scope . macro_rules
1270
1271
}
@@ -1400,7 +1401,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1400
1401
if ctxt == AssocCtxt :: Trait {
1401
1402
let parent = self . parent_scope . module ;
1402
1403
let expansion = self . parent_scope . expansion ;
1403
- self . r . define ( parent, ident, ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
1404
+ self . r . define ( parent, ident, ns, self . res ( def_id) , vis, item. span , expansion) ;
1404
1405
} else if !matches ! ( & item. kind, AssocItemKind :: Delegation ( deleg) if deleg. from_glob) {
1405
1406
let impl_def_id = self . r . tcx . local_parent ( local_def_id) ;
1406
1407
let key = BindingKey :: new ( ident. normalize_to_macros_2_0 ( ) , ns) ;
@@ -1485,7 +1486,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1485
1486
let feed = self . r . feed ( variant. id ) ;
1486
1487
let def_id = feed. key ( ) ;
1487
1488
let vis = self . resolve_visibility ( & variant. vis ) ;
1488
- self . r . define ( parent, ident, TypeNS , ( self . res ( def_id) , vis, variant. span , expn_id) ) ;
1489
+ self . r . define ( parent, ident, TypeNS , self . res ( def_id) , vis, variant. span , expn_id) ;
1489
1490
self . r . feed_visibility ( feed, vis) ;
1490
1491
1491
1492
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
@@ -1501,7 +1502,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1501
1502
let feed = self . r . feed ( ctor_node_id) ;
1502
1503
let ctor_def_id = feed. key ( ) ;
1503
1504
let ctor_res = self . res ( ctor_def_id) ;
1504
- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1505
+ self . r . define ( parent, ident, ValueNS , ctor_res, ctor_vis, variant. span , expn_id) ;
1505
1506
self . r . feed_visibility ( feed, ctor_vis) ;
1506
1507
}
1507
1508
0 commit comments