}
}
+ /// Returns `""` (empty string) or `"mutably "` depending on the mutability.
+ pub fn mutably_str(self) -> &'static str {
+ match self {
+ Mutability::Not => "",
+ Mutability::Mut => "mutably ",
+ }
+ }
+
/// Return `true` if self is mutable
pub fn is_mut(self) -> bool {
matches!(self, Self::Mut)
})
.collect();
err.multipart_suggestion_verbose(
- &format!(
- "consider {}borrowing {value_name}",
- if borrow_level.is_mut() { "mutably " } else { "" }
- ),
+ format!("consider {}borrowing {value_name}", borrow_level.mutably_str()),
sugg,
Applicability::MaybeIncorrect,
);
}
let sugg_expr = if needs_parens { format!("({src})") } else { src };
- return Some(match mutability {
- hir::Mutability::Mut => (
- sp,
- "consider mutably borrowing here".to_string(),
- format!("{prefix}&mut {sugg_expr}"),
- Applicability::MachineApplicable,
- false,
- false,
- ),
- hir::Mutability::Not => (
- sp,
- "consider borrowing here".to_string(),
- format!("{prefix}&{sugg_expr}"),
- Applicability::MachineApplicable,
- false,
- false,
- ),
- });
+ return Some((
+ sp,
+ format!("consider {}borrowing here", mutability.mutably_str()),
+ format!("{prefix}{}{sugg_expr}", mutability.ref_prefix_str()),
+ Applicability::MachineApplicable,
+ false,
+ false,
+ ));
}
}
}