Skip to content

[Nightly RustC -- Debug only] Type check fails in async functions when compiling to debug. #72442

Closed
@vicky5124

Description

@vicky5124

The rustc compiler panics for being unable to check the type of an object.
In the example, it's shown in the form of path.to_str() returning an Option, and File::open() being unable to take Option as a parameter type.

error[E0277]: the trait bound `std::option::Option<&str>: std::convert::AsRef<std::path::Path>` is not satisfied
   --> src/main.rs:7:28
    |
7   |     let mut f = File::open(path.to_str())?;
    |                            ^^^^^^^^^^^^^ the trait `std::convert::AsRef<std::path::Path>` is not implemented for `std::option::Option<&str>`
    |
   ::: /home/nitsuga/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/fs.rs:374:20
    |
374 |     pub fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
    |                    ----------- required by this bound in `std::fs::File::open`

This would be the expected compilation error for that snippet of code, but instead of that, the compiler just panics.

This error only occurs on asynchronous functions and in nightly.
It also only happens when not compiling with --release, only in debug.

Code

use std::fs::File;
use std::io::prelude::*;

// async_std or just calling an async function in any way possible will produce the same panic
// just here for example usage, as tokio is the most common async runtime.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let path = std::path::Path::new(".");
    let mut f = File::open(path.to_str())?;
    let mut src = String::new();

    f.read_to_string(&mut src)?;

    Ok(())
}

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (d8878868c 2020-05-18)
binary: rustc
commit-hash: d8878868c8d7ef3779e7243953fc050cbb0e0565
commit-date: 2020-05-18
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

Error output

Backtrace

https://pastebin.com/6WaHRfij
RUST_BACKTRACE=1 cargo run --verbose

Metadata

Metadata

Assignees

Labels

A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions