Skip to content

Commit 1d1f142

Browse files
committed
Auto merge of #102257 - cjgillot:let-else-lint, r=dingxiangfei2009
Fix lint scoping for let-else. The scoping for let-else is inconsistent with HIR nesting. This creates cases, in `ui/let-else/let-else-allow-unused.rs` for instance, where an `allow` lint attribute does not apply to the bindings created by `let-else`. This PR is an attempt to correct this. As there is no lint that currently relies on this, the test for this behaviour is #101500. cc `@dingxiangfei2009` as you filed #101894
2 parents e1d7dec + 73c52bc commit 1d1f142

File tree

1 file changed

+27
-16
lines changed
  • compiler/rustc_mir_build/src/build

1 file changed

+27
-16
lines changed

compiler/rustc_mir_build/src/build/block.rs

+27-16
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
221221

222222
let init = &this.thir[*initializer];
223223
let initializer_span = init.span;
224-
this.declare_bindings(
225-
visibility_scope,
226-
remainder_span,
227-
pattern,
228-
ArmHasGuard(false),
229-
Some((None, initializer_span)),
230-
);
231-
this.visit_primary_bindings(
232-
pattern,
233-
UserTypeProjections::none(),
234-
&mut |this, _, _, _, node, span, _, _| {
235-
this.storage_live_binding(block, node, span, OutsideGuard, true);
236-
this.schedule_drop_for_binding(node, span, OutsideGuard);
237-
},
238-
);
239224
let failure = unpack!(
240225
block = this.in_opt_scope(
241226
opt_destruction_scope.map(|de| (de, source_info)),
242227
|this| {
243228
let scope = (*init_scope, source_info);
244229
this.in_scope(scope, *lint_level, |this| {
230+
this.declare_bindings(
231+
visibility_scope,
232+
remainder_span,
233+
pattern,
234+
ArmHasGuard(false),
235+
Some((None, initializer_span)),
236+
);
237+
this.visit_primary_bindings(
238+
pattern,
239+
UserTypeProjections::none(),
240+
&mut |this, _, _, _, node, span, _, _| {
241+
this.storage_live_binding(
242+
block,
243+
node,
244+
span,
245+
OutsideGuard,
246+
true,
247+
);
248+
this.schedule_drop_for_binding(
249+
node,
250+
span,
251+
OutsideGuard,
252+
);
253+
},
254+
);
245255
this.ast_let_else(
246256
block,
247257
init,
@@ -306,7 +316,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
306316
ArmHasGuard(false),
307317
Some((None, initializer_span)),
308318
);
309-
this.expr_into_pattern(block, &pattern, init) // irrefutable pattern
319+
this.expr_into_pattern(block, &pattern, init)
320+
// irrefutable pattern
310321
})
311322
},
312323
)

0 commit comments

Comments
 (0)