Refactor and re-use BindingAnnotation
This commit is contained in:
parent
9353538c7b
commit
02ba216e3c
25 changed files with 176 additions and 225 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue