Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vicky5124 opened this issue May 21, 2020 · 4 comments · Fixed by #72450
Closed
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vicky5124
Copy link

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

@vicky5124 vicky5124 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 21, 2020
@doctorn
Copy link
Contributor

doctorn commented May 21, 2020

cc @csmoe (likely due to #71948 - suggest_await_before_try)

@vicky5124
Copy link
Author

cc @csmoe (likely due to #71948 - suggest_await_before_try)

I can see why that could cause it.
I've also seen that #72426 could be caused due to a similar issue.
If it's the same issue, this issue should be kept as it provides a smaller example to reproduce and extra information in reproducing.

@jonas-schievink jonas-schievink added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label May 21, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 21, 2020
@csmoe
Copy link
Member

csmoe commented May 21, 2020

@doctorn @nitsuga5124 oh, sorry, my bad, investigating.

@JohnTitor JohnTitor added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label May 21, 2020
@csmoe csmoe self-assigned this May 22, 2020
@csmoe csmoe mentioned this issue May 22, 2020
@csmoe csmoe removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label May 22, 2020
@csmoe
Copy link
Member

csmoe commented May 22, 2020

Kind of strange, this ice only triggered with -Cincremental, CARGO_INCREMENTAL=0 cargo b won't ice.

here is a mcve:

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    block_on(async {
        {
            let path = std::path::Path::new(".");
            let mut f = File::open(path.to_str())?;
            //~^ ERROR the trait bound `std::option::Option<&str>: std::convert::AsRef<std::path::Path>` is not satisfied
            let mut src = String::new();
            f.read_to_string(&mut src)?;
            Ok(())
        }
    })
}

fn block_on<F>(f: F) -> Result<(), ()>
where
    F: Future<Output = Result<(), Box<dyn std::error::Error>>>,
{
    Ok(())
}

ICE: rustc --edition 2018 -Cincremental ice.rs
no-ICE: rustc --edition 2018 ice.rs

@csmoe csmoe added the A-incr-comp Area: Incremental compilation label May 22, 2020
@wesleywiser wesleywiser added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 22, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue May 25, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#72061 (add regression tests for stalled_on const vars)
 - rust-lang#72424 (fix ICE when debug-printing MIR)
 - rust-lang#72450 (Fix ice-rust-lang#72442)
 - rust-lang#72451 (Perform MIR NRVO even if types don't match)
 - rust-lang#72538 (Removed all instances of const_field.)

Failed merges:

r? @ghost
@bors bors closed this as completed in a7ff5a0 May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants