@@ -18,6 +18,30 @@ impl Boundness {
18
18
}
19
19
}
20
20
21
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
22
+ pub ( crate ) enum ReExport {
23
+ Implicit ,
24
+ Explicit ,
25
+ None ,
26
+ }
27
+
28
+ impl ReExport {
29
+ pub ( crate ) const fn is_implicit ( self ) -> bool {
30
+ matches ! ( self , ReExport :: Implicit )
31
+ }
32
+
33
+ pub ( crate ) fn or ( self , other : ReExport ) -> ReExport {
34
+ match ( self , other) {
35
+ ( ReExport :: Implicit , ReExport :: Explicit ) | ( ReExport :: Explicit , ReExport :: Implicit ) => {
36
+ ReExport :: Explicit
37
+ }
38
+ ( ReExport :: Implicit , ReExport :: Implicit ) => ReExport :: Implicit ,
39
+ ( ReExport :: Explicit , ReExport :: Explicit ) => ReExport :: Explicit ,
40
+ ( non_none, ReExport :: None ) | ( ReExport :: None , non_none) => non_none,
41
+ }
42
+ }
43
+ }
44
+
21
45
/// The result of a symbol lookup, which can either be a (possibly unbound) type
22
46
/// or a completely unbound symbol.
23
47
///
@@ -37,7 +61,7 @@ impl Boundness {
37
61
/// ```
38
62
#[ derive( Debug , Clone , PartialEq , Eq ) ]
39
63
pub ( crate ) enum Symbol < ' db > {
40
- Type ( Type < ' db > , Boundness ) ,
64
+ Type ( Type < ' db > , ReExport , Boundness ) ,
41
65
Unbound ,
42
66
}
43
67
@@ -48,8 +72,8 @@ impl<'db> Symbol<'db> {
48
72
49
73
pub ( crate ) fn possibly_unbound ( & self ) -> bool {
50
74
match self {
51
- Symbol :: Type ( _, Boundness :: PossiblyUnbound ) | Symbol :: Unbound => true ,
52
- Symbol :: Type ( _, Boundness :: Bound ) => false ,
75
+ Symbol :: Type ( _, _ , Boundness :: PossiblyUnbound ) | Symbol :: Unbound => true ,
76
+ Symbol :: Type ( _, _ , Boundness :: Bound ) => false ,
53
77
}
54
78
}
55
79
@@ -59,7 +83,7 @@ impl<'db> Symbol<'db> {
59
83
/// if there is at least one control-flow path where the symbol is bound, return the type.
60
84
pub ( crate ) fn ignore_possibly_unbound ( & self ) -> Option < Type < ' db > > {
61
85
match self {
62
- Symbol :: Type ( ty, _) => Some ( * ty) ,
86
+ Symbol :: Type ( ty, _, _ ) => Some ( * ty) ,
63
87
Symbol :: Unbound => None ,
64
88
}
65
89
}
@@ -74,12 +98,15 @@ impl<'db> Symbol<'db> {
74
98
#[ must_use]
75
99
pub ( crate ) fn or_fall_back_to ( self , db : & ' db dyn Db , fallback : & Symbol < ' db > ) -> Symbol < ' db > {
76
100
match fallback {
77
- Symbol :: Type ( fallback_ty, fallback_boundness) => match self {
78
- Symbol :: Type ( _, Boundness :: Bound ) => self ,
79
- Symbol :: Type ( ty, boundness @ Boundness :: PossiblyUnbound ) => Symbol :: Type (
80
- UnionType :: from_elements ( db, [ * fallback_ty, ty] ) ,
81
- fallback_boundness. or ( boundness) ,
82
- ) ,
101
+ Symbol :: Type ( fallback_ty, fallback_re_export, fallback_boundness) => match self {
102
+ Symbol :: Type ( _, _, Boundness :: Bound ) => self ,
103
+ Symbol :: Type ( ty, re_export, boundness @ Boundness :: PossiblyUnbound ) => {
104
+ Symbol :: Type (
105
+ UnionType :: from_elements ( db, [ * fallback_ty, ty] ) ,
106
+ fallback_re_export. or ( re_export) ,
107
+ fallback_boundness. or ( boundness) ,
108
+ )
109
+ }
83
110
Symbol :: Unbound => fallback. clone ( ) ,
84
111
} ,
85
112
Symbol :: Unbound => self ,
@@ -89,7 +116,7 @@ impl<'db> Symbol<'db> {
89
116
#[ must_use]
90
117
pub ( crate ) fn map_type ( self , f : impl FnOnce ( Type < ' db > ) -> Type < ' db > ) -> Symbol < ' db > {
91
118
match self {
92
- Symbol :: Type ( ty, boundness) => Symbol :: Type ( f ( ty) , boundness) ,
119
+ Symbol :: Type ( ty, re_export , boundness) => Symbol :: Type ( f ( ty) , re_export , boundness) ,
93
120
Symbol :: Unbound => Symbol :: Unbound ,
94
121
}
95
122
}
@@ -114,41 +141,54 @@ mod tests {
114
141
Symbol :: Unbound
115
142
) ;
116
143
assert_eq ! (
117
- Symbol :: Unbound . or_fall_back_to( & db, & Symbol :: Type ( ty1, PossiblyUnbound ) ) ,
118
- Symbol :: Type ( ty1, PossiblyUnbound )
144
+ Symbol :: Unbound
145
+ . or_fall_back_to( & db, & Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound ) ) ,
146
+ Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
119
147
) ;
120
148
assert_eq ! (
121
- Symbol :: Unbound . or_fall_back_to( & db, & Symbol :: Type ( ty1, Bound ) ) ,
122
- Symbol :: Type ( ty1, Bound )
149
+ Symbol :: Unbound . or_fall_back_to( & db, & Symbol :: Type ( ty1, ReExport :: None , Bound ) ) ,
150
+ Symbol :: Type ( ty1, ReExport :: None , Bound )
123
151
) ;
124
152
125
153
// Start from a possibly unbound symbol
126
154
assert_eq ! (
127
- Symbol :: Type ( ty1, PossiblyUnbound ) . or_fall_back_to( & db, & Symbol :: Unbound ) ,
128
- Symbol :: Type ( ty1, PossiblyUnbound )
155
+ Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
156
+ . or_fall_back_to( & db, & Symbol :: Unbound ) ,
157
+ Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
129
158
) ;
130
159
assert_eq ! (
131
- Symbol :: Type ( ty1, PossiblyUnbound )
132
- . or_fall_back_to( & db, & Symbol :: Type ( ty2, PossiblyUnbound ) ) ,
133
- Symbol :: Type ( UnionType :: from_elements( & db, [ ty2, ty1] ) , PossiblyUnbound )
160
+ Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
161
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , PossiblyUnbound ) ) ,
162
+ Symbol :: Type (
163
+ UnionType :: from_elements( & db, [ ty2, ty1] ) ,
164
+ ReExport :: None ,
165
+ PossiblyUnbound
166
+ )
134
167
) ;
135
168
assert_eq ! (
136
- Symbol :: Type ( ty1, PossiblyUnbound ) . or_fall_back_to( & db, & Symbol :: Type ( ty2, Bound ) ) ,
137
- Symbol :: Type ( UnionType :: from_elements( & db, [ ty2, ty1] ) , Bound )
169
+ Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
170
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , Bound ) ) ,
171
+ Symbol :: Type (
172
+ UnionType :: from_elements( & db, [ ty2, ty1] ) ,
173
+ ReExport :: None ,
174
+ Bound
175
+ )
138
176
) ;
139
177
140
178
// Start from a definitely bound symbol
141
179
assert_eq ! (
142
- Symbol :: Type ( ty1, Bound ) . or_fall_back_to( & db, & Symbol :: Unbound ) ,
143
- Symbol :: Type ( ty1, Bound )
180
+ Symbol :: Type ( ty1, ReExport :: None , Bound ) . or_fall_back_to( & db, & Symbol :: Unbound ) ,
181
+ Symbol :: Type ( ty1, ReExport :: None , Bound )
144
182
) ;
145
183
assert_eq ! (
146
- Symbol :: Type ( ty1, Bound ) . or_fall_back_to( & db, & Symbol :: Type ( ty2, PossiblyUnbound ) ) ,
147
- Symbol :: Type ( ty1, Bound )
184
+ Symbol :: Type ( ty1, ReExport :: None , Bound )
185
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , PossiblyUnbound ) ) ,
186
+ Symbol :: Type ( ty1, ReExport :: None , Bound )
148
187
) ;
149
188
assert_eq ! (
150
- Symbol :: Type ( ty1, Bound ) . or_fall_back_to( & db, & Symbol :: Type ( ty2, Bound ) ) ,
151
- Symbol :: Type ( ty1, Bound )
189
+ Symbol :: Type ( ty1, ReExport :: None , Bound )
190
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , Bound ) ) ,
191
+ Symbol :: Type ( ty1, ReExport :: None , Bound )
152
192
) ;
153
193
}
154
194
}
0 commit comments