Fix incorrect suggestion when clone_on_ref_ptr is triggered in macros

This commit is contained in:
ThibsG 2020-08-24 14:01:27 +02:00
parent 27ae4d303c
commit 3d820f71fe
3 changed files with 32 additions and 7 deletions

View file

@ -2150,18 +2150,19 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::
return;
};
let snippet = if in_macro(arg.span) {
snippet_with_macro_callsite(cx, arg.span, "_")
} else {
snippet(cx, arg.span, "_")
};
span_lint_and_sugg(
cx,
CLONE_ON_REF_PTR,
expr.span,
"using `.clone()` on a ref-counted pointer",
"try this",
format!(
"{}::<{}>::clone(&{})",
caller_type,
subst.type_at(0),
snippet(cx, arg.span, "_")
),
format!("{}::<{}>::clone(&{})", caller_type, subst.type_at(0), snippet),
Applicability::Unspecified, // Sometimes unnecessary ::<_> after Rc/Arc/Weak
);
}