about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-03 09:48:05 +0000
committerbors <bors@rust-lang.org>2023-07-03 09:48:05 +0000
commit2b03bb08b286aa5eaf983766dfde1a77aa0f11dd (patch)
treefe22e13db97054be6123026b750df233a326292f
parentc46ddeb9e146a21b2ad12d63543d111629099393 (diff)
parent75c339cd0ad7c38f8d258a369570400eae933973 (diff)
downloadrust-2b03bb08b286aa5eaf983766dfde1a77aa0f11dd.tar.gz
rust-2b03bb08b286aa5eaf983766dfde1a77aa0f11dd.zip
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`
-rw-r--r--clippy_lints/src/arc_with_non_send_sync.rs6
-rw-r--r--tests/ui/arc_with_non_send_sync.rs3
-rw-r--r--tests/ui/arc_with_non_send_sync.stderr2
3 files changed, 9 insertions, 2 deletions
diff --git a/clippy_lints/src/arc_with_non_send_sync.rs b/clippy_lints/src/arc_with_non_send_sync.rs
index a1e44668e1a..62313df9f90 100644
--- a/clippy_lints/src/arc_with_non_send_sync.rs
+++ b/clippy_lints/src/arc_with_non_send_sync.rs
@@ -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;
 
@@ -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()
diff --git a/tests/ui/arc_with_non_send_sync.rs b/tests/ui/arc_with_non_send_sync.rs
index ac786f68c12..9d5849277c2 100644
--- a/tests/ui/arc_with_non_send_sync.rs
+++ b/tests/ui/arc_with_non_send_sync.rs
@@ -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`.
diff --git a/tests/ui/arc_with_non_send_sync.stderr b/tests/ui/arc_with_non_send_sync.stderr
index fc2fc5f93b1..520c21b565b 100644
--- a/tests/ui/arc_with_non_send_sync.stderr
+++ b/tests/ui/arc_with_non_send_sync.stderr
@@ -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));
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^