2020-03-12 20:41:13 +00:00
|
|
|
#![warn(clippy::all)]
|
2022-08-03 03:56:59 +00:00
|
|
|
#![allow(clippy::boxed_local, clippy::disallowed_names)]
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2022-03-27 12:41:09 +00:00
|
|
|
pub struct MyStruct;
|
2020-03-12 20:41:13 +00:00
|
|
|
|
|
|
|
pub struct SubT<T> {
|
|
|
|
foo: T,
|
|
|
|
}
|
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
mod outer_box {
|
2023-07-03 17:42:48 +00:00
|
|
|
use crate::{MyStruct, SubT};
|
2021-06-02 05:41:52 +00:00
|
|
|
use std::boxed::Box;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn box_test6<T>(foo: Box<Rc<T>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Box<Rc<T>>`
|
|
|
|
//~| NOTE: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn box_test7<T>(foo: Box<Arc<T>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Box<Arc<T>>`
|
|
|
|
//~| NOTE: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn box_test8() -> Box<Rc<SubT<usize>>> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Box<Rc<SubT<usize>>>`
|
|
|
|
//~| NOTE: `Rc<SubT<usize>>` is already on the heap, `Box<Rc<SubT<usize>>>` makes an e
|
2021-06-02 05:41:52 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Box<Arc<T>>`
|
|
|
|
//~| NOTE: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
|
|
|
|
//~| ERROR: usage of `Box<Arc<SubT<T>>>`
|
|
|
|
//~| NOTE: `Arc<SubT<T>>` is already on the heap, `Box<Arc<SubT<T>>>` makes an extra a
|
2021-06-02 05:41:52 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
mod outer_rc {
|
2023-07-03 17:42:48 +00:00
|
|
|
use crate::{MyStruct, SubT};
|
2021-06-02 05:41:52 +00:00
|
|
|
use std::boxed::Box;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn rc_test5(a: Rc<Box<bool>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<bool>>`
|
|
|
|
//~| NOTE: `Box<bool>` is already on the heap, `Rc<Box<bool>>` makes an extra allocati
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn rc_test7(a: Rc<Arc<bool>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Arc<bool>>`
|
|
|
|
//~| NOTE: `Arc<bool>` is already on the heap, `Rc<Arc<bool>>` makes an extra allocati
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<SubT<usize>>>`
|
|
|
|
//~| NOTE: `Box<SubT<usize>>` is already on the heap, `Rc<Box<SubT<usize>>>` makes an
|
2021-06-02 05:41:52 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Arc<T>>`
|
|
|
|
//~| NOTE: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
|
|
|
|
//~| ERROR: usage of `Rc<Arc<SubT<T>>>`
|
|
|
|
//~| NOTE: `Arc<SubT<T>>` is already on the heap, `Rc<Arc<SubT<T>>>` makes an extra al
|
2021-06-02 05:41:52 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
mod outer_arc {
|
2023-07-03 17:42:48 +00:00
|
|
|
use crate::{MyStruct, SubT};
|
2021-06-02 05:41:52 +00:00
|
|
|
use std::boxed::Box;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn arc_test5(a: Arc<Box<bool>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Arc<Box<bool>>`
|
|
|
|
//~| NOTE: `Box<bool>` is already on the heap, `Arc<Box<bool>>` makes an extra allocat
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn arc_test6(a: Arc<Rc<bool>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Arc<Rc<bool>>`
|
|
|
|
//~| NOTE: `Rc<bool>` is already on the heap, `Arc<Rc<bool>>` makes an extra allocatio
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-06-02 05:41:52 +00:00
|
|
|
pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Arc<Box<SubT<usize>>>`
|
|
|
|
//~| NOTE: `Box<SubT<usize>>` is already on the heap, `Arc<Box<SubT<usize>>>` makes an
|
2021-06-02 05:41:52 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Arc<Rc<T>>`
|
|
|
|
//~| NOTE: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
|
|
|
|
//~| ERROR: usage of `Arc<Rc<SubT<T>>>`
|
|
|
|
//~| NOTE: `Rc<SubT<T>>` is already on the heap, `Arc<Rc<SubT<T>>>` makes an extra all
|
2021-06-02 05:41:52 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 20:41:13 +00:00
|
|
|
|
2021-08-22 07:22:28 +00:00
|
|
|
// https://github.com/rust-lang/rust-clippy/issues/7487
|
|
|
|
mod box_dyn {
|
|
|
|
use std::boxed::Box;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub trait T {}
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
a: Box<Box<dyn T>>,
|
|
|
|
b: Rc<Box<dyn T>>,
|
|
|
|
c: Arc<Box<dyn T>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn test_box(_: Box<Box<dyn T>>) {}
|
|
|
|
pub fn test_rc(_: Rc<Box<dyn T>>) {}
|
|
|
|
pub fn test_arc(_: Arc<Box<dyn T>>) {}
|
|
|
|
pub fn test_rc_box(_: Rc<Box<Box<dyn T>>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<Box<dyn T>>>`
|
|
|
|
//~| NOTE: `Box<Box<dyn T>>` is already on the heap, `Rc<Box<Box<dyn T>>>` makes an ex
|
2021-08-22 07:22:28 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 18:21:51 +00:00
|
|
|
// https://github.com/rust-lang/rust-clippy/issues/8604
|
2022-05-12 23:06:23 +00:00
|
|
|
mod box_fat_ptr {
|
2022-05-10 18:21:51 +00:00
|
|
|
use std::boxed::Box;
|
2022-05-12 23:06:23 +00:00
|
|
|
use std::path::Path;
|
2022-05-10 18:21:51 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-05-12 23:06:23 +00:00
|
|
|
pub struct DynSized {
|
|
|
|
foo: [usize],
|
|
|
|
}
|
|
|
|
|
2022-05-10 18:21:51 +00:00
|
|
|
struct S {
|
|
|
|
a: Box<Box<str>>,
|
|
|
|
b: Rc<Box<str>>,
|
|
|
|
c: Arc<Box<str>>,
|
2022-05-12 23:06:23 +00:00
|
|
|
|
|
|
|
e: Box<Box<[usize]>>,
|
|
|
|
f: Box<Box<Path>>,
|
|
|
|
g: Box<Box<DynSized>>,
|
2022-05-10 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 23:06:23 +00:00
|
|
|
pub fn test_box_str(_: Box<Box<str>>) {}
|
|
|
|
pub fn test_rc_str(_: Rc<Box<str>>) {}
|
|
|
|
pub fn test_arc_str(_: Arc<Box<str>>) {}
|
|
|
|
|
|
|
|
pub fn test_box_slice(_: Box<Box<[usize]>>) {}
|
|
|
|
pub fn test_box_path(_: Box<Box<Path>>) {}
|
|
|
|
pub fn test_box_custom(_: Box<Box<DynSized>>) {}
|
|
|
|
|
|
|
|
pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<Box<str>>>`
|
|
|
|
//~| NOTE: `Box<Box<str>>` is already on the heap, `Rc<Box<Box<str>>>` makes an extra
|
2022-05-12 23:06:23 +00:00
|
|
|
pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<Box<[usize]>>>`
|
|
|
|
//~| NOTE: `Box<Box<[usize]>>` is already on the heap, `Rc<Box<Box<[usize]>>>` makes a
|
2022-05-12 23:06:23 +00:00
|
|
|
pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<Box<Path>>>`
|
|
|
|
//~| NOTE: `Box<Box<Path>>` is already on the heap, `Rc<Box<Box<Path>>>` makes an extr
|
2022-05-12 23:06:23 +00:00
|
|
|
pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: usage of `Rc<Box<Box<DynSized>>>`
|
|
|
|
//~| NOTE: `Box<Box<DynSized>>` is already on the heap, `Rc<Box<Box<DynSized>>>` makes
|
2022-05-10 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
2023-09-14 21:20:50 +00:00
|
|
|
// https://github.com/rust-lang/rust-clippy/issues/11417
|
|
|
|
fn type_in_closure() {
|
|
|
|
let _ = |_: &mut Box<Box<dyn ToString>>| {};
|
|
|
|
}
|
|
|
|
|
2020-03-12 20:41:13 +00:00
|
|
|
fn main() {}
|