Skip to content

Commit

Permalink
Add continue livenodes in liveness check for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakSingh31 committed Feb 27, 2024
1 parent 53ed660 commit 46d6915
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn propagate_through_block(&mut self, blk: &hir::Block<'_>, succ: LiveNode) -> LiveNode {
if blk.targeted_by_break {
self.break_ln.insert(blk.hir_id, succ);
self.cont_ln.insert(blk.hir_id, succ);
}
let succ = self.propagate_through_opt_expr(blk.expr, succ);
blk.stmts.iter().rev().fold(succ, |succ, stmt| self.propagate_through_stmt(stmt, succ))
Expand Down
31 changes: 31 additions & 0 deletions tests/ui/mir/liveness/cont-in-fn-issue-113379.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![allow(incomplete_features)]
#![feature(adt_const_params)]

trait Trait<const S: &'static str> {}

struct Bug<T>
where
T: Trait<
{
'b: {
continue 'b;
//~^ ERROR [E0080]
//~| ERROR [E0080]
//~| ERROR [E0696]
}
},
>,
{
t: T,
}

fn f() -> impl Sized {
'b: {
continue 'b;
//~^ ERROR [E0696]
}
}

fn main() {
f();
}
40 changes: 40 additions & 0 deletions tests/ui/mir/liveness/cont-in-fn-issue-113379.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error[E0696]: `continue` pointing to a labeled block
--> $DIR/cont-in-fn-issue-113379.rs:11:17
|
LL | / 'b: {
LL | | continue 'b;
| | ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
LL | |
LL | |
LL | |
LL | | }
| |_____________- labeled block the `continue` points to

error[E0696]: `continue` pointing to a labeled block
--> $DIR/cont-in-fn-issue-113379.rs:24:9
|
LL | / 'b: {
LL | | continue 'b;
| | ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
LL | |
LL | | }
| |_____- labeled block the `continue` points to

error[E0080]: evaluation of constant value failed
--> $DIR/cont-in-fn-issue-113379.rs:11:17
|
LL | continue 'b;
| ^^^^^^^^^^^ entering unreachable code

error[E0080]: evaluation of constant value failed
--> $DIR/cont-in-fn-issue-113379.rs:11:17
|
LL | continue 'b;
| ^^^^^^^^^^^ entering unreachable code
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0080, E0696.
For more information about an error, try `rustc --explain E0080`.
8 changes: 8 additions & 0 deletions tests/ui/mir/liveness/cont-in-match-arm-issue-121623.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
match () {
_ => 'b: {
continue 'b;
//~^ ERROR [E0696]
}
}
}
14 changes: 14 additions & 0 deletions tests/ui/mir/liveness/cont-in-match-arm-issue-121623.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0696]: `continue` pointing to a labeled block
--> $DIR/cont-in-match-arm-issue-121623.rs:4:13
|
LL | _ => 'b: {
| ______________-
LL | | continue 'b;
| | ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
LL | |
LL | | }
| |_________- labeled block the `continue` points to

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0696`.

0 comments on commit 46d6915

Please sign in to comment.