1
Fork 0

Rename BindingAnnotation to BindingMode

This commit is contained in:
Jules Bertholet 2024-04-16 19:23:30 -04:00
parent d19e48d79a
commit 2a4624ddd1
No known key found for this signature in database
GPG key ID: 32034DAFC38C1BFC
81 changed files with 222 additions and 256 deletions

View file

@ -568,7 +568,7 @@ impl Pat {
// In a type expression `_` is an inference variable.
PatKind::Wild => TyKind::Infer,
// An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`.
PatKind::Ident(BindingAnnotation::NONE, ident, None) => {
PatKind::Ident(BindingMode::NONE, ident, None) => {
TyKind::Path(None, Path::from_ident(*ident))
}
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
@ -675,7 +675,7 @@ impl Pat {
pub fn descr(&self) -> Option<String> {
match &self.kind {
PatKind::Wild => Some("_".to_string()),
PatKind::Ident(BindingAnnotation::NONE, ident, None) => Some(format!("{ident}")),
PatKind::Ident(BindingMode::NONE, ident, None) => Some(format!("{ident}")),
PatKind::Ref(pat, mutbl) => pat.descr().map(|d| format!("&{}{d}", mutbl.prefix_str())),
_ => None,
}
@ -716,14 +716,14 @@ impl ByRef {
}
}
/// Explicit binding annotations given in the HIR for a binding. Note
/// that this is not the final binding *mode* that we infer after type
/// inference.
/// The mode of a binding (`mut`, `ref mut`, etc).
/// Used for both the wxplicit binding annotations given in the HIR for a binding
/// and the final binding *mode* that we infer after type inference.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Encodable, Decodable, HashStable_Generic)]
pub struct BindingAnnotation(pub ByRef, pub Mutability);
pub struct BindingMode(pub ByRef, pub Mutability);
impl BindingAnnotation {
impl BindingMode {
pub const NONE: Self = Self(ByRef::No, Mutability::Not);
pub const REF: Self = Self(ByRef::Yes(Mutability::Not), Mutability::Not);
pub const MUT: Self = Self(ByRef::No, Mutability::Mut);
@ -771,7 +771,7 @@ pub enum PatKind {
/// or a unit struct/variant pattern, or a const pattern (in the last two cases the third
/// field must be `None`). Disambiguation cannot be done with parser alone, so it happens
/// during name resolution.
Ident(BindingAnnotation, Ident, Option<P<Pat>>),
Ident(BindingMode, Ident, Option<P<Pat>>),
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest),
@ -2384,7 +2384,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
impl Param {
/// Attempts to cast parameter to `ExplicitSelf`.
pub fn to_self(&self) -> Option<ExplicitSelf> {
if let PatKind::Ident(BindingAnnotation(ByRef::No, mutbl), ident, _) = self.pat.kind {
if let PatKind::Ident(BindingMode(ByRef::No, mutbl), ident, _) = self.pat.kind {
if ident.name == kw::SelfLower {
return match self.ty.kind {
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
@ -2436,7 +2436,7 @@ impl Param {
attrs,
pat: P(Pat {
id: DUMMY_NODE_ID,
kind: PatKind::Ident(BindingAnnotation(ByRef::No, mutbl), eself_ident, None),
kind: PatKind::Ident(BindingMode(ByRef::No, mutbl), eself_ident, None),
span,
tokens: None,
}),