diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-25 20:12:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-25 20:12:47 +0100 |
| commit | ed202b820831c15cea388d67985feae3784bac13 (patch) | |
| tree | 31d70a26d4c84fad7745a92cc71f6a24f94a37fd /src/librustdoc | |
| parent | 54fa9cab7c64b195ceb263b7feaabe20b6c01ece (diff) | |
| parent | a31ae159bc29ae26396160b1f3cb0fb358b4eae7 (diff) | |
| download | rust-ed202b820831c15cea388d67985feae3784bac13.tar.gz rust-ed202b820831c15cea388d67985feae3784bac13.zip | |
Rollup merge of #94154 - Urgau:rustdoc-check-cfg, r=GuillaumeGomez
Wire up unstable rustc --check-cfg to rustdoc This pull-request wire up the new unstable `--check-cfg` option from `rustc` to `rustdoc` as [requested](https://github.com/rust-lang/rust/pull/93915#discussion_r807560445) in the [pull-request](https://github.com/rust-lang/rust/pull/93915) that introduce `--check-cfg`. The motivation was describe in the original PR by ``@jyn514`` who wrote https://github.com/rust-lang/rust/pull/89346#issuecomment-930129761: > > add plumbing to pass --check-cfg from rustdoc (do we want this one?) > > It would be useful, I think, it catches issues like cfg(doctst) or something (and in general I would like expansion to match rustc as closely as possible).
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/config.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/doctest.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 1 |
4 files changed, 16 insertions, 2 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 6e483d27f33..93f90b90e0a 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -80,6 +80,8 @@ crate struct Options { crate extern_strs: Vec<String>, /// List of `cfg` flags to hand to the compiler. Always includes `rustdoc`. crate cfgs: Vec<String>, + /// List of check cfg flags to hand to the compiler. + crate check_cfgs: Vec<String>, /// Codegen options to hand to the compiler. crate codegen_options: CodegenOptions, /// Codegen options strings to hand to the compiler. @@ -172,6 +174,7 @@ impl fmt::Debug for Options { .field("libs", &self.libs) .field("externs", &FmtExterns(&self.externs)) .field("cfgs", &self.cfgs) + .field("check-cfgs", &self.check_cfgs) .field("codegen_options", &"...") .field("debugging_options", &"...") .field("target", &self.target) @@ -506,6 +509,7 @@ impl Options { }; let cfgs = matches.opt_strs("cfg"); + let check_cfgs = matches.opt_strs("check-cfg"); let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s)); @@ -677,6 +681,7 @@ impl Options { externs, extern_strs, cfgs, + check_cfgs, codegen_options, codegen_options_strs, debugging_opts, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index c2f6f7aea75..2b82575f710 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -192,6 +192,7 @@ crate fn create_config( libs, externs, mut cfgs, + check_cfgs, codegen_options, debugging_opts, target, @@ -219,6 +220,7 @@ crate fn create_config( // these are definitely not part of rustdoc, but we want to warn on them anyway. rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), + rustc_lint::builtin::UNEXPECTED_CFGS.name.to_string(), ]; lints_to_show.extend(crate::lint::RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); @@ -253,7 +255,7 @@ crate fn create_config( interface::Config { opts: sessopts, crate_cfg: interface::parse_cfgspecs(cfgs), - crate_check_cfg: interface::parse_check_cfg(vec![]), + crate_check_cfg: interface::parse_check_cfg(check_cfgs), input, input_path: cpath, output_file: None, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index dc9ce052cb5..13253312901 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -91,7 +91,7 @@ crate fn run(options: RustdocOptions) -> Result<(), ErrorReported> { let config = interface::Config { opts: sessopts, crate_cfg: interface::parse_cfgspecs(cfgs), - crate_check_cfg: interface::parse_check_cfg(vec![]), + crate_check_cfg: interface::parse_check_cfg(options.check_cfgs.clone()), input, input_path: None, output_file: None, @@ -321,6 +321,12 @@ fn run_test( for cfg in &rustdoc_options.cfgs { compiler.arg("--cfg").arg(&cfg); } + if !rustdoc_options.check_cfgs.is_empty() { + compiler.arg("-Z").arg("unstable-options"); + for check_cfg in &rustdoc_options.check_cfgs { + compiler.arg("--check-cfg").arg(&check_cfg); + } + } if let Some(sysroot) = rustdoc_options.maybe_sysroot { compiler.arg("--sysroot").arg(sysroot); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 9d3e58a3a66..d7e1f90bcf1 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -259,6 +259,7 @@ fn opts() -> Vec<RustcOptGroup> { o.optmulti("L", "library-path", "directory to add to crate search path", "DIR") }), stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")), + unstable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")), stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")), unstable("extern-html-root-url", |o| { o.optmulti( |
