Skip to content

Commit f6a9247

Browse files
committed
add FRTs as ty::Field
1 parent b6b2961 commit f6a9247

File tree

27 files changed

+98
-7
lines changed

27 files changed

+98
-7
lines changed

compiler/rustc_hir_analysis/src/variance/constraints.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
273273
self.add_constraints_from_args(current, def.did(), args, variance);
274274
}
275275

276+
ty::Field(ty, _) => {
277+
self.add_constraints_from_ty(current, ty, variance);
278+
}
279+
276280
ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, ref data) => {
277281
self.add_constraints_from_invariant_args(current, data.args, variance);
278282
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
802802
| ty::RawPtr(_, _)
803803
| ty::Ref(..)
804804
| ty::Never
805+
| ty::Field(..)
805806
| ty::Tuple(..) => {
806807
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
807808
}

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
415415
| ty::Uint(..)
416416
| ty::Float(..)
417417
| ty::Adt(..)
418+
| ty::Field(..)
418419
| ty::Str
419420
| ty::Error(_)
420421
| ty::Array(..)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ use crate::traits::solve::{
7878
};
7979
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
8080
use crate::ty::{
81-
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
82-
GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, ParamTy,
83-
Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
81+
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, FieldPath, GenericArg,
82+
GenericArgs, GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst,
83+
ParamTy, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
8484
PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
8585
ValTree, ValTreeKind, Visibility,
8686
};
@@ -565,6 +565,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
565565
| ty::Uint(_)
566566
| ty::Float(_)
567567
| ty::Adt(_, _)
568+
| ty::Field(_, _)
568569
| ty::Foreign(_)
569570
| ty::Str
570571
| ty::Array(_, _)

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
390390
ty::Array(typ, sz) => ty::Array(typ.try_fold_with(folder)?, sz.try_fold_with(folder)?),
391391
ty::Slice(typ) => ty::Slice(typ.try_fold_with(folder)?),
392392
ty::Adt(tid, args) => ty::Adt(tid, args.try_fold_with(folder)?),
393+
ty::Field(ty, field_path) => ty::Field(ty.try_fold_with(folder)?, field_path),
393394
ty::Dynamic(trait_ty, region, representation) => ty::Dynamic(
394395
trait_ty.try_fold_with(folder)?,
395396
region.try_fold_with(folder)?,
@@ -437,6 +438,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
437438
ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
438439
ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
439440
ty::Adt(tid, args) => ty::Adt(tid, args.fold_with(folder)),
441+
ty::Field(ty, field_path) => ty::Field(ty.fold_with(folder), field_path),
440442
ty::Dynamic(trait_ty, region, representation) => {
441443
ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder), representation)
442444
}
@@ -481,6 +483,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
481483
}
482484
ty::Slice(typ) => typ.visit_with(visitor),
483485
ty::Adt(_, args) => args.visit_with(visitor),
486+
ty::Field(ty, _) => ty.visit_with(visitor),
484487
ty::Dynamic(trait_ty, reg, _) => {
485488
try_visit!(trait_ty.visit_with(visitor));
486489
reg.visit_with(visitor)

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use super::GenericParamDefKind;
2525
use crate::infer::canonical::Canonical;
2626
use crate::ty::InferTy::*;
2727
use crate::ty::{
28-
self, AdtDef, BoundRegionKind, Discr, GenericArg, GenericArgs, GenericArgsRef, List, ParamEnv,
29-
Region, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy,
28+
self, AdtDef, BoundRegionKind, Discr, FieldPath, GenericArg, GenericArgs, GenericArgsRef, List,
29+
ParamEnv, Region, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable, TypeVisitor,
30+
UintTy,
3031
};
3132

3233
// Re-export and re-parameterize some `I = TyCtxt<'tcx>` types here
@@ -667,6 +668,15 @@ impl<'tcx> Ty<'tcx> {
667668
Ty::new(tcx, Adt(def, args))
668669
}
669670

671+
pub fn new_field_type(
672+
tcx: TyCtxt<'tcx>,
673+
container: Ty<'tcx>,
674+
field_path: FieldPath<'tcx>,
675+
) -> Ty<'tcx> {
676+
assert!(!field_path.0.is_empty());
677+
Ty::new(tcx, Field(container, field_path))
678+
}
679+
670680
#[inline]
671681
pub fn new_foreign(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
672682
Ty::new(tcx, Foreign(def_id))
@@ -972,6 +982,14 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
972982
Ty::new_adt(interner, adt_def, args)
973983
}
974984

985+
fn new_field_type(
986+
interner: TyCtxt<'tcx>,
987+
container: Ty<'tcx>,
988+
field_path: FieldPath<'tcx>,
989+
) -> Self {
990+
Ty::new_field_type(interner, container, field_path)
991+
}
992+
975993
fn new_foreign(interner: TyCtxt<'tcx>, def_id: DefId) -> Self {
976994
Ty::new_foreign(interner, def_id)
977995
}
@@ -1967,6 +1985,7 @@ impl<'tcx> Ty<'tcx> {
19671985
},
19681986

19691987
ty::Adt(_, _)
1988+
| ty::Field(_, _)
19701989
| ty::Tuple(_)
19711990
| ty::Array(..)
19721991
| ty::Foreign(_)

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ impl<'tcx> Ty<'tcx> {
14091409
pub fn is_structural_eq_shallow(self, tcx: TyCtxt<'tcx>) -> bool {
14101410
match self.kind() {
14111411
// Look for an impl of `StructuralPartialEq`.
1412-
ty::Adt(..) => tcx.has_structural_eq_impl(self),
1412+
ty::Adt(..) | ty::Field(..) => tcx.has_structural_eq_impl(self),
14131413

14141414
// Primitive types that satisfy `Eq`.
14151415
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str | ty::Never => true,

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
165165
| ty::Bound(_, _)
166166
| ty::Infer(_)
167167
| ty::Error(_)
168+
| ty::Field(..)
168169
| ty::Placeholder(_) => {
169170
bug!("When Place is Deref it's type shouldn't be {place_ty:#?}")
170171
}
@@ -183,6 +184,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
183184
| ty::Coroutine(_, _)
184185
| ty::Tuple(_) => (),
185186
ty::Bool
187+
| ty::Field(..)
186188
| ty::Char
187189
| ty::Int(_)
188190
| ty::Uint(_)

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ fn try_write_constant<'tcx>(
937937
// Unsupported for now.
938938
ty::Array(_, _)
939939
| ty::Pat(_, _)
940+
| ty::Field(..)
940941

941942
// Do not attempt to support indirection in constants.
942943
| ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..) | ty::Str | ty::Slice(_)

compiler/rustc_next_trait_solver/src/canonicalizer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
364364
| ty::Uint(_)
365365
| ty::Float(_)
366366
| ty::Adt(_, _)
367+
| ty::Field(_, _)
367368
| ty::Foreign(_)
368369
| ty::Str
369370
| ty::Array(_, _)

0 commit comments

Comments
 (0)