Skip to content

Commit 37eb690

Browse files
committed
Do not error on let ref x: str = *"";
1 parent 17ed1ff commit 37eb690

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

compiler/rustc_hir_typeck/src/gather_locals.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,28 @@ 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 _: dyn Trait;`
110+
hir::PatKind::Wild => {}
111+
// We explicitly allow `let ref x: str = *"";`
112+
hir::PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes(_), _), ..) => {}
113+
_ => {
114+
if self.outermost_fn_param_pat.is_some() {
115+
if !self.fcx.tcx.features().unsized_fn_params {
116+
self.fcx.require_type_is_sized(
117+
ty,
118+
hir_ty.span,
119+
traits::SizedArgumentType(Some(decl.pat.hir_id)),
120+
);
121+
}
122+
} else {
123+
if !self.fcx.tcx.features().unsized_locals {
124+
self.fcx.require_type_is_sized(
125+
ty,
126+
hir_ty.span,
127+
traits::VariableType(decl.pat.hir_id),
128+
);
129+
}
126130
}
127131
}
128132
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ build-pass
2+
fn main() {
3+
let ref x: str = *"";
4+
}

0 commit comments

Comments
 (0)