Repository navigation
Handle macro_use prelude - #5105
Merged
Merged
Conversation
P-E-P
force-pushed
the
extended_testsuite
branch
from
November 23, 2026 12:55
8febd62 to
78bdb99
Compare
P-E-P
force-pushed
the
extended_testsuite
branch
3 times, most recently
from
November 23, 2026 15:39
7f14751 to
bb74379
Compare
CohenArthur
reviewed
Nov 23, 2026
P-E-P
force-pushed
the
extended_testsuite
branch
4 times, most recently
from
November 27, 2026 13:56
ba7c5e4 to
e7b5d90
Compare
Macros from extern crate should be accessible, their identifier should be brought into scope as shadowable identifiers when using the macro_use attribute. gcc/rust/ChangeLog: * expand/rust-extern-crate-loader.cc (ExternCrateLoaderVisitor::visit): Identify macro_use on extern crates. * resolve/rust-forever-stack.h: Add macro_use prelude to forever stack. Add function to add macros to the macro_use prelude. * resolve/rust-forever-stack.hxx: Add macros to macro_use prelude and dump macro_use prelude. * resolve/rust-name-resolution-context.cc (NameResolutionContext::NameResolutionContext): Initialize prelude. (NameResolutionContext::merge): Add all extern crate macros to macro_use prelude when the macro_use attribute is used. * resolve/rust-name-resolution-context.h: Add macro_use_prelude node. * rust-session-manager.cc (Session::expansion): Forward macro_use attribute status. (Session::load_extern_crate): Likewise. * rust-session-manager.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
P-E-P
force-pushed
the
extended_testsuite
branch
2 times, most recently
from
November 27, 2026 14:23
dbe231a to
920bf21
Compare
P-E-P
marked this pull request as ready for review
November 27, 2026 14:24
Macros imported from extern crates using the macro_use prelude should be resolved and remain shadowable, and thus be resolved after all other namespaces. gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Add function prototype. * resolve/rust-forever-stack.hxx: Add function to retrieve identifier from macro_use prelude. * resolve/rust-name-resolution-context.hxx: Lookup macro_use prelude when everything else has failed. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
We need macros from both the std lib as well as the core library. In order to do so we need to add the macro_use attribute on their declaration. gcc/rust/ChangeLog: * ast/rust-ast.cc (Crate::inject_extern_crate): Inject the macro_use attribute when injecting the crate. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
gcc/testsuite/ChangeLog: * rust/minicore/build_error.rs: New test. * rust/minicore/build_error_core/lib.rs: New test. * rust/minicore/compiler_builtins.rs: New test. * rust/minicore/compiler_builtins_core/lib.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
gcc/rust/ChangeLog: * expand/rust-extern-crate-loader.cc (ExternCrateLoaderVisitor::visit): Use explicit MacroUse enum instead of boolean. * resolve/rust-name-resolution-context.cc (NameResolutionContext::merge): Likewise. * resolve/rust-name-resolution-context.h: Likewise. * rust-session-manager.cc (Session::load_extern_crate): Likewise. * rust-session-manager.h: Likewise. * rust-load-crate.h: New file with MacroUse definition. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
P-E-P
force-pushed
the
extended_testsuite
branch
from
November 27, 2026 14:55
920bf21 to
b43f388
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
External crates may use the
#[macro_use]attribute to bring their macros within the crate's scope. This allow macro call within a crate without specifying its canonical path within the external crate name.This is achieved using the
macro_useprelude.