Add Mutability::mutably_str
This commit is contained in:
parent
e51cd6e822
commit
4439f1f6a6
3 changed files with 17 additions and 22 deletions
|
@ -804,6 +804,14 @@ impl Mutability {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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
|
/// Return `true` if self is mutable
|
||||||
pub fn is_mut(self) -> bool {
|
pub fn is_mut(self) -> bool {
|
||||||
matches!(self, Self::Mut)
|
matches!(self, Self::Mut)
|
||||||
|
|
|
@ -576,10 +576,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
err.multipart_suggestion_verbose(
|
err.multipart_suggestion_verbose(
|
||||||
&format!(
|
format!("consider {}borrowing {value_name}", borrow_level.mutably_str()),
|
||||||
"consider {}borrowing {value_name}",
|
|
||||||
if borrow_level.is_mut() { "mutably " } else { "" }
|
|
||||||
),
|
|
||||||
sugg,
|
sugg,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
|
|
@ -863,24 +863,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let sugg_expr = if needs_parens { format!("({src})") } else { src };
|
let sugg_expr = if needs_parens { format!("({src})") } else { src };
|
||||||
return Some(match mutability {
|
return Some((
|
||||||
hir::Mutability::Mut => (
|
sp,
|
||||||
sp,
|
format!("consider {}borrowing here", mutability.mutably_str()),
|
||||||
"consider mutably borrowing here".to_string(),
|
format!("{prefix}{}{sugg_expr}", mutability.ref_prefix_str()),
|
||||||
format!("{prefix}&mut {sugg_expr}"),
|
Applicability::MachineApplicable,
|
||||||
Applicability::MachineApplicable,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
));
|
||||||
),
|
|
||||||
hir::Mutability::Not => (
|
|
||||||
sp,
|
|
||||||
"consider borrowing here".to_string(),
|
|
||||||
format!("{prefix}&{sugg_expr}"),
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue