diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index df620ddb66529..b689765bf6fa1 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3689,7 +3689,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let ident = Ident::new(kw::SelfLower, span.normalize_to_macro_rules()); let res = Res::Local(delegation.id); this.innermost_rib_bindings(ValueNS).insert(ident, res); - this.visit_block(body); + + //As we lower target_expr_template body to a body of a function we need a label rib (#148889) + this.with_label_rib(RibKind::FnOrCoroutine, |this| { + this.visit_block(body); + }); }); } diff --git a/tests/ui/delegation/unreachable-label-ice-148889.rs b/tests/ui/delegation/unreachable-label-ice-148889.rs new file mode 100644 index 0000000000000..e5f9fa1cf4934 --- /dev/null +++ b/tests/ui/delegation/unreachable-label-ice-148889.rs @@ -0,0 +1,18 @@ +#![allow(incomplete_features)] +#![feature(fn_delegation)] + +trait Trait { + fn static_method2(x: i32, y: i32) -> i32 { + x + y + } +} + +struct S; +impl Trait for S {} + +pub fn main() { + 'foo: loop { + reuse ::static_method2 { loop { break 'foo; } } + //~^ ERROR use of unreachable label `'foo` + } +} diff --git a/tests/ui/delegation/unreachable-label-ice-148889.stderr b/tests/ui/delegation/unreachable-label-ice-148889.stderr new file mode 100644 index 0000000000000..2141962609183 --- /dev/null +++ b/tests/ui/delegation/unreachable-label-ice-148889.stderr @@ -0,0 +1,13 @@ +error[E0767]: use of unreachable label `'foo` + --> $DIR/unreachable-label-ice-148889.rs:15:59 + | +LL | 'foo: loop { + | ---- unreachable label defined here +LL | reuse ::static_method2 { loop { break 'foo; } } + | ^^^^ unreachable label `'foo` + | + = note: labels are unreachable through functions, closures, async blocks and modules + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0767`.