Skip to content

Commit bc114c4

Browse files
tests from the relevant issue trackers
1 parent 876f04d commit bc114c4

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// edition:2018
2+
// run-pass
3+
4+
use std::ops::Index;
5+
6+
/// A `Send + !Sync` for demonstration purposes.
7+
struct Banana(*mut ());
8+
unsafe impl Send for Banana {}
9+
10+
impl Banana {
11+
/// Make a static mutable reference to Banana for convenience purposes.
12+
///
13+
/// Any potential unsoundness here is not super relevant to the issue at hand.
14+
fn new() -> &'static mut Banana {
15+
static mut BANANA: Banana = Banana(std::ptr::null_mut());
16+
unsafe { &mut BANANA }
17+
}
18+
}
19+
20+
// Peach is still Send (because `impl Send for &mut T where T: Send`)
21+
struct Peach<'a>(&'a mut Banana);
22+
23+
impl<'a> std::ops::Index<usize> for Peach<'a> {
24+
type Output = ();
25+
fn index(&self, _: usize) -> &() {
26+
&()
27+
}
28+
}
29+
30+
async fn baz(_: &()) {}
31+
32+
async fn bar() {
33+
let peach = Peach(Banana::new());
34+
let r = &*peach.index(0);
35+
baz(r).await;
36+
peach.index(0); // make sure peach is retained across yield point
37+
}
38+
39+
async fn bat() {
40+
let peach = Peach(Banana::new());
41+
let r = &peach[0];
42+
baz(r).await;
43+
peach[0]; // make sure peach is retained across yield point
44+
}
45+
46+
fn assert_send<T: Send>(_: T) {}
47+
48+
pub fn main() {
49+
assert_send(bar());
50+
assert_send(bat());
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// edition:2018
2+
// run-pass
3+
#![feature(generators, generator_trait, negative_impls)]
4+
5+
fn assert_send<T: Send>(_: T) {}
6+
7+
struct Client;
8+
9+
impl Client {
10+
fn status(&self) -> i16 {
11+
200
12+
}
13+
}
14+
15+
impl !Sync for Client {}
16+
17+
fn status(_: &Client) -> i16 {
18+
200
19+
}
20+
21+
fn main() {
22+
let g = || {
23+
let x = Client;
24+
match status(&x) {
25+
_ => yield,
26+
}
27+
match (&*&x).status() {
28+
_ => yield,
29+
}
30+
};
31+
assert_send(g);
32+
}

0 commit comments

Comments
 (0)