Skip to content

Commit 6b7a441

Browse files
Add an opt-out in pretty printing for RTN rendering
1 parent 30f168e commit 6b7a441

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

compiler/rustc_hir_analysis/src/check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt as _};
8484
use rustc_infer::traits::ObligationCause;
8585
use rustc_middle::query::Providers;
8686
use rustc_middle::ty::error::{ExpectedFound, TypeError};
87+
use rustc_middle::ty::print::with_types_for_suggestion;
8788
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypingMode};
8889
use rustc_middle::{bug, span_bug};
8990
use rustc_session::parse::feature_err;
@@ -240,11 +241,11 @@ fn missing_items_err(
240241
(Vec::new(), Vec::new(), Vec::new());
241242

242243
for &trait_item in missing_items {
243-
let snippet = suggestion_signature(
244+
let snippet = with_types_for_suggestion!(suggestion_signature(
244245
tcx,
245246
trait_item,
246247
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
247-
);
248+
));
248249
let code = format!("{padding}{snippet}\n{padding}");
249250
if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
250251
missing_trait_item_label

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

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ thread_local! {
6363
static FORCE_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
6464
static REDUCED_QUERIES: Cell<bool> = const { Cell::new(false) };
6565
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
66+
static TYPE_FOR_SUGGESTION: Cell<bool> = const { Cell::new(false) };
6667
}
6768

6869
macro_rules! define_helper {
@@ -122,6 +123,11 @@ define_helper!(
122123
/// Prevent selection of visible paths. `Display` impl of DefId will prefer
123124
/// visible (public) reexports of types as paths.
124125
fn with_no_visible_paths(NoVisibleGuard, NO_VISIBLE_PATH);
126+
/// Render a type for the purposes of a suggestion, rather than for diagnostic
127+
/// clarity. Right now, this suppresses the "{{ path::to::Trait::method(..) }}"
128+
/// for RPITITs, but it could be used to render more friendly representations
129+
/// for things like `FnDef`, too.
130+
fn with_types_for_suggestion(TypeForSuggestionGuard, TYPE_FOR_SUGGESTION);
125131
);
126132

127133
/// Avoids running any queries during prints.
@@ -1224,6 +1230,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12241230
}
12251231

12261232
if self.tcx().features().return_type_notation()
1233+
&& !with_types_for_suggestion()
12271234
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) =
12281235
self.tcx().opt_rpitit_info(def_id)
12291236
&& let ty::Alias(_, alias_ty) =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ run-rustfix
2+
3+
#![allow(unused)]
4+
#![feature(return_type_notation)]
5+
6+
trait Foo {
7+
fn missing() -> impl Sized;
8+
}
9+
10+
impl Foo for () {
11+
//~^ ERROR not all trait items implemented, missing: `missing`
12+
fn missing() -> impl Sized { todo!() }
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ run-rustfix
2+
3+
#![allow(unused)]
4+
#![feature(return_type_notation)]
5+
6+
trait Foo {
7+
fn missing() -> impl Sized;
8+
}
9+
10+
impl Foo for () {
11+
//~^ ERROR not all trait items implemented, missing: `missing`
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `missing`
2+
--> $DIR/rendering.rs:10:1
3+
|
4+
LL | fn missing() -> impl Sized;
5+
| --------------------------- `missing` from trait
6+
...
7+
LL | impl Foo for () {
8+
| ^^^^^^^^^^^^^^^ missing `missing` in implementation
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)