Skip to content

Commit 0b5a4c1

Browse files
committed
Remove Print::Output
Now that `Printer` doesn't have subprinters anymore, the output of a printing operation is always the same.
1 parent 3895f0e commit 0b5a4c1

File tree

6 files changed

+27
-43
lines changed

6 files changed

+27
-43
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
140140
}
141141
fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, Self::Error>
142142
where
143-
T: Print<'tcx, Self, Output = Self, Error = Self::Error>,
143+
T: Print<'tcx, Self, Error = Self::Error>,
144144
{
145145
if let Some(first) = elems.next() {
146146
self = first.print(self)?;

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Highlighted<'tcx, T> {
2828

2929
impl<'tcx, T> IntoDiagnosticArg for Highlighted<'tcx, T>
3030
where
31-
T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>, Error = fmt::Error, Output = FmtPrinter<'a, 'tcx>>,
31+
T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>, Error = fmt::Error>,
3232
{
3333
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
3434
rustc_errors::DiagnosticArgValue::Str(self.to_string().into())
@@ -43,7 +43,7 @@ impl<'tcx, T> Highlighted<'tcx, T> {
4343

4444
impl<'tcx, T> fmt::Display for Highlighted<'tcx, T>
4545
where
46-
T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>, Error = fmt::Error, Output = FmtPrinter<'a, 'tcx>>,
46+
T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>, Error = fmt::Error>,
4747
{
4848
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4949
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS);

compiler/rustc_middle/src/ty/print/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ pub use self::pretty::*;
1313
// FIXME(eddyb) false positive, the lifetime parameters are used with `P: Printer<...>`.
1414
#[allow(unused_lifetimes)]
1515
pub trait Print<'tcx, P> {
16-
type Output;
1716
type Error;
1817

19-
fn print(&self, cx: P) -> Result<Self::Output, Self::Error>;
18+
fn print(&self, cx: P) -> Result<P, Self::Error>;
2019
}
2120

2221
/// Interface for outputting user-facing "type-system entities"
@@ -289,34 +288,30 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
289288
}
290289

291290
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Region<'tcx> {
292-
type Output = P;
293291
type Error = P::Error;
294-
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
292+
fn print(&self, cx: P) -> Result<P, Self::Error> {
295293
cx.print_region(*self)
296294
}
297295
}
298296

299297
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for Ty<'tcx> {
300-
type Output = P;
301298
type Error = P::Error;
302299

303-
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
300+
fn print(&self, cx: P) -> Result<P, Self::Error> {
304301
cx.print_type(*self)
305302
}
306303
}
307304

308305
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
309-
type Output = P;
310306
type Error = P::Error;
311-
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
307+
fn print(&self, cx: P) -> Result<P, Self::Error> {
312308
cx.print_dyn_existential(self)
313309
}
314310
}
315311

316312
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Const<'tcx> {
317-
type Output = P;
318313
type Error = P::Error;
319-
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
314+
fn print(&self, cx: P) -> Result<P, Self::Error> {
320315
cx.print_const(*self)
321316
}
322317
}

compiler/rustc_middle/src/ty/print/pretty.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
217217

218218
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, Self::Error>
219219
where
220-
T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
220+
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
221221
{
222222
value.as_ref().skip_binder().print(self)
223223
}
@@ -228,15 +228,15 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
228228
f: F,
229229
) -> Result<Self, Self::Error>
230230
where
231-
T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
231+
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
232232
{
233233
f(value.as_ref().skip_binder(), self)
234234
}
235235

236236
/// Prints comma-separated elements.
237237
fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, Self::Error>
238238
where
239-
T: Print<'tcx, Self, Output = Self, Error = Self::Error>,
239+
T: Print<'tcx, Self, Error = Self::Error>,
240240
{
241241
if let Some(first) = elems.next() {
242242
self = first.print(self)?;
@@ -2085,7 +2085,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
20852085

20862086
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, Self::Error>
20872087
where
2088-
T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
2088+
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
20892089
{
20902090
self.pretty_in_binder(value)
20912091
}
@@ -2096,7 +2096,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
20962096
f: C,
20972097
) -> Result<Self, Self::Error>
20982098
where
2099-
T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
2099+
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
21002100
{
21012101
self.pretty_wrap_binder(value, f)
21022102
}
@@ -2345,7 +2345,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
23452345
value: &ty::Binder<'tcx, T>,
23462346
) -> Result<(Self, T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>), fmt::Error>
23472347
where
2348-
T: Print<'tcx, Self, Output = Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
2348+
T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
23492349
{
23502350
fn name_by_region_index(
23512351
index: usize,
@@ -2515,7 +2515,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
25152515

25162516
pub fn pretty_in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, fmt::Error>
25172517
where
2518-
T: Print<'tcx, Self, Output = Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
2518+
T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
25192519
{
25202520
let old_region_index = self.region_index;
25212521
let (new, new_value, _) = self.name_all_regions(value)?;
@@ -2531,7 +2531,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
25312531
f: C,
25322532
) -> Result<Self, fmt::Error>
25332533
where
2534-
T: Print<'tcx, Self, Output = Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
2534+
T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
25352535
{
25362536
let old_region_index = self.region_index;
25372537
let (new, new_value, _) = self.name_all_regions(value)?;
@@ -2596,24 +2596,22 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
25962596

25972597
impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::Binder<'tcx, T>
25982598
where
2599-
T: Print<'tcx, P, Output = P, Error = P::Error> + TypeFoldable<TyCtxt<'tcx>>,
2599+
T: Print<'tcx, P, Error = P::Error> + TypeFoldable<TyCtxt<'tcx>>,
26002600
{
2601-
type Output = P;
26022601
type Error = P::Error;
26032602

2604-
fn print(&self, cx: P) -> Result<Self::Output, Self::Error> {
2603+
fn print(&self, cx: P) -> Result<P, Self::Error> {
26052604
cx.in_binder(self)
26062605
}
26072606
}
26082607

26092608
impl<'tcx, T, U, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::OutlivesPredicate<T, U>
26102609
where
2611-
T: Print<'tcx, P, Output = P, Error = P::Error>,
2612-
U: Print<'tcx, P, Output = P, Error = P::Error>,
2610+
T: Print<'tcx, P, Error = P::Error>,
2611+
U: Print<'tcx, P, Error = P::Error>,
26132612
{
2614-
type Output = P;
26152613
type Error = P::Error;
2616-
fn print(&self, mut cx: P) -> Result<Self::Output, Self::Error> {
2614+
fn print(&self, mut cx: P) -> Result<P, Self::Error> {
26172615
define_scoped_cx!(cx);
26182616
p!(print(self.0), ": ", print(self.1));
26192617
Ok(cx)
@@ -2640,9 +2638,8 @@ macro_rules! forward_display_to_print {
26402638
macro_rules! define_print_and_forward_display {
26412639
(($self:ident, $cx:ident): $($ty:ty $print:block)+) => {
26422640
$(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty {
2643-
type Output = P;
26442641
type Error = fmt::Error;
2645-
fn print(&$self, $cx: P) -> Result<Self::Output, Self::Error> {
2642+
fn print(&$self, $cx: P) -> Result<P, Self::Error> {
26462643
#[allow(unused_mut)]
26472644
let mut $cx = $cx;
26482645
define_scoped_cx!($cx);

compiler/rustc_symbol_mangling/src/legacy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'tcx> PrettyPrinter<'tcx> for &mut SymbolPrinter<'tcx> {
367367
}
368368
fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, Self::Error>
369369
where
370-
T: Print<'tcx, Self, Output = Self, Error = Self::Error>,
370+
T: Print<'tcx, Self, Error = Self::Error>,
371371
{
372372
if let Some(first) = elems.next() {
373373
self = first.print(self)?;

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ pub trait TypeErrCtxtExt<'tcx> {
6060
suggest_increasing_limit: bool,
6161
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
6262
where
63-
T: fmt::Display
64-
+ TypeFoldable<TyCtxt<'tcx>>
65-
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
63+
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
6664
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug;
6765

6866
fn report_overflow_error<T>(
@@ -73,9 +71,7 @@ pub trait TypeErrCtxtExt<'tcx> {
7371
mutate: impl FnOnce(&mut Diagnostic),
7472
) -> !
7573
where
76-
T: fmt::Display
77-
+ TypeFoldable<TyCtxt<'tcx>>
78-
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
74+
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
7975
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug;
8076

8177
fn report_overflow_no_abort(&self, obligation: PredicateObligation<'tcx>) -> ErrorGuaranteed;
@@ -227,9 +223,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
227223
mutate: impl FnOnce(&mut Diagnostic),
228224
) -> !
229225
where
230-
T: fmt::Display
231-
+ TypeFoldable<TyCtxt<'tcx>>
232-
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
226+
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
233227
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug,
234228
{
235229
let mut err = self.build_overflow_error(predicate, span, suggest_increasing_limit);
@@ -247,9 +241,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
247241
suggest_increasing_limit: bool,
248242
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
249243
where
250-
T: fmt::Display
251-
+ TypeFoldable<TyCtxt<'tcx>>
252-
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
244+
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
253245
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug,
254246
{
255247
let predicate = self.resolve_vars_if_possible(predicate.clone());

0 commit comments

Comments
 (0)