@@ -1045,7 +1045,7 @@ impl<'a, Ty> TyLayout<'a, Ty> {
1045
1045
/// This is conservative: in doubt, it will answer `true`.
1046
1046
///
1047
1047
/// FIXME: Once we removed all the conservatism, we could alternatively
1048
- /// create an all-0/all-undef constant and run the vonst value validator to see if
1048
+ /// create an all-0/all-undef constant and run the const value validator to see if
1049
1049
/// this is a valid value for the given type.
1050
1050
pub fn might_permit_raw_init < C , E > ( self , cx : & C , zero : bool ) -> Result < bool , E >
1051
1051
where
@@ -1067,59 +1067,22 @@ impl<'a, Ty> TyLayout<'a, Ty> {
1067
1067
}
1068
1068
} ;
1069
1069
1070
- // Abi is the most informative here .
1071
- let res = match & self . abi {
1070
+ // Check the ABI .
1071
+ let valid = match & self . abi {
1072
1072
Abi :: Uninhabited => false , // definitely UB
1073
1073
Abi :: Scalar ( s) => scalar_allows_raw_init ( s) ,
1074
1074
Abi :: ScalarPair ( s1, s2) => scalar_allows_raw_init ( s1) && scalar_allows_raw_init ( s2) ,
1075
1075
Abi :: Vector { element : s, count } => * count == 0 || scalar_allows_raw_init ( s) ,
1076
- Abi :: Aggregate { .. } => {
1077
- match self . variants {
1078
- Variants :: Multiple { .. } => {
1079
- if zero {
1080
- // FIXME(#66151):
1081
- // could we identify the variant with discriminant 0, check that?
1082
- true
1083
- } else {
1084
- // FIXME(#66151): This needs to have some sort of discriminant,
1085
- // which cannot be undef. But for now we are conservative.
1086
- true
1087
- }
1088
- }
1089
- Variants :: Single { .. } => {
1090
- // For aggregates, recurse.
1091
- match self . fields {
1092
- FieldPlacement :: Union ( ..) => true , // An all-0 unit is fine.
1093
- FieldPlacement :: Array { .. } =>
1094
- // FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
1095
- // with any element type, so let us not (yet) complain about that.
1096
- /* count == 0 ||
1097
- self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
1098
- {
1099
- true
1100
- }
1101
- FieldPlacement :: Arbitrary { .. } => {
1102
- // FIXME(#66151) cargo depends on sized-chunks 0.3.0 which
1103
- // has some illegal zero-initialization, so let us not (yet)
1104
- // complain about aggregates either.
1105
- /* let mut res = true;
1106
- // Check that all fields accept zero-init.
1107
- for idx in 0..offsets.len() {
1108
- let field = self.field(cx, idx).to_result()?;
1109
- if !field.might_permit_raw_init(cx, zero)? {
1110
- res = false;
1111
- break;
1112
- }
1113
- }
1114
- res */
1115
- true
1116
- }
1117
- }
1118
- }
1119
- }
1120
- }
1076
+ Abi :: Aggregate { .. } => true , // Cannot be excluded *right now*.
1121
1077
} ;
1122
- trace ! ( "might_permit_raw_init({:?}, zero={}) = {}" , self . details, zero, res) ;
1123
- Ok ( res)
1078
+ if !valid {
1079
+ // This is definitely not okay.
1080
+ trace ! ( "might_permit_raw_init({:?}, zero={}): not valid" , self . details, zero) ;
1081
+ return Ok ( false ) ;
1082
+ }
1083
+
1084
+ // If we have not found an error yet, we need to recursively descend.
1085
+ // FIXME(#66151): For now, we are conservative and do not do this.
1086
+ Ok ( true )
1124
1087
}
1125
1088
}
0 commit comments