-
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.
Rollup merge of #122701 - compiler-errors:allocator-suspend, r=oli-obk
Detect allocator for box in `must_not_suspend` lint I don't expect this to happen in practice, but better to check than not. Fixes #122643
- Loading branch information
Showing
3 changed files
with
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@ edition: 2021 | ||
|
||
#![feature(must_not_suspend, allocator_api)] | ||
#![deny(must_not_suspend)] | ||
|
||
use std::alloc::*; | ||
use std::ptr::NonNull; | ||
|
||
#[must_not_suspend] | ||
struct MyAllocatorWhichMustNotSuspend; | ||
|
||
unsafe impl Allocator for MyAllocatorWhichMustNotSuspend { | ||
fn allocate(&self, l: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
Global.allocate(l) | ||
} | ||
unsafe fn deallocate(&self, p: NonNull<u8>, l: Layout) { | ||
Global.deallocate(p, l) | ||
} | ||
} | ||
|
||
async fn suspend() {} | ||
|
||
async fn foo() { | ||
let x = Box::new_in(1i32, MyAllocatorWhichMustNotSuspend); | ||
//~^ ERROR allocator `MyAllocatorWhichMustNotSuspend` held across a suspend point, but should not be | ||
suspend().await; | ||
drop(x); | ||
} | ||
|
||
fn main() {} |
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,22 @@ | ||
error: allocator `MyAllocatorWhichMustNotSuspend` held across a suspend point, but should not be | ||
--> $DIR/allocator.rs:24:9 | ||
| | ||
LL | let x = Box::new_in(1i32, MyAllocatorWhichMustNotSuspend); | ||
| ^ | ||
LL | | ||
LL | suspend().await; | ||
| ----- the value is held across this suspend point | ||
| | ||
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point | ||
--> $DIR/allocator.rs:24:9 | ||
| | ||
LL | let x = Box::new_in(1i32, MyAllocatorWhichMustNotSuspend); | ||
| ^ | ||
note: the lint level is defined here | ||
--> $DIR/allocator.rs:4:9 | ||
| | ||
LL | #![deny(must_not_suspend)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|