Repository: rustls/rustls (language: rust)

Issue:
`cargo doc` fails when docsrs is enabled but fips is disabled due to `cfg(any))`
https://github.com/rustls/rustls/blame/1177a465680cfac8c2a4b7217758d488d5d840c4/rustls/src/crypto/mod.rs#L571

Hi, we're trying to run cargo doc against the dioxus repo but it's failing since there's an invalid configuration on rustls/src/crypto/mod.rs:571.

The cfg takes ANY docsrs or fips. But in our repo we explicitly have fips/aws-lc-sys disabled since aws-lc-sys is causing us massive headaches (nasm requirement on windows, issues on android, etc).

```
error[E0433]: failed to resolve: use of undeclared crate or module `aws_lc_rs`
   --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.23.12/src/crypto/mod.rs:574:5
    |
574 |     aws_lc_rs::default_provider()
    |     ^^^^^^^^^ use of undeclared crate or module `aws_lc_rs`

    Checking exr v1.72.0
   Compiling built v0.7.3
For more information about this error, try `rustc --explain E0433`.
error: could not compile `rustls` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
```

The solution here is probably to provide cfg out the inner part of the function with an `unimplemented!()` if fips is disabled.

I'd be happy to make that PR but the core team might be faster.


Discussion / hints:
I don't think it is worth defending that `cfg(docsrs)` works with feature combinations except a) `--all-features`, or b) those that are specified in the `Cargo.toml` docs.rs stanza. Really all `docsrs` is doing here is enabling automatic feature-gate annotations, and those only work usefully if all the features are enabled.

It sounds like you've arrived at the set of features you want to enable -- may I suggest that you simply don't use `cfg(docsrs)`? The resulting documentation is everything available for the features you have selected.
Maybe I don't understand - 

I'm trying to publish a crate of ours that is using rustls in a rather normal way:

```
rustls = { version="0.23.12", default-features=false, features =["logging","std","tls12","ring"] }
```

when we build for `docs.rs` the build fails because docs.rs passes `--cfg(docsrs)` but aws_lc_rs isn't enabled. The way the features are laid out here implies that *either* docsrs *or* aws_lc_rs are enabled and then proceeds to call a function from aws_lc_rs.

We have to work around this by setting the aws_lc_rs dep manually by exposing a feature that shouldn't really be there:
```
# rest of the cargo.toml...
[dependencies]
aws-lc-rs = { optional = true } 

[features]
aws-lc-rs = ["dep:aws-lc-rs"]

[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
features = ["axum", "web", "aws-lc-rs"]
```

rustls should not have an `any` cfg for docsrs and aws_lc_rs since any downstream crates that don't use aws_lc_rs won't be able to build for docs.rs


Ah, ok, apologies. I was assuming that `package.metadata.docs.rs` was ignored when this crate appeared as a dependency in a docs.rs build. Will fix this.

Fix patch:
diff --git a/rustls/src/crypto/mod.rs b/rustls/src/crypto/mod.rs
index b73f0115a88..595827bc78e 100644
--- a/rustls/src/crypto/mod.rs
+++ b/rustls/src/crypto/mod.rs
@@ -568,7 +568,7 @@ impl From<&[u8]> for SharedSecret {
 ///     .with_no_client_auth();
 /// # }
 /// ```
-#[cfg(any(feature = "fips", docsrs))]
+#[cfg(all(feature = "aws_lc_rs", any(feature = "fips", docsrs)))]
 #[cfg_attr(docsrs, doc(cfg(feature = "fips")))]
 pub fn default_fips_provider() -> CryptoProvider {
     aws_lc_rs::default_provider()


Test patch: