Add suggestion for replacement
This commit is contained in:
parent
e5ea5395b9
commit
616395f40b
2 changed files with 7 additions and 6 deletions
|
@ -290,12 +290,14 @@ fn check_ty(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool) {
|
|||
let boxed_type = cx.tcx.type_of(def_id);
|
||||
if boxed_type.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env);
|
||||
then {
|
||||
span_help_and_lint(
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
VEC_BOX_SIZED,
|
||||
ast_ty.span,
|
||||
"you seem to be trying to use `Vec<Box<T>>`, but T is Sized. Consider using just `Vec<T>`",
|
||||
"`Vec<T>` is already on the heap, `Vec<Box<T>>` makes an extra allocation.",
|
||||
"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.",
|
||||
"try",
|
||||
format!("Vec<{}>", boxed_type),
|
||||
Applicability::MachineApplicable
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
error: you seem to be trying to use `Vec<Box<T>>`, but T is Sized. Consider using just `Vec<T>`
|
||||
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.
|
||||
--> $DIR/vec_box_sized.rs:10:14
|
||||
|
|
||||
10 | sized_type: Vec<Box<SizedStruct>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
|
|
||||
= note: `-D clippy::vec-box-sized` implied by `-D warnings`
|
||||
= help: `Vec<T>` is already on the heap, `Vec<Box<T>>` makes an extra allocation.
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
Loading…
Reference in a new issue