Skip to content

Commit 9713677

Browse files
committed
Test foreign CoerceShared private tuple field
1 parent 7eee68f commit 9713677

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
#![feature(reborrow)]
21
#![allow(dead_code)]
32

3+
use std::marker::PhantomData;
4+
45
#[derive(Clone, Copy)]
56
pub struct ForeignRef<'a> {
67
value: &'a i32,
78
}
9+
10+
// SAFETY invariant: the pointer is valid as `&'a i32`.
11+
#[derive(Clone, Copy)]
12+
pub struct ForeignPtrRef<'a>((*const i32, PhantomData<&'a ()>));
13+
14+
impl<'a> ForeignPtrRef<'a> {
15+
pub fn new(r: &'a i32) -> Self {
16+
ForeignPtrRef((r, PhantomData))
17+
}
18+
19+
pub fn to_ref(self) -> &'a i32 {
20+
unsafe { &*self.0.0 }
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ normalize-stderr: "\n\n\z" -> "\n"
2+
3+
//@ aux-build: reborrow_foreign_private.rs
4+
5+
#![feature(reborrow)]
6+
7+
extern crate reborrow_foreign_private;
8+
9+
use reborrow_foreign_private::ForeignPtrRef;
10+
use std::marker::{CoerceShared, PhantomData, Reborrow};
11+
use std::ptr;
12+
13+
struct LocalPtrMut<'a>((*const i32, PhantomData<&'a ()>));
14+
15+
impl<'a> Reborrow for LocalPtrMut<'a> {}
16+
17+
impl<'a> CoerceShared<ForeignPtrRef<'a>> for LocalPtrMut<'a> {}
18+
//~^ ERROR
19+
20+
fn main() {
21+
let local = LocalPtrMut((ptr::null(), PhantomData));
22+
let foreign: ForeignPtrRef<'_> = local;
23+
let _ = foreign.to_ref();
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: implementing `CoerceShared` requires all source and target fields to be accessible from the impl
2+
--> $DIR/coerce-shared-foreign-private-tuple-field.rs:17:1
3+
|
4+
LL | impl<'a> CoerceShared<ForeignPtrRef<'a>> for LocalPtrMut<'a> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)