-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Support for fatal compile_error that suppresses subsequent errors #68838
Comments
I think making compile_error always immediately fatal makes sense. Since it's unconditional and only useful in cases like this (I believe?), that should be fine. |
That's not the only use case for |
I think it's true that there are cases where it might not necessarily need to be fatal, but I don't know that I'd say that they are common, and that the usability impact of an (unnecessary) fatal error is worse than the impact of emitting a fatal error (and potentially losing others errors as a result). I am not sure what you mean by "don't let other crates compile" -- to my knowledge, Cargo has no way of knowing whether a fatal error (or a normal error) happened? If we decide not to pursue a fatal error, we're basically saying that good usage of compile_error for crate-level gating as @joshtriplett is proposing here should look something like this, I think, which while not bad seems much less ergonomic than the "just a fatal error" option.
Of course, an alternative design would be to try to have some heuristic -- e.g., compile_error at the "top level" of macro expansion, modulo cfg gating, would lead to a fatal error, but that seems like a bad idea. |
Hmm; maybe I'm misinformed; I thought a fatal error would prevent Cargo from proceeding to other crates. Regarding "common" or not, ideally it would be based on some survey. Otherwise it feels like mostly speculation. Doing A third design would be to add another macro (why I added the language team). |
@Mark-Simulacrum I don't think we should make |
I would suggest |
I guess -- maybe a good question to ask: why is making compile_error produce fatal errors a bad thing?. Both of you seem to be against the fatal error, but I'm still not entirely clear why. I think it's true that we're trying to move away from fatal errors in general -- but if the proposal is introducing another macro that would fatal error anyway, it seems like there's not much advantage in making compile_error not error fatally anyway. I would expect that we'd rather avoid two macros that do almost the same thing than make the existing macro uniformly usable (if subpar in some sense in some cases). |
FWIW, we could add an extra argument to compile_error!(error, "message"); // Non-fatal error
compile_error!(fatal_error, "message"); // Fatal error
compile_error!(warning, "message"); // Warning
compile_error!("message"); // Sugar for `compile_error!(error, "message")` (Inspired by CMake, of all things.) I also think non-fatal is a better default, we've done some significant amount of work making sure that non-fatal errors can be reported without causing a waterfall of follow-up errors in most cases. |
To add my two cents to this: The documentation currently states that Also, what is the current correct way to generate a fatal compile error? Calling |
Although it still spits out a bunch of errors at least the first one will be informative about the root cause. rust-lang/rust#68838 tracks a version that suppresses subsequent errors.
Although it still spits out a bunch of errors at least the first one will be informative about the root cause. rust-lang/rust#68838 tracks a version that suppresses subsequent errors.
Hi there! I was wondering what the current status of this is, and if there's an idiomatic way to do it. I have an attribute proc macro attached to At present, I'm generating a Assuming that there's no language solution for this yet, what's the best way to terminate compilation and suppress as much as of the following output as possible? |
If a crate includes something like:
then it isn't helpful for rustc to report that error but then go on to emit many more cascading errors about failed
use
statements and types that don't exist and similar.It's especially unhelpful when those additional errors scroll the initial error off the screen.
The text was updated successfully, but these errors were encountered: