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

Error location of compilation error is missing if code is inside a rocket route handler #1456

Closed
phideg opened this issue Oct 25, 2020 · 4 comments
Labels
deficiency Something doesn't work as well as it could upstream An unresolvable issue: an upstream dependency bug

Comments

@phideg
Copy link

phideg commented Oct 25, 2020

Bug Report

Version of Rocket
master (using stable Rust compiler rustc 1.47.0)

Operating system
windows (but also occurs on Linux)

Brief description of the bug
The diagnostic output (error location) of a compilation error is missing. The compilation error must be located inside the handler of a rocket route (only tested with attribute "get" so far). The code also must contain a closure. I would have expected the rust compiler to print the diagnostic details (the source code span where the error is located).

How to reproduce the issue
I could only reproduce the issue with the Rust stable compiler.

use rocket::{get, routes};
use tokio::runtime::Runtime;
 
fn test() -> u8 {
    0
}
 
pub fn bar(
    aggregate: impl Fn(u32),
) { }
 
#[get("/foo")]
fn foo() {
    let mut test = 0;
    test = test();
    bar(&|_: u32| {});
}
 
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut rt = Runtime::new()?;
    rt.block_on(
        rocket::ignite()
            .mount("/", routes![foo])
            .launch(),
    );
    Ok(())
}
PS C:\projects\rust\rocket_bug> cargo build
   Compiling rocket_bug v0.1.0 (C:\projects\rust\rocket_bug)
error[E0618]: expected function, found `{integer}`

error: aborting due to previous error

The rust nightly compiler will show the expected output:

PS C:\projects\rust\rocket_bug> rustup override set nightly
info: using existing install for 'nightly-x86_64-pc-windows-msvc'
info: override toolchain for 'C:\projects\rust\rocket_bug' set to 'nightly-x86_64-pc-windows-msvc'

  nightly-x86_64-pc-windows-msvc unchanged - rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)

PS C:\projects\rust\rocket_bug> cargo build
   Compiling rocket_bug v0.1.0 (C:\projects\rust\rocket_bug)
error[E0618]: expected function, found `{integer}`
  --> src\main.rs:15:12
   |
14 |     let mut test = 0;
   |         -------- `{integer}` defined here
15 |     test = test();
   |            ^^^^--
   |            |
   |            call expression requires function

error: aborting due to previous error

Ideas, if any, about what Rocket is doing incorrectly
I first thought it might be due to the rocket codegen. But it seems it is a Rust compiler bug. With the nightly compiler the issue can not be reproduced.

General Comments

So far I wasn't able to determine the corresponding commit that seems to fix the issue in rust nightly. Still I thought it would be worth reporting as maybe also others are running into that issue.

@SergioBenitez
Copy link
Member

That's rather unfortunate.

How does beta react?

@SergioBenitez SergioBenitez added the deficiency Something doesn't work as well as it could label Oct 30, 2020
@jebrosen
Copy link
Collaborator

I get the same on both stable and beta.

With the nightly compiler the issue can not be reproduced.

This kind of issue is almost always caused by rust-lang/rust#43081 or one of the related issues. This particular case might have been fixed by rust-lang/rust#77135 which landed around one month ago in nightly. &|...| {...} is actually in one of the test cases for that PR; the following change in the foo() function restores the error message on stable and on beta:

    bar(&(|_: u32| {}));

With this bug, I think there's generally nothing we can do besides waiting for the fixes to make it into the stable compiler. The information that eventually leads to the missing error information is lost before the input is passed to Rocket, with no reasonable way for rocket_codegen to reconstruct or work around it.

@jebrosen jebrosen added the upstream An unresolvable issue: an upstream dependency bug label Oct 30, 2020
@phideg
Copy link
Author

phideg commented Nov 1, 2020

@jebrosen thx for taking care of it.

@SergioBenitez
Copy link
Member

Since this is resolved in nightly, upstream is fixed, and the fixes should eventually make their way to stable. As such, I'm closing this issue as it is as "resolved" as it can be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deficiency Something doesn't work as well as it could upstream An unresolvable issue: an upstream dependency bug
Projects
None yet
Development

No branches or pull requests

3 participants