Skip to content

Commit 57b3e84

Browse files
khyperialcnr
authored andcommitted
Unnormalized migration: struct_tail takes fn taking Unnormalized
1 parent 869c941 commit 57b3e84

16 files changed

Lines changed: 50 additions & 62 deletions

File tree

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
183183
);
184184
}
185185

186-
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
186+
pub(super) fn normalize<T>(
187+
&mut self,
188+
value: Unnormalized<'tcx, T>,
189+
location: impl NormalizeLocation,
190+
) -> T
187191
where
188192
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
189193
{
190-
self.normalize_with_category(
191-
Unnormalized::new_wip(value),
192-
location,
193-
ConstraintCategory::Boring,
194-
)
194+
self.normalize_with_category(value, location, ConstraintCategory::Boring)
195195
}
196196

197197
pub(super) fn deeply_normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
@@ -242,7 +242,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
242242

243243
let mut normalize = |ty| self.normalize(ty, location);
244244
let tail = tcx.struct_tail_raw(ty, &cause, &mut normalize, || {});
245-
normalize(tail)
245+
normalize(Unnormalized::new_wip(tail))
246246
}
247247

248248
#[instrument(skip(self), level = "debug")]
@@ -287,7 +287,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
287287
// hack in `equate_inputs_and_outputs` which does have associated test cases.
288288
let mir_ty = match self.infcx.next_trait_solver() {
289289
true => mir_ty,
290-
false => self.normalize(mir_ty, Locations::All(span)),
290+
false => self.normalize(Unnormalized::new_wip(mir_ty), Locations::All(span)),
291291
};
292292

293293
let cause = ObligationCause::dummy_with_span(span);

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
235235
if let Err(_) =
236236
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
237237
{
238-
let b = self.normalize(b, Locations::All(span));
238+
let b = self.normalize(ty::Unnormalized::new(b), Locations::All(span));
239239
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
240240
.unwrap_or_else(|terr| {
241241
span_mirbug!(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
480480
let projected_ty = curr_projected_ty.projection_ty_core(
481481
tcx,
482482
proj,
483-
|ty| self.normalize(ty, locations),
483+
|ty| self.normalize(ty::Unnormalized::new_wip(ty), locations),
484484
|ty, variant_index, field, ()| PlaceTy::field_ty(tcx, ty, variant_index, field),
485485
|_| unreachable!(),
486486
);
@@ -490,8 +490,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
490490

491491
// Need to renormalize `a` as typecheck may have failed to normalize
492492
// higher-ranked aliases if normalization was ambiguous due to inference.
493-
let a = self.normalize(a, locations);
494-
let ty = self.normalize(curr_projected_ty.ty, locations);
493+
let a = self.normalize(ty::Unnormalized::new_wip(a), locations);
494+
let ty = self.normalize(ty::Unnormalized::new_wip(curr_projected_ty.ty), locations);
495495
self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
496496

497497
Ok(())
@@ -639,11 +639,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
639639

640640
let place_ty = place.ty(self.body, tcx).ty;
641641
debug!(?place_ty);
642-
let place_ty = self.normalize(place_ty, location);
642+
let place_ty = self.normalize(ty::Unnormalized::new_wip(place_ty), location);
643643
debug!("place_ty normalized: {:?}", place_ty);
644644
let rv_ty = rv.ty(self.body, tcx);
645645
debug!(?rv_ty);
646-
let rv_ty = self.normalize(rv_ty, location);
646+
let rv_ty = self.normalize(ty::Unnormalized::new_wip(rv_ty), location);
647647
debug!("normalized rv_ty: {:?}", rv_ty);
648648
if let Err(terr) =
649649
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
@@ -1082,7 +1082,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10821082
},
10831083
);
10841084

1085-
let src_ty = self.normalize(src_ty, location);
1085+
let src_ty =
1086+
self.normalize(ty::Unnormalized::new_wip(src_ty), location);
10861087
if let Err(terr) = self.sub_types(
10871088
src_ty,
10881089
*ty,
@@ -1124,7 +1125,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
11241125
// function definition. When we extract the
11251126
// signature, it comes from the `fn_sig` query,
11261127
// and hence may contain unnormalized results.
1127-
let src_ty = self.normalize(src_ty, location);
1128+
let src_ty = self.normalize(ty::Unnormalized::new_wip(src_ty), location);
11281129
if let Err(terr) = self.sub_types(
11291130
src_ty,
11301131
*ty,
@@ -1190,7 +1191,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
11901191
// function definition. When we extract the
11911192
// signature, it comes from the `fn_sig` query,
11921193
// and hence may contain unnormalized results.
1193-
let fn_sig = self.normalize(fn_sig, location);
1194+
let fn_sig = self.normalize(ty::Unnormalized::new_wip(fn_sig), location);
11941195

11951196
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
11961197

@@ -1786,8 +1787,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
17861787
);
17871788
}
17881789
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
1789-
let unnormalized_ty =
1790-
tcx.type_of(static_def_id).instantiate_identity().skip_norm_wip();
1790+
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
17911791
let normalized_ty = self.normalize(unnormalized_ty, locations);
17921792
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
17931793

@@ -1876,9 +1876,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18761876
| ProjectionElem::Subslice { .. }
18771877
| ProjectionElem::Downcast(..) => {}
18781878
ProjectionElem::Field(field, fty) => {
1879-
let fty = self.normalize(fty, location);
1879+
let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
18801880
let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
1881-
let ty = self.normalize(ty, location);
1881+
let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
18821882
debug!(?fty, ?ty);
18831883

18841884
if let Err(terr) = self.relate_types(
@@ -1892,7 +1892,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18921892
}
18931893
}
18941894
ProjectionElem::OpaqueCast(ty) => {
1895-
let ty = self.normalize(ty, location);
1895+
let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
18961896
self.relate_types(
18971897
ty,
18981898
context.ambient_variance(),
@@ -1945,7 +1945,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19451945
}
19461946
} else {
19471947
let dest_ty = destination.ty(self.body, tcx).ty;
1948-
let dest_ty = self.normalize(dest_ty, term_location);
1948+
let dest_ty = self.normalize(ty::Unnormalized::new_wip(dest_ty), term_location);
19491949
let category = match destination.as_local() {
19501950
Some(RETURN_PLACE) => {
19511951
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
@@ -2030,7 +2030,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20302030
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
20312031
let op_arg_ty = op_arg.node.ty(self.body, self.tcx());
20322032

2033-
let op_arg_ty = self.normalize(op_arg_ty, term_location);
2033+
let op_arg_ty = self.normalize(ty::Unnormalized::new_wip(op_arg_ty), term_location);
20342034
let category = if call_source.from_hir_call() {
20352035
ConstraintCategory::CallArgument(Some(
20362036
self.infcx.tcx.erase_and_anonymize_regions(func_ty),
@@ -2198,7 +2198,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21982198
let variant = &def.variant(variant_index);
21992199
let adj_field_index = active_field_index.unwrap_or(field_index);
22002200
if let Some(field) = variant.fields.get(adj_field_index) {
2201-
Ok(self.normalize(field.ty(tcx, args), location))
2201+
Ok(self.normalize(ty::Unnormalized::new_wip(field.ty(tcx, args)), location))
22022202
} else {
22032203
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
22042204
}
@@ -2302,7 +2302,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23022302
}
23032303
};
23042304
let operand_ty = operand.ty(self.body, tcx);
2305-
let operand_ty = self.normalize(operand_ty, location);
2305+
let operand_ty = self.normalize(ty::Unnormalized::new_wip(operand_ty), location);
23062306

23072307
if let Err(terr) = self.sub_types(
23082308
operand_ty,

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
1616
use rustc_hir as hir;
1717
use rustc_middle::mir::BinOp;
1818
use rustc_middle::ty::layout::HasTyCtxt;
19-
use rustc_middle::ty::{self, Ty, Unnormalized};
19+
use rustc_middle::ty::{self, Ty};
2020
use rustc_span::{Span, Symbol, sym};
2121

2222
use crate::builder::Builder;
@@ -539,10 +539,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
539539
match *in_elem.kind() {
540540
ty::RawPtr(p_ty, _) => {
541541
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
542-
bx.tcx.normalize_erasing_regions(
543-
ty::TypingEnv::fully_monomorphized(),
544-
Unnormalized::new_wip(ty),
545-
)
542+
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
546543
});
547544
require!(
548545
metadata.is_unit(),
@@ -556,10 +553,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
556553
match *out_elem.kind() {
557554
ty::RawPtr(p_ty, _) => {
558555
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
559-
bx.tcx.normalize_erasing_regions(
560-
ty::TypingEnv::fully_monomorphized(),
561-
Unnormalized::new_wip(ty),
562-
)
556+
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
563557
});
564558
require!(
565559
metadata.is_unit(),

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use rustc_hir::find_attr;
1818
use rustc_middle::mir::BinOp;
1919
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
2020
use rustc_middle::ty::offload_meta::OffloadMetadata;
21-
use rustc_middle::ty::{
22-
self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv, Unnormalized,
23-
};
21+
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
2422
use rustc_middle::{bug, span_bug};
2523
use rustc_session::config::CrateType;
2624
use rustc_session::errors::feature_err;
@@ -3053,7 +3051,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
30533051
match in_elem.kind() {
30543052
ty::RawPtr(p_ty, _) => {
30553053
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
3056-
bx.tcx.normalize_erasing_regions(bx.typing_env(), Unnormalized::new_wip(ty))
3054+
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
30573055
});
30583056
require!(
30593057
metadata.is_unit(),
@@ -3067,7 +3065,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
30673065
match out_elem.kind() {
30683066
ty::RawPtr(p_ty, _) => {
30693067
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
3070-
bx.tcx.normalize_erasing_regions(bx.typing_env(), Unnormalized::new_wip(ty))
3068+
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
30713069
});
30723070
require!(
30733071
metadata.is_unit(),

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn reconstruct_place_meta<'tcx>(
202202
let tail = tcx.struct_tail_raw(
203203
layout.ty,
204204
&ObligationCause::dummy(),
205-
|ty| ty,
205+
|ty| ty.skip_normalization(),
206206
|| {
207207
let branches = last_valtree.to_branch();
208208
last_valtree = branches.last().unwrap().to_value().valtree;

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx};
99
use rustc_hir::def_id::DefId;
1010
use rustc_hir::find_attr;
1111
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
12-
use rustc_middle::ty::{self, AdtDef, Instance, Ty, Unnormalized, VariantDef};
12+
use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef};
1313
use rustc_middle::{bug, mir, span_bug};
1414
use rustc_target::callconv::{ArgAbi, FnAbi};
1515
use tracing::field::Empty;
@@ -218,9 +218,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
218218
// Even if `ty` is normalized, the search for the unsized tail will project
219219
// to fields, which can yield non-normalized types. So we need to provide a
220220
// normalization function.
221-
let normalize = |ty| {
222-
self.tcx.normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(ty))
223-
};
221+
let normalize = |ty| self.tcx.normalize_erasing_regions(self.typing_env, ty);
224222
ty.ptr_metadata_ty(*self.tcx, normalize)
225223
};
226224
return interp_ok(meta_ty(caller) == meta_ty(callee));

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ pub(crate) fn check_static_item<'tcx>(
13141314
let tail = tcx.struct_tail_raw(
13151315
item_ty,
13161316
&ObligationCause::dummy(),
1317-
|ty| wfcx.deeply_normalize(span, loc, Unnormalized::new_wip(ty)),
1317+
|ty| wfcx.deeply_normalize(span, loc, ty),
13181318
|| {},
13191319
);
13201320

compiler/rustc_hir_typeck/src/expectation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
8181
let cause = ObligationCause::misc(span, fcx.body_id);
8282

8383
// FIXME: This is not right, even in the old solver...
84-
match fcx.tcx.struct_tail_raw(ty, &cause, |ty| ty, || {}).kind() {
84+
match fcx.tcx.struct_tail_raw(ty, &cause, |ty| ty.skip_normalization(), || {}).kind() {
8585
ty::Slice(_) | ty::Str | ty::Dynamic(..) => ExpectRvalueLikeUnsized(ty),
8686
_ => ExpectHasType(ty),
8787
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473473
let tail = self.tcx.struct_tail_raw(
474474
ty,
475475
&self.misc(span),
476-
|ty| self.normalize(span, Unnormalized::new_wip(ty)),
476+
|ty| self.normalize(span, ty),
477477
|| {},
478478
);
479479
// Sized types have static alignment, and so do slices.

0 commit comments

Comments
 (0)