From 7a9b4fb8b5fdfcd47a12bbfb929b7ea46a98556d Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 6 Jan 2024 13:26:00 +0800 Subject: [PATCH] remove unused parameters --- .../src/diagnostics/conflict_errors.rs | 11 +++++++++-- compiler/rustc_borrowck/src/lib.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 11 ----------- .../bindings-after-at/pat-at-same-name-both.stderr | 14 ++++++++++---- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index b7655b93ad19c..ce1a79dded74a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -3020,7 +3020,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// assignment to `x.f`). pub(crate) fn report_illegal_reassignment( &mut self, - _location: Location, (place, span): (Place<'tcx>, Span), assigned_span: Span, err_place: Place<'tcx>, @@ -3072,7 +3071,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { format!("mut {name}"), Applicability::MachineApplicable, ); - if !from_arg && decl.has_pattern_match() { + if !from_arg + && matches!( + decl.local_info(), + LocalInfo::User(BindingForm::Var(VarBindingForm { + opt_match_place: Some((Some(_), _)), + .. + })) + ) + { err.span_suggestion( decl.source_info.span, "to modify the original value, take a borrow instead", diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 4dba34c11f945..1048a5ec987c6 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2174,7 +2174,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // report the error as an illegal reassignment let init = &self.move_data.inits[init_index]; let assigned_span = init.span(self.body); - self.report_illegal_reassignment(location, (place, span), assigned_span, place); + self.report_illegal_reassignment((place, span), assigned_span, place); } else { self.report_mutability_error(place, span, the_place_err, error_access, location) } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index af4130d308424..e22d522862837 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1061,17 +1061,6 @@ impl<'tcx> LocalDecl<'tcx> { ) } - pub fn has_pattern_match(&self) -> bool { - matches!( - self.local_info(), - LocalInfo::User(BindingForm::Var(VarBindingForm { - binding_mode: ty::BindingMode::BindByValue(Mutability::Not), - opt_match_place: Some((Some(_), _)), - .. - })) - ) - } - /// Returns `true` if local is definitely not a `ref ident` or /// `ref mut ident` binding. (Such bindings cannot be made into /// mutable bindings, but the inverse does not necessarily hold). diff --git a/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr b/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr index e25c30cd4926a..41d1b79d97d1c 100644 --- a/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr +++ b/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr @@ -70,13 +70,19 @@ error[E0384]: cannot assign twice to immutable variable `a` --> $DIR/pat-at-same-name-both.rs:13:15 | LL | Ok(a @ b @ a) - | - - | | - | first assignment to `a` - | help: consider making this binding mutable: `mut a` + | - first assignment to `a` LL | LL | | Err(a @ b @ a) | ^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | Ok(a @ b @ mut a) + | ~~~~~ +help: to modify the original value, take a borrow instead + | +LL | Ok(a @ b @ ref mut a) + | ~~~~~~~~~ error: aborting due to 12 previous errors