forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#133130 - dianne:fix-133118, r=compiler-errors `suggest_borrow_generic_arg`: instantiate clauses properly This simplifies and fixes the way `suggest_borrow_generic_arg` instantiates callees' predicates when testing them to see if a moved argument can instead be borrowed. Previously, it would ICE if the moved argument's type included a region variable, since it was getting passed to a call of `EarlyBinder::instantiate`. This makes the instantiation much more straightforward, which also fixes the ICE. Fixes rust-lang#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`. |