mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 16:57:03 +00:00
a1a3abb08f
``` error[E0505]: cannot move out of `a` because it is borrowed --> $DIR/variance-issue-20533.rs:28:14 | LL | let a = AffineU32(1); | - binding `a` declared here LL | let x = foo(&a); | -- borrow of `a` occurs here LL | drop(a); | ^ move out of `a` occurs here LL | drop(x); | - borrow later used here | help: consider cloning the value if the performance cost is acceptable | LL | let x = foo(&a).clone(); | ++++++++ ```
29 lines
717 B
Rust
29 lines
717 B
Rust
// Regression test for issue #24622. The older associated types code
|
|
// was erroneously assuming that all projections outlived the current
|
|
// fn body, causing this (invalid) code to be accepted.
|
|
|
|
pub trait Foo<'a> {
|
|
type Bar: Clone;
|
|
}
|
|
|
|
impl<'a, T: 'a> Foo<'a> for T {
|
|
type Bar = &'a T;
|
|
}
|
|
|
|
fn denormalise<'a, T>(t: &'a T) -> <T as Foo<'a>>::Bar {
|
|
t
|
|
}
|
|
|
|
pub fn free_and_use<T: for<'a> Foo<'a>,
|
|
F: for<'a> FnOnce(<T as Foo<'a>>::Bar)>(x: T, f: F) {
|
|
let y;
|
|
'body: loop { // lifetime annotations added for clarity
|
|
's: loop { y = denormalise(&x); break }
|
|
drop(x); //~ ERROR cannot move out of `x` because it is borrowed
|
|
return f(y);
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
}
|