From b55d8a3b4917698fd6d389f05afc423086f33d97 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 10 May 2024 15:43:27 -0400 Subject: [PATCH] Apply nits, make some bounds into supertraits on inherent traits --- compiler/rustc_middle/src/ty/predicate.rs | 2 + compiler/rustc_traits/src/type_op.rs | 2 +- compiler/rustc_type_ir/src/inherent.rs | 50 ++++++++++++++++++--- compiler/rustc_type_ir/src/interner.rs | 55 ++++------------------- compiler/rustc_type_ir/src/ir_print.rs | 2 +- compiler/rustc_type_ir/src/trait_ref.rs | 2 +- 6 files changed, 57 insertions(+), 56 deletions(-) diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index 2279e27c8db..5387036d409 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -30,6 +30,8 @@ pub struct Predicate<'tcx>( pub(super) Interned<'tcx, WithCachedTypeInfo>>>, ); +impl<'tcx> rustc_type_ir::inherent::Predicate> for Predicate<'tcx> {} + impl<'tcx> rustc_type_ir::visit::Flags for Predicate<'tcx> { fn flags(&self) -> TypeFlags { self.0.flags diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 85c98bfd5dc..b6a59a4ad3a 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -3,7 +3,7 @@ use rustc_middle::query::Providers; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::{Clause, ParamEnvAnd}; -use rustc_middle::ty::{FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{FnSig, PolyFnSig, Ty, TyCtxt, TypeFoldable}; use rustc_trait_selection::infer::InferCtxtBuilderExt; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::query::type_op::ascribe_user_type::{ diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 84aeeae31d8..0fd34e0a65f 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -1,33 +1,69 @@ -use crate::{BoundVar, DebruijnIndex, Interner, UniverseIndex}; +use std::fmt::Debug; +use std::hash::Hash; -pub trait Ty> { +use crate::fold::TypeSuperFoldable; +use crate::visit::{Flags, TypeSuperVisitable}; +use crate::{ + BoundVar, ConstKind, DebruijnIndex, DebugWithInfcx, Interner, RegionKind, TyKind, UniverseIndex, +}; + +pub trait Ty>: + Copy + + DebugWithInfcx + + Hash + + Eq + + Into + + IntoKind> + + TypeSuperVisitable + + TypeSuperFoldable + + Flags +{ fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self; } -pub trait Region> { +pub trait Region>: + Copy + DebugWithInfcx + Hash + Eq + Into + IntoKind> + Flags +{ fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self; fn new_static(interner: I) -> Self; } -pub trait Const> { +pub trait Const>: + Copy + + DebugWithInfcx + + Hash + + Eq + + Into + + IntoKind> + + TypeSuperVisitable + + TypeSuperFoldable + + Flags +{ fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar, ty: I::Ty) -> Self; fn ty(self) -> I::Ty; } -pub trait GenericsOf { +pub trait GenericsOf> { fn count(&self) -> usize; } -pub trait GenericArgs { +pub trait GenericArgs>: + Copy + DebugWithInfcx + Hash + Eq + IntoIterator +{ fn type_at(self, i: usize) -> I::Ty; fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs; } +pub trait Predicate>: + Copy + Debug + Hash + Eq + TypeSuperVisitable + TypeSuperFoldable + Flags +{ +} + /// Common capabilities of placeholder kinds -pub trait PlaceholderLike { +pub trait PlaceholderLike: Copy + Debug + Hash + Eq { fn universe(self) -> UniverseIndex; fn var(self) -> BoundVar; diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 32f07b1ff61..c8bd7fea11b 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -2,23 +2,17 @@ use std::fmt::Debug; use std::hash::Hash; -use crate::fold::TypeSuperFoldable; use crate::inherent::*; use crate::ir_print::IrPrint; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable}; -use crate::{CanonicalVarInfo, ConstKind, DebugWithInfcx, RegionKind, TraitRef, TyKind}; +use crate::{CanonicalVarInfo, DebugWithInfcx, TraitRef}; pub trait Interner: Sized + Copy + IrPrint> { type DefId: Copy + Debug + Hash + Eq; type DefiningOpaqueTypes: Copy + Debug + Hash + Default + Eq + TypeVisitable; type AdtDef: Copy + Debug + Hash + Eq; - type GenericArgs: Copy - + DebugWithInfcx - + Hash - + Eq - + IntoIterator - + GenericArgs; + type GenericArgs: GenericArgs; type GenericArg: Copy + DebugWithInfcx + Hash + Eq; type Term: Copy + Debug + Hash + Eq; @@ -29,21 +23,12 @@ pub trait Interner: Sized + Copy + IrPrint> { type CanonicalVars: Copy + Debug + Hash + Eq + IntoIterator>; // Kinds of tys - type Ty: Copy - + DebugWithInfcx - + Hash - + Eq - + Into - + IntoKind> - + TypeSuperVisitable - + TypeSuperFoldable - + Flags - + Ty; + type Ty: Ty; type Tys: Copy + Debug + Hash + Eq + IntoIterator; type AliasTy: Copy + DebugWithInfcx + Hash + Eq; type ParamTy: Copy + Debug + Hash + Eq; type BoundTy: Copy + Debug + Hash + Eq; - type PlaceholderTy: Copy + Debug + Hash + Eq + PlaceholderLike; + type PlaceholderTy: PlaceholderLike; // Things stored inside of tys type ErrorGuaranteed: Copy + Debug + Hash + Eq; @@ -53,46 +38,24 @@ pub trait Interner: Sized + Copy + IrPrint> { type Pat: Copy + Debug + Hash + Eq + DebugWithInfcx; // Kinds of consts - type Const: Copy - + DebugWithInfcx - + Hash - + Eq - + Into - + IntoKind> - + TypeSuperVisitable - + TypeSuperFoldable - + Flags - + Const; + type Const: Const; type AliasConst: Copy + DebugWithInfcx + Hash + Eq; - type PlaceholderConst: Copy + Debug + Hash + Eq + PlaceholderLike; + type PlaceholderConst: PlaceholderLike; type ParamConst: Copy + Debug + Hash + Eq; type BoundConst: Copy + Debug + Hash + Eq; type ValueConst: Copy + Debug + Hash + Eq; type ExprConst: Copy + DebugWithInfcx + Hash + Eq; // Kinds of regions - type Region: Copy - + DebugWithInfcx - + Hash - + Eq - + Into - + IntoKind> - + Flags - + Region; + type Region: Region; type EarlyParamRegion: Copy + Debug + Hash + Eq; type LateParamRegion: Copy + Debug + Hash + Eq; type BoundRegion: Copy + Debug + Hash + Eq; type InferRegion: Copy + DebugWithInfcx + Hash + Eq; - type PlaceholderRegion: Copy + Debug + Hash + Eq + PlaceholderLike; + type PlaceholderRegion: PlaceholderLike; // Predicates - type Predicate: Copy - + Debug - + Hash - + Eq - + TypeSuperVisitable - + TypeSuperFoldable - + Flags; + type Predicate: Predicate; type TraitPredicate: Copy + Debug + Hash + Eq; type RegionOutlivesPredicate: Copy + Debug + Hash + Eq; type TypeOutlivesPredicate: Copy + Debug + Hash + Eq; diff --git a/compiler/rustc_type_ir/src/ir_print.rs b/compiler/rustc_type_ir/src/ir_print.rs index 265c582ac44..84e889b486a 100644 --- a/compiler/rustc_type_ir/src/ir_print.rs +++ b/compiler/rustc_type_ir/src/ir_print.rs @@ -8,7 +8,7 @@ pub trait IrPrint { } macro_rules! define_display_via_print { - ($($ty:ident,)*) => { + ($($ty:ident),+ $(,)?) => { $( impl fmt::Display for $ty { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/compiler/rustc_type_ir/src/trait_ref.rs b/compiler/rustc_type_ir/src/trait_ref.rs index a91fd1b2911..4bd513ab7e1 100644 --- a/compiler/rustc_type_ir/src/trait_ref.rs +++ b/compiler/rustc_type_ir/src/trait_ref.rs @@ -31,7 +31,7 @@ pub struct TraitRef { pub args: I::GenericArgs, /// This field exists to prevent the creation of `TraitRef` without /// calling [`TraitRef::new`]. - pub(super) _use_trait_ref_new_instead: (), + _use_trait_ref_new_instead: (), } impl TraitRef {