@@ -22,7 +22,6 @@ use super::{
22
22
AstOwner , FnDeclKind , ImplTraitContext , ImplTraitPosition , LoweringContext , ParamMode ,
23
23
ResolverAstLoweringExt ,
24
24
} ;
25
- use crate :: AllowReturnTypeNotation ;
26
25
27
26
pub ( super ) struct ItemLowerer < ' a , ' hir > {
28
27
pub ( super ) tcx : TyCtxt < ' hir > ,
@@ -152,22 +151,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
152
151
fn lower_distributed_slice (
153
152
& mut self ,
154
153
distributed_slice : & ast:: DistributedSlice ,
155
- ) -> DistributedSlice < ' hir > {
154
+ ) -> DistributedSlice {
156
155
match distributed_slice {
157
156
ast:: DistributedSlice :: None => DistributedSlice :: None ,
158
157
ast:: DistributedSlice :: Declaration ( span) => {
159
158
DistributedSlice :: Declaration ( self . lower_span ( * span) )
160
159
}
161
160
ast:: DistributedSlice :: Addition { declaration, id } => {
162
- DistributedSlice :: Addition ( self . lower_qpath (
163
- * id,
164
- & None ,
165
- declaration,
166
- ParamMode :: Optional ,
167
- AllowReturnTypeNotation :: No ,
168
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
169
- None ,
170
- ) )
161
+ let Some ( res) = self . resolver . get_partial_res ( * id) else {
162
+ self . dcx ( ) . span_delayed_bug ( declaration. span , "should have errored in resolve" ) ;
163
+ return DistributedSlice :: None ;
164
+ } ;
165
+
166
+ let Some ( did) = res. expect_full_res ( ) . opt_def_id ( ) else {
167
+ self . dcx ( ) . span_delayed_bug ( declaration. span , "should have errored in resolve" ) ;
168
+ return DistributedSlice :: None ;
169
+ } ;
170
+
171
+ let Some ( local) = did. as_local ( ) else {
172
+ panic ! ( "adding to slice outside local crate" ) ;
173
+ } ;
174
+
175
+ DistributedSlice :: Addition ( local)
171
176
}
172
177
}
173
178
}
@@ -202,8 +207,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
202
207
distributed_slice,
203
208
} ) => {
204
209
let ident = self . lower_ident ( * ident) ;
205
- let ( ty, body_id) =
206
- self . lower_const_item ( t, span, e. as_deref ( ) , ImplTraitPosition :: StaticTy ) ;
210
+ let ( ty, body_id) = self . lower_const_item (
211
+ t,
212
+ span,
213
+ e. as_deref ( ) ,
214
+ ImplTraitPosition :: StaticTy ,
215
+ distributed_slice,
216
+ ) ;
207
217
self . lower_define_opaque ( hir_id, define_opaque) ;
208
218
hir:: ItemKind :: Static (
209
219
ident,
@@ -228,7 +238,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
228
238
id,
229
239
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
230
240
|this| {
231
- this. lower_const_item ( ty, span, expr. as_deref ( ) , ImplTraitPosition :: ConstTy )
241
+ this. lower_const_item (
242
+ ty,
243
+ span,
244
+ expr. as_deref ( ) ,
245
+ ImplTraitPosition :: ConstTy ,
246
+ distributed_slice,
247
+ )
232
248
} ,
233
249
) ;
234
250
self . lower_define_opaque ( hir_id, & define_opaque) ;
@@ -339,6 +355,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
339
355
in_assoc_ty : false ,
340
356
} ,
341
357
} ,
358
+ false ,
342
359
) ,
343
360
} ,
344
361
) ;
@@ -422,6 +439,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
422
439
let lowered_ty = this. lower_ty (
423
440
ty,
424
441
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ImplSelf ) ,
442
+ false ,
425
443
) ;
426
444
427
445
( trait_ref, lowered_ty)
@@ -524,8 +542,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
524
542
span : Span ,
525
543
body : Option < & Expr > ,
526
544
impl_trait_position : ImplTraitPosition ,
545
+ distributed_slice : & ast:: DistributedSlice ,
527
546
) -> ( & ' hir hir:: Ty < ' hir > , hir:: BodyId ) {
528
- let ty = self . lower_ty ( ty, ImplTraitContext :: Disallowed ( impl_trait_position) ) ;
547
+ let ty = self . lower_ty (
548
+ ty,
549
+ ImplTraitContext :: Disallowed ( impl_trait_position) ,
550
+ matches ! ( distributed_slice, ast:: DistributedSlice :: Declaration ( ..) ) ,
551
+ ) ;
529
552
( ty, self . lower_const_body ( span, body) )
530
553
}
531
554
@@ -700,8 +723,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
700
723
define_opaque,
701
724
distributed_slice,
702
725
} ) => {
703
- let ty =
704
- self . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: StaticTy ) ) ;
726
+ let ty = self . lower_ty (
727
+ ty,
728
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: StaticTy ) ,
729
+ false ,
730
+ ) ;
705
731
let safety = self . lower_safety ( * safety, hir:: Safety :: Unsafe ) ;
706
732
if define_opaque. is_some ( ) {
707
733
self . dcx ( ) . span_err ( i. span , "foreign statics cannot define opaque types" ) ;
@@ -796,7 +822,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
796
822
& mut self ,
797
823
( index, f) : ( usize , & FieldDef ) ,
798
824
) -> hir:: FieldDef < ' hir > {
799
- let ty = self . lower_ty ( & f. ty , ImplTraitContext :: Disallowed ( ImplTraitPosition :: FieldTy ) ) ;
825
+ let ty =
826
+ self . lower_ty ( & f. ty , ImplTraitContext :: Disallowed ( ImplTraitPosition :: FieldTy ) , false ) ;
800
827
let hir_id = self . lower_node_id ( f. id ) ;
801
828
self . lower_attrs ( hir_id, & f. attrs , f. span ) ;
802
829
hir:: FieldDef {
@@ -834,8 +861,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
834
861
i. id ,
835
862
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
836
863
|this| {
837
- let ty = this
838
- . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
864
+ let ty = this. lower_ty (
865
+ ty,
866
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
867
+ false ,
868
+ ) ;
839
869
let body = expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) ) ) ;
840
870
841
871
hir:: TraitItemKind :: Const ( ty, body)
@@ -931,6 +961,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
931
961
this. lower_ty (
932
962
x,
933
963
ImplTraitContext :: Disallowed ( ImplTraitPosition :: AssocTy ) ,
964
+ false ,
934
965
)
935
966
} ) ;
936
967
hir:: TraitItemKind :: Type (
@@ -1027,8 +1058,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
1027
1058
i. id ,
1028
1059
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
1029
1060
|this| {
1030
- let ty = this
1031
- . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
1061
+ let ty = this. lower_ty (
1062
+ ty,
1063
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
1064
+ false ,
1065
+ ) ;
1032
1066
let body = this. lower_const_body ( i. span , expr. as_deref ( ) ) ;
1033
1067
this. lower_define_opaque ( hir_id, & define_opaque) ;
1034
1068
hir:: ImplItemKind :: Const ( ty, body)
@@ -1093,6 +1127,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1093
1127
in_assoc_ty : true ,
1094
1128
} ,
1095
1129
} ,
1130
+ false ,
1096
1131
) ;
1097
1132
hir:: ImplItemKind :: Type ( ty)
1098
1133
}
@@ -1921,8 +1956,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
1921
1956
} ) => hir:: WherePredicateKind :: BoundPredicate ( hir:: WhereBoundPredicate {
1922
1957
bound_generic_params : self
1923
1958
. lower_generic_params ( bound_generic_params, hir:: GenericParamSource :: Binder ) ,
1924
- bounded_ty : self
1925
- . lower_ty ( bounded_ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ) ,
1959
+ bounded_ty : self . lower_ty (
1960
+ bounded_ty,
1961
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
1962
+ false ,
1963
+ ) ,
1926
1964
bounds : self . lower_param_bounds (
1927
1965
bounds,
1928
1966
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
@@ -1945,10 +1983,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
1945
1983
}
1946
1984
WherePredicateKind :: EqPredicate ( WhereEqPredicate { lhs_ty, rhs_ty } ) => {
1947
1985
hir:: WherePredicateKind :: EqPredicate ( hir:: WhereEqPredicate {
1948
- lhs_ty : self
1949
- . lower_ty ( lhs_ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ) ,
1950
- rhs_ty : self
1951
- . lower_ty ( rhs_ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ) ,
1986
+ lhs_ty : self . lower_ty (
1987
+ lhs_ty,
1988
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
1989
+ false ,
1990
+ ) ,
1991
+ rhs_ty : self . lower_ty (
1992
+ rhs_ty,
1993
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
1994
+ false ,
1995
+ ) ,
1952
1996
} )
1953
1997
}
1954
1998
} ) ;
0 commit comments