@@ -5,7 +5,7 @@ use rustc_ast::*;
55use rustc_errors:: ErrorGuaranteed ;
66use rustc_hir:: def:: { DefKind , Res } ;
77use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
8- use rustc_hir:: { self as hir, DistributedSlice , HirId , LifetimeSource , PredicateOrigin } ;
8+ use rustc_hir:: { self as hir, DistributedSlice , HirId , InvalidDistributedSliceDeclaration , LifetimeSource , PredicateOrigin } ;
99use rustc_index:: { IndexSlice , IndexVec } ;
1010use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
1111use rustc_span:: edit_distance:: find_best_match_for_name;
@@ -14,6 +14,8 @@ use smallvec::{SmallVec, smallvec};
1414use thin_vec:: ThinVec ;
1515use tracing:: instrument;
1616
17+ use crate :: errors:: DistributedSliceWithInitializer ;
18+
1719use super :: errors:: {
1820 InvalidAbi , InvalidAbiSuggestion , MisplacedRelaxTraitBound , TupleStructWithDefault ,
1921} ;
@@ -154,6 +156,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
154156 ) -> DistributedSlice {
155157 match distributed_slice {
156158 ast:: DistributedSlice :: None => DistributedSlice :: None ,
159+ ast:: DistributedSlice :: Err ( _) => DistributedSlice :: None ,
157160 ast:: DistributedSlice :: Declaration ( span, _) => {
158161 DistributedSlice :: Declaration ( self . lower_span ( * span) )
159162 }
@@ -733,13 +736,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
733736 let ty = self . lower_ty (
734737 ty,
735738 ImplTraitContext :: Disallowed ( ImplTraitPosition :: StaticTy ) ,
736- false ,
739+ matches ! ( distributed_slice , ast :: DistributedSlice :: Err ( _ ) ) ,
737740 ) ;
738741 let safety = self . lower_safety ( * safety, hir:: Safety :: Unsafe ) ;
739742 if define_opaque. is_some ( ) {
740743 self . dcx ( ) . span_err ( i. span , "foreign statics cannot define opaque types" ) ;
741744 }
742- ( ident, hir:: ForeignItemKind :: Static ( ty, * mutability, safety) )
745+ ( ident, hir:: ForeignItemKind :: Static ( ty, * mutability, safety, if let ast:: DistributedSlice :: Err ( eg) = distributed_slice {
746+ InvalidDistributedSliceDeclaration :: Yes ( * eg)
747+ } else {
748+ InvalidDistributedSliceDeclaration :: No
749+ } ) )
743750 }
744751 ForeignItemKind :: TyAlias ( box TyAlias { ident, .. } ) => {
745752 ( ident, hir:: ForeignItemKind :: Type )
@@ -861,6 +868,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
861868 ty,
862869 expr,
863870 define_opaque,
871+ distributed_slice,
864872 ..
865873 } ) => {
866874 let ( generics, kind) = self . lower_generics (
@@ -871,12 +879,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
871879 let ty = this. lower_ty (
872880 ty,
873881 ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
874- false ,
882+ matches ! ( distributed_slice , ast :: DistributedSlice :: Err ( _ ) ) ,
875883 ) ;
876884 let body =
877885 expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) , None ) ) ;
878886
879- hir:: TraitItemKind :: Const ( ty, body)
887+ hir:: TraitItemKind :: Const ( ty, body, if let ast:: DistributedSlice :: Err ( eg) = distributed_slice {
888+ InvalidDistributedSliceDeclaration :: Yes ( * eg)
889+ } else {
890+ InvalidDistributedSliceDeclaration :: No
891+ } )
880892 } ,
881893 ) ;
882894
@@ -1058,6 +1070,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10581070 ty,
10591071 expr,
10601072 define_opaque,
1073+ distributed_slice,
10611074 ..
10621075 } ) => (
10631076 * ident,
@@ -1069,11 +1082,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
10691082 let ty = this. lower_ty (
10701083 ty,
10711084 ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
1072- false ,
1085+ matches ! ( distributed_slice , ast :: DistributedSlice :: Err ( _ ) ) ,
10731086 ) ;
10741087 let body = this. lower_const_body ( i. span , expr. as_deref ( ) , None ) ;
10751088 this. lower_define_opaque ( hir_id, & define_opaque) ;
1076- hir:: ImplItemKind :: Const ( ty, body)
1089+ hir:: ImplItemKind :: Const ( ty, body, if let ast:: DistributedSlice :: Err ( eg) = distributed_slice {
1090+ InvalidDistributedSliceDeclaration :: Yes ( * eg)
1091+ } else {
1092+ InvalidDistributedSliceDeclaration :: No
1093+ } )
10771094 } ,
10781095 ) ,
10791096 ) ,
@@ -1369,7 +1386,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
13691386 span : this. lower_span ( span) ,
13701387 }
13711388 }
1372- ( Some ( expr) , Some ( _) ) => panic ! ( "distributed slice with initializer" ) ,
1389+ ( Some ( _) , Some ( node_id) ) => {
1390+ let eg = this. tcx . dcx ( ) . emit_err ( DistributedSliceWithInitializer {
1391+ span,
1392+ } ) ;
1393+
1394+ let expr_hir_id = this. lower_node_id ( node_id) ;
1395+ hir:: Expr {
1396+ hir_id : expr_hir_id,
1397+ kind : rustc_hir:: ExprKind :: Err ( eg) ,
1398+ span : this. lower_span ( span) ,
1399+ }
1400+ } ,
13731401 ( None , None ) => {
13741402 this. expr_err ( span, this. dcx ( ) . span_delayed_bug ( span, "no block" ) )
13751403 }
0 commit comments