]> git.lizzy.rs Git - rust.git/commitdiff
Remove redundant `input_path` field from `Config`
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 6 Dec 2022 18:56:28 +0000 (18:56 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 16 Jan 2023 08:03:06 +0000 (08:03 +0000)
compiler/rustc_driver/src/lib.rs
compiler/rustc_interface/src/interface.rs
compiler/rustc_interface/src/passes.rs
compiler/rustc_session/src/config.rs
src/librustdoc/core.rs
src/librustdoc/doctest.rs

index c56443512f4d27b96f4525debc5ab660f1431727..ec46fc8999a17ef0b4ef715844aad21113d8bbe6 100644 (file)
@@ -219,7 +219,6 @@ fn run_compiler(
         crate_cfg: cfg,
         crate_check_cfg: check_cfg,
         input: Input::File(PathBuf::new()),
-        input_path: None,
         output_file: ofile,
         output_dir: odir,
         file_loader,
@@ -237,9 +236,8 @@ fn run_compiler(
 
     match make_input(config.opts.error_format, &matches.free) {
         Err(reported) => return Err(reported),
-        Ok(Some((input, input_file_path))) => {
+        Ok(Some(input)) => {
             config.input = input;
-            config.input_path = input_file_path;
 
             callbacks.config(&mut config);
         }
@@ -437,7 +435,7 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
 fn make_input(
     error_format: ErrorOutputType,
     free_matches: &[String],
-) -> Result<Option<(Input, Option<PathBuf>)>, ErrorGuaranteed> {
+) -> Result<Option<Input>, ErrorGuaranteed> {
     if free_matches.len() == 1 {
         let ifile = &free_matches[0];
         if ifile == "-" {
@@ -459,12 +457,12 @@ fn make_input(
                 let line = isize::from_str_radix(&line, 10)
                     .expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
                 let file_name = FileName::doc_test_source_code(PathBuf::from(path), line);
-                Ok(Some((Input::Str { name: file_name, input: src }, None)))
+                Ok(Some(Input::Str { name: file_name, input: src }))
             } else {
-                Ok(Some((Input::Str { name: FileName::anon_source_code(&src), input: src }, None)))
+                Ok(Some(Input::Str { name: FileName::anon_source_code(&src), input: src }))
             }
         } else {
-            Ok(Some((Input::File(PathBuf::from(ifile)), Some(PathBuf::from(ifile)))))
+            Ok(Some(Input::File(PathBuf::from(ifile))))
         }
     } else {
         Ok(None)
index 7f761b005edd0946ce8e406282fa529f899268a5..22a01db5e7573e436435c6f1c119e2591cf056f6 100644 (file)
@@ -36,7 +36,6 @@ pub struct Compiler {
     pub(crate) sess: Lrc<Session>,
     codegen_backend: Lrc<Box<dyn CodegenBackend>>,
     pub(crate) input: Input,
-    pub(crate) input_path: Option<PathBuf>,
     pub(crate) output_dir: Option<PathBuf>,
     pub(crate) output_file: Option<PathBuf>,
     pub(crate) temps_dir: Option<PathBuf>,
@@ -244,7 +243,6 @@ pub struct Config {
     pub crate_check_cfg: CheckCfg,
 
     pub input: Input,
-    pub input_path: Option<PathBuf>,
     pub output_dir: Option<PathBuf>,
     pub output_file: Option<PathBuf>,
     pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
@@ -292,7 +290,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
                 config.crate_cfg,
                 config.crate_check_cfg,
                 config.file_loader,
-                config.input_path.clone(),
+                config.input.opt_path(),
                 config.lint_caps,
                 config.make_codegen_backend,
                 registry.clone(),
@@ -308,7 +306,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
                 sess: Lrc::new(sess),
                 codegen_backend: Lrc::new(codegen_backend),
                 input: config.input,
-                input_path: config.input_path,
                 output_dir: config.output_dir,
                 output_file: config.output_file,
                 temps_dir,
index 5dd758c94512f29e6e88e2f94d3a830cfce477ba..bba0a50a93fae2cedbd56a2dce8c48b3d484e5d4 100644 (file)
@@ -686,7 +686,7 @@ pub fn prepare_outputs(
         generated_output_paths(sess, &outputs, compiler.output_file.is_some(), crate_name);
 
     // Ensure the source file isn't accidentally overwritten during compilation.
-    if let Some(ref input_path) = compiler.input_path {
+    if let Some(ref input_path) = compiler.input.opt_path() {
         if sess.opts.will_create_output_file() {
             if output_contains_path(&output_paths, input_path) {
                 let reported = sess.emit_err(InputFileWouldBeOverWritten { path: input_path });
index 55576b4e0d19df06c04f03cba652af8852faffbf..2679164b927e54bd7c681623353fc4d9108a826e 100644 (file)
@@ -591,6 +591,24 @@ pub fn source_name(&self) -> FileName {
             Input::Str { ref name, .. } => name.clone(),
         }
     }
+
+    pub fn opt_path(&self) -> Option<PathBuf> {
+        match self {
+            Input::File(file) => Some(file.clone()),
+            Input::Str { name, .. } => match name {
+                FileName::Real(real) => real.local_path().map(|p| p.to_owned()),
+                FileName::QuoteExpansion(_) => None,
+                FileName::Anon(_) => None,
+                FileName::MacroExpansion(_) => None,
+                FileName::ProcMacroSourceCode(_) => None,
+                FileName::CfgSpec(_) => None,
+                FileName::CliCrateAttr(_) => None,
+                FileName::Custom(_) => None,
+                FileName::DocTest(path, _) => Some(path.to_owned()),
+                FileName::InlineAsm(_) => None,
+            },
+        }
+    }
 }
 
 #[derive(Clone, Hash, Debug, HashStable_Generic)]
index da0df596c41e34f7ca88e07b1e7b0811b75ed22d..2153e7d8c9ad9623193aed1fc98994b270e8f788 100644 (file)
@@ -225,7 +225,6 @@ pub(crate) fn create_config(
     // Add the doc cfg into the doc build.
     cfgs.push("doc".to_string());
 
-    let cpath = Some(input.clone());
     let input = Input::File(input);
 
     // By default, rustdoc ignores all lints.
@@ -277,7 +276,6 @@ pub(crate) fn create_config(
         crate_cfg: interface::parse_cfgspecs(cfgs),
         crate_check_cfg: interface::parse_check_cfg(check_cfgs),
         input,
-        input_path: cpath,
         output_file: None,
         output_dir: None,
         file_loader: None,
index d1b6d470e86ce91da866d11d89abbed6dc1622be..c1a652c75f4a16a0999fface3e8d8f8db60752af 100644 (file)
@@ -95,7 +95,6 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
         crate_cfg: interface::parse_cfgspecs(cfgs),
         crate_check_cfg: interface::parse_check_cfg(options.check_cfgs.clone()),
         input,
-        input_path: None,
         output_file: None,
         output_dir: None,
         file_loader: None,