Skip to content

Commit 20eebb2

Browse files
Fix pretty printing of placeholder types
1 parent f508b8c commit 20eebb2

File tree

8 files changed

+41
-36
lines changed

8 files changed

+41
-36
lines changed

compiler/rustc_infer/src/infer/region_constraints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl<'tcx> fmt::Display for GenericKind<'tcx> {
655655
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
656656
match *self {
657657
GenericKind::Param(ref p) => write!(f, "{p}"),
658-
GenericKind::Placeholder(ref p) => write!(f, "{p:?}"),
658+
GenericKind::Placeholder(ref p) => write!(f, "{p}"),
659659
GenericKind::Alias(ref p) => write!(f, "{p}"),
660660
}
661661
}

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
823823
ty::Alias(ty::Projection | ty::Inherent | ty::Free, ref data) => {
824824
p!(print(data))
825825
}
826-
ty::Placeholder(placeholder) => match placeholder.bound.kind {
827-
ty::BoundTyKind::Anon => p!(write("{placeholder:?}")),
828-
ty::BoundTyKind::Param(def_id) => match self.should_print_verbose() {
829-
true => p!(write("{:?}", ty.kind())),
830-
false => p!(write("{}", self.tcx().item_name(def_id))),
831-
},
832-
},
826+
ty::Placeholder(placeholder) => p!(print(placeholder)),
833827
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
834828
// We use verbose printing in 'NO_QUERIES' mode, to
835829
// avoid needing to call `predicates_of`. This should
@@ -3374,6 +3368,16 @@ define_print_and_forward_display! {
33743368
p!(write("{}", self.name))
33753369
}
33763370

3371+
ty::PlaceholderType {
3372+
match self.bound.kind {
3373+
ty::BoundTyKind::Anon => p!(write("{self:?}")),
3374+
ty::BoundTyKind::Param(def_id) => match cx.should_print_verbose() {
3375+
true => p!(write("{self:?}")),
3376+
false => p!(write("{}", cx.tcx().item_name(def_id))),
3377+
},
3378+
}
3379+
}
3380+
33773381
ty::ParamConst {
33783382
p!(write("{}", self.name))
33793383
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ TrivialTypeTraversalImpls! {
275275
crate::ty::BoundVar,
276276
crate::ty::InferConst,
277277
crate::ty::Placeholder<crate::ty::BoundRegion>,
278-
crate::ty::Placeholder<crate::ty::BoundTy>,
279278
crate::ty::Placeholder<ty::BoundVar>,
280279
crate::ty::UserTypeAnnotationIndex,
281280
crate::ty::ValTree<'tcx>,
@@ -304,6 +303,7 @@ TrivialTypeTraversalAndLiftImpls! {
304303
crate::ty::instance::ReifyReason,
305304
crate::ty::ParamConst,
306305
crate::ty::ParamTy,
306+
crate::ty::Placeholder<crate::ty::BoundTy>,
307307
rustc_hir::def_id::DefId,
308308
// tidy-alphabetical-end
309309
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
702702
}
703703

704704
let labeled_user_string = match bound_kind {
705-
GenericKind::Param(ref p) => format!("the parameter type `{p}`"),
706-
GenericKind::Placeholder(ref p) => format!("the placeholder type `{p:?}`"),
707-
GenericKind::Alias(ref p) => match p.kind(self.tcx) {
705+
GenericKind::Param(_) => format!("the parameter type `{bound_kind}`"),
706+
GenericKind::Placeholder(_) => format!("the placeholder type `{bound_kind}`"),
707+
GenericKind::Alias(p) => match p.kind(self.tcx) {
708708
ty::Projection | ty::Inherent => {
709-
format!("the associated type `{p}`")
709+
format!("the associated type `{bound_kind}`")
710710
}
711-
ty::Free => format!("the type alias `{p}`"),
712-
ty::Opaque => format!("the opaque type `{p}`"),
711+
ty::Free => format!("the type alias `{bound_kind}`"),
712+
ty::Opaque => format!("the opaque type `{bound_kind}`"),
713713
},
714714
};
715715

tests/ui/traits/non_lifetime_binders/placeholders-dont-outlive-static.bad.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ LL | #![feature(non_lifetime_binders)]
77
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error[E0310]: the placeholder type `!1_"T"` may not live long enough
10+
error[E0310]: the placeholder type `T` may not live long enough
1111
--> $DIR/placeholders-dont-outlive-static.rs:13:5
1212
|
1313
LL | foo();
1414
| ^^^^^
1515
| |
16-
| the placeholder type `!1_"T"` must be valid for the static lifetime...
16+
| the placeholder type `T` must be valid for the static lifetime...
1717
| ...so that the type `T` will meet its required lifetime bounds
1818
|
1919
help: consider adding an explicit lifetime bound
2020
|
21-
LL | fn bad() where !1_"T": 'static {
22-
| +++++++++++++++++++++
21+
LL | fn bad() where T: 'static {
22+
| ++++++++++++++++
2323

2424
error: aborting due to 1 previous error; 1 warning emitted
2525

tests/ui/traits/non_lifetime_binders/placeholders-dont-outlive-static.good.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ LL | #![feature(non_lifetime_binders)]
77
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error[E0310]: the placeholder type `!1_"T"` may not live long enough
10+
error[E0310]: the placeholder type `T` may not live long enough
1111
--> $DIR/placeholders-dont-outlive-static.rs:19:5
1212
|
1313
LL | foo();
1414
| ^^^^^
1515
| |
16-
| the placeholder type `!1_"T"` must be valid for the static lifetime...
16+
| the placeholder type `T` must be valid for the static lifetime...
1717
| ...so that the type `T` will meet its required lifetime bounds
1818
|
1919
help: consider adding an explicit lifetime bound
2020
|
21-
LL | fn good() where for<T> T: 'static, !1_"T": 'static {
22-
| +++++++++++++++++
21+
LL | fn good() where for<T> T: 'static, T: 'static {
22+
| ++++++++++++
2323

2424
error: aborting due to 1 previous error; 1 warning emitted
2525

tests/ui/traits/non_lifetime_binders/placeholders-dont-outlive-static.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn foo() where for<T> T: 'static {}
1111
#[cfg(bad)]
1212
fn bad() {
1313
foo();
14-
//[bad]~^ ERROR the placeholder type `!1_"T"` may not live long enough
14+
//[bad]~^ ERROR the placeholder type `T` may not live long enough
1515
}
1616

1717
#[cfg(good)]

tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ LL | #![feature(non_lifetime_binders)]
77
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error[E0309]: the placeholder type `!1_"F"` may not live long enough
10+
error[E0309]: the placeholder type `F` may not live long enough
1111
--> $DIR/type-match-with-late-bound.rs:8:1
1212
|
1313
LL | async fn walk2<'a, T: 'a>(_: T)
14-
| ^ -- the placeholder type `!1_"F"` must be valid for the lifetime `'a` as defined here...
14+
| ^ -- the placeholder type `F` must be valid for the lifetime `'a` as defined here...
1515
| _|
1616
| |
1717
LL | | where
@@ -25,36 +25,37 @@ LL | for<F> F: 'a,
2525
| ^^
2626
help: consider adding an explicit lifetime bound
2727
|
28-
LL | for<F> F: 'a, !1_"F": 'a
29-
| ++++++++++
28+
LL | for<F> F: 'a, F: 'a
29+
| +++++
3030

31-
error[E0309]: the placeholder type `!1_"F"` may not live long enough
31+
error[E0309]: the placeholder type `F` may not live long enough
3232
--> $DIR/type-match-with-late-bound.rs:11:1
3333
|
3434
LL | async fn walk2<'a, T: 'a>(_: T)
35-
| -- the placeholder type `!1_"F"` must be valid for the lifetime `'a` as defined here...
35+
| -- the placeholder type `F` must be valid for the lifetime `'a` as defined here...
3636
...
3737
LL | {}
3838
| ^^ ...so that the type `F` will meet its required lifetime bounds
3939
|
4040
help: consider adding an explicit lifetime bound
4141
|
42-
LL | for<F> F: 'a, !1_"F": 'a
43-
| ++++++++++
42+
LL | for<F> F: 'a, F: 'a
43+
| +++++
4444

45-
error[E0309]: the placeholder type `!2_"F"` may not live long enough
45+
error[E0309]: the placeholder type `F` may not live long enough
4646
--> $DIR/type-match-with-late-bound.rs:11:1
4747
|
4848
LL | async fn walk2<'a, T: 'a>(_: T)
49-
| -- the placeholder type `!2_"F"` must be valid for the lifetime `'a` as defined here...
49+
| -- the placeholder type `F` must be valid for the lifetime `'a` as defined here...
5050
...
5151
LL | {}
5252
| ^^ ...so that the type `F` will meet its required lifetime bounds
5353
|
54+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5455
help: consider adding an explicit lifetime bound
5556
|
56-
LL | for<F> F: 'a, !2_"F": 'a
57-
| ++++++++++
57+
LL | for<F> F: 'a, F: 'a
58+
| +++++
5859

5960
error: aborting due to 3 previous errors; 1 warning emitted
6061

0 commit comments

Comments
 (0)