2023-08-24 19:32:12 +00:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-07-02 12:35:19 +00:00
|
|
|
#![warn(clippy::arc_with_non_send_sync)]
|
|
|
|
#![allow(unused_variables)]
|
2023-07-31 21:53:53 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macros;
|
|
|
|
|
2023-07-02 12:35:19 +00:00
|
|
|
use std::cell::RefCell;
|
2023-07-31 21:53:53 +00:00
|
|
|
use std::ptr::{null, null_mut};
|
2023-07-02 12:35:19 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
|
|
fn foo<T>(x: T) {
|
|
|
|
// Should not lint - purposefully ignoring generic args.
|
|
|
|
let a = Arc::new(x);
|
|
|
|
}
|
2023-07-17 08:19:29 +00:00
|
|
|
fn issue11076<T>() {
|
|
|
|
let a: Arc<Vec<T>> = Arc::new(Vec::new());
|
|
|
|
}
|
2023-07-02 12:35:19 +00:00
|
|
|
|
2023-07-31 21:53:53 +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-07-02 12:35:19 +00:00
|
|
|
fn main() {
|
2023-07-17 08:19:29 +00:00
|
|
|
let _ = Arc::new(42);
|
2023-07-02 12:35:19 +00:00
|
|
|
|
2023-07-17 08:19:29 +00:00
|
|
|
let _ = Arc::new(RefCell::new(42));
|
2023-11-16 18:13:24 +00:00
|
|
|
//~^ ERROR: usage of an `Arc` that is not `Send` and `Sync`
|
2023-07-31 21:53:53 +00:00
|
|
|
//~| NOTE: the trait `Sync` is not implemented for `RefCell<i32>`
|
|
|
|
|
2023-07-17 08:19:29 +00:00
|
|
|
let mutex = Mutex::new(1);
|
|
|
|
let _ = Arc::new(mutex.lock().unwrap());
|
2023-11-16 18:13:24 +00:00
|
|
|
//~^ ERROR: usage of an `Arc` that is not `Send` and `Sync`
|
2023-07-31 21:53:53 +00:00
|
|
|
//~| NOTE: the trait `Send` is not implemented for `MutexGuard<'_, i32>`
|
|
|
|
|
2023-07-17 08:19:29 +00:00
|
|
|
let _ = Arc::new(&42 as *const i32);
|
2023-11-16 18:13:24 +00:00
|
|
|
//~^ ERROR: usage of an `Arc` that is not `Send` and `Sync`
|
2023-07-31 21:53:53 +00:00
|
|
|
//~| NOTE: the trait `Send` is not implemented for `*const i32`
|
|
|
|
//~| NOTE: the trait `Sync` is not implemented for `*const i32`
|
2023-07-02 12:35:19 +00:00
|
|
|
}
|