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

ICE: Broken MIR: generator contains type (on build) #83971

Closed
utherpally opened this issue Apr 7, 2021 · 1 comment
Closed

ICE: Broken MIR: generator contains type (on build) #83971

utherpally opened this issue Apr 7, 2021 · 1 comment
Labels
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.

Comments

@utherpally
Copy link

Minimal example

Code

Playground

cargo run: ok.
cargo build: failed.

// https://github.com/http-rs/tide/blob/v0.16.0/src/middleware.rs
use async_trait::async_trait;
use std::future::Future;
use std::pin::Pin;

pub type Result = std::io::Result<()>;

#[async_trait]
pub trait Middleware<State>: Send   Sync   'static {
    /// Asynchronously handle the request, and return a response.
    async fn handle(&self, req: Request<State>, next: Next<'_, State>) -> crate::Result;

    /// Set the middleware's name. By default it uses the type signature.
    fn name(&self) -> &str {
        std::any::type_name::<Self>()
    }
}

pub struct Next<'a, State>(&'a str, State);

pub struct Request<State>(State);

#[async_trait]
impl<State, F> Middleware<State> for F
where
    State: Clone   Send   Sync   'static,
    F: Send
          Sync
          'static
          for<'a> Fn(
            Request<State>,
            Next<'a, State>,
        ) -> Pin<Box<dyn Future<Output = crate::Result>   'a   Send>>,
{
    async fn handle(&self, req: Request<State>, next: Next<'_, State>) -> crate::Result {
        (self)(req, next).await
    }
}

fn main() {

}

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (c051c5ddd 2021-04-06) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: compiler/rustc_mir/src/transform/generator.rs:751:13: Broken MIR: generator contains type Pin<Box<dyn Future<Output = std::result::Result<(), std::io::Error>>   Send>> in MIR, but typeck only knows about for<'r, 's, 't0> {ResumeTy, &'r F, Request<State>, Next<'s, State>, Pin<Box<(dyn Future<Output = std::result::Result<(), std::io::Error>>   Send   't0)>>, ()}
Backtrace

warning: function is never used: `main`
  --> src/lib.rs:39:4
   |
39 | fn main() {
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_mir/src/transform/generator.rs:751:13: Broken MIR: generator contains type Pin<Box<dyn Future<Output = std::result::Result<(), std::io::Error>>   Send>> in MIR, but typeck only knows about for<'r, 's, 't0> {ResumeTy, &'r F, Request<State>, Next<'s, State>, Pin<Box<(dyn Future<Output = std::result::Result<(), std::io::Error>>   Send   't0)>>, ()}
  --> src/lib.rs:34:89
   |
34 |       async fn handle(&self, req: Request<State>, next: Next<'_, State>) -> crate::Result {
   |  _________________________________________________________________________________________^
35 | |         (self)(req, next).await
36 | |     }
   | |_____^

thread 'rustc' panicked at 'Box<Any>', /rustc/c051c5ddda79f45fad196ca3a4690251e377d043/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug, I-ICE, T-compiler&template=ice.md

note: rustc 1.53.0-nightly (c051c5ddd 2021-04-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at src/lib.rs:23:1: 37:2>::handle::{closure#0}`
#1 [layout_raw] computing layout of `[static generator@src/lib.rs:34:89: 36:6 for<'r, 's, 't0> {std::future::ResumeTy, &'r F, Request<State>, Next<'s, State>, std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = std::result::Result<(), std::io::Error>>   std::marker::Send   't0)>>, ()}]`
end of query stack
error: aborting due to previous error; 1 warning emitted

error: could not compile `playground`

To learn more, run the command again with --verbose.

@utherpally utherpally 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 Apr 7, 2021
@SNCPlay42
Copy link
Contributor

Duplicate of #83737

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

3 participants