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

Missing filename and line number in error #811

Closed
jminer opened this issue Nov 3, 2018 · 11 comments
Closed

Missing filename and line number in error #811

jminer opened this issue Nov 3, 2018 · 11 comments
Labels
upstream An unresolvable issue: an upstream dependency bug
Milestone

Comments

@jminer
Copy link

jminer commented Nov 3, 2018

I don't know if this is a rustc bug or Rocket bug, but since it is happening with a Rocket macro, I thought I'd start here. While updating Rocket to the newest version, I ran into a compile error with no file or line number.

Newest Rocket from git (983ee9b)
Windows 10 64-bit
Rust nightly 8b096314a 2018-11-02
This issue also happened with the Rocket and rustc from a week ago.

#![feature(proc_macro_hygiene, decl_macro)]

use rocket::request::Form};
use rocket::response::content::Plain

#[macro_use]
extern crate rocket;

fn main() {
    rocket::ignite()
        .mount("/", routes![create_account_post])
        .launch();
}

fn create_user(email: &str) -> Result<(), ()> {
    Ok(())
}

#[derive(FromForm)]
struct CreateAccountForm {
    email: String,
}

#[post("/create-account", data = "<form>")]
fn create_account_post(form: Form<CreateAccountForm>) -> Plain<String> {
    let f = form.get();
    match create_user(&f.email) {
        Err(()) => {
            return Plain("".into());
        },
        res @ _ => res.unwrap(),
    }

    Plain("".into())
}

I get this error

error[E0599]: no method named `get` found for type `rocket::request::Form<CreateAccountForm>` in the current scope
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following traits define an item `get`, perhaps you need to implement one of them:
          candidate #1: `core::panic::BoxMeUp`
          candidate #2: `std::slice::SliceIndex`

which does not include the file or line number of the error. I've tried making some changes like removing the match so I'm ignoring the return value of create_user(), and then I do get file and line number. But with the code as is, it seems all errors in the function are missing file and line.

@jebrosen
Copy link
Collaborator

jebrosen commented Nov 3, 2018

Removing the curly braces around the Err(()) arm appears to restore the proper error message.

Furthermore, this appears with RUST_LOG=syntax :

INFO 2018-11-03T20:00:13Z: syntax::parse::token: cached tokens found, but they're not "probably equal", going with stringified version

Given that, I'm going to assume for now that this is caused by or similar to rust-lang/rust#43081.

As for resolving the error, match create_user(&form.email) should work.

@jebrosen jebrosen added the upstream An unresolvable issue: an upstream dependency bug label Nov 3, 2018
@SergioBenitez SergioBenitez added this to the 0.5.0 milestone Nov 12, 2018
@MetallicCloud
Copy link

Just to +1 onto this, I've recently been upgrading to 0.4, and it's been a bit of a nightmare, because I have dozens of errors with no indication of where they are coming from. I've had to resort to having a separate impl function for each route I have, just so I can find the issues. ie.:


#[get("/login")]
fn user_login(login_context: LoginContext) -> RouteResult {
    user_login_impl(login_context)
}

fn user_login_impl(login_context: LoginContext) -> RouteResult {
 ...
}

@SergioBenitez
Copy link
Member

@MetallicCloud Please report the source that resulted in losing spans. That'll help resolve this issue upstream.

@SergioBenitez SergioBenitez modified the milestones: 0.5.0, 0.4.0 Nov 14, 2018
@MetallicCloud
Copy link

@SergioBenitez Hmm, I don't know how hopeful this is going to be. I've been trying to come up with a minimum reproducible set of code, however the issue keeps moving. For instance, in the code below I've moved RouteResult::Redirect from a String to rocket::http::uri::Origin for 0.4 (note user_login)...

pub enum RouteResult {
   Template(String, Option<serde_json::value::Value>),
   Redirect(rocket::http::uri::Origin<'static>),
   Error(Status),
}

#[get("/login")]
fn user_login(login_context: LoginContext) -> RouteResult {
    if login_context.user.is_some() {
        RouteResult::Redirect("/".to_string())
    }
    else {
        let fake = "";
        RouteResult::create_template("login", fake)
    }
}

I get the vague error:

error[E0308]: mismatched types
  |
  = note: expected type `rocket::http::uri::Origin<'static>`
             found type `std::string::String`

However I had to go back a few commits to get that unspecific error. I've spent days moving to 0.4 and finally have it compiling, so when I replaced my impl solution with the above code in user_login, I got the error with the proper line number. I spent a bit of time trying to slowly undo my changes until I got the error without the line number, but there have been a lot, and I couldn't narrow it down.

@jebrosen
Copy link
Collaborator

Do you geta better error message if you join the else with the { on the following line, as in } else {?

@MetallicCloud
Copy link

@jebrosen No, that doesn't help. But I've seen it depend on the contents of the block. For instance, changing seemingly unrelated other parts of the code makes the above give the line number, however if I get it showing the line number, then replace the above else block with

let params = LoginContext::new();
 RouteResult::create_template("login", params)

It stops working again.

@SergioBenitez
Copy link
Member

@MetallicCloud @jminer Can you try the latest nightly and report whether you get the correct diagnostic output?

@SergioBenitez
Copy link
Member

I've confirmed that the original report is now resolved upstream by rust-lang/rust#55971. @MetallicCloud I'd bet your issues are resolved as well, but if you spot any more issues like this, please do report them!

@MetallicCloud
Copy link

Sorry for the slow response. Yep, good as gold now. Thanks!

@lroux-at-jellysmack
Copy link

Hi, I'm commenting on this old issue because the issue reappeared,

I experience this with rocket 0.4.5 and 0.4.6(haven't tried older versions) since I started to develop my project (approx. 2months).
The compiler completely looses track of the error locations with the functions that have rocket attribute macros on them, which is very annoying when hunting an error.

Do you know what can be causing that ?

Thanks

@jebrosen
Copy link
Collaborator

@lroux-at-jellysmack It's a bug in rustc with proc_macro attributes when code is formatted in certain ways; see #1456 for a more recent example and discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream An unresolvable issue: an upstream dependency bug
Projects
None yet
Development

No branches or pull requests

5 participants