@@ -33,40 +33,42 @@ use crate::imports::{ImportData, ImportKind};
33
33
use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
34
34
use crate :: {
35
35
BindingKey , Determinacy , ExternPreludeEntry , Finalize , MacroData , Module , ModuleKind ,
36
- ModuleOrUniformRoot , NameBinding , NameBindingData , NameBindingKind , ParentScope , PathResult ,
37
- ResolutionError , Resolver , ResolverArenas , Segment , ToNameBinding , Used , VisResolutionError ,
38
- errors,
36
+ ModuleOrUniformRoot , NameBinding , ParentScope , PathResult , ResolutionError , Resolver , Segment ,
37
+ Used , VisResolutionError , errors,
39
38
} ;
40
39
41
40
type Res = def:: Res < NodeId > ;
42
41
43
- impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId ) {
44
- fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
45
- arenas. alloc_name_binding ( NameBindingData {
46
- kind : NameBindingKind :: Res ( self . 0 ) ,
47
- ambiguity : None ,
48
- warn_ambiguity : false ,
49
- vis : self . 1 . to_def_id ( ) ,
50
- span : self . 2 ,
51
- expansion : self . 3 ,
52
- } )
53
- }
54
- }
55
-
56
42
impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
57
43
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
58
44
/// otherwise, reports an error.
59
- pub ( crate ) fn define < T > ( & mut self , parent : Module < ' ra > , ident : Ident , ns : Namespace , def : T )
60
- where
61
- T : ToNameBinding < ' ra > ,
62
- {
63
- 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
+ ) {
64
52
let key = self . new_disambiguated_key ( ident, ns) ;
65
53
if let Err ( old_binding) = self . try_define ( parent, key, binding, false ) {
66
54
self . report_conflict ( parent, ident, ns, old_binding, binding) ;
67
55
}
68
56
}
69
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
+
70
72
/// Walks up the tree of definitions starting at `def_id`,
71
73
/// stopping at the first encountered module.
72
74
/// Parent block modules for arbitrary def-ids are not recorded for the local crate,
@@ -222,7 +224,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
222
224
_,
223
225
)
224
226
| Res :: PrimTy ( ..)
225
- | Res :: ToolMod => self . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
227
+ | Res :: ToolMod => self . define ( parent, ident, TypeNS , res, vis, span, expansion) ,
226
228
Res :: Def (
227
229
DefKind :: Fn
228
230
| DefKind :: AssocFn
@@ -231,9 +233,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
231
233
| DefKind :: AssocConst
232
234
| DefKind :: Ctor ( ..) ,
233
235
_,
234
- ) => self . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
236
+ ) => self . define ( parent, ident, ValueNS , res, vis, span, expansion) ,
235
237
Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
236
- self . define ( parent, ident, MacroNS , ( res, vis, span, expansion) )
238
+ self . define ( parent, ident, MacroNS , res, vis, span, expansion)
237
239
}
238
240
Res :: Def (
239
241
DefKind :: TyParam
@@ -706,7 +708,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
706
708
let expansion = parent_scope. expansion ;
707
709
708
710
// Define a name in the type namespace if it is not anonymous.
709
- self . r . define ( parent, ident, TypeNS , ( adt_res, adt_vis, adt_span, expansion) ) ;
711
+ self . r . define ( parent, ident, TypeNS , adt_res, adt_vis, adt_span, expansion) ;
710
712
self . r . feed_visibility ( feed, adt_vis) ;
711
713
let def_id = feed. key ( ) ;
712
714
@@ -758,7 +760,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
758
760
}
759
761
760
762
ItemKind :: Mod ( _, ident, ref mod_kind) => {
761
- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
763
+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
762
764
763
765
if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
764
766
self . r . mods_with_parse_errors . insert ( def_id) ;
@@ -777,10 +779,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
777
779
ItemKind :: Const ( box ConstItem { ident, .. } )
778
780
| ItemKind :: Delegation ( box Delegation { ident, .. } )
779
781
| ItemKind :: Static ( box StaticItem { ident, .. } ) => {
780
- self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
782
+ self . r . define ( parent, ident, ValueNS , res, vis, sp, expansion) ;
781
783
}
782
784
ItemKind :: Fn ( box Fn { ident, .. } ) => {
783
- self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
785
+ self . r . define ( parent, ident, ValueNS , res, vis, sp, expansion) ;
784
786
785
787
// Functions introducing procedural macros reserve a slot
786
788
// in the macro namespace as well (see #52225).
@@ -789,11 +791,11 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
789
791
790
792
// These items live in the type namespace.
791
793
ItemKind :: TyAlias ( box TyAlias { ident, .. } ) | ItemKind :: TraitAlias ( ident, ..) => {
792
- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
794
+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
793
795
}
794
796
795
797
ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
796
- self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
798
+ self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
797
799
798
800
self . parent_scope . module = self . r . new_module (
799
801
Some ( parent) ,
@@ -845,7 +847,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
845
847
let feed = self . r . feed ( ctor_node_id) ;
846
848
let ctor_def_id = feed. key ( ) ;
847
849
let ctor_res = self . res ( ctor_def_id) ;
848
- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
850
+ self . r . define ( parent, ident, ValueNS , ctor_res, ctor_vis, sp, expansion) ;
849
851
self . r . feed_visibility ( feed, ctor_vis) ;
850
852
// We need the field visibility spans also for the constructor for E0603.
851
853
self . insert_field_visibilities_local ( ctor_def_id. to_def_id ( ) , vdata. fields ( ) ) ;
@@ -909,9 +911,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
909
911
}
910
912
. map ( |module| {
911
913
let used = self . process_macro_use_imports ( item, module) ;
912
- let res = module. res ( ) . unwrap ( ) ;
913
- let vis = ty:: Visibility :: < LocalDefId > :: Public ;
914
- let binding = ( res, vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
914
+ let binding = self . r . arenas . new_pub_res_binding ( module. res ( ) . unwrap ( ) , sp, expansion) ;
915
915
( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
916
916
} )
917
917
. unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
@@ -968,7 +968,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
968
968
) ;
969
969
}
970
970
}
971
- self . r . define ( parent, ident, TypeNS , imported_binding) ;
971
+ self . r . define_binding ( parent, ident, TypeNS , imported_binding) ;
972
972
}
973
973
974
974
/// Constructs the reduced graph for one foreign item.
@@ -985,7 +985,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
985
985
let parent = self . parent_scope . module ;
986
986
let expansion = self . parent_scope . expansion ;
987
987
let vis = self . resolve_visibility ( & item. vis ) ;
988
- self . r . define ( parent, ident, ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
988
+ self . r . define ( parent, ident, ns, self . res ( def_id) , vis, item. span , expansion) ;
989
989
self . r . feed_visibility ( feed, vis) ;
990
990
}
991
991
@@ -1225,7 +1225,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1225
1225
} else {
1226
1226
ty:: Visibility :: Restricted ( CRATE_DEF_ID )
1227
1227
} ;
1228
- let binding = ( res, vis, span, expansion) . to_name_binding ( self . r . arenas ) ;
1228
+ let binding = self . r . arenas . new_res_binding ( res, vis. to_def_id ( ) , span, expansion) ;
1229
1229
self . r . set_binding_parent_module ( binding, parent_scope. module ) ;
1230
1230
self . r . all_macro_rules . insert ( ident. name ) ;
1231
1231
if is_macro_export {
@@ -1244,7 +1244,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1244
1244
} ) ;
1245
1245
self . r . import_use_map . insert ( import, Used :: Other ) ;
1246
1246
let import_binding = self . r . import ( binding, import) ;
1247
- self . r . define ( self . r . graph_root , ident, MacroNS , import_binding) ;
1247
+ self . r . define_binding ( self . r . graph_root , ident, MacroNS , import_binding) ;
1248
1248
} else {
1249
1249
self . r . check_reserved_macro_name ( ident, res) ;
1250
1250
self . insert_unused_macro ( ident, def_id, item. id ) ;
@@ -1272,7 +1272,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1272
1272
if !vis. is_public ( ) {
1273
1273
self . insert_unused_macro ( ident, def_id, item. id ) ;
1274
1274
}
1275
- self . r . define ( module, ident, MacroNS , ( res, vis, span, expansion) ) ;
1275
+ self . r . define ( module, ident, MacroNS , res, vis, span, expansion) ;
1276
1276
self . r . feed_visibility ( feed, vis) ;
1277
1277
self . parent_scope . macro_rules
1278
1278
}
@@ -1408,7 +1408,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1408
1408
if ctxt == AssocCtxt :: Trait {
1409
1409
let parent = self . parent_scope . module ;
1410
1410
let expansion = self . parent_scope . expansion ;
1411
- self . r . define ( parent, ident, ns, ( self . res ( def_id) , vis, item. span , expansion) ) ;
1411
+ self . r . define ( parent, ident, ns, self . res ( def_id) , vis, item. span , expansion) ;
1412
1412
} else if !matches ! ( & item. kind, AssocItemKind :: Delegation ( deleg) if deleg. from_glob) {
1413
1413
let impl_def_id = self . r . tcx . local_parent ( local_def_id) ;
1414
1414
let key = BindingKey :: new ( ident. normalize_to_macros_2_0 ( ) , ns) ;
@@ -1493,7 +1493,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1493
1493
let feed = self . r . feed ( variant. id ) ;
1494
1494
let def_id = feed. key ( ) ;
1495
1495
let vis = self . resolve_visibility ( & variant. vis ) ;
1496
- self . r . define ( parent, ident, TypeNS , ( self . res ( def_id) , vis, variant. span , expn_id) ) ;
1496
+ self . r . define ( parent, ident, TypeNS , self . res ( def_id) , vis, variant. span , expn_id) ;
1497
1497
self . r . feed_visibility ( feed, vis) ;
1498
1498
1499
1499
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
@@ -1509,7 +1509,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1509
1509
let feed = self . r . feed ( ctor_node_id) ;
1510
1510
let ctor_def_id = feed. key ( ) ;
1511
1511
let ctor_res = self . res ( ctor_def_id) ;
1512
- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1512
+ self . r . define ( parent, ident, ValueNS , ctor_res, ctor_vis, variant. span , expn_id) ;
1513
1513
self . r . feed_visibility ( feed, ctor_vis) ;
1514
1514
}
1515
1515
0 commit comments