Skip to content

Commit 2411692

Browse files
committed
Make preconditions of check_pat_ref & borrow_pat_suggestion clearer
1 parent e9d49b2 commit 2411692

File tree

1 file changed

+5
-3
lines changed
  • compiler/rustc_typeck/src/check

1 file changed

+5
-3
lines changed

compiler/rustc_typeck/src/check/pat.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
649649
}
650650
}
651651

652-
fn borrow_pat_suggestion(&self, err: &mut Diagnostic, pat: &Pat<'_>, inner: &Pat<'_>) {
652+
// Precondition: pat is a Ref(_) pattern
653+
fn borrow_pat_suggestion(&self, err: &mut Diagnostic, pat: &Pat<'_>) {
653654
let tcx = self.tcx;
654-
if let PatKind::Ref(_, mutbl) = pat.kind
655+
if let PatKind::Ref(inner, mutbl) = pat.kind
655656
&& let PatKind::Binding(_, _, binding, ..) = inner.kind {
656657
let binding_parent_id = tcx.hir().get_parent_node(pat.hir_id);
657658
let binding_parent = tcx.hir().get(binding_parent_id);
@@ -1835,6 +1836,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18351836
box_ty
18361837
}
18371838

1839+
// Precondition: Pat is Ref(inner)
18381840
fn check_pat_ref(
18391841
&self,
18401842
pat: &'tcx Pat<'tcx>,
@@ -1868,7 +1870,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18681870
// Look for a case like `fn foo(&foo: u32)` and suggest
18691871
// `fn foo(foo: &u32)`
18701872
if let Some(mut err) = err {
1871-
self.borrow_pat_suggestion(&mut err, pat, inner);
1873+
self.borrow_pat_suggestion(&mut err, pat);
18721874
err.emit();
18731875
}
18741876
(rptr_ty, inner_ty)

0 commit comments

Comments
 (0)