Auto merge of #5899 - JarredAllen:rc-box-suggestion, r=yaahc
Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T> Fixes #5722 changelog: Suggest `Rc<Box<T>>` -> `Rc<T>` in [`redundant_allocation`] lint
This commit is contained in:
commit
d5f5487252
@ -353,14 +353,25 @@ fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: boo
|
||||
);
|
||||
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,
|
||||
_ => return,
|
||||
},
|
||||
_ => return,
|
||||
};
|
||||
let inner_span = match &last_path_segment(&box_ty).args.unwrap().args[0] {
|
||||
GenericArg::Type(ty) => ty.span,
|
||||
_ => return,
|
||||
};
|
||||
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
|
||||
|
@ -33,7 +33,7 @@ pub fn test5(a: Rc<bool>) {}
|
||||
|
||||
// Rc<Box<T>>
|
||||
|
||||
pub fn test6(a: Box<bool>) {}
|
||||
pub fn test6(a: Rc<bool>) {}
|
||||
|
||||
// Box<&T>
|
||||
|
||||
|
@ -28,7 +28,7 @@ error: usage of `Rc<Box<T>>`
|
||||
--> $DIR/redundant_allocation.rs:36:17
|
||||
|
|
||||
LL | pub fn test6(a: Rc<Box<bool>>) {}
|
||||
| ^^^^^^^^^^^^^ help: try: `Box<bool>`
|
||||
| ^^^^^^^^^^^^^ help: try: `Rc<bool>`
|
||||
|
||||
error: usage of `Box<&T>`
|
||||
--> $DIR/redundant_allocation.rs:40:22
|
||||
|
Loading…
Reference in New Issue
Block a user