diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index fcd49f5d01567..d62d66af1f2db 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -35,9 +35,9 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr use rustc_session::cstore::MetadataLoader; use rustc_session::getopts; use rustc_session::lint::{Lint, LintId}; -use rustc_session::{config, DiagnosticOutput, Session}; +use rustc_session::{config, Session}; use rustc_session::{early_error, early_error_no_abort, early_warn}; -use rustc_span::source_map::{FileLoader, FileName}; +use rustc_span::source_map::FileName; use rustc_span::symbol::sym; use rustc_target::json::ToJson; @@ -139,76 +139,13 @@ pub fn diagnostics_registry() -> Registry { Registry::new(rustc_error_codes::DIAGNOSTICS) } -/// This is the primary entry point for rustc. -pub struct RunCompiler<'a, 'b> { - at_args: &'a [String], - callbacks: &'b mut (dyn Callbacks + Send), - file_loader: Option>, - emitter: Option>, - make_codegen_backend: - Option Box + 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 } - } - - /// Set a custom codegen backend. - /// - /// Used by cg_clif. - pub fn set_make_codegen_backend( - &mut self, - make_codegen_backend: Option< - Box Box + Send>, - >, - ) -> &mut Self { - self.make_codegen_backend = make_codegen_backend; - self - } - - /// Emit diagnostics to the specified location. - /// - /// Used by RLS. - pub fn set_emitter(&mut self, emitter: Option>) -> &mut Self { - self.emitter = emitter; - self - } - - /// Load files from sources other than the file system. - /// - /// Used by RLS. - pub fn set_file_loader( - &mut self, - file_loader: Option>, - ) -> &mut Self { - self.file_loader = file_loader; - self - } - - /// Parse args and run the compiler. - pub fn run(self) -> interface::Result<()> { - run_compiler( - self.at_args, - self.callbacks, - self.file_loader, - self.emitter, - self.make_codegen_backend, - ) - } -} -fn run_compiler( +// Primary entry point used by rustc, clippy, and miri. +pub fn run_compiler( at_args: &[String], callbacks: &mut (dyn Callbacks + Send), - file_loader: Option>, - emitter: Option>, - make_codegen_backend: Option< - Box Box + Send>, - >, ) -> interface::Result<()> { let args = args::arg_expand_all(at_args); - let diagnostic_output = emitter.map_or(DiagnosticOutput::Default, DiagnosticOutput::Raw); let Some(matches) = handle_options(&args) else { return Ok(()) }; let sopts = config::build_session_options(&matches); @@ -229,13 +166,10 @@ fn run_compiler( input_path: None, output_file: ofile, output_dir: odir, - file_loader, - diagnostic_output, lint_caps: Default::default(), parse_sess_created: None, register_lints: None, override_queries: None, - make_codegen_backend, registry: diagnostics_registry(), }; @@ -1371,7 +1305,7 @@ pub fn main() -> ! { }) }) .collect::>(); - RunCompiler::new(&args, &mut callbacks).run() + run_compiler(&args, &mut callbacks) }); if callbacks.time_passes { diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index 9002a24e42f9d..73f57d99247e5 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -4,7 +4,6 @@ use rustc_ast::{token, AttrVec, Attribute, Inline, Item, ModSpans}; use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed}; use rustc_parse::new_parser_from_file; use rustc_parse::validate_attr; -use rustc_session::parse::ParseSess; use rustc_session::Session; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; @@ -151,7 +150,7 @@ fn mod_file_path<'a>( DirOwnership::Owned { relative } => relative, DirOwnership::UnownedViaBlock => None, }; - let result = default_submod_path(&sess.parse_sess, ident, relative, dir_path); + let result = default_submod_path(ident, relative, dir_path); match dir_ownership { DirOwnership::Owned { .. } => result, DirOwnership::UnownedViaBlock => Err(ModError::ModInBlock(match result { @@ -201,7 +200,6 @@ fn mod_file_path_from_attr( /// Returns a path to a module. // Public for rustfmt usage. pub fn default_submod_path<'a>( - sess: &'a ParseSess, ident: Ident, relative: Option, dir_path: &Path, @@ -223,8 +221,8 @@ pub fn default_submod_path<'a>( format!("{}{}{}mod.rs", relative_prefix, ident.name, path::MAIN_SEPARATOR); let default_path = dir_path.join(&default_path_str); let secondary_path = dir_path.join(&secondary_path_str); - let default_exists = sess.source_map().file_exists(&default_path); - let secondary_exists = sess.source_map().file_exists(&secondary_path); + let default_exists = default_path.exists(); + let secondary_exists = secondary_path.exists(); match (default_exists, secondary_exists) { (true, false) => Ok(ModulePathSuccess { diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 949bd02ad6839..14886ad2eff8e 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -17,8 +17,8 @@ use rustc_session::config::{self, CheckCfg, ErrorOutputType, Input, OutputFilena use rustc_session::early_error; use rustc_session::lint; use rustc_session::parse::{CrateConfig, ParseSess}; -use rustc_session::{DiagnosticOutput, Session}; -use rustc_span::source_map::{FileLoader, FileName}; +use rustc_session::Session; +use rustc_span::source_map::FileName; use rustc_span::symbol::sym; use std::path::PathBuf; use std::result; @@ -246,8 +246,6 @@ pub struct Config { pub input_path: Option, pub output_dir: Option, pub output_file: Option, - pub file_loader: Option>, - pub diagnostic_output: DiagnosticOutput, pub lint_caps: FxHashMap, @@ -268,10 +266,6 @@ pub struct Config { pub override_queries: Option, - /// This is a callback from the driver that is called to create a codegen backend. - pub make_codegen_backend: - Option Box + Send>>, - /// Registry of diagnostics codes. pub registry: Registry, } @@ -284,11 +278,8 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R config.opts, config.crate_cfg, config.crate_check_cfg, - config.diagnostic_output, - config.file_loader, config.input_path.clone(), config.lint_caps, - config.make_codegen_backend, registry.clone(), ); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 2cd959689e6cf..3f13bb60f7937 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -17,7 +17,7 @@ use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, Switc use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; -use rustc_session::{build_session, getopts, DiagnosticOutput, Session}; +use rustc_session::{build_session, getopts, Session}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::symbol::sym; use rustc_span::SourceFileHashAlgorithm; @@ -40,16 +40,7 @@ fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) { let registry = registry::Registry::new(&[]); let (sessopts, cfg) = build_session_options_and_crate_config(matches); - let sess = build_session( - sessopts, - None, - None, - registry, - DiagnosticOutput::Default, - Default::default(), - None, - None, - ); + let sess = build_session(sessopts, None, None, registry, Default::default(), None); (sess, cfg) } diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index f7e70d355cf86..be55b47f8f624 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -18,10 +18,9 @@ use rustc_session::config::{self, CrateType}; use rustc_session::config::{ErrorOutputType, Input, OutputFilenames}; use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer}; use rustc_session::parse::CrateConfig; -use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session}; +use rustc_session::{early_error, filesearch, output, Session}; use rustc_span::edition::Edition; use rustc_span::lev_distance::find_best_match_for_name; -use rustc_span::source_map::FileLoader; use rustc_span::symbol::{sym, Symbol}; use std::env; use std::env::consts::{DLL_PREFIX, DLL_SUFFIX}; @@ -65,23 +64,14 @@ pub fn create_session( sopts: config::Options, cfg: FxHashSet<(String, Option)>, check_cfg: CheckCfg, - diagnostic_output: DiagnosticOutput, - file_loader: Option>, input_path: Option, lint_caps: FxHashMap, - make_codegen_backend: Option< - Box Box + Send>, - >, descriptions: Registry, ) -> (Lrc, Lrc>) { - let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend { - make_codegen_backend(&sopts) - } else { - get_codegen_backend( - &sopts.maybe_sysroot, - sopts.unstable_opts.codegen_backend.as_ref().map(|name| &name[..]), - ) - }; + let codegen_backend = get_codegen_backend( + &sopts.maybe_sysroot, + sopts.unstable_opts.codegen_backend.as_ref().map(|name| &name[..]), + ); // target_override is documented to be called before init(), so this is okay let target_override = codegen_backend.target_override(&sopts); @@ -99,16 +89,8 @@ pub fn create_session( } }; - let mut sess = session::build_session( - sopts, - input_path, - bundle, - descriptions, - diagnostic_output, - lint_caps, - file_loader, - target_override, - ); + let mut sess = + session::build_session(sopts, input_path, bundle, descriptions, lint_caps, target_override); codegen_backend.init(&sess); diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 59b544ce9eb83..293d2995114b8 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -33,7 +33,7 @@ use rustc_errors::{ use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; use rustc_span::edition::Edition; -use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMap, Span}; +use rustc_span::source_map::{SourceMap, Span}; use rustc_span::{sym, SourceFileHashAlgorithm, Symbol}; use rustc_target::asm::InlineAsmArch; use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel}; @@ -44,7 +44,6 @@ use rustc_target::spec::{ use std::cell::{self, RefCell}; use std::env; use std::fmt; -use std::io::Write; use std::ops::{Div, Mul}; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -1204,11 +1203,10 @@ fn default_emitter( source_map: Lrc, bundle: Option>, fallback_bundle: LazyFallbackBundle, - emitter_dest: Option>, ) -> Box { let macro_backtrace = sopts.unstable_opts.macro_backtrace; - match (sopts.error_format, emitter_dest) { - (config::ErrorOutputType::HumanReadable(kind), dst) => { + match sopts.error_format { + config::ErrorOutputType::HumanReadable(kind) => { let (short, color_config) = kind.unzip(); if let HumanReadableErrorType::AnnotateSnippet(_) = kind { @@ -1221,33 +1219,20 @@ fn default_emitter( ); Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing)) } else { - let emitter = match dst { - None => EmitterWriter::stderr( - color_config, - Some(source_map), - bundle, - fallback_bundle, - short, - sopts.unstable_opts.teach, - sopts.diagnostic_width, - macro_backtrace, - ), - Some(dst) => EmitterWriter::new( - dst, - Some(source_map), - bundle, - fallback_bundle, - short, - false, // no teach messages when writing to a buffer - false, // no colors when writing to a buffer - None, // no diagnostic width - macro_backtrace, - ), - }; + let emitter = EmitterWriter::stderr( + color_config, + Some(source_map), + bundle, + fallback_bundle, + short, + sopts.unstable_opts.teach, + sopts.diagnostic_width, + macro_backtrace, + ); Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing)) } } - (config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new( + config::ErrorOutputType::Json { pretty, json_rendered } => Box::new( JsonEmitter::stderr( Some(registry), source_map, @@ -1260,28 +1245,9 @@ fn default_emitter( ) .ui_testing(sopts.unstable_opts.ui_testing), ), - (config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new( - JsonEmitter::new( - dst, - Some(registry), - source_map, - bundle, - fallback_bundle, - pretty, - json_rendered, - sopts.diagnostic_width, - macro_backtrace, - ) - .ui_testing(sopts.unstable_opts.ui_testing), - ), } } -pub enum DiagnosticOutput { - Default, - Raw(Box), -} - // JUSTIFICATION: literally session construction #[allow(rustc::bad_opt_access)] pub fn build_session( @@ -1289,9 +1255,7 @@ pub fn build_session( local_crate_source_file: Option, bundle: Option>, registry: rustc_errors::registry::Registry, - diagnostics_output: DiagnosticOutput, driver_lint_caps: FxHashMap, - file_loader: Option>, target_override: Option, ) -> Session { // FIXME: This is not general enough to make the warning lint completely override @@ -1305,11 +1269,6 @@ pub fn build_session( let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow); let can_emit_warnings = !(warnings_allow || cap_lints_allow); - let write_dest = match diagnostics_output { - DiagnosticOutput::Default => None, - DiagnosticOutput::Raw(write) => Some(write), - }; - let sysroot = match &sopts.maybe_sysroot { Some(sysroot) => sysroot.clone(), None => filesearch::get_or_default_sysroot(), @@ -1324,7 +1283,6 @@ pub fn build_session( early_warn(sopts.error_format, &warning) } - let loader = file_loader.unwrap_or_else(|| Box::new(RealFileLoader)); let hash_kind = sopts.unstable_opts.src_hash_algorithm.unwrap_or_else(|| { if target_cfg.is_like_msvc { SourceFileHashAlgorithm::Sha1 @@ -1332,18 +1290,13 @@ pub fn build_session( SourceFileHashAlgorithm::Md5 } }); - let source_map = Lrc::new(SourceMap::with_file_loader_and_hash_kind( - loader, - sopts.file_path_mapping(), - hash_kind, - )); + let source_map = Lrc::new(SourceMap::with_hash_kind(sopts.file_path_mapping(), hash_kind)); let fallback_bundle = fallback_fluent_bundle( rustc_errors::DEFAULT_LOCALE_RESOURCES, sopts.unstable_opts.translate_directionality_markers, ); - let emitter = - default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle, write_dest); + let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle); let span_diagnostic = rustc_errors::Handler::with_emitter_and_flags( emitter, diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 4d94c92d3f2b1..21c481102c61a 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -94,28 +94,6 @@ pub fn dummy_spanned(t: T) -> Spanned { // SourceFile, MultiByteChar, FileName, FileLines // -/// An abstraction over the fs operations used by the Parser. -pub trait FileLoader { - /// Query the existence of a file. - fn file_exists(&self, path: &Path) -> bool; - - /// Read the contents of a UTF-8 file into memory. - fn read_file(&self, path: &Path) -> io::Result; -} - -/// A FileLoader that uses std::fs to load real files. -pub struct RealFileLoader; - -impl FileLoader for RealFileLoader { - fn file_exists(&self, path: &Path) -> bool { - path.exists() - } - - fn read_file(&self, path: &Path) -> io::Result { - fs::read_to_string(path) - } -} - /// This is a [SourceFile] identifier that is used to correlate source files between /// subsequent compilation sessions (which is something we need to do during /// incremental compilation). @@ -170,7 +148,6 @@ pub struct SourceMap { used_address_space: AtomicU32, files: RwLock, - file_loader: Box, // This is used to apply the file path remapping as specified via // `--remap-path-prefix` to all `SourceFile`s allocated within this `SourceMap`. path_mapping: FilePathMapping, @@ -181,22 +158,16 @@ pub struct SourceMap { impl SourceMap { pub fn new(path_mapping: FilePathMapping) -> SourceMap { - Self::with_file_loader_and_hash_kind( - Box::new(RealFileLoader), - path_mapping, - SourceFileHashAlgorithm::Md5, - ) + Self::with_hash_kind(path_mapping, SourceFileHashAlgorithm::Md5) } - pub fn with_file_loader_and_hash_kind( - file_loader: Box, + pub fn with_hash_kind( path_mapping: FilePathMapping, hash_kind: SourceFileHashAlgorithm, ) -> SourceMap { SourceMap { used_address_space: AtomicU32::new(0), files: Default::default(), - file_loader, path_mapping, hash_kind, } @@ -206,12 +177,8 @@ impl SourceMap { &self.path_mapping } - pub fn file_exists(&self, path: &Path) -> bool { - self.file_loader.file_exists(path) - } - pub fn load_file(&self, path: &Path) -> io::Result> { - let src = self.file_loader.read_file(path)?; + let src = fs::read_to_string(path)?; let filename = path.to_owned().into(); Ok(self.new_source_file(filename, src)) } @@ -221,8 +188,6 @@ impl SourceMap { /// Unlike `load_file`, guarantees that no normalization like BOM-removal /// takes place. pub fn load_binary_file(&self, path: &Path) -> io::Result> { - // Ideally, this should use `self.file_loader`, but it can't - // deal with binary files yet. let bytes = fs::read(path)?; // We need to add file to the `SourceMap`, so that it is present @@ -985,7 +950,7 @@ impl SourceMap { source_file.add_external_src(|| { match source_file.name { FileName::Real(ref name) if let Some(local_path) = name.local_path() => { - self.file_loader.read_file(local_path).ok() + fs::read_to_string(local_path).ok() } _ => None, } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b463b934e292d..5866f3515d856 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -14,7 +14,6 @@ use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_resolve as resolve; use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::lint; -use rustc_session::DiagnosticOutput; use rustc_session::Session; use rustc_span::symbol::sym; use rustc_span::{source_map, Span, Symbol}; @@ -285,8 +284,6 @@ pub(crate) fn create_config( input_path: cpath, output_file: None, output_dir: None, - file_loader: None, - diagnostic_output: DiagnosticOutput::Default, lint_caps, parse_sess_created: None, register_lints: Some(Box::new(crate::lint::register_lints)), @@ -318,7 +315,6 @@ pub(crate) fn create_config( (rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id) }; }), - make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), } } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index f4ec60735a8dd..3ebebf068bf0e 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -14,7 +14,7 @@ use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::attr::InnerAttrPolicy; use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::parse::ParseSess; -use rustc_session::{lint, DiagnosticOutput, Session}; +use rustc_session::{lint, Session}; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMap; use rustc_span::symbol::sym; @@ -99,13 +99,10 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { input_path: None, output_file: None, output_dir: None, - file_loader: None, - diagnostic_output: DiagnosticOutput::Default, lint_caps, parse_sess_created: None, register_lints: Some(Box::new(crate::lint::register_lints)), override_queries: None, - make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), }; diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs index fd294b018afa6..f569bc6dd72e8 100644 --- a/src/test/run-make-fulldeps/issue-19371/foo.rs +++ b/src/test/run-make-fulldeps/issue-19371/foo.rs @@ -5,7 +5,6 @@ extern crate rustc_driver; extern crate rustc_session; extern crate rustc_span; -use rustc_session::DiagnosticOutput; use rustc_session::config::{Input, Options, OutputType, OutputTypes}; use rustc_interface::interface; use rustc_span::source_map::FileName; @@ -54,13 +53,10 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { input_path: None, output_file: Some(output), output_dir: None, - file_loader: None, - diagnostic_output: DiagnosticOutput::Default, lint_caps: Default::default(), parse_sess_created: None, register_lints: None, override_queries: None, - make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), }; diff --git a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs index 8f78bda033ec1..1d467c6fb5e69 100644 --- a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs @@ -39,7 +39,7 @@ fn main() { rustc_args.push("-Zpolonius".to_owned()); let mut callbacks = CompilerCalls::default(); // Call the Rust compiler with our callbacks. - rustc_driver::RunCompiler::new(&rustc_args, &mut callbacks).run() + rustc_driver::run_compiler(&rustc_args, &mut callbacks) }); std::process::exit(exit_code); } diff --git a/src/test/ui-fulldeps/compiler-calls.rs b/src/test/ui-fulldeps/compiler-calls.rs index a9520b59277ac..144cd35b87fc9 100644 --- a/src/test/ui-fulldeps/compiler-calls.rs +++ b/src/test/ui-fulldeps/compiler-calls.rs @@ -26,7 +26,7 @@ fn main() { let mut count = 1; let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()]; rustc_driver::catch_fatal_errors(|| { - rustc_driver::RunCompiler::new(&args, &mut TestCalls { count: &mut count }).run().ok(); + rustc_driver::run_compiler(&args, &mut TestCalls { count: &mut count }).ok(); }) .ok(); assert_eq!(count, 2); diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index 235eae5af1ec3..a7fe273ab657d 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -285,7 +285,7 @@ pub fn main() { args.extend(vec!["--sysroot".into(), sys_root]); }; - return rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); + return rustc_driver::run_compiler(&args, &mut DefaultCallbacks); } if orig_args.iter().any(|a| a == "--version" || a == "-V") { @@ -345,9 +345,9 @@ pub fn main() { let clippy_enabled = !cap_lints_allow && (!no_deps || in_primary_package); if clippy_enabled { args.extend(clippy_args); - rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }).run() + rustc_driver::run_compiler(&args, &mut ClippyCallbacks { clippy_args_var }) } else { - rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }).run() + rustc_driver::run_compiler(&args, &mut RustcCallbacks { clippy_args_var }) } })) } diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 7d32ee4257326..a5a0833db47a6 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -301,7 +301,7 @@ fn run_compiler( // Invoke compiler, and handle return code. let exit_code = rustc_driver::catch_with_exit_code(move || { - rustc_driver::RunCompiler::new(&args, callbacks).run() + rustc_driver::run_compiler(&args, callbacks) }); std::process::exit(exit_code) } diff --git a/src/tools/rustfmt/src/modules.rs b/src/tools/rustfmt/src/modules.rs index 7a0d1736c59a6..76b8f9d292d20 100644 --- a/src/tools/rustfmt/src/modules.rs +++ b/src/tools/rustfmt/src/modules.rs @@ -366,10 +366,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { // Look for nested path, like `#[cfg_attr(feature = "foo", path = "bar.rs")]`. let mut mods_outside_ast = self.find_mods_outside_of_ast(attrs, sub_mod); - match self - .parse_sess - .default_submod_path(mod_name, relative, &self.directory.path) - { + match ParseSess::default_submod_path(mod_name, relative, &self.directory.path) { Ok(ModulePathSuccess { file_path, dir_ownership, diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs index 6efeee98fea6c..32beb3072c25f 100644 --- a/src/tools/rustfmt/src/parse/session.rs +++ b/src/tools/rustfmt/src/parse/session.rs @@ -181,25 +181,21 @@ impl ParseSess { /// or {dir_path}/{symbol}/{id}/mod.rs. if None, resolve the module at {dir_path}/{id}.rs. /// * `dir_path` - Module resolution will occur relative to this directory. pub(crate) fn default_submod_path( - &self, id: symbol::Ident, relative: Option, dir_path: &Path, ) -> Result> { - rustc_expand::module::default_submod_path(&self.parse_sess, id, relative, dir_path).or_else( - |e| { - // If resloving a module relative to {dir_path}/{symbol} fails because a file - // could not be found, then try to resolve the module relative to {dir_path}. - // If we still can't find the module after searching for it in {dir_path}, - // surface the original error. - if matches!(e, ModError::FileNotFound(..)) && relative.is_some() { - rustc_expand::module::default_submod_path(&self.parse_sess, id, None, dir_path) - .map_err(|_| e) - } else { - Err(e) - } - }, - ) + rustc_expand::module::default_submod_path(id, relative, dir_path).or_else(|e| { + // If resolving a module relative to {dir_path}/{symbol} fails because a file + // could not be found, then try to resolve the module relative to {dir_path}. + // If we still can't find the module after searching for it in {dir_path}, + // surface the original error. + if matches!(e, ModError::FileNotFound(..)) && relative.is_some() { + rustc_expand::module::default_submod_path(id, None, dir_path).map_err(|_| e) + } else { + Err(e) + } + }) } pub(crate) fn is_file_parsed(&self, path: &Path) -> bool {