Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ impl Input {
}
}

#[derive(Clone, Hash, Debug, HashStable_Generic, PartialEq, Encodable, Decodable)]
#[derive(Clone, Hash, Debug, HashStable_Generic, PartialEq, Eq, Encodable, Decodable)]
pub enum OutFileName {
Real(PathBuf),
Stdout,
Expand Down
22 changes: 10 additions & 12 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::DiagCtxtHandle;
use rustc_session::config::{
self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns,
OptionsTargetModifiers, Sysroot, UnstableOptions, get_cmd_lint_options, nightly_options,
parse_crate_types_from_list, parse_externs, parse_target_triple,
OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, 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 @@ -320,7 +320,7 @@ pub(crate) enum EmitType {
Unversioned,
Toolchain,
InvocationSpecific,
DepInfo(Option<PathBuf>),
DepInfo(Option<OutFileName>),
}

impl FromStr for EmitType {
Expand All @@ -332,13 +332,11 @@ impl FromStr for EmitType {
"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(())
}
}
option => match option.strip_prefix("dep-info=") {
Some("-") => Ok(Self::DepInfo(Some(OutFileName::Stdout))),
Some(f) => Ok(Self::DepInfo(Some(OutFileName::Real(f.into())))),
None => Err(()),
},
}
}
}
Expand All @@ -348,10 +346,10 @@ impl RenderOptions {
self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific)
}

pub(crate) fn dep_info(&self) -> Option<Option<&Path>> {
pub(crate) fn dep_info(&self) -> Option<Option<&OutFileName>> {
for emit in &self.emit {
if let EmitType::DepInfo(file) = emit {
return Some(file.as_deref());
return Some(file.as_ref());
}
}
None
Expand Down
7 changes: 2 additions & 5 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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, OutFileName, OutputType, OutputTypes, ResolveDocLinks,
self, CrateType, ErrorOutputType, Input, OutputType, OutputTypes, ResolveDocLinks,
};
pub(crate) use rustc_session::config::{Options, UnstableOptions};
use rustc_session::{Session, lint};
Expand Down Expand Up @@ -272,10 +272,7 @@ pub(crate) fn create_config(
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())),
)])
OutputTypes::new(&[(OutputType::DepInfo, file.cloned())])
} else {
OutputTypes::new(&[])
},
Expand Down
11 changes: 11 additions & 0 deletions tests/run-make/rustdoc-dep-info/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ fn main() {
assert!(!path("precedence1.d").exists());
assert!(!path("precedence2.d").exists());
assert!(path("precedence3.d").exists());

// stdout (-) also wins if being the last.
let result = rustdoc()
.input("lib.rs")
.arg("-Zunstable-options")
.emit("dep-info=precedence1.d")
.emit("dep-info=-")
.run();
assert!(!path("precedence1.d").exists());
assert!(!path("-").exists()); // `-` shouldn't be treated as a file path
assert!(!result.stdout().is_empty()); // Something emitted to stdout
}
Loading