Skip to content

Commit

Permalink
Simplify markdown_input fn and subsequent logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed May 4, 2024
1 parent 1193e96 commit 7e1dc74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ffi::OsStr;
use std::fmt;
use std::io;
use std::io::Read;
use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;

Expand Down Expand Up @@ -816,12 +817,10 @@ impl Options {
}

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

Expand Down
15 changes: 5 additions & 10 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,18 +730,13 @@ fn main_args(
core::new_dcx(options.error_format, None, options.diagnostic_width, &options.unstable_opts);

match (options.should_test, options.markdown_input()) {
(true, true) => return wrap_return(&diag, markdown::test(options)),
(true, false) => return doctest::run(&diag, options),
(false, true) => {
(true, Some(_)) => return wrap_return(&diag, markdown::test(options)),
(true, None) => return doctest::run(&diag, options),
(false, Some(input)) => {
let input = input.to_owned();
let edition = options.edition;
let config = core::create_config(options, &render_options, using_internal_features);

use rustc_session::config::Input;
let input = match &config.input {
Input::File(path) => path.clone(),
Input::Str { .. } => unreachable!("only path to markdown are supported"),
};

// `markdown::render` can invoke `doctest::make_test`, which
// requires session globals and a thread pool, so we use
// `run_compiler`.
Expand All @@ -752,7 +747,7 @@ fn main_args(
}),
);
}
(false, false) => {}
(false, None) => {}
}

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

0 comments on commit 7e1dc74

Please sign in to comment.