-
Notifications
You must be signed in to change notification settings - Fork 35
Fix unsoundness issues #106 and #107 #109
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40a8deb
Fix unsoundness issues #106 and #107
aumetra 22a7375
Merge branch 'tokio-rs:master' into fix-unsoundness
aumetra 64e8585
Add UI tests for unsoundness bugs
aumetra 95afc7a
Increase MSRV
aumetra b807ad6
rustfmt UI tests
aumetra 742540d
Rename break label
aumetra a280ba5
Allow clippy lint for newer versions
aumetra 891daed
Use inline const
aumetra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,31 @@ | ||
use async_stream::stream; | ||
use futures_util::StreamExt; | ||
|
||
use std::pin::pin; | ||
|
||
macro_rules! asynk { | ||
($e:expr) => { | ||
async { $e } | ||
}; | ||
} | ||
|
||
#[tokio::main] | ||
|
||
aumetra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async fn main() { | ||
pin!(stream! { | ||
let yield_42 = asynk!(yield 42_usize); | ||
let s = stream! { | ||
yield Box::new(12345); | ||
yield_42.await; // yield 42 -- wait that's not a Box!? | ||
}; | ||
for await (n, i) in s.enumerate() { | ||
println!("Item at index {n}:\n {i}"); | ||
// Item at index 0: | ||
// 12345 | ||
// Item at index 1: | ||
// Segmentation fault | ||
} | ||
}) | ||
.next() | ||
.await; | ||
} |
This file contains hidden or 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,36 @@ | ||
error[E0767]: use of unreachable label `'check_stream_scope` | ||
--> tests/ui/unsoundness_issue_106.rs:15:10 | ||
| | ||
15 | pin!(stream! { | ||
| __________^ | ||
16 | | let yield_42 = asynk!(yield 42_usize); | ||
17 | | let s = stream! { | ||
18 | | yield Box::new(12345); | ||
... | | ||
27 | | } | ||
28 | | }) | ||
| | ^ | ||
| | | | ||
| |_____unreachable label `'check_stream_scope` | ||
| unreachable label defined here | ||
| | ||
= note: labels are unreachable through functions, closures, async blocks and modules | ||
= note: this error originates in the macro `$crate::__private::stream_inner` which comes from the expansion of the macro `stream` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0267]: `break` inside `async` block | ||
--> tests/ui/unsoundness_issue_106.rs:15:10 | ||
| | ||
8 | async { $e } | ||
| ----- enclosing `async` block | ||
... | ||
15 | pin!(stream! { | ||
| __________^ | ||
16 | | let yield_42 = asynk!(yield 42_usize); | ||
17 | | let s = stream! { | ||
18 | | yield Box::new(12345); | ||
... | | ||
27 | | } | ||
28 | | }) | ||
| |_____^ cannot `break` inside `async` block | ||
| | ||
= note: this error originates in the macro `$crate::__private::stream_inner` which comes from the expansion of the macro `stream` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains hidden or 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,23 @@ | ||
use async_stream::stream; | ||
use futures_util::StreamExt; | ||
|
||
use std::pin::pin; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut outer = vec![]; | ||
{ | ||
let v = vec![0; 10]; | ||
let v_ref = &v; | ||
let mut s = pin!(stream! { | ||
for x in v_ref { | ||
yield x | ||
} | ||
}); | ||
while let Some(x) = s.next().await { | ||
outer.push(x); | ||
} | ||
}; | ||
// use-after-free | ||
println!("{outer:?}"); // […garbage allocator internals…, 0, 0, 0] | ||
} |
This file contains hidden or 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,13 @@ | ||
error[E0597]: `v` does not live long enough | ||
--> tests/ui/unsoundness_issue_107.rs:11:21 | ||
| | ||
10 | let v = vec![0; 10]; | ||
| - binding `v` declared here | ||
11 | let v_ref = &v; | ||
| ^^ borrowed value does not live long enough | ||
... | ||
20 | }; | ||
| - `v` dropped here while still borrowed | ||
21 | // use-after-free | ||
22 | println!("{outer:?}"); // […garbage allocator internals…, 0, 0, 0] | ||
| --------- borrow later used here |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.