Skip to content

Commit 179a22f

Browse files
committed
Auto merge of rust-lang#10153 - llogiq:box-default-trim-paths, r=Jarcho
trim paths in `box_default` This might help with rust-lang#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
2 parents 3f48ed5 + d3a50d2 commit 179a22f

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

clippy_lints/src/box_default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::{
88
Block, Expr, ExprKind, Local, Node, QPath, TyKind,
99
};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
11-
use rustc_middle::lint::in_external_macro;
11+
use rustc_middle::{lint::in_external_macro, ty::print::with_forced_trimmed_paths};
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
1313
use rustc_span::sym;
1414

@@ -59,7 +59,7 @@ impl LateLintPass<'_> for BoxDefault {
5959
if is_plain_default(arg_path) || given_type(cx, expr) {
6060
"Box::default()".into()
6161
} else {
62-
format!("Box::<{arg_ty}>::default()")
62+
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
6363
},
6464
Applicability::MachineApplicable
6565
);

tests/ui/box_default.fixed

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ macro_rules! outer {
2121
fn main() {
2222
let _string: Box<String> = Box::default();
2323
let _byte = Box::<u8>::default();
24-
let _vec = Box::<std::vec::Vec<u8>>::default();
24+
let _vec = Box::<Vec<u8>>::default();
2525
let _impl = Box::<ImplementsDefault>::default();
2626
let _impl2 = Box::<ImplementsDefault>::default();
2727
let _impl3: Box<ImplementsDefault> = Box::default();
2828
let _own = Box::new(OwnDefault::default()); // should not lint
29-
let _in_macro = outer!(Box::<std::string::String>::default());
30-
let _string_default = outer!(Box::<std::string::String>::default());
29+
let _in_macro = outer!(Box::<String>::default());
30+
let _string_default = outer!(Box::<String>::default());
3131
let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
3232
let _vec3: Box<Vec<bool>> = Box::default();
33-
let _vec4: Box<_> = Box::<std::vec::Vec<bool>>::default();
33+
let _vec4: Box<_> = Box::<Vec<bool>>::default();
3434
let _more = ret_ty_fn();
3535
call_ty_fn(Box::default());
3636
}

tests/ui/box_default.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error: `Box::new(_)` of default value
1616
--> $DIR/box_default.rs:24:16
1717
|
1818
LL | let _vec = Box::new(Vec::<u8>::new());
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<u8>>::default()`
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<u8>>::default()`
2020

2121
error: `Box::new(_)` of default value
2222
--> $DIR/box_default.rs:25:17
@@ -40,13 +40,13 @@ error: `Box::new(_)` of default value
4040
--> $DIR/box_default.rs:29:28
4141
|
4242
LL | let _in_macro = outer!(Box::new(String::new()));
43-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
43+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
4444

4545
error: `Box::new(_)` of default value
4646
--> $DIR/box_default.rs:30:34
4747
|
4848
LL | let _string_default = outer!(Box::new(String::from("")));
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
5050

5151
error: `Box::new(_)` of default value
5252
--> $DIR/box_default.rs:31:46
@@ -64,7 +64,7 @@ error: `Box::new(_)` of default value
6464
--> $DIR/box_default.rs:33:25
6565
|
6666
LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<bool>>::default()`
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<bool>>::default()`
6868

6969
error: `Box::new(_)` of default value
7070
--> $DIR/box_default.rs:35:16

0 commit comments

Comments
 (0)