2023-07-25 22:56:43 +00:00
|
|
|
//@aux-build:proc_macros.rs:proc-macro
|
2023-06-04 17:33:13 +00:00
|
|
|
#![warn(clippy::arc_with_non_send_sync)]
|
|
|
|
#![allow(unused_variables)]
|
2023-07-25 22:56:43 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macros;
|
|
|
|
|
2023-06-04 17:33:13 +00:00
|
|
|
use std::cell::RefCell;
|
2023-07-25 22:56:43 +00:00
|
|
|
use std::ptr::{null, null_mut};
|
2023-06-04 17:33:13 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
2023-06-08 07:22:04 +00:00
|
|
|
fn foo<T>(x: T) {
|
|
|
|
// Should not lint - purposefully ignoring generic args.
|
|
|
|
let a = Arc::new(x);
|
|
|
|
}
|
2023-07-03 09:34:02 +00:00
|
|
|
fn issue11076<T>() {
|
|
|
|
let a: Arc<Vec<T>> = Arc::new(Vec::new());
|
|
|
|
}
|
2023-06-08 07:22:04 +00:00
|
|
|
|
2023-07-25 22:56:43 +00: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 17:33:13 +00:00
|
|
|
fn main() {
|
2023-07-04 16:58:02 +00:00
|
|
|
let _ = Arc::new(42);
|
2023-06-04 17:33:13 +00:00
|
|
|
|
2023-07-04 16:58:02 +00:00
|
|
|
let _ = Arc::new(RefCell::new(42));
|
2023-07-25 22:56:43 +00: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 16:58:02 +00:00
|
|
|
let mutex = Mutex::new(1);
|
|
|
|
let _ = Arc::new(mutex.lock().unwrap());
|
2023-07-25 22:56:43 +00: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 16:58:02 +00:00
|
|
|
let _ = Arc::new(&42 as *const i32);
|
2023-07-25 22:56:43 +00: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 17:33:13 +00:00
|
|
|
}
|