Rust: Cannot import macros from extern crate with `use` in edition 2018

Created on 28 Sep 2018  路  1Comment  路  Source: rust-lang/rust

#![deny(rust_2018_idioms)]

// works
// #[macro_use]
// extern crate clap; // 2.32.0

// err
use clap::app_from_crate;

fn main() {
  app_from_crate!();
}

Err:

error: cannot find macro `crate_name!` in this scope
  --> src/main.rs:11:3
   |
11 |   app_from_crate!();
   |   ^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: cannot find macro `crate_version!` in this scope
  --> src/main.rs:11:3
   |
11 |   app_from_crate!();
   |   ^^^^^^^^^^^^^^^^^^ help: you could try the macro: `rustc_version`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: cannot find macro `crate_authors!` in this scope
  --> src/main.rs:11:3
   |
11 |   app_from_crate!();
   |   ^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

playground


And it's kind of strange that rustc won't complain about unidiomatic extern crate ... even #![deny(rust_2018_idioms)] in the working one.
cc @petrochenkov

A-macros-2.0

Most helpful comment

This is not an issue in rustc, clap just doesn't use $crate::crate_name! or #[macro_export(local_inner_macros)], so you have to continue using #[macro_use] or to import all the helper macros by yourself:

`use clap::{app_from_crate, crate_name, crate_version, crate_authors}`

or

use clap::*;

>All comments

This is not an issue in rustc, clap just doesn't use $crate::crate_name! or #[macro_export(local_inner_macros)], so you have to continue using #[macro_use] or to import all the helper macros by yourself:

`use clap::{app_from_crate, crate_name, crate_version, crate_authors}`

or

use clap::*;
Was this page helpful?
0 / 5 - 0 ratings