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

Consolidate pattern check errors #53840

Closed
estebank opened this issue Aug 30, 2018 · 5 comments
Closed

Consolidate pattern check errors #53840

estebank opened this issue Aug 30, 2018 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@estebank
Copy link
Contributor

Given:

enum E {
    Foo(String, String, String),
}

fn main() {
    match E::Foo("".into(), "".into(), "".into()) {
        E::Foo(a, b, ref c) => {}
    }
}

the current pattern check emits one diagnostic per mismatched usage:

error[E0009]: cannot bind by-move and by-ref in the same pattern
 --> file.rs:7:16
  |
7 |         E::Foo(a, b, ref c) => {}
  |                ^     ----- both by-ref and by-move used
  |                |
  |                by-move pattern here

error[E0009]: cannot bind by-move and by-ref in the same pattern
 --> file.rs:7:19
  |
7 |         E::Foo(a, b, ref c) => {}
  |                   ^  ----- both by-ref and by-move used
  |                   |
  |                   by-move pattern here

Ideally, the pattern check should collect all problematic patterns when possible to reduce how many diagnostics are emitted:

error[E0009]: cannot bind by-move and by-ref in the same pattern
 --> file.rs:7:16
  |
7 |         E::Foo(a, b, ref c) => {}
  |                ^  ^  ----- both by-ref and by-move used
  |                |  |
  |                |  by-move pattern here
  |                by-move pattern here
  |
help: use by-ref everywhere
  |
7 |         E::Foo(ref a, ref b, ref c) => {}
  |                ^^^    ^^^
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Aug 30, 2018
@PramodBisht
Copy link
Contributor

@estebank can I take this on, if nobody is working on it.

@estebank
Copy link
Contributor Author

estebank commented Sep 9, 2018

@PramodBisht that would be great!

@PramodBisht
Copy link
Contributor

@estebank if we collect them first and then emit once then there can be a case where the diagnostic order is different from the present state. Is that okay?

@estebank
Copy link
Contributor Author

estebank commented Sep 9, 2018

That should be fine.

PramodBisht added a commit to PramodBisht/rust that referenced this issue Oct 2, 2018
we are consolidating `cannot bind by-move and by-ref in the same
pattern` message present on the different lines into single diagnostic
message.

To do this, we are first gathering those spans into the vector
after that we are throwing them with the help of MultiSpan in
a separate block.

Addresses: rust-lang#53840
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 2, 2018
rust-lang#53840: Consolidate pattern check errors

rust-lang#53840  on this PR we are aggregating `cannot bind by-move and by-ref in the same pattern` message present on the different lines into one diagnostic message. Here we are first gathering those `spans` on `vector` then we are throwing them with the help of `MultiSpan`
r? @estebank

Addresses: rust-lang#53480
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 2, 2018
rust-lang#53840: Consolidate pattern check errors

rust-lang#53840  on this PR we are aggregating `cannot bind by-move and by-ref in the same pattern` message present on the different lines into one diagnostic message. Here we are first gathering those `spans` on `vector` then we are throwing them with the help of `MultiSpan`
r? @estebank

Addresses: rust-lang#53480
bors added a commit that referenced this issue Oct 2, 2018
Rollup of 10 pull requests

Successful merges:

 - #54269 (#53840: Consolidate pattern check errors)
 - #54458 (Allow both explicit and elided lifetimes in the same impl header)
 - #54603 (Add `crate::` to trait suggestions in Rust 2018.)
 - #54648 (Update Cargo's submodule)
 - #54680 (make run-pass tests with empty main just compile-pass tests)
 - #54687 (Use impl_header_lifetime_elision in libcore)
 - #54699 (Re-export `getopts` so custom drivers can reference it.)
 - #54702 (do not promote comparing function pointers)
 - #54728 (Renumber `proc_macro` tracking issues)
 - #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn)

Failed merges:

r? @ghost
@PramodBisht
Copy link
Contributor

I think this can be closed now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

2 participants