-
-
Notifications
You must be signed in to change notification settings - Fork 17.3k
give noalias back to refs in closures #162361
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
+104
−19
Merged
Changes from all commits
Commits
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
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
18 changes: 18 additions & 0 deletions
18
src/tools/miri/tests/fail/both_borrows/closure-captured-ref.rs
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,18 @@ | ||
| //@revisions: stack tree | ||
| //@[tree]compile-flags: -Zmiri-tree-borrows | ||
|
|
||
| //@[stack]error-in-other-file: protected | ||
| //@[tree]error-in-other-file: forbidden | ||
|
|
||
| // A reference in a closure is treated like a reference in a struct. | ||
| fn main() { | ||
| fn invoke(f: impl FnOnce()) { | ||
| // The closure has captured a reference that will be freed while `invoke` runs. | ||
| f() | ||
| } | ||
|
|
||
| let p = Box::leak(Box::new(0i32)); | ||
| invoke(move || { | ||
| drop(unsafe { Box::from_raw(p) }); | ||
| }); | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/tools/miri/tests/fail/both_borrows/closure-captured-ref.stack.stderr
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,26 @@ | ||
| error: Undefined Behavior: deallocating while item [Unique for <TAG>] is strongly protected | ||
| --> RUSTLIB/alloc/src/boxed.rs:LL:CC | ||
| | | ||
| LL | self.1.deallocate(From::from(ptr.cast()), layout); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here | ||
| | | ||
| = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental | ||
| = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information | ||
| = note: stack backtrace: | ||
| 0: <std::boxed::Box<i32> as std::ops::Drop>::drop | ||
| at RUSTLIB/alloc/src/boxed.rs:LL:CC | ||
| 1: std::ptr::drop_glue::<std::boxed::Box<i32>> - shim(Some(std::boxed::Box<i32>)) | ||
| at RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
| 2: std::mem::drop::<std::boxed::Box<i32>> | ||
| at RUSTLIB/core/src/mem/mod.rs:LL:CC | ||
| 3: main::{closure#0} | ||
| at tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
| 4: main::invoke::<{closure@tests/fail/both_borrows/closure-captured-ref.rs:LL:CC}> | ||
| at tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
| 5: main | ||
| at tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
|
|
||
| note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
41 changes: 41 additions & 0 deletions
41
src/tools/miri/tests/fail/both_borrows/closure-captured-ref.tree.stderr
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,41 @@ | ||
| error: Undefined Behavior: deallocation through <TAG> at ALLOC[0x0] is forbidden | ||
| --> RUSTLIB/alloc/src/boxed.rs:LL:CC | ||
| | | ||
| LL | self.1.deallocate(From::from(ptr.cast()), layout); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here | ||
| | | ||
| = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental | ||
| = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/tree-borrows.md for further information | ||
| = help: the allocation of the accessed tag <TAG> also contains the strongly protected tag <TAG> | ||
| = help: the strongly protected tag <TAG> disallows deallocations | ||
| help: the accessed tag <TAG> was created here | ||
| --> tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
| | | ||
| LL | drop(unsafe { Box::from_raw(p) }); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| help: the strongly protected tag <TAG> was created here, in the initial state Reserved | ||
| --> tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
| | | ||
| LL | invoke(move || { | ||
| | ____________^ | ||
| LL | | drop(unsafe { Box::from_raw(p) }); | ||
| LL | | }); | ||
| | |_____^ | ||
| = note: stack backtrace: | ||
| 0: <std::boxed::Box<i32> as std::ops::Drop>::drop | ||
| at RUSTLIB/alloc/src/boxed.rs:LL:CC | ||
| 1: std::ptr::drop_glue::<std::boxed::Box<i32>> - shim(Some(std::boxed::Box<i32>)) | ||
| at RUSTLIB/core/src/ptr/mod.rs:LL:CC | ||
| 2: std::mem::drop::<std::boxed::Box<i32>> | ||
| at RUSTLIB/core/src/mem/mod.rs:LL:CC | ||
| 3: main::{closure#0} | ||
| at tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
| 4: main::invoke::<{closure@tests/fail/both_borrows/closure-captured-ref.rs:LL:CC}> | ||
| at tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
| 5: main | ||
| at tests/fail/both_borrows/closure-captured-ref.rs:LL:CC | ||
|
|
||
| note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what a CoroutineClosure is / why it is a separate type. But I'll assume it contains a corotuine so we should have MaybeDangling there.
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RalfJung CoroutineClosure is the type of
async || expr. It's not a coroutine, and doesn't contain a coroutine. It's a closure that returns a coroutine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Then I guess it should be treated like closures here.