Skip to content

Commit

Permalink
use a minimized example
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki committed Aug 24, 2022
1 parent 3855e03 commit c57ecfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
29 changes: 6 additions & 23 deletions src/test/ui/regions/do-not-suggest-adding-bound-to-opaque-type.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
#![feature(allocator_api)]
pub trait T {}

use std::{
alloc::{AllocError, Allocator, Layout},
ptr::NonNull,
};
struct S<'a>(&'a ());

struct GhostBump;
impl<'a> T for S<'a> {}

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 foo() -> impl T {
let x = ();
S(&x) //~ ERROR `x` does not live long enough
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0597]: `arena` does not live long enough
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:22:31
error[E0597]: `x` does not live long enough
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:9:7
|
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 | S(&x)
| --^^-
| | |
| | borrowed value does not live long enough
| opaque type requires that `x` is borrowed for `'static`
LL | }
| - `arena` dropped here while still borrowed
| - `x` dropped here while still borrowed

error: aborting due to previous error

Expand Down

0 comments on commit c57ecfa

Please sign in to comment.