Represent mutability checks more concisely
diff --git a/syntax/check.rs b/syntax/check.rs
index 9aaf738..53dd843 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -147,7 +147,7 @@
}
fn check_type_ref(cx: &mut Check, ty: &Ref) {
- if ty.mutability.is_some() && !ty.pinned {
+ if ty.mutable && !ty.pinned {
if let Some(requires_pin) = match &ty.inner {
Type::Ident(ident) if ident.rust == CxxString || is_opaque_cxx(cx, &ident.rust) => {
Some(ident.rust.to_string())
@@ -268,9 +268,9 @@
let ref span = span_for_receiver_error(receiver);
if receiver.ty.is_self() {
- let mutability = match receiver.mutability {
- Some(_) => "mut ",
- None => "",
+ let mutability = match receiver.mutable {
+ true => "mut ",
+ false => "",
};
let msg = format!(
"unnamed receiver type is only allowed if the surrounding \
@@ -284,10 +284,7 @@
&& !cx.types.rust.contains(&receiver.ty.rust)
{
cx.error(span, "unrecognized receiver type");
- } else if receiver.mutability.is_some()
- && !receiver.pinned
- && is_opaque_cxx(cx, &receiver.ty.rust)
- {
+ } else if receiver.mutable && !receiver.pinned && is_opaque_cxx(cx, &receiver.ty.rust) {
cx.error(
span,
format!(
@@ -346,13 +343,13 @@
fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
match &efn.ret {
- Some(Type::Ref(ty)) if ty.mutability.is_some() => {}
+ Some(Type::Ref(ty)) if ty.mutable => {}
_ => return,
}
for arg in &efn.args {
if let Type::Ref(ty) = &arg.ty {
- if ty.mutability.is_some() {
+ if ty.mutable {
return;
}
}
diff --git a/syntax/impls.rs b/syntax/impls.rs
index 318cfae..c11c386 100644
--- a/syntax/impls.rs
+++ b/syntax/impls.rs
@@ -124,22 +124,21 @@
pinned,
ampersand: _,
lifetime,
- mutability,
+ mutable,
inner,
pin_tokens: _,
+ mutability: _,
} = self;
let Ref {
pinned: pinned2,
ampersand: _,
lifetime: lifetime2,
- mutability: mutability2,
+ mutable: mutable2,
inner: inner2,
pin_tokens: _,
+ mutability: _,
} = other;
- pinned == pinned2
- && lifetime == lifetime2
- && mutability.is_some() == mutability2.is_some()
- && inner == inner2
+ pinned == pinned2 && lifetime == lifetime2 && mutable == mutable2 && inner == inner2
}
}
@@ -149,13 +148,14 @@
pinned,
ampersand: _,
lifetime,
- mutability,
+ mutable,
inner,
pin_tokens: _,
+ mutability: _,
} = self;
pinned.hash(state);
lifetime.hash(state);
- mutability.is_some().hash(state);
+ mutable.hash(state);
inner.hash(state);
}
}
@@ -246,26 +246,25 @@
pinned,
ampersand: _,
lifetime,
- mutability,
+ mutable,
var: _,
ty,
shorthand: _,
pin_tokens: _,
+ mutability: _,
} = self;
let Receiver {
pinned: pinned2,
ampersand: _,
lifetime: lifetime2,
- mutability: mutability2,
+ mutable: mutable2,
var: _,
ty: ty2,
shorthand: _,
pin_tokens: _,
+ mutability: _,
} = other;
- pinned == pinned2
- && lifetime == lifetime2
- && mutability.is_some() == mutability2.is_some()
- && ty == ty2
+ pinned == pinned2 && lifetime == lifetime2 && mutable == mutable2 && ty == ty2
}
}
@@ -275,15 +274,16 @@
pinned,
ampersand: _,
lifetime,
- mutability,
+ mutable,
var: _,
ty,
shorthand: _,
pin_tokens: _,
+ mutability: _,
} = self;
pinned.hash(state);
lifetime.hash(state);
- mutability.is_some().hash(state);
+ mutable.hash(state);
ty.hash(state);
}
}
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 9d0f829..7f9b918 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -138,11 +138,12 @@
pub pinned: bool,
pub ampersand: Token![&],
pub lifetime: Option<Lifetime>,
- pub mutability: Option<Token![mut]>,
+ pub mutable: bool,
pub var: Token![self],
pub ty: ResolvableName,
pub shorthand: bool,
pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>,
+ pub mutability: Option<Token![mut]>,
}
pub struct Variant {
@@ -178,9 +179,10 @@
pub pinned: bool,
pub ampersand: Token![&],
pub lifetime: Option<Lifetime>,
- pub mutability: Option<Token![mut]>,
+ pub mutable: bool,
pub inner: Type,
pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>,
+ pub mutability: Option<Token![mut]>,
}
pub struct Slice {
diff --git a/syntax/parse.rs b/syntax/parse.rs
index fcc44d2..c4549ea 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -397,11 +397,12 @@
pinned: false,
ampersand: *ampersand,
lifetime: lifetime.clone(),
- mutability: arg.mutability,
+ mutable: arg.mutability.is_some(),
var: arg.self_token,
ty: ResolvableName::make_self(arg.self_token.span),
shorthand: true,
pin_tokens: None,
+ mutability: arg.mutability,
});
continue;
}
@@ -429,11 +430,12 @@
pinned: reference.pinned,
ampersand: reference.ampersand,
lifetime: reference.lifetime,
- mutability: reference.mutability,
+ mutable: reference.mutable,
var: Token),
ty: ident,
shorthand: false,
pin_tokens: reference.pin_tokens,
+ mutability: reference.mutability,
});
continue;
}
@@ -641,9 +643,10 @@
pinned: false,
ampersand: ty.and_token,
lifetime: ty.lifetime.clone(),
- mutability: ty.mutability,
+ mutable: ty.mutability.is_some(),
inner,
pin_tokens: None,
+ mutability: ty.mutability,
})))
}