diff options
| author | bors <bors@rust-lang.org> | 2025-03-03 19:34:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-03 19:34:25 +0000 |
| commit | e16a049adbf94d610787430b6efdf31d896dc5b6 (patch) | |
| tree | 4909ade923f6869ee52593a6627c2a8fd78b692f /src | |
| parent | d4916623403bc29927f467ccb1a80ba836a04139 (diff) | |
| parent | 15e97bd45eb83bc4114149702899bba97072bbb6 (diff) | |
| download | rust-e16a049adbf94d610787430b6efdf31d896dc5b6.tar.gz rust-e16a049adbf94d610787430b6efdf31d896dc5b6.zip | |
Auto merge of #137914 - matthiaskrgr:rollup-phaxe6f, r=matthiaskrgr
Rollup of 6 pull requests
Successful merges:
- #137103 ({json|html}docck: catch and error on deprecated syntax)
- #137632 (rustdoc: when merging target features, keep the highest stability)
- #137684 (Add rustdoc support for `--emit=dep-info[=path]`)
- #137794 (make qnx pass a test)
- #137801 (tests: Unignore target modifier tests on all platforms)
- #137826 (test(codegen): add looping_over_ne_bytes test for #133528)
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
| -rwxr-xr-x | src/etc/htmldocck.py | 14 | ||||
| -rw-r--r-- | src/librustdoc/config.rs | 28 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 24 | ||||
| -rw-r--r-- | src/librustdoc/html/render/write_shared.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 10 | ||||
| -rw-r--r-- | src/tools/jsondocck/src/main.rs | 43 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/external_deps/rustdoc.rs | 7 |
7 files changed, 98 insertions, 30 deletions
diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index d6b594aca71..06fc6518e3b 100755 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -297,10 +297,24 @@ LINE_PATTERN = re.compile( re.X | re.UNICODE, ) +DEPRECATED_LINE_PATTERN = re.compile( + r""" + //\s+@ +""", + re.X | re.UNICODE, +) + def get_commands(template): with io.open(template, encoding="utf-8") as f: for lineno, line in concat_multi_lines(f): + if DEPRECATED_LINE_PATTERN.search(line): + print_err( + lineno, + line, + "Deprecated command syntax, replace `// @` with `//@ `", + ) + continue m = LINE_PATTERN.search(line) if not m: continue diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index fd4d9845c89..e67fe6c88ea 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -315,23 +315,30 @@ pub(crate) enum ModuleSorting { Alphabetical, } -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub(crate) enum EmitType { Unversioned, Toolchain, InvocationSpecific, + DepInfo(Option<PathBuf>), } impl FromStr for EmitType { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { - use EmitType::*; match s { - "unversioned-shared-resources" => Ok(Unversioned), - "toolchain-shared-resources" => Ok(Toolchain), - "invocation-specific" => Ok(InvocationSpecific), - _ => Err(()), + "unversioned-shared-resources" => Ok(Self::Unversioned), + "toolchain-shared-resources" => Ok(Self::Toolchain), + "invocation-specific" => Ok(Self::InvocationSpecific), + "dep-info" => Ok(Self::DepInfo(None)), + option => { + if let Some(file) = option.strip_prefix("dep-info=") { + Ok(Self::DepInfo(Some(Path::new(file).into()))) + } else { + Err(()) + } + } } } } @@ -340,6 +347,15 @@ impl RenderOptions { pub(crate) fn should_emit_crate(&self) -> bool { self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific) } + + pub(crate) fn dep_info(&self) -> Option<Option<&Path>> { + for emit in &self.emit { + if let EmitType::DepInfo(file) = emit { + return Some(file.as_deref()); + } + } + None + } } /// Create the input (string or file path) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 757a2a6e0dd..679921c3269 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -15,11 +15,12 @@ use rustc_hir::def::Res; use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{HirId, Path}; -use rustc_interface::interface; use rustc_lint::{MissingDoc, late_lint_mod}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; -use rustc_session::config::{self, CrateType, ErrorOutputType, Input, ResolveDocLinks}; +use rustc_session::config::{ + self, CrateType, ErrorOutputType, Input, OutFileName, OutputType, OutputTypes, ResolveDocLinks, +}; pub(crate) use rustc_session::config::{Options, UnstableOptions}; use rustc_session::{Session, lint}; use rustc_span::source_map; @@ -219,7 +220,7 @@ pub(crate) fn create_config( remap_path_prefix, .. }: RustdocOptions, - RenderOptions { document_private, .. }: &RenderOptions, + render_options: &RenderOptions, ) -> rustc_interface::Config { // Add the doc cfg into the doc build. cfgs.push("doc".to_string()); @@ -245,8 +246,11 @@ pub(crate) fn create_config( let crate_types = if proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; - let resolve_doc_links = - if *document_private { ResolveDocLinks::All } else { ResolveDocLinks::Exported }; + let resolve_doc_links = if render_options.document_private { + ResolveDocLinks::All + } else { + ResolveDocLinks::Exported + }; let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false); // plays with error output here! let sessopts = config::Options { @@ -269,10 +273,18 @@ pub(crate) fn create_config( crate_name, test, remap_path_prefix, + output_types: if let Some(file) = render_options.dep_info() { + OutputTypes::new(&[( + OutputType::DepInfo, + file.map(|f| OutFileName::Real(f.to_path_buf())), + )]) + } else { + OutputTypes::new(&[]) + }, ..Options::default() }; - interface::Config { + rustc_interface::Config { opts: sessopts, crate_cfg: cfgs, crate_check_cfg: check_cfgs, diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 0185d0c3bb5..b2bbf4614bf 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -153,7 +153,7 @@ fn write_rendered_cross_crate_info( include_sources: bool, ) -> Result<(), Error> { let m = &opt.should_merge; - if opt.emit.is_empty() || opt.emit.contains(&EmitType::InvocationSpecific) { + if opt.should_emit_crate() { if include_sources { write_rendered_cci::<SourcesPart, _>(SourcesPart::blank, dst, crates, m)?; } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1f2f8f7d33a..c1e6d324d5a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -561,7 +561,7 @@ fn opts() -> Vec<RustcOptGroup> { "", "emit", "Comma separated list of types of output for rustdoc to emit", - "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]", + "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific,dep-info]", ), opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""), opt( @@ -890,7 +890,13 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { // if we ran coverage, bail early, we don't need to also generate docs at this point // (also we didn't load in any of the useful passes) return; - } else if run_check { + } + + if render_opts.dep_info().is_some() { + rustc_interface::passes::write_dep_info(tcx); + } + + if run_check { // Since we're in "check" mode, no need to generate anything beyond this point. return; } diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index 7bfa7e3355d..54249fbd9ae 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; use std::process::ExitCode; -use std::sync::OnceLock; +use std::sync::LazyLock; use std::{env, fs}; use regex::{Regex, RegexBuilder}; @@ -151,8 +151,7 @@ impl CommandKind { } } -static LINE_PATTERN: OnceLock<Regex> = OnceLock::new(); -fn line_pattern() -> Regex { +static LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| { RegexBuilder::new( r#" //@\s+ @@ -165,7 +164,19 @@ fn line_pattern() -> Regex { .unicode(true) .build() .unwrap() -} +}); + +static DEPRECATED_LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| { + RegexBuilder::new( + r#" + //\s+@ + "#, + ) + .ignore_whitespace(true) + .unicode(true) + .build() + .unwrap() +}); fn print_err(msg: &str, lineno: usize) { eprintln!("Invalid command: {} on line {}", msg, lineno) @@ -184,21 +195,23 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> { for (lineno, line) in file.split('\n').enumerate() { let lineno = lineno + 1; - let cap = match LINE_PATTERN.get_or_init(line_pattern).captures(line) { - Some(c) => c, - None => continue, + if DEPRECATED_LINE_PATTERN.is_match(line) { + print_err("Deprecated command syntax, replace `// @` with `//@ `", lineno); + errors = true; + continue; + } + + let Some(cap) = LINE_PATTERN.captures(line) else { + continue; }; - let negated = cap.name("negated").unwrap().as_str() == "!"; + let negated = &cap["negated"] == "!"; let args_str = &cap["args"]; - let args = match shlex::split(args_str) { - Some(args) => args, - None => { - print_err(&format!("Invalid arguments to shlex::split: `{args_str}`",), lineno); - errors = true; - continue; - } + let Some(args) = shlex::split(args_str) else { + print_err(&format!("Invalid arguments to shlex::split: `{args_str}`",), lineno); + errors = true; + continue; }; if let Some((kind, path)) = CommandKind::parse(&cap["cmd"], negated, &args) { diff --git a/src/tools/run-make-support/src/external_deps/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs index 3c0e9c82f0b..8a659cd3d8a 100644 --- a/src/tools/run-make-support/src/external_deps/rustdoc.rs +++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs @@ -132,4 +132,11 @@ impl Rustdoc { self.cmd.arg(format); self } + + /// Specify type(s) of output files to generate. + pub fn emit<S: AsRef<str>>(&mut self, kinds: S) -> &mut Self { + let kinds = kinds.as_ref(); + self.cmd.arg(format!("--emit={kinds}")); + self + } } |
