Skip to content

Commit 616395f

Browse files
committed
Add suggestion for replacement
1 parent e5ea539 commit 616395f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clippy_lints/src/types.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,14 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
290290
let boxed_type = cx.tcx.type_of(def_id);
291291
if boxed_type.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env);
292292
then {
293-
span_help_and_lint(
293+
span_lint_and_sugg(
294294
cx,
295295
VEC_BOX_SIZED,
296296
ast_ty.span,
297-
"you seem to be trying to use `Vec<Box<T>>`, but T is Sized. Consider using just `Vec<T>`",
298-
"`Vec<T>` is already on the heap, `Vec<Box<T>>` makes an extra allocation.",
297+
"you seem to be trying to use `Vec<Box<T>>`, but T is Sized. `Vec<T>` is already on the heap, `Vec<Box<T>>` makes an extra allocation.",
298+
"try",
299+
format!("Vec<{}>", boxed_type),
300+
Applicability::MachineApplicable
299301
)
300302
}
301303
}

tests/ui/vec_box_sized.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
error: you seem to be trying to use `Vec<Box<T>>`, but T is Sized. Consider using just `Vec<T>`
1+
error: you seem to be trying to use `Vec<Box<T>>`, but T is Sized. `Vec<T>` is already on the heap, `Vec<Box<T>>` makes an extra allocation.
22
--> $DIR/vec_box_sized.rs:10:14
33
|
44
10 | sized_type: Vec<Box<SizedStruct>>,
5-
| ^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
66
|
77
= note: `-D clippy::vec-box-sized` implied by `-D warnings`
8-
= help: `Vec<T>` is already on the heap, `Vec<Box<T>>` makes an extra allocation.
98

109
error: aborting due to previous error
1110

0 commit comments

Comments
 (0)