@@ -105,24 +105,41 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
105105 . insert ( hir_ty. hir_id , c_ty) ;
106106
107107 let ty = o_ty. normalized ;
108- if let hir:: PatKind :: Wild = decl. pat . kind {
109- // We explicitly allow `let _: dyn Trait;` (!)
110- } else {
111- if self . outermost_fn_param_pat . is_some ( ) {
112- if !self . fcx . tcx . features ( ) . unsized_fn_params {
113- self . fcx . require_type_is_sized (
114- ty,
115- hir_ty. span ,
116- traits:: SizedArgumentType ( Some ( decl. pat . hir_id ) ) ,
117- ) ;
118- }
119- } else {
120- if !self . fcx . tcx . features ( ) . unsized_locals {
121- self . fcx . require_type_is_sized (
122- ty,
123- hir_ty. span ,
124- traits:: VariableType ( decl. pat . hir_id ) ,
125- ) ;
108+ match decl. pat . kind {
109+ // We explicitly allow `let ref x: str = *"";`
110+ hir:: PatKind :: Binding ( hir:: BindingAnnotation ( hir:: ByRef :: Yes ( _) , _) , ..) => { }
111+ // We explicitly allow `let _: dyn Trait;` and allow the `visit_pat` check to
112+ // handle `let (x, _): (sized, str) = *r;`. Otherwise with the later we'd
113+ // complain incorrectly about the `str` that is otherwise unused.
114+ _ if {
115+ let mut is_wild = false ;
116+ decl. pat . walk ( |pat| {
117+ if let hir:: PatKind :: Wild = pat. kind {
118+ is_wild = true ;
119+ false
120+ } else {
121+ true
122+ }
123+ } ) ;
124+ is_wild
125+ } => { }
126+ _ => {
127+ if self . outermost_fn_param_pat . is_some ( ) {
128+ if !self . fcx . tcx . features ( ) . unsized_fn_params {
129+ self . fcx . require_type_is_sized (
130+ ty,
131+ hir_ty. span ,
132+ traits:: SizedArgumentType ( Some ( decl. pat . hir_id ) ) ,
133+ ) ;
134+ }
135+ } else {
136+ if !self . fcx . tcx . features ( ) . unsized_locals {
137+ self . fcx . require_type_is_sized (
138+ ty,
139+ hir_ty. span ,
140+ traits:: VariableType ( decl. pat . hir_id ) ,
141+ ) ;
142+ }
126143 }
127144 }
128145 }
0 commit comments