Account for ownership mismatch on argument that doesn't meet bound#153749
Account for ownership mismatch on argument that doesn't meet bound#153749estebank wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| mod needs_deref { | ||
| #[derive(Clone, Copy, Debug)] | ||
| struct Hello; | ||
|
|
||
| trait Tr: Clone + Copy {} | ||
| impl Tr for Hello {} | ||
|
|
||
| fn foo<T: Tr, K: std::fmt::Debug>(_v: T, _w: T, _k: K) {} | ||
|
|
||
| struct S; | ||
| impl S { | ||
| fn foo<K: std::fmt::Debug, T: Tr>(&self, _v: T, _w: T, _k: K) {} | ||
| } | ||
|
|
||
| fn bar() { | ||
| let hellos = [Hello; 3]; | ||
| for hi in hellos.iter() { | ||
| foo(hi, hi, hi); //~ ERROR: the trait bound `&needs_deref::Hello: needs_deref::Tr` is not satisfied | ||
| S.foo(hi, hi, hi); //~ ERROR: the trait bound `&needs_deref::Hello: needs_deref::Tr` is not satisfied | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
@arferreira This case I was mentioning that would be nice to handle after this PR (plus one other test for Hello not being Copy but still being Clone) is what still needs to be handled. We should suggest
foo(*hi, *hi, hi);
S.foo(*hi, *hi, hi);
for the case above and
foo(hi.clone(), hi.clone(), hi);
S.foo(hi.clone(), hi.clone(), hi);
if possible.
There was a problem hiding this comment.
Sounds good, I'll pick up that. Thanks for the context!
This comment has been minimized.
This comment has been minimized.
```
error[E0277]: the trait bound `needs_borrow::Hello: needs_borrow::Tr` is not satisfied
--> $DIR/ownership-mismatch-on-arg.rs:42:13
|
LL | foo(hi, hi, hi);
| ^^^ -- -- `needs_borrow::Hello` doesn't satisfy the trait bound
| | |
| | `needs_borrow::Hello` doesn't satisfy the trait bound
| unsatisfied trait bound
|
help: the trait `needs_borrow::Tr` is not implemented for `needs_borrow::Hello`
--> $DIR/ownership-mismatch-on-arg.rs:27:5
|
LL | struct Hello;
| ^^^^^^^^^^^^
help: the trait `needs_borrow::Tr` is implemented for `&needs_borrow::Hello`
--> $DIR/ownership-mismatch-on-arg.rs:30:5
|
LL | impl Tr for &Hello {}
| ^^^^^^^^^^^^^^^^^^
note: required by a bound in `needs_borrow::foo`
--> $DIR/ownership-mismatch-on-arg.rs:32:15
|
LL | fn foo<T: Tr, K: std::fmt::Debug>(_v: T, _w: T, _k: K) {}
| ^^ required by this bound in `foo`
help: consider borrowing these argument
|
LL | foo(&hi, &hi, hi);
| + +
```
|
r? types |
|
sry for not getting to this for so long, currently cleaning up my notification backlog r? types |
| let ty = self.tcx.instantiate_bound_regions_with_erased( | ||
| poly_trait_pred.self_ty(), | ||
| ); |
There was a problem hiding this comment.
Minor nit, but this can be pull out of the loop. Probably renamed to erased_self_ty
| } | ||
| c | ||
| } | ||
| ObligationCauseCode::WhereClauseInExpr(def_id, _, hir_id, idx) |
There was a problem hiding this comment.
A lot of this code is duplicated...any way to deduplicate?
Fix #134805.