Skip to content
Open
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
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fn list_metadata(sess: &Session, metadata_loader: &dyn MetadataLoader) {
}
}

fn print_crate_info(
pub fn print_crate_info(
codegen_backend: &dyn CodegenBackend,
sess: &Session,
parse_attrs: bool,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tracing::debug;

pub use crate::config::cfg::{Cfg, CheckCfg, ExpectedValues};
use crate::config::native_libs::parse_native_libs;
pub use crate::config::print_request::{PrintKind, PrintRequest};
pub use crate::config::print_request::{PrintKind, PrintRequest, collect_print_requests};
use crate::errors::FileWriteFail;
pub use crate::options::*;
use crate::search_paths::SearchPath;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config/print_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(crate) static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
)
});

pub(crate) fn collect_print_requests(
pub fn collect_print_requests(
early_dcx: &EarlyDiagCtxt,
cg: &mut CodegenOptions,
unstable_opts: &UnstableOptions,
Expand Down
14 changes: 11 additions & 3 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::DiagCtxtHandle;
use rustc_session::config::{
self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns,
OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options,
nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple,
OptionsTargetModifiers, OutFileName, PrintRequest, Sysroot, UnstableOptions,
collect_print_requests, get_cmd_lint_options, nightly_options, parse_crate_types_from_list,
parse_externs, parse_target_triple,
};
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
Expand Down Expand Up @@ -119,6 +120,8 @@ pub(crate) struct Options {
pub(crate) describe_lints: bool,
/// What level to cap lints at.
pub(crate) lint_cap: Option<Level>,
/// Print requests to hand to the compiler.
pub(crate) prints: Vec<PrintRequest>,

// Options specific to running doctests
/// Whether we should run doctests instead of generating docs.
Expand Down Expand Up @@ -210,6 +213,7 @@ impl fmt::Debug for Options {
.field("lint_opts", &self.lint_opts)
.field("describe_lints", &self.describe_lints)
.field("lint_cap", &self.lint_cap)
.field("prints", &self.prints)
.field("should_test", &self.should_test)
.field("test_args", &self.test_args)
.field("test_run_directory", &self.test_run_directory)
Expand Down Expand Up @@ -410,7 +414,7 @@ impl Options {
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();

let mut target_modifiers = BTreeMap::<OptionsTargetModifiers, String>::new();
let codegen_options = CodegenOptions::build(early_dcx, matches, &mut target_modifiers);
let mut codegen_options = CodegenOptions::build(early_dcx, matches, &mut target_modifiers);
let unstable_opts = UnstableOptions::build(early_dcx, matches, &mut target_modifiers);

let remap_path_prefix = match parse_remap_path_prefix(matches) {
Expand Down Expand Up @@ -564,6 +568,9 @@ impl Options {
}
};

let prints =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sense that there are certain rustc print requests which I don't think rustdoc can support.

E.g., I'm curious what will happen if you pass --print=link-args to rustdoc under your PR. Contrary to most other rustc print request that make rustc stop compilation early, link-args actually requires full analysis+codegen IINM … which rustdoc obv doesn't do. I guess it just doesn't print anything?

If so, that would be an example of a rustc print request that shouldn't be a legal rustdoc one.

There's also --print=native-static-libs that seems to require sth. similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g., I'm curious what will happen if you pass --print=link-args to rustdoc under your PR. Contrary to most other rustc print request that make rustc stop compilation early, link-args actually requires full analysis+codegen IINM … which rustdoc obv doesn't do. I guess it just doesn't print anything?

Yup, print_crate_info is a no-op for them as it's codegen_ssa that print them, and since the codegen isn't called, they don't print anything.

I'll filter the prints depending on if they make sense depending on the file type (.rs / .md / both) and action (doc / doctest / any).

collect_print_requests(early_dcx, &mut codegen_options, &unstable_opts, matches);

let externs = parse_externs(early_dcx, matches, &unstable_opts);
let extern_html_root_urls = match parse_extern_html_roots(matches) {
Ok(ex) => ex,
Expand Down Expand Up @@ -853,6 +860,7 @@ impl Options {
lint_opts,
describe_lints,
lint_cap,
prints,
should_test,
test_args,
show_coverage,
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub(crate) fn create_config(
lint_opts,
describe_lints,
lint_cap,
prints,
scrape_examples_options,
remap_path_prefix,
target_modifiers,
Expand Down Expand Up @@ -269,6 +270,7 @@ pub(crate) fn create_config(
diagnostic_width,
edition,
describe_lints,
prints,
crate_name,
test,
remap_path_prefix,
Expand Down
14 changes: 14 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@ fn opts() -> Vec<RustcOptGroup> {
"Comma separated list of types of output for rustdoc to emit",
"[toolchain-shared-resources,invocation-specific,dep-info]",
),
opt(
Stable,
Comment thread
ShE3py marked this conversation as resolved.
Outdated
Multi,
"",
"print",
"Rustdoc information to print on stdout (or to a file)",
"<INFO>[=<FILE>]",
),
opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""),
opt(
Unstable,
Expand Down Expand Up @@ -885,6 +893,12 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
return;
}

if rustc_driver::print_crate_info(&*compiler.codegen_backend, sess, true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: IINM, this won't be run if the input file is *.md or if --test is passed. Not sure what the consequences of that are.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, --print=crate-name doesn't really make sense for *.md inputs I feel like?

== rustc_driver::Compilation::Stop
{
return;
}

let krate = rustc_interface::passes::parse(sess);
rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| {
if sess.dcx().has_errors().is_some() {
Expand Down
Loading