Change:
This argument list is slowly getting out of hand. Maybe we should create a builder pattern struct that doesn't require most calls to use ? Anyway, pre-existing, if you rather open an issue about it than fix it here, I'm fine with merging this PR Originally posted by in
modify labels: +A-driver +C-cleanup +T-compiler
I would like to give this a try if mentoring is available
I'll be happy to mentor, but we should wait for to get merged, because any change you do will conflict with that PR. Though you can start by basing your change on top of that PR. You will need to modify each place that is modified in that PR, so keep it bookmarked and look at it whenever you end up wondering what you may need to touch. The root change to do is to make private and add a new struct right next to it. That new struct should have a field for every parameter of the function and an inherent method () that just forwards all these fields to . You'll need a method that takes only the non- fields as parameters and creates a new instance of your builder struct with those fileds initialized and the rest set to . Then you'll need a method for each field to be able to set it. After adjusting all the callsites and everything compiles again, you should make a commit and put all follow-up changes in separate commits. As a follow up change you can make take the struct as an argument instead of all the fields individually. You can then destructure the struct in the body of to get all the fields out. There may be other things that you may notice while implementing this change that could be optimized, idk, but we can close this issue after the above changes.
Hi I was trying to get my hands on this. But since Optional fields can't be copied to runcompile, how can I pass those fields to ?. Here is code change that you suggested. I could technically replace to accept references instead of values but that will require the entire function to refactor, and I am not sure I can do that. Am I doing it wrong? What alternative I can take to get this issue fixed?
can take instead of .
Thanks just been away from rust for like 15 days and completely forgot I can do that. one more thing. was also used in miri and rls submodules. Do I need to make a pull request there for the changes. Thanks.
Once (beta branching) is merged it is fine for miri and rls to break. Submitting a PR there is nice, but not necessary. The respective maintainers are normally the ones to fix them again.

Discussion:
Registry::new(&rustc_error_codes::DIAGNOSTICS) } <ins> pub struct RunCompiler<'a, 'b> { at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send), file_loader: Option<Box<dyn FileLoader + Send + Sync>>, emitter: Option<Box<dyn Write + Send>>, make_codegen_backend: Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>, } impl<'a, 'b> RunCompiler<'a, 'b> { pub fn new(at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send)) -> Self { Self { at_args, callbacks, file_loader: None, emitter: None, make_codegen_backend: None } } pub fn set_make_codegen_backend( &mut self, make_codegen_backend: Option< Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>, >, ) -> &mut Self { self.make_codegen_backend = make_codegen_backend; self } pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &mut Self { self.emitter = emitter; self } pub fn set_file_loader( &mut self, file_loader: Option<Box<dyn FileLoader + Send + Sync>>, ) -> &mut Self { self.file_loader = file_loader; self } pub fn run(self) -> interface::Result<()> { run_compiler( self.at_args, self.callbacks, self.file_loader, self.emitter, self.make_codegen_backend, ) } } </ins> // Parse args and run the compiler. This is the primary entry point for rustc. // The FileLoader provides a way to load files from sources other than the file system. <del> pub fn run_compiler( </del> <ins> fn run_compiler( </ins> at_args: &[String], callbacks: &mut (dyn Callbacks + Send), file_loader: Option<Box<dyn FileLoader + Send + Sync>>,

}) }) .collect::<Vec<_>>(); <del> run_compiler(&args, &mut callbacks, None, None, None) </del> <ins> RunCompiler::new(&args, &mut callbacks).run() </ins> }); // The extra `t` is necessary to align this label with the others. print_time_passes_entry(callbacks.time_passes, "ttotal", start.elapsed());

let mut count = 1; let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()]; rustc_driver::catch_fatal_errors(|| { <del> rustc_driver::run_compiler( &args, &mut TestCalls { count: &mut count }, None, None, None, ).ok(); }).ok(); </del> <ins> rustc_driver::RunCompiler::new(&args, &mut TestCalls { count: &mut count }).run().ok(); }) .ok(); </ins> assert_eq!(count, 2); }

args.extend(vec!["--sysroot".into(), sys_root]); }; <del> return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None, None); </del> <ins> return rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); </ins> } if orig_args.iter().any(|a| a == "--version" || a == "-V") {

let mut default = DefaultCallbacks; let callbacks: &mut (dyn rustc_driver::Callbacks + Send) = if clippy_enabled { &mut clippy } else { &mut default }; <del> rustc_driver::run_compiler(&args, callbacks, None, None, None) </del> <ins> rustc_driver::RunCompiler::new(&args, callbacks).run() </ins> })) }