diff --git a/Cargo.lock b/Cargo.lock index 6f7a309894ca5..e54dba588c013 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4222,6 +4222,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_messages", "rustc_errors", + "rustc_expand", "rustc_feature", "rustc_fluent_macro", "rustc_graphviz", diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 8ace560d85d16..737c0509333ee 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -40,6 +40,7 @@ pub fn provide(providers: &mut Providers) { providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; providers.eval_static_initializer = const_eval::eval_static_initializer_provider; providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider; + providers.hooks.after_register_builtin_macros = |_, _| {}; providers.eval_to_valtree = |tcx, ty::PseudoCanonicalInput { typing_env, value }| { const_eval::eval_to_valtree(tcx, typing_env, value) }; diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index f2c150715329d..490d5648baed2 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1,5 +1,6 @@ use std::any::Any; use std::default::Default; +use std::fmt::Debug; use std::iter; use std::path::Component::Prefix; use std::path::{Path, PathBuf}; @@ -1090,7 +1091,7 @@ pub struct DeriveResolution { pub is_const: bool, } -pub trait ResolverExpand { +pub trait ResolverExpand: Debug { fn next_node_id(&mut self) -> NodeId; fn invocation_parent(&self, id: LocalExpnId) -> LocalDefId; @@ -1101,6 +1102,7 @@ pub trait ResolverExpand { fragment: &AstFragment, ); fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind); + fn override_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind); fn expansion_for_ast_pass( &mut self, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 3ba224723e365..4e0324b47fcfc 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -140,6 +140,7 @@ fn configure_and_expand( crate_name, ); rustc_builtin_macros::register_builtin_macros(resolver); + tcx.after_register_builtin_macros(resolver); let num_standard_library_imports = sess.time("crate_injection", || { rustc_builtin_macros::standard_library_imports::inject( diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index fbcce16cedca8..53614e006dd1a 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -17,6 +17,7 @@ rustc_ast_ir = { path = "../rustc_ast_ir" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links rustc_errors = { path = "../rustc_errors" } +rustc_expand = { path = "../rustc_expand" } rustc_feature = { path = "../rustc_feature" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_graphviz = { path = "../rustc_graphviz" } diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs index 9d2f0a4523713..742119a7dd694 100644 --- a/compiler/rustc_middle/src/hooks/mod.rs +++ b/compiler/rustc_middle/src/hooks/mod.rs @@ -88,6 +88,8 @@ declare_hooks! { hook alloc_self_profile_query_strings() -> (); + hook after_register_builtin_macros(resolver: &mut dyn rustc_expand::base::ResolverExpand) -> (); + /// Saves and writes the DepGraph to the file system. /// /// This function saves both the dep-graph and the query result cache, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 2063c46124c29..4f3f346ce82dd 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1280,6 +1280,12 @@ pub struct Resolver<'ra, 'tcx> { impl_trait_names: FxHashMap, } +impl std::fmt::Debug for Resolver<'_, '_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Resolver").finish_non_exhaustive() + } +} + /// This provides memory for the rest of the crate. The `'ra` lifetime that is /// used by many types in this crate is an abbreviation of `ResolverArenas`. #[derive(Default)] diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 72ed899024168..3fd42c89d3c44 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -203,6 +203,10 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { } } + fn override_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) { + self.builtin_macros.insert(name, ext); + } + // Create a new Expansion with a definition site of the provided module, or // a fake empty `#[no_implicit_prelude]` module if no module is provided. fn expansion_for_ast_pass(