Skip to content

Commit f5c6014

Browse files
committed
Remove redundant input_path field from Config
1 parent 6b1a789 commit f5c6014

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ fn run_compiler(
219219
crate_cfg: cfg,
220220
crate_check_cfg: check_cfg,
221221
input: Input::File(PathBuf::new()),
222-
input_path: None,
223222
output_file: ofile,
224223
output_dir: odir,
225224
file_loader,
@@ -237,9 +236,8 @@ fn run_compiler(
237236

238237
match make_input(config.opts.error_format, &matches.free) {
239238
Err(reported) => return Err(reported),
240-
Ok(Some((input, input_file_path))) => {
239+
Ok(Some(input)) => {
241240
config.input = input;
242-
config.input_path = input_file_path;
243241

244242
callbacks.config(&mut config);
245243
}
@@ -437,7 +435,7 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
437435
fn make_input(
438436
error_format: ErrorOutputType,
439437
free_matches: &[String],
440-
) -> Result<Option<(Input, Option<PathBuf>)>, ErrorGuaranteed> {
438+
) -> Result<Option<Input>, ErrorGuaranteed> {
441439
if free_matches.len() == 1 {
442440
let ifile = &free_matches[0];
443441
if ifile == "-" {
@@ -459,12 +457,12 @@ fn make_input(
459457
let line = isize::from_str_radix(&line, 10)
460458
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
461459
let file_name = FileName::doc_test_source_code(PathBuf::from(path), line);
462-
Ok(Some((Input::Str { name: file_name, input: src }, None)))
460+
Ok(Some(Input::Str { name: file_name, input: src }))
463461
} else {
464-
Ok(Some((Input::Str { name: FileName::anon_source_code(&src), input: src }, None)))
462+
Ok(Some(Input::Str { name: FileName::anon_source_code(&src), input: src }))
465463
}
466464
} else {
467-
Ok(Some((Input::File(PathBuf::from(ifile)), Some(PathBuf::from(ifile)))))
465+
Ok(Some(Input::File(PathBuf::from(ifile))))
468466
}
469467
} else {
470468
Ok(None)

compiler/rustc_interface/src/interface.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub struct Compiler {
3636
pub(crate) sess: Lrc<Session>,
3737
codegen_backend: Lrc<Box<dyn CodegenBackend>>,
3838
pub(crate) input: Input,
39-
pub(crate) input_path: Option<PathBuf>,
4039
pub(crate) output_dir: Option<PathBuf>,
4140
pub(crate) output_file: Option<PathBuf>,
4241
pub(crate) temps_dir: Option<PathBuf>,
@@ -244,7 +243,6 @@ pub struct Config {
244243
pub crate_check_cfg: CheckCfg,
245244

246245
pub input: Input,
247-
pub input_path: Option<PathBuf>,
248246
pub output_dir: Option<PathBuf>,
249247
pub output_file: Option<PathBuf>,
250248
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
292290
config.crate_cfg,
293291
config.crate_check_cfg,
294292
config.file_loader,
295-
config.input_path.clone(),
293+
config.input.opt_path(),
296294
config.lint_caps,
297295
config.make_codegen_backend,
298296
registry.clone(),
@@ -308,7 +306,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
308306
sess: Lrc::new(sess),
309307
codegen_backend: Lrc::new(codegen_backend),
310308
input: config.input,
311-
input_path: config.input_path,
312309
output_dir: config.output_dir,
313310
output_file: config.output_file,
314311
temps_dir,

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pub fn prepare_outputs(
686686
generated_output_paths(sess, &outputs, compiler.output_file.is_some(), crate_name);
687687

688688
// Ensure the source file isn't accidentally overwritten during compilation.
689-
if let Some(ref input_path) = compiler.input_path {
689+
if let Some(ref input_path) = compiler.input.opt_path() {
690690
if sess.opts.will_create_output_file() {
691691
if output_contains_path(&output_paths, input_path) {
692692
let reported = sess.emit_err(InputFileWouldBeOverWritten { path: input_path });

compiler/rustc_session/src/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,24 @@ impl Input {
591591
Input::Str { ref name, .. } => name.clone(),
592592
}
593593
}
594+
595+
pub fn opt_path(&self) -> Option<PathBuf> {
596+
match self {
597+
Input::File(file) => Some(file.clone()),
598+
Input::Str { name, .. } => match name {
599+
FileName::Real(real) => real.local_path().map(|p| p.to_owned()),
600+
FileName::QuoteExpansion(_) => None,
601+
FileName::Anon(_) => None,
602+
FileName::MacroExpansion(_) => None,
603+
FileName::ProcMacroSourceCode(_) => None,
604+
FileName::CfgSpec(_) => None,
605+
FileName::CliCrateAttr(_) => None,
606+
FileName::Custom(_) => None,
607+
FileName::DocTest(path, _) => Some(path.to_owned()),
608+
FileName::InlineAsm(_) => None,
609+
},
610+
}
611+
}
594612
}
595613

596614
#[derive(Clone, Hash, Debug, HashStable_Generic)]

src/librustdoc/core.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ pub(crate) fn create_config(
225225
// Add the doc cfg into the doc build.
226226
cfgs.push("doc".to_string());
227227

228-
let cpath = Some(input.clone());
229228
let input = Input::File(input);
230229

231230
// By default, rustdoc ignores all lints.
@@ -277,7 +276,6 @@ pub(crate) fn create_config(
277276
crate_cfg: interface::parse_cfgspecs(cfgs),
278277
crate_check_cfg: interface::parse_check_cfg(check_cfgs),
279278
input,
280-
input_path: cpath,
281279
output_file: None,
282280
output_dir: None,
283281
file_loader: None,

src/librustdoc/doctest.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
9595
crate_cfg: interface::parse_cfgspecs(cfgs),
9696
crate_check_cfg: interface::parse_check_cfg(options.check_cfgs.clone()),
9797
input,
98-
input_path: None,
9998
output_file: None,
10099
output_dir: None,
101100
file_loader: None,

0 commit comments

Comments
 (0)