diff options
| author | bors <bors@rust-lang.org> | 2023-07-03 09:48:05 +0000 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2023-08-17 16:52:14 +0200 |
| commit | 18880374387ff1e53b1c8d22688c1ec0f0e6bd56 (patch) | |
| tree | 964797fa9ab49ab96f9fda744357cb623f9568b7 /src | |
| parent | 214ab1197f5a1ea327333976fbb83b96624b0a93 (diff) | |
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`
Diffstat (limited to 'src')
3 files changed, 9 insertions, 2 deletions
diff --git a/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs b/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs index a1e44668e1a..62313df9f90 100644 --- a/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs +++ b/src/tools/clippy/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/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs b/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs index ac786f68c12..9d5849277c2 100644 --- a/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs +++ b/src/tools/clippy/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/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr b/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr index fc2fc5f93b1..520c21b565b 100644 --- a/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr +++ b/src/tools/clippy/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)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
