File tree 3 files changed +12
-2
lines changed 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use if_chain::if_chain;
6
6
use rustc_hir:: { Expr , ExprKind } ;
7
7
use rustc_lint:: LateContext ;
8
8
use rustc_lint:: LateLintPass ;
9
+ use rustc_middle:: ty;
9
10
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
10
11
use rustc_span:: symbol:: sym;
11
12
@@ -46,6 +47,10 @@ impl LateLintPass<'_> for ArcWithNonSendSync {
46
47
if let ExprKind :: Path ( func_path) = func. kind;
47
48
if last_path_segment( & func_path) . ident. name == sym:: new;
48
49
if let arg_ty = cx. typeck_results( ) . expr_ty( arg) ;
50
+ if match arg_ty. kind( ) {
51
+ ty:: Param ( _) => false ,
52
+ _ => true ,
53
+ } ;
49
54
if !cx. tcx
50
55
. lang_items( )
51
56
. sync_trait( )
Original file line number Diff line number Diff line change 3
3
use std:: cell:: RefCell ;
4
4
use std:: sync:: { Arc , Mutex } ;
5
5
6
+ fn foo < T > ( x : T ) {
7
+ // Should not lint - purposefully ignoring generic args.
8
+ let a = Arc :: new ( x) ;
9
+ }
10
+
6
11
fn main ( ) {
7
12
// This is safe, as `i32` implements `Send` and `Sync`.
8
13
let a = Arc :: new ( 42 ) ;
Original file line number Diff line number Diff line change 1
1
error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
2
- --> $DIR/arc_with_non_send_sync.rs:11 :13
2
+ --> $DIR/arc_with_non_send_sync.rs:16 :13
3
3
|
4
4
LL | let b = Arc::new(RefCell::new(42));
5
5
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6
6
|
7
- = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like Mutex<T>
7
+ = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like ` Mutex<T>`
8
8
= note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings`
9
9
10
10
error: aborting due to previous error
You can’t perform that action at this time.
0 commit comments