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

file!, line! and col! (and possibly module!) do the Wrong Thing. #3066

Closed
paulstansifer opened this issue Jul 31, 2012 · 8 comments
Closed
Labels
A-syntaxext Area: Syntax extensions E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@paulstansifer
Copy link
Contributor

In the following code, the error message refers to the location of the macro calls at HERE, not NOTHERE. I think this (a) isn't what happens in C, etc., and (b) is never useful.

Fixing this should be a simple mater of getting the syntax backtrace from cx in source_util.rs and finding the topmost span, and ignoring the span that's temptingly passed in as an argument. Except that the results won't be any different until #3065 is fixed.

macro_rules! my_complex_macro {
    { } => {
        fmt!("You invoked the macro wrong! (%s:%u:%u)",
             file!(), line!(), col!()) //HERE
    }
}

fn main() {
    io::println(my_complex_macro!()); //NOT HERE
}
@paulstansifer
Copy link
Contributor Author

Add the following to the last list of syntax extensions in the syntax extensions section in rust.md when this bug is fixed:

* `line!`, `col!`, `file!`, `module_path!` : produce a string containing the
given source location information, relative to the starting location of
expansion

@catamorphism
Copy link
Contributor

Blocked by #3065, de-milestoning

@catamorphism
Copy link
Contributor

Nominating for milestone 5, production-ready

@graydon
Copy link
Contributor

graydon commented Jun 13, 2013

accepted for production-ready milestone

@graydon
Copy link
Contributor

graydon commented Jul 11, 2013

I'm confused, I think #4888 fixed this. I don't understand the statement above that #3065 blocks this. Why?

@catamorphism
Copy link
Contributor

@graydon -- in the original issue, @paulstansifer said "the results won't be any different until #3065 is fixed." Maybe he will see this and explain why.

@paulstansifer
Copy link
Contributor Author

#3065 is about making sure the syntactic backtrace (in expn_info) is correctly populated in the case of new-style macros. Perhaps that has gotten fixed somewhere along the line? Unfortunately, I don't have time right now to test the relevant examples. But if the example in the body of the bug report does work, I am comfortable declaring this bug fixed, because I can't imagine it being fixed only halfway.

@pnkfelix
Copy link
Member

I just ran the example from reported in this bug, and the emitted message points to the line with "NOT HERE":

% /tmp/ldemo
You invoked the macro wrong! (/tmp/ldemo.rs:9:12)

So I'm closing this bug.

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants