1
Fork 0

Rollup merge of #124047 - Jules-Bertholet:match-ergonomics-cleanups, r=Nadrieril

Match ergonomics 2024: miscellaneous code cleanups

- Store `ByRef` instead of `BindingAnnotation` in `PatInfo`
- Rename `BindingAnnotation` to `BindingMode`

r? ``@Nadrieril``

cc #123076

``@rustbot`` label A-patterns
This commit is contained in:
Matthias Krüger 2024-04-18 08:37:48 +02:00 committed by GitHub
commit 7add0bdf7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
81 changed files with 254 additions and 286 deletions

View file

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

View file

@ -178,7 +178,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let pat_id = self.lower_node_id(pat_node_id); let pat_id = self.lower_node_id(pat_node_id);
let pat = self.arena.alloc(hir::Pat { let pat = self.arena.alloc(hir::Pat {
hir_id: pat_id, 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, span: ty.span,
default_binding_modes: false, default_binding_modes: false,
}); });

View file

@ -643,7 +643,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (pat, task_context_hid) = self.pat_ident_binding_mode( let (pat, task_context_hid) = self.pat_ident_binding_mode(
span, span,
Ident::with_dummy_span(sym::_task_context), Ident::with_dummy_span(sym::_task_context),
hir::BindingAnnotation::MUT, hir::BindingMode::MUT,
); );
let param = hir::Param { let param = hir::Param {
hir_id: self.next_id(), 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 // 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. // this name to identify what is being awaited by a suspended async functions.
let awaitee_ident = Ident::with_dummy_span(sym::__awaitee); let awaitee_ident = Ident::with_dummy_span(sym::__awaitee);
let (awaitee_pat, awaitee_pat_hid) = self.pat_ident_binding_mode( let (awaitee_pat, awaitee_pat_hid) =
gen_future_span, self.pat_ident_binding_mode(gen_future_span, awaitee_ident, hir::BindingMode::MUT);
awaitee_ident,
hir::BindingAnnotation::MUT,
);
let task_context_ident = Ident::with_dummy_span(sym::_task_context); let task_context_ident = Ident::with_dummy_span(sym::_task_context);
@ -1648,7 +1645,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `mut iter` // `mut iter`
let iter = Ident::with_dummy_span(sym::iter); let iter = Ident::with_dummy_span(sym::iter);
let (iter_pat, iter_pat_nid) = 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 match_expr = {
let iter = self.expr_ident(head_span, iter, iter_pat_nid); let iter = self.expr_ident(head_span, iter, iter_pat_nid);

View file

@ -1179,9 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Check if this is a binding pattern, if so, we can optimize and avoid adding a // 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 <pat> = __argN;` statement. In this case, we do not rename the parameter.
let (ident, is_simple_parameter) = match parameter.pat.kind { let (ident, is_simple_parameter) = match parameter.pat.kind {
hir::PatKind::Binding(hir::BindingAnnotation(ByRef::No, _), _, ident, _) => { hir::PatKind::Binding(hir::BindingMode(ByRef::No, _), _, ident, _) => (ident, true),
(ident, true)
}
// For `ref mut` or wildcard arguments, we can't reuse the binding, but // For `ref mut` or wildcard arguments, we can't reuse the binding, but
// we can keep the same name for the parameter. // we can keep the same name for the parameter.
// This lets rustdoc render it correctly in documentation. // 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 // because the user may have specified a `ref mut` binding in the next
// statement. // statement.
let (move_pat, move_id) = 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_expr = self.expr_ident(desugared_span, ident, new_parameter_id);
let move_stmt = self.stmt_let_pat( let move_stmt = self.stmt_let_pat(
None, None,

View file

@ -1895,7 +1895,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| { implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
let is_mutable_pat = matches!( let is_mutable_pat = matches!(
arg.pat.kind, arg.pat.kind,
PatKind::Ident(hir::BindingAnnotation(_, Mutability::Mut), ..) PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
); );
match &arg.ty.kind { 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) { 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) { 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( fn pat_ident_binding_mode(
&mut self, &mut self,
span: Span, span: Span,
ident: Ident, ident: Ident,
bm: hir::BindingAnnotation, bm: hir::BindingMode,
) -> (&'hir hir::Pat<'hir>, HirId) { ) -> (&'hir hir::Pat<'hir>, HirId) {
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm); let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
(self.arena.alloc(pat), hir_id) (self.arena.alloc(pat), hir_id)
@ -2499,7 +2499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self, &mut self,
span: Span, span: Span,
ident: Ident, ident: Ident,
bm: hir::BindingAnnotation, bm: hir::BindingMode,
) -> (hir::Pat<'hir>, HirId) { ) -> (hir::Pat<'hir>, HirId) {
let hir_id = self.next_id(); let hir_id = self.next_id();

View file

@ -243,7 +243,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_pat_ident( fn lower_pat_ident(
&mut self, &mut self,
p: &Pat, p: &Pat,
annotation: BindingAnnotation, annotation: BindingMode,
ident: Ident, ident: Ident,
lower_sub: impl FnOnce(&mut Self) -> Option<&'hir hir::Pat<'hir>>, lower_sub: impl FnOnce(&mut Self) -> Option<&'hir hir::Pat<'hir>>,
) -> hir::PatKind<'hir> { ) -> hir::PatKind<'hir> {

View file

@ -276,8 +276,8 @@ impl<'a> AstValidator<'a> {
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) { fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
for Param { pat, .. } in &decl.inputs { for Param { pat, .. } in &decl.inputs {
match pat.kind { match pat.kind {
PatKind::Ident(BindingAnnotation::NONE, _, None) | PatKind::Wild => {} PatKind::Ident(BindingMode::NONE, _, None) | PatKind::Wild => {}
PatKind::Ident(BindingAnnotation::MUT, ident, None) => { PatKind::Ident(BindingMode::MUT, ident, None) => {
report_err(pat.span, Some(ident), true) report_err(pat.span, Some(ident), true)
} }
_ => report_err(pat.span, None, false), _ => report_err(pat.span, None, false),

View file

@ -17,7 +17,7 @@ use rustc_ast::util::classify;
use rustc_ast::util::comments::{Comment, CommentStyle}; use rustc_ast::util::comments::{Comment, CommentStyle};
use rustc_ast::util::parser; use rustc_ast::util::parser;
use rustc_ast::{self as ast, AttrArgs, AttrArgsEq, BlockCheckMode, PatKind}; 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::{GenericArg, GenericBound, SelfKind};
use rustc_ast::{InlineAsmOperand, InlineAsmRegOrRegClass}; use rustc_ast::{InlineAsmOperand, InlineAsmRegOrRegClass};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
@ -1558,7 +1558,7 @@ impl<'a> State<'a> {
match &pat.kind { match &pat.kind {
PatKind::Wild => self.word("_"), PatKind::Wild => self.word("_"),
PatKind::Never => 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() { if mutbl.is_mut() {
self.word_nbsp("mut"); self.word_nbsp("mut");
} }
@ -1654,7 +1654,7 @@ impl<'a> State<'a> {
if mutbl.is_mut() { if mutbl.is_mut() {
self.word("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.popen();
self.print_pat(inner); self.print_pat(inner);
self.pclose(); self.pclose();

View file

@ -377,7 +377,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if p.span == self.expr_span { if p.span == self.expr_span {
self.pat = Some(p); 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 { if i.span == self.expr_span || p.span == self.expr_span {
self.pat = Some(p); self.pat = Some(p);
} }

View file

@ -5,7 +5,7 @@ use core::ops::ControlFlow;
use hir::{ExprKind, Param}; use hir::{ExprKind, Param};
use rustc_errors::{Applicability, Diag}; use rustc_errors::{Applicability, Diag};
use rustc_hir::intravisit::Visitor; 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_infer::traits;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt};
@ -303,7 +303,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{ {
match *decl.local_info() { match *decl.local_info() {
LocalInfo::User(BindingForm::Var(mir::VarBindingForm { 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_ty_info: Some(sp),
opt_match_place: _, opt_match_place: _,
pat_span: _, pat_span: _,
@ -398,7 +398,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let upvar_hir_id = captured_place.get_root_variable(); let upvar_hir_id = captured_place.get_root_variable();
if let Node::Pat(pat) = self.infcx.tcx.hir_node(upvar_hir_id) 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 pat.kind
{ {
if upvar_ident.name == kw::SelfLower { if upvar_ident.name == kw::SelfLower {
@ -729,7 +729,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
debug!("local_decl: {:?}", local_decl); debug!("local_decl: {:?}", local_decl);
let pat_span = match *local_decl.local_info() { let pat_span = match *local_decl.local_info() {
LocalInfo::User(BindingForm::Var(mir::VarBindingForm { LocalInfo::User(BindingForm::Var(mir::VarBindingForm {
binding_mode: BindingAnnotation(ByRef::No, Mutability::Not), binding_mode: BindingMode(ByRef::No, Mutability::Not),
opt_ty_info: _, opt_ty_info: _,
opt_match_place: _, opt_match_place: _,
pat_span, pat_span,
@ -1086,7 +1086,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} }
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
binding_mode: BindingAnnotation(ByRef::No, _), binding_mode: BindingMode(ByRef::No, _),
opt_ty_info, opt_ty_info,
.. ..
})) => { })) => {
@ -1154,7 +1154,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} }
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { 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; 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() { match *local_decl.local_info() {
// Check if mutably borrowing a mutable reference. // Check if mutably borrowing a mutable reference.
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm { 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)), })) => matches!(local_decl.ty.kind(), ty::Ref(_, _, hir::Mutability::Mut)),
LocalInfo::User(mir::BindingForm::ImplicitSelf(kind)) => { LocalInfo::User(mir::BindingForm::ImplicitSelf(kind)) => {

View file

@ -180,7 +180,7 @@ pub use SubstructureFields::*;
use crate::{deriving, errors}; use crate::{deriving, errors};
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::{ 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, Mutability, PatKind, TyKind, VariantData,
}; };
use rustc_attr as attr; use rustc_attr as attr;
@ -1479,11 +1479,7 @@ impl<'a> TraitDef<'a> {
struct_field.ident, struct_field.ident,
cx.pat( cx.pat(
path.span, path.span,
PatKind::Ident( PatKind::Ident(BindingMode(by_ref, Mutability::Not), path, None),
BindingAnnotation(by_ref, Mutability::Not),
path,
None,
),
), ),
) )
}); });

View file

@ -202,7 +202,7 @@ impl<'a> ExtCtxt<'a> {
ex: P<ast::Expr>, ex: P<ast::Expr>,
) -> ast::Stmt { ) -> ast::Stmt {
let pat = if mutbl { 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 { } else {
self.pat_ident(sp, ident) self.pat_ident(sp, ident)
}; };
@ -490,14 +490,14 @@ impl<'a> ExtCtxt<'a> {
self.pat(span, PatKind::Lit(expr)) self.pat(span, PatKind::Lit(expr))
} }
pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> { 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( pub fn pat_ident_binding_mode(
&self, &self,
span: Span, span: Span,
ident: Ident, ident: Ident,
ann: ast::BindingAnnotation, ann: ast::BindingMode,
) -> P<ast::Pat> { ) -> P<ast::Pat> {
let pat = PatKind::Ident(ann, ident.with_span_pos(span), None); let pat = PatKind::Ident(ann, ident.with_span_pos(span), None);
self.pat(span, pat) self.pat(span, pat)

View file

@ -7,7 +7,7 @@ use crate::LangItem;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::util::parser::ExprPrecedence; use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, TraitObjectSyntax, UintTy}; 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}; pub use rustc_ast::{ImplPolarity, IsAuto, Movability, Mutability, UnOp};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_data_structures::fingerprint::Fingerprint; 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, /// 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), /// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID),
/// which is the pattern ID of the first `x`. /// 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, ..}`). /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`. /// The `bool` is `true` in the presence of a `..`.

View file

@ -1,6 +1,6 @@
use crate::def::{CtorOf, DefKind, Res}; use crate::def::{CtorOf, DefKind, Res};
use crate::def_id::{DefId, DefIdSet}; 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::symbol::Ident;
use rustc_span::Span; use rustc_span::Span;
@ -60,7 +60,7 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T {
impl hir::Pat<'_> { impl hir::Pat<'_> {
/// Call `f` on every "binding" in a pattern, e.g., on `a` in /// Call `f` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }` /// `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| { self.walk_always(|p| {
if let PatKind::Binding(binding_mode, _, ident, _) = p.kind { if let PatKind::Binding(binding_mode, _, ident, _) = p.kind {
f(binding_mode, p.hir_id, p.span, ident); 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 /// 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 /// visited. If they're all never patterns we visit nothing, which is ok since a never pattern
/// cannot have bindings. /// cannot have bindings.
pub fn each_binding_or_first( pub fn each_binding_or_first(&self, f: &mut impl FnMut(hir::BindingMode, HirId, Span, Ident)) {
&self,
f: &mut impl FnMut(hir::BindingAnnotation, HirId, Span, Ident),
) {
self.walk(|p| match &p.kind { self.walk(|p| match &p.kind {
PatKind::Or(ps) => { PatKind::Or(ps) => {
for p in *ps { for p in *ps {
@ -98,7 +95,7 @@ impl hir::Pat<'_> {
pub fn simple_ident(&self) -> Option<Ident> { pub fn simple_ident(&self) -> Option<Ident> {
match self.kind { match self.kind {
PatKind::Binding(BindingAnnotation(ByRef::No, _), _, ident, None) => Some(ident), PatKind::Binding(BindingMode(ByRef::No, _), _, ident, None) => Some(ident),
_ => None, _ => None,
} }
} }
@ -135,8 +132,8 @@ impl hir::Pat<'_> {
pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> { pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> {
let mut result = None; let mut result = None;
self.each_binding(|annotation, _, _, _| match annotation { self.each_binding(|annotation, _, _, _| match annotation {
hir::BindingAnnotation::REF if result.is_none() => result = Some(hir::Mutability::Not), hir::BindingMode::REF if result.is_none() => result = Some(hir::Mutability::Not),
hir::BindingAnnotation::REF_MUT => result = Some(hir::Mutability::Mut), hir::BindingMode::REF_MUT => result = Some(hir::Mutability::Mut),
_ => {} _ => {}
}); });
result result

View file

@ -654,7 +654,7 @@ fn resolve_local<'tcx>(
// & expression, and its lifetime would be extended to the end of the block (due // & expression, and its lifetime would be extended to the end of the block (due
// to a different rule, not the below code). // to a different rule, not the below code).
match pat.kind { 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)), 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::Box(subpat) | PatKind::Deref(subpat) => is_binding_pat(subpat),
PatKind::Ref(_, _) PatKind::Ref(_, _)
| PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..) | PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..)
| PatKind::Wild | PatKind::Wild
| PatKind::Never | PatKind::Never
| PatKind::Path(_) | PatKind::Path(_)

View file

@ -10,7 +10,7 @@ use rustc_ast_pretty::pp::{self, Breaks};
use rustc_ast_pretty::pprust::{Comments, PrintState}; use rustc_ast_pretty::pprust::{Comments, PrintState};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId, BindingMode, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId,
LifetimeParamKind, Node, PatKind, RangeEnd, Term, TraitBoundModifier, LifetimeParamKind, Node, PatKind, RangeEnd, Term, TraitBoundModifier,
}; };
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
@ -1723,7 +1723,7 @@ impl<'a> State<'a> {
match pat.kind { match pat.kind {
PatKind::Wild => self.word("_"), PatKind::Wild => self.word("_"),
PatKind::Never => 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() { if mutbl.is_mut() {
self.word_nbsp("mut"); self.word_nbsp("mut");
} }

View file

@ -7,7 +7,7 @@ use rustc_errors::{
}; };
use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::pat_util::EnumerateAndAdjustIterator; 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;
use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_lint as lint; use rustc_lint as lint;
@ -79,7 +79,7 @@ struct TopInfo<'tcx> {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct PatInfo<'tcx, 'a> { struct PatInfo<'tcx, 'a> {
binding_mode: BindingAnnotation, binding_mode: ByRef,
max_ref_mutbl: Mutability, max_ref_mutbl: Mutability,
top_info: TopInfo<'tcx>, top_info: TopInfo<'tcx>,
decl_origin: Option<DeclOrigin<'a>>, decl_origin: Option<DeclOrigin<'a>>,
@ -125,8 +125,6 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
} }
} }
const INITIAL_BM: BindingAnnotation = BindingAnnotation(ByRef::No, Mutability::Not);
/// Mode for adjusting the expected type and binding mode. /// Mode for adjusting the expected type and binding mode.
enum AdjustMode { enum AdjustMode {
/// Peel off all immediate reference types. /// Peel off all immediate reference types.
@ -163,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) { ) {
let info = TopInfo { expected, origin_expr, span }; let info = TopInfo { expected, origin_expr, span };
let pat_info = PatInfo { let pat_info = PatInfo {
binding_mode: INITIAL_BM, binding_mode: ByRef::No,
max_ref_mutbl: Mutability::Mut, max_ref_mutbl: Mutability::Mut,
top_info: info, top_info: info,
decl_origin, decl_origin,
@ -296,43 +294,43 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
pat: &'tcx Pat<'tcx>, pat: &'tcx Pat<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
def_bm: BindingAnnotation, def_br: ByRef,
adjust_mode: AdjustMode, adjust_mode: AdjustMode,
max_ref_mutbl: Mutability, max_ref_mutbl: Mutability,
) -> (Ty<'tcx>, BindingAnnotation, Mutability, bool) { ) -> (Ty<'tcx>, ByRef, Mutability, bool) {
if let ByRef::Yes(mutbl) = def_bm.0 { if let ByRef::Yes(mutbl) = def_br {
debug_assert!(mutbl <= max_ref_mutbl); debug_assert!(mutbl <= max_ref_mutbl);
} }
match adjust_mode { match adjust_mode {
AdjustMode::Pass => (expected, def_bm, max_ref_mutbl, false), AdjustMode::Pass => (expected, def_br, max_ref_mutbl, false),
AdjustMode::Reset => (expected, INITIAL_BM, Mutability::Mut, false), AdjustMode::Reset => (expected, ByRef::No, Mutability::Mut, false),
AdjustMode::ResetAndConsumeRef(ref_pat_mutbl) => { AdjustMode::ResetAndConsumeRef(ref_pat_mutbl) => {
let mutbls_match = def_bm.0 == ByRef::Yes(ref_pat_mutbl); let mutbls_match = def_br == ByRef::Yes(ref_pat_mutbl);
if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 { if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
if mutbls_match { if mutbls_match {
debug!("consuming inherited reference"); debug!("consuming inherited reference");
(expected, INITIAL_BM, cmp::min(max_ref_mutbl, ref_pat_mutbl), true) (expected, ByRef::No, cmp::min(max_ref_mutbl, ref_pat_mutbl), true)
} else { } else {
let (new_ty, new_bm, max_ref_mutbl) = if ref_pat_mutbl == Mutability::Mut { let (new_ty, new_bm, max_ref_mutbl) = if ref_pat_mutbl == Mutability::Mut {
self.peel_off_references( self.peel_off_references(
pat, pat,
expected, expected,
def_bm, def_br,
Mutability::Not, Mutability::Not,
max_ref_mutbl, max_ref_mutbl,
) )
} else { } else {
(expected, def_bm.cap_ref_mutability(Mutability::Not), Mutability::Not) (expected, def_br.cap_ref_mutability(Mutability::Not), Mutability::Not)
}; };
(new_ty, new_bm, max_ref_mutbl, false) (new_ty, new_bm, max_ref_mutbl, false)
} }
} else { } else {
(expected, INITIAL_BM, max_ref_mutbl, mutbls_match) (expected, ByRef::No, max_ref_mutbl, mutbls_match)
} }
} }
AdjustMode::Peel => { AdjustMode::Peel => {
let peeled = let peeled =
self.peel_off_references(pat, expected, def_bm, Mutability::Mut, max_ref_mutbl); self.peel_off_references(pat, expected, def_br, Mutability::Mut, max_ref_mutbl);
(peeled.0, peeled.1, peeled.2, false) (peeled.0, peeled.1, peeled.2, false)
} }
} }
@ -413,10 +411,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
pat: &'tcx Pat<'tcx>, pat: &'tcx Pat<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
mut def_bm: BindingAnnotation, mut def_br: ByRef,
max_peelable_mutability: Mutability, max_peelable_mutability: Mutability,
mut max_ref_mutability: Mutability, mut max_ref_mutability: Mutability,
) -> (Ty<'tcx>, BindingAnnotation, Mutability) { ) -> (Ty<'tcx>, ByRef, Mutability) {
let mut expected = self.try_structurally_resolve_type(pat.span, expected); let mut expected = self.try_structurally_resolve_type(pat.span, expected);
// Peel off as many `&` or `&mut` from the scrutinee type as possible. For example, // Peel off as many `&` or `&mut` from the scrutinee type as possible. For example,
// for `match &&&mut Some(5)` the loop runs three times, aborting when it reaches // for `match &&&mut Some(5)` the loop runs three times, aborting when it reaches
@ -437,7 +435,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat_adjustments.push(expected); pat_adjustments.push(expected);
expected = self.try_structurally_resolve_type(pat.span, inner_ty); expected = self.try_structurally_resolve_type(pat.span, inner_ty);
def_bm.0 = ByRef::Yes(match def_bm.0 { def_br = ByRef::Yes(match def_br {
// If default binding mode is by value, make it `ref` or `ref mut` // If default binding mode is by value, make it `ref` or `ref mut`
// (depending on whether we observe `&` or `&mut`). // (depending on whether we observe `&` or `&mut`).
ByRef::No | ByRef::No |
@ -450,21 +448,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 { if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
def_bm = def_bm.cap_ref_mutability(max_ref_mutability); def_br = def_br.cap_ref_mutability(max_ref_mutability);
if def_bm.0 == ByRef::Yes(Mutability::Not) { if def_br == ByRef::Yes(Mutability::Not) {
max_ref_mutability = Mutability::Not; max_ref_mutability = Mutability::Not;
} }
} }
if !pat_adjustments.is_empty() { if !pat_adjustments.is_empty() {
debug!("default binding mode is now {:?}", def_bm); debug!("default binding mode is now {:?}", def_br);
self.typeck_results self.typeck_results
.borrow_mut() .borrow_mut()
.pat_adjustments_mut() .pat_adjustments_mut()
.insert(pat.hir_id, pat_adjustments); .insert(pat.hir_id, pat_adjustments);
} }
(expected, def_bm, max_ref_mutability) (expected, def_br, max_ref_mutability)
} }
fn check_pat_lit( fn check_pat_lit(
@ -669,17 +667,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_pat_ident( fn check_pat_ident(
&self, &self,
pat: &'tcx Pat<'tcx>, pat: &'tcx Pat<'tcx>,
ba: BindingAnnotation, ba: BindingMode,
var_id: HirId, var_id: HirId,
sub: Option<&'tcx Pat<'tcx>>, sub: Option<&'tcx Pat<'tcx>>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
pat_info: PatInfo<'tcx, '_>, pat_info: PatInfo<'tcx, '_>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let PatInfo { binding_mode: BindingAnnotation(def_br, _), top_info: ti, .. } = pat_info; let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info;
// Determine the binding mode... // Determine the binding mode...
let bm = match ba { let bm = match ba {
BindingAnnotation(ByRef::No, Mutability::Mut) BindingMode(ByRef::No, Mutability::Mut)
if !(pat.span.at_least_rust_2024() if !(pat.span.at_least_rust_2024()
&& self.tcx.features().mut_preserve_binding_mode_2024) && self.tcx.features().mut_preserve_binding_mode_2024)
&& matches!(def_br, ByRef::Yes(_)) => && matches!(def_br, ByRef::Yes(_)) =>
@ -691,10 +689,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat.span, pat.span,
errors::DereferencingMutBinding { span: 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), BindingMode(ByRef::No, mutbl) => BindingMode(def_br, mutbl),
BindingAnnotation(ByRef::Yes(_), _) => ba, BindingMode(ByRef::Yes(_), _) => ba,
}; };
// ...and store it in a side table: // ...and store it in a side table:
self.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm); self.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm);
@ -736,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. /// bindings have the same type by comparing them all against the type of that first pat.
fn check_binding_alt_eq_ty( fn check_binding_alt_eq_ty(
&self, &self,
ba: BindingAnnotation, ba: BindingMode,
span: Span, span: Span,
var_id: HirId, var_id: HirId,
ty: Ty<'tcx>, ty: Ty<'tcx>,
@ -776,10 +774,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span, span: Span,
expected: Ty<'tcx>, expected: Ty<'tcx>,
actual: Ty<'tcx>, actual: Ty<'tcx>,
ba: BindingAnnotation, ba: BindingMode,
) { ) {
match (expected.kind(), actual.kind(), ba) { 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) => if self.can_eq(self.param_env, *inner_ty, actual) =>
{ {
err.span_suggestion_verbose( err.span_suggestion_verbose(
@ -789,7 +787,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }
(_, ty::Ref(_, inner_ty, _), BindingAnnotation::REF) (_, ty::Ref(_, inner_ty, _), BindingMode::REF)
if self.can_eq(self.param_env, expected, *inner_ty) => if self.can_eq(self.param_env, expected, *inner_ty) =>
{ {
err.span_suggestion_verbose( err.span_suggestion_verbose(
@ -881,7 +879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let PatKind::Ref(the_ref, _) = i.kind if let PatKind::Ref(the_ref, _) = i.kind
&& let PatKind::Binding(mt, _, ident, _) = the_ref.kind && let PatKind::Binding(mt, _, ident, _) = the_ref.kind
{ {
let BindingAnnotation(_, mtblty) = mt; let BindingMode(_, mtblty) = mt;
err.span_suggestion_verbose( err.span_suggestion_verbose(
i.span, i.span,
format!("consider removing `&{mutability}` from the pattern"), format!("consider removing `&{mutability}` from the pattern"),

View file

@ -229,8 +229,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
else { else {
bug!(); bug!();
}; };
let hir::PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), _, _, _) = let hir::PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), _, _, _) = pat.kind
pat.kind
else { else {
// Complex pattern, skip the non-upvar local. // Complex pattern, skip the non-upvar local.
continue; continue;

View file

@ -1056,7 +1056,7 @@ impl UnusedParens {
avoid_mut: bool, avoid_mut: bool,
keep_space: (bool, bool), keep_space: (bool, bool),
) { ) {
use ast::{BindingAnnotation, PatKind}; use ast::{BindingMode, PatKind};
if let PatKind::Paren(inner) = &value.kind { if let PatKind::Paren(inner) = &value.kind {
match inner.kind { match inner.kind {
@ -1068,7 +1068,7 @@ impl UnusedParens {
// Avoid `p0 | .. | pn` if we should. // Avoid `p0 | .. | pn` if we should.
PatKind::Or(..) if avoid_or => return, PatKind::Or(..) if avoid_or => return,
// Avoid `mut x` and `mut x @ p` if we should: // 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; return;
} }
// Otherwise proceed with linting. // Otherwise proceed with linting.

View file

@ -18,8 +18,7 @@ use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, Into
use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
use rustc_hir::{ use rustc_hir::{
self as hir, BindingAnnotation, ByRef, CoroutineDesugaring, CoroutineKind, HirId, self as hir, BindingMode, ByRef, CoroutineDesugaring, CoroutineKind, HirId, ImplicitSelfKind,
ImplicitSelfKind,
}; };
use rustc_session::Session; use rustc_session::Session;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
@ -930,7 +929,7 @@ pub enum LocalKind {
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub struct VarBindingForm<'tcx> { pub struct VarBindingForm<'tcx> {
/// Is variable bound via `x`, `mut x`, `ref x`, `ref mut x`, `mut ref x`, or `mut ref mut x`? /// 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, /// If an explicit type was provided for this variable binding,
/// this holds the source Span of that type. /// this holds the source Span of that type.
/// ///
@ -1155,7 +1154,7 @@ impl<'tcx> LocalDecl<'tcx> {
self.local_info(), self.local_info(),
LocalInfo::User( LocalInfo::User(
BindingForm::Var(VarBindingForm { BindingForm::Var(VarBindingForm {
binding_mode: BindingAnnotation(ByRef::No, _), binding_mode: BindingMode(ByRef::No, _),
opt_ty_info: _, opt_ty_info: _,
opt_match_place: _, opt_match_place: _,
pat_span: _, pat_span: _,
@ -1172,7 +1171,7 @@ impl<'tcx> LocalDecl<'tcx> {
self.local_info(), self.local_info(),
LocalInfo::User( LocalInfo::User(
BindingForm::Var(VarBindingForm { BindingForm::Var(VarBindingForm {
binding_mode: BindingAnnotation(ByRef::No, _), binding_mode: BindingMode(ByRef::No, _),
opt_ty_info: _, opt_ty_info: _,
opt_match_place: _, opt_match_place: _,
pat_span: _, pat_span: _,

View file

@ -12,7 +12,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; 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::newtype_index;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::middle::region; use rustc_middle::middle::region;
@ -603,10 +603,7 @@ impl<'tcx> Pat<'tcx> {
pub fn simple_ident(&self) -> Option<Symbol> { pub fn simple_ident(&self) -> Option<Symbol> {
match self.kind { match self.kind {
PatKind::Binding { PatKind::Binding {
name, name, mode: BindingMode(ByRef::No, _), subpattern: None, ..
mode: BindingAnnotation(ByRef::No, _),
subpattern: None,
..
} => Some(name), } => Some(name),
_ => None, _ => None,
} }
@ -730,7 +727,7 @@ pub enum PatKind<'tcx> {
Binding { Binding {
name: Symbol, name: Symbol,
#[type_visitable(ignore)] #[type_visitable(ignore)]
mode: BindingAnnotation, mode: BindingMode,
#[type_visitable(ignore)] #[type_visitable(ignore)]
var: LocalVarId, var: LocalVarId,
ty: Ty<'tcx>, ty: Ty<'tcx>,

View file

@ -17,7 +17,7 @@ use rustc_hir::{
def::{DefKind, Res}, def::{DefKind, Res},
def_id::{DefId, LocalDefId, LocalDefIdMap}, def_id::{DefId, LocalDefId, LocalDefIdMap},
hir_id::OwnerId, hir_id::OwnerId,
BindingAnnotation, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability, BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability,
}; };
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_macros::HashStable; use rustc_macros::HashStable;
@ -78,8 +78,8 @@ pub struct TypeckResults<'tcx> {
adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>, adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,
/// Stores the actual binding mode for all instances of [`BindingAnnotation`]. /// Stores the actual binding mode for all instances of [`BindingMode`].
pat_binding_modes: ItemLocalMap<BindingAnnotation>, pat_binding_modes: ItemLocalMap<BindingMode>,
/// Stores the types which were implicitly dereferenced in pattern binding modes /// Stores the types which were implicitly dereferenced in pattern binding modes
/// for later usage in THIR lowering. For example, /// 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, _)))) matches!(self.type_dependent_defs().get(expr.hir_id), Some(Ok((DefKind::AssocFn, _))))
} }
pub fn extract_binding_mode( pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option<BindingMode> {
&self,
s: &Session,
id: HirId,
sp: Span,
) -> Option<BindingAnnotation> {
self.pat_binding_modes().get(id).copied().or_else(|| { self.pat_binding_modes().get(id).copied().or_else(|| {
s.dcx().span_bug(sp, "missing binding mode"); 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 } 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 } 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; let mut has_ref_mut = false;
pat.walk(|pat| { pat.walk(|pat| {
if let hir::PatKind::Binding(_, id, _, _) = pat.kind 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) self.pat_binding_modes().get(id)
{ {
has_ref_mut = true; has_ref_mut = true;

View file

@ -14,7 +14,7 @@ use rustc_data_structures::{
fx::{FxHashSet, FxIndexMap, FxIndexSet}, fx::{FxHashSet, FxIndexMap, FxIndexSet},
stack::ensure_sufficient_stack, stack::ensure_sufficient_stack,
}; };
use rustc_hir::{BindingAnnotation, ByRef}; use rustc_hir::{BindingMode, ByRef};
use rustc_middle::middle::region; use rustc_middle::middle::region;
use rustc_middle::mir::{self, *}; use rustc_middle::mir::{self, *};
use rustc_middle::thir::{self, *}; use rustc_middle::thir::{self, *};
@ -621,12 +621,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
) -> BlockAnd<()> { ) -> BlockAnd<()> {
match irrefutable_pat.kind { match irrefutable_pat.kind {
// Optimize the case of `let x = ...` to write directly into `x` // Optimize the case of `let x = ...` to write directly into `x`
PatKind::Binding { PatKind::Binding { mode: BindingMode(ByRef::No, _), var, subpattern: None, .. } => {
mode: BindingAnnotation(ByRef::No, _),
var,
subpattern: None,
..
} => {
let place = let place =
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true); self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
unpack!(block = self.expr_into_dest(place, block, initializer_id)); unpack!(block = self.expr_into_dest(place, block, initializer_id));
@ -652,7 +647,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
box Pat { box Pat {
kind: kind:
PatKind::Binding { PatKind::Binding {
mode: BindingAnnotation(ByRef::No, _), mode: BindingMode(ByRef::No, _),
var, var,
subpattern: None, subpattern: None,
.. ..
@ -893,7 +888,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
f: &mut impl FnMut( f: &mut impl FnMut(
&mut Self, &mut Self,
Symbol, Symbol,
BindingAnnotation, BindingMode,
LocalVarId, LocalVarId,
Span, Span,
Ty<'tcx>, Ty<'tcx>,
@ -1148,7 +1143,7 @@ struct Binding<'tcx> {
span: Span, span: Span,
source: Place<'tcx>, source: Place<'tcx>,
var_id: LocalVarId, var_id: LocalVarId,
binding_mode: BindingAnnotation, binding_mode: BindingMode,
} }
/// Indicates that the type of `source` must be a subtype of the /// 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, source_info: SourceInfo,
visibility_scope: SourceScope, visibility_scope: SourceScope,
name: Symbol, name: Symbol,
mode: BindingAnnotation, mode: BindingMode,
var_id: LocalVarId, var_id: LocalVarId,
var_ty: Ty<'tcx>, var_ty: Ty<'tcx>,
user_ty: UserTypeProjections, user_ty: UserTypeProjections,

View file

@ -9,7 +9,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; 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::bit_set::GrowableBitSet;
use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@ -931,7 +931,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Don't introduce extra copies for simple bindings // Don't introduce extra copies for simple bindings
PatKind::Binding { PatKind::Binding {
var, var,
mode: BindingAnnotation(ByRef::No, mutability), mode: BindingMode(ByRef::No, mutability),
subpattern: None, subpattern: None,
.. ..
} => { } => {
@ -941,7 +941,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let Some(kind) = param.self_kind { if let Some(kind) = param.self_kind {
LocalInfo::User(BindingForm::ImplicitSelf(kind)) LocalInfo::User(BindingForm::ImplicitSelf(kind))
} else { } else {
let binding_mode = BindingAnnotation(ByRef::No, mutability); let binding_mode = BindingMode(ByRef::No, mutability);
LocalInfo::User(BindingForm::Var(VarBindingForm { LocalInfo::User(BindingForm::Var(VarBindingForm {
binding_mode, binding_mode,
opt_ty_info: param.ty_span, opt_ty_info: param.ty_span,

View file

@ -2,7 +2,7 @@ use crate::build::ExprCategory;
use crate::errors::*; use crate::errors::*;
use rustc_errors::DiagArgValue; 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::mir::BorrowKind;
use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::visit::Visitor;
use rustc_middle::thir::*; use rustc_middle::thir::*;
@ -288,7 +288,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
visit::walk_pat(self, pat); 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 { if self.inside_adt {
let ty::Ref(_, ty, _) = ty.kind() else { let ty::Ref(_, ty, _) = ty.kind() else {
span_bug!( span_bug!(

View file

@ -15,7 +15,7 @@ use rustc_errors::{
}; };
use rustc_hir::def::*; use rustc_hir::def::*;
use rustc_hir::def_id::LocalDefId; 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::middle::limits::get_limit_size;
use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::visit::Visitor;
use rustc_middle::thir::*; use rustc_middle::thir::*;
@ -839,7 +839,7 @@ fn check_for_bindings_named_same_as_variants(
) { ) {
if let PatKind::Binding { if let PatKind::Binding {
name, name,
mode: BindingAnnotation(ByRef::No, Mutability::Not), mode: BindingMode(ByRef::No, Mutability::Not),
subpattern: None, subpattern: None,
ty, ty,
.. ..

View file

@ -29,7 +29,7 @@ use rustc_ast::token::{self, Delimiter, Lit, LitKind, Token, TokenKind};
use rustc_ast::tokenstream::AttrTokenTree; use rustc_ast::tokenstream::AttrTokenTree;
use rustc_ast::util::parser::AssocOp; use rustc_ast::util::parser::AssocOp;
use rustc_ast::{ 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, BlockCheckMode, Expr, ExprKind, GenericArg, Generics, HasTokens, Item, ItemKind, Param, Pat,
PatKind, Path, PathSegment, QSelf, Ty, TyKind, 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 { pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param {
let pat = P(Pat { let pat = P(Pat {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
kind: PatKind::Ident(BindingAnnotation::NONE, ident, None), kind: PatKind::Ident(BindingMode::NONE, ident, None),
span: ident.span, span: ident.span,
tokens: None, 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 { match &first_pat.kind {
PatKind::Ident(_, old_ident, _) => { PatKind::Ident(_, old_ident, _) => {
let path = PatKind::Path( let path = PatKind::Path(

View file

@ -2712,7 +2712,7 @@ impl<'a> Parser<'a> {
match ty { match ty {
Ok(ty) => { Ok(ty) => {
let ident = Ident::new(kw::Empty, this.prev_token.span); 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); let pat = this.mk_pat_ident(ty.span, bm, ident);
(pat, ty) (pat, ty)
} }

View file

@ -16,8 +16,8 @@ use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::token::{self, BinOpToken, Delimiter, Token}; use rustc_ast::token::{self, BinOpToken, Delimiter, Token};
use rustc_ast::{ use rustc_ast::{
self as ast, AttrVec, BindingAnnotation, ByRef, Expr, ExprKind, MacCall, Mutability, Pat, self as ast, AttrVec, BindingMode, ByRef, Expr, ExprKind, MacCall, Mutability, Pat, PatField,
PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax,
}; };
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_errors::{Applicability, Diag, PResult}; use rustc_errors::{Applicability, Diag, PResult};
@ -486,7 +486,7 @@ impl<'a> Parser<'a> {
} }
// Parse ref ident @ pat / ref mut ident @ pat // Parse ref ident @ pat / ref mut ident @ pat
let mutbl = self.parse_mutability(); 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) { } else if self.eat_keyword(kw::Box) {
self.parse_pat_box()? self.parse_pat_box()?
} else if self.check_inline_const(0) { } else if self.check_inline_const(0) {
@ -511,7 +511,7 @@ impl<'a> Parser<'a> {
// Parse `ident @ pat` // Parse `ident @ pat`
// This can give false positives and parse nullary enums, // This can give false positives and parse nullary enums,
// they are dealt with later in resolve. // 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() { } else if self.is_start_of_pat_with_path() {
// Parse pattern starting with a path // Parse pattern starting with a path
let (qself, path) = if self.eat_lt() { 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)?; let mut pat = self.parse_pat_no_top_alt(Some(Expected::Identifier), None)?;
// If we don't have `mut $ident (@ pat)?`, error. // If we don't have `mut $ident (@ pat)?`, error.
if let PatKind::Ident(BindingAnnotation(br @ ByRef::No, m @ Mutability::Not), ..) = if let PatKind::Ident(BindingMode(br @ ByRef::No, m @ Mutability::Not), ..) = &mut pat.kind
&mut pat.kind
{ {
// Don't recurse into the subpattern. // Don't recurse into the subpattern.
// `mut` on the outer binding doesn't affect the inner bindings. // `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); 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); self.psess.gated_spans.gate(sym::mut_ref, pat.span);
} }
Ok(pat.into_inner().kind) Ok(pat.into_inner().kind)
@ -792,7 +790,7 @@ impl<'a> Parser<'a> {
struct AddMut(bool); struct AddMut(bool);
impl MutVisitor for AddMut { impl MutVisitor for AddMut {
fn visit_pat(&mut self, pat: &mut P<Pat>) { 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 &mut pat.kind
{ {
self.0 = true; self.0 = true;
@ -1025,7 +1023,7 @@ impl<'a> Parser<'a> {
/// error message when parsing mistakes like `ref foo(a, b)`. /// error message when parsing mistakes like `ref foo(a, b)`.
fn parse_pat_ident( fn parse_pat_ident(
&mut self, &mut self,
binding_annotation: BindingAnnotation, binding_annotation: BindingMode,
syntax_loc: Option<PatternLocation>, syntax_loc: Option<PatternLocation>,
) -> PResult<'a, PatKind> { ) -> PResult<'a, PatKind> {
let ident = self.parse_ident_common(false)?; let ident = self.parse_ident_common(false)?;
@ -1163,7 +1161,7 @@ impl<'a> Parser<'a> {
None 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 { } else {
let pat = self.parse_pat_with_range_pat(false, None, None)?; 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)); 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() if let Some(last) = fields.iter().last()
&& last.is_shorthand && last.is_shorthand
&& let PatKind::Ident(binding, ident, None) = last.pat.kind && let PatKind::Ident(binding, ident, None) = last.pat.kind
&& binding != BindingAnnotation::NONE && binding != BindingMode::NONE
&& self.token == token::Colon && self.token == token::Colon
// We found `ref mut? ident:`, try to parse a `name,` or `name }`. // 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)) && 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()?; let fieldname = self.parse_field_name()?;
hi = self.prev_token.span; 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 fieldpat = self.mk_pat_ident(boxed_span.to(hi), ann, fieldname);
let subpat = let subpat =
if is_box { self.mk_pat(lo.to(hi), PatKind::Box(fieldpat)) } else { fieldpat }; 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)) self.mk_pat(span, PatKind::Ident(ann, ident, None))
} }

View file

@ -83,8 +83,7 @@ fn check_abi(tcx: TyCtxt<'_>, def_id: LocalDefId, abi: Abi) {
fn check_no_patterns(tcx: TyCtxt<'_>, params: &[hir::Param<'_>]) { fn check_no_patterns(tcx: TyCtxt<'_>, params: &[hir::Param<'_>]) {
for param in params { for param in params {
match param.pat.kind { match param.pat.kind {
hir::PatKind::Wild hir::PatKind::Wild | hir::PatKind::Binding(hir::BindingMode::NONE, _, _, None) => {}
| hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, _, None) => {}
_ => { _ => {
tcx.dcx().emit_err(NoPatterns { span: param.pat.span }); tcx.dcx().emit_err(NoPatterns { span: param.pat.span });
} }

View file

@ -46,7 +46,7 @@ use diagnostics::{ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
struct BindingInfo { struct BindingInfo {
span: Span, span: Span,
annotation: BindingAnnotation, annotation: BindingMode,
} }
#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[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( fn try_resolve_as_non_binding(
&mut self, &mut self,
pat_src: PatternSource, pat_src: PatternSource,
ann: BindingAnnotation, ann: BindingMode,
ident: Ident, ident: Ident,
has_sub: bool, has_sub: bool,
) -> Option<Res> { ) -> Option<Res> {
// An immutable (no `mut`) by-value (no `ref`) binding pattern without // An immutable (no `mut`) by-value (no `ref`) binding pattern without
// a sub pattern (no `@ $pat`) is syntactically ambiguous as it could // a sub pattern (no `@ $pat`) is syntactically ambiguous as it could
// also be interpreted as a path to e.g. a constant, variant, etc. // 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 ls_binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS)?;
let (res, binding) = match ls_binding { let (res, binding) = match ls_binding {

View file

@ -751,9 +751,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// Get the local name of this closure. This can be inaccurate because // Get the local name of this closure. This can be inaccurate because
// of the possibility of reassignment, but this should be good enough. // of the possibility of reassignment, but this should be good enough.
match &kind { match &kind {
hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, ident, None) => { hir::PatKind::Binding(hir::BindingMode::NONE, _, ident, None) => Some(ident.name),
Some(ident.name)
}
_ => { _ => {
err.note(msg); err.note(msg);
None None

View file

@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::intravisit::{walk_ty, Visitor};
use rustc_hir::{ use rustc_hir::{
self as hir, BindingAnnotation, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, self as hir, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node,
Pat, PatKind, Path, QPath, TyKind, UnOp, Pat, PatKind, Path, QPath, TyKind, UnOp,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -599,7 +599,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
} }
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
if let PatKind::Binding(BindingAnnotation::REF, id, name, _) = pat.kind { if let PatKind::Binding(BindingMode::REF, id, name, _) = pat.kind {
if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) { if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) {
// This binding id has been seen before. Add this pattern to the list of changes. // This binding id has been seen before. Add this pattern to the list of changes.
if let Some(prev_pat) = opt_prev_pat { if let Some(prev_pat) = opt_prev_pat {

View file

@ -5,7 +5,7 @@ use clippy_utils::ty::type_diagnostic_name;
use clippy_utils::usage::{local_used_after_expr, local_used_in}; use clippy_utils::usage::{local_used_after_expr, local_used_in};
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id}; use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety}; use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{ use rustc_middle::ty::{
@ -229,7 +229,7 @@ fn check_inputs(
&& params.iter().zip(self_arg.into_iter().chain(args)).all(|(p, arg)| { && params.iter().zip(self_arg.into_iter().chain(args)).all(|(p, arg)| {
matches!( matches!(
p.pat.kind, p.pat.kind,
PatKind::Binding(BindingAnnotation::NONE, id, _, None) PatKind::Binding(BindingMode::NONE, id, _, None)
if path_to_local_id(arg, id) if path_to_local_id(arg, id)
) )
// Only allow adjustments which change regions (i.e. re-borrowing). // Only allow adjustments which change regions (i.e. re-borrowing).

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_applicability;
use clippy_utils::{is_expn_of, path_def_id}; use clippy_utils::{is_expn_of, path_def_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind}; use rustc_hir::{BindingMode, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::{sym, ExpnId}; use rustc_span::{sym, ExpnId};
@ -114,7 +114,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>)
&& let Node::Pat(res_pat) = cx.tcx.hir_node(expr_res) && let Node::Pat(res_pat) = cx.tcx.hir_node(expr_res)
// Find id of the local we found in the block // Find id of the local we found in the block
&& let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, local_hir_id, _ident, None) = local.pat.kind
// If those two are the same hir id // If those two are the same hir id
&& res_pat.hir_id == local_hir_id && res_pat.hir_id == local_hir_id

View file

@ -94,7 +94,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<Hir
pat.walk_always(|pat| { pat.walk_always(|pat| {
// We'll just ignore mut and ref mut for simplicity sake right now // We'll just ignore mut and ref mut for simplicity sake right now
if let hir::PatKind::Binding( if let hir::PatKind::Binding(
hir::BindingAnnotation(by_ref, hir::Mutability::Not), hir::BindingMode(by_ref, hir::Mutability::Not),
value_hir_id, value_hir_id,
ident, ident,
sub_pat, sub_pat,

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
use clippy_utils::visitors::is_local_used; use clippy_utils::visitors::is_local_used;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{BindingAnnotation, Mutability}; use rustc_hir::{BindingMode, Mutability};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
}; };
let mutability = match mode { let mutability = match mode {
BindingAnnotation(_, Mutability::Mut) => "<mut> ", BindingMode(_, Mutability::Mut) => "<mut> ",
_ => "", _ => "",
}; };

View file

@ -7,7 +7,7 @@ use clippy_utils::{higher, is_res_lang_ctor, path_res, peel_blocks_with_stmt};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::Span; use rustc_span::Span;
@ -107,7 +107,7 @@ fn get_binding(pat: &Pat<'_>) -> Option<HirId> {
hir_id = None; hir_id = None;
return; return;
} }
if let BindingAnnotation::NONE = annotation { if let BindingMode::NONE = annotation {
hir_id = Some(id); hir_id = Some(id);
} }
}); });

View file

@ -2,7 +2,7 @@ use super::MUT_RANGE_BOUND;
use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::diagnostics::span_lint_and_note;
use clippy_utils::{get_enclosing_block, higher, path_to_local}; use clippy_utils::{get_enclosing_block, higher, path_to_local};
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Node, PatKind}; use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind};
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext; use rustc_lint::LateContext;
@ -41,7 +41,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option<Span>) {
fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option<HirId> { fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option<HirId> {
if let Some(hir_id) = path_to_local(bound) if let Some(hir_id) = path_to_local(bound)
&& let Node::Pat(pat) = cx.tcx.hir_node(hir_id) && let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
&& let PatKind::Binding(BindingAnnotation::MUT, ..) = pat.kind && let PatKind::Binding(BindingMode::MUT, ..) = pat.kind
{ {
return Some(hir_id); return Some(hir_id);
} }

View file

@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Mutability, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, Mutability, Node, Pat, PatKind, Stmt, StmtKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::SyntaxContext; use rustc_span::SyntaxContext;
@ -61,7 +61,7 @@ pub(super) fn check<'tcx>(
let node = cx.tcx.hir_node(hir_id); let node = cx.tcx.hir_node(hir_id);
if let Node::Pat(pat) = node if let Node::Pat(pat) = node
&& let PatKind::Binding(bind_ann, ..) = pat.kind && let PatKind::Binding(bind_ann, ..) = pat.kind
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) && !matches!(bind_ann, BindingMode(_, Mutability::Mut))
&& let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id) && let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
&& let Some(init) = parent_let_expr.init && let Some(init) = parent_let_expr.init
{ {

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet_opt;
use clippy_utils::visitors::{is_local_used, local_used_once}; use clippy_utils::visitors::{is_local_used, local_used_once};
use clippy_utils::{is_trait_method, path_to_local_id}; use clippy_utils::{is_trait_method, path_to_local_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, ExprKind, LetStmt, Node, PatKind, StmtKind}; use rustc_hir::{BindingMode, ExprKind, LetStmt, Node, PatKind, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -62,7 +62,7 @@ impl_lint_pass!(ManualHashOne => [MANUAL_HASH_ONE]);
impl LateLintPass<'_> for ManualHashOne { impl LateLintPass<'_> for ManualHashOne {
fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) { fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
// `let mut hasher = seg.build_hasher();` // `let mut hasher = seg.build_hasher();`
if let PatKind::Binding(BindingAnnotation::MUT, hasher, _, None) = local.pat.kind if let PatKind::Binding(BindingMode::MUT, hasher, _, None) = local.pat.kind
&& let Some(init) = local.init && let Some(init) = local.init
&& !init.span.from_expansion() && !init.span.from_expansion()
&& let ExprKind::MethodCall(seg, build_hasher, [], _) = init.kind && let ExprKind::MethodCall(seg, build_hasher, [], _) = init.kind

View file

@ -11,7 +11,7 @@ use rustc_ast::util::parser::PREC_POSTFIX;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath}; use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::{sym, SyntaxContext}; use rustc_span::{sym, SyntaxContext};
@ -139,7 +139,7 @@ where
} }
// `ref` and `ref mut` annotations were handled earlier. // `ref` and `ref mut` annotations were handled earlier.
let annotation = if matches!(annotation, BindingAnnotation::MUT) { let annotation = if matches!(annotation, BindingMode::MUT) {
"mut " "mut "
} else { } else {
"" ""

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability; use clippy_utils::source::snippet_with_applicability;
use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks}; use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath}; use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty; use rustc_middle::ty;
@ -67,7 +67,7 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> { fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> {
if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind
&& is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome) && is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome)
&& let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind && let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind
&& let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind && let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind
&& is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome) && is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome)
&& let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind && let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind

View file

@ -8,7 +8,7 @@ use clippy_utils::{
}; };
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::LangItem::OptionNone; use rustc_hir::LangItem::OptionNone;
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatKind, Path, QPath}; use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatKind, Path, QPath};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::sym; use rustc_span::sym;
@ -178,7 +178,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
}, },
)), )),
) => { ) => {
return !matches!(annot, BindingAnnotation(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name; return !matches!(annot, BindingMode(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name;
}, },
// Example: `Custom::TypeA => Custom::TypeB`, or `None => None` // Example: `Custom::TypeA => Custom::TypeB`, or `None => None`
(PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => { (PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => {

View file

@ -4,7 +4,7 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, peel_mid_ty_re
use clippy_utils::{is_lint_allowed, is_unit_expr, is_wild, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs}; use clippy_utils::{is_lint_allowed, is_unit_expr, is_wild, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs};
use core::cmp::max; use core::cmp::max;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind}; use rustc_hir::{Arm, BindingMode, Block, Expr, ExprKind, Pat, PatKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
@ -166,7 +166,7 @@ fn collect_pat_paths<'a>(acc: &mut Vec<Ty<'a>>, cx: &LateContext<'a>, pat: &Pat<
let p_ty = cx.typeck_results().pat_ty(p); let p_ty = cx.typeck_results().pat_ty(p);
collect_pat_paths(acc, cx, p, p_ty); collect_pat_paths(acc, cx, p, p_ty);
}), }),
PatKind::TupleStruct(..) | PatKind::Binding(BindingAnnotation::NONE, .., None) | PatKind::Path(_) => { PatKind::TupleStruct(..) | PatKind::Binding(BindingMode::NONE, .., None) | PatKind::Path(_) => {
acc.push(ty); acc.push(ty);
}, },
_ => {}, _ => {},

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_context; use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::is_copy; use clippy_utils::ty::is_copy;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath}; use rustc_hir::{BindingMode, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::print::with_forced_trimmed_paths;
@ -69,7 +69,7 @@ pub(super) fn check(
_ => false, _ => false,
}, },
// local binding capturing a reference // local binding capturing a reference
Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..)) => { Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..)) => {
return; return;
}, },
_ => false, _ => false,

View file

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use clippy_utils::ty::implements_trait; use clippy_utils::ty::implements_trait;
use rustc_ast::{BindingAnnotation, Mutability}; use rustc_ast::{BindingMode, Mutability};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint::LateContext; use rustc_lint::LateContext;
@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(
span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| { span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| {
let (applicability, pat) = if let Some(id) = path_to_local(recv) let (applicability, pat) = if let Some(id) = path_to_local(recv)
&& let hir::Node::Pat(pat) = cx.tcx.hir_node(id) && let hir::Node::Pat(pat) = cx.tcx.hir_node(id)
&& let hir::PatKind::Binding(BindingAnnotation(_, Mutability::Not), _, ident, _) = pat.kind && let hir::PatKind::Binding(BindingMode(_, Mutability::Not), _, ident, _) = pat.kind
{ {
(Applicability::Unspecified, Some((pat.span, ident))) (Applicability::Unspecified, Some((pat.span, ident)))
} else { } else {

View file

@ -6,7 +6,7 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_sugg, span_lint_an
use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{pat_is_wild, sugg}; use clippy_utils::{pat_is_wild, sugg};
use rustc_hir::{BindingAnnotation, Body, BorrowKind, ByRef, Expr, ExprKind, Mutability, Pat, PatKind}; use rustc_hir::{BindingMode, Body, BorrowKind, ByRef, Expr, ExprKind, Mutability, Pat, PatKind};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::ty; use rustc_middle::ty;
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};

View file

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet_opt; use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{implements_trait, is_copy}; use clippy_utils::ty::{implements_trait, is_copy};
use rustc_ast::BindingAnnotation; use rustc_ast::BindingMode;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Body, Expr, ExprKind, HirId, HirIdSet, PatKind}; use rustc_hir::{Body, Expr, ExprKind, HirId, HirIdSet, PatKind};
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
@ -89,7 +89,7 @@ pub(super) fn check<'tcx>(
} }
match it.kind { match it.kind {
PatKind::Binding(BindingAnnotation(_, Mutability::Mut), _, _, _) PatKind::Binding(BindingMode(_, Mutability::Mut), _, _, _)
| PatKind::Ref(_, Mutability::Mut) => { | PatKind::Ref(_, Mutability::Mut) => {
to_be_discarded = true; to_be_discarded = true;
false false

View file

@ -3,7 +3,7 @@ use clippy_utils::source::snippet;
use clippy_utils::{is_trait_method, path_to_local}; use clippy_utils::{is_trait_method, path_to_local};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{BindingAnnotation, Node, PatKind}; use rustc_hir::{BindingMode, Node, PatKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::sym; use rustc_span::sym;
@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
if let Some(id) = path_to_local(recv) if let Some(id) = path_to_local(recv)
&& let Node::Pat(pat) = cx.tcx.hir_node(id) && let Node::Pat(pat) = cx.tcx.hir_node(id)
&& let PatKind::Binding(ann, _, _, _) = pat.kind && let PatKind::Binding(ann, _, _, _) = pat.kind
&& ann != BindingAnnotation::MUT && ann != BindingMode::MUT
{ {
application = Applicability::Unspecified; application = Applicability::Unspecified;
diag.span_help( diag.span_help(

View file

@ -51,13 +51,13 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
let closure_expr = peel_blocks(closure_body.value); let closure_expr = peel_blocks(closure_body.value);
match closure_body.params[0].pat.kind { match closure_body.params[0].pat.kind {
hir::PatKind::Ref(inner, Mutability::Not) => { hir::PatKind::Ref(inner, Mutability::Not) => {
if let hir::PatKind::Binding(hir::BindingAnnotation::NONE, .., name, None) = inner.kind { if let hir::PatKind::Binding(hir::BindingMode::NONE, .., name, None) = inner.kind {
if ident_eq(name, closure_expr) { if ident_eq(name, closure_expr) {
lint_explicit_closure(cx, e.span, recv.span, true, msrv); lint_explicit_closure(cx, e.span, recv.span, true, msrv);
} }
} }
}, },
hir::PatKind::Binding(hir::BindingAnnotation::NONE, .., name, None) => { hir::PatKind::Binding(hir::BindingMode::NONE, .., name, None) => {
match closure_expr.kind { match closure_expr.kind {
hir::ExprKind::Unary(hir::UnOp::Deref, inner) => { hir::ExprKind::Unary(hir::UnOp::Deref, inner) => {
if ident_eq(name, inner) { if ident_eq(name, inner) {

View file

@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind, BindingMode, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind,
}; };
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
@ -86,7 +86,7 @@ pub(super) fn check<'tcx>(
} }
}, },
Node::LetStmt(l) => { Node::LetStmt(l) => {
if let PatKind::Binding(BindingAnnotation::NONE | BindingAnnotation::MUT, id, _, None) = l.pat.kind if let PatKind::Binding(BindingMode::NONE | BindingMode::MUT, id, _, None) = l.pat.kind
&& let ty = cx.typeck_results().expr_ty(collect_expr) && let ty = cx.typeck_results().expr_ty(collect_expr)
&& [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList] && [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList]
.into_iter() .into_iter()

View file

@ -8,7 +8,7 @@ use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths}
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind, BindingMode, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind,
}; };
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty; use rustc_middle::ty;
@ -129,7 +129,7 @@ fn check_manual_split_once_indirect(
let ctxt = expr.span.ctxt(); let ctxt = expr.span.ctxt();
let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); let mut parents = cx.tcx.hir().parent_iter(expr.hir_id);
if let (_, Node::LetStmt(local)) = parents.next()? if let (_, Node::LetStmt(local)) = parents.next()?
&& let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind && let PatKind::Binding(BindingMode::MUT, iter_binding_id, iter_ident, None) = local.pat.kind
&& let (iter_stmt_id, Node::Stmt(_)) = parents.next()? && let (iter_stmt_id, Node::Stmt(_)) = parents.next()?
&& let (_, Node::Block(enclosing_block)) = parents.next()? && let (_, Node::Block(enclosing_block)) = parents.next()?
&& let mut stmts = enclosing_block && let mut stmts = enclosing_block
@ -200,7 +200,7 @@ fn indirect_usage<'tcx>(
) -> Option<IndirectUsage<'tcx>> { ) -> Option<IndirectUsage<'tcx>> {
if let StmtKind::Let(&LetStmt { if let StmtKind::Let(&LetStmt {
pat: Pat { pat: Pat {
kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None), kind: PatKind::Binding(BindingMode::NONE, _, ident, None),
.. ..
}, },
init: Some(init_expr), init: Some(init_expr),

View file

@ -9,7 +9,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{ use rustc_hir::{
BinOpKind, BindingAnnotation, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind, BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) { if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) {
return; return;
} }
if let PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..) = arg.pat.kind { if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind {
span_lint( span_lint(
cx, cx,
TOPLEVEL_REF_ARG, TOPLEVEL_REF_ARG,
@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
if !in_external_macro(cx.tcx.sess, stmt.span) if !in_external_macro(cx.tcx.sess, stmt.span)
&& let StmtKind::Let(local) = stmt.kind && let StmtKind::Let(local) = stmt.kind
&& let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind && let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind
&& let Some(init) = local.init && let Some(init) = local.init
// Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue. // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
&& is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id) && is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id)

View file

@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_ast::ast::{BindingAnnotation, ByRef, Lifetime, Mutability, Param, PatKind, Path, TyKind}; use rustc_ast::ast::{BindingMode, ByRef, Lifetime, Mutability, Param, PatKind, Path, TyKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -117,13 +117,13 @@ impl EarlyLintPass for NeedlessArbitrarySelfType {
match &p.ty.kind { match &p.ty.kind {
TyKind::Path(None, path) => { TyKind::Path(None, path) => {
if let PatKind::Ident(BindingAnnotation(ByRef::No, mutbl), _, _) = p.pat.kind { if let PatKind::Ident(BindingMode(ByRef::No, mutbl), _, _) = p.pat.kind {
check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl); check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl);
} }
}, },
TyKind::Ref(lifetime, mut_ty) => { TyKind::Ref(lifetime, mut_ty) => {
if let TyKind::Path(None, path) = &mut_ty.ty.kind if let TyKind::Path(None, path) = &mut_ty.ty.kind
&& let PatKind::Ident(BindingAnnotation::NONE, _, _) = p.pat.kind && let PatKind::Ident(BindingMode::NONE, _, _) = p.pat.kind
{ {
check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl); check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl);
} }

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, Mutability, Node, Pat, PatKind}; use rustc_hir::{BindingMode, Mutability, Node, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef {
match pat.kind { match pat.kind {
// Check sub_pat got a `ref` keyword (excluding `ref mut`). // Check sub_pat got a `ref` keyword (excluding `ref mut`).
PatKind::Binding(BindingAnnotation::REF, _, ident, None) => { PatKind::Binding(BindingMode::REF, _, ident, None) => {
span_lint_and_then( span_lint_and_then(
cx, cx,
NEEDLESS_BORROWED_REFERENCE, NEEDLESS_BORROWED_REFERENCE,
@ -128,7 +128,7 @@ fn check_subpatterns<'tcx>(
for subpattern in subpatterns { for subpattern in subpatterns {
match subpattern.kind { match subpattern.kind {
PatKind::Binding(BindingAnnotation::REF, _, ident, None) => { PatKind::Binding(BindingMode::REF, _, ident, None) => {
// `ref ident` // `ref ident`
// ^^^^ // ^^^^
let span = subpattern.span.until(ident.span); let span = subpattern.span.until(ident.span);

View file

@ -6,7 +6,7 @@ use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_loca
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::{Applicability, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, BindingMode, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt,
StmtKind, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -369,7 +369,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
init: None, init: None,
pat: pat:
&Pat { &Pat {
kind: PatKind::Binding(BindingAnnotation::NONE, binding_id, _, None), kind: PatKind::Binding(BindingMode::NONE, binding_id, _, None),
.. ..
}, },
source: LocalSource::Normal, source: LocalSource::Normal,

View file

@ -9,7 +9,7 @@ use rustc_ast::ast::Attribute;
use rustc_errors::{Applicability, Diag}; use rustc_errors::{Applicability, Diag};
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind, BindingMode, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind,
QPath, TyKind, QPath, TyKind,
}; };
use rustc_hir_typeck::expr_use_visitor as euv; use rustc_hir_typeck::expr_use_visitor as euv;
@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
}) })
&& !implements_borrow_trait && !implements_borrow_trait
&& !all_borrowable_trait && !all_borrowable_trait
&& let PatKind::Binding(BindingAnnotation(_, Mutability::Not), canonical_id, ..) = arg.pat.kind && let PatKind::Binding(BindingMode(_, Mutability::Not), canonical_id, ..) = arg.pat.kind
&& !moved_vars.contains(&canonical_id) && !moved_vars.contains(&canonical_id)
{ {
// Dereference suggestion // Dereference suggestion

View file

@ -7,7 +7,7 @@ use clippy_utils::{
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
use rustc_hir::{Arm, BindingAnnotation, Expr, ExprKind, MatchSource, Mutability, Pat, PatKind, Path, QPath, UnOp}; use rustc_hir::{Arm, BindingMode, Expr, ExprKind, MatchSource, Mutability, Pat, PatKind, Path, QPath, UnOp};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::SyntaxContext; use rustc_span::SyntaxContext;
@ -129,7 +129,7 @@ fn try_get_option_occurrence<'tcx>(
.filter_map(|(id, &c)| none_captures.get(id).map(|&c2| (c, c2))) .filter_map(|(id, &c)| none_captures.get(id).map(|&c2| (c, c2)))
.all(|(x, y)| x.is_imm_ref() && y.is_imm_ref()) .all(|(x, y)| x.is_imm_ref() && y.is_imm_ref())
{ {
let capture_mut = if bind_annotation == BindingAnnotation::MUT { let capture_mut = if bind_annotation == BindingMode::MUT {
"mut " "mut "
} else { } else {
"" ""
@ -149,8 +149,8 @@ fn try_get_option_occurrence<'tcx>(
(mutb == Mutability::Not, mutb == Mutability::Mut) (mutb == Mutability::Not, mutb == Mutability::Mut)
}, },
_ => ( _ => (
bind_annotation == BindingAnnotation::REF, bind_annotation == BindingMode::REF,
bind_annotation == BindingAnnotation::REF_MUT, bind_annotation == BindingMode::REF_MUT,
), ),
}; };

View file

@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{BindingAnnotation, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; use rustc_hir::{BindingMode, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
@ -221,7 +221,7 @@ impl<'tcx> PassByRefOrValue {
// if function has a body and parameter is annotated with mut, ignore // if function has a body and parameter is annotated with mut, ignore
if let Some(param) = fn_body.and_then(|body| body.params.get(index)) { if let Some(param) = fn_body.and_then(|body| body.params.get(index)) {
match param.pat.kind { match param.pat.kind {
PatKind::Binding(BindingAnnotation::NONE, _, _, _) => {}, PatKind::Binding(BindingMode::NONE, _, _, _) => {},
_ => continue, _ => continue,
} }
} }

View file

@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId;
use rustc_hir::hir_id::{HirId, HirIdMap}; use rustc_hir::hir_id::{HirId, HirIdMap};
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{ use rustc_hir::{
self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, self as hir, AnonConst, BinOpKind, BindingMode, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg,
ImplItemKind, ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, ImplItemKind, ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind,
TyKind, Unsafety, TyKind, Unsafety,
}; };
@ -606,7 +606,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
Some((Node::Stmt(_), _)) => (), Some((Node::Stmt(_), _)) => (),
Some((Node::LetStmt(l), _)) => { Some((Node::LetStmt(l), _)) => {
// Only trace simple bindings. e.g `let x = y;` // Only trace simple bindings. e.g `let x = y;`
if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind { if let PatKind::Binding(BindingMode::NONE, id, _, None) = l.pat.kind {
self.bindings.insert(id, args_idx); self.bindings.insert(id, args_idx);
} else { } else {
set_skip_flag(); set_skip_flag();
@ -687,7 +687,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
.filter_map(|(i, arg)| { .filter_map(|(i, arg)| {
let param = &body.params[arg.idx]; let param = &body.params[arg.idx];
match param.pat.kind { match param.pat.kind {
PatKind::Binding(BindingAnnotation::NONE, id, _, None) PatKind::Binding(BindingMode::NONE, id, _, None)
if !is_lint_allowed(cx, PTR_ARG, param.hir_id) => if !is_lint_allowed(cx, PTR_ARG, param.hir_id) =>
{ {
Some((id, i)) Some((id, i))

View file

@ -14,7 +14,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Body, ByRef, Expr, ExprKind, LetStmt, Mutability, Node, PatKind, PathSegment, QPath, BindingMode, Block, Body, ByRef, Expr, ExprKind, LetStmt, Mutability, Node, PatKind, PathSegment, QPath,
Stmt, StmtKind, Stmt, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -283,7 +283,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
&& !is_else_clause(cx.tcx, expr) && !is_else_clause(cx.tcx, expr)
&& let PatKind::TupleStruct(ref path1, [field], ddpos) = let_pat.kind && let PatKind::TupleStruct(ref path1, [field], ddpos) = let_pat.kind
&& ddpos.as_opt_usize().is_none() && ddpos.as_opt_usize().is_none()
&& let PatKind::Binding(BindingAnnotation(by_ref, _), bind_id, ident, None) = field.kind && let PatKind::Binding(BindingMode(by_ref, _), bind_id, ident, None) = field.kind
&& let caller_ty = cx.typeck_results().expr_ty(let_expr) && let caller_ty = cx.typeck_results().expr_ty(let_expr)
&& let if_block = IfBlockType::IfLet( && let if_block = IfBlockType::IfLet(
cx.qpath_res(path1, let_pat.hir_id), cx.qpath_res(path1, let_pat.hir_id),

View file

@ -3,7 +3,7 @@ use clippy_utils::is_from_proc_macro;
use clippy_utils::ty::needs_ordered_drop; use clippy_utils::ty::needs_ordered_drop;
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath}; use rustc_hir::{BindingMode, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath};
use rustc_hir_typeck::expr_use_visitor::PlaceBase; use rustc_hir_typeck::expr_use_visitor::PlaceBase;
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if !local.span.is_desugaring(DesugaringKind::Async) if !local.span.is_desugaring(DesugaringKind::Async)
// the pattern is a single by-value binding // the pattern is a single by-value binding
&& let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind && let PatKind::Binding(BindingMode(ByRef::No, mutability), _, ident, None) = local.pat.kind
// the binding is not type-ascribed // the binding is not type-ascribed
&& local.ty.is_none() && local.ty.is_none()
// the expression is a resolved path // the expression is a resolved path
@ -109,7 +109,7 @@ fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_v
} }
/// Find the annotation of a binding introduced by a pattern, or `None` if it's not introduced. /// Find the annotation of a binding introduced by a pattern, or `None` if it's not introduced.
fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingAnnotation> { fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingMode> {
let mut ret = None; let mut ret = None;
pat.each_binding_or_first(&mut |annotation, _, _, ident| { pat.each_binding_or_first(&mut |annotation, _, _, ident| {

View file

@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::diagnostics::span_lint_and_help;
use rustc_ast::ast::{BindingAnnotation, Pat, PatKind}; use rustc_ast::ast::{BindingMode, Pat, PatKind};
use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -28,7 +28,7 @@ declare_lint_pass!(RefPatterns => [REF_PATTERNS]);
impl EarlyLintPass for RefPatterns { impl EarlyLintPass for RefPatterns {
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) { fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
if let PatKind::Ident(BindingAnnotation::REF, _, _) = pat.kind if let PatKind::Ident(BindingMode::REF, _, _) = pat.kind
&& !pat.span.from_expansion() && !pat.span.from_expansion()
{ {
span_lint_and_help( span_lint_and_help(

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
use clippy_utils::{is_from_proc_macro, path_to_local_id}; use clippy_utils::{is_from_proc_macro, path_to_local_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind}; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if let Some(init_expr) = local.init if let Some(init_expr) = local.init
&& let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind && let PatKind::Binding(BindingMode::MUT, id, _, None) = local.pat.kind
&& !in_external_macro(cx.sess(), local.span) && !in_external_macro(cx.sess(), local.span)
&& let Some(init) = get_vec_init_kind(cx, init_expr) && let Some(init) = get_vec_init_kind(cx, init_expr)
&& !matches!( && !matches!(

View file

@ -7,7 +7,7 @@ use clippy_utils::{
}; };
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, Visitor}; use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, Visitor};
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, Stmt, StmtKind}; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, PatKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for SlowVectorInit {
// Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)`
// or `Vec::new()` // or `Vec::new()`
if let StmtKind::Let(local) = stmt.kind if let StmtKind::Let(local) = stmt.kind
&& let PatKind::Binding(BindingAnnotation::MUT, local_id, _, None) = local.pat.kind && let PatKind::Binding(BindingMode::MUT, local_id, _, None) = local.pat.kind
&& let Some(init) = local.init && let Some(init) = local.init
&& let Some(size_expr) = Self::as_vec_initializer(cx, init) && let Some(size_expr) = Self::as_vec_initializer(cx, init)
{ {

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use clippy_utils::ty::is_copy; use clippy_utils::ty::is_copy;
use clippy_utils::{get_parent_expr, path_to_local}; use clippy_utils::{get_parent_expr, path_to_local};
use rustc_hir::{BindingAnnotation, Expr, ExprKind, Node, PatKind, UnOp}; use rustc_hir::{BindingMode, Expr, ExprKind, Node, PatKind, UnOp};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -84,7 +84,7 @@ fn is_mutable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
if let Some(hir_id) = path_to_local(expr) if let Some(hir_id) = path_to_local(expr)
&& let Node::Pat(pat) = cx.tcx.hir_node(hir_id) && let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
{ {
matches!(pat.kind, PatKind::Binding(BindingAnnotation::MUT, ..)) matches!(pat.kind, PatKind::Binding(BindingMode::MUT, ..))
} else { } else {
true true
} }

View file

@ -137,12 +137,12 @@ fn insert_necessary_parens(pat: &mut P<Pat>) {
struct Visitor; struct Visitor;
impl MutVisitor for Visitor { impl MutVisitor for Visitor {
fn visit_pat(&mut self, pat: &mut P<Pat>) { fn visit_pat(&mut self, pat: &mut P<Pat>) {
use ast::BindingAnnotation; use ast::BindingMode;
noop_visit_pat(pat, self); noop_visit_pat(pat, self);
let target = match &mut pat.kind { let target = match &mut pat.kind {
// `i @ a | b`, `box a | b`, and `& mut? a | b`. // `i @ a | b`, `box a | b`, and `& mut? a | b`.
Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p,
Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingAnnotation::MUT, ..)) => p, // `&(mut x)` Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingMode::MUT, ..)) => p, // `&(mut x)`
_ => return, _ => return,
}; };
target.kind = Paren(P(take_pat(target))); target.kind = Paren(P(take_pat(target)));

View file

@ -5,7 +5,7 @@ use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts};
use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, path_to_local}; use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, path_to_local};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; use rustc_hir::{BindingMode, Expr, ExprKind, HirId, MatchSource, Node, PatKind};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::Obligation; use rustc_infer::traits::Obligation;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -282,7 +282,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
if let Some(id) = path_to_local(recv) if let Some(id) = path_to_local(recv)
&& let Node::Pat(pat) = cx.tcx.hir_node(id) && let Node::Pat(pat) = cx.tcx.hir_node(id)
&& let PatKind::Binding(ann, ..) = pat.kind && let PatKind::Binding(ann, ..) = pat.kind
&& ann != BindingAnnotation::MUT && ann != BindingMode::MUT
{ {
// Do not remove .into_iter() applied to a non-mutable local variable used in // Do not remove .into_iter() applied to a non-mutable local variable used in
// a larger expression context as it would differ in mutability. // a larger expression context as it would differ in mutability.

View file

@ -7,7 +7,7 @@ use rustc_ast::LitIntType;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{ use rustc_hir::{
ArrayLen, BindingAnnotation, CaptureBy, Closure, ClosureKind, CoroutineKind, ExprKind, FnRetTy, HirId, Lit, ArrayLen, BindingMode, CaptureBy, Closure, ClosureKind, CoroutineKind, ExprKind, FnRetTy, HirId, Lit,
PatKind, QPath, StmtKind, TyKind, PatKind, QPath, StmtKind, TyKind,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
@ -645,14 +645,14 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
bind!(self, name); bind!(self, name);
opt_bind!(self, sub); opt_bind!(self, sub);
let ann = match ann { let ann = match ann {
BindingAnnotation::NONE => "NONE", BindingMode::NONE => "NONE",
BindingAnnotation::REF => "REF", BindingMode::REF => "REF",
BindingAnnotation::MUT => "MUT", BindingMode::MUT => "MUT",
BindingAnnotation::REF_MUT => "REF_MUT", BindingMode::REF_MUT => "REF_MUT",
BindingAnnotation::MUT_REF => "MUT_REF", BindingMode::MUT_REF => "MUT_REF",
BindingAnnotation::MUT_REF_MUT => "MUT_REF_MUT", BindingMode::MUT_REF_MUT => "MUT_REF_MUT",
}; };
kind!("Binding(BindingAnnotation::{ann}, _, {name}, {sub})"); kind!("Binding(BindingMode::{ann}, _, {name}, {sub})");
self.ident(name); self.ident(name);
sub.if_some(|p| self.pat(p)); sub.if_some(|p| self.pat(p));
}, },

View file

@ -7,7 +7,7 @@ use core::ops::ControlFlow;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, BindingMode, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if let Some(init_expr) = local.init if let Some(init_expr) = local.init
&& let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind && let PatKind::Binding(BindingMode::MUT, id, name, None) = local.pat.kind
&& !in_external_macro(cx.sess(), local.span) && !in_external_macro(cx.sess(), local.span)
&& let Some(init) = get_vec_init_kind(cx, init_expr) && let Some(init) = get_vec_init_kind(cx, init_expr)
&& !matches!(init, VecInitKind::WithExprCapacity(_)) && !matches!(init, VecInitKind::WithExprCapacity(_))

View file

@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHasher;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::MatchSource::TryDesugar; use rustc_hir::MatchSource::TryDesugar;
use rustc_hir::{ use rustc_hir::{
ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, ArrayLen, BinOpKind, BindingMode, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg,
GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path,
PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding,
}; };
@ -947,7 +947,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
pub fn hash_pat(&mut self, pat: &Pat<'_>) { pub fn hash_pat(&mut self, pat: &Pat<'_>) {
std::mem::discriminant(&pat.kind).hash(&mut self.s); std::mem::discriminant(&pat.kind).hash(&mut self.s);
match pat.kind { match pat.kind {
PatKind::Binding(BindingAnnotation(by_ref, mutability), _, _, pat) => { PatKind::Binding(BindingMode(by_ref, mutability), _, _, pat) => {
std::mem::discriminant(&by_ref).hash(&mut self.s); std::mem::discriminant(&by_ref).hash(&mut self.s);
std::mem::discriminant(&mutability).hash(&mut self.s); std::mem::discriminant(&mutability).hash(&mut self.s);
if let Some(pat) = pat { if let Some(pat) = pat {

View file

@ -99,7 +99,7 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet};
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
use rustc_hir::{ use rustc_hir::{
self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, ByRef, Closure, Destination, Expr, self as hir, def, Arm, ArrayLen, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, Destination, Expr,
ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item,
ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment,
PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp,
@ -184,7 +184,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr
/// canonical binding `HirId`. /// canonical binding `HirId`.
pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> {
if let Node::Pat(pat) = cx.tcx.hir_node(hir_id) if let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
&& matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) && matches!(pat.kind, PatKind::Binding(BindingMode::NONE, ..))
&& let Node::LetStmt(local) = cx.tcx.parent_hir_node(hir_id) && let Node::LetStmt(local) = cx.tcx.parent_hir_node(hir_id)
{ {
return local.init; return local.init;

View file

@ -5,7 +5,7 @@ if let StmtKind::Local(local) = stmt.kind
&& match_qpath(qpath, &["char"]) && match_qpath(qpath, &["char"])
&& let ExprKind::Lit(ref lit) = expr.kind && let ExprKind::Lit(ref lit) = expr.kind
&& let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node && let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
&& name.as_str() == "x" && name.as_str() == "x"
{ {
// report your lint here // report your lint here

View file

@ -4,13 +4,13 @@ if let ExprKind::Block(block, None) = expr.kind
&& let Some(init) = local.init && let Some(init) = local.init
&& let ExprKind::Lit(ref lit) = init.kind && let ExprKind::Lit(ref lit) = init.kind
&& let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node && let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
&& name.as_str() == "x" && name.as_str() == "x"
&& let StmtKind::Local(local1) = block.stmts[1].kind && let StmtKind::Local(local1) = block.stmts[1].kind
&& let Some(init1) = local1.init && let Some(init1) = local1.init
&& let ExprKind::Lit(ref lit1) = init1.kind && let ExprKind::Lit(ref lit1) = init1.kind
&& let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node && let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node
&& let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name1, None) = local1.pat.kind
&& name1.as_str() == "_t" && name1.as_str() == "_t"
&& let StmtKind::Semi(e) = block.stmts[2].kind && let StmtKind::Semi(e) = block.stmts[2].kind
&& let ExprKind::Unary(UnOp::Neg, inner) = e.kind && let ExprKind::Unary(UnOp::Neg, inner) = e.kind
@ -28,7 +28,7 @@ if let ExprKind::Block(block, None) = expr.kind
&& let ExprKind::Path(ref qpath) = func.kind && let ExprKind::Path(ref qpath) = func.kind
&& match_qpath(qpath, &["String", "new"]) && match_qpath(qpath, &["String", "new"])
&& args.is_empty() && args.is_empty()
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
&& name.as_str() == "expr" && name.as_str() == "expr"
&& let Some(trailing_expr) = block.expr && let Some(trailing_expr) = block.expr
&& let ExprKind::Call(func1, args1) = trailing_expr.kind && let ExprKind::Call(func1, args1) = trailing_expr.kind

View file

@ -1,5 +1,5 @@
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr) if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = pat.kind
&& name.as_str() == "y" && name.as_str() == "y"
&& let ExprKind::Struct(qpath, fields, None) = arg.kind && let ExprKind::Struct(qpath, fields, None) = arg.kind
&& matches!(qpath, QPath::LangItem(LangItem::Range, _)) && matches!(qpath, QPath::LangItem(LangItem::Range, _))
@ -16,7 +16,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
&& let Some(init) = local.init && let Some(init) = local.init
&& let ExprKind::Path(ref qpath1) = init.kind && let ExprKind::Path(ref qpath1) = init.kind
&& match_qpath(qpath1, &["y"]) && match_qpath(qpath1, &["y"])
&& let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name1, None) = local.pat.kind
&& name1.as_str() == "z" && name1.as_str() == "z"
&& block.expr.is_none() && block.expr.is_none()
{ {

View file

@ -34,7 +34,7 @@ if let StmtKind::Local(local) = stmt.kind
&& let ExprKind::Path(ref qpath3) = inner2.kind && let ExprKind::Path(ref qpath3) = inner2.kind
&& match_qpath(qpath3, &["x"]) && match_qpath(qpath3, &["x"])
&& block.expr.is_none() && block.expr.is_none()
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
&& name.as_str() == "print_text" && name.as_str() == "print_text"
{ {
// report your lint here // report your lint here

View file

@ -1,5 +1,5 @@
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr) if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = pat.kind
&& name.as_str() == "i" && name.as_str() == "i"
&& let ExprKind::Struct(qpath, fields, None) = arg.kind && let ExprKind::Struct(qpath, fields, None) = arg.kind
&& matches!(qpath, QPath::LangItem(LangItem::Range, _)) && matches!(qpath, QPath::LangItem(LangItem::Range, _))

View file

@ -20,7 +20,7 @@ if let StmtKind::Local(local) = stmt.kind
&& let Some(init1) = local1.init && let Some(init1) = local1.init
&& let ExprKind::Lit(ref lit4) = init1.kind && let ExprKind::Lit(ref lit4) = init1.kind
&& let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node && let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name, None) = local1.pat.kind
&& name.as_str() == "x" && name.as_str() == "x"
&& let Some(trailing_expr) = block.expr && let Some(trailing_expr) = block.expr
&& let ExprKind::Path(ref qpath) = trailing_expr.kind && let ExprKind::Path(ref qpath) = trailing_expr.kind
@ -29,7 +29,7 @@ if let StmtKind::Local(local) = stmt.kind
&& arms[2].guard.is_none() && arms[2].guard.is_none()
&& let ExprKind::Lit(ref lit5) = arms[2].body.kind && let ExprKind::Lit(ref lit5) = arms[2].body.kind
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node && let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node
&& let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind && let PatKind::Binding(BindingMode::NONE, _, name1, None) = local.pat.kind
&& name1.as_str() == "a" && name1.as_str() == "a"
{ {
// report your lint here // report your lint here

View file

@ -1,6 +1,4 @@
use rustc_ast::ast::{ use rustc_ast::ast::{self, BindingMode, ByRef, Pat, PatField, PatKind, RangeEnd, RangeSyntax};
self, BindingAnnotation, ByRef, Pat, PatField, PatKind, RangeEnd, RangeSyntax,
};
use rustc_ast::ptr; use rustc_ast::ptr;
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
@ -106,7 +104,7 @@ impl Rewrite for Pat {
write_list(&items, &fmt) write_list(&items, &fmt)
} }
PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape), PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape),
PatKind::Ident(BindingAnnotation(by_ref, mutability), ident, ref sub_pat) => { PatKind::Ident(BindingMode(by_ref, mutability), ident, ref sub_pat) => {
let mut_prefix = format_mutability(mutability).trim(); let mut_prefix = format_mutability(mutability).trim();
let (ref_kw, mut_infix) = match by_ref { let (ref_kw, mut_infix) = match by_ref {

View file

@ -12,7 +12,7 @@ params: [
kind: PatKind { kind: PatKind {
Binding { Binding {
name: "foo" name: "foo"
mode: BindingAnnotation(No, Not) mode: BindingMode(No, Not)
var: LocalVarId(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).2)) var: LocalVarId(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).2))
ty: Foo ty: Foo
is_primary: true is_primary: true