-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggest_borrow_generic_arg
: instantiate clauses properly
Fixes issue 133118. This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
- Loading branch information
Showing
5 changed files
with
60 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! regression test for #133118 | ||
pub trait Alpha { | ||
fn y(self) -> usize; | ||
} | ||
|
||
pub trait Beta { | ||
type Gamma; | ||
fn gamma(&self) -> Self::Gamma; | ||
} | ||
|
||
pub fn a<T: Alpha>(_x: T) -> usize { | ||
todo!(); | ||
} | ||
|
||
pub fn x<B>(beta: &B) -> usize | ||
where | ||
for<'a> &'a B: Beta, | ||
for<'a> <&'a B as Beta>::Gamma: Alpha, | ||
{ | ||
let g1 = beta.gamma(); | ||
a(g1) + a(g1) //~ ERROR use of moved value: `g1` [E0382] | ||
} | ||
|
||
pub fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0382]: use of moved value: `g1` | ||
--> $DIR/region-var-in-moved-ty-issue-133118.rs:22:15 | ||
| | ||
LL | let g1 = beta.gamma(); | ||
| -- move occurs because `g1` has type `<&B as Beta>::Gamma`, which does not implement the `Copy` trait | ||
LL | a(g1) + a(g1) | ||
| -- ^^ value used here after move | ||
| | | ||
| value moved here | ||
| | ||
note: consider changing this parameter type in function `a` to borrow instead if owning the value isn't necessary | ||
--> $DIR/region-var-in-moved-ty-issue-133118.rs:12:24 | ||
| | ||
LL | pub fn a<T: Alpha>(_x: T) -> usize { | ||
| - ^ this parameter takes ownership of the value | ||
| | | ||
| in this function | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |