Refactor and re-use BindingAnnotation
This commit is contained in:
parent
9353538c7b
commit
02ba216e3c
25 changed files with 176 additions and 225 deletions
|
@ -7,7 +7,7 @@ use crate::LangItem;
|
|||
use rustc_ast as ast;
|
||||
use rustc_ast::util::parser::ExprPrecedence;
|
||||
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, TraitObjectSyntax, UintTy};
|
||||
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
|
||||
pub use rustc_ast::{BindingAnnotation, BorrowKind, ByRef, ImplPolarity, IsAuto};
|
||||
pub use rustc_ast::{CaptureBy, Movability, Mutability};
|
||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
|
@ -1049,30 +1049,6 @@ pub struct PatField<'hir> {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
|
||||
pub enum BindingAnnotation {
|
||||
/// No binding annotation given: this means that the final binding mode
|
||||
/// will depend on whether we have skipped through a `&` reference
|
||||
/// when matching. For example, the `x` in `Some(x)` will have binding
|
||||
/// mode `None`; if you do `let Some(x) = &Some(22)`, it will
|
||||
/// ultimately be inferred to be by-reference.
|
||||
///
|
||||
/// Note that implicit reference skipping is not implemented yet (#42640).
|
||||
Unannotated,
|
||||
|
||||
/// Annotated with `mut x` -- could be either ref or not, similar to `None`.
|
||||
Mutable,
|
||||
|
||||
/// Annotated as `ref`, like `ref x`
|
||||
Ref,
|
||||
|
||||
/// Annotated as `ref mut x`.
|
||||
RefMut,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
|
||||
pub enum RangeEnd {
|
||||
Included,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::def::{CtorOf, DefKind, Res};
|
||||
use crate::def_id::DefId;
|
||||
use crate::hir::{self, HirId, PatKind};
|
||||
use crate::hir::{self, BindingAnnotation, ByRef, HirId, PatKind};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
use rustc_span::symbol::Ident;
|
||||
|
@ -93,12 +93,7 @@ impl hir::Pat<'_> {
|
|||
|
||||
pub fn simple_ident(&self) -> Option<Ident> {
|
||||
match self.kind {
|
||||
PatKind::Binding(
|
||||
hir::BindingAnnotation::Unannotated | hir::BindingAnnotation::Mutable,
|
||||
_,
|
||||
ident,
|
||||
None,
|
||||
) => Some(ident),
|
||||
PatKind::Binding(BindingAnnotation(ByRef::No, _), _, ident, None) => Some(ident),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -135,11 +130,11 @@ impl hir::Pat<'_> {
|
|||
pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> {
|
||||
let mut result = None;
|
||||
self.each_binding(|annotation, _, _, _| match annotation {
|
||||
hir::BindingAnnotation::Ref => match result {
|
||||
hir::BindingAnnotation::REF => match result {
|
||||
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
|
||||
_ => {}
|
||||
},
|
||||
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
|
||||
hir::BindingAnnotation::REF_MUT => result = Some(hir::Mutability::Mut),
|
||||
_ => {}
|
||||
});
|
||||
result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue