False positive in arc_with_non_send_sync
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
Start by locating the implementation and tests for the arc_with_non_send_sync lint, then run the provided Rust reproducer to confirm the warning. Trace why the Arc construction is flagged despite the enclosing Worker being marked Send and Sync; done means the reproducer emits no lint while the lint's intended warnings remain covered.
Written by the indexing model from the issue text.
Description
Summary
This lint triggers when a non-send type is wrapped in Arc, even if this Arc is then used by the type that is Send.
The reproducer example is messy, but still, probably lint shouldn't trigger there.
Playground link for convenience.
Lint Name
arc_with_non_send_sync
Reproducer
I tried this code:
use std::{sync::Arc, marker::PhantomData, cell::Cell};
#[derive(Default)]
struct ResourceNotSend {
_not_send: PhantomData<Cell<()>>,
}
impl ResourceNotSend {
fn threadsafe_method(&self) {
println!("huh");
}
}
struct Worker {
resource: Arc<ResourceNotSend>
}
unsafe impl Send for Worker {}
unsafe impl Sync for Worker {}
impl Worker {
fn foo(&self) {
self.resource.threadsafe_method();
}
}
fn main() {
let resource = Arc::new(ResourceNotSend::default());
let worker = Worker { resource: resource.clone() };
std::thread::spawn(move || {
worker.foo();
}).join().unwrap();
}
I saw this happen:
warning: usage of an `Arc` that is not `Send` or `Sync`
--> src/main.rs:29:20
|
29 | let resource = Arc::new(ResourceNotSend::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the trait `Sync` is not implemented for `ResourceNotSend`
= note: required for `Arc<ResourceNotSend>` to implement `Send` and `Sync`
= help: consider using an `Rc` instead or wrapping the inner type with a `Mutex`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
= note: `#[warn(clippy::arc_with_non_send_sync)]` on by default
I expected to see this happen:
No lint spawned.
Version
rustc 1.73.0-nightly (08d00b40a 2023-08-09)
binary: rustc
commit-hash: 08d00b40aef2017fe6dba3ff7d6476efa0c10888
commit-date: 2023-08-09
host: aarch64-apple-darwin
release: 1.73.0-nightly
LLVM version: 17.0.0
Additional Labels
No response
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rust-clippy
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/rust-clippy#17674 · 5 comments ·
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#17673 · 3 comments ·
-
C-bug I-false-positive
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rust-lang/rust-clippy#17566 ·
-
A-documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rust-lang/rust-clippy#17259 · 3 comments ·
-
A-documentation A-website C-bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#16981 · 1 reaction ·
All issues in rust-lang/rust-clippy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100