forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider mutations as borrows in drop tracking
This is needed to match MIR more conservative approximation of any borrowed value being live across a suspend point (See rust-lang#94067). This change considers an expression such as `x.y = z` to be a borrow of `x` and therefore keeps `x` live across suspend points.
- Loading branch information
Showing
4 changed files
with
123 additions
and
3 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
45 changes: 45 additions & 0 deletions
45
src/test/ui/async-await/drop-track-field-assign-nonsend.rs
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,45 @@ | ||
// Derived from an ICE found in tokio-xmpp during a crater run. | ||
// edition:2021 | ||
// compile-flags: -Zdrop-tracking | ||
|
||
#![allow(dead_code)] | ||
|
||
#[derive(Clone)] | ||
struct InfoResult { | ||
node: Option<std::rc::Rc<String>> | ||
} | ||
|
||
struct Agent { | ||
info_result: InfoResult | ||
} | ||
|
||
impl Agent { | ||
async fn handle(&mut self) { | ||
let mut info = self.info_result.clone(); | ||
info.node = None; | ||
let element = parse_info(info); | ||
let _ = send_element(element).await; | ||
} | ||
} | ||
|
||
struct Element { | ||
} | ||
|
||
async fn send_element(_: Element) {} | ||
|
||
fn parse(_: &[u8]) -> Result<(), ()> { | ||
Ok(()) | ||
} | ||
|
||
fn parse_info(_: InfoResult) -> Element { | ||
Element { } | ||
} | ||
|
||
fn assert_send<T: Send>(_: T) {} | ||
|
||
fn main() { | ||
let agent = Agent { info_result: InfoResult { node: None } }; | ||
// FIXME: It would be nice for this to work. See #94067. | ||
assert_send(agent.handle()); | ||
//~^ cannot be sent between threads safely | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/ui/async-await/drop-track-field-assign-nonsend.stderr
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 @@ | ||
error: future cannot be sent between threads safely | ||
--> $DIR/drop-track-field-assign-nonsend.rs:43:17 | ||
| | ||
LL | assert_send(agent.handle()); | ||
| ^^^^^^^^^^^^^^ future returned by `handle` is not `Send` | ||
| | ||
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `Rc<String>` | ||
note: future is not `Send` as this value is used across an await | ||
--> $DIR/drop-track-field-assign-nonsend.rs:21:38 | ||
| | ||
LL | let mut info = self.info_result.clone(); | ||
| -------- has type `InfoResult` which is not `Send` | ||
... | ||
LL | let _ = send_element(element).await; | ||
| ^^^^^^ await occurs here, with `mut info` maybe used later | ||
LL | } | ||
| - `mut info` is later dropped here | ||
note: required by a bound in `assert_send` | ||
--> $DIR/drop-track-field-assign-nonsend.rs:38:19 | ||
| | ||
LL | fn assert_send<T: Send>(_: T) {} | ||
| ^^^^ required by this bound in `assert_send` | ||
|
||
error: aborting due to previous error | ||
|
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,44 @@ | ||
// Derived from an ICE found in tokio-xmpp during a crater run. | ||
// edition:2021 | ||
// compile-flags: -Zdrop-tracking | ||
// build-pass | ||
|
||
#![allow(dead_code)] | ||
|
||
#[derive(Clone)] | ||
struct InfoResult { | ||
node: Option<String> | ||
} | ||
|
||
struct Agent { | ||
info_result: InfoResult | ||
} | ||
|
||
impl Agent { | ||
async fn handle(&mut self) { | ||
let mut info = self.info_result.clone(); | ||
info.node = Some("bar".into()); | ||
let element = parse_info(info); | ||
let _ = send_element(element).await; | ||
} | ||
} | ||
|
||
struct Element { | ||
} | ||
|
||
async fn send_element(_: Element) {} | ||
|
||
fn parse(_: &[u8]) -> Result<(), ()> { | ||
Ok(()) | ||
} | ||
|
||
fn parse_info(_: InfoResult) -> Element { | ||
Element { } | ||
} | ||
|
||
fn main() { | ||
let mut agent = Agent { | ||
info_result: InfoResult { node: None } | ||
}; | ||
let _ = agent.handle(); | ||
} |