Skip to content

Do not apply #[macro_use] to implicitly injected extern crate std;, use standard library prelude instead #53977

Description

@petrochenkov

Macros like vec or println are currently automatically available to user code through injected standard library

#[macro_use]
extern crate std;

#[macro_use] puts all the macro names into macro prelude, so they are available in inner modules without additional imports.

It would be good to avoid this, especially given that #[macro_use] is going to be gradually deprecated.
We have analogous way to put things into prelude for non-macro namespaces - standard library prelude std::prelude::v1, all stable library macros can be reexported through it instead of #[macro_use] in backward-compatible way.
Undesirable unstable macros like select can be removed from prelude in the process.

The only issue is that several imports for several macros (env, vec, panic) would also import corresponding modules from the standard library (std::env, std::vec, std::panic) and put them into prelude. This is certainly not desirable.

The solution is to come up with some way for a use item to import the name only in the single selected namespace, something like

use a::b in type;
use a::b in macro;
use a::b in value;

Alternatively, this can be done with hacks for cross-crate scenarios (stdlib prelude is indeed a cross-crate scenario).

(All of this is applicable to libcore as well.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyI-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE]

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions