File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 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;
66use rustc_hir:: { Expr , ExprKind } ;
77use rustc_lint:: LateContext ;
88use rustc_lint:: LateLintPass ;
9+ use rustc_middle:: ty;
910use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1011use rustc_span:: symbol:: sym;
1112
@@ -46,6 +47,10 @@ impl LateLintPass<'_> for ArcWithNonSendSync {
4647 if let ExprKind :: Path ( func_path) = func. kind;
4748 if last_path_segment( & func_path) . ident. name == sym:: new;
4849 if let arg_ty = cx. typeck_results( ) . expr_ty( arg) ;
50+ if match arg_ty. kind( ) {
51+ ty:: Param ( _) => false ,
52+ _ => true ,
53+ } ;
4954 if !cx. tcx
5055 . lang_items( )
5156 . sync_trait( )
Original file line number Diff line number Diff line change 33use std:: cell:: RefCell ;
44use std:: sync:: { Arc , Mutex } ;
55
6+ fn foo < T > ( x : T ) {
7+ // Should not lint - purposefully ignoring generic args.
8+ let a = Arc :: new ( x) ;
9+ }
10+
611fn main ( ) {
712 // This is safe, as `i32` implements `Send` and `Sync`.
813 let a = Arc :: new ( 42 ) ;
Original file line number Diff line number Diff line change 11error: 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
33 |
44LL | let b = Arc::new(RefCell::new(42));
55 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
66 |
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>`
88 = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings`
99
1010error: aborting due to previous error
You can’t perform that action at this time.
0 commit comments