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

#[macro_use(info)] raise error: macro undefined: 'log!' #54

Closed
Narann opened this issue Aug 14, 2015 · 7 comments · Fixed by #288
Closed

#[macro_use(info)] raise error: macro undefined: 'log!' #54

Narann opened this issue Aug 14, 2015 · 7 comments · Fixed by #288

Comments

@Narann
Copy link

Narann commented Aug 14, 2015

Code:

#[macro_use(info)]
extern crate log;

Error:

<log macros>:4:1: 4:4 error: macro undefined: 'log!'
<log macros>:4 log ! ( $ crate:: LogLevel:: Info , $ ( $ arg ) * ) ; )
               ^~~

I will use #[macro_use] for now but I thought it was interesting to limit the macro to import in the namespace

$rustc --version
rustc 1.1.0-dev
@Amanieu
Copy link
Member

Amanieu commented Jan 18, 2016

The info, warn, error and trace macros all use the log macro internally, so just specifying #[macro_use(info, log)] should work.

@dtolnay
Copy link
Member

dtolnay commented May 13, 2017

This is annoying. Is there a way this could be handled better using $crate? Have info! expand to an #[inline(always)] #[doc(hidden)] helper rather than to log!.

@sfackler
Copy link
Member

log! needs to be a macro because it invokes file!, module_path! and line!. We could duplicate log!'s logic into info! etc which would avoid the import issue.

How many people actually selectively import log macros, though?

@dtolnay
Copy link
Member

dtolnay commented May 24, 2017

Relevant API guidelines issue: rust-lang/api-guidelines#68

@seanmonstar
Copy link

Rust issue: rust-lang/rust#25003

@mjkillough
Copy link

log! needs to be a macro because it invokes file!, module_path! and line!. We could duplicate log!'s logic into info! etc which would avoid the import issue.

The bulk of the log! macro could be moved into an inlined helper function which is used by the log!/error!/... macros, with each passing the output of file!/module_path!/line! in as arguments to the function. There wouldn't be much duplication, but the helper function would have to be part of the public API of the log crate, which is a little ugly.

However, I'd be tempted to just duplicate log!'s logic into the other macros. There isn't that much to it.

@richard-uk1
Copy link

richard-uk1 commented Aug 4, 2018

This is going to come up with Rust 2018 - because you now import macros, the info! macro will fail unless you also import the log! macro.

EDIT: I don't really see any way around the problem, unless the inner macro expansion happens before the macro is expanded in the consumer crate. Otherwise it's hard to support both versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants