Closed
Description
pub async fn f(x: &mut i32) -> &i32 {
let y = &*x;
*x += 1;
y
}
Output on 1.46.0-nightly (2020-07-04 0cd7ff7) (Playground)
Compiling playground v0.0.1 (/playground)
error[E0506]: cannot assign to `*x` because it is borrowed
--> src/lib.rs:3:5
|
2 | let y = &*x;
| --- borrow of `*x` occurs here
3 | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
4 | y
| - returning this value requires that `*x` is borrowed for `'1`
5 | }
| - return type of generator is &'1 i32
error: aborting due to previous error
For more information about this error, try `rustc --explain E0506`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
Without async
, a note like this is emitted, and should also be emitted with async
:
1 | pub fn f(x: &mut i32) -> &i32 {
| - let's call the lifetime of this reference `'1`
Output on stable 1.44.1 (with async) is different:
Compiling playground v0.0.1 (/playground)
error[E0506]: cannot assign to `*x` because it is borrowed
--> src/lib.rs:3:5
|
2 | let y = &*x;
| --- borrow of `*x` occurs here
3 | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0506`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done