Skip to content

Wrong error message for associated constants: error[E0158]: statics cannot be referenced in patterns #47570

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

Closed
matklad opened this issue Jan 19, 2018 · 0 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@matklad
Copy link
Member

matklad commented Jan 19, 2018

trait X {
  const X: usize;
}

struct A;
struct B;

impl X for A {
  const X: usize = 0;
}

impl X for B {
  const X: usize = 1;
}

fn do_match<T1: X, T2: X>(x: usize) {
  let r = match x {
     T1::X => "T1",
     T2::X => "T2",
     _ => "?",
  };
  println!("{}", r);
}

fn main() {
  do_match::<A, B>(1);
  do_match::<A, A>(1);
  do_match::<B, B>(1);
}
λ rustc main.rs                                                                                                                     ~/trash
error[E0158]: statics cannot be referenced in patterns
  --> main.rs:18:6
   |
18 |      T1::X => "T1",
   |      ^^^^^

error[E0158]: statics cannot be referenced in patterns
  --> main.rs:19:6
   |
19 |      T2::X => "T2",
   |      ^^^^^

error: aborting due to 2 previous errors

Looks like the error message is slightly off-base? Should it be something along the lines of "can't match on generic constants"?

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints A-associated-items Area: Associated items (types, constants & functions) labels Jan 23, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jan 31, 2018
…or, r=nikomatsakis

Update associated constants error message

Fixes rust-lang#47570.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

2 participants