mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
trim paths in box_default
This commit is contained in:
parent
0bca8dd254
commit
d3a50d2fda
3 changed files with 10 additions and 10 deletions
|
@ -8,7 +8,7 @@ use rustc_hir::{
|
||||||
Block, Expr, ExprKind, Local, Node, QPath, TyKind,
|
Block, Expr, ExprKind, Local, Node, QPath, TyKind,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::{lint::in_external_macro, ty::print::with_forced_trimmed_paths};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ impl LateLintPass<'_> for BoxDefault {
|
||||||
if is_plain_default(arg_path) || given_type(cx, expr) {
|
if is_plain_default(arg_path) || given_type(cx, expr) {
|
||||||
"Box::default()".into()
|
"Box::default()".into()
|
||||||
} else {
|
} else {
|
||||||
format!("Box::<{arg_ty}>::default()")
|
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
|
||||||
},
|
},
|
||||||
Applicability::MachineApplicable
|
Applicability::MachineApplicable
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,16 +21,16 @@ macro_rules! outer {
|
||||||
fn main() {
|
fn main() {
|
||||||
let _string: Box<String> = Box::default();
|
let _string: Box<String> = Box::default();
|
||||||
let _byte = Box::<u8>::default();
|
let _byte = Box::<u8>::default();
|
||||||
let _vec = Box::<std::vec::Vec<u8>>::default();
|
let _vec = Box::<Vec<u8>>::default();
|
||||||
let _impl = Box::<ImplementsDefault>::default();
|
let _impl = Box::<ImplementsDefault>::default();
|
||||||
let _impl2 = Box::<ImplementsDefault>::default();
|
let _impl2 = Box::<ImplementsDefault>::default();
|
||||||
let _impl3: Box<ImplementsDefault> = Box::default();
|
let _impl3: Box<ImplementsDefault> = Box::default();
|
||||||
let _own = Box::new(OwnDefault::default()); // should not lint
|
let _own = Box::new(OwnDefault::default()); // should not lint
|
||||||
let _in_macro = outer!(Box::<std::string::String>::default());
|
let _in_macro = outer!(Box::<String>::default());
|
||||||
let _string_default = outer!(Box::<std::string::String>::default());
|
let _string_default = outer!(Box::<String>::default());
|
||||||
let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
|
let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
|
||||||
let _vec3: Box<Vec<bool>> = Box::default();
|
let _vec3: Box<Vec<bool>> = Box::default();
|
||||||
let _vec4: Box<_> = Box::<std::vec::Vec<bool>>::default();
|
let _vec4: Box<_> = Box::<Vec<bool>>::default();
|
||||||
let _more = ret_ty_fn();
|
let _more = ret_ty_fn();
|
||||||
call_ty_fn(Box::default());
|
call_ty_fn(Box::default());
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:24:16
|
--> $DIR/box_default.rs:24:16
|
||||||
|
|
|
|
||||||
LL | let _vec = Box::new(Vec::<u8>::new());
|
LL | let _vec = Box::new(Vec::<u8>::new());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<u8>>::default()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<u8>>::default()`
|
||||||
|
|
||||||
error: `Box::new(_)` of default value
|
error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:25:17
|
--> $DIR/box_default.rs:25:17
|
||||||
|
@ -40,13 +40,13 @@ error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:29:28
|
--> $DIR/box_default.rs:29:28
|
||||||
|
|
|
|
||||||
LL | let _in_macro = outer!(Box::new(String::new()));
|
LL | let _in_macro = outer!(Box::new(String::new()));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
|
||||||
|
|
||||||
error: `Box::new(_)` of default value
|
error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:30:34
|
--> $DIR/box_default.rs:30:34
|
||||||
|
|
|
|
||||||
LL | let _string_default = outer!(Box::new(String::from("")));
|
LL | let _string_default = outer!(Box::new(String::from("")));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
|
||||||
|
|
||||||
error: `Box::new(_)` of default value
|
error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:31:46
|
--> $DIR/box_default.rs:31:46
|
||||||
|
@ -64,7 +64,7 @@ error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:33:25
|
--> $DIR/box_default.rs:33:25
|
||||||
|
|
|
|
||||||
LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
|
LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<bool>>::default()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<bool>>::default()`
|
||||||
|
|
||||||
error: `Box::new(_)` of default value
|
error: `Box::new(_)` of default value
|
||||||
--> $DIR/box_default.rs:35:16
|
--> $DIR/box_default.rs:35:16
|
||||||
|
|
Loading…
Add table
Reference in a new issue