Skip to content

Commit 7c825ed

Browse files
committed
PR-Feedback; fix for printing Region
1 parent df1786f commit 7c825ed

13 files changed

Lines changed: 48 additions & 106 deletions

File tree

compiler/rustc_hir_analysis/src/check/always_applicable.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
1111
use rustc_infer::traits::{ObligationCause, ObligationCauseCode};
1212
use rustc_middle::span_bug;
1313
use rustc_middle::ty::util::CheckRegions;
14-
use rustc_middle::ty::{
15-
self, GenericArgsRef, RegionExt, RegionUtilitiesExt, Ty, TyCtxt, TypingMode,
16-
};
14+
use rustc_middle::ty::{self, GenericArgsRef, RegionExt, Ty, TyCtxt, TypingMode};
1715
use rustc_trait_selection::regions::InferCtxtRegionExt;
1816
use rustc_trait_selection::traits::{self, ObligationCtxt};
1917

@@ -266,17 +264,13 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>(
266264
let item_span = tcx.def_span(adt_def_id);
267265
let self_descr = tcx.def_descr(adt_def_id);
268266
let outlives = match error {
269-
RegionResolutionError::ConcreteFailure(_, a, b) => {
270-
format!("{}: {}", b.to_string(), a.to_string())
271-
}
267+
RegionResolutionError::ConcreteFailure(_, a, b) => format!("{b}: {a}"),
272268
RegionResolutionError::GenericBoundFailure(_, generic, r) => {
273-
format!("{generic}: {}", r.to_string())
274-
}
275-
RegionResolutionError::SubSupConflict(_, _, _, a, _, b, _) => {
276-
format!("{}: {}", b.to_string(), a.to_string())
269+
format!("{generic}: {r}")
277270
}
271+
RegionResolutionError::SubSupConflict(_, _, _, a, _, b, _) => format!("{b}: {a}"),
278272
RegionResolutionError::UpperBoundUniverseConflict(a, _, _, _, b) => {
279-
format!("{}: {}", b.to_string(), ty::Region::new_var(tcx, a).to_string())
273+
format!("{b}: {a}", a = ty::Region::new_var(tcx, a))
280274
}
281275
RegionResolutionError::CannotNormalize(..) => unreachable!(),
282276
};

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
916916
e
917917
} else {
918918
bug!(
919-
"expected to map region {} to early-bound identity region, but got {}",
920-
region.to_string(),
921-
id_region.to_string()
919+
"expected to map region {region} to early-bound identity region, but got {id_region}"
922920
);
923921
}
924922
} else {

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,8 @@ fn bounds_from_generic_predicates<'tcx>(
406406
&& !v.is_empty()
407407
{
408408
format!(
409-
"{}: {}",
410-
region.to_string(),
411-
v.into_iter().map(|r| r.to_string()).collect::<Vec<_>>().join(" + ")
409+
"{region}: {}",
410+
v.into_iter().map(Region::to_string).collect::<Vec<_>>().join(" + ")
412411
)
413412
} else {
414413
region.to_string()
@@ -454,7 +453,7 @@ fn fn_sig_suggestion<'tcx>(
454453
Some(match ty.kind() {
455454
ty::Param(_) if assoc.is_method() && i == 0 => "self".to_string(),
456455
ty::Ref(reg, ref_ty, mutability) if i == 0 => {
457-
let reg = format!("{} ", reg.to_string());
456+
let reg = format!("{reg} ");
458457
let reg = match &reg[..] {
459458
"'_ " | " " => "",
460459
reg => reg,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
620620
// In our example, requires that `Self: 'a`
621621
if ty_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *ty, *region_a) {
622622
debug!(?ty_idx, ?region_a_idx);
623-
debug!("required clause: {ty} must outlive {}", region_a.to_string());
623+
debug!("required clause: {ty} must outlive {region_a}");
624624
// Translate into the generic parameters of the GAT. In
625625
// our example, the type was `Self`, which will also be
626626
// `Self` in the GAT.
@@ -655,11 +655,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
655655
}
656656
if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) {
657657
debug!(?region_a_idx, ?region_b_idx);
658-
debug!(
659-
"required clause: {} must outlive {}",
660-
region_a.to_string(),
661-
region_b.to_string()
662-
);
658+
debug!("required clause: {region_a} must outlive {region_b}");
663659
// Translate into the generic parameters of the GAT.
664660
let region_a_param = gat_generics.param_at(*region_a_idx, tcx);
665661
let region_a_param = ty::Region::new_early_param(
@@ -2496,10 +2492,7 @@ fn lint_redundant_lifetimes<'tcx>(
24962492
rustc_lint_defs::builtin::REDUNDANT_LIFETIMES,
24972493
tcx.local_def_id_to_hir_id(def_id.expect_local()),
24982494
tcx.def_span(def_id),
2499-
RedundantLifetimeArgsLint {
2500-
candidate: candidate.diag_arg(),
2501-
victim: victim.diag_arg(),
2502-
},
2495+
RedundantLifetimeArgsLint { candidate, victim },
25032496
);
25042497
}
25052498
}
@@ -2511,7 +2504,7 @@ fn lint_redundant_lifetimes<'tcx>(
25112504
#[note("you can use the `{$candidate}` lifetime directly, in place of `{$victim}`")]
25122505
struct RedundantLifetimeArgsLint<'tcx> {
25132506
/// The lifetime we have found to be redundant.
2514-
victim: ty::RegionDiagArg<'tcx>,
2507+
victim: ty::Region<'tcx>,
25152508
// The lifetime we can replace the victim with.
2516-
candidate: ty::RegionDiagArg<'tcx>,
2509+
candidate: ty::Region<'tcx>,
25172510
}

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use rustc_infer::traits::Obligation;
1414
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
1515
use rustc_middle::ty::print::PrintTraitRefExt as _;
1616
use rustc_middle::ty::{
17-
self, RegionUtilitiesExt, Ty, TyCtxt, TypeVisitableExt, TypingMode,
18-
suggest_constraining_type_params,
17+
self, Ty, TyCtxt, TypeVisitableExt, TypingMode, suggest_constraining_type_params,
1918
};
2019
use rustc_span::{DUMMY_SP, Span, sym};
2120
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
@@ -727,7 +726,7 @@ fn infringing_fields_error<'tcx>(
727726
let ty = ty.to_string();
728727
match error {
729728
RegionResolutionError::ConcreteFailure(origin, a, b) => {
730-
let predicate = format!("{}: {}", b.to_string(), a.to_string());
729+
let predicate = format!("{b}: {a}");
731730
errors
732731
.entry((ty.clone(), predicate.clone()))
733732
.or_default()
@@ -739,7 +738,7 @@ fn infringing_fields_error<'tcx>(
739738
}
740739
}
741740
RegionResolutionError::GenericBoundFailure(origin, a, b) => {
742-
let predicate = format!("{}: {}", a.to_string(), b.to_string());
741+
let predicate = format!("{a}: {b}");
743742
errors
744743
.entry((ty.clone(), predicate.clone()))
745744
.or_default()

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::mir::interpret::{
1515
};
1616
use crate::mir::visit::Visitor;
1717
use crate::mir::*;
18-
use crate::ty::RegionUtilitiesExt;
1918

2019
const INDENT: &str = " ";
2120
/// Alignment for lining up comments following MIR statements

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub use self::predicate::{
9999
RegionOutlivesPredicate, SubtypePredicate, TraitPredicate, TraitRef, TypeOutlivesPredicate,
100100
};
101101
pub use self::region::{
102-
EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionDiagArg, RegionExt,
103-
RegionKind, RegionUtilitiesExt, RegionVid,
102+
EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionExt, RegionKind,
103+
RegionUtilitiesExt, RegionVid,
104104
};
105105
pub use self::sty::{
106106
AliasTy, AliasTyKind, Article, Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy,

compiler/rustc_middle/src/ty/opaque_types.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use tracing::{debug, instrument, trace};
55

66
use crate::error::ConstNotUsedTraitAlias;
77
use crate::ty::{
8-
self, GenericArg, GenericArgKind, RegionExt, RegionUtilitiesExt, Ty, TyCtxt, TypeFoldable,
9-
TypeFolder, TypeSuperFoldable,
8+
self, GenericArg, GenericArgKind, RegionExt, Ty, TyCtxt, TypeFoldable, TypeFolder,
9+
TypeSuperFoldable,
1010
};
1111

1212
pub type OpaqueTypeKey<'tcx> = rustc_type_ir::OpaqueTypeKey<TyCtxt<'tcx>>;
@@ -126,17 +126,15 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
126126
Some(u) => panic!("region mapped to unexpected kind: {u:?}"),
127127
None if self.do_not_error => self.tcx.lifetimes.re_static,
128128
None => {
129-
let r = r.to_string();
130129
let e = self
131130
.tcx
132131
.dcx()
133132
.struct_span_err(self.span, "non-defining opaque type use in defining scope")
134133
.with_span_label(
135134
self.span,
136135
format!(
137-
"lifetime `{}` is part of concrete type but not used in \
136+
"lifetime `{r}` is part of concrete type but not used in \
138137
parameter list of the `impl Trait` type alias",
139-
r
140138
),
141139
)
142140
.emit();

compiler/rustc_middle/src/ty/region.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
1-
use std::fmt;
2-
3-
use rustc_errors::{DiagArgValue, IntoDiagArg, MultiSpan};
4-
use rustc_hir::def::Namespace;
1+
use rustc_errors::MultiSpan;
52
use rustc_hir::def_id::DefId;
63
use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
74
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Symbol, kw, sym};
85
pub use rustc_type_ir::RegionVid;
96
use rustc_type_ir::{Region as IrRegion, RegionKind as IrRegionKind};
107
use tracing::debug;
118

12-
use crate::ty::print::{FmtPrinter, Print};
139
use crate::ty::{self, BoundVar, TyCtxt, TypeFlags};
1410

1511
pub type Region<'tcx> = IrRegion<TyCtxt<'tcx>>;
1612
pub type RegionKind<'tcx> = IrRegionKind<TyCtxt<'tcx>>;
1713

18-
#[derive(Copy, Clone)]
19-
pub struct RegionDisplay<'tcx>(pub Region<'tcx>);
20-
21-
#[derive(Copy, Clone)]
22-
pub struct RegionDiagArg<'tcx>(pub Region<'tcx>);
23-
24-
impl fmt::Display for RegionDisplay<'_> {
25-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26-
ty::tls::with(|tcx| {
27-
let mut p = FmtPrinter::new(tcx, Namespace::TypeNS);
28-
tcx.lift(self.0).expect("could not lift region for printing").print(&mut p)?;
29-
f.write_str(&p.into_buffer())
30-
})
31-
}
32-
}
33-
34-
impl IntoDiagArg for RegionDiagArg<'_> {
35-
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
36-
DiagArgValue::Str(RegionDisplay(self.0).to_string().into())
37-
}
38-
}
39-
4014
#[extension(pub trait RegionExt<'tcx>)]
4115
impl<'tcx> Region<'tcx> {
4216
#[inline]
@@ -118,18 +92,6 @@ impl<'tcx> Region<'tcx> {
11892
/// Region utilities
11993
#[extension(pub trait RegionUtilitiesExt<'tcx>)]
12094
impl<'tcx> Region<'tcx> {
121-
fn display(self) -> RegionDisplay<'tcx> {
122-
RegionDisplay(self)
123-
}
124-
125-
fn diag_arg(self) -> RegionDiagArg<'tcx> {
126-
RegionDiagArg(self)
127-
}
128-
129-
fn to_string(self) -> String {
130-
self.display().to_string()
131-
}
132-
13395
fn kind(self) -> RegionKind<'tcx> {
13496
*self.0.0
13597
}

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
20422042
long_ty_path: &mut Option<PathBuf>,
20432043
) -> Option<(DiagStyledString, DiagStyledString)> {
20442044
match values {
2045-
ValuePairs::Regions(exp_found) => self.expected_found_str_region(exp_found),
2045+
ValuePairs::Regions(exp_found) => self.expected_found_str(exp_found),
20462046
ValuePairs::Terms(exp_found) => self.expected_found_str_term(exp_found, long_ty_path),
20472047
ValuePairs::Aliases(exp_found) => self.expected_found_str(exp_found),
20482048
ValuePairs::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
@@ -2116,21 +2116,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21162116
})
21172117
}
21182118

2119-
fn expected_found_str_region(
2120-
&self,
2121-
exp_found: ty::error::ExpectedFound<ty::Region<'tcx>>,
2122-
) -> Option<(DiagStyledString, DiagStyledString)> {
2123-
let exp_found = self.resolve_vars_if_possible(exp_found);
2124-
if exp_found.references_error() {
2125-
return None;
2126-
}
2127-
2128-
Some((
2129-
DiagStyledString::highlighted(exp_found.expected.to_string()),
2130-
DiagStyledString::highlighted(exp_found.found.to_string()),
2131-
))
2132-
}
2133-
21342119
/// Returns a string of the form "expected `{}`, found `{}`".
21352120
fn expected_found_str<T: fmt::Display + TypeFoldable<TyCtxt<'tcx>>>(
21362121
&self,

0 commit comments

Comments
 (0)