Auto merge of #5951 - ThibsG:FixMacroCloneOnRefPtr2076, r=ebroto
Fix incorrect suggestion when `clone_on_ref_ptr` is triggered in macros In the lint `clone_on_ref_ptr`, if the `span` is in a macro, don't expand it for suggestion. Fixes: #2076 changelog: none r? @ebroto
This commit is contained in:
commit
ad7a03cbaa
3 changed files with 28 additions and 7 deletions
|
|
@ -2150,18 +2150,15 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::
|
|||
return;
|
||||
};
|
||||
|
||||
let snippet = snippet_with_macro_callsite(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
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue