From d3157c3414b86f5931b0b834a82a357a10483646 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Apr 2026 16:48:50 +1000 Subject: [PATCH 1/6] Remove unnecessary `lift` calls. Various places where `lift` just isn't necessary. --- compiler/rustc_middle/src/mir/pretty.rs | 4 ---- .../rustc_public/src/unstable/convert/internal.rs | 15 +++++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index d160aada80a83..9c7f591155b52 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1911,8 +1911,6 @@ fn pretty_print_const_value_tcx<'tcx>( // E.g. `transmute([0usize; 2]): (u8, *mut T)` needs to know `T: Sized` // to be able to destructure the tuple into `(0u8, *mut T)` (_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_non_region_param() => { - let ct = tcx.lift(ct).unwrap(); - let ty = tcx.lift(ty).unwrap(); if let Some(contents) = tcx.try_destructure_mir_constant_for_user_output(ct, ty) { let fields: Vec<(ConstValue, Ty<'_>)> = contents.fields.to_vec(); match *ty.kind() { @@ -1937,7 +1935,6 @@ fn pretty_print_const_value_tcx<'tcx>( .variant .expect("destructed mir constant of adt without variant idx"); let variant_def = &def.variant(variant_idx); - let args = tcx.lift(args).unwrap(); let mut p = FmtPrinter::new(tcx, Namespace::ValueNS); p.print_alloc_ids = true; p.pretty_print_value_path(variant_def.def_id, args)?; @@ -1974,7 +1971,6 @@ fn pretty_print_const_value_tcx<'tcx>( (ConstValue::Scalar(scalar), _) => { let mut p = FmtPrinter::new(tcx, Namespace::ValueNS); p.print_alloc_ids = true; - let ty = tcx.lift(ty).unwrap(); p.pretty_print_const_scalar(scalar, ty)?; fmt.write_str(&p.into_buffer())?; return Ok(()); diff --git a/compiler/rustc_public/src/unstable/convert/internal.rs b/compiler/rustc_public/src/unstable/convert/internal.rs index eb56397cdca64..ba21f807e8a7b 100644 --- a/compiler/rustc_public/src/unstable/convert/internal.rs +++ b/compiler/rustc_public/src/unstable/convert/internal.rs @@ -49,9 +49,9 @@ impl RustcInternal for DefId { fn internal<'tcx>( &self, tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - tcx.lift(tables.def_ids[*self]).unwrap() + tables.def_ids[*self] } } @@ -78,7 +78,7 @@ impl RustcInternal for GenericArgKind { GenericArgKind::Type(ty) => ty.internal(tables, tcx).into(), GenericArgKind::Const(cnst) => cnst.internal(tables, tcx).into(), }; - tcx.lift(arg).unwrap() + arg } } @@ -316,11 +316,10 @@ impl RustcInternal for FnSig { .set_abi(self.abi.internal(tables, tcx)) .set_safe(self.safety == Safety::Safe) .set_c_variadic(self.c_variadic); - tcx.lift(rustc_ty::FnSig { + rustc_ty::FnSig { inputs_and_output: tcx.mk_type_list(&self.inputs_and_output.internal(tables, tcx)), fn_sig_kind, - }) - .unwrap() + } } } @@ -553,9 +552,9 @@ impl RustcInternal for AllocId { fn internal<'tcx>( &self, tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - tcx.lift(tables.alloc_ids[*self]).unwrap() + tables.alloc_ids[*self] } } From 78d73d19126127b6d7a01024cf132fba4f4d9eab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Apr 2026 18:57:33 +1000 Subject: [PATCH 2/6] Adjust lifetimes on `tls::with*` functions. By moving the lifetimes from the closures to the enclosing function, we no longer need to call `lift` within them. --- .../rustc_const_eval/src/interpret/operand.rs | 12 ++++-------- compiler/rustc_middle/src/mir/consts.rs | 1 - compiler/rustc_middle/src/mir/pretty.rs | 8 +------- compiler/rustc_middle/src/ty/consts/valtree.rs | 3 +-- compiler/rustc_middle/src/ty/context/tls.rs | 16 ++++++++-------- compiler/rustc_middle/src/ty/instance.rs | 3 +-- compiler/rustc_middle/src/ty/print/mod.rs | 7 +++---- compiler/rustc_middle/src/ty/print/pretty.rs | 7 ++----- 8 files changed, 20 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 6c9cd2e608ae1..dc54fc28f1bec 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -216,14 +216,10 @@ impl std::fmt::Display for ImmTy<'_, Prov> { ty::tls::with(|tcx| { match self.imm { Immediate::Scalar(s) => { - if let Some(ty) = tcx.lift(self.layout.ty) { - let s = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| { - print_scalar(p, s, ty) - })?; - f.write_str(&s)?; - return Ok(()); - } - write!(f, "{:x}: {}", s, self.layout.ty) + let s = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| { + print_scalar(p, s, self.layout.ty) + })?; + f.write_str(&s) } Immediate::ScalarPair(a, b) => { // FIXME(oli-obk): at least print tuples and slices nicely diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index de3ef6deca1fc..fd07455917246 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -493,7 +493,6 @@ impl<'tcx> Display for Const<'tcx> { // FIXME(valtrees): Correctly print mir constants. Const::Unevaluated(c, _ty) => { ty::tls::with(move |tcx| { - let c = tcx.lift(c).unwrap(); // Matches `GlobalId` printing. let instance = with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args)); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 9c7f591155b52..8c8145229fd50 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1165,7 +1165,6 @@ impl<'tcx> Debug for Rvalue<'tcx> { AggregateKind::Adt(adt_did, variant, args, _user_ty, _) => { ty::tls::with(|tcx| { let variant_def = &tcx.adt_def(adt_did).variant(variant); - let args = tcx.lift(args).expect("could not lift for printing"); let name = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| { p.print_def_path(variant_def.def_id, args) })?; @@ -1187,7 +1186,6 @@ impl<'tcx> Debug for Rvalue<'tcx> { AggregateKind::Closure(def_id, args) | AggregateKind::CoroutineClosure(def_id, args) => ty::tls::with(|tcx| { let name = if tcx.sess.opts.unstable_opts.span_free_formats { - let args = tcx.lift(args).unwrap(); format!("{{closure@{}}}", tcx.def_path_str_with_args(def_id, args),) } else { let span = tcx.def_span(def_id); @@ -1995,11 +1993,7 @@ pub(crate) fn pretty_print_const_value<'tcx>( ty: Ty<'tcx>, fmt: &mut Formatter<'_>, ) -> fmt::Result { - ty::tls::with(|tcx| { - let ct = tcx.lift(ct).unwrap(); - let ty = tcx.lift(ty).unwrap(); - pretty_print_const_value_tcx(tcx, ct, ty, fmt) - }) + ty::tls::with(|tcx| pretty_print_const_value_tcx(tcx, ct, ty, fmt)) } /////////////////////////////////////////////////////////////////////////// diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 50242613b3e7f..c1fabbdec49ea 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -238,9 +238,8 @@ impl<'tcx> rustc_type_ir::inherent::ValueConst> for Value<'tcx> { impl<'tcx> fmt::Display for Value<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::tls::with(move |tcx| { - let cv = tcx.lift(*self).unwrap(); let mut p = FmtPrinter::new(tcx, Namespace::ValueNS); - p.pretty_print_const_valtree(cv, /*print_ty*/ true)?; + p.pretty_print_const_valtree(*self, /*print_ty*/ true)?; f.write_str(&p.into_buffer()) }) } diff --git a/compiler/rustc_middle/src/ty/context/tls.rs b/compiler/rustc_middle/src/ty/context/tls.rs index d1561c37172c3..d655565581999 100644 --- a/compiler/rustc_middle/src/ty/context/tls.rs +++ b/compiler/rustc_middle/src/ty/context/tls.rs @@ -60,9 +60,9 @@ where /// Allows access to the current `ImplicitCtxt` in a closure if one is available. #[inline] #[track_caller] -pub fn with_context_opt(f: F) -> R +pub fn with_context_opt<'a, 'tcx: 'a, F, R>(f: F) -> R where - F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R, + F: FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R, { let context = TLV.get(); if context.is_null() { @@ -79,9 +79,9 @@ where /// Allows access to the current `ImplicitCtxt`. /// Panics if there is no `ImplicitCtxt` available. #[inline] -pub fn with_context(f: F) -> R +pub fn with_context<'a, 'tcx: 'a, F, R>(f: F) -> R where - F: for<'a, 'tcx> FnOnce(&ImplicitCtxt<'a, 'tcx>) -> R, + F: FnOnce(&ImplicitCtxt<'a, 'tcx>) -> R, { with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls"))) } @@ -89,9 +89,9 @@ where /// Allows access to the `TyCtxt` in the current `ImplicitCtxt`. /// Panics if there is no `ImplicitCtxt` available. #[inline] -pub fn with(f: F) -> R +pub fn with<'tcx, F, R>(f: F) -> R where - F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> R, + F: FnOnce(TyCtxt<'tcx>) -> R, { with_context(|context| f(context.tcx)) } @@ -100,9 +100,9 @@ where /// The closure is passed None if there is no `ImplicitCtxt` available. #[inline] #[track_caller] -pub fn with_opt(f: F) -> R +pub fn with_opt<'tcx, F, R>(f: F) -> R where - F: for<'tcx> FnOnce(Option>) -> R, + F: FnOnce(Option>) -> R, { with_context_opt( #[track_caller] diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 408edf19dbf23..899cd1717bc10 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -381,8 +381,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::tls::with(|tcx| { let mut p = FmtPrinter::new(tcx, Namespace::ValueNS); - let instance = tcx.lift(*self).expect("could not lift for printing"); - instance.print(&mut p)?; + self.print(&mut p)?; let s = p.into_buffer(); f.write_str(&s) }) diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index d2ae226c4d8dc..40d71b0e14fc0 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -11,7 +11,6 @@ use crate::ty::{self, GenericArg, Ty, TyCtxt}; // `pretty` is a separate module only for organization. mod pretty; pub use self::pretty::*; -use super::Lift; pub type PrintError = std::fmt::Error; @@ -411,14 +410,14 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Const<'tcx> { } } -impl rustc_type_ir::ir_print::IrPrint for TyCtxt<'_> +impl<'a, 'tcx, T> rustc_type_ir::ir_print::IrPrint for TyCtxt<'tcx> where - T: Copy + for<'a, 'tcx> Lift, Lifted: Print<'tcx, FmtPrinter<'a, 'tcx>>>, + T: Copy + Print<'tcx, FmtPrinter<'a, 'tcx>>, { fn print(t: &T, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { ty::tls::with(|tcx| { let mut p = FmtPrinter::new(tcx, Namespace::TypeNS); - tcx.lift(*t).expect("could not lift for printing").print(&mut p)?; + t.print(&mut p)?; fmt.write_str(&p.into_buffer())?; Ok(()) }) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 1b2332098665a..a76d72677b2f2 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2082,10 +2082,9 @@ pub(crate) fn pretty_print_const<'tcx>( print_types: bool, ) -> fmt::Result { ty::tls::with(|tcx| { - let literal = tcx.lift(c).unwrap(); let mut p = FmtPrinter::new(tcx, Namespace::ValueNS); p.print_alloc_ids = true; - p.pretty_print_const(literal, print_types)?; + p.pretty_print_const(c, print_types)?; fmt.write_str(&p.into_buffer())?; Ok(()) }) @@ -3097,9 +3096,7 @@ macro_rules! forward_display_to_print { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::tls::with(|tcx| { let mut p = FmtPrinter::new(tcx, Namespace::TypeNS); - tcx.lift(*self) - .expect("could not lift for printing") - .print(&mut p)?; + self.print(&mut p)?; f.write_str(&p.into_buffer())?; Ok(()) }) From fc61b67bd0b5ef063ae39284ede1162591c53b7f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Apr 2026 19:40:37 +1000 Subject: [PATCH 3/6] Adjust lifetimes on `FmtPrinter` and `Print`. By using 'tcx in the right places and avoiding HRTBs, we can avoid some more lifting. --- compiler/rustc_middle/src/ty/error.rs | 36 +++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index a4c30f1f88434..5f77bcfefad6f 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -12,7 +12,7 @@ use rustc_macros::extension; pub use rustc_type_ir::error::ExpectedFound; use crate::ty::print::{FmtPrinter, Print, with_forced_trimmed_paths}; -use crate::ty::{self, Lift, Ty, TyCtxt}; +use crate::ty::{self, Ty, TyCtxt}; pub type TypeError<'tcx> = rustc_type_ir::error::TypeError>; @@ -218,15 +218,18 @@ impl<'tcx> Ty<'tcx> { } impl<'tcx> TyCtxt<'tcx> { - pub fn string_with_limit(self, t: T, length_limit: usize, ns: hir::def::Namespace) -> String + pub fn string_with_limit<'a, T>( + self, + t: T, + length_limit: usize, + ns: hir::def::Namespace, + ) -> String where - T: Copy + for<'a, 'b> Lift, Lifted: Print<'b, FmtPrinter<'a, 'b>>>, + T: Copy + Print<'tcx, FmtPrinter<'a, 'tcx>>, { let mut type_limit = 50; - let regular = FmtPrinter::print_string(self, ns, |p| { - self.lift(t).expect("could not lift for printing").print(p) - }) - .expect("could not write to `String`"); + let regular = FmtPrinter::print_string(self, ns, |p| t.print(p)) + .expect("could not write to `String`"); if regular.len() <= length_limit { return regular; } @@ -235,10 +238,7 @@ impl<'tcx> TyCtxt<'tcx> { // Look for the longest properly trimmed path that still fits in length_limit. short = with_forced_trimmed_paths!({ let mut p = FmtPrinter::new_with_limit(self, ns, Limit(type_limit)); - self.lift(t) - .expect("could not lift for printing") - .print(&mut p) - .expect("could not print type"); + t.print(&mut p).expect("could not print type"); p.into_buffer() }); if short.len() <= length_limit || type_limit == 0 { @@ -253,9 +253,9 @@ impl<'tcx> TyCtxt<'tcx> { /// `tcx.short_string(ty, diag.long_ty_path())`. The diagnostic itself is the one that keeps /// the existence of a "long type" anywhere in the diagnostic, so the note telling the user /// where we wrote the file to is only printed once. The path will use the type namespace. - pub fn short_string(self, t: T, path: &mut Option) -> String + pub fn short_string<'a, T>(self, t: T, path: &mut Option) -> String where - T: Copy + Hash + for<'a, 'b> Lift, Lifted: Print<'b, FmtPrinter<'a, 'b>>>, + T: Copy + Hash + Print<'tcx, FmtPrinter<'a, 'tcx>>, { self.short_string_namespace(t, path, hir::def::Namespace::TypeNS) } @@ -264,19 +264,17 @@ impl<'tcx> TyCtxt<'tcx> { /// `tcx.short_string(ty, diag.long_ty_path())`. The diagnostic itself is the one that keeps /// the existence of a "long type" anywhere in the diagnostic, so the note telling the user /// where we wrote the file to is only printed once. - pub fn short_string_namespace( + pub fn short_string_namespace<'a, T>( self, t: T, path: &mut Option, namespace: hir::def::Namespace, ) -> String where - T: Copy + Hash + for<'a, 'b> Lift, Lifted: Print<'b, FmtPrinter<'a, 'b>>>, + T: Copy + Hash + Print<'tcx, FmtPrinter<'a, 'tcx>>, { - let regular = FmtPrinter::print_string(self, namespace, |p| { - self.lift(t).expect("could not lift for printing").print(p) - }) - .expect("could not write to `String`"); + let regular = FmtPrinter::print_string(self, namespace, |p| t.print(p)) + .expect("could not write to `String`"); if !self.sess.opts.unstable_opts.write_long_types_to_disk || self.sess.opts.verbose { return regular; From ca51624495e148e829a8dbf7e587c5057f10cf27 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Apr 2026 19:30:02 +1000 Subject: [PATCH 4/6] Adjust lifetimes on `RustcInternal`. As in the previous commits, increased use of 'tcx and avoidance of HRTBs avoids the need for some lifting. --- .../rustc_public/src/compiler_interface.rs | 4 +- .../rustc_public/src/rustc_internal/mod.rs | 4 +- .../src/unstable/convert/internal.rs | 121 +++++++++--------- compiler/rustc_public/src/unstable/mod.rs | 2 +- 4 files changed, 63 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_public/src/compiler_interface.rs b/compiler/rustc_public/src/compiler_interface.rs index c2f36bea81ca6..64c4ebcb5d462 100644 --- a/compiler/rustc_public/src/compiler_interface.rs +++ b/compiler/rustc_public/src/compiler_interface.rs @@ -897,12 +897,12 @@ where /// /// I.e., This function will load the current interface and calls a function with it. /// Do not nest these, as that will ICE. -pub(crate) fn with(f: impl for<'tcx> FnOnce(&CompilerInterface<'tcx>) -> R) -> R { +pub(crate) fn with<'tcx, R>(f: impl FnOnce(&CompilerInterface<'tcx>) -> R) -> R { assert!(TLV.is_set()); TLV.with(|tlv| { let ptr = tlv.get(); assert!(!ptr.is_null()); - f(unsafe { *(ptr as *const &CompilerInterface<'_>) }) + f(unsafe { *(ptr as *const &CompilerInterface<'tcx>) }) }) } diff --git a/compiler/rustc_public/src/rustc_internal/mod.rs b/compiler/rustc_public/src/rustc_internal/mod.rs index 49dc64572923a..95954bb23d882 100644 --- a/compiler/rustc_public/src/rustc_internal/mod.rs +++ b/compiler/rustc_public/src/rustc_internal/mod.rs @@ -58,8 +58,8 @@ pub fn crate_num(item: &crate::Crate) -> CrateNum { /// Loads the current context and calls a function with it. /// Do not nest these, as that will ICE. -pub(crate) fn with_bridge( - f: impl for<'tcx> FnOnce(&mut Tables<'tcx, BridgeTys>, &CompilerCtxt<'tcx, BridgeTys>) -> R, +pub(crate) fn with_bridge<'tcx, R>( + f: impl FnOnce(&mut Tables<'tcx, BridgeTys>, &CompilerCtxt<'tcx, BridgeTys>) -> R, ) -> R { with(|compiler| { let mut tables = compiler.tables.borrow_mut(); diff --git a/compiler/rustc_public/src/unstable/convert/internal.rs b/compiler/rustc_public/src/unstable/convert/internal.rs index ba21f807e8a7b..1d15ee7247606 100644 --- a/compiler/rustc_public/src/unstable/convert/internal.rs +++ b/compiler/rustc_public/src/unstable/convert/internal.rs @@ -26,7 +26,7 @@ impl RustcInternal for CrateItem { type T<'tcx> = rustc_span::def_id::DefId; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { self.0.internal(tables, tcx) @@ -37,7 +37,7 @@ impl RustcInternal for CrateNum { type T<'tcx> = rustc_span::def_id::CrateNum; fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { rustc_span::def_id::CrateNum::from_usize(self.0) @@ -48,7 +48,7 @@ impl RustcInternal for DefId { type T<'tcx> = rustc_span::def_id::DefId; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { tables.def_ids[*self] @@ -59,7 +59,7 @@ impl RustcInternal for GenericArgs { type T<'tcx> = rustc_ty::GenericArgsRef<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { InternalCx::mk_args_from_iter(tcx, self.0.iter().map(|arg| arg.internal(tables, tcx))) @@ -70,7 +70,7 @@ impl RustcInternal for GenericArgKind { type T<'tcx> = rustc_ty::GenericArg<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { let arg: rustc_ty::GenericArg<'tcx> = match self { @@ -86,7 +86,7 @@ impl RustcInternal for Region { type T<'tcx> = rustc_ty::Region<'tcx>; fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { // Cannot recover region. Use erased for now. @@ -98,10 +98,10 @@ impl RustcInternal for Ty { type T<'tcx> = InternalTy<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + tables: &mut Tables<'tcx, BridgeTys>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - tcx.lift(tables.types[*self]).unwrap() + tables.types[*self] } } @@ -109,10 +109,10 @@ impl RustcInternal for TyConst { type T<'tcx> = InternalConst<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + tables: &mut Tables<'tcx, BridgeTys>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - tcx.lift(tables.ty_consts[self.id]).unwrap() + tables.ty_consts[self.id] } } @@ -120,7 +120,7 @@ impl RustcInternal for Pattern { type T<'tcx> = rustc_ty::Pattern<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { tcx.mk_pat(match self { @@ -141,7 +141,7 @@ impl RustcInternal for RigidTy { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -208,7 +208,7 @@ impl RustcInternal for IntTy { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -227,7 +227,7 @@ impl RustcInternal for UintTy { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -246,7 +246,7 @@ impl RustcInternal for FloatTy { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -263,7 +263,7 @@ impl RustcInternal for Mutability { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -278,7 +278,7 @@ impl RustcInternal for Movability { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -293,7 +293,7 @@ impl RustcInternal for RawPtrKind { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -309,7 +309,7 @@ impl RustcInternal for FnSig { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { let fn_sig_kind = rustc_ty::FnSigKind::default() @@ -328,7 +328,7 @@ impl RustcInternal for VariantIdx { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { rustc_abi::VariantIdx::from(self.to_index()) @@ -340,7 +340,7 @@ impl RustcInternal for VariantDef { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { self.adt_def.internal(tables, tcx).variant(self.idx.internal(tables, tcx)) @@ -351,22 +351,17 @@ impl RustcInternal for MirConst { type T<'tcx> = rustc_middle::mir::Const<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + tables: &mut Tables<'tcx, BridgeTys>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { let constant = tables.mir_consts[self.id]; match constant { - rustc_middle::mir::Const::Ty(ty, ct) => { - rustc_middle::mir::Const::Ty(tcx.lift(ty).unwrap(), tcx.lift(ct).unwrap()) - } + rustc_middle::mir::Const::Ty(ty, ct) => rustc_middle::mir::Const::Ty(ty, ct), rustc_middle::mir::Const::Unevaluated(uneval, ty) => { - rustc_middle::mir::Const::Unevaluated( - tcx.lift(uneval).unwrap(), - tcx.lift(ty).unwrap(), - ) + rustc_middle::mir::Const::Unevaluated(uneval, ty) } rustc_middle::mir::Const::Val(const_val, ty) => { - rustc_middle::mir::Const::Val(tcx.lift(const_val).unwrap(), tcx.lift(ty).unwrap()) + rustc_middle::mir::Const::Val(const_val, ty) } } } @@ -377,7 +372,7 @@ impl RustcInternal for MonoItem { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { use rustc_middle::mono as rustc_mono; @@ -396,10 +391,10 @@ impl RustcInternal for Instance { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + tables: &mut Tables<'tcx, BridgeTys>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - tcx.lift(tables.instances[self.def]).unwrap() + tables.instances[self.def] } } @@ -408,7 +403,7 @@ impl RustcInternal for StaticDef { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { self.0.internal(tables, tcx) @@ -425,7 +420,7 @@ where fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { rustc_ty::Binder::bind_with_vars( @@ -442,7 +437,7 @@ impl RustcInternal for BoundVariableKind { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -469,7 +464,7 @@ impl RustcInternal for ExistentialPredicate { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -491,7 +486,7 @@ impl RustcInternal for ExistentialProjection { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { use crate::unstable::internal_cx::ExistentialProjectionHelpers; @@ -508,7 +503,7 @@ impl RustcInternal for TermKind { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -523,7 +518,7 @@ impl RustcInternal for ExistentialTraitRef { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { use crate::unstable::internal_cx::ExistentialTraitRefHelpers; @@ -539,7 +534,7 @@ impl RustcInternal for TraitRef { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { use crate::unstable::internal_cx::TraitRefHelpers; @@ -551,7 +546,7 @@ impl RustcInternal for AllocId { type T<'tcx> = rustc_middle::mir::interpret::AllocId; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { tables.alloc_ids[*self] @@ -563,7 +558,7 @@ impl RustcInternal for ClosureKind { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -578,7 +573,7 @@ impl RustcInternal for AdtDef { type T<'tcx> = rustc_ty::AdtDef<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { InternalCx::adt_def(tcx, self.0.internal(tables, tcx)) @@ -590,7 +585,7 @@ impl RustcInternal for Abi { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match *self { @@ -631,7 +626,7 @@ impl RustcInternal for Safety { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -646,7 +641,7 @@ impl RustcInternal for Constness { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -661,7 +656,7 @@ impl RustcInternal for Asyncness { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -675,7 +670,7 @@ impl RustcInternal for Span { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { tables.spans[*self] @@ -687,10 +682,10 @@ impl RustcInternal for Layout { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, - tcx: impl InternalCx<'tcx>, + tables: &mut Tables<'tcx, BridgeTys>, + _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - tcx.lift(tables.layouts[*self]).unwrap() + tables.layouts[*self] } } @@ -699,7 +694,7 @@ impl RustcInternal for Place { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { rustc_middle::mir::Place { @@ -714,7 +709,7 @@ impl RustcInternal for ProjectionElem { fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -748,7 +743,7 @@ impl RustcInternal for BinOp { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -784,7 +779,7 @@ impl RustcInternal for UnOp { fn internal<'tcx>( &self, - _tables: &mut Tables<'_, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, _tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { match self { @@ -803,7 +798,7 @@ where fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { (*self).internal(tables, tcx) @@ -818,7 +813,7 @@ where fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { self.as_ref().map(|inner| inner.internal(tables, tcx)) @@ -833,7 +828,7 @@ where fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { self.iter().map(|e| e.internal(tables, tcx)).collect() diff --git a/compiler/rustc_public/src/unstable/mod.rs b/compiler/rustc_public/src/unstable/mod.rs index ec979eef40cd1..0e462e044d574 100644 --- a/compiler/rustc_public/src/unstable/mod.rs +++ b/compiler/rustc_public/src/unstable/mod.rs @@ -93,7 +93,7 @@ pub trait RustcInternal { type T<'tcx>; fn internal<'tcx>( &self, - tables: &mut Tables<'_, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx>; } From 4e4a2a757ec7e95d5728b912e44e15262edc4fe7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Apr 2026 19:52:53 +1000 Subject: [PATCH 5/6] Adjust lifetimes on `Stable`. Once again, increased use of 'tcx avoids the need for some lifting. --- .../rustc_public/src/unstable/convert/mod.rs | 36 +-- .../src/unstable/convert/stable/abi.rs | 92 +++--- .../src/unstable/convert/stable/mir.rs | 166 ++++++----- .../src/unstable/convert/stable/ty.rs | 261 +++++++++--------- compiler/rustc_public/src/unstable/mod.rs | 6 +- .../rustc_public_bridge/src/context/impls.rs | 8 +- 6 files changed, 281 insertions(+), 288 deletions(-) diff --git a/compiler/rustc_public/src/unstable/convert/mod.rs b/compiler/rustc_public/src/unstable/convert/mod.rs index f20406631e3ff..348813b2faefb 100644 --- a/compiler/rustc_public/src/unstable/convert/mod.rs +++ b/compiler/rustc_public/src/unstable/convert/mod.rs @@ -23,10 +23,10 @@ where { type T = T::T; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { (*self).stable(tables, cx) } @@ -38,10 +38,10 @@ where { type T = Option; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { self.as_ref().map(|value| value.stable(tables, cx)) } @@ -54,10 +54,10 @@ where { type T = Result; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { Ok(val) => Ok(val.stable(tables, cx)), @@ -71,10 +71,10 @@ where T: Stable<'tcx>, { type T = Vec; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { self.iter().map(|e| e.stable(tables, cx)).collect() } @@ -86,10 +86,10 @@ where U: Stable<'tcx>, { type T = (T::T, U::T); - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { (self.0.stable(tables, cx), self.1.stable(tables, cx)) } @@ -100,10 +100,10 @@ where T: Stable<'tcx>, { type T = RangeInclusive; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { RangeInclusive::new(self.start().stable(tables, cx), self.end().stable(tables, cx)) } diff --git a/compiler/rustc_public/src/unstable/convert/stable/abi.rs b/compiler/rustc_public/src/unstable/convert/stable/abi.rs index d8c4cee7abbe4..fe86e83b01df5 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/abi.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/abi.rs @@ -41,10 +41,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Endian { impl<'tcx> Stable<'tcx> for rustc_abi::TyAndLayout<'tcx, ty::Ty<'tcx>> { type T = TyAndLayout; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { TyAndLayout { ty: self.ty.stable(tables, cx), layout: self.layout.stable(tables, cx) } } @@ -53,22 +53,22 @@ impl<'tcx> Stable<'tcx> for rustc_abi::TyAndLayout<'tcx, ty::Ty<'tcx>> { impl<'tcx> Stable<'tcx> for rustc_abi::Layout<'tcx> { type T = Layout; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + _cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { - tables.layout_id(cx.lift(*self).unwrap()) + tables.layout_id(*self) } } impl<'tcx> Stable<'tcx> for rustc_abi::LayoutData { type T = LayoutShape; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { LayoutShape { fields: self.fields.stable(tables, cx), @@ -83,10 +83,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::LayoutData Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> { type T = FnAbi; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { assert!(self.args.len() >= self.fixed_count as usize); assert!(!self.c_variadic || matches!(self.conv, CanonAbi::C)); @@ -103,10 +103,10 @@ impl<'tcx> Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> { impl<'tcx> Stable<'tcx> for callconv::ArgAbi<'tcx, ty::Ty<'tcx>> { type T = ArgAbi; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { ArgAbi { ty: self.layout.ty.stable(tables, cx), @@ -178,10 +178,10 @@ impl<'tcx> Stable<'tcx> for callconv::PassMode { impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape { type T = FieldsShape; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { rustc_abi::FieldsShape::Primitive => FieldsShape::Primitive, @@ -199,10 +199,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape { impl<'tcx> Stable<'tcx> for rustc_abi::Variants { type T = VariantsShape; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { rustc_abi::Variants::Single { index } => { @@ -232,10 +232,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Variants Stable<'tcx> for rustc_abi::TagEncoding { type T = TagEncoding; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { rustc_abi::TagEncoding::Direct => TagEncoding::Direct, @@ -253,10 +253,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding { impl<'tcx> Stable<'tcx> for rustc_abi::NumScalableVectors { type T = NumScalableVectors; - fn stable<'cx>( + fn stable( &self, - _tables: &mut Tables<'cx, BridgeTys>, - _cx: &CompilerCtxt<'cx, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, + _cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { NumScalableVectors(self.0) } @@ -265,10 +265,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::NumScalableVectors { impl<'tcx> Stable<'tcx> for rustc_abi::BackendRepr { type T = ValueAbi; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match *self { rustc_abi::BackendRepr::Scalar(scalar) => ValueAbi::Scalar(scalar.stable(tables, cx)), @@ -309,10 +309,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Align { impl<'tcx> Stable<'tcx> for rustc_abi::Scalar { type T = Scalar; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { rustc_abi::Scalar::Initialized { value, valid_range } => Scalar::Initialized { @@ -327,10 +327,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Scalar { impl<'tcx> Stable<'tcx> for rustc_abi::Primitive { type T = Primitive; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { rustc_abi::Primitive::Int(length, signed) => { @@ -390,10 +390,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::WrappingRange { impl<'tcx> Stable<'tcx> for rustc_abi::ReprFlags { type T = ReprFlags; - fn stable<'cx>( + fn stable( &self, - _tables: &mut Tables<'cx, BridgeTys>, - _cx: &CompilerCtxt<'cx, BridgeTys>, + _tables: &mut Tables<'tcx, BridgeTys>, + _cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { ReprFlags { is_simd: self.intersects(Self::IS_SIMD), @@ -407,10 +407,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ReprFlags { impl<'tcx> Stable<'tcx> for rustc_abi::IntegerType { type T = IntegerType; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { rustc_abi::IntegerType::Pointer(signed) => IntegerType::Pointer { is_signed: *signed }, @@ -424,10 +424,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::IntegerType { impl<'tcx> Stable<'tcx> for rustc_abi::ReprOptions { type T = ReprOptions; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { ReprOptions { int: self.int.map(|int| int.stable(tables, cx)), diff --git a/compiler/rustc_public/src/unstable/convert/stable/mir.rs b/compiler/rustc_public/src/unstable/convert/stable/mir.rs index 0d04053aab76b..3d2647b851d9d 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mir.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mir.rs @@ -15,10 +15,10 @@ use crate::{Error, alloc, opaque}; impl<'tcx> Stable<'tcx> for mir::Body<'tcx> { type T = crate::mir::Body; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::mir::Body::new( self.basic_blocks @@ -50,10 +50,10 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> { impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> { type T = crate::mir::VarDebugInfo; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::mir::VarDebugInfo { name: self.name.to_string(), @@ -67,10 +67,10 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> { impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> { type T = crate::mir::Statement; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { Statement { kind: self.kind.stable(tables, cx), @@ -81,10 +81,10 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> { impl<'tcx> Stable<'tcx> for mir::SourceInfo { type T = crate::mir::SourceInfo; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::mir::SourceInfo { span: self.span.stable(tables, cx), scope: self.scope.into() } } @@ -92,10 +92,10 @@ impl<'tcx> Stable<'tcx> for mir::SourceInfo { impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> { type T = crate::mir::VarDebugInfoFragment; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { VarDebugInfoFragment { ty: self.ty.stable(tables, cx), @@ -106,10 +106,10 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> { impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> { type T = crate::mir::VarDebugInfoContents; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { mir::VarDebugInfoContents::Place(place) => { @@ -129,10 +129,10 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> { impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> { type T = crate::mir::StatementKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { mir::StatementKind::Assign(assign) => crate::mir::StatementKind::Assign( @@ -188,10 +188,10 @@ impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> { impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> { type T = crate::mir::Rvalue; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::Rvalue::*; match self { @@ -271,10 +271,10 @@ impl<'tcx> Stable<'tcx> for mir::RawPtrKind { impl<'tcx> Stable<'tcx> for mir::BorrowKind { type T = crate::mir::BorrowKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::BorrowKind::*; match *self { @@ -310,10 +310,10 @@ impl<'tcx> Stable<'tcx> for mir::FakeBorrowKind { impl<'tcx> Stable<'tcx> for mir::RuntimeChecks { type T = crate::mir::RuntimeChecks; - fn stable<'cx>( + fn stable( &self, - _: &mut Tables<'cx, BridgeTys>, - _: &CompilerCtxt<'cx, BridgeTys>, + _: &mut Tables<'tcx, BridgeTys>, + _: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::RuntimeChecks::*; match self { @@ -326,10 +326,10 @@ impl<'tcx> Stable<'tcx> for mir::RuntimeChecks { impl<'tcx> Stable<'tcx> for mir::CastKind { type T = crate::mir::CastKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::CastKind::*; match self { @@ -366,10 +366,10 @@ impl<'tcx> Stable<'tcx> for mir::FakeReadCause { impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> { type T = crate::mir::Operand; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::Operand::*; match self { @@ -384,10 +384,10 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> { impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> { type T = crate::mir::ConstOperand; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::mir::ConstOperand { span: self.span.stable(tables, cx), @@ -399,10 +399,10 @@ impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> { impl<'tcx> Stable<'tcx> for mir::Place<'tcx> { type T = crate::mir::Place; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::mir::Place { local: self.local.as_usize(), @@ -413,10 +413,10 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> { impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> { type T = crate::mir::ProjectionElem; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::ProjectionElem::*; match self { @@ -491,10 +491,10 @@ impl<'tcx> Stable<'tcx> for mir::UnwindAction { impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> { type T = crate::mir::NonDivergingIntrinsic; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::NonDivergingIntrinsic; @@ -516,10 +516,10 @@ impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> { impl<'tcx> Stable<'tcx> for mir::AssertMessage<'tcx> { type T = crate::mir::AssertMessage; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::AssertKind; match self { @@ -613,10 +613,10 @@ impl<'tcx> Stable<'tcx> for mir::UnOp { impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { type T = crate::mir::AggregateKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { mir::AggregateKind::Array(ty) => { @@ -658,10 +658,10 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> { type T = crate::mir::InlineAsmOperand; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::InlineAsmOperand; @@ -685,10 +685,10 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> { impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { type T = crate::mir::Terminator; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::mir::Terminator; Terminator { @@ -700,10 +700,10 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> { type T = crate::mir::TerminatorKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::mir::TerminatorKind; match self { @@ -789,10 +789,10 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> { impl<'tcx> Stable<'tcx> for mir::interpret::ConstAllocation<'tcx> { type T = Allocation; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { self.inner().stable(tables, cx) } @@ -801,10 +801,10 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ConstAllocation<'tcx> { impl<'tcx> Stable<'tcx> for mir::interpret::Allocation { type T = crate::ty::Allocation; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_public_bridge::context::AllocRangeHelpers; alloc::allocation_filter( @@ -818,10 +818,10 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation { impl<'tcx> Stable<'tcx> for mir::interpret::AllocId { type T = crate::mir::alloc::AllocId; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - _: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + _: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { tables.create_alloc_id(*self) } @@ -830,10 +830,10 @@ impl<'tcx> Stable<'tcx> for mir::interpret::AllocId { impl<'tcx> Stable<'tcx> for mir::interpret::GlobalAlloc<'tcx> { type T = GlobalAlloc; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { mir::interpret::GlobalAlloc::Function { instance, .. } => { @@ -859,12 +859,12 @@ impl<'tcx> Stable<'tcx> for mir::interpret::GlobalAlloc<'tcx> { impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { type T = crate::ty::MirConst; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { - let id = tables.intern_mir_const(cx.lift(*self).unwrap()); + let id = tables.intern_mir_const(*self); match *self { mir::Const::Ty(ty, c) => MirConst::new( crate::ty::ConstantKind::Ty(c.stable(tables, cx)), @@ -885,8 +885,6 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { MirConst::new(ConstantKind::ZeroSized, ty, id) } mir::Const::Val(val, ty) => { - let ty = cx.lift(ty).unwrap(); - let val = cx.lift(val).unwrap(); let kind = ConstantKind::Allocated(alloc::new_allocation(ty, val, tables, cx)); let ty = ty.stable(tables, cx); MirConst::new(kind, ty, id) @@ -906,10 +904,10 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ErrorHandled { impl<'tcx> Stable<'tcx> for MonoItem<'tcx> { type T = crate::mir::mono::MonoItem; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::mir::mono::MonoItem as StableMonoItem; match self { diff --git a/compiler/rustc_public/src/unstable/convert/stable/ty.rs b/compiler/rustc_public/src/unstable/convert/stable/ty.rs index 3aa3408caddc8..8e45fcb1a29c3 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/ty.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/ty.rs @@ -26,10 +26,10 @@ impl<'tcx> Stable<'tcx> for ty::AliasTyKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> { type T = crate::ty::AliasTy; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::AliasTy { args, kind, .. } = self; crate::ty::AliasTy { @@ -41,10 +41,10 @@ impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> { impl<'tcx> Stable<'tcx> for ty::AliasTerm<'tcx> { type T = crate::ty::AliasTerm; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::AliasTerm { args, kind, .. } = self; crate::ty::AliasTerm { @@ -57,10 +57,10 @@ impl<'tcx> Stable<'tcx> for ty::AliasTerm<'tcx> { impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> { type T = crate::ty::ExistentialPredicate; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::ExistentialPredicate::*; match self { @@ -78,10 +78,10 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> { impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> { type T = crate::ty::ExistentialTraitRef; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::ExistentialTraitRef { def_id, args, .. } = self; crate::ty::ExistentialTraitRef { @@ -94,10 +94,10 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> { impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> { type T = crate::ty::TermKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::TermKind; match self { @@ -113,10 +113,10 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> { type T = crate::ty::ExistentialProjection; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::ExistentialProjection { def_id, args, term, .. } = self; crate::ty::ExistentialProjection { @@ -129,10 +129,10 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> { impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion { type T = crate::mir::PointerCoercion; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::ty::adjustment::PointerCoercion; match self { @@ -172,10 +172,10 @@ impl<'tcx> Stable<'tcx> for ty::AdtKind { impl<'tcx> Stable<'tcx> for ty::FieldDef { type T = crate::ty::FieldDef; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::ty::FieldDef { def: tables.create_def_id(self.did), @@ -186,10 +186,10 @@ impl<'tcx> Stable<'tcx> for ty::FieldDef { impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> { type T = crate::ty::GenericArgs; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { GenericArgs(self.iter().map(|arg| arg.kind().stable(tables, cx)).collect()) } @@ -198,10 +198,10 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> { impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> { type T = crate::ty::GenericArgKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::GenericArgKind; match self { @@ -220,10 +220,10 @@ where { type T = crate::ty::Binder; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::Binder; @@ -244,10 +244,10 @@ where { type T = crate::ty::EarlyBinder; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::EarlyBinder; @@ -259,10 +259,10 @@ where // But it's a public field of FnSig (which has a public mirror type), so allow conversions. impl<'tcx> Stable<'tcx> for ty::FnSigKind { type T = (bool /*c_variadic*/, crate::mir::Safety, crate::ty::Abi); - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { ( self.c_variadic(), @@ -274,10 +274,10 @@ impl<'tcx> Stable<'tcx> for ty::FnSigKind { impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> { type T = crate::ty::FnSig; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::FnSig; let (c_variadic, safety, abi) = self.fn_sig_kind.stable(tables, cx); @@ -298,10 +298,10 @@ impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> { impl<'tcx> Stable<'tcx> for ty::BoundTyKind<'tcx> { type T = crate::ty::BoundTyKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::BoundTyKind; @@ -317,10 +317,10 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::BoundRegionKind<'tcx> { type T = crate::ty::BoundRegionKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::BoundRegionKind; @@ -339,10 +339,10 @@ impl<'tcx> Stable<'tcx> for ty::BoundRegionKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::BoundVariableKind<'tcx> { type T = crate::ty::BoundVariableKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::BoundVariableKind; @@ -403,21 +403,21 @@ impl<'tcx> Stable<'tcx> for ty::FloatTy { impl<'tcx> Stable<'tcx> for Ty<'tcx> { type T = crate::ty::Ty; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + _cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { - tables.intern_ty(cx.lift(*self).unwrap()) + tables.intern_ty(*self) } } impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { type T = crate::ty::TyKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match self { ty::Bool => TyKind::RigidTy(RigidTy::Bool), @@ -499,10 +499,10 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> { type T = crate::ty::Pattern; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { match **self { ty::PatternKind::Range { start, end } => crate::ty::Pattern::Range { @@ -521,13 +521,12 @@ impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> { impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { type T = crate::ty::TyConst; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { - let ct = cx.lift(*self).unwrap(); - let kind = match ct.kind() { + let kind = match self.kind() { ty::ConstKind::Value(cv) => { let const_val = cx.valtree_to_const_val(cv); if matches!(const_val, mir::ConstValue::ZeroSized) { @@ -550,7 +549,7 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { ty::ConstKind::Placeholder(_) => unimplemented!(), ty::ConstKind::Expr(_) => unimplemented!(), }; - let id = tables.intern_ty_const(ct); + let id = tables.intern_ty_const(*self); crate::ty::TyConst::new(kind, id) } } @@ -573,10 +572,10 @@ impl<'tcx> Stable<'tcx> for ty::ParamTy { impl<'tcx> Stable<'tcx> for ty::BoundTy<'tcx> { type T = crate::ty::BoundTy; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::BoundTy; BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables, cx) } @@ -600,10 +599,10 @@ impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind { impl<'tcx> Stable<'tcx> for ty::TraitDef { type T = crate::ty::TraitDecl; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::opaque; use crate::ty::TraitDecl; @@ -630,10 +629,10 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef { impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> { type T = crate::ty::TraitRef; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::TraitRef; @@ -644,10 +643,10 @@ impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> { impl<'tcx> Stable<'tcx> for ty::Generics { type T = crate::ty::Generics; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::Generics; @@ -689,10 +688,10 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind { impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef { type T = crate::ty::GenericParamDef; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { GenericParamDef { name: self.name.to_string(), @@ -707,10 +706,10 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef { impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> { type T = crate::ty::PredicateKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::ty::PredicateKind; match self { @@ -745,10 +744,10 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> { type T = crate::ty::ClauseKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use rustc_middle::ty::ClauseKind; match *self { @@ -804,10 +803,10 @@ impl<'tcx> Stable<'tcx> for ty::ClosureKind { impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> { type T = crate::ty::SubtypePredicate; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::SubtypePredicate { a, b, a_is_expected: _ } = self; crate::ty::SubtypePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) } @@ -817,10 +816,10 @@ impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> { impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> { type T = crate::ty::CoercePredicate; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::CoercePredicate { a, b } = self; crate::ty::CoercePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) } @@ -842,10 +841,10 @@ impl<'tcx> Stable<'tcx> for ty::AliasRelationDirection { impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> { type T = crate::ty::TraitPredicate; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::TraitPredicate { trait_ref, polarity } = self; crate::ty::TraitPredicate { @@ -861,10 +860,10 @@ where { type T = crate::ty::OutlivesPredicate; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::OutlivesPredicate(a, b) = self; crate::ty::OutlivesPredicate(a.stable(tables, cx), b.stable(tables, cx)) @@ -874,10 +873,10 @@ where impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> { type T = crate::ty::ProjectionPredicate; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { let ty::ProjectionPredicate { projection_term, term } = self; crate::ty::ProjectionPredicate { @@ -915,10 +914,10 @@ impl<'tcx> Stable<'tcx> for ty::PredicatePolarity { impl<'tcx> Stable<'tcx> for ty::Region<'tcx> { type T = crate::ty::Region; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { Region { kind: self.kind().stable(tables, cx) } } @@ -927,10 +926,10 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> { impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> { type T = crate::ty::RegionKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::{BoundRegion, EarlyParamRegion, RegionKind}; match self { @@ -962,12 +961,12 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> { impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> { type T = crate::mir::mono::Instance; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + _cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { - let def = tables.instance_def(cx.lift(*self).unwrap()); + let def = tables.instance_def(*self); let kind = match self.def { ty::InstanceKind::Item(..) => crate::mir::mono::InstanceKind::Item, ty::InstanceKind::Intrinsic(..) => crate::mir::mono::InstanceKind::Intrinsic, @@ -1057,10 +1056,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi { impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule { type T = crate::ty::ForeignModule; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::ty::ForeignModule { def_id: tables.foreign_module_def(self.def_id), @@ -1072,10 +1071,10 @@ impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule { impl<'tcx> Stable<'tcx> for ty::AssocKind { type T = crate::ty::AssocKind; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::{AssocKind, AssocTypeData}; match *self { @@ -1117,10 +1116,10 @@ impl<'tcx> Stable<'tcx> for ty::AssocContainer { impl<'tcx> Stable<'tcx> for ty::AssocItem { type T = crate::ty::AssocItem; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::ty::AssocItem { def_id: tables.assoc_def(self.def_id), @@ -1133,10 +1132,10 @@ impl<'tcx> Stable<'tcx> for ty::AssocItem { impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData { type T = crate::ty::ImplTraitInTraitData; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - _: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + _: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::ImplTraitInTraitData; match self { @@ -1156,10 +1155,10 @@ impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData { impl<'tcx> Stable<'tcx> for rustc_middle::ty::util::Discr<'tcx> { type T = crate::ty::Discr; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { crate::ty::Discr { val: self.val, ty: self.ty.stable(tables, cx) } } @@ -1168,10 +1167,10 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::util::Discr<'tcx> { impl<'tcx> Stable<'tcx> for rustc_middle::ty::VtblEntry<'tcx> { type T = crate::ty::VtblEntry; - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T { use crate::ty::VtblEntry; match self { diff --git a/compiler/rustc_public/src/unstable/mod.rs b/compiler/rustc_public/src/unstable/mod.rs index 0e462e044d574..3f0434639f387 100644 --- a/compiler/rustc_public/src/unstable/mod.rs +++ b/compiler/rustc_public/src/unstable/mod.rs @@ -73,10 +73,10 @@ pub trait Stable<'tcx>: PointeeSized { /// The stable representation of the type implementing Stable. type T; /// Converts an object to the equivalent rustc_public's IR representation. - fn stable<'cx>( + fn stable( &self, - tables: &mut Tables<'cx, BridgeTys>, - cx: &CompilerCtxt<'cx, BridgeTys>, + tables: &mut Tables<'tcx, BridgeTys>, + cx: &CompilerCtxt<'tcx, BridgeTys>, ) -> Self::T; } diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index bb504bd0017a0..7c754dcd55667 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -17,8 +17,8 @@ use rustc_middle::ty::util::Discr; use rustc_middle::ty::{ AdtDef, AdtKind, AssocItem, Binder, ClosureKind, CoroutineArgsExt, EarlyBinder, ExistentialTraitRef, FnSig, GenericArgsRef, Instance, InstanceKind, IntrinsicDef, List, - PolyFnSig, ScalarInt, TraitDef, TraitRef, Ty, TyCtxt, TyKind, TypeVisitableExt, UintTy, - ValTree, VariantDef, VtblEntry, + PolyFnSig, ScalarInt, TraitDef, TraitRef, Ty, TyKind, TypeVisitableExt, UintTy, ValTree, + VariantDef, VtblEntry, }; use rustc_middle::{mir, ty}; use rustc_session::cstore::ForeignModule; @@ -53,10 +53,6 @@ impl<'tcx, B: Bridge> AllocRangeHelpers<'tcx> for CompilerCtxt<'tcx, B> { } impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { - pub fn lift>>(&self, value: T) -> Option { - self.tcx.lift(value) - } - pub fn adt_def(&self, def_id: DefId) -> AdtDef<'tcx> { self.tcx.adt_def(def_id) } From d4b0e059b45a98bea9903dba44baf5e70cd23482 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Apr 2026 20:17:25 +1000 Subject: [PATCH 6/6] Remove all remaining lifting code. Thanks to the previous commits, none of this code used any more and it can all be removed. Specifically: - The `Lift` trait. - The `Lift` and `Lift_Generic` proc macros, and all their uses. - The declarative macros used to impl `Lift` for various types. - The `rustc_macros::lift` and `rustc_type_ir::lift` modules. This commit also eliminates two FIXME comments. --- compiler/rustc_macros/src/lib.rs | 2 - compiler/rustc_macros/src/lift.rs | 49 ----------- compiler/rustc_middle/src/macros.rs | 22 +---- compiler/rustc_middle/src/mir/consts.rs | 6 +- .../rustc_middle/src/ty/consts/valtree.rs | 6 +- compiler/rustc_middle/src/ty/context.rs | 83 +------------------ compiler/rustc_middle/src/ty/generic_args.rs | 14 +--- compiler/rustc_middle/src/ty/instance.rs | 9 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 14 ++-- .../rustc_middle/src/ty/structural_impls.rs | 68 ++------------- .../src/unstable/internal_cx/mod.rs | 4 - compiler/rustc_public/src/unstable/mod.rs | 2 - .../src/traits/query/type_op/normalize.rs | 6 +- compiler/rustc_type_ir/src/binder.rs | 54 +----------- compiler/rustc_type_ir/src/canonical.rs | 6 +- compiler/rustc_type_ir/src/const_kind.rs | 6 +- compiler/rustc_type_ir/src/lib.rs | 1 - compiler/rustc_type_ir/src/lift.rs | 21 ----- compiler/rustc_type_ir/src/pattern.rs | 6 +- compiler/rustc_type_ir/src/predicate.rs | 46 ++++------ compiler/rustc_type_ir/src/solve/mod.rs | 6 +- compiler/rustc_type_ir/src/ty_kind.rs | 18 ++-- compiler/rustc_type_ir/src/ty_kind/closure.rs | 10 +-- compiler/rustc_type_ir_macros/src/lib.rs | 76 ----------------- 25 files changed, 66 insertions(+), 471 deletions(-) delete mode 100644 compiler/rustc_macros/src/lift.rs delete mode 100644 compiler/rustc_type_ir/src/lift.rs diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 44969908b3f41..fa4ecfbfd7114 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -12,7 +12,6 @@ mod current_version; mod diagnostics; mod extension; mod hash_stable; -mod lift; mod print_attribute; mod query; mod serialize; @@ -176,7 +175,6 @@ decl_derive!( /// visited (and its type is not required to implement `Walkable`). visitable::visitable_derive ); -decl_derive!([Lift, attributes(lift)] => lift::lift_derive); decl_derive!( [Diagnostic, attributes( // struct attributes diff --git a/compiler/rustc_macros/src/lift.rs b/compiler/rustc_macros/src/lift.rs deleted file mode 100644 index 03ea396a42c75..0000000000000 --- a/compiler/rustc_macros/src/lift.rs +++ /dev/null @@ -1,49 +0,0 @@ -use quote::quote; -use syn::parse_quote; - -pub(super) fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { - s.add_bounds(synstructure::AddBounds::Generics); - s.bind_with(|_| synstructure::BindStyle::Move); - - let tcx: syn::Lifetime = parse_quote!('tcx); - let newtcx: syn::GenericParam = parse_quote!('__lifted); - - let lifted = { - let ast = s.ast(); - let ident = &ast.ident; - - // Replace `'tcx` lifetime by the `'__lifted` lifetime - let (_, generics, _) = ast.generics.split_for_impl(); - let mut generics: syn::AngleBracketedGenericArguments = syn::parse_quote! { #generics }; - for arg in generics.args.iter_mut() { - match arg { - syn::GenericArgument::Lifetime(l) if *l == tcx => { - *arg = parse_quote!('__lifted); - } - syn::GenericArgument::Type(t) => { - *arg = syn::parse_quote! { #t::Lifted }; - } - _ => {} - } - } - - quote! { #ident #generics } - }; - - let body = s.each_variant(|vi| { - let bindings = &vi.bindings(); - vi.construct(|_, index| { - let bi = &bindings[index]; - quote! { __tcx.lift(#bi)? } - }) - }); - - s.add_impl_generic(newtcx); - s.bound_impl(quote!(::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>), quote! { - type Lifted = #lifted; - - fn lift_to_interner(self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> { - Some(match self { #body }) - } - }) -} diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 0ae774ebee795..fd374b8157c68 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -36,24 +36,11 @@ macro_rules! span_bug { } /////////////////////////////////////////////////////////////////////////// -// Lift and TypeFoldable/TypeVisitable macros +// TypeFoldable/TypeVisitable macros // // When possible, use one of these (relatively) convenient macros to write // the impls for you. -macro_rules! TrivialLiftImpls { - ($($ty:ty),+ $(,)?) => { - $( - impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty { - type Lifted = Self; - fn lift_to_interner(self, _: $crate::ty::TyCtxt<'tcx>) -> Option { - Some(self) - } - } - )+ - }; -} - /// Used for types that are `Copy` and which **do not care about arena /// allocated data** (i.e., don't need to be folded). macro_rules! TrivialTypeTraversalImpls { @@ -89,10 +76,3 @@ macro_rules! TrivialTypeTraversalImpls { )+ }; } - -macro_rules! TrivialTypeTraversalAndLiftImpls { - ($($t:tt)*) => { - TrivialTypeTraversalImpls! { $($t)* } - TrivialLiftImpls! { $($t)* } - } -} diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index fd07455917246..b65b27dc86ca4 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Display, Formatter}; use rustc_abi::{HasDataLayout, Size}; use rustc_hir::def_id::DefId; -use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; +use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_span::{DUMMY_SP, RemapPathScopeComponents, Span, Symbol}; use rustc_type_ir::TypeVisitableExt; @@ -208,7 +208,7 @@ impl ConstValue { /// Constants #[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)] -#[derive(TypeFoldable, TypeVisitable, Lift)] +#[derive(TypeFoldable, TypeVisitable)] pub enum Const<'tcx> { /// This constant came from the type system. /// @@ -458,7 +458,7 @@ impl<'tcx> Const<'tcx> { /// An unevaluated (potentially generic) constant used in MIR. #[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)] -#[derive(Hash, HashStable, TypeFoldable, TypeVisitable, Lift)] +#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)] pub struct UnevaluatedConst<'tcx> { pub def: DefId, pub args: GenericArgsRef<'tcx>, diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index c1fabbdec49ea..5b354e690e644 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -4,9 +4,7 @@ use std::ops::Deref; use rustc_abi::{FIRST_VARIANT, VariantIdx}; use rustc_data_structures::intern::Interned; use rustc_hir::def::Namespace; -use rustc_macros::{ - HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension, -}; +use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension}; use super::ScalarInt; use crate::mir::interpret::{ErrorHandled, Scalar}; @@ -97,7 +95,7 @@ pub type ConstToValTreeResult<'tcx> = Result, Ty<'tcx>>, Er /// Note that this is also used by pattern elaboration to represent values which cannot occur in types, /// such as raw pointers and floats. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable, Lift)] +#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)] pub struct Value<'tcx> { pub ty: Ty<'tcx>, pub valtree: ValTree<'tcx>, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 60237c98fed2c..67fa983114ab9 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -13,7 +13,7 @@ use std::hash::{Hash, Hasher}; use std::marker::{PhantomData, PointeeSized}; use std::ops::{Bound, Deref}; use std::sync::{Arc, OnceLock}; -use std::{fmt, iter, mem}; +use std::{fmt, iter}; use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx}; use rustc_ast as ast; @@ -45,7 +45,6 @@ use rustc_session::lint::Lint; use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_type_ir::TyKind::*; -pub use rustc_type_ir::lift::Lift; use rustc_type_ir::{CollectAndApply, FnSigKind, WithCachedTypeInfo, elaborate, search_graph}; use tracing::{debug, instrument}; @@ -1002,10 +1001,6 @@ impl<'tcx> TyCtxt<'tcx> { (start, end) } - pub fn lift>>(self, value: T) -> Option { - value.lift_to_interner(self) - } - /// Creates a type context. To use the context call `fn enter` which /// provides a `TyCtxt`. /// @@ -1729,82 +1724,6 @@ impl<'tcx> TyCtxt<'tcx> { } } -macro_rules! nop_lift { - ($set:ident; $ty:ty => $lifted:ty) => { - impl<'a, 'tcx> Lift> for $ty { - type Lifted = $lifted; - fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - // Assert that the set has the right type. - // Given an argument that has an interned type, the return type has the type of - // the corresponding interner set. This won't actually return anything, we're - // just doing this to compute said type! - fn _intern_set_ty_from_interned_ty<'tcx, Inner>( - _x: Interned<'tcx, Inner>, - ) -> InternedSet<'tcx, Inner> { - unreachable!() - } - fn _type_eq(_x: &T, _y: &T) {} - fn _test<'tcx>(x: $lifted, tcx: TyCtxt<'tcx>) { - // If `x` is a newtype around an `Interned`, then `interner` is an - // interner of appropriate type. (Ideally we'd also check that `x` is a - // newtype with just that one field. Not sure how to do that.) - let interner = _intern_set_ty_from_interned_ty(x.0); - // Now check that this is the same type as `interners.$set`. - _type_eq(&interner, &tcx.interners.$set); - } - - tcx.interners - .$set - .contains_pointer_to(&InternedInSet(&*self.0.0)) - // SAFETY: `self` is interned and therefore valid - // for the entire lifetime of the `TyCtxt`. - .then(|| unsafe { mem::transmute(self) }) - } - } - }; -} - -macro_rules! nop_list_lift { - ($set:ident; $ty:ty => $lifted:ty) => { - impl<'a, 'tcx> Lift> for &'a List<$ty> { - type Lifted = &'tcx List<$lifted>; - fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - // Assert that the set has the right type. - if false { - let _x: &InternedSet<'tcx, List<$lifted>> = &tcx.interners.$set; - } - - if self.is_empty() { - return Some(List::empty()); - } - tcx.interners - .$set - .contains_pointer_to(&InternedInSet(self)) - .then(|| unsafe { mem::transmute(self) }) - } - } - }; -} - -nop_lift! { type_; Ty<'a> => Ty<'tcx> } -nop_lift! { region; Region<'a> => Region<'tcx> } -nop_lift! { const_; Const<'a> => Const<'tcx> } -nop_lift! { pat; Pattern<'a> => Pattern<'tcx> } -nop_lift! { const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx> } -nop_lift! { predicate; Predicate<'a> => Predicate<'tcx> } -nop_lift! { predicate; Clause<'a> => Clause<'tcx> } -nop_lift! { layout; Layout<'a> => Layout<'tcx> } -nop_lift! { valtree; ValTree<'a> => ValTree<'tcx> } - -nop_list_lift! { type_lists; Ty<'a> => Ty<'tcx> } -nop_list_lift! { - poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx> -} -nop_list_lift! { bound_variable_kinds; ty::BoundVariableKind<'a> => ty::BoundVariableKind<'tcx> } - -// This is the impl for `&'a GenericArgs<'a>`. -nop_list_lift! { args; GenericArg<'a> => GenericArg<'tcx> } - macro_rules! sty_debug_print { ($fmt: expr, $ctxt: expr, $($variant: ident),*) => {{ // Curious inner module to allow variant names to be used as diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index daeabf24d749f..163e2a1839306 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -17,7 +17,7 @@ use smallvec::SmallVec; use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::{ self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, FallibleTypeFolder, InlineConstArgs, - Lift, List, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, VisitorResult, + List, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, VisitorResult, walk_visitable_list, }; @@ -317,18 +317,6 @@ impl<'tcx> GenericArg<'tcx> { } } -impl<'a, 'tcx> Lift> for GenericArg<'a> { - type Lifted = GenericArg<'tcx>; - - fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - match self.kind() { - GenericArgKind::Lifetime(lt) => tcx.lift(lt).map(|lt| lt.into()), - GenericArgKind::Type(ty) => tcx.lift(ty).map(|ty| ty.into()), - GenericArgKind::Const(ct) => tcx.lift(ct).map(|ct| ct.into()), - } - } -} - impl<'tcx> TypeFoldable> for GenericArg<'tcx> { fn try_fold_with>>( self, diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 899cd1717bc10..c18de6cf91e00 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -6,7 +6,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Namespace}; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::lang_items::LangItem; -use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable}; +use rustc_macros::{HashStable, TyDecodable, TyEncodable}; use rustc_span::def_id::LOCAL_CRATE; use rustc_span::{DUMMY_SP, Span}; use tracing::{debug, instrument}; @@ -25,11 +25,8 @@ use crate::ty::{ /// Monomorphization happens on-the-fly and no monomorphized MIR is ever created. Instead, this type /// simply couples a potentially generic `InstanceKind` with some args, and codegen and const eval /// will do all required instantiations as they run. -/// -/// Note: the `Lift` impl is currently not used by rustc, but is used by -/// rustc_codegen_cranelift when the `jit` feature is enabled. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] -#[derive(HashStable, Lift, TypeFoldable, TypeVisitable)] +#[derive(HashStable, TypeFoldable, TypeVisitable)] pub struct Instance<'tcx> { pub def: InstanceKind<'tcx>, pub args: GenericArgsRef<'tcx>, @@ -58,7 +55,7 @@ pub enum ReifyReason { } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable, Lift)] +#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] pub enum InstanceKind<'tcx> { /// A user-defined callable item. /// diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d8303a671c4a5..49ffbacb50c3b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -83,7 +83,7 @@ pub use self::consts::{ const_lit_matches_ty, }; pub use self::context::{ - CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls, + CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, TyCtxt, TyCtxtFeed, tls, }; pub use self::fold::*; pub use self::instance::{Instance, InstanceKind, ReifyReason}; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index a76d72677b2f2..6f45002dac618 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -14,7 +14,7 @@ use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; use rustc_hir::def_id::{DefIdMap, DefIdSet, LOCAL_CRATE, ModDefId}; use rustc_hir::definitions::{DefKey, DefPathDataName}; use rustc_hir::limit::Limit; -use rustc_macros::{Lift, extension}; +use rustc_macros::extension; use rustc_session::cstore::{ExternCrate, ExternCrateSource}; use rustc_span::{Ident, RemapPathScopeComponents, Symbol, kw, sym}; use rustc_type_ir::{FieldInfo, Unnormalized, Upcast as _, elaborate}; @@ -2964,7 +2964,7 @@ where /// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only /// the trait path. That is, it will print `Trait` instead of /// `>`. -#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift, Hash)] +#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Hash)] pub struct TraitRefPrintOnlyTraitPath<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> rustc_errors::IntoDiagArg for TraitRefPrintOnlyTraitPath<'tcx> { @@ -2984,7 +2984,7 @@ impl<'tcx> fmt::Debug for TraitRefPrintOnlyTraitPath<'tcx> { /// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only /// the trait path, and additionally tries to "sugar" `Fn(...)` trait bounds. -#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift, Hash)] +#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Hash)] pub struct TraitRefPrintSugared<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> rustc_errors::IntoDiagArg for TraitRefPrintSugared<'tcx> { @@ -3005,7 +3005,7 @@ impl<'tcx> fmt::Debug for TraitRefPrintSugared<'tcx> { /// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only /// the trait name. That is, it will print `Trait` instead of /// `>`. -#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)] +#[derive(Copy, Clone, TypeFoldable, TypeVisitable)] pub struct TraitRefPrintOnlyTraitName<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> fmt::Debug for TraitRefPrintOnlyTraitName<'tcx> { @@ -3040,7 +3040,7 @@ impl<'tcx> ty::Binder<'tcx, ty::TraitRef<'tcx>> { } } -#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift, Hash)] +#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Hash)] pub struct TraitPredPrintModifiersAndPath<'tcx>(ty::TraitPredicate<'tcx>); impl<'tcx> fmt::Debug for TraitPredPrintModifiersAndPath<'tcx> { @@ -3056,7 +3056,7 @@ impl<'tcx> ty::TraitPredicate<'tcx> { } } -#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift, Hash)] +#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Hash)] pub struct TraitPredPrintWithBoundConstness<'tcx>( ty::TraitPredicate<'tcx>, Option, @@ -3084,7 +3084,7 @@ impl<'tcx> ty::PolyTraitPredicate<'tcx> { } } -#[derive(Debug, Copy, Clone, Lift)] +#[derive(Debug, Copy, Clone)] pub struct PrintClosureAsImpl<'tcx> { pub closure: ty::ClosureArgs>, } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index f6d5d226683b3..083c36953fc37 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1,4 +1,4 @@ -//! This module contains implementations of the `Lift`, `TypeFoldable` and +//! This module contains implementations of the `Debug`, `TypeFoldable` and //! `TypeVisitable` traits for various types in the Rust compiler. Most are //! written by hand, though we've recently added some macros and proc-macros //! to help with the tedium. @@ -15,8 +15,8 @@ use super::{GenericArg, GenericArgKind, Pattern, Region}; use crate::mir::PlaceElem; use crate::ty::print::{FmtPrinter, Printer, with_no_trimmed_paths}; use crate::ty::{ - self, FallibleTypeFolder, Lift, Term, TermKind, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, - TypeSuperVisitable, TypeVisitable, TypeVisitor, + self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, + TypeVisitable, TypeVisitor, }; impl fmt::Debug for ty::TraitDef { @@ -181,28 +181,6 @@ impl<'tcx> fmt::Debug for Region<'tcx> { // For things that don't carry any arena-allocated data (and are // copy...), just add them to one of these lists as appropriate. -// For things for which the type library provides traversal implementations -// for all Interners, we only need to provide a Lift implementation. -TrivialLiftImpls! { - (), - bool, - usize, - u64, - // tidy-alphabetical-start - crate::mir::Promoted, - crate::mir::interpret::AllocId, - crate::mir::interpret::Scalar, - crate::ty::ParamConst, - rustc_abi::ExternAbi, - rustc_abi::Size, - rustc_hir::Safety, - rustc_middle::mir::ConstValue, - rustc_type_ir::BoundConstness, - rustc_type_ir::FnSigKind, - rustc_type_ir::PredicatePolarity, - // tidy-alphabetical-end -} - // For some things about which the type library does not know, or does not // provide any traversal implementations, we need to provide a traversal // implementation (only for TyCtxt<'_> interners). @@ -222,6 +200,7 @@ TrivialTypeTraversalImpls! { crate::mir::Promoted, crate::mir::RawPtrKind, crate::mir::RetagKind, + crate::mir::RuntimeChecks, crate::mir::SourceInfo, crate::mir::SourceScope, crate::mir::SourceScopeLocalData, @@ -233,11 +212,13 @@ TrivialTypeTraversalImpls! { crate::ty::AssocKind, crate::ty::BoundRegion<'tcx>, crate::ty::BoundTy<'tcx>, + crate::ty::ParamTy, crate::ty::ScalarInt, crate::ty::UserTypeAnnotationIndex, crate::ty::abstract_const::NotConstEvaluatable, crate::ty::adjustment::AutoBorrowMutability, crate::ty::adjustment::PointerCoercion, + crate::ty::instance::ReifyReason, rustc_abi::FieldIdx, rustc_abi::VariantIdx, rustc_ast::InlineAsmOptions, @@ -246,6 +227,7 @@ TrivialTypeTraversalImpls! { rustc_hir::HirId, rustc_hir::MatchSource, rustc_hir::RangeEnd, + rustc_hir::def_id::DefId, rustc_hir::def_id::LocalDefId, rustc_span::Ident, rustc_span::Span, @@ -254,42 +236,6 @@ TrivialTypeTraversalImpls! { // tidy-alphabetical-end } -// For some things about which the type library does not know, or does not -// provide any traversal implementations, we need to provide a traversal -// implementation and a lift implementation (the former only for TyCtxt<'_> -// interners). -TrivialTypeTraversalAndLiftImpls! { - // tidy-alphabetical-start - crate::mir::RuntimeChecks, - crate::ty::ParamTy, - crate::ty::instance::ReifyReason, - rustc_hir::def_id::DefId, - // tidy-alphabetical-end -} - -/////////////////////////////////////////////////////////////////////////// -// Lift implementations - -impl<'tcx, T: Lift>> Lift> for Option { - type Lifted = Option; - fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - Some(match self { - Some(x) => Some(tcx.lift(x)?), - None => None, - }) - } -} - -impl<'a, 'tcx> Lift> for Term<'a> { - type Lifted = ty::Term<'tcx>; - fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - match self.kind() { - TermKind::Ty(ty) => tcx.lift(ty).map(Into::into), - TermKind::Const(c) => tcx.lift(c).map(Into::into), - } - } -} - /////////////////////////////////////////////////////////////////////////// // Traversal implementations. diff --git a/compiler/rustc_public/src/unstable/internal_cx/mod.rs b/compiler/rustc_public/src/unstable/internal_cx/mod.rs index 161f2754bed87..6cfce30d36a4c 100644 --- a/compiler/rustc_public/src/unstable/internal_cx/mod.rs +++ b/compiler/rustc_public/src/unstable/internal_cx/mod.rs @@ -44,10 +44,6 @@ impl<'tcx> InternalCx<'tcx> for TyCtxt<'tcx> { self } - fn lift>>(self, value: T) -> Option { - TyCtxt::lift(self, value) - } - fn mk_args_from_iter(self, iter: I) -> T::Output where I: Iterator, diff --git a/compiler/rustc_public/src/unstable/mod.rs b/compiler/rustc_public/src/unstable/mod.rs index 3f0434639f387..c6589450bd91b 100644 --- a/compiler/rustc_public/src/unstable/mod.rs +++ b/compiler/rustc_public/src/unstable/mod.rs @@ -26,8 +26,6 @@ mod internal_cx; pub trait InternalCx<'tcx>: Copy + Clone { fn tcx(self) -> TyCtxt<'tcx>; - fn lift>>(self, value: T) -> Option; - fn mk_args_from_iter(self, iter: I) -> T::Output where I: Iterator, diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs index 1b8a02f78b579..b6ef60ed5d550 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs @@ -4,7 +4,7 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::traits::query::NoSolution; pub use rustc_middle::traits::query::type_op::{DeeplyNormalize, Normalize}; use rustc_middle::ty::{ - self, Lift, ParamEnvAnd, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Unnormalized, + self, ParamEnvAnd, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Unnormalized, }; use rustc_span::Span; @@ -79,9 +79,7 @@ where } } -pub trait Normalizable<'tcx>: - fmt::Debug + TypeFoldable> + Lift> + Copy -{ +pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable> + Copy { fn type_op_method( tcx: TyCtxt<'tcx>, canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Normalize>>, diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 2b0dc221844ec..d9fb2bc7366d2 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -6,15 +6,12 @@ use std::ops::{ControlFlow, Deref}; use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use tracing::instrument; use crate::data_structures::SsoHashSet; use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; use crate::inherent::*; -use crate::lift::Lift; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; use crate::{self as ty, DebruijnIndex, Interner, UniverseIndex, Unnormalized}; @@ -36,23 +33,6 @@ pub struct Binder { impl Eq for Binder {} -// FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't -// understand how to turn `T` to `T::Lifted` in the output `type Lifted`. -impl Lift for Binder -where - T: Lift, - I::BoundVarKinds: Lift, -{ - type Lifted = Binder; - - fn lift_to_interner(self, cx: U) -> Option { - Some(Binder { - value: self.value.lift_to_interner(cx)?, - bound_vars: self.bound_vars.lift_to_interner(cx)?, - }) - } -} - #[cfg(feature = "nightly")] macro_rules! impl_binder_encode_decode { ($($t:ty),+ $(,)?) => { @@ -988,23 +968,8 @@ impl fmt::Debug for ty::Placeholder { } } -impl Lift for Placeholder -where - T: Lift, -{ - type Lifted = Placeholder; - - fn lift_to_interner(self, cx: U) -> Option { - Some(Placeholder { - universe: self.universe, - bound: self.bound.lift_to_interner(cx)?, - _tcx: PhantomData, - }) - } -} - #[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] -#[derive(Lift_Generic, GenericTypeVisitable)] +#[derive(GenericTypeVisitable)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -1067,7 +1032,7 @@ impl BoundRegionKind { } #[derive_where(Clone, Copy, PartialEq, Eq, Debug, Hash; I: Interner)] -#[derive(Lift_Generic, GenericTypeVisitable)] +#[derive(GenericTypeVisitable)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -1078,7 +1043,7 @@ pub enum BoundTyKind { } #[derive_where(Clone, Copy, PartialEq, Eq, Debug, Hash; I: Interner)] -#[derive(Lift_Generic, GenericTypeVisitable)] +#[derive(GenericTypeVisitable)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -1184,17 +1149,6 @@ pub struct BoundTy { pub kind: BoundTyKind, } -impl Lift for BoundTy -where - BoundTyKind: Lift>, -{ - type Lifted = BoundTy; - - fn lift_to_interner(self, cx: U) -> Option { - Some(BoundTy { var: self.var, kind: self.kind.lift_to_interner(cx)? }) - } -} - impl fmt::Debug for ty::BoundTy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.kind { diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index be5e483c808d4..9a59d3cad3932 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -5,9 +5,7 @@ use arrayvec::ArrayVec; use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::data_structures::HashMap; use crate::inherent::*; @@ -222,7 +220,7 @@ impl CanonicalVarKind { feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) )] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct CanonicalVarValues { pub var_values: I::GenericArgs, } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 68c87dd0bbeb7..17f74d73846b6 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -5,9 +5,7 @@ use derive_where::derive_where; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::{self as ty, BoundVarIndexKind, Interner}; @@ -69,7 +67,7 @@ impl fmt::Debug for ConstKind { /// An unevaluated (potentially generic) constant used in the type-system. #[derive_where(Clone, Copy, Debug, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 8f314ab86da24..9f0a1f06ad951 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -26,7 +26,6 @@ pub mod fast_reject; pub mod inherent; pub mod ir_print; pub mod lang_items; -pub mod lift; pub mod outlives; pub mod relate; pub mod search_graph; diff --git a/compiler/rustc_type_ir/src/lift.rs b/compiler/rustc_type_ir/src/lift.rs deleted file mode 100644 index e5a099d1f5042..0000000000000 --- a/compiler/rustc_type_ir/src/lift.rs +++ /dev/null @@ -1,21 +0,0 @@ -/// A trait implemented for all `X<'a>` types that can be safely and -/// efficiently converted to `X<'tcx>` as long as they are part of the -/// provided `TyCtxt<'tcx>`. -/// This can be done, for example, for `Ty<'tcx>` or `GenericArgsRef<'tcx>` -/// by looking them up in their respective interners. -/// -/// However, this is still not the best implementation as it does -/// need to compare the components, even for interned values. -/// It would be more efficient if `TypedArena` provided a way to -/// determine whether the address is in the allocated range. -/// -/// `None` is returned if the value or one of the components is not part -/// of the provided context. -/// For `Ty`, `None` can be returned if either the type interner doesn't -/// contain the `TyKind` key or if the address of the interned -/// pointer differs. The latter case is possible if a primitive type, -/// e.g., `()` or `u8`, was interned in a different context. -pub trait Lift: std::fmt::Debug { - type Lifted: std::fmt::Debug; - fn lift_to_interner(self, cx: I) -> Option; -} diff --git a/compiler/rustc_type_ir/src/pattern.rs b/compiler/rustc_type_ir/src/pattern.rs index d0febc739db4c..ec98c082619c0 100644 --- a/compiler/rustc_type_ir/src/pattern.rs +++ b/compiler/rustc_type_ir/src/pattern.rs @@ -1,14 +1,12 @@ use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::Interner; #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 0545fbfda6e41..e80f1c1528d77 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -4,12 +4,9 @@ use std::{fmt, iter}; use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::inherent::*; -use crate::lift::Lift; use crate::upcast::{Upcast, UpcastFrom}; use crate::visit::TypeVisitableExt as _; use crate::{self as ty, AliasTyKind, Interner}; @@ -26,26 +23,12 @@ pub struct OutlivesPredicate(pub A, pub I::Region); impl Eq for OutlivesPredicate {} -// FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't -// understand how to turn `A` to `A::Lifted` in the output `type Lifted`. -impl Lift for OutlivesPredicate -where - A: Lift, - I::Region: Lift, -{ - type Lifted = OutlivesPredicate; - - fn lift_to_interner(self, cx: U) -> Option { - Some(OutlivesPredicate(self.0.lift_to_interner(cx)?, self.1.lift_to_interner(cx)?)) - } -} - /// `'a == 'b`. /// For the rationale behind having this instead of a pair of bidirectional /// `'a: 'b` and `'b: 'a`, see /// [this discusstion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/A.20question.20on.20.23251/near/584167074). #[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -60,7 +43,7 @@ impl RegionEqPredicate { } #[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -120,7 +103,7 @@ impl RegionConstraint { /// Trait references also appear in object types like `Foo`, but in /// that case the `Self` parameter is absent from the generic parameters. #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -197,7 +180,7 @@ impl ty::Binder> { } #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -344,7 +327,7 @@ impl fmt::Display for PredicatePolarity { } #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -403,7 +386,7 @@ impl ty::Binder> { /// The generic parameters don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -472,7 +455,7 @@ impl ty::Binder> { /// A `ProjectionPredicate` for an `ExistentialTraitRef`. #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -561,7 +544,6 @@ impl ty::Binder> { } #[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] -#[derive(Lift_Generic)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -668,7 +650,7 @@ impl From> for AliasTermKind { /// * For an inherent projection, this would be `Ty::N<...>`. /// * For an opaque type, there is no explicit syntax. #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -880,7 +862,7 @@ impl From> for AliasTerm { /// Form #2 eventually yields one of these `ProjectionPredicate` /// instances to normalize the LHS. #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -943,7 +925,7 @@ impl fmt::Debug for ProjectionPredicate { /// Used by the new solver to normalize an alias. This always expects the `term` to /// be an unconstrained inference variable which is used as the output. #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -980,7 +962,7 @@ impl fmt::Debug for NormalizesTo { } #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -1026,7 +1008,7 @@ impl ty::Binder> { /// whether the `a` type is the type that we should label as "expected" when /// presenting user diagnostics. #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -1041,7 +1023,7 @@ impl Eq for SubtypePredicate {} /// Encodes that we have to coerce *from* the `a` type to the `b` type. #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index fe779b66dc245..91776c7109278 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -5,9 +5,7 @@ use std::hash::Hash; use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::lang_items::SolverTraitLangItem; use crate::search_graph::PathKind; @@ -35,7 +33,7 @@ pub struct NoSolution; /// we're currently typechecking while the `predicate` is some trait bound. #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, P)] #[derive_where(Copy; I: Interner, P: Copy)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 61ac5acca7405..acabafe220fa2 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -9,9 +9,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; use rustc_type_ir::data_structures::{NoError, UnifyKey, UnifyValue}; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use self::TyKind::*; pub use self::closure::*; @@ -23,7 +21,7 @@ use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy}; mod closure; #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(GenericTypeVisitable, Lift_Generic)] +#[derive(GenericTypeVisitable)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -436,7 +434,7 @@ impl fmt::Debug for TyKind { /// * For an inherent projection, this would be `Ty::N<...>`. /// * For an opaque type, there is no explicit syntax. #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -868,7 +866,7 @@ impl FnSigKind { feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) )] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct FnSig { pub inputs_and_output: I::Tys, #[type_visitable(ignore)] @@ -1009,7 +1007,7 @@ impl fmt::Debug for FnSig { // impls in this crate for `Binder`. #[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct UnsafeBinderInner(ty::Binder); impl Eq for UnsafeBinderInner {} @@ -1075,7 +1073,7 @@ where feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) )] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct FnSigTys { pub inputs_and_output: I::Tys, } @@ -1127,7 +1125,7 @@ impl ty::Binder> { feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) )] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct FnHeader { #[type_visitable(ignore)] #[type_foldable(identity)] @@ -1159,7 +1157,7 @@ impl Eq for FnHeader {} feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) )] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct CoroutineWitnessTypes { pub types: I::Tys, pub assumptions: I::RegionAssumptions, diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index 1ad5ed45e8b10..cd9fcd8ee7e84 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -1,9 +1,7 @@ use std::ops::ControlFlow; use derive_where::derive_where; -use rustc_type_ir_macros::{ - GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, -}; +use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::data_structures::DelayedMap; use crate::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable, shift_region}; @@ -104,7 +102,7 @@ use crate::{self as ty, Interner}; /// * `GR`: The "return type", which is the type of value returned upon /// completion of the coroutine. #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct ClosureArgs { /// Lifetime and type parameters from the enclosing function, /// concatenated with a tuple containing the types of the upvars. @@ -208,7 +206,7 @@ impl ClosureArgs { } #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct CoroutineClosureArgs { pub args: I::GenericArgs, } @@ -553,7 +551,7 @@ pub struct GenSig { impl Eq for GenSig {} /// Similar to `ClosureArgs`; see the above documentation for more. #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] -#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] +#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct CoroutineArgs { pub args: I::GenericArgs, } diff --git a/compiler/rustc_type_ir_macros/src/lib.rs b/compiler/rustc_type_ir_macros/src/lib.rs index 8df10b6a9eccd..8aff81b7f4a2e 100644 --- a/compiler/rustc_type_ir_macros/src/lib.rs +++ b/compiler/rustc_type_ir_macros/src/lib.rs @@ -1,5 +1,4 @@ use quote::{ToTokens, quote}; -use syn::visit_mut::VisitMut; use syn::{Attribute, parse_quote}; use synstructure::decl_derive; @@ -9,9 +8,6 @@ decl_derive!( decl_derive!( [TypeFoldable_Generic, attributes(type_foldable)] => type_foldable_derive ); -decl_derive!( - [Lift_Generic] => lift_derive -); #[cfg(not(feature = "nightly"))] decl_derive!( [GenericTypeVisitable] => customizable_type_visitable_derive @@ -144,78 +140,6 @@ fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke ) } -fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { - if let syn::Data::Union(_) = s.ast().data { - panic!("cannot derive on union") - } - - if !s.ast().generics.type_params().any(|ty| ty.ident == "I") { - s.add_impl_generic(parse_quote! { I }); - } - - s.add_bounds(synstructure::AddBounds::None); - s.add_where_predicate(parse_quote! { I: Interner }); - s.add_impl_generic(parse_quote! { J }); - s.add_where_predicate(parse_quote! { J: Interner }); - - let mut wc = vec![]; - s.bind_with(|_| synstructure::BindStyle::Move); - let body_fold = s.each_variant(|vi| { - let bindings = vi.bindings(); - vi.construct(|field, index| { - let ty = field.ty.clone(); - let lifted_ty = lift(ty.clone()); - wc.push(parse_quote! { #ty: ::rustc_type_ir::lift::Lift }); - let bind = &bindings[index]; - quote! { - #bind.lift_to_interner(interner)? - } - }) - }); - for wc in wc { - s.add_where_predicate(wc); - } - - let (_, ty_generics, _) = s.ast().generics.split_for_impl(); - let name = s.ast().ident.clone(); - let self_ty: syn::Type = parse_quote! { #name #ty_generics }; - let lifted_ty = lift(self_ty); - - s.bound_impl( - quote!(::rustc_type_ir::lift::Lift), - quote! { - type Lifted = #lifted_ty; - - fn lift_to_interner( - self, - interner: J, - ) -> Option { - Some(match self { #body_fold }) - } - }, - ) -} - -fn lift(mut ty: syn::Type) -> syn::Type { - struct ItoJ; - impl VisitMut for ItoJ { - fn visit_type_path_mut(&mut self, i: &mut syn::TypePath) { - if i.qself.is_none() { - if let Some(first) = i.path.segments.first_mut() - && first.ident == "I" - { - *first = parse_quote! { J }; - } - } - syn::visit_mut::visit_type_path_mut(self, i); - } - } - - ItoJ.visit_type_mut(&mut ty); - - ty -} - #[cfg(not(feature = "nightly"))] fn customizable_type_visitable_derive( mut s: synstructure::Structure<'_>,