Skip to content

Commit 3fb166f

Browse files
committed
tiny PR
1 parent 57b3e84 commit 3fb166f

58 files changed

Lines changed: 242 additions & 231 deletions

File tree

Some content is hidden

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

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12391239
// In practice unless there are more than one field with the same type, we'll be
12401240
// suggesting a single field at a type, because we don't aggregate multiple borrow
12411241
// checker errors involving the functional record update syntax into a single one.
1242-
let field_ty = field.ty(self.infcx.tcx, args);
1242+
let field_ty = field.ty(self.infcx.tcx, args).skip_norm_wip();
12431243
let ident = field.ident(self.infcx.tcx);
12441244
if field_ty == ty && fields.iter().all(|field| field.ident.name != ident.name) {
12451245
// Suggest adding field and cloning it.
@@ -1314,10 +1314,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13141314
} else if let ty::Adt(def, args) = ty.kind()
13151315
&& let Some(local_did) = def.did().as_local()
13161316
&& def.variants().iter().all(|variant| {
1317-
variant
1318-
.fields
1319-
.iter()
1320-
.all(|field| self.implements_clone(field.ty(self.infcx.tcx, args)))
1317+
variant.fields.iter().all(|field| {
1318+
self.implements_clone(field.ty(self.infcx.tcx, args).skip_norm_wip())
1319+
})
13211320
})
13221321
{
13231322
let ty_span = self.infcx.tcx.def_span(def.did());

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
241241
);
242242

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

248247
#[instrument(skip(self), level = "debug")]

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
481481
tcx,
482482
proj,
483483
|ty| self.normalize(ty::Unnormalized::new_wip(ty), locations),
484-
|ty, variant_index, field, ()| PlaceTy::field_ty(tcx, ty, variant_index, field),
484+
|ty, variant_index, field, ()| {
485+
PlaceTy::field_ty(tcx, ty, variant_index, field).skip_norm_wip()
486+
},
485487
|_| unreachable!(),
486488
);
487489
curr_projected_ty = projected_ty;
@@ -1878,7 +1880,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18781880
ProjectionElem::Field(field, fty) => {
18791881
let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
18801882
let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
1881-
let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
1883+
let ty = self.normalize(ty, location);
18821884
debug!(?fty, ?ty);
18831885

18841886
if let Err(terr) = self.relate_types(
@@ -2198,7 +2200,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21982200
let variant = &def.variant(variant_index);
21992201
let adj_field_index = active_field_index.unwrap_or(field_index);
22002202
if let Some(field) = variant.fields.get(adj_field_index) {
2201-
Ok(self.normalize(ty::Unnormalized::new_wip(field.ty(tcx, args)), location))
2203+
Ok(self.normalize(field.ty(tcx, args), location))
22022204
} else {
22032205
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
22042206
}
@@ -2513,8 +2515,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25132515
else {
25142516
continue;
25152517
};
2516-
let dest_ty = dest_field.ty(tcx, dest_args);
2517-
let borrowed_ty = borrowed_field.ty(tcx, borrowed_args);
2518+
let dest_ty = dest_field.ty(tcx, dest_args).skip_norm_wip();
2519+
let borrowed_ty = borrowed_field.ty(tcx, borrowed_args).skip_norm_wip();
25182520
if let (
25192521
ty::Ref(borrow_region, _, Mutability::Mut),
25202522
ty::Ref(ref_region, _, Mutability::Not),

compiler/rustc_const_eval/src/const_eval/type_info/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
194194
variant_def.fields.len() as u64,
195195
|this, i, place| {
196196
let field_def = &variant_def.fields[FieldIdx::from_usize(i as usize)];
197-
let field_ty = field_def.ty(*this.tcx, generics);
197+
let field_ty = field_def.ty(*this.tcx, generics).skip_norm_wip();
198198
this.write_field(field_ty, place, variant_layout, Some(field_def.name), i)
199199
},
200200
)

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
109109

110110
let all_fields_1zst = |variant: &VariantDef| -> InterpResult<'tcx, _> {
111111
for field in &variant.fields {
112-
let ty = field.ty(*self.tcx, args);
112+
let ty = field.ty(*self.tcx, args).skip_norm_wip();
113113
let layout = self.layout_of(ty)?;
114114
if !layout.is_1zst() {
115115
return interp_ok(false);
@@ -134,7 +134,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
134134
if relevant_variant.fields.len() != 1 {
135135
return interp_ok(layout);
136136
}
137-
let inner = relevant_variant.fields[FieldIdx::from_u32(0)].ty(*self.tcx, args);
137+
let inner =
138+
relevant_variant.fields[FieldIdx::from_u32(0)].ty(*self.tcx, args).skip_norm_wip();
138139
let inner = self.layout_of(inner)?;
139140

140141
// Check if the inner type is one of the NPO-guaranteed ones.

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
13861386
};
13871387

13881388
for (i, field) in adt.non_enum_variant().fields.iter().enumerate() {
1389-
if field.ty(*self.tcx, substs).is_raw_ptr() {
1389+
if field.ty(*self.tcx, substs).skip_norm_wip().is_raw_ptr() {
13901390
return self.project_field(&va_list_inner, FieldIdx::from_usize(i));
13911391
}
13921392
}

compiler/rustc_hir_analysis/src/check/always_applicable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn ensure_all_fields_are_const_destruct<'tcx>(
197197
let args = ty::GenericArgs::identity_for_item(tcx, impl_def_id);
198198
let destruct_trait = tcx.lang_items().destruct_trait().unwrap();
199199
for field in tcx.adt_def(adt_def_id).all_fields() {
200-
let field_ty = field.ty(tcx, args);
200+
let field_ty = field.ty(tcx, args).skip_norm_wip();
201201
let cause = traits::ObligationCause::new(
202202
tcx.def_span(field.did),
203203
impl_def_id,

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
168168
let args = ty::GenericArgs::identity_for_item(tcx, item_def_id);
169169

170170
for field in &def.non_enum_variant().fields {
171-
if !allowed_union_or_unsafe_field(tcx, field.ty(tcx, args), typing_env, span) {
171+
if !allowed_union_or_unsafe_field(
172+
tcx,
173+
field.ty(tcx, args).skip_norm_wip(),
174+
typing_env,
175+
span,
176+
) {
172177
let (field_span, ty_span) = match tcx.hir_get_if_local(field.did) {
173178
// We are currently checking the type this field came from, so it must be local.
174179
Some(Node::Field(field)) => (field.span, field.ty.span),
@@ -738,7 +743,7 @@ fn is_enum_of_nonnullable_ptr<'tcx>(
738743
let (([], [field]) | ([field], [])) = (&var_one.fields.raw[..], &var_two.fields.raw[..]) else {
739744
return false;
740745
};
741-
matches!(field.ty(tcx, args).kind(), ty::FnPtr(..) | ty::Ref(..))
746+
matches!(field.ty(tcx, args).skip_norm_wip().kind(), ty::FnPtr(..) | ty::Ref(..))
742747
}
743748

744749
fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
@@ -1440,7 +1445,7 @@ fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
14401445
}
14411446

14421447
let array_field = &fields[FieldIdx::ZERO];
1443-
let array_ty = array_field.ty(tcx, args);
1448+
let array_ty = array_field.ty(tcx, args).skip_norm_wip();
14441449
let ty::Array(element_ty, len_const) = array_ty.kind() else {
14451450
struct_span_code_err!(
14461451
tcx.dcx(),
@@ -1545,7 +1550,7 @@ fn check_scalable_vector(tcx: TyCtxt<'_>, span: Span, def_id: LocalDefId, scalab
15451550

15461551
match scalable {
15471552
ScalableElt::ElementCount(..) => {
1548-
let element_ty = &fields[FieldIdx::ZERO].ty(tcx, args);
1553+
let element_ty = &fields[FieldIdx::ZERO].ty(tcx, args).skip_norm_wip();
15491554

15501555
// Check that `element_ty` only uses types valid in the lanes of a scalable vector
15511556
// register: scalar types which directly match a "machine" type - integers, floats and
@@ -1565,7 +1570,7 @@ fn check_scalable_vector(tcx: TyCtxt<'_>, span: Span, def_id: LocalDefId, scalab
15651570
ScalableElt::Container => {
15661571
let mut prev_field_ty = None;
15671572
for field in fields.iter() {
1568-
let element_ty = field.ty(tcx, args);
1573+
let element_ty = field.ty(tcx, args).skip_norm_wip();
15691574
if let ty::Adt(def, _) = element_ty.kind()
15701575
&& def.repr().scalable()
15711576
{
@@ -1683,7 +1688,7 @@ pub(super) fn check_packed_inner(
16831688

16841689
stack.push(def_id);
16851690
for field in &def.non_enum_variant().fields {
1686-
if let ty::Adt(def, _) = field.ty(tcx, args).kind()
1691+
if let ty::Adt(def, _) = field.ty(tcx, args).skip_norm_wip().kind()
16871692
&& !stack.contains(&def.did())
16881693
&& let Some(mut defs) = check_packed_inner(tcx, def.did(), stack)
16891694
{
@@ -1761,7 +1766,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
17611766
}
17621767

17631768
let field_infos = adt.all_fields().map(|field| {
1764-
let ty = field.ty(tcx, GenericArgs::identity_for_item(tcx, field.did));
1769+
let ty = field.ty(tcx, GenericArgs::identity_for_item(tcx, field.did)).skip_norm_wip();
17651770
let layout = tcx.layout_of(typing_env.as_query_input(ty));
17661771
// We are currently checking the type this field came from, so it must be local
17671772
let span = tcx.hir_span_if_local(field.did).unwrap();
@@ -1828,7 +1833,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
18281833
return ControlFlow::Break(UnsuitedInfo { ty, reason: UnsuitedReason::ReprC });
18291834
}
18301835
def.all_fields()
1831-
.map(|field| field.ty(tcx, args))
1836+
.map(|field| field.ty(tcx, args).skip_norm_wip())
18321837
.try_for_each(|t| check_unsuited(tcx, typing_env, t))
18331838
}
18341839
_ => ControlFlow::Continue(()),

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
391391
return None;
392392
}
393393

394-
let ty_a = field.ty(tcx, args_a);
395-
let ty_b = field.ty(tcx, args_b);
394+
let ty_a = field.ty(tcx, args_a).skip_norm_wip();
395+
let ty_b = field.ty(tcx, args_b).skip_norm_wip();
396396

397397
// FIXME: We could do normalization here, but is it really worth it?
398398
if ty_a == ty_b {
@@ -748,6 +748,7 @@ fn generic_lifetime_params_count(args: &[ty::GenericArg<'_>]) -> usize {
748748
args.iter().filter(|arg| arg.as_region().is_some()).count()
749749
}
750750

751+
// FIXME(#155345): This should return `Unnormalized`
751752
fn collect_struct_data_fields<'tcx>(
752753
tcx: TyCtxt<'tcx>,
753754
def: ty::AdtDef<'tcx>,
@@ -758,7 +759,7 @@ fn collect_struct_data_fields<'tcx>(
758759
.iter()
759760
.filter_map(|f| {
760761
// Ignore PhantomData fields
761-
let ty = f.ty(tcx, args);
762+
let ty = f.ty(tcx, args).skip_norm_wip();
762763
if ty.is_phantom_data() {
763764
return None;
764765
}
@@ -922,7 +923,8 @@ pub(crate) fn coerce_unsized_info<'tcx>(
922923
let diff_fields = fields
923924
.iter_enumerated()
924925
.filter_map(|(i, f)| {
925-
let (a, b) = (f.ty(tcx, args_a), f.ty(tcx, args_b));
926+
let (a, b) =
927+
(f.ty(tcx, args_a).skip_norm_wip(), f.ty(tcx, args_b).skip_norm_wip());
926928

927929
// Ignore PhantomData fields
928930
let unnormalized_ty = tcx.type_of(f.did).instantiate_identity();

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,12 +2048,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20482048
ty::Adt(adt, args) if adt.is_struct() => variant
20492049
.fields
20502050
.iter()
2051-
.map(|f| self.normalize(span, Unnormalized::new_wip(f.ty(self.tcx, args))))
2051+
.map(|f| self.normalize(span, f.ty(self.tcx, args)))
20522052
.collect(),
20532053
ty::Adt(adt, args) if adt.is_enum() => variant
20542054
.fields
20552055
.iter()
2056-
.map(|f| self.normalize(span, Unnormalized::new_wip(f.ty(self.tcx, args))))
2056+
.map(|f| self.normalize(span, f.ty(self.tcx, args)))
20572057
.collect(),
20582058
_ => {
20592059
self.dcx().emit_err(FunctionalRecordUpdateOnNonStruct { span });
@@ -2168,12 +2168,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21682168
ty::Adt(adt, args) if adt.is_struct() => variant
21692169
.fields
21702170
.iter()
2171-
.map(|f| {
2172-
self.normalize(
2173-
expr.span,
2174-
Unnormalized::new_wip(f.ty(self.tcx, args)),
2175-
)
2176-
})
2171+
.map(|f| self.normalize(expr.span, f.ty(self.tcx, args)))
21772172
.collect(),
21782173
_ => {
21792174
self.dcx().emit_err(FunctionalRecordUpdateOnNonStruct {
@@ -2359,7 +2354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23592354
variant.fields.iter().find(|field| field.ident(self.tcx) == last_expr_field.ident)
23602355
&& let range_def_id = self.tcx.lang_items().range_struct()
23612356
&& variant_field
2362-
.and_then(|field| field.ty(self.tcx, args).ty_adt_def())
2357+
.and_then(|field| field.ty(self.tcx, args).skip_norm_wip().ty_adt_def())
23632358
.map(|adt| adt.did())
23642359
!= range_def_id
23652360
{
@@ -3360,7 +3355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33603355
.map(|field_def| {
33613356
(
33623357
field_def.ident(self.tcx).normalize_to_macros_2_0(),
3363-
field_def.ty(self.tcx, args),
3358+
field_def.ty(self.tcx, args).skip_norm_wip(),
33643359
)
33653360
})
33663361
.collect::<Vec<_>>(),

0 commit comments

Comments
 (0)