@@ -9,7 +9,7 @@ use crate::def_collector::collect_definitions;
9
9
use crate :: imports:: { ImportData , ImportKind } ;
10
10
use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
11
11
use crate :: Namespace :: { self , MacroNS , TypeNS , ValueNS } ;
12
- use crate :: { errors, BindingKey , MacroData , NameBindingData } ;
12
+ use crate :: { errors, AmbiguityKind , BindingKey , MacroData , NameBindingData } ;
13
13
use crate :: { Determinacy , ExternPreludeEntry , Finalize , Module , ModuleKind , ModuleOrUniformRoot } ;
14
14
use crate :: { NameBinding , NameBindingKind , ParentScope , PathResult , PerNS , ResolutionError } ;
15
15
use crate :: { Resolver , ResolverArenas , Segment , ToNameBinding , VisResolutionError } ;
@@ -62,6 +62,46 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span,
62
62
}
63
63
}
64
64
65
+ impl < ' a , Id : Into < DefId > > ToNameBinding < ' a >
66
+ for ( Module < ' a > , ty:: Visibility < Id > , Span , LocalExpnId , bool )
67
+ {
68
+ fn to_name_binding ( self , arenas : & ' a ResolverArenas < ' a > ) -> NameBinding < ' a > {
69
+ let mut binding = NameBindingData {
70
+ kind : NameBindingKind :: Module ( self . 0 ) ,
71
+ ambiguity : None ,
72
+ warn_ambiguity : false ,
73
+ vis : self . 1 . to_def_id ( ) ,
74
+ span : self . 2 ,
75
+ expansion : self . 3 ,
76
+ } ;
77
+ if self . 4 {
78
+ binding. ambiguity =
79
+ Some ( ( arenas. alloc_name_binding ( binding. clone ( ) ) , AmbiguityKind :: ExternalCrate ) ) ;
80
+ binding. warn_ambiguity = true ;
81
+ }
82
+ arenas. alloc_name_binding ( binding)
83
+ }
84
+ }
85
+
86
+ impl < ' a , Id : Into < DefId > > ToNameBinding < ' a > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId , bool ) {
87
+ fn to_name_binding ( self , arenas : & ' a ResolverArenas < ' a > ) -> NameBinding < ' a > {
88
+ let mut binding = NameBindingData {
89
+ kind : NameBindingKind :: Res ( self . 0 ) ,
90
+ ambiguity : None ,
91
+ warn_ambiguity : false ,
92
+ vis : self . 1 . to_def_id ( ) ,
93
+ span : self . 2 ,
94
+ expansion : self . 3 ,
95
+ } ;
96
+ if self . 4 {
97
+ binding. ambiguity =
98
+ Some ( ( arenas. alloc_name_binding ( binding. clone ( ) ) , AmbiguityKind :: ExternalCrate ) ) ;
99
+ binding. warn_ambiguity = true ;
100
+ }
101
+ arenas. alloc_name_binding ( binding)
102
+ }
103
+ }
104
+
65
105
impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
66
106
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
67
107
/// otherwise, reports an error.
@@ -71,7 +111,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
71
111
{
72
112
let binding = def. to_name_binding ( self . arenas ) ;
73
113
let key = self . new_disambiguated_key ( ident, ns) ;
74
- if let Err ( old_binding) = self . try_define ( parent, key, binding, false ) {
114
+ if let Err ( old_binding) = self . try_define ( parent, key, binding, binding . warn_ambiguity ) {
75
115
self . report_conflict ( parent, ident, ns, old_binding, binding) ;
76
116
}
77
117
}
@@ -932,7 +972,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
932
972
/// Builds the reduced graph for a single item in an external crate.
933
973
fn build_reduced_graph_for_external_crate_res ( & mut self , child : & ModChild ) {
934
974
let parent = self . parent_scope . module ;
935
- let ModChild { ident, res, vis, ref reexport_chain } = * child;
975
+ let ModChild { ident, res, vis, ref reexport_chain, ambiguity } = * child;
936
976
let span = self . r . def_span (
937
977
reexport_chain
938
978
. first ( )
@@ -945,7 +985,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
945
985
match res {
946
986
Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
947
987
let module = self . r . expect_module ( def_id) ;
948
- self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
988
+ self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion, ambiguity ) ) ;
949
989
}
950
990
Res :: Def (
951
991
DefKind :: Struct
@@ -959,7 +999,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
959
999
_,
960
1000
)
961
1001
| Res :: PrimTy ( ..)
962
- | Res :: ToolMod => self . r . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
1002
+ | Res :: ToolMod => {
1003
+ self . r . define ( parent, ident, TypeNS , ( res, vis, span, expansion, ambiguity) )
1004
+ }
963
1005
Res :: Def (
964
1006
DefKind :: Fn
965
1007
| DefKind :: AssocFn
@@ -968,9 +1010,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
968
1010
| DefKind :: AssocConst
969
1011
| DefKind :: Ctor ( ..) ,
970
1012
_,
971
- ) => self . r . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
1013
+ ) => self . r . define ( parent, ident, ValueNS , ( res, vis, span, expansion, ambiguity ) ) ,
972
1014
Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
973
- self . r . define ( parent, ident, MacroNS , ( res, vis, span, expansion) )
1015
+ self . r . define ( parent, ident, MacroNS , ( res, vis, span, expansion, ambiguity ) )
974
1016
}
975
1017
Res :: Def (
976
1018
DefKind :: TyParam
0 commit comments