rust-lang / rust-lang/rust-clippy
arc_with_non_send_sync warns on the caller of a function instead of the function itself
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
This happens when we have a function that expects Arc<NonSendSync>. It generates a warning on the calls to the function (more specifically when the Arcs are constructed), but the user cannot fix this warning if this function is provided by a library because they need the library to fix their function first.
Lint Name
arc_with_non_send_sync
Reproducer
I tried this code:
use std::sync::Arc;
fn library_func(_param: Arc<*const ()>) {
todo!();
}
fn main() {
library_func(Arc::new(&() as *const ()));
}
I saw this happen:
warning: usage of an `Arc` that is not `Send` and `Sync`
--> src/main.rs:8:18
|
8 | library_func(Arc::new(&() as *const ()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `Arc<*const ()>` is not `Send` and `Sync` as `*const ()` is neither `Send` nor `Sync`
= help: if the `Arc` will not used be across threads replace it with an `Rc`
= help: otherwise make `*const ()` `Send` and `Sync` or consider a wrapper type such as `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:
warning: usage of an `Arc` that is not `Send` and `Sync`
--> src/main.rs:3:17
|
3 | fn library_func(_param: Arc<*const ()>)
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `Arc<*const ()>` is not `Send` and `Sync` as `*const ()` is neither `Send` nor `Sync`
= help: if the `Arc` will not used be across threads replace it with an `Rc`
= help: otherwise make `*const ()` `Send` and `Sync` or consider a wrapper type such as `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
Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2
Additional Labels
No response
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.
Research direction
Start by locating the implementation and tests for the arc_with_non_send_sync lint, then run the supplied reproducer with the library function and its Arc<*const ()> parameter. The change is done when the warning points to the function parameter rather than the caller's Arc::new expression, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100