Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add - (stdin) support in rustdoc #124611

Merged
merged 3 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Simplify markdown_input fn and subsequent logic
  • Loading branch information
Urgau committed May 4, 2024
commit 7e1dc742d620123f251c696c8aae864a226d1c89
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
Loading