@@ -5,7 +5,10 @@ use rustc_ast::*;
5
5
use rustc_errors:: ErrorGuaranteed ;
6
6
use rustc_hir:: def:: { DefKind , Res } ;
7
7
use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
8
- use rustc_hir:: { self as hir, DistributedSlice , HirId , LifetimeSource , PredicateOrigin } ;
8
+ use rustc_hir:: {
9
+ self as hir, DistributedSlice , HirId , InvalidDistributedSliceDeclaration , LifetimeSource ,
10
+ PredicateOrigin ,
11
+ } ;
9
12
use rustc_index:: { IndexSlice , IndexVec } ;
10
13
use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
11
14
use rustc_span:: edit_distance:: find_best_match_for_name;
@@ -22,6 +25,7 @@ use super::{
22
25
AstOwner , FnDeclKind , ImplTraitContext , ImplTraitPosition , LoweringContext , ParamMode ,
23
26
ResolverAstLoweringExt ,
24
27
} ;
28
+ use crate :: errors:: DistributedSliceWithInitializer ;
25
29
26
30
pub ( super ) struct ItemLowerer < ' a , ' hir > {
27
31
pub ( super ) tcx : TyCtxt < ' hir > ,
@@ -154,6 +158,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
154
158
) -> DistributedSlice {
155
159
match distributed_slice {
156
160
ast:: DistributedSlice :: None => DistributedSlice :: None ,
161
+ ast:: DistributedSlice :: Err ( _) => DistributedSlice :: None ,
157
162
ast:: DistributedSlice :: Declaration ( span, _) => {
158
163
DistributedSlice :: Declaration ( self . lower_span ( * span) )
159
164
}
@@ -733,13 +738,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
733
738
let ty = self . lower_ty (
734
739
ty,
735
740
ImplTraitContext :: Disallowed ( ImplTraitPosition :: StaticTy ) ,
736
- false ,
741
+ matches ! ( distributed_slice , ast :: DistributedSlice :: Err ( _ ) ) ,
737
742
) ;
738
743
let safety = self . lower_safety ( * safety, hir:: Safety :: Unsafe ) ;
739
744
if define_opaque. is_some ( ) {
740
745
self . dcx ( ) . span_err ( i. span , "foreign statics cannot define opaque types" ) ;
741
746
}
742
- ( ident, hir:: ForeignItemKind :: Static ( ty, * mutability, safety) )
747
+ (
748
+ ident,
749
+ hir:: ForeignItemKind :: Static (
750
+ ty,
751
+ * mutability,
752
+ safety,
753
+ if let ast:: DistributedSlice :: Err ( eg) = distributed_slice {
754
+ InvalidDistributedSliceDeclaration :: Yes ( * eg)
755
+ } else {
756
+ InvalidDistributedSliceDeclaration :: No
757
+ } ,
758
+ ) ,
759
+ )
743
760
}
744
761
ForeignItemKind :: TyAlias ( box TyAlias { ident, .. } ) => {
745
762
( ident, hir:: ForeignItemKind :: Type )
@@ -861,6 +878,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
861
878
ty,
862
879
expr,
863
880
define_opaque,
881
+ distributed_slice,
864
882
..
865
883
} ) => {
866
884
let ( generics, kind) = self . lower_generics (
@@ -871,12 +889,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
871
889
let ty = this. lower_ty (
872
890
ty,
873
891
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
874
- false ,
892
+ matches ! ( distributed_slice , ast :: DistributedSlice :: Err ( _ ) ) ,
875
893
) ;
876
894
let body =
877
895
expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) , None ) ) ;
878
896
879
- hir:: TraitItemKind :: Const ( ty, body)
897
+ hir:: TraitItemKind :: Const (
898
+ ty,
899
+ body,
900
+ if let ast:: DistributedSlice :: Err ( eg) = distributed_slice {
901
+ InvalidDistributedSliceDeclaration :: Yes ( * eg)
902
+ } else {
903
+ InvalidDistributedSliceDeclaration :: No
904
+ } ,
905
+ )
880
906
} ,
881
907
) ;
882
908
@@ -1058,6 +1084,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1058
1084
ty,
1059
1085
expr,
1060
1086
define_opaque,
1087
+ distributed_slice,
1061
1088
..
1062
1089
} ) => (
1063
1090
* ident,
@@ -1069,11 +1096,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
1069
1096
let ty = this. lower_ty (
1070
1097
ty,
1071
1098
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
1072
- false ,
1099
+ matches ! ( distributed_slice , ast :: DistributedSlice :: Err ( _ ) ) ,
1073
1100
) ;
1074
1101
let body = this. lower_const_body ( i. span , expr. as_deref ( ) , None ) ;
1075
1102
this. lower_define_opaque ( hir_id, & define_opaque) ;
1076
- hir:: ImplItemKind :: Const ( ty, body)
1103
+ hir:: ImplItemKind :: Const (
1104
+ ty,
1105
+ body,
1106
+ if let ast:: DistributedSlice :: Err ( eg) = distributed_slice {
1107
+ InvalidDistributedSliceDeclaration :: Yes ( * eg)
1108
+ } else {
1109
+ InvalidDistributedSliceDeclaration :: No
1110
+ } ,
1111
+ )
1077
1112
} ,
1078
1113
) ,
1079
1114
) ,
@@ -1369,7 +1404,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
1369
1404
span : this. lower_span ( span) ,
1370
1405
}
1371
1406
}
1372
- ( Some ( expr) , Some ( _) ) => panic ! ( "distributed slice with initializer" ) ,
1407
+ ( Some ( _) , Some ( node_id) ) => {
1408
+ let eg = this. tcx . dcx ( ) . emit_err ( DistributedSliceWithInitializer { span } ) ;
1409
+
1410
+ let expr_hir_id = this. lower_node_id ( node_id) ;
1411
+ hir:: Expr {
1412
+ hir_id : expr_hir_id,
1413
+ kind : rustc_hir:: ExprKind :: Err ( eg) ,
1414
+ span : this. lower_span ( span) ,
1415
+ }
1416
+ }
1373
1417
( None , None ) => {
1374
1418
this. expr_err ( span, this. dcx ( ) . span_delayed_bug ( span, "no block" ) )
1375
1419
}
0 commit comments