diff options
| author | bors <bors@rust-lang.org> | 2022-09-06 03:16:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-06 03:16:29 +0000 |
| commit | 6c358c67d4d39b1b4dbbcee89e96ec748d771e9e (patch) | |
| tree | 0b408a0a95a82676690a365e92530600e2a78874 /compiler/rustc_resolve | |
| parent | 56b27110e7f72ea01312d99f1b1e0577431cbbd0 (diff) | |
| parent | 9ea82d57e296efd6dfc0cb0a6c4c09f4111c123d (diff) | |
| download | rust-6c358c67d4d39b1b4dbbcee89e96ec748d771e9e.tar.gz rust-6c358c67d4d39b1b4dbbcee89e96ec748d771e9e.zip | |
Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
`BindingAnnotation` refactor
* `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`)
* `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)`
* Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}`
One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`.
I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
Diffstat (limited to 'compiler/rustc_resolve')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index dbe4d691f04..b37feb15890 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -20,7 +20,7 @@ use rustc_errors::DiagnosticId; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, PartialRes, PerNS}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; -use rustc_hir::{PrimTy, TraitCandidate}; +use rustc_hir::{BindingAnnotation, PrimTy, TraitCandidate}; use rustc_middle::middle::resolve_lifetime::Set1; use rustc_middle::ty::DefIdTree; use rustc_middle::{bug, span_bug}; @@ -50,7 +50,7 @@ use diagnostics::{ #[derive(Copy, Clone, Debug)] struct BindingInfo { span: Span, - binding_mode: BindingMode, + annotation: BindingAnnotation, } #[derive(Copy, Clone, PartialEq, Eq, Debug)] @@ -2865,10 +2865,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { pat.walk(&mut |pat| { match pat.kind { - PatKind::Ident(binding_mode, ident, ref sub_pat) + PatKind::Ident(annotation, ident, ref sub_pat) if sub_pat.is_some() || self.is_base_res_local(pat.id) => { - binding_map.insert(ident, BindingInfo { span: ident.span, binding_mode }); + binding_map.insert(ident, BindingInfo { span: ident.span, annotation }); } PatKind::Or(ref ps) => { // Check the consistency of this or-pattern and @@ -2925,7 +2925,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { binding_error.target.insert(pat_outer.span); } Some(binding_outer) => { - if binding_outer.binding_mode != binding_inner.binding_mode { + if binding_outer.annotation != binding_inner.annotation { // The binding modes in the outer and inner bindings differ. inconsistent_vars .entry(name) @@ -3146,14 +3146,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { fn try_resolve_as_non_binding( &mut self, pat_src: PatternSource, - bm: BindingMode, + ann: BindingAnnotation, ident: Ident, has_sub: bool, ) -> Option<Res> { // An immutable (no `mut`) by-value (no `ref`) binding pattern without // a sub pattern (no `@ $pat`) is syntactically ambiguous as it could // also be interpreted as a path to e.g. a constant, variant, etc. - let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not); + let is_syntactic_ambiguity = !has_sub && ann == BindingAnnotation::NONE; let ls_binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS)?; let (res, binding) = match ls_binding { |
