Rollup merge of #149496 - aerooneqq:ice-issue-148889, r=petrochenkov

Fix #148889: Add label rib when visiting delegation body

This PR relates to the delegation feature rust-lang/rust#118212, it fixes rust-lang/rust#148889 ICE.
r? `@petrochenkov`
This commit is contained in:
Matthias Krüger 2025-12-01 17:55:12 +01:00 committed by GitHub
commit e0091c5590
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 1 deletions

View file

@ -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);
});
});
}

View file

@ -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 <S as Trait>::static_method2 { loop { break 'foo; } }
//~^ ERROR use of unreachable label `'foo`
}
}

View file

@ -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 <S as Trait>::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`.