mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-20 10:55:14 +00:00
Place binder correctly for arbitrary trait bound suggestion
This commit is contained in:
parent
f63ccaf25f
commit
16e2b9f662
@ -117,7 +117,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
|
||||
}
|
||||
|
||||
let param_name = trait_pred.skip_binder().self_ty().to_string();
|
||||
let mut constraint = trait_pred.print_modifiers_and_trait_path().to_string();
|
||||
let mut constraint = trait_pred.to_string();
|
||||
|
||||
if let Some((name, term)) = associated_ty {
|
||||
// FIXME: this case overlaps with code in TyCtxt::note_and_explain_type_err.
|
||||
@ -144,7 +144,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
|
||||
this requirement",
|
||||
if generics.where_clause_span.is_empty() { "introducing a" } else { "extending the" },
|
||||
),
|
||||
format!("{} {}: {}", generics.add_where_or_trailing_comma(), param_name, constraint),
|
||||
format!("{} {constraint}", generics.add_where_or_trailing_comma()),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
true
|
||||
|
@ -0,0 +1,16 @@
|
||||
trait Foo
|
||||
where
|
||||
for<'a> &'a Self: Bar,
|
||||
{
|
||||
}
|
||||
|
||||
impl Foo for () {}
|
||||
|
||||
trait Bar {}
|
||||
|
||||
impl Bar for &() {}
|
||||
|
||||
fn foo<T: Foo>() {}
|
||||
//~^ ERROR the trait bound `for<'a> &'a T: Bar` is not satisfied
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,22 @@
|
||||
error[E0277]: the trait bound `for<'a> &'a T: Bar` is not satisfied
|
||||
--> $DIR/correct-binder-for-arbitrary-bound-sugg.rs:13:11
|
||||
|
|
||||
LL | fn foo<T: Foo>() {}
|
||||
| ^^^ the trait `for<'a> Bar` is not implemented for `&'a T`
|
||||
|
|
||||
note: required by a bound in `Foo`
|
||||
--> $DIR/correct-binder-for-arbitrary-bound-sugg.rs:3:23
|
||||
|
|
||||
LL | trait Foo
|
||||
| --- required by a bound in this trait
|
||||
LL | where
|
||||
LL | for<'a> &'a Self: Bar,
|
||||
| ^^^ required by this bound in `Foo`
|
||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
||||
|
|
||||
LL | fn foo<T: Foo>() where for<'a> &'a T: Bar {}
|
||||
| ++++++++++++++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user