Skip to content

Commit 6e66f58

Browse files
committed
fmt
1 parent b133d67 commit 6e66f58

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,24 +524,28 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
524524
// These are intrinsics that compile to panics so that we can get a message
525525
// which mentions the offending type, even from a const context.
526526
#[derive(Debug, PartialEq)]
527-
enum PanicIntrinsic { IfUninhabited, IfZeroInvalid, IfAnyInvalid };
527+
enum PanicIntrinsic {
528+
IfUninhabited,
529+
IfZeroInvalid,
530+
IfAnyInvalid,
531+
};
528532
let panic_intrinsic = intrinsic.and_then(|i| match i {
529533
// FIXME: Move to symbols instead of strings.
530534
"panic_if_uninhabited" => Some(PanicIntrinsic::IfUninhabited),
531535
"panic_if_zero_invalid" => Some(PanicIntrinsic::IfZeroInvalid),
532536
"panic_if_any_invalid" => Some(PanicIntrinsic::IfAnyInvalid),
533-
_ => None
537+
_ => None,
534538
});
535539
if let Some(intrinsic) = panic_intrinsic {
536540
use PanicIntrinsic::*;
537541
let ty = instance.unwrap().substs.type_at(0);
538542
let layout = bx.layout_of(ty);
539543
let do_panic = match intrinsic {
540544
IfUninhabited => layout.abi.is_uninhabited(),
541-
IfZeroInvalid => // We unwrap as the error type is `!`.
542-
!layout.might_permit_raw_init(&bx, /*zero:*/ true).unwrap(),
543-
IfAnyInvalid => // We unwrap as the error type is `!`.
544-
!layout.might_permit_raw_init(&bx, /*zero:*/ false).unwrap(),
545+
// We unwrap as the error type is `!`.
546+
IfZeroInvalid => !layout.might_permit_raw_init(&bx, /*zero:*/ true).unwrap(),
547+
// We unwrap as the error type is `!`.
548+
IfAnyInvalid => !layout.might_permit_raw_init(&bx, /*zero:*/ false).unwrap(),
545549
};
546550
if do_panic {
547551
let msg_str = if layout.abi.is_uninhabited() {

src/librustc_target/abi/mod.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,22 +1047,17 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10471047
/// FIXME: Once we removed all the conservatism, we could alternatively
10481048
/// create an all-0/all-undef constant and run the vonst value validator to see if
10491049
/// this is a valid value for the given type.
1050-
pub fn might_permit_raw_init<C, E>(
1051-
self,
1052-
cx: &C,
1053-
zero: bool,
1054-
) -> Result<bool, E>
1050+
pub fn might_permit_raw_init<C, E>(self, cx: &C, zero: bool) -> Result<bool, E>
10551051
where
10561052
Self: Copy,
10571053
Ty: TyLayoutMethods<'a, C>,
1058-
C: LayoutOf<Ty = Ty, TyLayout: MaybeResult<Self, Error = E>> + HasDataLayout
1054+
C: LayoutOf<Ty = Ty, TyLayout: MaybeResult<Self, Error = E>> + HasDataLayout,
10591055
{
10601056
let scalar_allows_raw_init = move |s: &Scalar| -> bool {
10611057
if zero {
10621058
let range = &s.valid_range;
10631059
// The range must contain 0.
1064-
range.contains(&0) ||
1065-
(*range.start() > *range.end()) // wrap-around allows 0
1060+
range.contains(&0) || (*range.start() > *range.end()) // wrap-around allows 0
10661061
} else {
10671062
// The range must include all values. `valid_range_exclusive` handles
10681063
// the wrap-around using target arithmetic; with wrap-around then the full
@@ -1076,13 +1071,11 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10761071
let res = match &self.abi {
10771072
Abi::Uninhabited => false, // definitely UB
10781073
Abi::Scalar(s) => scalar_allows_raw_init(s),
1079-
Abi::ScalarPair(s1, s2) =>
1080-
scalar_allows_raw_init(s1) && scalar_allows_raw_init(s2),
1081-
Abi::Vector { element: s, count } =>
1082-
*count == 0 || scalar_allows_raw_init(s),
1074+
Abi::ScalarPair(s1, s2) => scalar_allows_raw_init(s1) && scalar_allows_raw_init(s2),
1075+
Abi::Vector { element: s, count } => *count == 0 || scalar_allows_raw_init(s),
10831076
Abi::Aggregate { .. } => {
10841077
match self.variants {
1085-
Variants::Multiple { .. } =>
1078+
Variants::Multiple { .. } => {
10861079
if zero {
10871080
// FIXME(#66151):
10881081
// could we identify the variant with discriminant 0, check that?
@@ -1091,17 +1084,20 @@ impl<'a, Ty> TyLayout<'a, Ty> {
10911084
// FIXME(#66151): This needs to have some sort of discriminant,
10921085
// which cannot be undef. But for now we are conservative.
10931086
true
1094-
},
1087+
}
1088+
}
10951089
Variants::Single { .. } => {
10961090
// For aggregates, recurse.
10971091
match self.fields {
10981092
FieldPlacement::Union(..) => true, // An all-0 unit is fine.
10991093
FieldPlacement::Array { .. } =>
1100-
// FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
1101-
// with any element type, so let us not (yet) complain about that.
1102-
/* count == 0 ||
1103-
self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
1104-
true,
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+
}
11051101
FieldPlacement::Arbitrary { .. } => {
11061102
// FIXME(#66151) cargo depends on sized-chunks 0.3.0 which
11071103
// has some illegal zero-initialization, so let us not (yet)

src/librustc_typeck/check/intrinsic.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
147147
),
148148
"rustc_peek" => (1, vec![param(0)], param(0)),
149149
"caller_location" => (0, vec![], tcx.caller_location_ty()),
150-
"panic_if_uninhabited" |
151-
"panic_if_zero_invalid" |
152-
"panic_if_any_invalid" =>
153-
(1, Vec::new(), tcx.mk_unit()),
150+
"panic_if_uninhabited" | "panic_if_zero_invalid" | "panic_if_any_invalid" => {
151+
(1, Vec::new(), tcx.mk_unit())
152+
}
154153
"init" => (1, Vec::new(), param(0)),
155154
"uninit" => (1, Vec::new(), param(0)),
156155
"forget" => (1, vec![param(0)], tcx.mk_unit()),

0 commit comments

Comments
 (0)