Skip to content

Commit 2b03bb0

Browse files
committed
Auto merge of #11077 - y21:issue11076, r=Manishearth
[`arc_with_non_send_sync`]: don't lint if type has nested type parameters Fixes #11076 changelog: [`arc_with_non_send_sync`]: don't lint if type has nested type parameters r? `@Manishearth`
2 parents c46ddeb + 75c339c commit 2b03bb0

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

clippy_lints/src/arc_with_non_send_sync.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::{Expr, ExprKind};
77
use rustc_lint::LateContext;
88
use rustc_lint::LateLintPass;
99
use rustc_middle::ty;
10+
use rustc_middle::ty::GenericArgKind;
1011
use rustc_session::{declare_lint_pass, declare_tool_lint};
1112
use rustc_span::symbol::sym;
1213

@@ -47,7 +48,10 @@ impl LateLintPass<'_> for ArcWithNonSendSync {
4748
if let ExprKind::Path(func_path) = func.kind;
4849
if last_path_segment(&func_path).ident.name == sym::new;
4950
if let arg_ty = cx.typeck_results().expr_ty(arg);
50-
if !matches!(arg_ty.kind(), ty::Param(_));
51+
// make sure that the type is not and does not contain any type parameters
52+
if arg_ty.walk().all(|arg| {
53+
!matches!(arg.unpack(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_)))
54+
});
5155
if !cx.tcx
5256
.lang_items()
5357
.sync_trait()

tests/ui/arc_with_non_send_sync.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fn foo<T>(x: T) {
77
// Should not lint - purposefully ignoring generic args.
88
let a = Arc::new(x);
99
}
10+
fn issue11076<T>() {
11+
let a: Arc<Vec<T>> = Arc::new(Vec::new());
12+
}
1013

1114
fn main() {
1215
// This is safe, as `i32` implements `Send` and `Sync`.

tests/ui/arc_with_non_send_sync.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
2-
--> $DIR/arc_with_non_send_sync.rs:16:13
2+
--> $DIR/arc_with_non_send_sync.rs:19:13
33
|
44
LL | let b = Arc::new(RefCell::new(42));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)