-
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 explain #48337
Rustc explain #48337
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
\"rustc --explain {}\"", | ||
&error_codes[0]).expect("failed to give tips..."); | ||
} else { | ||
writeln!(self.dst, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this message show up for errors that don't show any extra information if --explain
is run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand your point...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I confused this with the teach
flag
The travis failure doesn't make any sense. When I run rustc on the tests, I don't get the same output, even with the same parameters. Did I miss something (it's just like the code is run in parts and then the new error message gets printed after each of them)? |
r? @estebank |
That might be because ui tests are run with |
Should I update how it's done then? Because right now, as I said, it has nothing in common with the actual output... |
0d4682c
to
a317e7a
Compare
Should be done now. |
a317e7a
to
4c63eea
Compare
Still failing :-/ Minimal difference due to JSON encoding:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The windows/linux normalizer changes \
to /
, previously the json decoder removed escape backslashes during string decoding
src/tools/compiletest/src/runtest.rs
Outdated
@@ -1629,8 +1632,8 @@ impl<'test> TestCx<'test> { | |||
.iter() | |||
.any(|s| s.starts_with("--error-format")) | |||
{ | |||
rustc.args(&["--error-format", "json"]); | |||
}, | |||
//rustc.args(&["--error-format", "json"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover comment.
2818fe4
to
8dbdae2
Compare
It passed tests. \o/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After addressing the nitpick, r=me.
if !self.short_message && !self.error_codes.is_empty() { | ||
let mut error_codes = self.error_codes.clone().into_iter().collect::<Vec<_>>(); | ||
error_codes.sort(); | ||
if error_codes.len() > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this restrict the error list to some reasonable amount? I'm ok with any amount, but I'd constrain it to at most two full 80 col lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really matter? I can do it but I'm not sure if this is very useful... You're not supposed to try to have as much errors as possible when writing code haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be rare, but I see no reason for us not to gracefully handle that case :)
It won't ever be possible for a given project to have more than a subset of the ~600 errors the compiler has, but regardless, it is worthless to list the error codes, once the user understands how to use the flag, it makes more sense to scroll to the error that they want more information on and copy the error code from there, as the error code on it's own is meaningless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll limit then.
I still think there's value in limiting the amount of error codes listed to a reasonable amount, but it is silly to block on it. Also, it would also be nice to have a way to disable this output, but I won't block this PR on this. We need to add a compiler config file to handle this and other cases (--teach, coloring, one line output, etc.). @bors r+ |
📌 Commit 8dbdae2 has been approved by |
☔ The latest upstream changes (presumably #48399) made this pull request unmergeable. Please resolve the merge conflicts. |
Damn, it was new tests... |
CI passed so let's r+ again (with a higher priority to avoid being outdated once again)... @bors: r=estebank p=10 |
📌 Commit ce6429a has been approved by |
Rustc explain Fixes #48041. To make the review easier, I separated tests update to code update. Also, I used this script to generate new ui tests stderr: ```python from os import listdir from os.path import isdir, isfile, join PATH = "src/test/ui" def do_something(path): files = [join(path, f) for f in listdir(path)] for f in files: if isdir(f): do_something(f) continue if not isfile(f) or not f.endswith(".stderr"): continue x = open(f, "r") content = x.read().strip() if "error[E" not in content: continue errors = dict() for y in content.splitlines(): if y.startswith("error[E"): errors[y[6:11]] = True errors = sorted(errors.keys()) if len(errors) < 1: print("weird... {}".format(f)) continue if len(errors) > 1: content += "\n\nYou've got a few errors: {}".format(", ".join(errors)) content += "\nIf you want more information on an error, try using \"rustc --explain {}\"".format(errors[0]) else: content += "\n\nIf you want more information on this error, try using \"rustc --explain {}\"".format(errors[0]) content += "\n" x = open(f, "w") x.write(content) do_something(PATH) ```
☀️ Test successful - status-appveyor, status-travis |
@@ -2544,6 +2545,7 @@ impl<'test> TestCx<'test> { | |||
} | |||
} | |||
if !explicit { | |||
let proc_res = self.compile_test(&["--error-format", "json"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's just compile all the tests twice.
Who cares about time, certainly not Appveyor.
I know I'm late, but I would argue that this would be better phrased as something more like:
(avoids informal-sounding second person, omits needless word 'using', backticks instead of quotation marks for code). |
@zackmdavis: A bit yes. Let me update then... |
@@ -115,6 +116,33 @@ struct FileWithAnnotatedLines { | |||
multiline_depth: usize, | |||
} | |||
|
|||
impl Drop for EmitterWriter { | |||
fn drop(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuillaumeGomez (more belated commentary in light of #48550) What was the motivation for putting the this in drop()
? Semantically, printing the message notifying the user about --explain
does not seem like a "cleanup" action. As Niko suggested, I would kind of expect this to go with the "aborting due to previous error" message in Handler.abort_if_errors
—and it looks like the Handler
already knows which codes have been emitted, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, if this is true, it might allow to make my task for #48562.
This reverts commit 1dc2015, which switched to compiling the UI tests twice rather than extracting the humanized output from a field in the JSON output. A conflict in this revert commit had to be fixed manually where changes introduced in rust-lang#48449 collide with the change we're trying to revert (from rust-lang#48337). This is in the matter of rust-lang#48550. Conflicts: src/tools/compiletest/src/runtest.rs
This reverts commit 9b597a1. That commit added a message informing users about the `rustc --explain` functionality inside of a `Drop` implementation for `EmitterWriter`. In addition to exhibiting questionable semantics (printing a hopefully-helpful message for the user does not seem like a "cleanup" action), this resulted in divergent behavior between humanized output and JSON output, because the latter actually instantiates an `EmitterWriter` for every diagnostic. Several conflicts in this revert commit had to be fixed manually, again owing to code-area collision between rust-lang#48449 and rust-lang#48337. This is in the matter of rust-lang#48550. Conflicts: src/librustc_errors/emitter.rs
@GuillaumeGomez One last comment (sorry if it seems like I've been overly critical with respect to this feature; sometimes good code requires a lot of discussion, and sometimes I have a lot of things to say), but arguably the |
TIL that you can not only The commit message on that PR implies the idea was to make |
Fixes #48041.
To make the review easier, I separated tests update to code update. Also, I used this script to generate new ui tests stderr: