2023-07-27 08:23:04 -05:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-06-04 12:33:13 -05:00
|
|
|
#![warn(clippy::arc_with_non_send_sync)]
|
|
|
|
#![allow(unused_variables)]
|
2023-07-25 17:56:43 -05:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macros;
|
|
|
|
|
2023-06-04 12:33:13 -05:00
|
|
|
use std::cell::RefCell;
|
2023-07-25 17:56:43 -05:00
|
|
|
use std::ptr::{null, null_mut};
|
2023-06-04 12:33:13 -05:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
2023-06-08 02:22:04 -05:00
|
|
|
fn foo<T>(x: T) {
|
|
|
|
// Should not lint - purposefully ignoring generic args.
|
|
|
|
let a = Arc::new(x);
|
|
|
|
}
|
2023-07-03 04:34:02 -05:00
|
|
|
fn issue11076<T>() {
|
|
|
|
let a: Arc<Vec<T>> = Arc::new(Vec::new());
|
|
|
|
}
|
2023-06-08 02:22:04 -05:00
|
|
|
|
2023-07-25 17:56:43 -05:00
|
|
|
fn issue11232() {
|
|
|
|
external! {
|
|
|
|
let a: Arc<*const u8> = Arc::new(null());
|
|
|
|
let a: Arc<*mut u8> = Arc::new(null_mut());
|
|
|
|
}
|
|
|
|
with_span! {
|
|
|
|
span
|
|
|
|
let a: Arc<*const u8> = Arc::new(null());
|
|
|
|
let a: Arc<*mut u8> = Arc::new(null_mut());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 12:33:13 -05:00
|
|
|
fn main() {
|
2023-07-04 11:58:02 -05:00
|
|
|
let _ = Arc::new(42);
|
2023-06-04 12:33:13 -05:00
|
|
|
|
2023-07-04 11:58:02 -05:00
|
|
|
let _ = Arc::new(RefCell::new(42));
|
2023-07-25 17:56:43 -05:00
|
|
|
//~^ ERROR: usage of an `Arc` that is not `Send` or `Sync`
|
|
|
|
//~| NOTE: the trait `Sync` is not implemented for `RefCell<i32>`
|
|
|
|
|
2023-07-04 11:58:02 -05:00
|
|
|
let mutex = Mutex::new(1);
|
|
|
|
let _ = Arc::new(mutex.lock().unwrap());
|
2023-07-25 17:56:43 -05:00
|
|
|
//~^ ERROR: usage of an `Arc` that is not `Send` or `Sync`
|
|
|
|
//~| NOTE: the trait `Send` is not implemented for `MutexGuard<'_, i32>`
|
|
|
|
|
2023-07-04 11:58:02 -05:00
|
|
|
let _ = Arc::new(&42 as *const i32);
|
2023-07-25 17:56:43 -05:00
|
|
|
//~^ ERROR: usage of an `Arc` that is not `Send` or `Sync`
|
|
|
|
//~| NOTE: the trait `Send` is not implemented for `*const i32`
|
|
|
|
//~| NOTE: the trait `Sync` is not implemented for `*const i32`
|
2023-06-04 12:33:13 -05:00
|
|
|
}
|