Skip to content

Commit e0091c5

Browse files
authored
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 #118212, it fixes #148889 ICE. r? `@petrochenkov`
2 parents 6900946 + 62fe6a0 commit e0091c5

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
36893689
let ident = Ident::new(kw::SelfLower, span.normalize_to_macro_rules());
36903690
let res = Res::Local(delegation.id);
36913691
this.innermost_rib_bindings(ValueNS).insert(ident, res);
3692-
this.visit_block(body);
3692+
3693+
//As we lower target_expr_template body to a body of a function we need a label rib (#148889)
3694+
this.with_label_rib(RibKind::FnOrCoroutine, |this| {
3695+
this.visit_block(body);
3696+
});
36933697
});
36943698
}
36953699

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![allow(incomplete_features)]
2+
#![feature(fn_delegation)]
3+
4+
trait Trait {
5+
fn static_method2(x: i32, y: i32) -> i32 {
6+
x + y
7+
}
8+
}
9+
10+
struct S;
11+
impl Trait for S {}
12+
13+
pub fn main() {
14+
'foo: loop {
15+
reuse <S as Trait>::static_method2 { loop { break 'foo; } }
16+
//~^ ERROR use of unreachable label `'foo`
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0767]: use of unreachable label `'foo`
2+
--> $DIR/unreachable-label-ice-148889.rs:15:59
3+
|
4+
LL | 'foo: loop {
5+
| ---- unreachable label defined here
6+
LL | reuse <S as Trait>::static_method2 { loop { break 'foo; } }
7+
| ^^^^ unreachable label `'foo`
8+
|
9+
= note: labels are unreachable through functions, closures, async blocks and modules
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0767`.

0 commit comments

Comments
 (0)