Skip to content

Commit 7e1dc74

Browse files
committed
Simplify markdown_input fn and subsequent logic
1 parent 1193e96 commit 7e1dc74

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/librustdoc/config.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::ffi::OsStr;
33
use std::fmt;
44
use std::io;
55
use std::io::Read;
6+
use std::path::Path;
67
use std::path::PathBuf;
78
use std::str::FromStr;
89

@@ -816,12 +817,10 @@ impl Options {
816817
}
817818

818819
/// Returns `true` if the file given as `self.input` is a Markdown file.
819-
pub(crate) fn markdown_input(&self) -> bool {
820+
pub(crate) fn markdown_input(&self) -> Option<&Path> {
820821
self.input
821822
.opt_path()
822-
.map(std::path::Path::extension)
823-
.flatten()
824-
.is_some_and(|e| e == "md" || e == "markdown")
823+
.filter(|p| matches!(p.extension(), Some(e) if e == "md" || e == "markdown"))
825824
}
826825
}
827826

src/librustdoc/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -730,18 +730,13 @@ fn main_args(
730730
core::new_dcx(options.error_format, None, options.diagnostic_width, &options.unstable_opts);
731731

732732
match (options.should_test, options.markdown_input()) {
733-
(true, true) => return wrap_return(&diag, markdown::test(options)),
734-
(true, false) => return doctest::run(&diag, options),
735-
(false, true) => {
733+
(true, Some(_)) => return wrap_return(&diag, markdown::test(options)),
734+
(true, None) => return doctest::run(&diag, options),
735+
(false, Some(input)) => {
736+
let input = input.to_owned();
736737
let edition = options.edition;
737738
let config = core::create_config(options, &render_options, using_internal_features);
738739

739-
use rustc_session::config::Input;
740-
let input = match &config.input {
741-
Input::File(path) => path.clone(),
742-
Input::Str { .. } => unreachable!("only path to markdown are supported"),
743-
};
744-
745740
// `markdown::render` can invoke `doctest::make_test`, which
746741
// requires session globals and a thread pool, so we use
747742
// `run_compiler`.
@@ -752,7 +747,7 @@ fn main_args(
752747
}),
753748
);
754749
}
755-
(false, false) => {}
750+
(false, None) => {}
756751
}
757752

758753
// need to move these items separately because we lose them by the time the closure is called,

0 commit comments

Comments
 (0)