Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest using
move
when trying to share `...::channel::{Receiver, S…
…ender}` Extend `rustc_on_unimplemented` to match on ADT without evaluating type arguments.
- Loading branch information
Showing
4 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::thread; | ||
use std::sync::mpsc::channel; | ||
|
||
fn bar() { | ||
let (send, recv) = channel(); | ||
let t = thread::spawn(|| { | ||
recv.recv().unwrap(); | ||
//~^^ ERROR `std::sync::mpsc::Receiver<()>` cannot be shared between threads safely | ||
}); | ||
|
||
send.send(()); | ||
|
||
t.join().unwrap(); | ||
} | ||
|
||
fn foo() { | ||
let (tx, _rx) = channel(); | ||
thread::spawn(|| tx.send(()).unwrap()); | ||
//~^ ERROR `std::sync::mpsc::Sender<()>` cannot be shared between threads safely | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0277]: `std::sync::mpsc::Receiver<()>` cannot be shared between threads safely | ||
--> $DIR/closure-move-sync.rs:16:13 | ||
| | ||
16 | let t = thread::spawn(|| { | ||
| ^^^^^^^^^^^^^ `std::sync::mpsc::Receiver<()>` cannot be shared safely, if using a closure consider marking it `move` | ||
| | ||
= help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Receiver<()>` | ||
= note: required because of the requirements on the impl of `std::marker::Send` for `&std::sync::mpsc::Receiver<()>` | ||
= note: required because it appears within the type `[closure@$DIR/closure-move-sync.rs:16:27: 19:6 recv:&std::sync::mpsc::Receiver<()>]` | ||
= note: required by `std::thread::spawn` | ||
|
||
error[E0277]: `std::sync::mpsc::Sender<()>` cannot be shared between threads safely | ||
--> $DIR/closure-move-sync.rs:28:5 | ||
| | ||
28 | thread::spawn(|| tx.send(()).unwrap()); | ||
| ^^^^^^^^^^^^^ `std::sync::mpsc::Sender<()>` cannot be shared safely, if using a closure consider marking it `move` | ||
| | ||
= help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender<()>` | ||
= note: required because of the requirements on the impl of `std::marker::Send` for `&std::sync::mpsc::Sender<()>` | ||
= note: required because it appears within the type `[closure@$DIR/closure-move-sync.rs:28:19: 28:42 tx:&std::sync::mpsc::Sender<()>]` | ||
= note: required by `std::thread::spawn` | ||
|
||
error: aborting due to 2 previous errors | ||
|