Stream: t-compiler/wg-diagnostics

Topic: #57008 suggest `|` when `,` founds in invalid match value


Knium (Jan 28 2019 at 05:37, on Zulip):

Hi, is this the correct way to use this?
I have a question, what word should I set at stderr?

Current:

enum E {A, B, C}

fn foo(e: E) -> u32 {
    match e {
        E::A,E::B => 0,
        E::C => 1
    }
}
error: unexpected `,` in pattern
 --> src/main.rs:5:13
  |
5 |         E::A,E::B => 0,
  |         ----^---- help: try adding parentheses: `(E::A,E::B)`

Aim at

error: unexpected `,` in pattern
 --> src/main.rs:5:13
  |
5 |         E::A,E::B => 0,
  |         ----^---- help: try adding parentheses or vertical bar: `(E::A,E::B)` or `E::A | E::B`

like this? Thank you!

oli (Jan 28 2019 at 08:15, on Zulip):

Is this a structured suggestion? If you use span_suggestion the compiler will take care of displaying them properly

Knium (Jan 28 2019 at 11:24, on Zulip):

Does your this mean about the error message of Aim at? Assume that, it is typed by my hand.
So span_suggestion_with_applicability is called there currently.

oli (Jan 28 2019 at 11:28, on Zulip):

Ah, perfect. You can just call that method twice, once for the , suggestion and once for the | suggestion

Knium (Jan 28 2019 at 15:33, on Zulip):

Calling twice works the following result. Does it look good to you for now?

error: unexpected `,` in pattern
 --> src/main.rs:5:13
  |
5 |         E::A,E::B => 0,
  |             ^
help: try adding parentheses
  |
5 |         (E::A,E::B) => 0,
  |         ^^^^^^^^^^^
help: or vertical bar
  |
5 |         `E::A|E::B` => 0,
  |         ^^^^^^^^^^^

If so, I will try to update some tests.

oli (Jan 28 2019 at 15:43, on Zulip):

lgtm. I think it should say "or a vertical bar"

davidtwco (Jan 28 2019 at 15:44, on Zulip):

Perhaps add ellipsis, ie. try adding parentheses.. and ..or a vertical bar.

oli (Jan 28 2019 at 15:58, on Zulip):

Oh I also just noticed that there are backticks in the vertical bar suggestion ;)

davidtwco (Jan 28 2019 at 15:59, on Zulip):

If it isn't too hard, I'd look into suggesting E::A | E::B with a space. Looks like it just replaces the incorrect lonely , though which is probably fine.

Knium (Jan 29 2019 at 02:48, on Zulip):

I corrected the things that you pointed out and pushed my commit, pls check my PR :pray:
Oops, the building was failed... I'm fixing now!

Last update: Nov 15 2019 at 10:20UTC