Friction log: optional deps in features
list confusing
#9459
Labels
A-diagnostics
Area: Error and warning messages generated by Cargo itself.
A-features
Area: features — conditional compilation
S-accepted
Status: Issue or feature is accepted, and has a team member available to help mentor or review
Cargo's user experience confused me earlier today, so I wanted to share
my thoughts.
I have an existing binary that uses
reqwests
with the default OpenSSLTLS backend. I wanted to change this to use
rustls
instead. So I madethe following change to my
Cargo.toml
:I knew about disabling default features, so I did that off the bat, and
when I rebuilt I saw that
rustls
had been added to myCargo.lock
andopenssl-sys
had been removed. So far, so good. But the code failed atruntime:
The "invalid URL, scheme is not http" bit suggested to me that Rustls
wasn't actually wired up correctly, and I had only managed to disable
the default TLS backend. I poked at
reqwest
'sCargo.toml
and sawthat there was also a
reqwest-tls
feature, so I changed my patch to:…and this worked.
What happened? I had misread the
reqwest
docs, which clearly statethat the Rustls feature is called
rustls-tls
(turns out that I didn'tneed
"rustls"
in the features array at all). Enabling"rustls"
onlyturned on the optional dependency without enabling any of the
cfg
guards, so the functionality was still dead. I was extra confused
because I had tried setting
features = ["zzz"]
, and Cargo politelycomplained to me that
"zzz"
was not a feature. This led me to believethat
"rustls"
was a feature, though it was not.So, the final, correct patch was just:
but it was harder for me to get there than perhaps it could have been.
I found it surprising that the
features
array also enables things thatare not features, and it occurred to me that if I were designing this
from scratch, I might not make that decision. There could be separate
fields for
features = ["foo"]
anddeps = ["bar"]
, with appropriatelyprecise checking for each.
I searched briefly for related discussion on issues in this repo, but
didn't find anything. Other than this issue, Cargo is lovely, as always;
thank you! :-)
The text was updated successfully, but these errors were encountered: