-
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
Add feature to disable the panic_impl provided by std #100156
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) soon. Please see the contribution instructions for more information. |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
I'm not sure what to do about this. If you're using |
The std panic handler also does a bunch of other stuff beside calling the hook. I want to override all that. |
Hmm, I think this counts as an unstable API then. I suppose you should write a ACP (see the bot post for links) for it? I guess if I'm being honest, I am pretty sympathetic to this desire in principal (I agree the default panic handler does things someone might not want, although the programs where I've wanted this changed were all We had a bunch of discussion about stdlib features at rustconf postconf too (CC @cuviper who I know was there, and @joshtriplett who... might have been at that session too?) (I'm not sure if this is T-libs-api or T-libs, TBH, but since ACP is "API change proposal", I think I'll toggle it?) @rustbot label +T-libs-api -T-libs |
Just to be safe I opened an ACP here rust-lang/libs-team#80, I'm confident there shouldn't be any drawbacks to such a simple change but I'd love more input from the lib's team. This is also my first time contributing to rust so please forgive me if I didn't properly understand the rustc-dev-guide. |
Do we have any precedent for a cargo feature that removes functionality? The usual rule is that features should be purely additive, and I think it would be very strange for the standard library to break that rule.
Part of that discussion was about removing content from the minimal set, The idea was that For your case, maybe |
I would like to use this feature, I would love to see it implemented in any way seen fit. |
Are we sure we want to do this as a negative feature? Usually that's a mistake. This is mentioned in the ACP (which seems to have been accepted) rust-lang/libs-team#80, but not discussed further. |
I guess I'll nominate it but it should be a quick discussion. |
We have a general rule against adding new features to the standard library that have no path to stabilization, and it isn't clear that this is worth the additional complexity in configuration options. The ACP mentions several motivating use cases for this, but I don't think that this feature will actually help achieve these goals:
It's not clear what "other stuff" refers to here: the panic machinery in
Everything else, including backtraces, is handled by the default panic hook which can be overridden.
Again, the use case isn't clear. What are these constraints? Is it just binary size? We already have ways to disable unwinding (
This is unlikely to ever work with |
Looking back I do not think having a [profile.release]
panic = "abort # or unwind It might be a good idea to had a third toggle label "none" or something similar to remove impl. [profile.release]
panic = "none" This could also accept
Perhaps I could have used better wording. What I meant is that it might be desirable to have completely custom code in the panic_handler. This I feel is less of a case of why and more of why should std restrict this? It can be useful even if rarely and it has no impact on user not making use of the feature. I opened this issue back when I did because I need to override the whole panic_handler while still using std, unfortunately I cannot recall what I needed it for but I feel like having more choice is always better than not.
The original use case was for an extremely tiny embedded Linux board. Using std would have been immensely useful since I was still running on top of Linux but squeezing every last byte out of the system was essential.
I am still trying to compile std myself to make sure it works but there is no reason it shouldn't. The way this kind of linking "hacks" work is by making sure there are no panic being linked. Even if std panics if its never called and removed by compiler optimizations it will compile just fine. Making sure that panics are not present is very important for certain applications, especially industry critical targets that can't afford to have panicking paths. This is far from elegant and I always felt like the language its really lacking in that department but this is still a solution nonetheless. I feel like there is value in being able to make std more flexible and this feature would allow panicking to meet that goal. |
This seems like it needs further design work so I am moving it to the author. The latest proposal feels like it probably needs an RFC. @rustbot author |
☔ The latest upstream changes (presumably #119002) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm going to be away for a few months, so I'm rerolling my PRs so that folks don't have to wait for me. Sorry/thanks. r? libs |
@morr0ne any updates on this? |
I think there is definitely value in adding a mechanism to disable the panic handler provided by std. How to do so in a way that feels “rusty” and has a proper stabilisation path is tricky. I am going to write and RFC that address the issues I mentioned in my previous comments. |
This is blocked on writing an rfc, which i think hasn't been written and it will take a while to be accepted which will cause this pr to bitrot till then. So closing this and a new one can be created later once the rfc is accepted |
Currently is only possible to mark a function with #[panic_handler] in no_std environments. This pr adds a feature to disable the
panic_impl
provided by std so that it can be defined in normal programs. Since the feature is not enabled by default it does not affect existing code.Should fix #59222 and hopefully a small but useful step towards custom panic implementation: #32837
ACP: rust-lang/libs-team#80