-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make unused-extern-crate warn-by-default #42588
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
|
Blocked by #42591 |
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. |
@oli-obk is this ever intended to become a hard error? it seems like, in that scenario, you could also set |
I don't really understand why this was allow before, can somebody give me some background? @ishitatsuyuki sorry for the delay btw. |
Right. I got so hung up in the lint triggering inside the macro, I forgot you can attach attributes to macro invocations. |
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. |
@ishitatsuyuki sorry, what are you fixing with this whitelist? |
(I guess some errors we see in practice?) |
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 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. |
We can do that via the |
Sorry, I have absolutely no understanding of rustc internals. Can you take a look for me? |
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 |
Can you say a bit more? |
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 |
If |
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 |
I think I agree with @retep998 and @petrochenkov that this is a non-obvious use (and I don't mind |
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. |
Finally it's done. Let's see the community's reaction to the lint. |
While attempting to compile latest rust:
|
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! |
This comit applies the following changes: * Deletes the `is_allocator` query as it's no longer used * Moves the `is_sanitizer_runtime` method to a query * Moves the `is_profiler_runtime` method to a query * Moves the `panic_strategy` method to a query * Moves the `is_no_builtins` method to a query * Deletes the cstore method of `is_compiler_builtins`. The query was added in rust-lang#42588 but the `CrateStore` method was not deleted A good bit of these methods were used late in linking during trans so a new dedicated structure was created to ship a calculated form of this information over to the linker rather than having to ship the whole of `TyCtxt` over to linking.
This still has some false positives in some cases unfortunately. But I just added |
@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. |
@CryZe |
This changed in rust-lang/rust#42588.
This comit applies the following changes: * Deletes the `is_allocator` query as it's no longer used * Moves the `is_sanitizer_runtime` method to a query * Moves the `is_profiler_runtime` method to a query * Moves the `panic_strategy` method to a query * Moves the `is_no_builtins` method to a query * Deletes the cstore method of `is_compiler_builtins`. The query was added in rust-lang#42588 but the `CrateStore` method was not deleted A good bit of these methods were used late in linking during trans so a new dedicated structure was created to ship a calculated form of this information over to the linker rather than having to ship the whole of `TyCtxt` over to linking.
This is a partial revert of rust-lang#42588. There is a usability concern reported in rust-lang#44294 that was not considered in the discussion of the PR, so I would like to back this out of 1.21. As is, I think users would have a worse and more confusing experience with this lint enabled by default. We can re-enabled once there are better diagnostics or the case in rust-lang#44294 does not trigger the lint.
Allow unused extern crate again This is a partial revert of #42588. There is a usability concern reported in #44294 that was not considered in the discussion of the PR, so I would like to back this out of 1.21. As is, I think users would have a worse and more confusing experience with this lint enabled by default. We can re-enabled once there are better diagnostics or the case in #44294 does not trigger the lint.
This is a partial revert of rust-lang#42588. There is a usability concern reported in rust-lang#44294 that was not considered in the discussion of the PR, so I would like to back this out of 1.21. As is, I think users would have a worse and more confusing experience with this lint enabled by default. We can re-enabled once there are better diagnostics or the case in rust-lang#44294 does not trigger the lint.
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