Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T>
This commit is contained in:
parent
439bae62a4
commit
480ccc3dbe
3 changed files with 15 additions and 4 deletions
|
|
@ -353,14 +353,25 @@ impl Types {
|
|||
);
|
||||
return; // don't recurse into the type
|
||||
}
|
||||
if let Some(span) = match_type_parameter(cx, qpath, &paths::BOX) {
|
||||
if match_type_parameter(cx, qpath, &paths::BOX).is_some() {
|
||||
let box_ty = match &last_path_segment(qpath).args.unwrap().args[0] {
|
||||
GenericArg::Type(ty) => match &ty.kind {
|
||||
TyKind::Path(qpath) => qpath,
|
||||
_ => panic!("Box that isn't a type"),
|
||||
},
|
||||
_ => panic!("Rc without type argument"),
|
||||
};
|
||||
let inner_span = match &last_path_segment(&box_ty).args.unwrap().args[0] {
|
||||
GenericArg::Type(ty) => ty.span,
|
||||
_ => panic!("Box without type argument"),
|
||||
};
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
REDUNDANT_ALLOCATION,
|
||||
hir_ty.span,
|
||||
"usage of `Rc<Box<T>>`",
|
||||
"try",
|
||||
snippet(cx, span, "..").to_string(),
|
||||
format!("Rc<{}>", snippet(cx, inner_span, "..")),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
return; // don't recurse into the type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue