@@ -23,16 +23,19 @@ pub trait Provider {
2323impl_provider_utils ! ( ) ;
2424
2525cfg_if ! {
26- if #[ cfg( feature = "provider-tls-default" ) ] {
26+ // An explicit provider selection overrides the platform default. `provider-tls-s2n` and
27+ // `provider-tls-rustls` lets a consumer force a specific TLS implementation just by enabling its feature,
28+ // without having to disable default features.
29+ if #[ cfg( feature = "provider-tls-s2n" ) ] {
30+ pub use s2n_tls as default ;
31+ } else if #[ cfg( feature = "provider-tls-rustls" ) ] {
32+ pub use rustls as default ;
33+ } else if #[ cfg( feature = "provider-tls-default" ) ] {
2734 #[ cfg_attr( docsrs, doc( cfg( feature = "provider-tls-default" ) ) ) ]
2835 pub mod default {
2936 //! Provides the recommended implementation of TLS using platform detection
3037 pub use super :: default_tls:: * ;
3138 }
32- } else if #[ cfg( feature = "provider-tls-s2n" ) ] {
33- pub use s2n_tls as default ;
34- } else if #[ cfg( feature = "provider-tls-rustls" ) ] {
35- pub use rustls as default ;
3639 } else {
3740 pub mod default {
3841 //! Provides the recommended implementation of TLS using platform detection
@@ -190,7 +193,15 @@ impl Provider for &str {
190193 }
191194}
192195
193- #[ cfg( feature = "provider-tls-default" ) ]
196+ // `default_tls` only backs the `default` module when `provider-tls-default` is the effective
197+ // choice, i.e. when neither `provider-tls-s2n` nor `provider-tls-rustls` overrides it (see the
198+ // cfg_if above). When an override is active, the re-export below would be unused, so we compile
199+ // the stub instead to avoid dead code.
200+ #[ cfg( all(
201+ feature = "provider-tls-default" ,
202+ not( feature = "provider-tls-s2n" ) ,
203+ not( feature = "provider-tls-rustls" )
204+ ) ) ]
194205mod default_tls {
195206 pub use s2n_quic_tls_default:: * ;
196207
@@ -199,19 +210,9 @@ mod default_tls {
199210 //
200211 // Note: I know this looks like a mess. And it is. Hopefully in the future cargo will support
201212 // platform-specific default features.
202- //
203- // The default provider is s2n-tls on unix and whenever `provider-tls-default-s2n` forces it;
204- // otherwise it is rustls. We only add the impl below when the default type doesn't already
205- // have one from the explicit `rustls`/`s2n_tls` provider modules, to avoid conflicting impls.
206213 #[ cfg( not( any(
207- all(
208- not( any( unix, feature = "provider-tls-default-s2n" ) ) ,
209- feature = "s2n-quic-rustls"
210- ) ,
211- all(
212- any( unix, feature = "provider-tls-default-s2n" ) ,
213- feature = "s2n-quic-tls"
214- )
214+ all( not( unix) , feature = "s2n-quic-rustls" ) ,
215+ all( unix, feature = "s2n-quic-tls" )
215216 ) ) ) ]
216217 mod default_provider {
217218 use super :: * ;
@@ -246,7 +247,11 @@ mod default_tls {
246247 }
247248 }
248249}
249- #[ cfg( not( feature = "provider-tls-default" ) ) ]
250+ #[ cfg( not( all(
251+ feature = "provider-tls-default" ,
252+ not( feature = "provider-tls-s2n" ) ,
253+ not( feature = "provider-tls-rustls" )
254+ ) ) ) ]
250255mod default_tls {
251256 // TODO stub out default that fails with error when started
252257}
0 commit comments