Skip to content

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

@phideg

Description

@phideg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    deficiencySomething doesn't work as well as it couldupstreamAn unresolvable issue: an upstream dependency bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions