Skip to content

Deny-by-default is too strong for arc_with_non_send_sync #11079

Closed
@Aaron1011

Description

@Aaron1011

Summary

The recently added arc_with_non_send_sync is deny-by-default. The description claims that "Wrapping a type in Arc doesn’t add thread safety to the underlying data, so data races could occur when touching the underlying data.". However, this is only true in the presence of unsafe code - when this lint fires, the Arc itself will be !Send/!Sync, preventing it from being shared between threads by safe code (and sound unsafe code).

This lint fired several times in my project - while it's a legitimate lint, I think warn-by-default would be a more reasonable setting.

Reproducer

I tried this code:

use std::cell::Cell;
use std::sync::Arc;

fn main() {
    let _a = Arc::new(Cell::new(0));
}

I expected to see this happen:

A warn-by-default lint.

Instead, this happened:

error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
 --> src/main.rs:5:14
  |
5 |     let _a = Arc::new(Cell::new(0));
  |              ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
  = note: `#[deny(clippy::arc_with_non_send_sync)]` on by default

Version

rustc 1.72.0-nightly (839e9a6e1 2023-07-02)
binary: rustc
commit-hash: 839e9a6e1210934fd24b15548b811a97c77138fc
commit-date: 2023-07-02
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions