Skip to content

Commit

Permalink
remove unused parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 11, 2024
1 parent 2c937d0 commit 7a9b4fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
11 changes: 9 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
14 changes: 10 additions & 4 deletions tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7a9b4fb

Please sign in to comment.