From bf3bb5fd37b5dcf54a723c8559bba6718630095b Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 16 Feb 2025 21:22:36 +1100 Subject: [PATCH] Flatten the check for ref/non-ref bindings --- compiler/rustc_borrowck/src/type_check/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 1f3a15df80cf..21b0a62fe430 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -462,17 +462,15 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { .into_iter() .flat_map(UserTypeProjections::projections_and_spans) { - let ty = if !local_decl.is_nonref_binding() { + let ty = if local_decl.is_nonref_binding() { + local_decl.ty + } else if let &ty::Ref(_, rty, _) = local_decl.ty.kind() { // If we have a binding of the form `let ref x: T = ..` // then remove the outermost reference so we can check the // type annotation for the remaining type. - if let ty::Ref(_, rty, _) = local_decl.ty.kind() { - *rty - } else { - bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty); - } + rty } else { - local_decl.ty + bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty); }; if let Err(terr) = self.typeck.relate_type_and_user_type(