@@ -22,7 +22,6 @@ use super::{
2222 AstOwner , FnDeclKind , ImplTraitContext , ImplTraitPosition , LoweringContext , ParamMode ,
2323 ResolverAstLoweringExt ,
2424} ;
25- use crate :: AllowReturnTypeNotation ;
2625
2726pub ( super ) struct ItemLowerer < ' a , ' hir > {
2827 pub ( super ) tcx : TyCtxt < ' hir > ,
@@ -152,22 +151,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
152151 fn lower_distributed_slice (
153152 & mut self ,
154153 distributed_slice : & ast:: DistributedSlice ,
155- ) -> DistributedSlice < ' hir > {
154+ ) -> DistributedSlice {
156155 match distributed_slice {
157156 ast:: DistributedSlice :: None => DistributedSlice :: None ,
158157 ast:: DistributedSlice :: Declaration ( span) => {
159158 DistributedSlice :: Declaration ( self . lower_span ( * span) )
160159 }
161160 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)
171176 }
172177 }
173178 }
@@ -202,8 +207,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
202207 distributed_slice,
203208 } ) => {
204209 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+ ) ;
207217 self . lower_define_opaque ( hir_id, define_opaque) ;
208218 hir:: ItemKind :: Static (
209219 * m,
@@ -228,7 +238,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
228238 id,
229239 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
230240 |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+ )
232248 } ,
233249 ) ;
234250 self . lower_define_opaque ( hir_id, & define_opaque) ;
@@ -339,6 +355,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
339355 in_assoc_ty : false ,
340356 } ,
341357 } ,
358+ false ,
342359 ) ,
343360 } ,
344361 ) ;
@@ -422,6 +439,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
422439 let lowered_ty = this. lower_ty (
423440 ty,
424441 ImplTraitContext :: Disallowed ( ImplTraitPosition :: ImplSelf ) ,
442+ false ,
425443 ) ;
426444
427445 ( trait_ref, lowered_ty)
@@ -524,8 +542,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
524542 span : Span ,
525543 body : Option < & Expr > ,
526544 impl_trait_position : ImplTraitPosition ,
545+ distributed_slice : & ast:: DistributedSlice ,
527546 ) -> ( & ' 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+ ) ;
529552 ( ty, self . lower_const_body ( span, body) )
530553 }
531554
@@ -700,8 +723,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
700723 define_opaque,
701724 distributed_slice,
702725 } ) => {
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+ ) ;
705731 let safety = self . lower_safety ( * safety, hir:: Safety :: Unsafe ) ;
706732 if define_opaque. is_some ( ) {
707733 self . dcx ( ) . span_err ( i. span , "foreign statics cannot define opaque types" ) ;
@@ -796,7 +822,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
796822 & mut self ,
797823 ( index, f) : ( usize , & FieldDef ) ,
798824 ) -> 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 ) ;
800827 let hir_id = self . lower_node_id ( f. id ) ;
801828 self . lower_attrs ( hir_id, & f. attrs , f. span ) ;
802829 hir:: FieldDef {
@@ -834,8 +861,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
834861 i. id ,
835862 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
836863 |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+ ) ;
839869 let body = expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) ) ) ;
840870
841871 hir:: TraitItemKind :: Const ( ty, body)
@@ -931,6 +961,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
931961 this. lower_ty (
932962 x,
933963 ImplTraitContext :: Disallowed ( ImplTraitPosition :: AssocTy ) ,
964+ false ,
934965 )
935966 } ) ;
936967 hir:: TraitItemKind :: Type (
@@ -1027,8 +1058,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
10271058 i. id ,
10281059 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
10291060 |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+ ) ;
10321066 let body = this. lower_const_body ( i. span , expr. as_deref ( ) ) ;
10331067 this. lower_define_opaque ( hir_id, & define_opaque) ;
10341068 hir:: ImplItemKind :: Const ( ty, body)
@@ -1093,6 +1127,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10931127 in_assoc_ty : true ,
10941128 } ,
10951129 } ,
1130+ false ,
10961131 ) ;
10971132 hir:: ImplItemKind :: Type ( ty)
10981133 }
@@ -1921,8 +1956,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
19211956 } ) => hir:: WherePredicateKind :: BoundPredicate ( hir:: WhereBoundPredicate {
19221957 bound_generic_params : self
19231958 . 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+ ) ,
19261964 bounds : self . lower_param_bounds (
19271965 bounds,
19281966 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Bound ) ,
@@ -1945,10 +1983,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
19451983 }
19461984 WherePredicateKind :: EqPredicate ( WhereEqPredicate { lhs_ty, rhs_ty } ) => {
19471985 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+ ) ,
19521996 } )
19531997 }
19541998 } ) ;
0 commit comments