Skip to content

Commit b362939

Browse files
committedJan 27, 2024
Auto merge of #120401 - matthiaskrgr:rollup-7740vrx, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - #103522 (stabilise array methods) - #113489 (impl `From<&[T; N]>` for `Cow<[T]>`) - #119342 (Emit suggestion when trying to write exclusive ranges as `..<`) - #119562 (Rename `pointer` field on `Pin`) - #119800 (Document `rustc_index::vec::IndexVec`) - #120205 (std: make `HEAP` initializer never inline) - #120277 (Normalize field types before checking validity) - #120311 (core: add `From<core::ascii::Char>` implementations) - #120366 (mark a doctest with UB as no_run) - #120378 (always normalize `LoweredTy` in the new solver) - #120382 (Classify closure arguments in refutable pattern in argument error) - #120389 (Add fmease to the compiler review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c073f56 + 6ce96c0 commit b362939

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+324
-106
lines changed
 

‎compiler/rustc_const_eval/src/transform/validate.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -810,13 +810,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
810810
let adt_def = self.tcx.adt_def(def_id);
811811
assert!(adt_def.is_union());
812812
assert_eq!(idx, FIRST_VARIANT);
813-
let dest = adt_def.non_enum_variant().fields[field].ty(self.tcx, args);
814-
if fields.len() != 1 {
813+
let dest_ty = self.tcx.normalize_erasing_regions(
814+
self.param_env,
815+
adt_def.non_enum_variant().fields[field].ty(self.tcx, args),
816+
);
817+
if fields.len() == 1 {
818+
let src_ty = fields.raw[0].ty(self.body, self.tcx);
819+
if !self.mir_assign_valid_types(src_ty, dest_ty) {
820+
self.fail(location, "union field has the wrong type");
821+
}
822+
} else {
815823
self.fail(location, "unions should have one initialized field");
816824
}
817-
if !self.mir_assign_valid_types(fields.raw[0].ty(self.body, self.tcx), dest) {
818-
self.fail(location, "union field has the wrong type");
819-
}
820825
}
821826
AggregateKind::Adt(def_id, idx, args, _, None) => {
822827
let adt_def = self.tcx.adt_def(def_id);
@@ -826,10 +831,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
826831
self.fail(location, "adt has the wrong number of initialized fields");
827832
}
828833
for (src, dest) in std::iter::zip(fields, &variant.fields) {
829-
if !self.mir_assign_valid_types(
830-
src.ty(self.body, self.tcx),
831-
dest.ty(self.tcx, args),
832-
) {
834+
let dest_ty = self
835+
.tcx
836+
.normalize_erasing_regions(self.param_env, dest.ty(self.tcx, args));
837+
if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest_ty) {
833838
self.fail(location, "adt field has the wrong type");
834839
}
835840
}

‎compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ pub struct LoweredTy<'tcx> {
369369

370370
impl<'tcx> LoweredTy<'tcx> {
371371
pub fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
372-
LoweredTy { raw, normalized: fcx.normalize(span, raw) }
372+
// FIXME(-Znext-solver): We're still figuring out how to best handle
373+
// normalization and this doesn't feel too great. We should look at this
374+
// code again before stabilizing it.
375+
let normalized = if fcx.next_trait_solver() {
376+
fcx.try_structurally_resolve_type(span, raw)
377+
} else {
378+
fcx.normalize(span, raw)
379+
};
380+
LoweredTy { raw, normalized }
373381
}
374382
}

0 commit comments

Comments
 (0)
Please sign in to comment.