-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
It would make a lot more sense if when a type impl !Sync
the compiler could report an other error than the error that comes from this impl block.
For example, take a look at this code :
use std::sync::mpsc::channel;
use std::thread;
struct Foo {}
impl Foo {
fn do_something(&self) {
println!("hello");
}
}
fn main() {
let (tx, rx) = channel::<Foo>();
thread::spawn(move || rx.iter().map(|f| f.do_something()));
}
Which outputs :
17 | thread::spawn(move || rx.iter().map(|f| f.do_something()));
| ^^^^^^^^^^^^^ `std::sync::mpsc::Receiver<Foo>` cannot be shared between threads safely
|
= help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Receiver<Foo>`
= note: required because of the requirements on the impl of `std::marker::Send` for `&std::sync::mpsc::Receiver<Foo>`
= note: required because it appears within the type `std::sync::mpsc::Iter<'_, Foo>`
= note: required because it appears within the type `std::iter::Map<std::sync::mpsc::Iter<'_, Foo>, [closure@src/main.rs:17:41: 17:61]>`
= note: required by `std::thread::spawn`
It would be way better if it could just say that Receiver
is explicitly not Sync
.
I know that this a bad example because the error is actually due to the fact that the compiler does not move rx
because we are returning a value from the call to map()
, but it was the only one that I had...
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.