Address review comments

This commit is contained in:
Samuel E. Moelius III 2021-12-14 18:36:19 -05:00
parent cb609a9904
commit 3beb6b1908
2 changed files with 12 additions and 16 deletions

View File

@ -1893,7 +1893,7 @@
/// and other `to_owned`-like functions.
///
/// ### Why is this bad?
/// The unnecessary calls result in unnecessary allocations.
/// The unnecessary calls result in useless allocations.
///
/// ### Example
/// ```rust

View File

@ -107,21 +107,17 @@ fn check_addr_of_expr(
then {
let (target_ty, n_target_refs) = peel_mid_ty_refs(target_ty);
let (receiver_ty, n_receiver_refs) = peel_mid_ty_refs(receiver_ty);
if_chain! {
if receiver_ty == target_ty;
if n_target_refs >= n_receiver_refs;
then {
span_lint_and_sugg(
cx,
UNNECESSARY_TO_OWNED,
parent.span,
&format!("unnecessary use of `{}`", method_name),
"use",
format!("{:&>width$}{}", "", receiver_snippet, width = n_target_refs - n_receiver_refs),
Applicability::MachineApplicable,
);
return true;
}
if receiver_ty == target_ty && n_target_refs >= n_receiver_refs {
span_lint_and_sugg(
cx,
UNNECESSARY_TO_OWNED,
parent.span,
&format!("unnecessary use of `{}`", method_name),
"use",
format!("{:&>width$}{}", "", receiver_snippet, width = n_target_refs - n_receiver_refs),
Applicability::MachineApplicable,
);
return true;
}
if_chain! {
if let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref);