Uh oh!
There was an error while loading. Please reload this page.
Make unused-extern-crate warn-by-default - #42588
Conversation
rust-highfive
commented
Jun 11, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
retep998
commented
Jun 11, 2017
|
ishitatsuyuki
commented
Jun 11, 2017
Blocked by #42591 |
oli-obk
commented
Jun 11, 2017
I'm on mobile right now, so I can't really check, but looking at the code it seems to me that when you import a macro that does an unused extern crate import, this lint will trigger, but you can't do anything about it except complain to the author. The macro might unconditionally depend on a crate because it might be hard to detect from the macro args, whether the extern crate is needed. |
nikomatsakis
commented
Jun 14, 2017
@oli-obk is this ever intended to become a hard error? it seems like, in that scenario, you could also set |
nikomatsakis
commented
Jun 14, 2017
I don't really understand why this was allow before, can somebody give me some background? @ishitatsuyuki sorry for the delay btw. |
oli-obk
commented
Jun 14, 2017
Right. I got so hung up in the lint triggering inside the macro, I forgot you can attach attributes to macro invocations. |
ishitatsuyuki
commented
Jun 14, 2017
ishitatsuyuki
commented
Jun 15, 2017
I've got a draft level fix for the blocker by using a hand crafted whitelist. I have no idea if this would work or not. Is there anyone who can give me some hints on this? @jseyfried submitted multiple PRs about the lint, but I'm afraid he's busy on something else since his activity graph is empty recently. |
nikomatsakis
commented
Jun 15, 2017
@ishitatsuyuki sorry, what are you fixing with this whitelist? |
nikomatsakis
commented
Jun 15, 2017
(I guess some errors we see in practice?) |
nikomatsakis
commented
Jun 15, 2017
I'm not really sure what's the best path forward, but I don't particularly love the whitelist. =) Maybe we aren't yet ready to make this lint default to warn. |
ishitatsuyuki
commented
Jun 15, 2017
nikomatsakis
commented
Jun 16, 2017
@ishitatsuyuki I see. Whitelisting the builtins crate is maybe right, but allocator crate doesn't quite seem right -- there could be other allocator crates -- maybe we should instead check whether it is an allocator crate. |
nikomatsakis
commented
Jun 16, 2017
We can do that via the |
ishitatsuyuki
commented
Jun 16, 2017
Sorry, I have absolutely no understanding of rustc internals. Can you take a look for me? |
alexcrichton
commented
Jun 22, 2017
ping @nikomatsakis, do you have thoughts on the last comment? As an aside, I personally feel this lint should never be turned on by default. I've very commonly used |
nikomatsakis
commented
Jun 22, 2017
Can you say a bit more? |
alexcrichton
commented
Jun 22, 2017
Sure yes. The compiler interprets Many To get everything to work, libgit2-sys contains I understand this is useful for pruning dependencies that are accidentally left in, but I don't think we're at a point yet where we should turn it on by default. As a result many sys crates are likely to just start picking up a bunch of |
petrochenkov
commented
Jun 22, 2017
If |
retep998
commented
Jun 22, 2017
I'm definitely in favor of this lint being warn by default. If you genuinely are just pulling in an external crate for the linkage, that really needs to be documented as such and having an |
nikomatsakis
commented
Jun 22, 2017
I think I agree with @retep998 and @petrochenkov that this is a non-obvious use (and I don't mind |
ishitatsuyuki
commented
Jun 23, 2017
I agree with the points mentioned above. I would like to ask for your opinion to build a whitelist for known link-only crates or not. This should include allocator-tagged crates and compiler_builtins. I think this isn't necessary though because if special linkages are going to be #allow with a description, it should apply to these crates too. |
This is a part of libbacktrace linkage and thus the compiler cannot detect if it's used or not.
ishitatsuyuki
commented
Aug 27, 2017
@bors r=petrochenkov |
bors
commented
Aug 27, 2017
📌 Commit a91bdf4 has been approved by |
bors
commented
Aug 27, 2017
bors
commented
Aug 27, 2017
☀️ Test successful - status-appveyor, status-travis |
ishitatsuyuki
commented
Aug 27, 2017
Finally it's done. Let's see the community's reaction to the lint. |
ghost
commented
Aug 28, 2017
While attempting to compile latest rust: |
ishitatsuyuki
commented
Aug 28, 2017
I think you're using local compiler for bootstrapping, but well that's indeed something worth to strip. PR coming. |
Yes I am using config.toml Thanks! |
CryZe
commented
Aug 30, 2017
This still has some false positives in some cases unfortunately. But I just added |
petrochenkov
commented
Aug 30, 2017
@CryZe |
Well, idk if it even shouldn't warn in my case. I have a C API, but I need to wrap it in a binary for emscripten (cause everything else doesn't really work well atm). So I just use So tldr: Symbols are only exported to the linker if you use extern crate. If you don't need anything else, you will still get warnings, even though the extern crate is important for the linker. Update: This may actually be an emscripten only thing. emcc requires a list of all the no_mangle functions, so rustc prepares this list for emcc. The code that prepares this list in rustc might be the one that requires the extern crate to be there. |
petrochenkov
commented
Aug 30, 2017
@CryZe |
gilescope
commented
May 18, 2018
Could a crate that's likely to be 'implicitly used' have a flag indicating that it has 'side effects' so we avoid giving false warnings. I'm guessing the types of crates where we would get false positives know who they are and would be able to flag themselves as such. I think its really important that we have this warning on by default because if each layer of crates has one or two more crates than they need build times will increase significantly. If we're to going to build truly huge stuff with Rust we need all levels of the crate ecosystem to be trying to keep their dependencies to a minimum. |
Apart from enabling the lint, this pull request also removes existing unused crates in the codebase, and fix some amount of false positives on crates with special purposes.
Now that all false positive issues are closed, it should be possible to make it available to wider users.
Quote:
Concerns: can break some
#[deny(warnings)].Close#42591