[arc_with_non_send_sync
]: look for nested type parameters
This commit is contained in:
parent
17a48c2652
commit
75c339cd0a
@ -7,6 +7,7 @@
|
||||
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 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
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()
|
||||
|
@ -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`.
|
||||
|
@ -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));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user