Skip to content

Commit b2f8f60

Browse files
Place binder correctly for arbitrary trait bound suggestion
1 parent 8f55d60 commit b2f8f60

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

compiler/rustc_middle/src/ty/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
118118
}
119119

120120
let param_name = trait_pred.skip_binder().self_ty().to_string();
121-
let mut constraint = trait_pred.print_modifiers_and_trait_path().to_string();
121+
let mut constraint = trait_pred.to_string();
122122

123123
if let Some((name, term)) = associated_ty {
124124
// FIXME: this case overlaps with code in TyCtxt::note_and_explain_type_err.
@@ -145,7 +145,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
145145
this requirement",
146146
if generics.where_clause_span.is_empty() { "introducing a" } else { "extending the" },
147147
),
148-
format!("{} {}: {}", generics.add_where_or_trailing_comma(), param_name, constraint),
148+
format!("{} {constraint}", generics.add_where_or_trailing_comma()),
149149
Applicability::MaybeIncorrect,
150150
);
151151
true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Foo
2+
where
3+
for<'a> &'a Self: Bar,
4+
{
5+
}
6+
7+
impl Foo for () {}
8+
9+
trait Bar {}
10+
11+
impl Bar for &() {}
12+
13+
fn foo<T: Foo>() {}
14+
//~^ ERROR the trait bound `for<'a> &'a T: Bar` is not satisfied
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0277]: the trait bound `for<'a> &'a T: Bar` is not satisfied
2+
--> $DIR/correct-binder-for-arbitrary-bound-sugg.rs:13:11
3+
|
4+
LL | fn foo<T: Foo>() {}
5+
| ^^^ the trait `for<'a> Bar` is not implemented for `&'a T`
6+
|
7+
note: required by a bound in `Foo`
8+
--> $DIR/correct-binder-for-arbitrary-bound-sugg.rs:3:23
9+
|
10+
LL | trait Foo
11+
| --- required by a bound in this
12+
LL | where
13+
LL | for<'a> &'a Self: Bar,
14+
| ^^^ required by this bound in `Foo`
15+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
16+
|
17+
LL | fn foo<T: Foo>() where for<'a> &'a T: Bar {}
18+
| ++++++++++++++++++++++++
19+
20+
error: aborting due to previous error
21+
22+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)