Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when crate_type attribute is ignored because of --crate-type #43987

Open
RalfJung opened this issue Aug 19, 2017 · 3 comments
Open

Warn when crate_type attribute is ignored because of --crate-type #43987

RalfJung opened this issue Aug 19, 2017 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CLI Area: Command-line interface (CLI) to the compiler C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

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.)

@RalfJung
Copy link
Member Author

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 #43637 for why that is interesting.

@petrochenkov
Copy link
Contributor

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 warnings on command line.

@ishitatsuyuki
Copy link
Contributor

@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.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Aug 20, 2017
@Enselic Enselic changed the title Warn when crate_type attribute is ignored Warn when crate_type attribute is ignored because of --crate-type Sep 15, 2023
@Enselic Enselic added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 15, 2023
@fmease fmease added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CLI Area: Command-line interface (CLI) to the compiler labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CLI Area: Command-line interface (CLI) to the compiler C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants