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);
|
let boxed_type = cx.tcx.type_of(def_id);
|
||||||
if boxed_type.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env);
|
if boxed_type.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env);
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
VEC_BOX_SIZED,
|
VEC_BOX_SIZED,
|
||||||
ast_ty.span,
|
ast_ty.span,
|
||||||
"you seem to be trying to use `Vec<Box<T>>`, but T is Sized. Consider using just `Vec<T>`",
|
"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.",
|
||||||
"`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
|
--> $DIR/vec_box_sized.rs:10:14
|
||||||
|
|
|
|
||||||
10 | sized_type: Vec<Box<SizedStruct>>,
|
10 | sized_type: Vec<Box<SizedStruct>>,
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::vec-box-sized` implied by `-D warnings`
|
= 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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue