File tree Expand file tree Collapse file tree 2 files changed +22
-15
lines changed Expand file tree Collapse file tree 2 files changed +22
-15
lines changed Original file line number Diff line number Diff line change
1
+ //! Test negative Sync implementation on structs.
2
+ //!
3
+ //! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync.
4
+
1
5
#![ feature( negative_impls) ]
2
6
3
7
use std:: marker:: Sync ;
4
8
5
- struct Foo { a : isize }
6
- impl !Sync for Foo { }
9
+ struct NotSyncStruct {
10
+ value : isize ,
11
+ }
12
+
13
+ impl !Sync for NotSyncStruct { }
7
14
8
- fn bar < T : Sync > ( _: T ) { }
15
+ fn requires_sync < T : Sync > ( _: T ) { }
9
16
10
17
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]
14
21
}
Original file line number Diff line number Diff line change 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
3
3
|
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
6
6
| |
7
7
| required by a bound introduced by this call
8
8
|
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
12
12
|
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 `
15
15
16
16
error: aborting due to 1 previous error
17
17
You can’t perform that action at this time.
0 commit comments