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

Errors inside a macro invocation don't report the full location of the error #5794

Closed
erickt opened this issue Apr 9, 2013 · 5 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-syntaxext Area: Syntax extensions

Comments

@erickt
Copy link
Contributor

erickt commented Apr 9, 2013

It seems the debug! code isn't properly pushing a span onto the macro expansion span stack. This code:

fn main() {
    let a = ~"";
    debug!("foo: %s %s", a);
}

Only reports the error inside the macro, but not where that macro is getting used:

<core-macros>:33:24: 33:42 error: not enough arguments to fmt! for the given format string
<core-macros>:33             __log(4u32, fmt!( $($arg),+ ))
                                         ^~~~~~~~~~~~~~~~~~
@alexcrichton
Copy link
Member

Nominating for production-ready

@huonw
Copy link
Member

huonw commented Aug 14, 2013

Triage visit: still valid, but this isn't at all specific to debug! or even the built-in macros (adjusting the title):

macro_rules! my_fmt {
    ($s:expr, $($e:expr),*) => {
        fmt!($s, $($e),*)
    }
}

fn main() {
    let a = ~"";
    my_fmt!("foo: %s %s", a);
}
5794.rs:3:8: 3:25 error: not enough arguments to fmt! for the given format string
5794.rs:3         fmt!($s, $($e),*)
                  ^~~~~~~~~~~~~~~~~

It's hard to see how this would be resolved in general, since some of the time the errors will be caused by something internal to the macro (e.g. => fmt!("%s %s", $e) in a macro body); possibly putting a note on the invocation of any macros that have errors, e.g.:

macro_rules! my_fmt {
    ($s:expr, $($e:expr),*) => {
        fmt!($s, $($e),*) // error: not enough arguments to fmt! ...
    }
}

fn main() {
    let a = ~"";
    my_fmt!("foo: %s %s", a); // note: macro invoked here
}

@graydon
Copy link
Contributor

graydon commented Aug 22, 2013

accepted for production-ready milestone

@alexcrichton
Copy link
Member

@jbclements, you were working in macros recently, do you have any idea what this would entail to fix? Right now @huonw and I are thinking that this should block #9153 because the error spans are so terrible.

@jbclements
Copy link
Contributor

duplicating comment from IRC, I think it might help a lot just to include the arguments to the macro that failed.

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 26, 2024
…, r=blyxyas

Extend `NONMINIMAL_BOOL` lint

Fixes rust-lang#5794.

r? `@blyxyas`

changelog: Extend `NONMINIMAL_BOOL` lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-syntaxext Area: Syntax extensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants