diff options
Diffstat (limited to 'compiler')
32 files changed, 115 insertions, 147 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f2452888948..0d44fbdd43d 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -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, }), diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index e26a65c1f29..f4d5e71bade 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -178,7 +178,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let pat_id = self.lower_node_id(pat_node_id); let pat = self.arena.alloc(hir::Pat { hir_id: pat_id, - kind: hir::PatKind::Binding(hir::BindingAnnotation::NONE, pat_id, Ident::empty(), None), + kind: hir::PatKind::Binding(hir::BindingMode::NONE, pat_id, Ident::empty(), None), span: ty.span, default_binding_modes: false, }); diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 66841c094ce..2305cc07795 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -643,7 +643,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (pat, task_context_hid) = self.pat_ident_binding_mode( span, Ident::with_dummy_span(sym::_task_context), - hir::BindingAnnotation::MUT, + hir::BindingMode::MUT, ); let param = hir::Param { hir_id: self.next_id(), @@ -805,11 +805,8 @@ impl<'hir> LoweringContext<'_, 'hir> { // debuggers and debugger extensions expect it to be called `__awaitee`. They use // this name to identify what is being awaited by a suspended async functions. let awaitee_ident = Ident::with_dummy_span(sym::__awaitee); - let (awaitee_pat, awaitee_pat_hid) = self.pat_ident_binding_mode( - gen_future_span, - awaitee_ident, - hir::BindingAnnotation::MUT, - ); + let (awaitee_pat, awaitee_pat_hid) = + self.pat_ident_binding_mode(gen_future_span, awaitee_ident, hir::BindingMode::MUT); let task_context_ident = Ident::with_dummy_span(sym::_task_context); @@ -1648,7 +1645,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // `mut iter` let iter = Ident::with_dummy_span(sym::iter); let (iter_pat, iter_pat_nid) = - self.pat_ident_binding_mode(head_span, iter, hir::BindingAnnotation::MUT); + self.pat_ident_binding_mode(head_span, iter, hir::BindingMode::MUT); let match_expr = { let iter = self.expr_ident(head_span, iter, iter_pat_nid); diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index abfea6078f2..e4c633aa324 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1179,9 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // Check if this is a binding pattern, if so, we can optimize and avoid adding a // `let <pat> = __argN;` statement. In this case, we do not rename the parameter. let (ident, is_simple_parameter) = match parameter.pat.kind { - hir::PatKind::Binding(hir::BindingAnnotation(ByRef::No, _), _, ident, _) => { - (ident, true) - } + hir::PatKind::Binding(hir::BindingMode(ByRef::No, _), _, ident, _) => (ident, true), // For `ref mut` or wildcard arguments, we can't reuse the binding, but // we can keep the same name for the parameter. // This lets rustdoc render it correctly in documentation. @@ -1244,7 +1242,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // because the user may have specified a `ref mut` binding in the next // statement. let (move_pat, move_id) = - self.pat_ident_binding_mode(desugared_span, ident, hir::BindingAnnotation::MUT); + self.pat_ident_binding_mode(desugared_span, ident, hir::BindingMode::MUT); let move_expr = self.expr_ident(desugared_span, ident, new_parameter_id); let move_stmt = self.stmt_let_pat( None, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index d6e62462b98..c5b5acf7f32 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1895,7 +1895,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| { let is_mutable_pat = matches!( arg.pat.kind, - PatKind::Ident(hir::BindingAnnotation(_, Mutability::Mut), ..) + PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..) ); match &arg.ty.kind { @@ -2478,18 +2478,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) { - self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE) + self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE) } fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) { - self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE) + self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE) } fn pat_ident_binding_mode( &mut self, span: Span, ident: Ident, - bm: hir::BindingAnnotation, + bm: hir::BindingMode, ) -> (&'hir hir::Pat<'hir>, HirId) { let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm); (self.arena.alloc(pat), hir_id) @@ -2499,7 +2499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, span: Span, ident: Ident, - bm: hir::BindingAnnotation, + bm: hir::BindingMode, ) -> (hir::Pat<'hir>, HirId) { let hir_id = self.next_id(); diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 8631d90be81..118a7322fbd 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -243,7 +243,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_pat_ident( &mut self, p: &Pat, - annotation: BindingAnnotation, + annotation: BindingMode, ident: Ident, lower_sub: impl FnOnce(&mut Self) -> Option<&'hir hir::Pat<'hir>>, ) -> hir::PatKind<'hir> { diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 495e90e967b..4e3d560ce89 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -276,8 +276,8 @@ impl<'a> AstValidator<'a> { fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) { for Param { pat, .. } in &decl.inputs { match pat.kind { - PatKind::Ident(BindingAnnotation::NONE, _, None) | PatKind::Wild => {} - PatKind::Ident(BindingAnnotation::MUT, ident, None) => { + PatKind::Ident(BindingMode::NONE, _, None) | PatKind::Wild => {} + PatKind::Ident(BindingMode::MUT, ident, None) => { report_err(pat.span, Some(ident), true) } _ => report_err(pat.span, None, false), diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 242335f769c..293e65ce872 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -17,7 +17,7 @@ use rustc_ast::util::classify; use rustc_ast::util::comments::{Comment, CommentStyle}; use rustc_ast::util::parser; use rustc_ast::{self as ast, AttrArgs, AttrArgsEq, BlockCheckMode, PatKind}; -use rustc_ast::{attr, BindingAnnotation, ByRef, DelimArgs, RangeEnd, RangeSyntax, Term}; +use rustc_ast::{attr, BindingMode, ByRef, DelimArgs, RangeEnd, RangeSyntax, Term}; use rustc_ast::{GenericArg, GenericBound, SelfKind}; use rustc_ast::{InlineAsmOperand, InlineAsmRegOrRegClass}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; @@ -1558,7 +1558,7 @@ impl<'a> State<'a> { match &pat.kind { PatKind::Wild => self.word("_"), PatKind::Never => self.word("!"), - PatKind::Ident(BindingAnnotation(by_ref, mutbl), ident, sub) => { + PatKind::Ident(BindingMode(by_ref, mutbl), ident, sub) => { if mutbl.is_mut() { self.word_nbsp("mut"); } @@ -1654,7 +1654,7 @@ impl<'a> State<'a> { if mutbl.is_mut() { self.word("mut "); } - if let PatKind::Ident(ast::BindingAnnotation::MUT, ..) = inner.kind { + if let PatKind::Ident(ast::BindingMode::MUT, ..) = inner.kind { self.popen(); self.print_pat(inner); self.pclose(); diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 8ccf88ec59c..ec0d4af599e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -377,7 +377,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if p.span == self.expr_span { self.pat = Some(p); } - if let hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, i, sub) = p.kind { + if let hir::PatKind::Binding(hir::BindingMode::NONE, _, i, sub) = p.kind { if i.span == self.expr_span || p.span == self.expr_span { self.pat = Some(p); } diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 602a84ce4dd..8b314217190 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -5,7 +5,7 @@ use core::ops::ControlFlow; use hir::{ExprKind, Param}; use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::Visitor; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, Node}; +use rustc_hir::{self as hir, BindingMode, ByRef, Node}; use rustc_infer::traits; use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt}; @@ -303,7 +303,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { { match *decl.local_info() { LocalInfo::User(BindingForm::Var(mir::VarBindingForm { - binding_mode: BindingAnnotation(ByRef::No, Mutability::Not), + binding_mode: BindingMode(ByRef::No, Mutability::Not), opt_ty_info: Some(sp), opt_match_place: _, pat_span: _, @@ -398,7 +398,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let upvar_hir_id = captured_place.get_root_variable(); if let Node::Pat(pat) = self.infcx.tcx.hir_node(upvar_hir_id) - && let hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, upvar_ident, _) = + && let hir::PatKind::Binding(hir::BindingMode::NONE, _, upvar_ident, _) = pat.kind { if upvar_ident.name == kw::SelfLower { @@ -729,7 +729,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { debug!("local_decl: {:?}", local_decl); let pat_span = match *local_decl.local_info() { LocalInfo::User(BindingForm::Var(mir::VarBindingForm { - binding_mode: BindingAnnotation(ByRef::No, Mutability::Not), + binding_mode: BindingMode(ByRef::No, Mutability::Not), opt_ty_info: _, opt_match_place: _, pat_span, @@ -1086,7 +1086,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { - binding_mode: BindingAnnotation(ByRef::No, _), + binding_mode: BindingMode(ByRef::No, _), opt_ty_info, .. })) => { @@ -1154,7 +1154,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { - binding_mode: BindingAnnotation(ByRef::Yes(_), _), + binding_mode: BindingMode(ByRef::Yes(_), _), .. })) => { let pattern_span: Span = local_decl.source_info.span; @@ -1356,7 +1356,7 @@ pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option< match *local_decl.local_info() { // Check if mutably borrowing a mutable reference. LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { - binding_mode: BindingAnnotation(ByRef::No, Mutability::Not), + binding_mode: BindingMode(ByRef::No, Mutability::Not), .. })) => matches!(local_decl.ty.kind(), ty::Ref(_, _, hir::Mutability::Mut)), LocalInfo::User(mir::BindingForm::ImplicitSelf(kind)) => { diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index f73106c1835..85d54e9257d 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -180,7 +180,7 @@ pub use SubstructureFields::*; use crate::{deriving, errors}; use rustc_ast::ptr::P; use rustc_ast::{ - self as ast, BindingAnnotation, ByRef, EnumDef, Expr, GenericArg, GenericParamKind, Generics, + self as ast, BindingMode, ByRef, EnumDef, Expr, GenericArg, GenericParamKind, Generics, Mutability, PatKind, TyKind, VariantData, }; use rustc_attr as attr; @@ -1479,11 +1479,7 @@ impl<'a> TraitDef<'a> { struct_field.ident, cx.pat( path.span, - PatKind::Ident( - BindingAnnotation(by_ref, Mutability::Not), - path, - None, - ), + PatKind::Ident(BindingMode(by_ref, Mutability::Not), path, None), ), ) }); diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index cdcf67b26f8..83f120525bc 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -202,7 +202,7 @@ impl<'a> ExtCtxt<'a> { ex: P<ast::Expr>, ) -> ast::Stmt { let pat = if mutbl { - self.pat_ident_binding_mode(sp, ident, ast::BindingAnnotation::MUT) + self.pat_ident_binding_mode(sp, ident, ast::BindingMode::MUT) } else { self.pat_ident(sp, ident) }; @@ -490,14 +490,14 @@ impl<'a> ExtCtxt<'a> { self.pat(span, PatKind::Lit(expr)) } pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> { - self.pat_ident_binding_mode(span, ident, ast::BindingAnnotation::NONE) + self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE) } pub fn pat_ident_binding_mode( &self, span: Span, ident: Ident, - ann: ast::BindingAnnotation, + ann: ast::BindingMode, ) -> P<ast::Pat> { let pat = PatKind::Ident(ann, ident.with_span_pos(span), None); self.pat(span, pat) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index b39056d8690..1ca30a48a51 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -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::{BinOp, BinOpKind, BindingAnnotation, BorrowKind, ByRef, CaptureBy}; +pub use rustc_ast::{BinOp, BinOpKind, BindingMode, BorrowKind, ByRef, CaptureBy}; pub use rustc_ast::{ImplPolarity, IsAuto, Movability, Mutability, UnOp}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_data_structures::fingerprint::Fingerprint; @@ -1151,7 +1151,7 @@ pub enum PatKind<'hir> { /// The `HirId` is the canonical ID for the variable being bound, /// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID), /// which is the pattern ID of the first `x`. - Binding(BindingAnnotation, HirId, Ident, Option<&'hir Pat<'hir>>), + Binding(BindingMode, HirId, Ident, Option<&'hir Pat<'hir>>), /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). /// The `bool` is `true` in the presence of a `..`. diff --git a/compiler/rustc_hir/src/pat_util.rs b/compiler/rustc_hir/src/pat_util.rs index 1eaab3d2aca..9991b02b1e1 100644 --- a/compiler/rustc_hir/src/pat_util.rs +++ b/compiler/rustc_hir/src/pat_util.rs @@ -1,6 +1,6 @@ use crate::def::{CtorOf, DefKind, Res}; use crate::def_id::{DefId, DefIdSet}; -use crate::hir::{self, BindingAnnotation, ByRef, HirId, PatKind}; +use crate::hir::{self, BindingMode, ByRef, HirId, PatKind}; use rustc_span::symbol::Ident; use rustc_span::Span; @@ -60,7 +60,7 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T { impl hir::Pat<'_> { /// Call `f` on every "binding" in a pattern, e.g., on `a` in /// `match foo() { Some(a) => (), None => () }` - pub fn each_binding(&self, mut f: impl FnMut(hir::BindingAnnotation, HirId, Span, Ident)) { + pub fn each_binding(&self, mut f: impl FnMut(hir::BindingMode, HirId, Span, Ident)) { self.walk_always(|p| { if let PatKind::Binding(binding_mode, _, ident, _) = p.kind { f(binding_mode, p.hir_id, p.span, ident); @@ -74,10 +74,7 @@ impl hir::Pat<'_> { /// When encountering an or-pattern `p_0 | ... | p_n` only the first non-never pattern will be /// visited. If they're all never patterns we visit nothing, which is ok since a never pattern /// cannot have bindings. - pub fn each_binding_or_first( - &self, - f: &mut impl FnMut(hir::BindingAnnotation, HirId, Span, Ident), - ) { + pub fn each_binding_or_first(&self, f: &mut impl FnMut(hir::BindingMode, HirId, Span, Ident)) { self.walk(|p| match &p.kind { PatKind::Or(ps) => { for p in *ps { @@ -98,7 +95,7 @@ impl hir::Pat<'_> { pub fn simple_ident(&self) -> Option<Ident> { match self.kind { - PatKind::Binding(BindingAnnotation(ByRef::No, _), _, ident, None) => Some(ident), + PatKind::Binding(BindingMode(ByRef::No, _), _, ident, None) => Some(ident), _ => None, } } @@ -135,8 +132,8 @@ 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 if result.is_none() => result = Some(hir::Mutability::Not), - hir::BindingAnnotation::REF_MUT => result = Some(hir::Mutability::Mut), + hir::BindingMode::REF if result.is_none() => result = Some(hir::Mutability::Not), + hir::BindingMode::REF_MUT => result = Some(hir::Mutability::Mut), _ => {} }); result diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 397893491a3..d2ea51f65f9 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -654,7 +654,7 @@ fn resolve_local<'tcx>( // & expression, and its lifetime would be extended to the end of the block (due // to a different rule, not the below code). match pat.kind { - PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes(_), _), ..) => true, + PatKind::Binding(hir::BindingMode(hir::ByRef::Yes(_), _), ..) => true, PatKind::Struct(_, field_pats, _) => field_pats.iter().any(|fp| is_binding_pat(fp.pat)), @@ -671,7 +671,7 @@ fn resolve_local<'tcx>( PatKind::Box(subpat) | PatKind::Deref(subpat) => is_binding_pat(subpat), PatKind::Ref(_, _) - | PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..) + | PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..) | PatKind::Wild | PatKind::Never | PatKind::Path(_) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 0f4d8df7293..285b99c2c69 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -10,7 +10,7 @@ use rustc_ast_pretty::pp::{self, Breaks}; use rustc_ast_pretty::pprust::{Comments, PrintState}; use rustc_hir as hir; use rustc_hir::{ - BindingAnnotation, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId, + BindingMode, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId, LifetimeParamKind, Node, PatKind, RangeEnd, Term, TraitBoundModifier, }; use rustc_span::source_map::SourceMap; @@ -1723,7 +1723,7 @@ impl<'a> State<'a> { match pat.kind { PatKind::Wild => self.word("_"), PatKind::Never => self.word("!"), - PatKind::Binding(BindingAnnotation(by_ref, mutbl), _, ident, sub) => { + PatKind::Binding(BindingMode(by_ref, mutbl), _, ident, sub) => { if mutbl.is_mut() { self.word_nbsp("mut"); } diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index aceb7a1c75d..6040b689f49 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -7,7 +7,7 @@ use rustc_errors::{ }; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::pat_util::EnumerateAndAdjustIterator; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability, Pat, PatKind}; +use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, Pat, PatKind}; use rustc_infer::infer; use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_lint as lint; @@ -667,7 +667,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn check_pat_ident( &self, pat: &'tcx Pat<'tcx>, - ba: BindingAnnotation, + ba: BindingMode, var_id: HirId, sub: Option<&'tcx Pat<'tcx>>, expected: Ty<'tcx>, @@ -677,7 +677,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Determine the binding mode... let bm = match ba { - BindingAnnotation(ByRef::No, Mutability::Mut) + BindingMode(ByRef::No, Mutability::Mut) if !(pat.span.at_least_rust_2024() && self.tcx.features().mut_preserve_binding_mode_2024) && matches!(def_br, ByRef::Yes(_)) => @@ -689,10 +689,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat.span, errors::DereferencingMutBinding { span: pat.span }, ); - BindingAnnotation(ByRef::No, Mutability::Mut) + BindingMode(ByRef::No, Mutability::Mut) } - BindingAnnotation(ByRef::No, mutbl) => BindingAnnotation(def_br, mutbl), - BindingAnnotation(ByRef::Yes(_), _) => ba, + BindingMode(ByRef::No, mutbl) => BindingMode(def_br, mutbl), + BindingMode(ByRef::Yes(_), _) => ba, }; // ...and store it in a side table: self.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm); @@ -734,7 +734,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// bindings have the same type by comparing them all against the type of that first pat. fn check_binding_alt_eq_ty( &self, - ba: BindingAnnotation, + ba: BindingMode, span: Span, var_id: HirId, ty: Ty<'tcx>, @@ -774,10 +774,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, expected: Ty<'tcx>, actual: Ty<'tcx>, - ba: BindingAnnotation, + ba: BindingMode, ) { match (expected.kind(), actual.kind(), ba) { - (ty::Ref(_, inner_ty, _), _, BindingAnnotation::NONE) + (ty::Ref(_, inner_ty, _), _, BindingMode::NONE) if self.can_eq(self.param_env, *inner_ty, actual) => { err.span_suggestion_verbose( @@ -787,7 +787,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Applicability::MaybeIncorrect, ); } - (_, ty::Ref(_, inner_ty, _), BindingAnnotation::REF) + (_, ty::Ref(_, inner_ty, _), BindingMode::REF) if self.can_eq(self.param_env, expected, *inner_ty) => { err.span_suggestion_verbose( @@ -879,7 +879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let PatKind::Ref(the_ref, _) = i.kind && let PatKind::Binding(mt, _, ident, _) = the_ref.kind { - let BindingAnnotation(_, mtblty) = mt; + let BindingMode(_, mtblty) = mt; err.span_suggestion_verbose( i.span, format!("consider removing `&{mutability}` from the pattern"), diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 60a5838cafc..2bf4f51a803 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -229,8 +229,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { else { bug!(); }; - let hir::PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), _, _, _) = - pat.kind + let hir::PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), _, _, _) = pat.kind else { // Complex pattern, skip the non-upvar local. continue; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 3fe1f21d56a..0b0949e4dd8 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1056,7 +1056,7 @@ impl UnusedParens { avoid_mut: bool, keep_space: (bool, bool), ) { - use ast::{BindingAnnotation, PatKind}; + use ast::{BindingMode, PatKind}; if let PatKind::Paren(inner) = &value.kind { match inner.kind { @@ -1068,7 +1068,7 @@ impl UnusedParens { // Avoid `p0 | .. | pn` if we should. PatKind::Or(..) if avoid_or => return, // Avoid `mut x` and `mut x @ p` if we should: - PatKind::Ident(BindingAnnotation::MUT, ..) if avoid_mut => { + PatKind::Ident(BindingMode::MUT, ..) if avoid_mut => { return; } // Otherwise proceed with linting. diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index df013effcb0..c331df1054b 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -18,8 +18,7 @@ use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, Into use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::{ - self as hir, BindingAnnotation, ByRef, CoroutineDesugaring, CoroutineKind, HirId, - ImplicitSelfKind, + self as hir, BindingMode, ByRef, CoroutineDesugaring, CoroutineKind, HirId, ImplicitSelfKind, }; use rustc_session::Session; use rustc_span::source_map::Spanned; @@ -930,7 +929,7 @@ pub enum LocalKind { #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub struct VarBindingForm<'tcx> { /// Is variable bound via `x`, `mut x`, `ref x`, `ref mut x`, `mut ref x`, or `mut ref mut x`? - pub binding_mode: BindingAnnotation, + pub binding_mode: BindingMode, /// If an explicit type was provided for this variable binding, /// this holds the source Span of that type. /// @@ -1155,7 +1154,7 @@ impl<'tcx> LocalDecl<'tcx> { self.local_info(), LocalInfo::User( BindingForm::Var(VarBindingForm { - binding_mode: BindingAnnotation(ByRef::No, _), + binding_mode: BindingMode(ByRef::No, _), opt_ty_info: _, opt_match_place: _, pat_span: _, @@ -1172,7 +1171,7 @@ impl<'tcx> LocalDecl<'tcx> { self.local_info(), LocalInfo::User( BindingForm::Var(VarBindingForm { - binding_mode: BindingAnnotation(ByRef::No, _), + binding_mode: BindingMode(ByRef::No, _), opt_ty_info: _, opt_match_place: _, pat_span: _, diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 8763e94c8b0..3b705017710 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -12,7 +12,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd}; +use rustc_hir::{BindingMode, ByRef, HirId, MatchSource, RangeEnd}; use rustc_index::newtype_index; use rustc_index::IndexVec; use rustc_middle::middle::region; @@ -603,10 +603,7 @@ impl<'tcx> Pat<'tcx> { pub fn simple_ident(&self) -> Option<Symbol> { match self.kind { PatKind::Binding { - name, - mode: BindingAnnotation(ByRef::No, _), - subpattern: None, - .. + name, mode: BindingMode(ByRef::No, _), subpattern: None, .. } => Some(name), _ => None, } @@ -730,7 +727,7 @@ pub enum PatKind<'tcx> { Binding { name: Symbol, #[type_visitable(ignore)] - mode: BindingAnnotation, + mode: BindingMode, #[type_visitable(ignore)] var: LocalVarId, ty: Ty<'tcx>, diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 818fb78793e..a28afcc4fb8 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -17,7 +17,7 @@ use rustc_hir::{ def::{DefKind, Res}, def_id::{DefId, LocalDefId, LocalDefIdMap}, hir_id::OwnerId, - BindingAnnotation, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability, + BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability, }; use rustc_index::IndexVec; use rustc_macros::HashStable; @@ -78,8 +78,8 @@ pub struct TypeckResults<'tcx> { adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>, - /// Stores the actual binding mode for all instances of [`BindingAnnotation`]. - pat_binding_modes: ItemLocalMap<BindingAnnotation>, + /// Stores the actual binding mode for all instances of [`BindingMode`]. + pat_binding_modes: ItemLocalMap<BindingMode>, /// Stores the types which were implicitly dereferenced in pattern binding modes /// for later usage in THIR lowering. For example, @@ -413,22 +413,17 @@ impl<'tcx> TypeckResults<'tcx> { matches!(self.type_dependent_defs().get(expr.hir_id), Some(Ok((DefKind::AssocFn, _)))) } - pub fn extract_binding_mode( - &self, - s: &Session, - id: HirId, - sp: Span, - ) -> Option<BindingAnnotation> { + pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option<BindingMode> { self.pat_binding_modes().get(id).copied().or_else(|| { s.dcx().span_bug(sp, "missing binding mode"); }) } - pub fn pat_binding_modes(&self) -> LocalTableInContext<'_, BindingAnnotation> { + pub fn pat_binding_modes(&self) -> LocalTableInContext<'_, BindingMode> { LocalTableInContext { hir_owner: self.hir_owner, data: &self.pat_binding_modes } } - pub fn pat_binding_modes_mut(&mut self) -> LocalTableInContextMut<'_, BindingAnnotation> { + pub fn pat_binding_modes_mut(&mut self) -> LocalTableInContextMut<'_, BindingMode> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.pat_binding_modes } } @@ -460,7 +455,7 @@ impl<'tcx> TypeckResults<'tcx> { let mut has_ref_mut = false; pat.walk(|pat| { if let hir::PatKind::Binding(_, id, _, _) = pat.kind - && let Some(BindingAnnotation(ByRef::Yes(Mutability::Mut), _)) = + && let Some(BindingMode(ByRef::Yes(Mutability::Mut), _)) = self.pat_binding_modes().get(id) { has_ref_mut = true; diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 367c391b45a..3228fe25ac1 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -14,7 +14,7 @@ use rustc_data_structures::{ fx::{FxHashSet, FxIndexMap, FxIndexSet}, stack::ensure_sufficient_stack, }; -use rustc_hir::{BindingAnnotation, ByRef}; +use rustc_hir::{BindingMode, ByRef}; use rustc_middle::middle::region; use rustc_middle::mir::{self, *}; use rustc_middle::thir::{self, *}; @@ -621,12 +621,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) -> BlockAnd<()> { match irrefutable_pat.kind { // Optimize the case of `let x = ...` to write directly into `x` - PatKind::Binding { - mode: BindingAnnotation(ByRef::No, _), - var, - subpattern: None, - .. - } => { + PatKind::Binding { mode: BindingMode(ByRef::No, _), var, subpattern: None, .. } => { let place = self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true); unpack!(block = self.expr_into_dest(place, block, initializer_id)); @@ -652,7 +647,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { box Pat { kind: PatKind::Binding { - mode: BindingAnnotation(ByRef::No, _), + mode: BindingMode(ByRef::No, _), var, subpattern: None, .. @@ -893,7 +888,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { f: &mut impl FnMut( &mut Self, Symbol, - BindingAnnotation, + BindingMode, LocalVarId, Span, Ty<'tcx>, @@ -1148,7 +1143,7 @@ struct Binding<'tcx> { span: Span, source: Place<'tcx>, var_id: LocalVarId, - binding_mode: BindingAnnotation, + binding_mode: BindingMode, } /// Indicates that the type of `source` must be a subtype of the @@ -2412,7 +2407,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { source_info: SourceInfo, visibility_scope: SourceScope, name: Symbol, - mode: BindingAnnotation, + mode: BindingMode, var_id: LocalVarId, var_ty: Ty<'tcx>, user_ty: UserTypeProjections, diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index b5d72619a38..cc525f2ac2f 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -9,7 +9,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Node}; +use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Node}; use rustc_index::bit_set::GrowableBitSet; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; @@ -931,7 +931,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Don't introduce extra copies for simple bindings PatKind::Binding { var, - mode: BindingAnnotation(ByRef::No, mutability), + mode: BindingMode(ByRef::No, mutability), subpattern: None, .. } => { @@ -941,7 +941,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if let Some(kind) = param.self_kind { LocalInfo::User(BindingForm::ImplicitSelf(kind)) } else { - let binding_mode = BindingAnnotation(ByRef::No, mutability); + let binding_mode = BindingMode(ByRef::No, mutability); LocalInfo::User(BindingForm::Var(VarBindingForm { binding_mode, opt_ty_info: param.ty_span, diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 9ee0fb79bf4..0c1e1d59c4f 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -2,7 +2,7 @@ use crate::build::ExprCategory; use crate::errors::*; use rustc_errors::DiagArgValue; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability}; +use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability}; use rustc_middle::mir::BorrowKind; use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; @@ -288,7 +288,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { visit::walk_pat(self, pat); } } - PatKind::Binding { mode: BindingAnnotation(ByRef::Yes(rm), _), ty, .. } => { + PatKind::Binding { mode: BindingMode(ByRef::Yes(rm), _), ty, .. } => { if self.inside_adt { let ty::Ref(_, ty, _) = ty.kind() else { span_bug!( diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 03195a122b4..241d38f90d2 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -15,7 +15,7 @@ use rustc_errors::{ }; use rustc_hir::def::*; use rustc_hir::def_id::LocalDefId; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId}; +use rustc_hir::{self as hir, BindingMode, ByRef, HirId}; use rustc_middle::middle::limits::get_limit_size; use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; @@ -839,7 +839,7 @@ fn check_for_bindings_named_same_as_variants( ) { if let PatKind::Binding { name, - mode: BindingAnnotation(ByRef::No, Mutability::Not), + mode: BindingMode(ByRef::No, Mutability::Not), subpattern: None, ty, .. diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 64f766543a7..f256dbf4360 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -29,7 +29,7 @@ use rustc_ast::token::{self, Delimiter, Lit, LitKind, Token, TokenKind}; use rustc_ast::tokenstream::AttrTokenTree; use rustc_ast::util::parser::AssocOp; use rustc_ast::{ - AngleBracketedArg, AngleBracketedArgs, AnonConst, AttrVec, BinOpKind, BindingAnnotation, Block, + AngleBracketedArg, AngleBracketedArgs, AnonConst, AttrVec, BinOpKind, BindingMode, Block, BlockCheckMode, Expr, ExprKind, GenericArg, Generics, HasTokens, Item, ItemKind, Param, Pat, PatKind, Path, PathSegment, QSelf, Ty, TyKind, }; @@ -51,7 +51,7 @@ use thin_vec::{thin_vec, ThinVec}; pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param { let pat = P(Pat { id: ast::DUMMY_NODE_ID, - kind: PatKind::Ident(BindingAnnotation::NONE, ident, None), + kind: PatKind::Ident(BindingMode::NONE, ident, None), span: ident.span, tokens: None, }); @@ -2787,7 +2787,7 @@ impl<'a> Parser<'a> { } _ => {} }, - PatKind::Ident(BindingAnnotation::NONE, ident, None) => { + PatKind::Ident(BindingMode::NONE, ident, None) => { match &first_pat.kind { PatKind::Ident(_, old_ident, _) => { let path = PatKind::Path( diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 8ae809f566b..84ecd0a0de5 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2712,7 +2712,7 @@ impl<'a> Parser<'a> { match ty { Ok(ty) => { let ident = Ident::new(kw::Empty, this.prev_token.span); - let bm = BindingAnnotation::NONE; + let bm = BindingMode::NONE; let pat = this.mk_pat_ident(ty.span, bm, ident); (pat, ty) } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index dd1ecf9b7c1..78d3d019bf4 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -16,8 +16,8 @@ use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor}; use rustc_ast::ptr::P; use rustc_ast::token::{self, BinOpToken, Delimiter, Token}; use rustc_ast::{ - self as ast, AttrVec, BindingAnnotation, ByRef, Expr, ExprKind, MacCall, Mutability, Pat, - PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, + self as ast, AttrVec, BindingMode, ByRef, Expr, ExprKind, MacCall, Mutability, Pat, PatField, + PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, }; use rustc_ast_pretty::pprust; use rustc_errors::{Applicability, Diag, PResult}; @@ -486,7 +486,7 @@ impl<'a> Parser<'a> { } // Parse ref ident @ pat / ref mut ident @ pat let mutbl = self.parse_mutability(); - self.parse_pat_ident(BindingAnnotation(ByRef::Yes(mutbl), Mutability::Not), syntax_loc)? + self.parse_pat_ident(BindingMode(ByRef::Yes(mutbl), Mutability::Not), syntax_loc)? } else if self.eat_keyword(kw::Box) { self.parse_pat_box()? } else if self.check_inline_const(0) { @@ -511,7 +511,7 @@ impl<'a> Parser<'a> { // Parse `ident @ pat` // This can give false positives and parse nullary enums, // they are dealt with later in resolve. - self.parse_pat_ident(BindingAnnotation::NONE, syntax_loc)? + self.parse_pat_ident(BindingMode::NONE, syntax_loc)? } else if self.is_start_of_pat_with_path() { // Parse pattern starting with a path let (qself, path) = if self.eat_lt() { @@ -766,8 +766,7 @@ impl<'a> Parser<'a> { let mut pat = self.parse_pat_no_top_alt(Some(Expected::Identifier), None)?; // If we don't have `mut $ident (@ pat)?`, error. - if let PatKind::Ident(BindingAnnotation(br @ ByRef::No, m @ Mutability::Not), ..) = - &mut pat.kind + if let PatKind::Ident(BindingMode(br @ ByRef::No, m @ Mutability::Not), ..) = &mut pat.kind { // Don't recurse into the subpattern. // `mut` on the outer binding doesn't affect the inner bindings. @@ -779,8 +778,7 @@ impl<'a> Parser<'a> { self.ban_mut_general_pat(mut_span, &pat, changed_any_binding); } - if matches!(pat.kind, PatKind::Ident(BindingAnnotation(ByRef::Yes(_), Mutability::Mut), ..)) - { + if matches!(pat.kind, PatKind::Ident(BindingMode(ByRef::Yes(_), Mutability::Mut), ..)) { self.psess.gated_spans.gate(sym::mut_ref, pat.span); } Ok(pat.into_inner().kind) @@ -792,7 +790,7 @@ impl<'a> Parser<'a> { struct AddMut(bool); impl MutVisitor for AddMut { fn visit_pat(&mut self, pat: &mut P<Pat>) { - if let PatKind::Ident(BindingAnnotation(ByRef::No, m @ Mutability::Not), ..) = + if let PatKind::Ident(BindingMode(ByRef::No, m @ Mutability::Not), ..) = &mut pat.kind { self.0 = true; @@ -1025,7 +1023,7 @@ impl<'a> Parser<'a> { /// error message when parsing mistakes like `ref foo(a, b)`. fn parse_pat_ident( &mut self, - binding_annotation: BindingAnnotation, + binding_annotation: BindingMode, syntax_loc: Option<PatternLocation>, ) -> PResult<'a, PatKind> { let ident = self.parse_ident_common(false)?; @@ -1163,7 +1161,7 @@ impl<'a> Parser<'a> { None }; - Ok(PatKind::Ident(BindingAnnotation::NONE, Ident::new(kw::Box, box_span), sub)) + Ok(PatKind::Ident(BindingMode::NONE, Ident::new(kw::Box, box_span), sub)) } else { let pat = self.parse_pat_with_range_pat(false, None, None)?; self.psess.gated_spans.gate(sym::box_patterns, box_span.to(self.prev_token.span)); @@ -1344,7 +1342,7 @@ impl<'a> Parser<'a> { if let Some(last) = fields.iter().last() && last.is_shorthand && let PatKind::Ident(binding, ident, None) = last.pat.kind - && binding != BindingAnnotation::NONE + && binding != BindingMode::NONE && self.token == token::Colon // We found `ref mut? ident:`, try to parse a `name,` or `name }`. && let Some(name_span) = self.look_ahead(1, |t| t.is_ident().then(|| t.span)) @@ -1400,7 +1398,7 @@ impl<'a> Parser<'a> { let fieldname = self.parse_field_name()?; hi = self.prev_token.span; - let ann = BindingAnnotation(by_ref, mutability); + let ann = BindingMode(by_ref, mutability); let fieldpat = self.mk_pat_ident(boxed_span.to(hi), ann, fieldname); let subpat = if is_box { self.mk_pat(lo.to(hi), PatKind::Box(fieldpat)) } else { fieldpat }; @@ -1418,7 +1416,7 @@ impl<'a> Parser<'a> { }) } - pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingAnnotation, ident: Ident) -> P<Pat> { + pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingMode, ident: Ident) -> P<Pat> { self.mk_pat(span, PatKind::Ident(ann, ident, None)) } diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index a1f37ee3b83..d45ee32a624 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -83,8 +83,7 @@ fn check_abi(tcx: TyCtxt<'_>, def_id: LocalDefId, abi: Abi) { fn check_no_patterns(tcx: TyCtxt<'_>, params: &[hir::Param<'_>]) { for param in params { match param.pat.kind { - hir::PatKind::Wild - | hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, _, None) => {} + hir::PatKind::Wild | hir::PatKind::Binding(hir::BindingMode::NONE, _, _, None) => {} _ => { tcx.dcx().emit_err(NoPatterns { span: param.pat.span }); } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index ba1391bc378..753ba09d886 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -46,7 +46,7 @@ use diagnostics::{ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime} #[derive(Copy, Clone, Debug)] struct BindingInfo { span: Span, - annotation: BindingAnnotation, + annotation: BindingMode, } #[derive(Copy, Clone, PartialEq, Eq, Debug)] @@ -3655,14 +3655,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { fn try_resolve_as_non_binding( &mut self, pat_src: PatternSource, - ann: BindingAnnotation, + ann: BindingMode, 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 && ann == BindingAnnotation::NONE; + let is_syntactic_ambiguity = !has_sub && ann == BindingMode::NONE; let ls_binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS)?; let (res, binding) = match ls_binding { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 4c1784a18e5..db3794c1c40 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -751,9 +751,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // Get the local name of this closure. This can be inaccurate because // of the possibility of reassignment, but this should be good enough. match &kind { - hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, ident, None) => { - Some(ident.name) - } + hir::PatKind::Binding(hir::BindingMode::NONE, _, ident, None) => Some(ident.name), _ => { err.note(msg); None |
