Skip to content

Commit d415200

Browse files
authored
Rollup merge of #137458 - compiler-errors:render-fn, r=fmease
Fix missing self subst when rendering `impl Fn*<T>` with no output type r? `@fmease` or reassign Fixes #133597 cc #137456
2 parents f5c6287 + 431b9aa commit d415200

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

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

+14-10
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
232232
f: F,
233233
) -> Result<(), PrintError>
234234
where
235-
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
235+
T: TypeFoldable<TyCtxt<'tcx>>,
236236
{
237237
f(value.as_ref().skip_binder(), self)
238238
}
@@ -1056,7 +1056,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10561056
// Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
10571057
let paren_needed = fn_traits.len() > 1 || traits.len() > 0 || !has_sized_bound;
10581058

1059-
for ((bound_args, is_async), entry) in fn_traits {
1059+
for ((bound_args_and_self_ty, is_async), entry) in fn_traits {
10601060
write!(self, "{}", if first { "" } else { " + " })?;
10611061
write!(self, "{}", if paren_needed { "(" } else { "" })?;
10621062

@@ -1067,7 +1067,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10671067
};
10681068

10691069
if let Some(return_ty) = entry.return_ty {
1070-
self.wrap_binder(&bound_args, |args, cx| {
1070+
self.wrap_binder(&bound_args_and_self_ty, |(args, _), cx| {
10711071
define_scoped_cx!(cx);
10721072
p!(write("{}", tcx.item_name(trait_def_id)));
10731073
p!("(");
@@ -1093,9 +1093,13 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10931093
} else {
10941094
// Otherwise, render this like a regular trait.
10951095
traits.insert(
1096-
bound_args.map_bound(|args| ty::TraitPredicate {
1096+
bound_args_and_self_ty.map_bound(|(args, self_ty)| ty::TraitPredicate {
10971097
polarity: ty::PredicatePolarity::Positive,
1098-
trait_ref: ty::TraitRef::new(tcx, trait_def_id, [Ty::new_tup(tcx, args)]),
1098+
trait_ref: ty::TraitRef::new(
1099+
tcx,
1100+
trait_def_id,
1101+
[self_ty, Ty::new_tup(tcx, args)],
1102+
),
10991103
}),
11001104
FxIndexMap::default(),
11011105
);
@@ -1229,7 +1233,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12291233
FxIndexMap<DefId, ty::Binder<'tcx, Term<'tcx>>>,
12301234
>,
12311235
fn_traits: &mut FxIndexMap<
1232-
(ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>>, bool),
1236+
(ty::Binder<'tcx, (&'tcx ty::List<Ty<'tcx>>, Ty<'tcx>)>, bool),
12331237
OpaqueFnEntry<'tcx>,
12341238
>,
12351239
) {
@@ -1249,7 +1253,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12491253
&& let ty::Tuple(types) = *trait_pred.skip_binder().trait_ref.args.type_at(1).kind()
12501254
{
12511255
let entry = fn_traits
1252-
.entry((trait_pred.rebind(types), is_async))
1256+
.entry((trait_pred.rebind((types, trait_pred.skip_binder().self_ty())), is_async))
12531257
.or_insert_with(|| OpaqueFnEntry { kind, return_ty: None });
12541258
if kind.extends(entry.kind) {
12551259
entry.kind = kind;
@@ -2379,7 +2383,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
23792383
f: C,
23802384
) -> Result<(), PrintError>
23812385
where
2382-
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
2386+
T: TypeFoldable<TyCtxt<'tcx>>,
23832387
{
23842388
self.pretty_wrap_binder(value, f)
23852389
}
@@ -2633,7 +2637,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
26332637
value: &ty::Binder<'tcx, T>,
26342638
) -> Result<(T, UnordMap<ty::BoundRegion, ty::Region<'tcx>>), fmt::Error>
26352639
where
2636-
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
2640+
T: TypeFoldable<TyCtxt<'tcx>>,
26372641
{
26382642
fn name_by_region_index(
26392643
index: usize,
@@ -2814,7 +2818,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
28142818
f: C,
28152819
) -> Result<(), fmt::Error>
28162820
where
2817-
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
2821+
T: TypeFoldable<TyCtxt<'tcx>>,
28182822
{
28192823
let old_region_index = self.region_index;
28202824
let (new_value, _) = self.name_all_regions(value)?;

tests/crashes/133597.rs

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Make sure we don't ICE printing `impl AsyncFnOnce<()>`.
2+
3+
#![feature(unboxed_closures, fn_traits)]
4+
5+
fn f() -> impl FnOnce<()> { || () }
6+
7+
fn main() { () = f(); }
8+
//~^ ERROR mismatched types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/existential-printing.rs:7:13
3+
|
4+
LL | fn f() -> impl FnOnce<()> { || () }
5+
| --------------- the expected opaque type
6+
LL |
7+
LL | fn main() { () = f(); }
8+
| ^^ --- this expression has type `impl FnOnce<()>`
9+
| |
10+
| expected opaque type, found `()`
11+
|
12+
= note: expected opaque type `impl FnOnce<()>`
13+
found unit type `()`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)