Shift lift calls outward.

Several printing functions (e.g. `short_string`) take a liftable
parameter. This commit changes the call sites to do the lifting instead.
This simplifies the type signatures and puts the `lift` calls inside
`tls::with` calls which is where they usually appear, and the minor cost
of having more `lift` call sites.
This commit is contained in:
Nicholas Nethercote
2026-04-30 21:04:27 +10:00
parent 67ba480fdb
commit 809fcab63e
4 changed files with 13 additions and 13 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ use crate::ty::{
impl IntoDiagArg for Ty<'_> {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
ty::tls::with(|tcx| {
let ty = tcx.short_string(self, path);
let ty = tcx.short_string(tcx.lift(self), path);
DiagArgValue::Str(std::borrow::Cow::Owned(ty))
})
}
@@ -31,7 +31,7 @@ impl IntoDiagArg for Ty<'_> {
impl IntoDiagArg for Instance<'_> {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
ty::tls::with(|tcx| {
let instance = tcx.short_string_namespace(self, path, Namespace::ValueNS);
let instance = tcx.short_string_namespace(tcx.lift(self), path, Namespace::ValueNS);
DiagArgValue::Str(std::borrow::Cow::Owned(instance))
})
}
+7 -7
View File
@@ -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<TyCtxt<'tcx>>;
@@ -220,10 +220,10 @@ impl<'tcx> Ty<'tcx> {
impl<'tcx> TyCtxt<'tcx> {
pub fn string_with_limit<T>(self, t: T, length_limit: usize, ns: hir::def::Namespace) -> String
where
T: Copy + for<'a, 'b> Lift<TyCtxt<'b>, Lifted: Print<FmtPrinter<'a, 'b>>>,
T: Copy + for<'a> Print<FmtPrinter<'a, 'tcx>>,
{
let mut type_limit = 50;
let regular = FmtPrinter::print_string(self, ns, |p| self.lift(t).print(p))
let regular = FmtPrinter::print_string(self, ns, |p| t.print(p))
.expect("could not write to `String`");
if regular.len() <= length_limit {
return regular;
@@ -233,7 +233,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).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 {
@@ -250,7 +250,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// where we wrote the file to is only printed once. The path will use the type namespace.
pub fn short_string<T>(self, t: T, path: &mut Option<PathBuf>) -> String
where
T: Copy + Hash + for<'a, 'b> Lift<TyCtxt<'b>, Lifted: Print<FmtPrinter<'a, 'b>>>,
T: Copy + Hash + for<'a> Print<FmtPrinter<'a, 'tcx>>,
{
self.short_string_namespace(t, path, hir::def::Namespace::TypeNS)
}
@@ -266,9 +266,9 @@ impl<'tcx> TyCtxt<'tcx> {
namespace: hir::def::Namespace,
) -> String
where
T: Copy + Hash + for<'a, 'b> Lift<TyCtxt<'b>, Lifted: Print<FmtPrinter<'a, 'b>>>,
T: Copy + Hash + for<'a> Print<FmtPrinter<'a, 'tcx>>,
{
let regular = FmtPrinter::print_string(self, namespace, |p| self.lift(t).print(p))
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 {
+2 -2
View File
@@ -113,7 +113,7 @@ impl<'tcx> Predicate<'tcx> {
impl<'tcx> rustc_errors::IntoDiagArg for Predicate<'tcx> {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
ty::tls::with(|tcx| {
let pred = tcx.short_string(self, path);
let pred = tcx.short_string(tcx.lift(self), path);
rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(pred))
})
}
@@ -122,7 +122,7 @@ impl<'tcx> rustc_errors::IntoDiagArg for Predicate<'tcx> {
impl<'tcx> rustc_errors::IntoDiagArg for Clause<'tcx> {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
ty::tls::with(|tcx| {
let clause = tcx.short_string(self, path);
let clause = tcx.short_string(tcx.lift(self), path);
rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(clause))
})
}
+2 -2
View File
@@ -2970,7 +2970,7 @@ pub struct TraitRefPrintOnlyTraitPath<'tcx>(ty::TraitRef<'tcx>);
impl<'tcx> rustc_errors::IntoDiagArg for TraitRefPrintOnlyTraitPath<'tcx> {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
ty::tls::with(|tcx| {
let trait_ref = tcx.short_string(self, path);
let trait_ref = tcx.short_string(tcx.lift(self), path);
rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(trait_ref))
})
}
@@ -2990,7 +2990,7 @@ pub struct TraitRefPrintSugared<'tcx>(ty::TraitRef<'tcx>);
impl<'tcx> rustc_errors::IntoDiagArg for TraitRefPrintSugared<'tcx> {
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
ty::tls::with(|tcx| {
let trait_ref = tcx.short_string(self, path);
let trait_ref = tcx.short_string(tcx.lift(self), path);
rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(trait_ref))
})
}