-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not suggest adding a bound to a opaque type
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
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
29 changes: 29 additions & 0 deletions
29
src/test/ui/regions/do-not-suggest-adding-bound-to-opaque-type.rs
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,29 @@ | ||
#![feature(allocator_api)] | ||
|
||
use std::{ | ||
alloc::{AllocError, Allocator, Layout}, | ||
ptr::NonNull, | ||
}; | ||
|
||
struct GhostBump; | ||
|
||
unsafe impl Allocator for &GhostBump { | ||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
todo!() | ||
} | ||
|
||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | ||
todo!() | ||
} | ||
} | ||
|
||
fn foo() -> impl Iterator<Item = usize> { | ||
let arena = GhostBump; | ||
let mut vec = Vec::new_in(&arena); //~ ERROR `arena` does not live long enough | ||
vec.push(1); | ||
vec.push(2); | ||
vec.push(3); | ||
vec.into_iter() | ||
} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/regions/do-not-suggest-adding-bound-to-opaque-type.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,14 @@ | ||
error[E0597]: `arena` does not live long enough | ||
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:22:31 | ||
| | ||
LL | let mut vec = Vec::new_in(&arena); | ||
| ^^^^^^ borrowed value does not live long enough | ||
... | ||
LL | vec.into_iter() | ||
| --------------- opaque type requires that `arena` is borrowed for `'static` | ||
LL | } | ||
| - `arena` dropped here while still borrowed | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |