Remove redundant input_path field from Config

This commit is contained in:
Oli Scherer 2022-12-06 18:56:28 +00:00
parent 6b1a789fb6
commit f5c601492e
6 changed files with 25 additions and 15 deletions

View 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)

View 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,

View 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 });

View 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)]

View 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,

View 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,