Skip to content
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

Merged
merged 1 commit into from
Sep 29, 2016
Merged

Conversation

GuillaumeGomez
Copy link
Member

Part of #35233.
Fixes #35211.

r? @jonathandturner

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)
Copy link
Contributor

@sophiajt sophiajt Sep 12, 2016

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?

@sophiajt
Copy link
Contributor

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.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Sep 18, 2016

Updated (I decided to use multispan in the end, way better).

@sophiajt
Copy link
Contributor

From travis:

error: /build/src/test/compile-fail/E0050.rs:12: unexpected "note": 'expected 2 parameters'

error: /build/src/test/compile-fail/E0050.rs:18: unexpected "note": 'found 1 parameter'

error: /build/src/test/compile-fail/E0050.rs:18: expected note not found: expected 2 parameters

error: 2 unexpected errors found, 1 expected errors not found
status: exit code: 101
command: /build/build/x86_64-unknown-linux-gnu/stage2/bin/rustc /build/src/test/compile-fail/E0050.rs -L /build/build/x86_64-unknown-linux-gnu/test/compile-fail --target=x86_64-unknown-linux-gnu --error-format json -L /build/build/x86_64-unknown-linux-gnu/test/compile-fail/E0050.stage2-x86_64-unknown-linux-gnu.compile-fail.libaux -C prefer-dynamic -o /build/build/x86_64-unknown-linux-gnu/test/compile-fail/E0050.stage2-x86_64-unknown-linux-gnu -Crpath -O -Lnative=/build/build/x86_64-unknown-linux-gnu/rust-test-helpers
unexpected errors (from JSON output): [
    Error {
        line_num: 12,
        kind: Some(
            Note
        ),
        msg: "expected 2 parameters"
    },
    Error {
        line_num: 18,
        kind: Some(
            Note
        ),
        msg: "found 1 parameter"
    }
]

not found errors (from test file): [
    Error {
        line_num: 18,
        kind: Some(
            Note
        ),
        msg: "expected 2 parameters"
    }
]

thread '[compile-fail] compile-fail/E0050.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:1084
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    [compile-fail] compile-fail/E0050.rs

test result: FAILED. 2571 passed; 1 failed; 12 ignored; 0 measured

@GuillaumeGomez
Copy link
Member Author

Updated.

@sophiajt
Copy link
Contributor

@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 merge_spans that you can use.

@GuillaumeGomez
Copy link
Member Author

Yeay! \o/

@GuillaumeGomez
Copy link
Member Author

Updated.

Also, please remember that "^" is red while "-" is blue. The output is nicer that what you might think.

@bstrie
Copy link
Contributor

bstrie commented Sep 25, 2016

r? @jonathandturner

@sophiajt
Copy link
Contributor

@bstrie yup, working out best path now. Currently potentially blocked by #36703

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")
Copy link
Contributor

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

Copy link
Contributor

@sophiajt sophiajt left a 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 }
| -------^^^^^--^------^----------------------
Copy link
Contributor

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
Copy link
Contributor

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.

} else {
format!("{} parameter", trait_number_args)
}))
.span_label(span,
Copy link
Contributor

@sophiajt sophiajt Sep 27, 2016

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.

Copy link
Contributor

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

Copy link
Contributor

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...

Copy link
Contributor

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

@GuillaumeGomez
Copy link
Member Author

@jonathandturner: I like your changes! Now it should be finally good. :D

@sophiajt
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 28, 2016

📌 Commit 61cbf41 has been approved by jonathandturner

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 28, 2016
bors added a commit that referenced this pull request Sep 28, 2016
Rollup of 11 pull requests

- Successful merges: #36376, #36672, #36740, #36757, #36765, #36769, #36782, #36783, #36784, #36795, #36796
- Failed merges:
@bors bors merged commit 61cbf41 into rust-lang:master Sep 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants