Skip to content

Commit 9309f7a

Browse files
committed
no_share-struct.rs
1 parent 1986ba3 commit 9309f7a

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
//! Test negative Sync implementation on structs.
2+
//!
3+
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync.
4+
15
#![feature(negative_impls)]
26

37
use std::marker::Sync;
48

5-
struct Foo { a: isize }
6-
impl !Sync for Foo {}
9+
struct NotSyncStruct {
10+
value: isize,
11+
}
12+
13+
impl !Sync for NotSyncStruct {}
714

8-
fn bar<T: Sync>(_: T) {}
15+
fn requires_sync<T: Sync>(_: T) {}
916

1017
fn main() {
11-
let x = Foo { a: 5 };
12-
bar(x);
13-
//~^ ERROR `Foo` cannot be shared between threads safely [E0277]
18+
let not_sync = NotSyncStruct { value: 5 };
19+
requires_sync(not_sync);
20+
//~^ ERROR `NotSyncStruct` cannot be shared between threads safely [E0277]
1421
}

tests/ui/traits/struct-negative-sync-impl.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error[E0277]: `Foo` cannot be shared between threads safely
2-
--> $DIR/no_share-struct.rs:12:9
1+
error[E0277]: `NotSyncStruct` cannot be shared between threads safely
2+
--> $DIR/struct-negative-sync-impl.rs:19:19
33
|
4-
LL | bar(x);
5-
| --- ^ `Foo` cannot be shared between threads safely
4+
LL | requires_sync(not_sync);
5+
| ------------- ^^^^^^^^ `NotSyncStruct` cannot be shared between threads safely
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Sync` is not implemented for `Foo`
10-
note: required by a bound in `bar`
11-
--> $DIR/no_share-struct.rs:8:11
9+
= help: the trait `Sync` is not implemented for `NotSyncStruct`
10+
note: required by a bound in `requires_sync`
11+
--> $DIR/struct-negative-sync-impl.rs:15:21
1212
|
13-
LL | fn bar<T: Sync>(_: T) {}
14-
| ^^^^ required by this bound in `bar`
13+
LL | fn requires_sync<T: Sync>(_: T) {}
14+
| ^^^^ required by this bound in `requires_sync`
1515

1616
error: aborting due to 1 previous error
1717

0 commit comments

Comments
 (0)