From a4d2e29e213d2a98ce8df56ada20dbe9a7391ae8 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 1 Nov 2022 14:55:03 +0000 Subject: [PATCH] =?UTF-8?q?Gleaning=20rustdocflags=20from=20`target.cfg(?= =?UTF-8?q?=E2=80=A6)`=20is=20not=20supported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bug was `rustflags_from_target` trying to learn rustdocflags from `target.cfg(…).rustflags`, which is definitely wrong. As of this writing, either `target.cfg(…).rustdocflags` or `target..rustdocflags` is not supported. --- src/cargo/core/compiler/build_context/target_info.rs | 12 +++++++++--- tests/testsuite/rustdocflags.rs | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index a8561278e..e297a2ef7 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -749,9 +749,15 @@ fn rustflags_from_target( .target_cfgs()? .iter() .filter_map(|(key, cfg)| { - cfg.rustflags - .as_ref() - .map(|rustflags| (key, &rustflags.val)) + match flag { + Flags::Rust => cfg + .rustflags + .as_ref() + .map(|rustflags| (key, &rustflags.val)), + // `target.cfg(…).rustdocflags` is currently not supported. + // In fact, neither is `target..rustdocflags`. + Flags::Rustdoc => None, + } }) .filter(|(key, _rustflags)| CfgExpr::matches_key(key, target_cfg)) .for_each(|(_key, cfg_rustflags)| { diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index 891c88a6f..6992961ce 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -148,9 +148,8 @@ fn not_affected_by_target_rustflags() { .with_stderr_contains("[RUNNING] `rustc [..] -D missing-docs[..]`") .run(); - // This is wrong behaviour. `cargo doc` shouldn't fail. + // `cargo doc` shouldn't fail. p.cargo("doc -v") - .with_status(101) - .with_stderr_contains("[RUNNING] `rustdoc [..] -D missing-docs[..]`") + .with_stderr_contains("[RUNNING] `rustdoc [..] --cfg foo[..]`") .run(); }