Warn when crate_type attribute is ignored because of --crate-type
I just learned the hard way (i.e. after lots of scratching my head) that the crate_type attribute is entirely ignored when Cargo is used. This is hinted at in https://doc.rust-lang.org/nightly/reference/linkage.html, but only if you know that cargo always passes --crate-type. The first hit when I search for the attribute is https://rustbyexample.com/attribute/crate.html which doesn't mention this at all.
Those sites should probably be fixed, but moreover, I think the compiler shouldn't just silently ignore these attributes. It should tell me. That would have saved me lots of time.
(There may be other attributes which are similarly ignored. crate_name comes to my mind. But I don't know for sure.)
I would find it even better if the attribute was not ignored but could be used to add more crate types to be built -- that would make it possible to use features to control additional crate types, e.g. to always build an rlib and optionally also a dylib. See https://github.com/rust-lang/rust/issues/43637 for why that is interesting.
Ralf Jung at 2017-08-19 12:22:40
It's also a bit strange that command-line is preferred to source in case of conflict. It's usually another way, e.g.
#![allow(warnings)]in source overrides-D warningson command line.Vadim Petrochenkov at 2017-08-19 12:25:21
@petrochenkov well,
#![deny(warnings)]can be allowed on command line though (that's what cargo do for deps). Maybe your example is just the precedence of allow and deny.Tatsuyuki Ishi at 2017-08-20 11:26:36