Skip to content

Commit c941b1c

Browse files
authored
Rollup merge of #136214 - momvart:driver_callback_crate_mut, r=bjorn3
Make crate AST mutation accessible for driver callback Following #134130, this brings back the ability to mutate AST before lowering.
2 parents 1f6a9aa + 5dfe0f8 commit c941b1c

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Diff for: compiler/rustc_driver_impl/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub trait Callbacks {
160160
fn after_crate_root_parsing(
161161
&mut self,
162162
_compiler: &interface::Compiler,
163-
_queries: &ast::Crate,
163+
_krate: &mut ast::Crate,
164164
) -> Compilation {
165165
Compilation::Continue
166166
}
@@ -311,7 +311,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
311311

312312
// Parse the crate root source code (doesn't parse submodules yet)
313313
// Everything else is parsed during macro expansion.
314-
let krate = passes::parse(sess);
314+
let mut krate = passes::parse(sess);
315315

316316
// If pretty printing is requested: Figure out the representation, print it and exit
317317
if let Some(pp_mode) = sess.opts.pretty {
@@ -328,7 +328,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
328328
return early_exit();
329329
}
330330

331-
if callbacks.after_crate_root_parsing(compiler, &krate) == Compilation::Stop {
331+
if callbacks.after_crate_root_parsing(compiler, &mut krate) == Compilation::Stop {
332332
return early_exit();
333333
}
334334

Diff for: src/doc/rustc-dev-guide/examples/rustc-driver-example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
5858
fn after_crate_root_parsing(
5959
&mut self,
6060
_compiler: &Compiler,
61-
krate: &rustc_ast::Crate,
61+
krate: &mut rustc_ast::Crate,
6262
) -> Compilation {
6363
for item in &krate.items {
6464
println!("{}", item_to_string(&item));

Diff for: src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
5858
fn after_crate_root_parsing(
5959
&mut self,
6060
_compiler: &Compiler,
61-
krate: &rustc_ast::Crate,
61+
krate: &mut rustc_ast::Crate,
6262
) -> Compilation {
6363
for item in &krate.items {
6464
println!("{}", item_to_string(&item));

0 commit comments

Comments
 (0)