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 https://github.com/rust-lang/rust/pull/101500. cc `@dingxiangfei2009` as you filed https://github.com/rust-lang/rust/pull/101894
This commit is contained in:
commit
1d1f142660
1 changed files with 27 additions and 16 deletions
|
@ -221,27 +221,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
let init = &this.thir[*initializer];
|
||||
let initializer_span = init.span;
|
||||
this.declare_bindings(
|
||||
visibility_scope,
|
||||
remainder_span,
|
||||
pattern,
|
||||
ArmHasGuard(false),
|
||||
Some((None, initializer_span)),
|
||||
);
|
||||
this.visit_primary_bindings(
|
||||
pattern,
|
||||
UserTypeProjections::none(),
|
||||
&mut |this, _, _, _, node, span, _, _| {
|
||||
this.storage_live_binding(block, node, span, OutsideGuard, true);
|
||||
this.schedule_drop_for_binding(node, span, OutsideGuard);
|
||||
},
|
||||
);
|
||||
let failure = unpack!(
|
||||
block = this.in_opt_scope(
|
||||
opt_destruction_scope.map(|de| (de, source_info)),
|
||||
|this| {
|
||||
let scope = (*init_scope, source_info);
|
||||
this.in_scope(scope, *lint_level, |this| {
|
||||
this.declare_bindings(
|
||||
visibility_scope,
|
||||
remainder_span,
|
||||
pattern,
|
||||
ArmHasGuard(false),
|
||||
Some((None, initializer_span)),
|
||||
);
|
||||
this.visit_primary_bindings(
|
||||
pattern,
|
||||
UserTypeProjections::none(),
|
||||
&mut |this, _, _, _, node, span, _, _| {
|
||||
this.storage_live_binding(
|
||||
block,
|
||||
node,
|
||||
span,
|
||||
OutsideGuard,
|
||||
true,
|
||||
);
|
||||
this.schedule_drop_for_binding(
|
||||
node,
|
||||
span,
|
||||
OutsideGuard,
|
||||
);
|
||||
},
|
||||
);
|
||||
this.ast_let_else(
|
||||
block,
|
||||
init,
|
||||
|
@ -306,7 +316,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
ArmHasGuard(false),
|
||||
Some((None, initializer_span)),
|
||||
);
|
||||
this.expr_into_pattern(block, &pattern, init) // irrefutable pattern
|
||||
this.expr_into_pattern(block, &pattern, init)
|
||||
// irrefutable pattern
|
||||
})
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue