Closed
Description
From Rust nightly-2019-09-16
to nightly-2019-06-18
, something has caused the following code to start throwing an unreachable expression warning. Changing it from an async fn
to an fn
throws no warnings.
async fn read_until(r: &mut std::net::TcpStream, byte: u8) -> io::Result<Vec<u8>> {
let mut buffer = Vec::new();
let mut single = [0; 1];
loop {
r.read(&mut single)?;
buffer.push(single[0]);
if single[0] == byte {
return Ok(buffer);
}
}
}
error: unreachable expression
--> src/main.rs:4:83
|
4 | async fn read_until(r: &mut std::net::TcpStream, byte: u8) -> io::Result<Vec<u8>> {
| ___________________________________________________________________________________^
5 | | let mut buffer = Vec::new();
6 | | let mut single = [0; 1];
7 | | loop {
... |
13 | | }
14 | | }
| |_^
note: lint level defined here
--> src/main.rs:3:8
|
3 | #[deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
A more recent nightly(2019-09-21) specifies the warning more closely:
warning: unreachable expression
--> src/main.rs:3:83
|
3 | async fn read_until(r: &mut std::net::TcpStream, byte: u8) -> io::Result<Vec<u8>> {
| ___________________________________________________________________________________^
4 | | let mut buffer = Vec::new();
5 | | let mut single = [0; 1];
6 | | loop {
... |
12 | | }
13 | | }
| |_^
|
= note: `#[warn(unreachable_code)]` on by default
note: any code following this expression is unreachable
--> src/main.rs:6:5
|
6 | / loop {
7 | | r.read(&mut single)?;
8 | | buffer.push(single[0]);
9 | | if single[0] == byte {
10 | | return Ok(buffer);
11 | | }
12 | | }
| |_____^
$: rustc --version --verbose
rustc 1.39.0-nightly (7efe1c6e6 2019-09-17)
binary: rustc
commit-hash: 7efe1c6e678a263b9464f2e7f06f552b4d4db5a5
commit-date: 2019-09-17
host: x86_64-unknown-linux-gnu
release: 1.39.0-nightly
LLVM version: 9.0
Metadata
Metadata
Assignees
Labels
No labels