Skip to content

Commit 93000bd

Browse files
Add explanations about the "config_command" macro and append "rustdoc_args" from "metadata" inside the macro too
1 parent d5bc7c1 commit 93000bd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/docbuilder/rustwide_builder.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ const ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
6969
const DUMMY_CRATE_NAME: &str = "empty-library";
7070
const DUMMY_CRATE_VERSION: &str = "1.0.0";
7171

72+
// This macro exists because of lifetimes issues surrounding the `Command::process_lines` method:
73+
// it expects a mutable reference to a closure, in which we capture a variable in order to store
74+
// the JSON output. Unfortunately, we *need* to create the command in the same scope level otherwise
75+
// rustc becomes very grumpy about the fact that the variable needs to be static because it is
76+
// captured in a mutably referenced closure.
77+
//
78+
// So either you create a function with a callback in which you pass the `Command` as an argument,
79+
// or you create a function returning a `Command`, it's very unhappy in both cases.
80+
//
81+
// TODO: make `Command::process_lines` take the closure by value rather than a mutable reference.
7282
macro_rules! config_command {
7383
($obj:ident, $build:expr, $target:expr, $metadata:expr, $limits:expr, $rustdoc_flags_extras:expr, $($extra:tt)+) => {{
7484
let mut cargo_args = vec!["doc", "--lib", "--no-deps"];
@@ -109,6 +119,11 @@ macro_rules! config_command {
109119
"--cap-lints".to_string(),
110120
"warn".to_string(),
111121
];
122+
123+
if let Some(package_rustdoc_args) = &$metadata.rustdoc_args {
124+
rustdoc_flags.append(&mut package_rustdoc_args.clone());
125+
}
126+
112127
rustdoc_flags.extend($rustdoc_flags_extras);
113128

114129
$build
@@ -603,9 +618,6 @@ impl RustwideBuilder {
603618
dep.version
604619
));
605620
}
606-
if let Some(package_rustdoc_args) = &metadata.rustdoc_args {
607-
rustdoc_flags.append(&mut package_rustdoc_args.iter().map(|s| s.to_owned()).collect());
608-
}
609621

610622
rustdoc_flags.extend(vec![
611623
"--resource-suffix".to_string(),

0 commit comments

Comments
 (0)