From 9c23bda030fa5e126407e3fd62a91e0bf8c57860 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 07:56:26 +0000 Subject: [PATCH 01/11] use `deref_patterns` in `rustc_borrowck` --- compiler/rustc_borrowck/src/dataflow.rs | 2 +- .../src/diagnostics/conflict_errors.rs | 14 +++++++------- .../src/diagnostics/explain_borrow.rs | 6 +++--- compiler/rustc_borrowck/src/diagnostics/mod.rs | 18 +++++++++--------- .../src/diagnostics/move_errors.rs | 2 +- .../src/diagnostics/mutability_errors.rs | 16 ++++++---------- compiler/rustc_borrowck/src/lib.rs | 12 ++++++------ .../src/polonius/legacy/loan_invalidations.rs | 10 +++++----- compiler/rustc_borrowck/src/type_check/mod.rs | 10 +++++----- compiler/rustc_borrowck/src/used_muts.rs | 2 +- 10 files changed, 44 insertions(+), 48 deletions(-) diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 8ddfa4b61edde..d187ed4074521 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -548,7 +548,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> { location: Location, ) { match &stmt.kind { - mir::StatementKind::Assign(box (lhs, rhs)) => { + mir::StatementKind::Assign((lhs, rhs)) => { if let mir::Rvalue::Ref(_, _, place) = rhs { if place.ignore_borrow( self.tcx, diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index c4fbe1b9e5d61..098c81d27de07 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -4009,12 +4009,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { Some(LocalDecl { local_info: ClearCrossCrate::Set( - box LocalInfo::User(BindingForm::Var(VarBindingForm { + LocalInfo::User(BindingForm::Var(VarBindingForm { opt_match_place: None, .. })) - | box LocalInfo::StaticRef { .. } - | box LocalInfo::Boring, + | LocalInfo::StaticRef { .. } + | LocalInfo::Boring, ), .. }) @@ -4185,7 +4185,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'tcx> { fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) { match statement { - Statement { kind: StatementKind::FakeRead(box (cause, place)), .. } + Statement { kind: StatementKind::FakeRead((cause, place)), .. } if *place == self.place => { self.cause = Some(*cause); @@ -4243,7 +4243,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // and it'll make sense. let location = borrow.reserve_location; debug!("annotate_argument_and_return_for_borrow: location={:?}", location); - if let Some(Statement { kind: StatementKind::Assign(box (reservation, _)), .. }) = + if let Some(Statement { kind: StatementKind::Assign((reservation, _)), .. }) = &self.body[location.block].statements.get(location.statement_index) { debug!("annotate_argument_and_return_for_borrow: reservation={:?}", reservation); @@ -4261,7 +4261,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { "annotate_argument_and_return_for_borrow: target={:?} stmt={:?}", target, stmt ); - if let StatementKind::Assign(box (place, rvalue)) = &stmt.kind + if let StatementKind::Assign((place, rvalue)) = &stmt.kind && let Some(assigned_to) = place.as_local() { debug!( @@ -4270,7 +4270,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { assigned_to, rvalue ); // Check if our `target` was captured by a closure. - if let Rvalue::Aggregate(box AggregateKind::Closure(def_id, args), operands) = + if let Rvalue::Aggregate(AggregateKind::Closure(def_id, args), operands) = rvalue { let def_id = def_id.expect_local(); diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 6a4f0038ba5d6..5d154cc7b9050 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -787,7 +787,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { let block = &self.body.basic_blocks[location.block]; let kind = if let Some(&Statement { - kind: StatementKind::FakeRead(box (FakeReadCause::ForLet(_), place)), + kind: StatementKind::FakeRead((FakeReadCause::ForLet(_), place)), .. }) = block.statements.get(location.statement_index) { @@ -849,7 +849,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { // will only ever have one item at any given time, but by using a vector, we can pop from // it which simplifies the termination logic. let mut queue = vec![location]; - let Some(Statement { kind: StatementKind::Assign(box (place, _)), .. }) = stmt else { + let Some(Statement { kind: StatementKind::Assign((place, _)), .. }) = stmt else { return false; }; let Some(mut target) = place.as_local() else { return false }; @@ -865,7 +865,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { debug!("was_captured_by_trait_object: stmt={:?}", stmt); // The only kind of statement that we care about is assignments... - if let StatementKind::Assign(box (place, rvalue)) = &stmt.kind { + if let StatementKind::Assign((place, rvalue)) = &stmt.kind { let Some(into) = place.local_or_deref_local() else { // Continue at the next location. queue.push(current_location.successor_within_block()); diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 9245e5f05f4c1..248396ba9849b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -243,7 +243,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let mut target = place.local_or_deref_local(); for stmt in &self.body[location.block].statements[location.statement_index..] { debug!("add_moved_or_invoked_closure_note: stmt={:?} target={:?}", stmt, target); - if let StatementKind::Assign(box (into, Rvalue::Use(from, _))) = &stmt.kind { + if let StatementKind::Assign((into, Rvalue::Use(from, _))) = &stmt.kind { debug!("add_fnonce_closure_note: into={:?} from={:?}", into, from); match from { Operand::Copy(place) | Operand::Move(place) @@ -260,7 +260,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let terminator = self.body[location.block].terminator(); debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator); if let TerminatorKind::Call { - func: Operand::Constant(box ConstOperand { const_, .. }), + func: Operand::Constant(ConstOperand { const_, .. }), args, .. } = &terminator.kind @@ -1030,7 +1030,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { }; debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt); - if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind + if let StatementKind::Assign((_, Rvalue::Aggregate(kind, places))) = &stmt.kind && let AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _) = **kind { debug!("move_spans: def_id={:?} places={:?}", def_id, places); @@ -1044,7 +1044,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // StatementKind::FakeRead only contains a def_id if they are introduced as a result // of pattern matching within a closure. - if let StatementKind::FakeRead(box (cause, place)) = stmt.kind { + if let StatementKind::FakeRead((cause, place)) = stmt.kind { match cause { FakeReadCause::ForMatchedPlace(Some(closure_def_id)) | FakeReadCause::ForLet(Some(closure_def_id)) => { @@ -1084,7 +1084,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // that has a `self` parameter. let target_temp = match stmt.kind { - StatementKind::Assign(box (temp, _)) if temp.as_local().is_some() => { + StatementKind::Assign((temp, _)) if temp.as_local().is_some() => { temp.as_local().unwrap() } _ => return normal_ret, @@ -1131,7 +1131,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { use self::UseSpans::*; debug!("borrow_spans: use_span={:?} location={:?}", use_span, location); - let Some(Statement { kind: StatementKind::Assign(box (place, _)), .. }) = + let Some(Statement { kind: StatementKind::Assign((place, _)), .. }) = self.body[location.block].statements.get(location.statement_index) else { return OtherUse(use_span); @@ -1157,10 +1157,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { self.body[location.block].statements[location.statement_index + 1..].iter(); for stmt in statements.chain(maybe_additional_statement) { - if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind { + if let StatementKind::Assign((_, Rvalue::Aggregate(kind, places))) = &stmt.kind { let (&def_id, is_coroutine) = match kind { - box AggregateKind::Closure(def_id, _) => (def_id, false), - box AggregateKind::Coroutine(def_id, _) => (def_id, true), + AggregateKind::Closure(def_id, _) => (def_id, false), + AggregateKind::Coroutine(def_id, _) => (def_id, true), _ => continue, }; let def_id = def_id.expect_local(); diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 3663ef28e4590..48e75719c0b16 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -122,7 +122,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // to a user variable is when initializing it. // If that ever stops being the case, then the ever initialized // flow could be used. - if let Some(StatementKind::Assign(box (place, Rvalue::Use(Operand::Move(move_from), _)))) = + if let Some(StatementKind::Assign((place, Rvalue::Use(Operand::Move(move_from), _)))) = self.body.basic_blocks[location.block] .statements .get(location.statement_index) diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 00317b376e8cb..a4025f28a5511 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -315,7 +315,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if let Some(mir::Statement { source_info, kind: - mir::StatementKind::Assign(box ( + mir::StatementKind::Assign(( _, mir::Rvalue::Ref( _, @@ -1418,10 +1418,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if let Some(mir::Statement { source_info: _, kind: - mir::StatementKind::Assign(box ( - _, - mir::Rvalue::Use(mir::Operand::Copy(place), _), - )), + mir::StatementKind::Assign((_, mir::Rvalue::Use(mir::Operand::Copy(place), _))), .. }) = first_assignment_stmt { @@ -1879,7 +1876,7 @@ fn suggest_ampmut<'tcx>( // ^^ lifetime annotation not allowed // if let Some(rhs_stmt) = opt_assignment_rhs_stmt - && let StatementKind::Assign(box (lhs, rvalue)) = &rhs_stmt.kind + && let StatementKind::Assign((lhs, rvalue)) = &rhs_stmt.kind && let mut rhs_span = rhs_stmt.source_info.span && let Ok(mut rhs_str) = tcx.sess.source_map().span_to_snippet(rhs_span) { @@ -1900,7 +1897,7 @@ fn suggest_ampmut<'tcx>( && let [user_ty_proj] = user_ty_projs.contents.as_slice() && user_ty_proj.projs.is_empty() && let Either::Left(rhs_stmt_new) = body.stmt_at(*assign) - && let StatementKind::Assign(box (_, rvalue_new)) = &rhs_stmt_new.kind + && let StatementKind::Assign((_, rvalue_new)) = &rhs_stmt_new.kind && let rhs_span_new = rhs_stmt_new.source_info.span && let Ok(rhs_str_new) = tcx.sess.source_map().span_to_snippet(rhs_span_new) { @@ -1908,9 +1905,8 @@ fn suggest_ampmut<'tcx>( } if let Either::Right(call) = body.stmt_at(*assign) - && let TerminatorKind::Call { - func: Operand::Constant(box const_operand), args, .. - } = &call.kind + && let TerminatorKind::Call { func: Operand::Constant(const_operand), args, .. } = + &call.kind && let ty::FnDef(method_def_id, method_args) = *const_operand.ty().kind() && let Some(trait_) = tcx.trait_of_assoc(method_def_id) && tcx.is_lang_item(trait_, hir::LangItem::Index) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index acdeea91a189f..16979f92cd9a0 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2,8 +2,8 @@ // tidy-alphabetical-start #![allow(internal_features)] -#![feature(box_patterns)] #![feature(default_field_values)] +#![feature(deref_patterns)] #![feature(file_buffered)] #![feature(negative_impls)] #![feature(never_type)] @@ -798,12 +798,12 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, self.check_activations(location, span, state); match &stmt.kind { - StatementKind::Assign(box (lhs, rhs)) => { + StatementKind::Assign((lhs, rhs)) => { self.consume_rvalue(location, (rhs, span), state); self.mutate_place(location, (*lhs, span), Shallow(None), state); } - StatementKind::FakeRead(box (_, place)) => { + StatementKind::FakeRead((_, place)) => { // Read for match doesn't access any memory and is used to // assert that a place is safe and live. So we don't have to // do any checks here. @@ -821,7 +821,7 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, state, ); } - StatementKind::Intrinsic(box kind) => match kind { + StatementKind::Intrinsic(kind) => match kind { NonDivergingIntrinsic::Assume(op) => { self.consume_operand(location, (op, span), state); } @@ -1566,7 +1566,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { ); } - Rvalue::BinaryOp(_bin_op, box (operand1, operand2)) => { + Rvalue::BinaryOp(_bin_op, (operand1, operand2)) => { self.consume_operand(location, (operand1, span), state); self.consume_operand(location, (operand2, span), state); } @@ -1689,7 +1689,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { debug!("temporary assigned in: stmt={:?}", stmt); match stmt.kind { - StatementKind::Assign(box ( + StatementKind::Assign(( _, Rvalue::Ref(_, _, source) | Rvalue::Use(Operand::Copy(source) | Operand::Move(source), _), diff --git a/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs b/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs index 136719a323ce1..8f04d7946ff1c 100644 --- a/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs +++ b/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs @@ -45,18 +45,18 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> { self.check_activations(location); match &statement.kind { - StatementKind::Assign(box (lhs, rhs)) => { + StatementKind::Assign((lhs, rhs)) => { self.consume_rvalue(location, rhs); self.mutate_place(location, *lhs, Shallow(None)); } - StatementKind::FakeRead(box (_, _)) => { + StatementKind::FakeRead((_, _)) => { // Only relevant for initialized/liveness/safety checks. } - StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => { + StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(op)) => { self.consume_operand(location, op); } - StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping { + StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping { src, dst, count, @@ -309,7 +309,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> { ); } - Rvalue::BinaryOp(_bin_op, box (operand1, operand2)) => { + Rvalue::BinaryOp(_bin_op, (operand1, operand2)) => { self.consume_operand(location, operand1); self.consume_operand(location, operand2); } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 8998ced10bf9e..499e057e8fdfb 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -581,7 +581,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.super_statement(stmt, location); let tcx = self.tcx(); match &stmt.kind { - StatementKind::Assign(box (place, rv)) => { + StatementKind::Assign((place, rv)) => { // Assignments to temporaries are not "interesting"; // they are not caused by the user, but rather artifacts // of lowering. Assignments to other sorts of places *are* interesting @@ -672,7 +672,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ); } } - StatementKind::AscribeUserType(box (place, projection), variance) => { + StatementKind::AscribeUserType((place, projection), variance) => { let place_ty = place.ty(self.body, tcx).ty; if let Err(terr) = self.relate_type_and_user_type( place_ty, @@ -693,7 +693,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ); } } - StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(..)) + StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(..)) | StatementKind::FakeRead(..) | StatementKind::StorageLive(..) | StatementKind::StorageDead(..) @@ -702,7 +702,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | StatementKind::PlaceMention(..) | StatementKind::BackwardIncompatibleDropHint { .. } | StatementKind::Nop => {} - StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(..)) + StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(..)) | StatementKind::SetDiscriminant { .. } => { bug!("Statement not allowed in this MIR phase") } @@ -1582,7 +1582,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { Rvalue::BinaryOp( BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge, - box (left, right), + (left, right), ) => { let ty_left = left.ty(self.body, tcx); match ty_left.kind() { diff --git a/compiler/rustc_borrowck/src/used_muts.rs b/compiler/rustc_borrowck/src/used_muts.rs index bde07c05c0e16..29c45e2c7bb6e 100644 --- a/compiler/rustc_borrowck/src/used_muts.rs +++ b/compiler/rustc_borrowck/src/used_muts.rs @@ -78,7 +78,7 @@ impl<'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'_, '_, '_, 'tcx> { } fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { - if let StatementKind::Assign(box (into, _)) = &statement.kind { + if let StatementKind::Assign((into, _)) = &statement.kind { debug!( "visit_statement: statement={:?} local={:?} \ never_initialized_mut_locals={:?}", From b24100d3ac0f59200978ba5b8234ac69a9e4bd17 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 14:14:52 +0000 Subject: [PATCH 02/11] use `deref_patterns` in `rustc_builtin_macros` --- compiler/rustc_builtin_macros/src/autodiff.rs | 4 ++-- compiler/rustc_builtin_macros/src/deriving/generic/mod.rs | 2 +- compiler/rustc_builtin_macros/src/format.rs | 2 +- compiler/rustc_builtin_macros/src/global_allocator.rs | 4 ++-- compiler/rustc_builtin_macros/src/lib.rs | 2 +- compiler/rustc_builtin_macros/src/test.rs | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs index afa393a545cd4..76c43e0df1a24 100644 --- a/compiler/rustc_builtin_macros/src/autodiff.rs +++ b/compiler/rustc_builtin_macros/src/autodiff.rs @@ -75,7 +75,7 @@ mod llvm_enzyme { // Get information about the function the macro is applied to fn extract_item_info(iitem: &Box) -> Option<(Visibility, FnSig, Ident, Generics)> { match &iitem.kind { - ItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => { + ItemKind::Fn(ast::Fn { sig, ident, generics, .. }) => { Some((iitem.vis.clone(), sig.clone(), ident.clone(), generics.clone())) } _ => None, @@ -226,7 +226,7 @@ mod llvm_enzyme { }, Annotatable::AssocItem(assoc_item, _ctxt @ (Impl { of_trait: _ } | Trait)) => { match &assoc_item.kind { - ast::AssocItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => Some(( + ast::AssocItemKind::Fn(ast::Fn { sig, ident, generics, .. }) => Some(( assoc_item.vis.clone(), sig.clone(), ident.clone(), diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index ace4048af26c1..8b8af1685287c 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1027,7 +1027,7 @@ impl<'a> MethodDef<'a> { match ty { // Selflike (`&Self`) arguments only occur in non-static methods. - Ref(box Self_, _) if !self.is_static() => selflike_args.push(arg_expr), + Ref(Self_, _) if !self.is_static() => selflike_args.push(arg_expr), Self_ => cx.dcx().span_bug(span, "`Self` in non-return position"), _ => nonselflike_args.push(arg_expr), } diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 1caa0e823090a..7c43693e15f84 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -456,7 +456,7 @@ fn make_format_args( parse::Piece::Lit(s) => { unfinished_literal.push_str(s); } - parse::Piece::NextArgument(box parse::Argument { position, position_span, format }) => { + parse::Piece::NextArgument(parse::Argument { position, position_span, format }) => { if !unfinished_literal.is_empty() { template.push(FormatArgsPiece::Literal(Symbol::intern(&unfinished_literal))); unfinished_literal.clear(); diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 208562b8d0bc0..684411d64d943 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -25,12 +25,12 @@ pub(crate) fn expand( // Allow using `#[global_allocator]` on an item statement // FIXME - if we get deref patterns, use them to reduce duplication here let (item, ident, is_stmt, ty_span) = if let Annotatable::Item(item) = &item - && let ItemKind::Static(box ast::StaticItem { ident, ty, .. }) = &item.kind + && let ItemKind::Static(ast::StaticItem { ident, ty, .. }) = &item.kind { (item, *ident, false, ecx.with_def_site_ctxt(ty.span)) } else if let Annotatable::Stmt(stmt) = &item && let StmtKind::Item(item) = &stmt.kind - && let ItemKind::Static(box ast::StaticItem { ident, ty, .. }) = &item.kind + && let ItemKind::Static(ast::StaticItem { ident, ty, .. }) = &item.kind { (item, *ident, true, ecx.with_def_site_ctxt(ty.span)) } else { diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index d39e3d8103542..d5d577d39d28b 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -3,8 +3,8 @@ // tidy-alphabetical-start #![allow(internal_features)] -#![feature(box_patterns)] #![feature(decl_macro)] +#![feature(deref_patterns)] #![feature(iter_order_by)] #![feature(proc_macro_internals)] #![feature(proc_macro_quote)] diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 1b761614f3e6d..ac865958011a6 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -56,9 +56,9 @@ pub(crate) fn expand_test_case( // `#[test_case]` is valid on functions, consts, and statics. Only modify // the item in those cases. match &mut item.kind { - ast::ItemKind::Fn(box ast::Fn { ident, .. }) - | ast::ItemKind::Const(box ast::ConstItem { ident, .. }) - | ast::ItemKind::Static(box ast::StaticItem { ident, .. }) => { + ast::ItemKind::Fn(ast::Fn { ident, .. }) + | ast::ItemKind::Const(ast::ConstItem { ident, .. }) + | ast::ItemKind::Static(ast::StaticItem { ident, .. }) => { ident.span = ident.span.with_ctxt(sp.ctxt()); let test_path_symbol = Symbol::intern(&item_path( // skip the name of the root module @@ -114,7 +114,7 @@ pub(crate) fn expand_test_or_bench( ) -> Vec { let (item, is_stmt) = match item { Annotatable::Item(i) => (i, false), - Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true), + Annotatable::Stmt(ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true), other => { not_testable_error(cx, is_bench, attr_sp, None); return vec![other]; From 161ebbaf9f9a54b5cf3b3efab101faf4462a487b Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 14:19:57 +0000 Subject: [PATCH 03/11] use `deref_patterns` in `rustc_const_eval` --- compiler/rustc_const_eval/src/check_consts/check.rs | 2 +- .../rustc_const_eval/src/check_consts/qualifs.rs | 2 +- compiler/rustc_const_eval/src/interpret/step.rs | 12 ++++++------ compiler/rustc_const_eval/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index b66d69b924076..58a06add664ed 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -665,7 +665,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } } - Rvalue::BinaryOp(op, box (lhs, rhs)) => { + Rvalue::BinaryOp(op, (lhs, rhs)) => { let lhs_ty = lhs.ty(self.body, self.tcx); let rhs_ty = rhs.ty(self.body, self.tcx); diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 6f7fccdaf2665..d30c125edfb07 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -236,7 +236,7 @@ where | Rvalue::UnaryOp(_, operand) | Rvalue::Cast(_, operand, _) => in_operand::(cx, in_local, operand), - Rvalue::BinaryOp(_, box (lhs, rhs)) => { + Rvalue::BinaryOp(_, (lhs, rhs)) => { in_operand::(cx, in_local, lhs) || in_operand::(cx, in_local, rhs) } diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 6aa2971c900cf..cd9d025f332e7 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -90,7 +90,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { use rustc_middle::mir::StatementKind::*; match &stmt.kind { - Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?, + Assign((place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?, SetDiscriminant { place, variant_index } => { let dest = self.eval_place(**place)?; @@ -111,11 +111,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // interpreter is solely intended for borrowck'ed code. FakeRead(..) => {} - Intrinsic(box intrinsic) => self.eval_nondiverging_intrinsic(intrinsic)?, + Intrinsic(intrinsic) => self.eval_nondiverging_intrinsic(intrinsic)?, // Evaluate the place expression, without reading from it. - PlaceMention(box place) => { - let _ = self.eval_place(*place)?; + PlaceMention(place) => { + let _ = self.eval_place(**place)?; } // This exists purely to guide borrowck lifetime inference, and does not have @@ -179,7 +179,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { CopyForDeref(_) => bug!("`CopyForDeref` in runtime MIR"), - BinaryOp(bin_op, box (ref left, ref right)) => { + BinaryOp(bin_op, (ref left, ref right)) => { let layout = util::binop_left_homogeneous(bin_op).then_some(dest.layout); let left = self.read_immediate(&self.eval_operand(left, layout)?)?; let layout = util::binop_right_homogeneous(bin_op).then_some(left.layout); @@ -197,7 +197,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { self.write_immediate(*result, &dest)?; } - Aggregate(box ref kind, ref operands) => { + Aggregate(ref kind, ref operands) => { self.write_aggregate(kind, operands, &dest)?; } diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 33da1c5ecf738..5ebcd0723f5b3 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -1,7 +1,7 @@ // tidy-alphabetical-start #![feature(array_try_map)] -#![feature(box_patterns)] #![feature(decl_macro)] +#![feature(deref_patterns)] #![feature(never_type)] #![feature(slice_ptr_get)] #![feature(trait_alias)] From dfe2f8590d464fbe01eb6745e2917cc5d7e79a0a Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:13:32 +0000 Subject: [PATCH 04/11] use `deref_patterns` in `rustc_hir_typeck` --- compiler/rustc_hir_typeck/src/coercion.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs | 2 +- compiler/rustc_hir_typeck/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index abd5f38f0ed08..fe034b332235e 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1705,7 +1705,7 @@ impl<'tcx> CoerceMany<'tcx> { ); unsized_return = self.is_return_ty_definitely_unsized(fcx); } - ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { + ObligationCauseCode::MatchExpressionArm(MatchExpressionArmCause { arm_span, arm_ty, prior_arm_ty, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 68bf29cc32a59..ced961f11515f 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -484,7 +484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, ) -> bool { if let traits::FulfillmentErrorCode::Select(traits::SelectionError::SignatureMismatch( - box traits::SignatureMismatchData { expected_trait_ref, .. }, + traits::SignatureMismatchData { expected_trait_ref, .. }, )) = error.code && let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) = expected_trait_ref.self_ty().kind() diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 15729bc311e57..55a01ddfba779 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -1,5 +1,5 @@ // tidy-alphabetical-start -#![feature(box_patterns)] +#![feature(deref_patterns)] #![feature(iter_intersperse)] #![feature(iter_order_by)] #![feature(never_type)] From 1a6d78220460499a663db3823fa337469380c26c Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:15:09 +0000 Subject: [PATCH 05/11] use `deref_patterns` in `rustc_lint` --- compiler/rustc_lint/src/builtin.rs | 6 +++--- compiler/rustc_lint/src/lib.rs | 2 +- compiler/rustc_lint/src/nonstandard_style.rs | 8 +++----- compiler/rustc_lint/src/precedence.rs | 2 +- compiler/rustc_lint/src/unused.rs | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 6a485ea06ee86..ea0791783a642 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -260,12 +260,12 @@ impl EarlyLintPass for UnsafeCode { fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) { match it.kind { - ast::ItemKind::Trait(box ast::Trait { safety: ast::Safety::Unsafe(_), .. }) => { + ast::ItemKind::Trait(ast::Trait { safety: ast::Safety::Unsafe(_), .. }) => { self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeTrait); } ast::ItemKind::Impl(ast::Impl { - of_trait: Some(box ast::TraitImplHeader { safety: ast::Safety::Unsafe(_), .. }), + of_trait: Some(ast::TraitImplHeader { safety: ast::Safety::Unsafe(_), .. }), .. }) => { self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeImpl); @@ -779,7 +779,7 @@ impl EarlyLintPass for AnonymousParameters { // This is a hard error in future editions; avoid linting and erroring return; } - if let ast::AssocItemKind::Fn(box Fn { ref sig, .. }) = it.kind { + if let ast::AssocItemKind::Fn(Fn { ref sig, .. }) = it.kind { for arg in sig.decl.inputs.iter() { if let ast::PatKind::Missing = arg.pat.kind { let ty_snip = cx.sess().source_map().span_to_snippet(arg.ty.span); diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index ea0e657f7edef..10fd1d1501b3b 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -21,7 +21,7 @@ // tidy-alphabetical-start #![allow(internal_features)] -#![feature(box_patterns)] +#![feature(deref_patterns)] #![feature(iter_order_by)] #![feature(rustc_attrs)] #![feature(titlecase)] diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 6cec7b0efd82f..fbbfbd86d319f 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -169,14 +169,12 @@ impl EarlyLintPass for NonCamelCaseTypes { } match &it.kind { - ast::ItemKind::TyAlias(box ast::TyAlias { ident, .. }) + ast::ItemKind::TyAlias(ast::TyAlias { ident, .. }) | ast::ItemKind::Enum(ident, ..) | ast::ItemKind::Struct(ident, ..) | ast::ItemKind::Union(ident, ..) => self.check_case(cx, "type", ident), - ast::ItemKind::Trait(box ast::Trait { ident, .. }) => { - self.check_case(cx, "trait", ident) - } - ast::ItemKind::TraitAlias(box ast::TraitAlias { ident, .. }) => { + ast::ItemKind::Trait(ast::Trait { ident, .. }) => self.check_case(cx, "trait", ident), + ast::ItemKind::TraitAlias(ast::TraitAlias { ident, .. }) => { self.check_case(cx, "trait alias", ident) } diff --git a/compiler/rustc_lint/src/precedence.rs b/compiler/rustc_lint/src/precedence.rs index 52321e25c7d43..7c073e5025b9b 100644 --- a/compiler/rustc_lint/src/precedence.rs +++ b/compiler/rustc_lint/src/precedence.rs @@ -43,7 +43,7 @@ impl EarlyLintPass for Precedence { let mut arg = operand; let mut at_least_one = false; - while let ExprKind::MethodCall(box MethodCall { receiver, .. }) = &arg.kind { + while let ExprKind::MethodCall(MethodCall { receiver, .. }) = &arg.kind { at_least_one = true; arg = receiver; } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 9f15f41955d86..0cb7b4cce8462 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -499,9 +499,9 @@ trait UnusedDelimLint { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { use ast::ItemKind::*; - let expr = if let Const(box ast::ConstItem { rhs_kind, .. }) = &item.kind { + let expr = if let Const(ast::ConstItem { rhs_kind, .. }) = &item.kind { if let Some(e) = rhs_kind.expr() { e } else { return } - } else if let Static(box ast::StaticItem { expr: Some(expr), .. }) = &item.kind { + } else if let Static(ast::StaticItem { expr: Some(expr), .. }) = &item.kind { expr } else { return; From d8242efd9682656e7e0fc39c0b25d728f4533fdb Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:25:00 +0000 Subject: [PATCH 06/11] use `deref_patterns` in `rustc_parse` --- compiler/rustc_parse/src/lib.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 4bfa899352393..7805994b441b8 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -2,9 +2,9 @@ // tidy-alphabetical-start #![cfg_attr(test, feature(iter_order_by))] -#![feature(box_patterns)] #![feature(debug_closure_helpers)] #![feature(default_field_values)] +#![feature(deref_patterns)] #![feature(iter_intersperse)] #![recursion_limit = "256"] // tidy-alphabetical-end diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index bd45bbb6a8582..68fda3b86ddcb 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1219,7 +1219,7 @@ impl<'a> Parser<'a> { let kind = match AssocItemKind::try_from(kind) { Ok(kind) => kind, Err(kind) => match kind { - ItemKind::Static(box StaticItem { + ItemKind::Static(StaticItem { ident, ty, safety: _, @@ -1475,7 +1475,7 @@ impl<'a> Parser<'a> { let kind = match ForeignItemKind::try_from(kind) { Ok(kind) => kind, Err(kind) => match kind { - ItemKind::Const(box ConstItem { ident, ty, rhs_kind, .. }) => { + ItemKind::Const(ConstItem { ident, ty, rhs_kind, .. }) => { let const_span = Some(span.with_hi(ident.span.lo())) .filter(|span| span.can_be_used_for_suggestions()); self.dcx().emit_err(errors::ExternItemCannotBeConst { @@ -1510,7 +1510,7 @@ impl<'a> Parser<'a> { let span = self.psess.source_map().guess_head_span(span); let descr = kind.descr(); let help = match kind { - ItemKind::DelegationMac(box DelegationMac { + ItemKind::DelegationMac(DelegationMac { suffixes: DelegationSuffixes::Glob(_), .. }) => false, From ca91ad499ed2a81a21ff1811fcc12804bf45c20b Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:27:06 +0000 Subject: [PATCH 07/11] use `deref_patterns` in `rustc_resolve` --- .../rustc_resolve/src/build_reduced_graph.rs | 16 ++--- compiler/rustc_resolve/src/def_collector.rs | 14 ++--- compiler/rustc_resolve/src/late.rs | 59 +++++++++---------- .../rustc_resolve/src/late/diagnostics.rs | 14 ++--- compiler/rustc_resolve/src/lib.rs | 2 +- 5 files changed, 49 insertions(+), 56 deletions(-) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 3b58ebaf8cc7c..09609166ec66b 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -865,12 +865,12 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { } // These items live in the value namespace. - ItemKind::Const(box ConstItem { ident, .. }) - | ItemKind::Delegation(box Delegation { ident, .. }) - | ItemKind::Static(box StaticItem { ident, .. }) => { + ItemKind::Const(ConstItem { ident, .. }) + | ItemKind::Delegation(Delegation { ident, .. }) + | ItemKind::Static(StaticItem { ident, .. }) => { self.r.define_local(parent, ident, ValueNS, res, vis, sp, expansion); } - ItemKind::Fn(box Fn { ident, .. }) => { + ItemKind::Fn(Fn { ident, .. }) => { self.r.define_local(parent, ident, ValueNS, res, vis, sp, expansion); // Functions introducing procedural macros reserve a slot @@ -879,12 +879,12 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { } // These items live in the type namespace. - ItemKind::TyAlias(box TyAlias { ident, .. }) - | ItemKind::TraitAlias(box TraitAlias { ident, .. }) => { + ItemKind::TyAlias(TyAlias { ident, .. }) + | ItemKind::TraitAlias(TraitAlias { ident, .. }) => { self.r.define_local(parent, ident, TypeNS, res, vis, sp, expansion); } - ItemKind::Enum(ident, _, _) | ItemKind::Trait(box ast::Trait { ident, .. }) => { + ItemKind::Enum(ident, _, _) | ItemKind::Trait(ast::Trait { ident, .. }) => { self.r.define_local(parent, ident, TypeNS, res, vis, sp, expansion); let module = self.r.new_local_module( @@ -1287,7 +1287,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { ItemKind::MacroDef(ident, def) => { (self.res(def_id), *ident, item.span, def.macro_rules) } - ItemKind::Fn(box ast::Fn { ident: fn_ident, .. }) => { + ItemKind::Fn(ast::Fn { ident: fn_ident, .. }) => { match self.proc_macro_stub(item, *fn_ident) { Some((macro_kind, ident, span)) => { let macro_kinds = macro_kind.into(); diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 0040ddbf5e24a..01160dc772b27 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -257,7 +257,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { fn visit_foreign_item(&mut self, fi: &'a ForeignItem) { let (ident, def_kind) = match fi.kind { - ForeignItemKind::Static(box StaticItem { + ForeignItemKind::Static(StaticItem { ident, ty: _, mutability, @@ -273,8 +273,8 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { (ident, DefKind::Static { safety, mutability, nested: false }) } - ForeignItemKind::Fn(box Fn { ident, .. }) => (ident, DefKind::Fn), - ForeignItemKind::TyAlias(box TyAlias { ident, .. }) => (ident, DefKind::ForeignTy), + ForeignItemKind::Fn(Fn { ident, .. }) => (ident, DefKind::Fn), + ForeignItemKind::TyAlias(TyAlias { ident, .. }) => (ident, DefKind::ForeignTy), ForeignItemKind::MacCall(_) => { self.visit_invoc_in_module(fi.id); self.visit_macro_invoc(fi.id); @@ -344,18 +344,18 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) { let (ident, def_kind, ns) = match &i.kind { - AssocItemKind::Fn(box Fn { ident, .. }) - | AssocItemKind::Delegation(box Delegation { ident, .. }) => { + AssocItemKind::Fn(Fn { ident, .. }) + | AssocItemKind::Delegation(Delegation { ident, .. }) => { (*ident, DefKind::AssocFn, ValueNS) } - AssocItemKind::Const(box ConstItem { ident, rhs_kind, .. }) => ( + AssocItemKind::Const(ConstItem { ident, rhs_kind, .. }) => ( *ident, DefKind::AssocConst { is_type_const: matches!(rhs_kind, ConstItemRhsKind::TypeConst { .. }), }, ValueNS, ), - AssocItemKind::Type(box TyAlias { ident, .. }) => (*ident, DefKind::AssocTy, TypeNS), + AssocItemKind::Type(TyAlias { ident, .. }) => (*ident, DefKind::AssocTy, TypeNS), AssocItemKind::MacCall(..) => { self.visit_macro_invoc(i.id); self.visit_assoc_item_mac_call(i, ctxt); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 3337a4626b040..165800719fd24 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1045,7 +1045,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.resolve_doc_links(&foreign_item.attrs, MaybeExported::Ok(foreign_item.id)); let def_kind = self.r.local_def_kind(foreign_item.id); match foreign_item.kind { - ForeignItemKind::TyAlias(box TyAlias { ref generics, .. }) => { + ForeignItemKind::TyAlias(TyAlias { ref generics, .. }) => { self.with_generic_param_rib( &generics.params, RibKind::Item(HasGenericParams::Yes(generics.span), def_kind), @@ -1055,7 +1055,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc |this| visit::walk_item(this, foreign_item), ); } - ForeignItemKind::Fn(box Fn { ref generics, .. }) => { + ForeignItemKind::Fn(Fn { ref generics, .. }) => { self.with_generic_param_rib( &generics.params, RibKind::Item(HasGenericParams::Yes(generics.span), def_kind), @@ -2809,7 +2809,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let def_kind = self.r.local_def_kind(item.id); match &item.kind { - ItemKind::TyAlias(box TyAlias { generics, .. }) => { + ItemKind::TyAlias(TyAlias { generics, .. }) => { self.with_generic_param_rib( &generics.params, RibKind::Item(HasGenericParams::Yes(generics.span), def_kind), @@ -2820,7 +2820,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); } - ItemKind::Fn(box Fn { generics, define_opaque, .. }) => { + ItemKind::Fn(Fn { generics, define_opaque, .. }) => { self.with_generic_param_rib( &generics.params, RibKind::Item(HasGenericParams::Yes(generics.span), def_kind), @@ -2851,7 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.diag_metadata.current_impl_items = None; } - ItemKind::Trait(box Trait { generics, bounds, items, impl_restriction, .. }) => { + ItemKind::Trait(Trait { generics, bounds, items, impl_restriction, .. }) => { // resolve paths for `impl` restrictions self.resolve_impl_restriction_path(impl_restriction); @@ -2873,7 +2873,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); } - ItemKind::TraitAlias(box TraitAlias { generics, bounds, .. }) => { + ItemKind::TraitAlias(TraitAlias { generics, bounds, .. }) => { // Create a new rib for the trait-wide type parameters. self.with_generic_param_rib( &generics.params, @@ -2913,13 +2913,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.parent_scope.module = orig_module; } - ItemKind::Static(box ast::StaticItem { - ident, - ty, - expr, - define_opaque, - eii_impls, - .. + ItemKind::Static(ast::StaticItem { + ident, ty, expr, define_opaque, eii_impls, .. }) => { self.with_static_rib(def_kind, |this| { this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| { @@ -2935,7 +2930,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.resolve_eii(&eii_impls); } - ItemKind::Const(box ast::ConstItem { + ItemKind::Const(ast::ConstItem { ident, generics, ty, @@ -3333,7 +3328,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { for item in trait_items { self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id)); match &item.kind { - AssocItemKind::Const(box ast::ConstItem { + AssocItemKind::Const(ast::ConstItem { generics, ty, rhs_kind, @@ -3385,7 +3380,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.resolve_define_opaques(define_opaque); } - AssocItemKind::Fn(box Fn { generics, define_opaque, .. }) => { + AssocItemKind::Fn(Fn { generics, define_opaque, .. }) => { walk_assoc_item(self, generics, LifetimeBinderKind::Function, item); self.resolve_define_opaques(define_opaque); @@ -3400,7 +3395,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { |this| this.resolve_delegation(delegation, item.id, false), ); } - AssocItemKind::Type(box TyAlias { generics, .. }) => self + AssocItemKind::Type(TyAlias { generics, .. }) => self .with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| { walk_assoc_item(this, generics, LifetimeBinderKind::Item, item) }), @@ -3551,7 +3546,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let prev = self.diag_metadata.current_impl_item.take(); self.diag_metadata.current_impl_item = Some(&item); match &item.kind { - AssocItemKind::Const(box ast::ConstItem { + AssocItemKind::Const(ast::ConstItem { ident, generics, ty, @@ -3632,7 +3627,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); self.resolve_define_opaques(define_opaque); } - AssocItemKind::Fn(box Fn { ident, generics, define_opaque, .. }) => { + AssocItemKind::Fn(Fn { ident, generics, define_opaque, .. }) => { debug!("resolve_implementation AssocItemKind::Fn"); // We also need a new scope for the impl item type parameters. self.with_generic_param_rib( @@ -3660,7 +3655,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.resolve_define_opaques(define_opaque); } - AssocItemKind::Type(box TyAlias { ident, generics, .. }) => { + AssocItemKind::Type(TyAlias { ident, generics, .. }) => { self.diag_metadata.in_non_gat_assoc_type = Some(generics.params.is_empty()); debug!("resolve_implementation AssocItemKind::Type"); // We also need a new scope for the impl item type parameters. @@ -3690,7 +3685,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); self.diag_metadata.in_non_gat_assoc_type = None; } - AssocItemKind::Delegation(box delegation) => { + AssocItemKind::Delegation(delegation) => { debug!("resolve_implementation AssocItemKind::Delegation"); self.with_generic_param_rib( &[], @@ -5245,7 +5240,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ExprKind::Field(ref subexpression, _) => { self.resolve_expr(subexpression, Some(expr)); } - ExprKind::MethodCall(box MethodCall { ref seg, ref receiver, ref args, .. }) => { + ExprKind::MethodCall(MethodCall { ref seg, ref receiver, ref args, .. }) => { self.resolve_expr(receiver, Some(expr)); for arg in args { self.resolve_expr(arg, None); @@ -5277,7 +5272,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { visit::walk_expr(self, expr); } // For closures, RibKind::FnOrCoroutine is added in visit_fn - ExprKind::Closure(box ast::Closure { + ExprKind::Closure(ast::Closure { binder: ClosureBinder::For { ref generic_params, span }, .. }) => { @@ -5577,16 +5572,16 @@ fn required_generic_args_suggestion(generics: &ast::Generics) -> Option impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> { fn visit_item(&mut self, item: &'ast Item) { match &item.kind { - ItemKind::TyAlias(box TyAlias { generics, .. }) - | ItemKind::Const(box ConstItem { generics, .. }) - | ItemKind::Fn(box Fn { generics, .. }) + ItemKind::TyAlias(TyAlias { generics, .. }) + | ItemKind::Const(ConstItem { generics, .. }) + | ItemKind::Fn(Fn { generics, .. }) | ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _) | ItemKind::Union(_, generics, _) | ItemKind::Impl(Impl { generics, .. }) - | ItemKind::Trait(box Trait { generics, .. }) - | ItemKind::TraitAlias(box TraitAlias { generics, .. }) => { - if let ItemKind::Fn(box Fn { sig, .. }) = &item.kind { + | ItemKind::Trait(Trait { generics, .. }) + | ItemKind::TraitAlias(TraitAlias { generics, .. }) => { + if let ItemKind::Fn(Fn { sig, .. }) = &item.kind { self.collect_fn_info(&sig.decl, item.id); } @@ -5601,7 +5596,7 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> { ItemKind::ForeignMod(ForeignMod { items, .. }) => { for foreign_item in items { - if let ForeignItemKind::Fn(box Fn { sig, .. }) = &foreign_item.kind { + if let ForeignItemKind::Fn(Fn { sig, .. }) = &foreign_item.kind { self.collect_fn_info(&sig.decl, foreign_item.id); } } @@ -5627,11 +5622,11 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> { } fn visit_assoc_item(&mut self, item: &'ast AssocItem, ctxt: AssocCtxt) { - if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind { + if let AssocItemKind::Fn(Fn { sig, .. }) = &item.kind { self.collect_fn_info(&sig.decl, item.id); } - if let AssocItemKind::Type(box ast::TyAlias { generics, .. }) = &item.kind { + if let AssocItemKind::Type(ast::TyAlias { generics, .. }) = &item.kind { let def_id = self.r.local_def_id(item.id); if let Some(suggestion) = required_generic_args_suggestion(generics) { self.r.item_required_generic_args_suggestions.insert(def_id, suggestion); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 6f86759d46c5f..82fa171a1e585 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -322,9 +322,9 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { && let Some(assoc) = self.diag_metadata.current_impl_item { let generics = match &assoc.kind { - AssocItemKind::Const(box ast::ConstItem { generics, .. }) - | AssocItemKind::Fn(box ast::Fn { generics, .. }) - | AssocItemKind::Type(box ast::TyAlias { generics, .. }) => Some(generics), + AssocItemKind::Const(ast::ConstItem { generics, .. }) + | AssocItemKind::Fn(ast::Fn { generics, .. }) + | AssocItemKind::Type(ast::TyAlias { generics, .. }) => Some(generics), AssocItemKind::Delegation(..) | AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => None, @@ -2073,9 +2073,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { let (lhs_span, rhs_span) = match &expr.kind { ExprKind::Field(base, ident) => (base.span, ident.span), - ExprKind::MethodCall(box MethodCall { receiver, span, .. }) => { - (receiver.span, *span) - } + ExprKind::MethodCall(MethodCall { receiver, span, .. }) => (receiver.span, *span), _ => return false, }; @@ -2767,7 +2765,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { { return Some(match &assoc_item.kind { ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst, - ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) if sig.decl.has_self() => { + ast::AssocItemKind::Fn(ast::Fn { sig, .. }) if sig.decl.has_self() => { AssocSuggestion::MethodWithSelf { called } } ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn { called }, @@ -3108,7 +3106,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { ExprKind::Call(..) => (None, true), // `Type.Foo(a, b)`, suggest replacing `.` -> `::` if variant `Foo` exists and is a tuple variant, // otherwise suggest adding a variant after `Type`. - ExprKind::MethodCall(box MethodCall { + ExprKind::MethodCall(MethodCall { receiver, span, seg: PathSegment { ident, .. }, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 91511cbcb65ab..ca8c2326c22de 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -9,11 +9,11 @@ // tidy-alphabetical-start #![allow(internal_features)] #![feature(arbitrary_self_types)] -#![feature(box_patterns)] #![feature(const_default)] #![feature(const_trait_impl)] #![feature(control_flow_into_value)] #![feature(default_field_values)] +#![feature(deref_patterns)] #![feature(iter_intersperse)] #![feature(rustc_attrs)] #![feature(trim_prefix_suffix)] From cb9362258f99a8af6be6fce3cf7e5f56d3a3e823 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:28:08 +0000 Subject: [PATCH 08/11] use `deref_patterns` in `rustc_ty_utils` --- compiler/rustc_ty_utils/src/consts.rs | 2 +- compiler/rustc_ty_utils/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 49e0bdde37870..f97b17b915e54 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -105,7 +105,7 @@ fn recurse_build<'tcx>( // } // ``` ExprKind::Block { block } => { - if let thir::Block { stmts: box [], expr: Some(e), .. } = &body.blocks[*block] { + if let thir::Block { stmts: [], expr: Some(e), .. } = &body.blocks[*block] { recurse_build(tcx, body, *e, root_span)? } else { maybe_supported_error(GenericConstantTooComplexSub::BlockNotSupported(node.span))? diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index 5f42a134ec9af..7cc68cc54a92c 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -6,7 +6,7 @@ // tidy-alphabetical-start #![feature(associated_type_defaults)] -#![feature(box_patterns)] +#![feature(deref_patterns)] #![feature(iterator_try_collect)] #![feature(never_type)] // tidy-alphabetical-end From 94a2a0eaf59fe98997d8ac018f0ee6679b2b7309 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:29:33 +0000 Subject: [PATCH 09/11] use `deref_patterns` in `rustc_trait_selection` --- .../src/error_reporting/infer/mod.rs | 21 +++++++++---------- .../mismatched_static_lifetime.rs | 2 +- .../nice_region_error/placeholder_error.rs | 16 +++++++------- .../src/error_reporting/infer/region.rs | 10 ++++----- .../src/error_reporting/infer/suggest.rs | 4 ++-- .../traits/fulfillment_errors.rs | 4 ++-- compiler/rustc_trait_selection/src/lib.rs | 2 +- 7 files changed, 29 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 887b0804c2296..c9e2312895820 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -432,7 +432,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } } - ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { + ObligationCauseCode::MatchExpressionArm(MatchExpressionArmCause { arm_block_id, arm_span, arm_ty, @@ -1910,9 +1910,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } let code = trace.cause.code(); - if let &(ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { - source, - .. + if let &(ObligationCauseCode::MatchExpressionArm(MatchExpressionArmCause { + source, .. }) | ObligationCauseCode::BlockTailExpression(.., source)) = code && let hir::MatchSource::TryDesugar(_) = source @@ -2302,14 +2301,14 @@ impl<'tcx> ObligationCause<'tcx> { ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => { ObligationCauseFailureCode::TryCompat { span, subdiags } } - ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { - source, .. - }) => match source { - hir::MatchSource::TryDesugar(_) => { - ObligationCauseFailureCode::TryCompat { span, subdiags } + ObligationCauseCode::MatchExpressionArm(MatchExpressionArmCause { source, .. }) => { + match source { + hir::MatchSource::TryDesugar(_) => { + ObligationCauseFailureCode::TryCompat { span, subdiags } + } + _ => ObligationCauseFailureCode::MatchCompat { span, subdiags }, } - _ => ObligationCauseFailureCode::MatchCompat { span, subdiags }, - }, + } ObligationCauseCode::IfExpression { .. } => { ObligationCauseFailureCode::IfElseDifferent { span, subdiags } } diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs index 711aab43d9e7b..4422980051afb 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs @@ -28,7 +28,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if !sub.is_static() { return None; } - let SubregionOrigin::Subtype(box TypeTrace { ref cause, .. }) = origin else { + let SubregionOrigin::Subtype(TypeTrace { ref cause, .. }) = origin else { return None; }; // If we added a "points at argument expression" obligation, we remove it here, we care diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs index 9cf016019bb09..fdbf4cf228de9 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs @@ -71,7 +71,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { Some(RegionResolutionError::SubSupConflict( vid, _, - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sub_placeholder @ Region(Interned(RePlaceholder(_), _)), _, sup_placeholder @ Region(Interned(RePlaceholder(_), _)), @@ -87,7 +87,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { Some(RegionResolutionError::SubSupConflict( vid, _, - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sub_placeholder @ Region(Interned(RePlaceholder(_), _)), _, _, @@ -103,7 +103,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { Some(RegionResolutionError::SubSupConflict( vid, _, - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), _, _, sup_placeholder @ Region(Interned(RePlaceholder(_), _)), @@ -121,7 +121,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { _, _, _, - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sup_placeholder @ Region(Interned(RePlaceholder(_), _)), _, )) => self.try_report_trait_placeholder_mismatch( @@ -136,7 +136,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { vid, _, _, - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sup_placeholder @ Region(Interned(RePlaceholder(_), _)), )) => self.try_report_trait_placeholder_mismatch( Some(ty::Region::new_var(self.tcx(), *vid)), @@ -147,7 +147,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { ), Some(RegionResolutionError::ConcreteFailure( - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sub_region @ Region(Interned(RePlaceholder(_), _)), sup_region @ Region(Interned(RePlaceholder(_), _)), )) => self.try_report_trait_placeholder_mismatch( @@ -159,7 +159,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { ), Some(RegionResolutionError::ConcreteFailure( - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sub_region @ Region(Interned(RePlaceholder(_), _)), sup_region, )) => self.try_report_trait_placeholder_mismatch( @@ -171,7 +171,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { ), Some(RegionResolutionError::ConcreteFailure( - SubregionOrigin::Subtype(box TypeTrace { cause, values }), + SubregionOrigin::Subtype(TypeTrace { cause, values }), sub_region, sup_region @ Region(Interned(RePlaceholder(_), _)), )) => self.try_report_trait_placeholder_mismatch( diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs index 2e9dcae700d2a..232fcf7e43809 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs @@ -303,10 +303,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { sup: Region<'tcx>, ) -> Diag<'a> { let mut err = match origin { - SubregionOrigin::Subtype(box trace) => { + SubregionOrigin::Subtype(trace) => { let terr = TypeError::RegionsDoesNotOutlive(sup, sub); let mut err = self.report_and_explain_type_error( - trace, + *trace, self.tcx.param_env(generic_param_scope), terr, ); @@ -631,7 +631,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // I can't think how to do better than this right now. -nikomatsakis debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure"); match placeholder_origin { - SubregionOrigin::Subtype(box ref trace) + SubregionOrigin::Subtype(ref trace) if matches!( &trace.cause.code().peel_derives(), ObligationCauseCode::WhereClause(..) @@ -661,10 +661,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) } } - SubregionOrigin::Subtype(box trace) => { + SubregionOrigin::Subtype(trace) => { let terr = TypeError::RegionsPlaceholderMismatch; return self.report_and_explain_type_error( - trace, + *trace, self.tcx.param_env(generic_param_scope), terr, ); diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs index fd51109db5f99..632f6fca82e11 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs @@ -209,7 +209,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { second: exp_span.shrink_to_hi(), }) } - ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { + ObligationCauseCode::MatchExpressionArm(MatchExpressionArmCause { prior_non_diverging_arms, .. }) => { @@ -248,7 +248,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let then_span = self.find_block_span_from_hir_id(then_expr.hir_id); Some(ConsiderAddingAwait::FutureSugg { span: then_span.shrink_to_hi() }) } - ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { + ObligationCauseCode::MatchExpressionArm(MatchExpressionArmCause { prior_non_diverging_arms, .. }) => Some({ diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 785118bc6d7eb..4b67cada078a4 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -692,7 +692,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } - SelectionError::SignatureMismatch(box SignatureMismatchData { + SelectionError::SignatureMismatch(SignatureMismatchData { found_trait_ref, expected_trait_ref, terr: terr @ TypeError::CyclicTy(_), @@ -702,7 +702,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { expected_trait_ref, terr, ), - SelectionError::SignatureMismatch(box SignatureMismatchData { + SelectionError::SignatureMismatch(SignatureMismatchData { found_trait_ref, expected_trait_ref, terr: _, diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index f0c67e4b4f89c..c1a0dcf5aa4c2 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -12,8 +12,8 @@ // tidy-alphabetical-start #![feature(associated_type_defaults)] -#![feature(box_patterns)] #![feature(default_field_values)] +#![feature(deref_patterns)] #![feature(hash_set_entry)] #![feature(iter_intersperse)] #![feature(iterator_try_reduce)] From 55b38dea38008e62cef58c29d340b7b3a1956afd Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:32:38 +0000 Subject: [PATCH 10/11] use `deref_patterns` in `rustc_middle` --- compiler/rustc_middle/src/lib.rs | 2 +- compiler/rustc_middle/src/mir/interpret/error.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 4 ++-- compiler/rustc_middle/src/mir/pretty.rs | 12 ++++++------ compiler/rustc_middle/src/mir/statement.rs | 4 ++-- compiler/rustc_middle/src/mir/visit.rs | 12 ++++++------ compiler/rustc_middle/src/thir/visit.rs | 8 ++++---- compiler/rustc_middle/src/traits/mod.rs | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 1d6132ba2a3ea..a9e547b5862a6 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -31,13 +31,13 @@ #![feature(allocator_api)] #![feature(associated_type_defaults)] #![feature(box_as_ptr)] -#![feature(box_patterns)] #![feature(closure_track_caller)] #![feature(const_default)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] #![feature(debug_closure_helpers)] #![feature(decl_macro)] +#![feature(deref_patterns)] #![feature(discriminant_kind)] #![feature(extern_types)] #![feature(file_buffered)] diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 5af8ec554f9db..7d9f6903d3ef0 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -200,7 +200,7 @@ impl InterpErrorBacktrace { impl<'tcx> InterpErrorInfo<'tcx> { pub fn into_parts(self) -> (InterpErrorKind<'tcx>, InterpErrorBacktrace) { - let InterpErrorInfo(box InterpErrorInfoInner { kind, backtrace }) = self; + let InterpErrorInfo(InterpErrorInfoInner { kind, backtrace }) = self; (kind, backtrace) } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 6124b92da5c10..423a9bb2c8f32 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1671,7 +1671,7 @@ pub fn find_self_call<'tcx>( debug!("find_self_call(local={:?}): terminator={:?}", local, body[block].terminator); if let Some(Terminator { kind: TerminatorKind::Call { func, args, .. }, .. }) = &body[block].terminator - && let Operand::Constant(box ConstOperand { const_, .. }) = func + && let Operand::Constant(ConstOperand { const_, .. }) = func && let ty::FnDef(def_id, fn_args) = *const_.ty().kind() && let Some(item) = tcx.opt_associated_item(def_id) && item.is_method() @@ -1685,7 +1685,7 @@ pub fn find_self_call<'tcx>( // Handle the case where `self_place` gets reborrowed. // This happens when the receiver is `&T`. for stmt in &body[block].statements { - if let StatementKind::Assign(box (place, rvalue)) = &stmt.kind + if let StatementKind::Assign((place, rvalue)) = &stmt.kind && let Some(reborrow_local) = place.as_local() && self_place.as_local() == Some(reborrow_local) && let Rvalue::Ref(_, _, deref_place) = rvalue diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 380ba959c25fa..f4b40ca12bbcb 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -522,7 +522,7 @@ fn write_scope_tree( impl Debug for VarDebugInfo<'_> { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { - if let Some(box VarDebugInfoFragment { ty, ref projection }) = self.composite { + if let Some(VarDebugInfoFragment { ty, ref projection }) = self.composite { pre_fmt_projection(&projection[..], fmt)?; write!(fmt, "({}: {})", self.name, ty)?; post_fmt_projection(&projection[..], fmt)?; @@ -806,8 +806,8 @@ impl Debug for StatementKind<'_> { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { use self::StatementKind::*; match *self { - Assign(box (ref place, ref rv)) => write!(fmt, "{place:?} = {rv:?}"), - FakeRead(box (ref cause, ref place)) => { + Assign((ref place, ref rv)) => write!(fmt, "{place:?} = {rv:?}"), + FakeRead((ref cause, ref place)) => { write!(fmt, "FakeRead({cause:?}, {place:?})") } StorageLive(ref place) => write!(fmt, "StorageLive({place:?})"), @@ -818,11 +818,11 @@ impl Debug for StatementKind<'_> { PlaceMention(ref place) => { write!(fmt, "PlaceMention({place:?})") } - AscribeUserType(box (ref place, ref c_ty), ref variance) => { + AscribeUserType((ref place, ref c_ty), ref variance) => { write!(fmt, "AscribeUserType({place:?}, {variance:?}, {c_ty:?})") } Coverage(ref kind) => write!(fmt, "Coverage::{kind:?}"), - Intrinsic(box ref intrinsic) => write!(fmt, "{intrinsic}"), + Intrinsic(ref intrinsic) => write!(fmt, "{intrinsic}"), ConstEvalCounter => write!(fmt, "ConstEvalCounter"), Nop => write!(fmt, "nop"), BackwardIncompatibleDropHint { ref place, reason: _ } => { @@ -1096,7 +1096,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { Cast(ref kind, ref place, ref ty) => { with_no_trimmed_paths!(write!(fmt, "{place:?} as {ty} ({kind:?})")) } - BinaryOp(ref op, box (ref a, ref b)) => write!(fmt, "{op:?}({a:?}, {b:?})"), + BinaryOp(ref op, (ref a, ref b)) => write!(fmt, "{op:?}({a:?}, {b:?})"), UnaryOp(ref op, ref a) => write!(fmt, "{op:?}({a:?})"), Discriminant(ref place) => write!(fmt, "discriminant({place:?})"), ThreadLocalRef(did) => ty::tls::with(|tcx| { diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index c5945848baad4..3833c9d4986aa 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -77,7 +77,7 @@ impl<'tcx> StatementKind<'tcx> { pub fn as_debuginfo(&self) -> Option> { match self { - StatementKind::Assign(box (place, Rvalue::Ref(_, _, ref_place))) + StatementKind::Assign((place, Rvalue::Ref(_, _, ref_place))) if let Some(local) = place.as_local() => { Some(StmtDebugInfo::AssignRef(local, *ref_place)) @@ -809,7 +809,7 @@ impl<'tcx> Rvalue<'tcx> { Ty::new_ptr(tcx, place_ty, kind.to_mutbl_lossy()) } Rvalue::Cast(.., ty) => ty, - Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => { + Rvalue::BinaryOp(op, (ref lhs, ref rhs)) => { let lhs_ty = lhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx); op.ty(tcx, lhs_ty, rhs_ty) diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index c660c77cd84a7..1893078400f14 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -419,10 +419,10 @@ macro_rules! make_mir_visitor { self.visit_statement_debuginfo(debuginfo, location); } match kind { - StatementKind::Assign(box (place, rvalue)) => { + StatementKind::Assign((place, rvalue)) => { self.visit_assign(place, rvalue, location); } - StatementKind::FakeRead(box (_, place)) => { + StatementKind::FakeRead((_, place)) => { self.visit_place( place, PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect), @@ -457,7 +457,7 @@ macro_rules! make_mir_visitor { location ); } - StatementKind::AscribeUserType(box (place, user_ty), variance) => { + StatementKind::AscribeUserType((place, user_ty), variance) => { self.visit_ascribe_user_ty( place, $(& $mutability)? *variance, @@ -471,7 +471,7 @@ macro_rules! make_mir_visitor { location ) } - StatementKind::Intrinsic(box intrinsic) => { + StatementKind::Intrinsic(intrinsic) => { match intrinsic { NonDivergingIntrinsic::Assume(op) => self.visit_operand(op, location), NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping { @@ -746,7 +746,7 @@ macro_rules! make_mir_visitor { self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)); } - Rvalue::BinaryOp(_bin_op, box(lhs, rhs)) => { + Rvalue::BinaryOp(_bin_op, (lhs, rhs)) => { self.visit_operand(lhs, location); self.visit_operand(rhs, location); } @@ -904,7 +904,7 @@ macro_rules! make_mir_visitor { self.visit_source_info(source_info); let location = Location::START; - if let Some(box VarDebugInfoFragment { + if let Some(VarDebugInfoFragment { ty, projection }) = composite { diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index aa1b6b1663bfd..397f171dadbd8 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -81,7 +81,7 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( visitor.visit_pat(pat); } Loop { body } => visitor.visit_expr(&visitor.thir()[body]), - LoopMatch { match_data: box LoopMatchMatchData { scrutinee, ref arms, .. }, .. } + LoopMatch { match_data: LoopMatchMatchData { scrutinee, ref arms, .. }, .. } | Match { scrutinee, ref arms, .. } => { visitor.visit_expr(&visitor.thir()[scrutinee]); for &arm in &**arms { @@ -123,7 +123,7 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( visitor.visit_expr(&visitor.thir()[field]); } } - Adt(box AdtExpr { + Adt(AdtExpr { ref fields, ref base, adt_def: _, @@ -145,7 +145,7 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( PlaceUnwrapUnsafeBinder { source } | ValueUnwrapUnsafeBinder { source } | WrapUnsafeBinder { source } => visitor.visit_expr(&visitor.thir()[source]), - Closure(box ClosureExpr { + Closure(ClosureExpr { closure_id: _, args: _, upvars: _, @@ -158,7 +158,7 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( NamedConst { def_id: _, args: _, user_ty: _ } => {} ConstParam { param: _, def_id: _ } => {} StaticRef { alloc_id: _, ty: _, def_id: _ } => {} - InlineAsm(box InlineAsmExpr { + InlineAsm(InlineAsmExpr { asm_macro: _, ref operands, template: _, diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index daa0df4013272..4cd124248e093 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -478,11 +478,11 @@ impl<'tcx> ObligationCauseCode<'tcx> { ObligationCauseCode::FunctionArg { parent_code, .. } => Some(parent_code), ObligationCauseCode::BuiltinDerived(derived) | ObligationCauseCode::WellFormedDerived(derived) - | ObligationCauseCode::ImplDerived(box ImplDerivedCause { derived, .. }) => { + | ObligationCauseCode::ImplDerived(ImplDerivedCause { derived, .. }) => { Some(&derived.parent_code) } ObligationCauseCode::BuiltinDerivedHost(derived) - | ObligationCauseCode::ImplDerivedHost(box ImplDerivedHostCause { derived, .. }) => { + | ObligationCauseCode::ImplDerivedHost(ImplDerivedHostCause { derived, .. }) => { Some(&derived.parent_code) } _ => None, @@ -509,7 +509,7 @@ impl<'tcx> ObligationCauseCode<'tcx> { ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)), ObligationCauseCode::BuiltinDerived(derived) | ObligationCauseCode::WellFormedDerived(derived) - | ObligationCauseCode::ImplDerived(box ImplDerivedCause { derived, .. }) => { + | ObligationCauseCode::ImplDerived(ImplDerivedCause { derived, .. }) => { Some((&derived.parent_code, Some(derived.parent_trait_pred))) } _ => None, From 1ffd6dbce0aca06fe3bdb8560f0275fdaa953d0e Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 7 May 2026 15:42:59 +0000 Subject: [PATCH 11/11] use `deref_patterns` in `rustc_codegen_ssa` --- compiler/rustc_codegen_ssa/src/lib.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 4 ++-- compiler/rustc_codegen_ssa/src/mir/statement.rs | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 22290d672c611..5ac9877c281f5 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -1,5 +1,5 @@ // tidy-alphabetical-start -#![feature(box_patterns)] +#![feature(deref_patterns)] #![feature(file_buffered)] #![feature(negative_impls)] #![feature(string_from_utf8_lossy_owned)] diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 9a491c9c3eb1f..e8dd8d0b26eac 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -525,7 +525,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.codegen_place_to_pointer(bx, place, mk_ptr) } - mir::Rvalue::BinaryOp(op_with_overflow, box (ref lhs, ref rhs)) + mir::Rvalue::BinaryOp(op_with_overflow, (ref lhs, ref rhs)) if let Some(op) = op_with_overflow.overflowing_to_wrapping() => { let lhs = self.codegen_operand(bx, lhs); @@ -545,7 +545,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { move_annotation: None, } } - mir::Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => { + mir::Rvalue::BinaryOp(op, (ref lhs, ref rhs)) => { let lhs = self.codegen_operand(bx, lhs); let rhs = self.codegen_operand(bx, rhs); let llresult = match (lhs.val, rhs.val) { diff --git a/compiler/rustc_codegen_ssa/src/mir/statement.rs b/compiler/rustc_codegen_ssa/src/mir/statement.rs index 1821710fbcc36..afbef86bd089e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/statement.rs +++ b/compiler/rustc_codegen_ssa/src/mir/statement.rs @@ -11,7 +11,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.codegen_stmt_debuginfos(bx, &statement.debuginfos); self.set_debug_loc(bx, statement.source_info); match statement.kind { - mir::StatementKind::Assign(box (ref place, ref rvalue)) => { + mir::StatementKind::Assign((ref place, ref rvalue)) => { if let Some(index) = place.as_local() { match self.locals[index] { LocalRef::Place(cg_dest) => self.codegen_rvalue(bx, cg_dest, rvalue), @@ -47,8 +47,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.codegen_rvalue(bx, cg_dest, rvalue); } } - mir::StatementKind::SetDiscriminant { box ref place, variant_index } => { - self.codegen_place(bx, place.as_ref()).codegen_set_discr(bx, variant_index); + mir::StatementKind::SetDiscriminant { ref place, variant_index } => { + self.codegen_place(bx, (**place).as_ref()).codegen_set_discr(bx, variant_index); } mir::StatementKind::StorageLive(local) => { if let LocalRef::Place(cg_place) = self.locals[local] { @@ -67,11 +67,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::StatementKind::Coverage(ref kind) => { self.codegen_coverage(bx, kind, statement.source_info.scope); } - mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => { + mir::StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(ref op)) => { let op_val = self.codegen_operand(bx, op); bx.assume(op_val.immediate()); } - mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( + mir::StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping( mir::CopyNonOverlapping { ref count, ref src, ref dst }, )) => { let dst_val = self.codegen_operand(bx, dst);