Add Mutability::ref_prefix_str
, order Mutability
, simplify code
This commit is contained in:
parent
d121aa3b55
commit
8195e12dd9
8 changed files with 51 additions and 97 deletions
|
@ -775,8 +775,9 @@ pub enum PatKind {
|
|||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
||||
#[derive(HashStable_Generic, Encodable, Decodable)]
|
||||
pub enum Mutability {
|
||||
Mut,
|
||||
// N.B. Order is deliberate, so that Not < Mut
|
||||
Not,
|
||||
Mut,
|
||||
}
|
||||
|
||||
impl Mutability {
|
||||
|
@ -787,12 +788,21 @@ impl Mutability {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
|
||||
pub fn prefix_str(&self) -> &'static str {
|
||||
match self {
|
||||
Mutability::Mut => "mut ",
|
||||
Mutability::Not => "",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `"&"` or `"&mut "` depending on the mutability.
|
||||
pub fn ref_prefix_str(&self) -> &'static str {
|
||||
match self {
|
||||
Mutability::Not => "&",
|
||||
Mutability::Mut => "&mut ",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of borrow in an `AddrOf` expression,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue