Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4222,6 +4222,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_messages",
"rustc_errors",
"rustc_expand",
"rustc_feature",
"rustc_fluent_macro",
"rustc_graphviz",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = |_, _| {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this have to do with const-eval...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, nothing lol. I was trying to figure out which crate's provide() function a default implementation should go under, and am not very familiar with the compiler's layout. Is this the right way to do that, and if so which provide() would be the right one to add it to?

Copy link
Member

@RalfJung RalfJung Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which provide() would be the right one to add it to?

I'm not sure either, I'm just a const-eval maintainer and was confused about what showed up on "my turf" here. ;)

Something that deals with macros, probably... or rustc_middle if nothing else fits, I guess.

providers.eval_to_valtree = |tcx, ty::PseudoCanonicalInput { typing_env, value }| {
const_eval::eval_to_valtree(tcx, typing_env, value)
};
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,12 @@ pub struct Resolver<'ra, 'tcx> {
impl_trait_names: FxHashMap<NodeId, Symbol>,
}

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)]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading