Skip to content

Commit e7130d3

Browse files
committed
feat(rustdoc): --emit=depinfo output to stdout via -
rustdoc's `--emit=depinfo` flag now supports using `-` to write the output to stdout.
1 parent 0abea28 commit e7130d3

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl Input {
11111111
}
11121112
}
11131113

1114-
#[derive(Clone, Hash, Debug, HashStable_Generic, PartialEq, Encodable, Decodable)]
1114+
#[derive(Clone, Hash, Debug, HashStable_Generic, PartialEq, Eq, Encodable, Decodable)]
11151115
pub enum OutFileName {
11161116
Real(PathBuf),
11171117
Stdout,

src/librustdoc/config.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_data_structures::fx::FxIndexMap;
99
use rustc_errors::DiagCtxtHandle;
1010
use rustc_session::config::{
1111
self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns,
12-
OptionsTargetModifiers, Sysroot, UnstableOptions, get_cmd_lint_options, nightly_options,
13-
parse_crate_types_from_list, parse_externs, parse_target_triple,
12+
OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options,
13+
nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple,
1414
};
1515
use rustc_session::lint::Level;
1616
use rustc_session::search_paths::SearchPath;
@@ -320,7 +320,7 @@ pub(crate) enum EmitType {
320320
Unversioned,
321321
Toolchain,
322322
InvocationSpecific,
323-
DepInfo(Option<PathBuf>),
323+
DepInfo(Option<OutFileName>),
324324
}
325325

326326
impl FromStr for EmitType {
@@ -332,13 +332,11 @@ impl FromStr for EmitType {
332332
"toolchain-shared-resources" => Ok(Self::Toolchain),
333333
"invocation-specific" => Ok(Self::InvocationSpecific),
334334
"dep-info" => Ok(Self::DepInfo(None)),
335-
option => {
336-
if let Some(file) = option.strip_prefix("dep-info=") {
337-
Ok(Self::DepInfo(Some(Path::new(file).into())))
338-
} else {
339-
Err(())
340-
}
341-
}
335+
option => match option.strip_prefix("dep-info=") {
336+
Some("-") => Ok(Self::DepInfo(Some(OutFileName::Stdout))),
337+
Some(f) => Ok(Self::DepInfo(Some(OutFileName::Real(f.into())))),
338+
None => Err(()),
339+
},
342340
}
343341
}
344342
}
@@ -348,10 +346,10 @@ impl RenderOptions {
348346
self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific)
349347
}
350348

351-
pub(crate) fn dep_info(&self) -> Option<Option<&Path>> {
349+
pub(crate) fn dep_info(&self) -> Option<Option<&OutFileName>> {
352350
for emit in &self.emit {
353351
if let EmitType::DepInfo(file) = emit {
354-
return Some(file.as_deref());
352+
return Some(file.as_ref());
355353
}
356354
}
357355
None

src/librustdoc/core.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_lint::{MissingDoc, late_lint_mod};
1919
use rustc_middle::hir::nested_filter;
2020
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
2121
use rustc_session::config::{
22-
self, CrateType, ErrorOutputType, Input, OutFileName, OutputType, OutputTypes, ResolveDocLinks,
22+
self, CrateType, ErrorOutputType, Input, OutputType, OutputTypes, ResolveDocLinks,
2323
};
2424
pub(crate) use rustc_session::config::{Options, UnstableOptions};
2525
use rustc_session::{Session, lint};
@@ -272,10 +272,7 @@ pub(crate) fn create_config(
272272
test,
273273
remap_path_prefix,
274274
output_types: if let Some(file) = render_options.dep_info() {
275-
OutputTypes::new(&[(
276-
OutputType::DepInfo,
277-
file.map(|f| OutFileName::Real(f.to_path_buf())),
278-
)])
275+
OutputTypes::new(&[(OutputType::DepInfo, file.cloned())])
279276
} else {
280277
OutputTypes::new(&[])
281278
},

tests/run-make/rustdoc-dep-info/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ fn main() {
5454
.emit("dep-info=-")
5555
.run();
5656
assert!(!path("precedence1.d").exists());
57-
assert!(path("-").exists()); // `-` be treated as a file path
58-
assert!(result.stdout().is_empty()); // Nothing emitted to stdout
57+
assert!(!path("-").exists()); // `-` shouldn't be treated as a file path
58+
assert!(!result.stdout().is_empty()); // Something emitted to stdout
5959
}

0 commit comments

Comments
 (0)