-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #116081 - compiler-errors:closure-captures-sized, r=cjg…
…illot Check that closure/generator's interior/capture types are sized check that closure upvars and generator interiors are sized. this check is only necessary when `unsized_fn_params` or `unsized_locals` is enabled, so only check if those are active. Fixes #93622 Fixes #61335 Fixes #68543
- Loading branch information
Showing
17 changed files
with
296 additions
and
4 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
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
21 changes: 21 additions & 0 deletions
21
tests/ui/async-await/awaiting-unsized-param.drop_tracking_mir.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,21 @@ | ||
warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/awaiting-unsized-param.rs:5:31 | ||
| | ||
LL | #![feature(unsized_fn_params, unsized_locals)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: the size for values of type `(dyn Future<Output = T> + Unpin + 'static)` cannot be known at compilation time | ||
--> $DIR/awaiting-unsized-param.rs:10:17 | ||
| | ||
LL | async fn bug<T>(mut f: dyn Future<Output = T> + Unpin) -> T { | ||
| ^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `(dyn Future<Output = T> + Unpin + 'static)` | ||
= note: all values captured by value by a closure must have a statically known size | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
21 changes: 21 additions & 0 deletions
21
tests/ui/async-await/awaiting-unsized-param.no_drop_tracking.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,21 @@ | ||
warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/awaiting-unsized-param.rs:5:31 | ||
| | ||
LL | #![feature(unsized_fn_params, unsized_locals)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: the size for values of type `(dyn Future<Output = T> + Unpin + 'static)` cannot be known at compilation time | ||
--> $DIR/awaiting-unsized-param.rs:10:17 | ||
| | ||
LL | async fn bug<T>(mut f: dyn Future<Output = T> + Unpin) -> T { | ||
| ^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `(dyn Future<Output = T> + Unpin + 'static)` | ||
= note: all values captured by value by a closure must have a statically known size | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,15 @@ | ||
// edition: 2021 | ||
// revisions: no_drop_tracking drop_tracking_mir | ||
// [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir | ||
|
||
#![feature(unsized_fn_params, unsized_locals)] | ||
//~^ WARN the feature `unsized_locals` is incomplete | ||
|
||
use std::future::Future; | ||
|
||
async fn bug<T>(mut f: dyn Future<Output = T> + Unpin) -> T { | ||
//~^ ERROR the size for values of type `(dyn Future<Output = T> + Unpin + 'static)` cannot be known at compilation time | ||
(&mut f).await | ||
} | ||
|
||
fn main() {} |
21 changes: 21 additions & 0 deletions
21
tests/ui/async-await/unsized-across-await.drop_tracking_mir.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,21 @@ | ||
warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/unsized-across-await.rs:5:12 | ||
| | ||
LL | #![feature(unsized_locals)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: the size for values of type `dyn std::fmt::Display` cannot be known at compilation time | ||
--> $DIR/unsized-across-await.rs:11:9 | ||
| | ||
LL | let _x = *x; | ||
| ^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `dyn std::fmt::Display` | ||
= note: all values live across `await` must have a statically known size | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
21 changes: 21 additions & 0 deletions
21
tests/ui/async-await/unsized-across-await.no_drop_tracking.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,21 @@ | ||
warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/unsized-across-await.rs:5:12 | ||
| | ||
LL | #![feature(unsized_locals)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: the size for values of type `dyn std::fmt::Display` cannot be known at compilation time | ||
--> $DIR/unsized-across-await.rs:11:9 | ||
| | ||
LL | let _x = *x; | ||
| ^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `dyn std::fmt::Display` | ||
= note: all values live across `await` must have a statically known size | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,18 @@ | ||
// edition: 2021 | ||
// revisions: no_drop_tracking drop_tracking_mir | ||
// [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir | ||
|
||
#![feature(unsized_locals)] | ||
//~^ WARN the feature `unsized_locals` is incomplete | ||
|
||
async fn f() {} | ||
|
||
async fn g(x: Box<dyn std::fmt::Display>) { | ||
let _x = *x; | ||
//~^ ERROR the size for values of type `dyn std::fmt::Display` cannot be known at compilation time | ||
f().await; | ||
} | ||
|
||
fn main() { | ||
let _a = g(Box::new(5)); | ||
} |
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,10 @@ | ||
// compile-flags: --crate-type=lib | ||
|
||
#![feature(unsized_fn_params)] | ||
|
||
pub fn f(k: dyn std::fmt::Display) { | ||
let k2 = move || { | ||
k.to_string(); | ||
//~^ ERROR the size for values of type `(dyn std::fmt::Display + 'static)` cannot be known at compilation time | ||
}; | ||
} |
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,14 @@ | ||
error[E0277]: the size for values of type `(dyn std::fmt::Display + 'static)` cannot be known at compilation time | ||
--> $DIR/capture-unsized-by-move.rs:7:9 | ||
| | ||
LL | let k2 = move || { | ||
| -- this closure captures all values by move | ||
LL | k.to_string(); | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `(dyn std::fmt::Display + 'static)` | ||
= note: all values captured by value by a closure must have a statically known size | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,10 @@ | ||
// build-pass | ||
// compile-flags: --crate-type=lib | ||
|
||
#![feature(unsized_fn_params)] | ||
|
||
pub fn f(k: dyn std::fmt::Display) { | ||
let k2 = || { | ||
k.to_string(); | ||
}; | ||
} |
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,34 @@ | ||
#![feature(generator_trait)] | ||
#![feature(generators)] | ||
#![feature(unsized_locals)] | ||
//~^ WARN the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
|
||
use std::ops::Generator; | ||
|
||
fn across() -> impl Generator { | ||
move || { | ||
let b: [u8] = *(Box::new([]) as Box<[u8]>); | ||
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time | ||
|
||
yield; | ||
|
||
for elem in b.iter() {} | ||
} | ||
} | ||
|
||
fn capture() -> impl Generator { | ||
let b: [u8] = *(Box::new([]) as Box<[u8]>); | ||
move || { | ||
println!("{:?}", &b); | ||
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time | ||
|
||
yield; | ||
|
||
for elem in b.iter() {} | ||
} | ||
} | ||
|
||
fn main() { | ||
across(); | ||
capture(); | ||
} |
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,32 @@ | ||
warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/unsized-across-yield.rs:3:12 | ||
| | ||
LL | #![feature(unsized_locals)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
--> $DIR/unsized-across-yield.rs:10:13 | ||
| | ||
LL | let b: [u8] = *(Box::new([]) as Box<[u8]>); | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `[u8]` | ||
= note: all values live across `yield` must have a statically known size | ||
|
||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
--> $DIR/unsized-across-yield.rs:22:27 | ||
| | ||
LL | move || { | ||
| -- this closure captures all values by move | ||
LL | println!("{:?}", &b); | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `[u8]` | ||
= note: all values captured by value by a closure must have a statically known size | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |