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