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 2 commits into
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.
|
r? types |
|
sry for not getting to this for so long, currently cleaning up my notification backlog r? types |
| } | ||
| 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?
There was a problem hiding this comment.
Sorry for the delay. I tried moving some of the suggestion logic to a closure, but there's some duplication in the pattern decomposition.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
```
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);
| + +
```
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r+ |
Account for ownership mismatch on argument that doesn't meet bound
```
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);
| + +
```
Fix rust-lang#134805.
…uwer Rollup of 23 pull requests Successful merges: - #153749 (Account for ownership mismatch on argument that doesn't meet bound) - #159326 (Deny multiple EII impls on a single item) - #159535 (Optimize slice::contains for bytewise types) - #159595 (Promote loongarch32-unknown-none* to Tier 2) - #160007 (allow `-Ldependency` search paths for panic runtimes) - #160184 (Add -Zinstrument-mcount={fentry-nop-record,fentry-record}) - #160320 (point at trait definition when it is used as a derive macro) - #160369 (When suggesting method names, prefer *exact* doc aliases over similar names) - #160406 (`DepKind` cleanups) - #160424 (Use `thread::available_parallelism` as the default limit for backend parallelism) - #159303 (Fix ICE for direct inline const generic defaults) - #159977 (Add regression test for bool indexing codegen) - #160011 (remove InterpError::map_err_info) - #160165 (reject `...` without pattern post-expansion) - #160295 (Fix rustdoc ICE when checking if a generic arg can be elided) - #160305 (Linkify C-SKY targets in `platform-support.md`) - #160314 (fix borrowck ICE for consts with fn pointer type) - #160322 (ElaborateBoxDeref: remove unnecessary projection) - #160338 (Add regression test for supertrait associated type normalization through dyn) - #160340 (Add regression test for unused_parens on contract clauses) - #160371 (Add doc aliases for transpositions `read_exact_buf` and `read_exact_buf_at`) - #160384 (Add PR body notes for Cargo lock file maintenance) - #160435 (bump tracing-tree)
Account for ownership mismatch on argument that doesn't meet bound
```
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);
| + +
```
Fix rust-lang#134805.
…uwer Rollup of 26 pull requests Successful merges: - #153749 (Account for ownership mismatch on argument that doesn't meet bound) - #158727 (std: use `readdir` on nearly all UNIX platforms) - #159130 (a bit optimize four-digit chunks in integer formatting) - #159326 (Deny multiple EII impls on a single item) - #159535 (Optimize slice::contains for bytewise types) - #159595 (Promote loongarch32-unknown-none* to Tier 2) - #160184 (Add -Zinstrument-mcount={fentry-nop-record,fentry-record}) - #160320 (point at trait definition when it is used as a derive macro) - #160369 (When suggesting method names, prefer *exact* doc aliases over similar names) - #160406 (`DepKind` cleanups) - #160424 (Use `thread::available_parallelism` as the default limit for backend parallelism) - #159303 (Fix ICE for direct inline const generic defaults) - #159977 (Add regression test for bool indexing codegen) - #160011 (remove InterpError::map_err_info) - #160165 (reject `...` without pattern post-expansion) - #160295 (Fix rustdoc ICE when checking if a generic arg can be elided) - #160305 (Linkify C-SKY targets in `platform-support.md`) - #160314 (fix borrowck ICE for consts with fn pointer type) - #160322 (ElaborateBoxDeref: remove unnecessary projection) - #160338 (Add regression test for supertrait associated type normalization through dyn) - #160340 (Add regression test for unused_parens on contract clauses) - #160371 (Add doc aliases for transpositions `read_exact_buf` and `read_exact_buf_at`) - #160384 (Add PR body notes for Cargo lock file maintenance) - #160412 (Move duplicate-names check for #[rustc_must_implement_one_of] to attribute parser) - #160435 (bump tracing-tree) - #160449 (Fix lookup of object files)
Fix #134805.