Auto merge of #10153 - llogiq:box-default-trim-paths, r=Jarcho
trim paths in `box_default` This might help with #10089, though I have not tested that yet. In any event, it keeps the suggestion short and to the point. --- changelog: Trim paths in [`box_default`] suggestion
This commit is contained in:
commit
179a22f624
@ -8,7 +8,7 @@
|
||||
Block, Expr, ExprKind, Local, Node, QPath, TyKind,
|
||||
};
|
||||
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_span::sym;
|
||||
|
||||
@ -59,7 +59,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if is_plain_default(arg_path) || given_type(cx, expr) {
|
||||
"Box::default()".into()
|
||||
} else {
|
||||
format!("Box::<{arg_ty}>::default()")
|
||||
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
|
||||
},
|
||||
Applicability::MachineApplicable
|
||||
);
|
||||
|
@ -21,16 +21,16 @@ macro_rules! outer {
|
||||
fn main() {
|
||||
let _string: Box<String> = Box::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 _impl2 = Box::<ImplementsDefault>::default();
|
||||
let _impl3: Box<ImplementsDefault> = Box::default();
|
||||
let _own = Box::new(OwnDefault::default()); // should not lint
|
||||
let _in_macro = outer!(Box::<std::string::String>::default());
|
||||
let _string_default = outer!(Box::<std::string::String>::default());
|
||||
let _in_macro = outer!(Box::<String>::default());
|
||||
let _string_default = outer!(Box::<String>::default());
|
||||
let _vec2: Box<Vec<ImplementsDefault>> = 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();
|
||||
call_ty_fn(Box::default());
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ error: `Box::new(_)` of default value
|
||||
--> $DIR/box_default.rs:24:16
|
||||
|
|
||||
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
|
||||
--> $DIR/box_default.rs:25:17
|
||||
@ -40,13 +40,13 @@ error: `Box::new(_)` of default value
|
||||
--> $DIR/box_default.rs:29:28
|
||||
|
|
||||
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
|
||||
--> $DIR/box_default.rs:30:34
|
||||
|
|
||||
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
|
||||
--> $DIR/box_default.rs:31:46
|
||||
@ -64,7 +64,7 @@ error: `Box::new(_)` of default value
|
||||
--> $DIR/box_default.rs:33:25
|
||||
|
|
||||
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
|
||||
--> $DIR/box_default.rs:35:16
|
||||
|
Loading…
Reference in New Issue
Block a user