Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn render_region_vid<'tcx>(
format!(" (for<{}>)", tcx.item_name(def_id))
}
ty::BoundRegionKind::ClosureEnv | ty::BoundRegionKind::Anon => " (for<'_>)".to_string(),
ty::BoundRegionKind::NamedAnon(_) => {
ty::BoundRegionKind::NamedForPrinting(_) => {
bug!("only used for pretty printing")
}
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
ty::BoundRegionKind::Anon => sym::anon,
ty::BoundRegionKind::Named(def_id) => tcx.item_name(def_id),
ty::BoundRegionKind::ClosureEnv => sym::env,
ty::BoundRegionKind::NamedAnon(_) => {
ty::BoundRegionKind::NamedForPrinting(_) => {
bug!("only used for pretty printing")
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
ty::BoundRegionKind::Anon => sym::anon,
ty::BoundRegionKind::Named(def_id) => self.type_checker.tcx().item_name(def_id),
ty::BoundRegionKind::ClosureEnv => sym::env,
ty::BoundRegionKind::NamedAnon(_) => bug!("only used for pretty printing"),
ty::BoundRegionKind::NamedForPrinting(_) => bug!("only used for pretty printing"),
};

if cfg!(debug_assertions) {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
.delayed_bug(format!("unexpected bound region kind: {:?}", br.kind));
return ControlFlow::Break(guar);
}
ty::BoundRegionKind::NamedAnon(_) => bug!("only used for pretty printing"),
ty::BoundRegionKind::NamedForPrinting(_) => {
bug!("only used for pretty printing")
}
});
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ where
&mut self,
origin: infer::SubregionOrigin<'tcx>,
region: ty::Region<'tcx>,
placeholder_ty: ty::PlaceholderType<'tcx>,
placeholder_ty: ty::PlaceholderType<TyCtxt<'tcx>>,
) {
let verify_bound = self
.verify_bound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<'a, 'tcx> LeakCheck<'a, 'tcx> {

fn error(
&self,
placeholder: ty::PlaceholderRegion<'tcx>,
placeholder: ty::PlaceholderRegion<TyCtx<'tcx>>,
other_region: ty::Region<'tcx>,
) -> TypeError<'tcx> {
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'tcx> Const<'tcx> {
#[inline]
pub fn new_placeholder(
tcx: TyCtxt<'tcx>,
placeholder: ty::PlaceholderConst<'tcx>,
placeholder: ty::PlaceholderConst<TyCtxt<'tcx>>,
) -> Const<'tcx> {
Const::new(tcx, ty::ConstKind::Placeholder(placeholder))
}
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
Const::new_canonical_bound(tcx, var)
}

fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<'tcx>) -> Self {
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<TyCtxt<'tcx>>) -> Self {
Const::new_placeholder(tcx, placeholder)
}

Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {

type FnInputTys = &'tcx [Ty<'tcx>];
type ParamTy = ParamTy;
type BoundTy = ty::BoundTy;
type Symbol = Symbol;

type PlaceholderTy = ty::PlaceholderType<'tcx>;
type PlaceholderTy = ty::PlaceholderType<TyCtxt<'tcx>>;
type ErrorGuaranteed = ErrorGuaranteed;
type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;

Expand All @@ -158,10 +157,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type Safety = hir::Safety;
type Abi = ExternAbi;
type Const = ty::Const<'tcx>;
type PlaceholderConst = ty::PlaceholderConst<'tcx>;

type ParamConst = ty::ParamConst;
type BoundConst = ty::BoundConst;
type ValueConst = ty::Value<'tcx>;
type ExprConst = ty::Expr<'tcx>;
type ValTree = ty::ValTree<'tcx>;
Expand All @@ -171,7 +168,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type EarlyParamRegion = ty::EarlyParamRegion;
type LateParamRegion = ty::LateParamRegion;
type BoundRegion = ty::BoundRegion;
type PlaceholderRegion = ty::PlaceholderRegion<'tcx>;
type BoundRegionKind = ty::BoundRegionKind;
type BoundVariableKind = ty::BoundVariableKind;

type RegionAssumptions = &'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>>;

Expand Down
94 changes: 0 additions & 94 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,100 +914,6 @@ impl<'tcx> DefinitionSiteHiddenType<'tcx> {
}
}

pub type PlaceholderRegion<'tcx> = ty::Placeholder<TyCtxt<'tcx>, BoundRegion>;

impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderRegion<'tcx> {
type Bound = BoundRegion;

fn universe(self) -> UniverseIndex {
self.universe
}

fn var(self) -> BoundVar {
self.bound.var
}

fn with_updated_universe(self, ui: UniverseIndex) -> Self {
ty::Placeholder::new(ui, self.bound)
}

fn new(ui: UniverseIndex, bound: BoundRegion) -> Self {
ty::Placeholder::new(ui, bound)
}

fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
ty::Placeholder::new(ui, BoundRegion { var, kind: BoundRegionKind::Anon })
}
}

pub type PlaceholderType<'tcx> = ty::Placeholder<TyCtxt<'tcx>, BoundTy>;

impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderType<'tcx> {
type Bound = BoundTy;

fn universe(self) -> UniverseIndex {
self.universe
}

fn var(self) -> BoundVar {
self.bound.var
}

fn with_updated_universe(self, ui: UniverseIndex) -> Self {
ty::Placeholder::new(ui, self.bound)
}

fn new(ui: UniverseIndex, bound: BoundTy) -> Self {
ty::Placeholder::new(ui, bound)
}

fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
ty::Placeholder::new(ui, BoundTy { var, kind: BoundTyKind::Anon })
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
#[derive(TyEncodable, TyDecodable)]
pub struct BoundConst {
pub var: BoundVar,
}

impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundConst {
fn var(self) -> BoundVar {
self.var
}

fn assert_eq(self, var: ty::BoundVariableKind) {
var.expect_const()
}
}

pub type PlaceholderConst<'tcx> = ty::Placeholder<TyCtxt<'tcx>, BoundConst>;

impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderConst<'tcx> {
type Bound = BoundConst;

fn universe(self) -> UniverseIndex {
self.universe
}

fn var(self) -> BoundVar {
self.bound.var
}

fn with_updated_universe(self, ui: UniverseIndex) -> Self {
ty::Placeholder::new(ui, self.bound)
}

fn new(ui: UniverseIndex, bound: BoundConst) -> Self {
ty::Placeholder::new(ui, bound)
}

fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
ty::Placeholder::new(ui, BoundConst { var })
}
}

pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo<Clause<'tcx>>;

impl<'tcx> rustc_type_ir::Flags for Clauses<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
(name, br.kind)
} else {
let name = next_name(self);
(name, ty::BoundRegionKind::NamedAnon(name))
(name, ty::BoundRegionKind::NamedForPrinting(name))
};

if let Some(lt_idx) = lifetime_idx {
Expand Down
95 changes: 43 additions & 52 deletions compiler/rustc_middle/src/ty/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ impl LateParamRegionKind {
BoundRegionKind::Anon => LateParamRegionKind::Anon(var.as_u32()),
BoundRegionKind::Named(def_id) => LateParamRegionKind::Named(def_id),
BoundRegionKind::ClosureEnv => LateParamRegionKind::ClosureEnv,
BoundRegionKind::NamedAnon(name) => LateParamRegionKind::NamedAnon(var.as_u32(), name),
BoundRegionKind::NamedForPrinting(name) => {
LateParamRegionKind::NamedAnon(var.as_u32(), name)
}
}
}

Expand All @@ -450,56 +452,45 @@ impl LateParamRegionKind {
}
}

#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
#[derive(HashStable)]
pub enum BoundRegionKind {
/// An anonymous region parameter for a given fn (&T)
Anon,

/// An anonymous region parameter with a `Symbol` name.
///
/// Used to give late-bound regions names for things like pretty printing.
NamedAnon(Symbol),

/// Late-bound regions that appear in the AST.
Named(DefId),

/// Anonymous region for the implicit env pointer parameter
/// to a closure
ClosureEnv,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable)]
pub struct BoundRegion {
pub var: BoundVar,
pub kind: BoundRegionKind,
}

impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundRegion {
fn var(self) -> BoundVar {
self.var
}

fn assert_eq(self, var: ty::BoundVariableKind) {
assert_eq!(self.kind, var.expect_region())
}
}

impl core::fmt::Debug for BoundRegion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.kind {
BoundRegionKind::Anon => write!(f, "{:?}", self.var),
BoundRegionKind::ClosureEnv => write!(f, "{:?}.Env", self.var),
BoundRegionKind::Named(def) => {
write!(f, "{:?}.Named({:?})", self.var, def)
}
BoundRegionKind::NamedAnon(symbol) => {
write!(f, "{:?}.NamedAnon({:?})", self.var, symbol)
}
}
}
}
//#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
//#[derive(HashStable)]
//pub enum BoundRegionKind {
// /// An anonymous region parameter for a given fn (&T)
// Anon,
//
// /// An anonymous region parameter with a `Symbol` name.
// ///
// /// Used to give late-bound regions names for things like pretty printing.
// NamedAnon(Symbol),
//
// /// Late-bound regions that appear in the AST.
// Named(DefId),
//
// /// Anonymous region for the implicit env pointer parameter
// /// to a closure
// ClosureEnv,
//}

//#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
//#[derive(HashStable)]
//pub struct BoundRegion {
// pub var: BoundVar,
// pub kind: BoundRegionKind,
//}
//
//impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundRegion {
// fn var(self) -> BoundVar {
// self.var
// }
//
// fn assert_eq(self, var: ty::BoundVariableKind) {
// assert_eq!(self.kind, var.expect_region())
// }
//
// fn new(var: BoundVar, kind: BoundRegionKind) -> Self {
// Self { var, kind }
// }
//}

impl BoundRegionKind {
pub fn is_named(&self, tcx: TyCtxt<'_>) -> bool {
Expand All @@ -512,7 +503,7 @@ impl BoundRegionKind {
let name = tcx.item_name(def_id);
if name != kw::UnderscoreLifetime { Some(name) } else { None }
}
BoundRegionKind::NamedAnon(name) => Some(name),
BoundRegionKind::NamedForPrinting(name) => Some(name),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl fmt::Debug for ty::BoundRegionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ty::BoundRegionKind::Anon => write!(f, "BrAnon"),
ty::BoundRegionKind::NamedAnon(name) => {
ty::BoundRegionKind::NamedForPrinting(name) => {
write!(f, "BrNamedAnon({name})")
}
ty::BoundRegionKind::Named(did) => {
Expand Down
Loading
Loading