Skip to content

Commit 851d9a5

Browse files
committed
Remove set_make_codegen_backend and set_file_loader
They can both be set inside the config callback too.
1 parent ad0c0fc commit 851d9a5

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

examples/rustc-driver-example.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::Path;
1919
use rustc_ast_pretty::pprust::item_to_string;
2020
use rustc_data_structures::sync::Lrc;
2121
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -51,6 +51,10 @@ fn main() {
5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
@@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
8387
}
8488

8589
fn main() {
86-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
87-
mut compiler => {
88-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
89-
compiler.run();
90-
}
91-
}
90+
RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks).run();
9291
}

examples/rustc-driver-interacting-with-the-ast.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::Path;
1919
use rustc_ast_pretty::pprust::item_to_string;
2020
use rustc_data_structures::sync::Lrc;
2121
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -51,6 +51,10 @@ fn main() {
5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
@@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
9094
}
9195

9296
fn main() {
93-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
94-
mut compiler => {
95-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
96-
compiler.run();
97-
}
98-
}
97+
RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks).run();
9998
}

0 commit comments

Comments
 (0)