2019-12-11 08:51:28 -06:00
|
|
|
#![feature(never_type)]
|
|
|
|
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
fn main() {
|
|
|
|
let val: ! = loop { break break; };
|
|
|
|
//~^ ERROR mismatched types
|
|
|
|
|
|
|
|
loop {
|
|
|
|
if true {
|
|
|
|
break "asdf";
|
|
|
|
} else {
|
|
|
|
break 123; //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let _: i32 = loop {
|
|
|
|
break "asdf"; //~ ERROR mismatched types
|
|
|
|
};
|
|
|
|
|
|
|
|
let _: i32 = 'outer_loop: loop {
|
|
|
|
loop {
|
|
|
|
break 'outer_loop "nope"; //~ ERROR mismatched types
|
|
|
|
break "ok";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-06-21 18:30:24 -05:00
|
|
|
'while_loop: while true { //~ WARN denote infinite loops with
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
break;
|
|
|
|
break (); //~ ERROR `break` with value from a `while` loop
|
|
|
|
loop {
|
|
|
|
break 'while_loop 123;
|
|
|
|
//~^ ERROR `break` with value from a `while` loop
|
|
|
|
break 456;
|
|
|
|
break 789;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-17 10:49:53 -05:00
|
|
|
while let Some(_) = Some(()) {
|
2019-11-17 23:11:42 -06:00
|
|
|
if break () { //~ ERROR `break` with value from a `while` loop
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
}
|
2017-03-17 10:49:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while let Some(_) = Some(()) {
|
|
|
|
break None;
|
2019-11-17 23:11:42 -06:00
|
|
|
//~^ ERROR `break` with value from a `while` loop
|
2017-03-17 10:49:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
'while_let_loop: while let Some(_) = Some(()) {
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
loop {
|
|
|
|
break 'while_let_loop "nope";
|
2019-11-17 23:11:42 -06:00
|
|
|
//~^ ERROR `break` with value from a `while` loop
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
break 33;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-17 10:49:53 -05:00
|
|
|
for _ in &[1,2,3] {
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
break (); //~ ERROR `break` with value from a `for` loop
|
|
|
|
break [()];
|
|
|
|
//~^ ERROR `break` with value from a `for` loop
|
2017-03-17 10:49:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
'for_loop: for _ in &[1,2,3] {
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
loop {
|
|
|
|
break Some(3);
|
|
|
|
break 'for_loop Some(17);
|
|
|
|
//~^ ERROR `break` with value from a `for` loop
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let _: i32 = 'a: loop {
|
|
|
|
let _: () = 'b: loop {
|
|
|
|
break ('c: loop {
|
|
|
|
break;
|
|
|
|
break 'c 123; //~ ERROR mismatched types
|
|
|
|
});
|
|
|
|
break 'a 123;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
loop {
|
|
|
|
break (break, break); //~ ERROR mismatched types
|
|
|
|
};
|
|
|
|
|
|
|
|
loop {
|
|
|
|
break;
|
|
|
|
break 2; //~ ERROR mismatched types
|
|
|
|
};
|
|
|
|
|
|
|
|
loop {
|
|
|
|
break 2;
|
|
|
|
break; //~ ERROR mismatched types
|
|
|
|
break 4;
|
|
|
|
};
|
2020-12-14 06:14:17 -06:00
|
|
|
|
|
|
|
'LOOP: for _ in 0 .. 9 {
|
|
|
|
break LOOP;
|
|
|
|
//~^ ERROR cannot find value `LOOP` in this scope
|
|
|
|
}
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
}
|