2022-10-23 08:18:45 -05:00
|
|
|
// run-rustfix
|
|
|
|
#![warn(clippy::box_default)]
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct ImplementsDefault;
|
|
|
|
|
|
|
|
struct OwnDefault;
|
|
|
|
|
|
|
|
impl OwnDefault {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! outer {
|
|
|
|
($e: expr) => {
|
|
|
|
$e
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _string: Box<String> = Box::default();
|
|
|
|
let _byte = Box::<u8>::default();
|
2023-01-12 12:48:13 -06:00
|
|
|
let _vec = Box::<Vec<u8>>::default();
|
2022-10-23 08:18:45 -05:00
|
|
|
let _impl = Box::<ImplementsDefault>::default();
|
|
|
|
let _impl2 = Box::<ImplementsDefault>::default();
|
|
|
|
let _impl3: Box<ImplementsDefault> = Box::default();
|
|
|
|
let _own = Box::new(OwnDefault::default()); // should not lint
|
2023-01-12 12:48:13 -06:00
|
|
|
let _in_macro = outer!(Box::<String>::default());
|
|
|
|
let _string_default = outer!(Box::<String>::default());
|
2022-10-23 08:18:45 -05:00
|
|
|
let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
|
|
|
|
let _vec3: Box<Vec<bool>> = Box::default();
|
2023-01-12 12:48:13 -06:00
|
|
|
let _vec4: Box<_> = Box::<Vec<bool>>::default();
|
2022-10-23 08:18:45 -05:00
|
|
|
let _more = ret_ty_fn();
|
|
|
|
call_ty_fn(Box::default());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ret_ty_fn() -> Box<bool> {
|
|
|
|
Box::<bool>::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::boxed_local)]
|
|
|
|
fn call_ty_fn(_b: Box<u8>) {
|
|
|
|
issue_9621_dyn_trait();
|
|
|
|
}
|
|
|
|
|
|
|
|
use std::io::{Read, Result};
|
|
|
|
|
|
|
|
impl Read for ImplementsDefault {
|
|
|
|
fn read(&mut self, _: &mut [u8]) -> Result<usize> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_9621_dyn_trait() {
|
|
|
|
let _: Box<dyn Read> = Box::<ImplementsDefault>::default();
|
2023-01-12 12:48:13 -06:00
|
|
|
issue_10089();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_10089() {
|
|
|
|
let _closure = || {
|
|
|
|
#[derive(Default)]
|
|
|
|
struct WeirdPathed;
|
|
|
|
|
|
|
|
let _ = Box::<WeirdPathed>::default();
|
|
|
|
};
|
2022-10-23 08:18:45 -05:00
|
|
|
}
|