Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clippy_lints/src/arc_with_non_send_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_lint::LateLintPass;
use rustc_middle::ty;
use rustc_middle::ty::GenericArgKind;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::sym;

Expand Down Expand Up @@ -47,7 +48,10 @@ impl LateLintPass<'_> for ArcWithNonSendSync {
if let ExprKind::Path(func_path) = func.kind;
if last_path_segment(&func_path).ident.name == sym::new;
if let arg_ty = cx.typeck_results().expr_ty(arg);
if !matches!(arg_ty.kind(), ty::Param(_));
// make sure that the type is not and does not contain any type parameters
if arg_ty.walk().all(|arg| {
!matches!(arg.unpack(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_)))
});
if !cx.tcx
.lang_items()
.sync_trait()
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/arc_with_non_send_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ fn foo<T>(x: T) {
// Should not lint - purposefully ignoring generic args.
let a = Arc::new(x);
}
fn issue11076<T>() {
let a: Arc<Vec<T>> = Arc::new(Vec::new());
}

fn main() {
// This is safe, as `i32` implements `Send` and `Sync`.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/arc_with_non_send_sync.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
--> $DIR/arc_with_non_send_sync.rs:16:13
--> $DIR/arc_with_non_send_sync.rs:19:13
|
LL | let b = Arc::new(RefCell::new(42));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down