Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill moved locals in borrowed locals analysis #110420

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ where
}
}

mir::Rvalue::Use(mir::Operand::Move(place)) => {
if place.projection.len() == 0 {
self.trans.kill(place.local)
}
}

mir::Rvalue::Cast(..)
| mir::Rvalue::ShallowInitBox(..)
| mir::Rvalue::Use(..)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ impl GeneratorSavedLocals {
out.insert(saved_local);
}
}

out
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ 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:23:38
note: captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send`
--> $DIR/drop-track-field-assign-nonsend.rs:19:21
|
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 | async fn handle(&mut self) {
| ^^^^^^^^^ has type `&mut Agent` which is not `Send`, because `Agent` is not `Send`
note: required by a bound in `assert_send`
--> $DIR/drop-track-field-assign-nonsend.rs:40:19
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ 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/field-assign-nonsend.rs:23:38
note: captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send`
--> $DIR/field-assign-nonsend.rs:19:21
|
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 | async fn handle(&mut self) {
| ^^^^^^^^^ has type `&mut Agent` which is not `Send`, because `Agent` is not `Send`
note: required by a bound in `assert_send`
--> $DIR/field-assign-nonsend.rs:40:19
|
Expand Down
33 changes: 33 additions & 0 deletions tests/ui/async-await/issue-96084.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// run-pass
// edition:2018

use std::mem;

async fn foo() {
let x = [0u8; 100];
async {}.await;
println!("{}", x.len());
}

async fn a() {
let fut = foo();
let fut = fut;
fut.await;
}

async fn b() {
let fut = foo();
println!("{}", mem::size_of_val(&fut));
let fut = fut;
fut.await;
}

fn main() {
assert_eq!(mem::size_of_val(&foo()), 102);

// 1 + sizeof(foo)
assert_eq!(mem::size_of_val(&a()), 103);

// 1 + (sizeof(foo) * 2)
assert_eq!(mem::size_of_val(&b()), 103);
}
2 changes: 1 addition & 1 deletion tests/ui/generator/size-moved-locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ fn overlap_x_and_y() -> impl Generator<Yield = (), Return = ()> {
fn main() {
assert_eq!(1025, std::mem::size_of_val(&move_before_yield()));
assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop()));
assert_eq!(2051, std::mem::size_of_val(&overlap_move_points()));
assert_eq!(1027, std::mem::size_of_val(&overlap_move_points()));
assert_eq!(1026, std::mem::size_of_val(&overlap_x_and_y()));
}