Skip to content

Commit be7f506

Browse files
Rework most of structural_traits to be Interner-agnostic
1 parent e0bca1d commit be7f506

File tree

10 files changed

+350
-139
lines changed

10 files changed

+350
-139
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
4444
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
4545
use rustc_middle::{bug, span_bug};
4646
use rustc_span::symbol::Symbol;
47-
use rustc_span::Span;
47+
use rustc_span::{Span, DUMMY_SP};
4848
use snapshot::undo_log::InferCtxtUndoLogs;
4949
use std::cell::{Cell, RefCell};
5050
use std::fmt;
@@ -405,6 +405,25 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
405405
}
406406
}
407407
}
408+
409+
fn instantiate_binder_with_infer<T: TypeFoldable<Self::Interner> + Copy>(
410+
&self,
411+
value: ty::Binder<'tcx, T>,
412+
) -> T {
413+
self.instantiate_binder_with_fresh_vars(
414+
DUMMY_SP,
415+
BoundRegionConversionTime::HigherRankedType,
416+
value,
417+
)
418+
}
419+
420+
fn enter_forall<T: TypeFoldable<Self::Interner> + Copy, U>(
421+
&self,
422+
value: ty::Binder<'tcx, T>,
423+
f: impl FnOnce(T) -> U,
424+
) -> U {
425+
self.enter_forall(value, f)
426+
}
408427
}
409428

410429
/// See the `error_reporting` module for more details.

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,23 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
204204
fn def_id(self) -> DefId {
205205
self.did()
206206
}
207+
208+
fn is_phantom_data(self) -> bool {
209+
self.is_phantom_data()
210+
}
211+
212+
fn all_field_tys(
213+
self,
214+
tcx: TyCtxt<'tcx>,
215+
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = Ty<'tcx>>> {
216+
ty::EarlyBinder::bind(
217+
self.all_fields().map(move |field| tcx.type_of(field.did).skip_binder()),
218+
)
219+
}
220+
221+
fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
222+
self.sized_constraint(tcx)
223+
}
207224
}
208225

209226
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_middle/src/ty/context.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
154154

155155
type VariancesOf = &'tcx [ty::Variance];
156156

157-
fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf {
157+
fn variances_of(self, def_id: DefId) -> Self::VariancesOf {
158158
self.variances_of(def_id)
159159
}
160160

@@ -198,7 +198,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
198198

199199
fn trait_ref_and_own_args_for_alias(
200200
self,
201-
def_id: Self::DefId,
201+
def_id: DefId,
202202
args: Self::GenericArgs,
203203
) -> (rustc_type_ir::TraitRef<Self>, Self::GenericArgsSlice) {
204204
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
@@ -246,7 +246,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
246246
self.mk_type_list_from_iter(args)
247247
}
248248

249-
fn parent(self, def_id: Self::DefId) -> Self::DefId {
249+
fn parent(self, def_id: DefId) -> DefId {
250250
self.parent(def_id)
251251
}
252252

@@ -259,6 +259,49 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
259259
fn features(self) -> Self::Features {
260260
self.features()
261261
}
262+
263+
fn bound_coroutine_hidden_types(
264+
self,
265+
def_id: DefId,
266+
) -> impl Iterator<Item = ty::EarlyBinder<'tcx, ty::Binder<'tcx, Ty<'tcx>>>> {
267+
self.bound_coroutine_hidden_types(def_id)
268+
}
269+
270+
fn fn_sig(self, def_id: DefId) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {
271+
self.fn_sig(def_id)
272+
}
273+
274+
fn coroutine_movability(self, def_id: DefId) -> rustc_ast::Movability {
275+
self.coroutine_movability(def_id)
276+
}
277+
278+
fn coroutine_for_closure(self, def_id: DefId) -> DefId {
279+
self.coroutine_for_closure(def_id)
280+
}
281+
282+
fn generics_require_sized_self(self, def_id: DefId) -> bool {
283+
self.generics_require_sized_self(def_id)
284+
}
285+
286+
fn item_bounds(
287+
self,
288+
def_id: DefId,
289+
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = ty::Clause<'tcx>>> {
290+
self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
291+
}
292+
293+
fn super_predicates_of(
294+
self,
295+
def_id: DefId,
296+
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = ty::Clause<'tcx>>> {
297+
ty::EarlyBinder::bind(
298+
self.super_predicates_of(def_id).instantiate_identity(self).predicates.into_iter(),
299+
)
300+
}
301+
302+
fn has_target_features(self, def_id: DefId) -> bool {
303+
!self.codegen_fn_attrs(def_id).target_features.is_empty()
304+
}
262305
}
263306

264307
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
@@ -281,6 +324,10 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
281324
fn generic_const_exprs(self) -> bool {
282325
self.generic_const_exprs
283326
}
327+
328+
fn coroutine_clone(self) -> bool {
329+
self.coroutine_clone
330+
}
284331
}
285332

286333
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub struct GenericArg<'tcx> {
4141
marker: PhantomData<(Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>)>,
4242
}
4343

44+
impl<'tcx> rustc_type_ir::inherent::GenericArg<TyCtxt<'tcx>> for GenericArg<'tcx> {}
45+
4446
impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArgsRef<'tcx> {
4547
fn type_at(self, i: usize) -> Ty<'tcx> {
4648
self.type_at(i)

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ pub struct Term<'tcx> {
488488
marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
489489
}
490490

491+
impl<'tcx> rustc_type_ir::inherent::Term<TyCtxt<'tcx>> for Term<'tcx> {}
492+
491493
impl<'tcx> rustc_type_ir::inherent::IntoKind for Term<'tcx> {
492494
type Kind = TermKind<'tcx>;
493495

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,10 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
786786
tcx.types.bool
787787
}
788788

789+
fn new_u8(tcx: TyCtxt<'tcx>) -> Self {
790+
tcx.types.u8
791+
}
792+
789793
fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferTy) -> Self {
790794
Ty::new_infer(tcx, infer)
791795
}

0 commit comments

Comments
 (0)