-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustc compiles function that is never used #70333
Comments
cc @rust-lang/wg-mir-opt perhaps? |
Here it is on playground - you can press the ASM button etc. I forget why the fact that these are actually unused, doesn't factor into whether this should compile or not, I wonder if this, once upon a time, fixed The problem with traits is it's almost impossible to figure out where they might be used from. You can write code that would have the effect of a downstream crate needing What's weird is adding Sadly I don't know these aspects of monomorphization, cc @michaelwoerister @Zoxc |
Ah, for some reason both functions need @WaffleLapkin Out of curiosity, is that a suitable workaround? We should keep this issue open, probably, but a fix might be hard or effectively impossible, so maybe you could use the workaround. |
@eddyb well, I was trying to copy std's approach with |
@WaffleLapkin There's even code like this where it switches between Lines 362 to 366 in 55299b2
|
It might have to do with the reachability pass being rather conservative around methods in trait impls? rust/src/librustc_mir/monomorphize/collector.rs Line 1008 in 1add455
|
Probably because the logic to find unused trait functions are not in place. Also see #50927. |
rustc
seems to compile never used functions in traits:Generates a lot of "panic" asm (godbolt).
I expected not to see unused functions in asm, but they are there.
This also happens when using lib with a similar (never used) trait.
Steps to reproduce
lib
andbin
crates:cargo new --bin neverbin && cargo new --lib neverlib
./neverlib/src/lib.rs
with:cargo asm
for bin crate, you'll see something like that:never_used
andcall_panic
functions, all thepanic!
stuffMeta
rustc --version --verbose
:P.S.
I may misunderstand something, and maybe I've forgot to turn on some optimizations, so correct me if I'm wrong. But this behaviour seems strange.
The text was updated successfully, but these errors were encountered: