-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Regression in error message when a custom derive panics #47812
Comments
It is indeed caused by #47634 where rustc no longer swallows stderr. This does seem desirable to me however and helps track down the bug in the plugin. How would you get panic backtraces on stable? |
It is not a bug in the plugin -- panicking is the intended way for custom derives to report errors to the user. #[macro_use]
extern crate serde_derive;
#[derive(Serialize)]
struct S {
#[serde(broken)]
f: u8,
}
Showing the line number within the custom derive at which the error was detected is unnecessary and unhelpful. |
I see that the RFC uses panics as a temporary way to report errors. We do still want to report the backtrace if desired though. cc @rust-lang/compiler |
Longer term, this does seem like a suboptimal way to report errors, since it doesn't allow for more than one error at a time very gracefully, right? Still, if that's the expected way, we have to support it.
At the limit, we can do a cc @rust-lang/libs -- how configurable is the "print to stderr on panic" code here? |
We can install a panic handler in rustc which does nothing when we are in compiler plugins. |
Seems like a decent idea. Would this also suppress |
It would suppress the |
@nikomatsakis yes |
@Zoxc I meant, if one does set |
@nikomatsakis We could do that, although it is likely users will have |
@Zoxc I suppose that could happen with
Isn't this arguing that we should show some sort of backtrace from inside the plugin? |
@nikomatsakis Indeed. I suggest we create a |
Huh. I propose we first fix the regression, then worry about |
I'd sort of rather we debate the whole "reuse |
triage: P-high It's important that proc-macro derive output not regress in the normal case. The rest can be debated. @oli-obk may take a shot at this over next few days, but I'm sure they won't object if somebody else does! I'd be happy with any of the above:
I'm a bit reluctant about introducing our own env vars, would want to at least get wider agreement on that, and decide what name to use carefully. |
@nrc Do any tools which depend on rustc also use a custom panic handler? |
I've opened a PR to fix this. Interestingly we have a test for the previous behavior already, |
panicking is only meant to be a temporary way to report errors for proc macros. There should be a better way in the long run, but we might also need to panic as a 'fatal error' mechanism. It is also the stabilised way to error out of a custom derive. I'm not aware of tools which use a custom panic handler, but it is certainly something they might want to do. I'd be very wary of letting any kind of panic reach the compiler driver API points or forcing a backtrace (or any error info) to be printed out on a panic which a tool can't catch. |
Huh. So I went digging into why the test did not fail and discovered that I just can't reproduce this problem at all... @dtolnay, I tried your reproduction, except that I had to add Are there some funny options or something that would be needed? Basically, I only see this output:
|
I am testing commit 56733bc |
This script should reproduce the error message I showed. #!/bin/bash
rustup update nightly-2018-02-08
cargo new repro --bin
echo >>repro/Cargo.toml '
[lib]
proc-macro = true
'
echo >repro/src/lib.rs '
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_derive(Panic)]
pub fn f(_input: TokenStream) -> TokenStream {
panic!("no can do");
}
'
echo >repro/src/main.rs '
#[macro_use]
extern crate repro;
#[derive(Panic)]
struct S;
fn main() {}
'
cargo +nightly-2018-02-08 build --manifest-path repro/Cargo.toml |
So -- strangely -- I see the message with nightly, but not with my local rustc. Perhaps it's one of the options I have enabled? |
Do not run the default panic hook inside procedural macros. Fixes rust-lang#47812 r? @nikomatsakis
Between nightly-2018-01-26 and nightly-2018-01-27 the error message for a custom derive panic got worse. This is the range 9fd7da9...bacb5c5. Mentioning @Zoxc because #47634 sounds relevant.
src/main.rs
src/lib.rs
Before:
After:
The text was updated successfully, but these errors were encountered: