-
Notifications
You must be signed in to change notification settings - Fork 13k
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
: erase regions sooner
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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
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`. |