-
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
Update E0050 to new error format #36376
Conversation
9a9b45f
to
2260b69
Compare
impl_m_span | ||
} else { | ||
mk_sp(impl_m_sig.decl.inputs[0].pat.span.lo, | ||
impl_m_sig.decl.inputs.last().unwrap().pat.span.hi) |
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.
Can you put a comment in here about why it's safe to mix spans? ie - how does this avoid the common pitfalls of mixing spans together?
Just had a couple points - needs a bit of commenting, and would be good, since you're changing spans, to move the unit test to a UI test. |
2260b69
to
7f9b576
Compare
Updated (I decided to use multispan in the end, way better). |
From travis:
|
7f9b576
to
09dd053
Compare
Updated. |
@GuillaumeGomez - if you want to merge the spans for the arguments, you should be able to now. I have a new method in CodeMap called |
Yeay! \o/ |
76abee7
to
d3fd646
Compare
Updated. Also, please remember that "^" is red while "-" is blue. The output is nicer that what you might think. |
d3fd646
to
8757c94
Compare
let (diff, text) = if impl_m.fty.sig.0.inputs.len() > trait_m.fty.sig.0.inputs.len() { | ||
(impl_m.fty.sig.0.inputs.len() - trait_m.fty.sig.0.inputs.len(), "less") | ||
} else { | ||
(trait_m.fty.sig.0.inputs.len() - impl_m.fty.sig.0.inputs.len(), "more") |
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.
nit: you could put impl_m.fty.sig.0.inputs.len()
and trait_m.fty.sig.0.inputs.len()
in variables rather than repeating them
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've added some comments. I think the big thing is following something closer to #35211
| ----------------------------- expected 2 parameters | ||
... | ||
18 | fn foo(&self, y: u8, z: u8) -> bool { true } | ||
| -------^^^^^--^------^---------------------- |
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.
This shouldn't be needed anymore
fn bar(&self) { } //~ ERROR E0050 | ||
//~| NOTE found 1 parameter | ||
fn less(&self, x: u8, y: u8, z: u8) { } //~ ERROR E0050 | ||
//~| NOTE found 4 parameters |
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.
Rather than putting "found x parameters" here, I think the design in #35211 would read better. Specifically the primary errors showing specifically what is going wrong.
191f754
to
07598f5
Compare
} else { | ||
format!("{} parameter", trait_number_args) | ||
})) | ||
.span_label(span, |
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's hard to tell by looking, but I'd expect this .span_label
to use the same span as the struct_span_err!
. Do you know why they're different?
I mention it because they have to be the same span for the ^^^ primary underline.
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.
Yup, I just tried building it and they aren't the same span, which gives you output like this:
error[E0050]: method `less` has 4 parameters but the declaration in trait `Foo::less` has 1
--> src/test/compile-fail/E0050.rs:24:13
|
14 | fn less(&self); //~ NOTE trait requires 1 parameter
| --------------- trait requires 1 parameter
...
24 | fn less(&self, x: u8, y: u8, z: u8) { } //~ ERROR E0050
| --------^^^^^--------------------------
| |
| expected 1 parameter, found 4
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 looks like you just need:
- .span_label(span,
+ .span_label(mspan,
And remove the unused span
. With that it's at least closer:
error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 4
--> src/test/compile-fail/E0050.rs:22:5
|
13 | fn bar(&self, x: u8, y: u8, z: u8); //~ NOTE trait requires 4 parameters
| ----------------------------------- trait requires 4 parameters
...
22 | fn bar(&self) { } //~ ERROR E0050
| ^^^^^^^^^^^^^^^^^ expected 4 parameters, found 1
error[E0050]: method `less` has 4 parameters but the declaration in trait `Foo::less` has 1
--> src/test/compile-fail/E0050.rs:24:13
|
14 | fn less(&self); //~ NOTE trait requires 1 parameter
| --------------- trait requires 1 parameter
...
24 | fn less(&self, x: u8, y: u8, z: u8) { } //~ ERROR E0050
| ^^^^^ expected 1 parameter, found 4
Not sure why it's doing the full underline rather than just the parameter...
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.
Played around a bit more. You can see what I ended up doing here: https://github.com/jonathandturner/rust/tree/e0050
Changes:
- Focused the trait secondary span on the parameter rather than underlining everything
- Focused the impl primary span on the parameter rather than underlining everything in the case of the trait having more parameters than the impl
- Made the displaying of the trait span optional since the trait may have come from outside the current crate
07598f5
to
61cbf41
Compare
@jonathandturner: I like your changes! Now it should be finally good. :D |
@bors r+ rollup |
📌 Commit 61cbf41 has been approved by |
…rner Update E0050 to new error format Part of rust-lang#35233. Fixes rust-lang#35211. r? @jonathandturner
Part of #35233.
Fixes #35211.
r? @jonathandturner