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

Better error message for matching against not-imported enum variant #12594

Closed
edwardw opened this issue Feb 27, 2014 · 3 comments
Closed

Better error message for matching against not-imported enum variant #12594

edwardw opened this issue Feb 27, 2014 · 3 comments

Comments

@edwardw
Copy link
Contributor

edwardw commented Feb 27, 2014

If only the enumeration type itself is imported but not its variants, a match expression reports unreachable pattern instead of unrecognised type:

pub mod inner {
  pub enum E {
    E1,
    E2
  }
}

pub mod foo {
  use inner::E; // change this to use inner::{E, E1, E2} then all will be fine

  pub fn bar(e: E) -> int {
    match e {
      E1 => 0,
      E2 => 1    // error: unreachable pattern
    }
  }
}

pub fn main() {}

Is this something intentional? Or should we give it a more sensible error message?

@pnkfelix
Copy link
Member

This is a duplicate of #4612, #4639, #7807, #10402.

The above were closed either as dupes of each other or with a statement saying that the work remaining was captured by a more general lint for our capitalization convention. I am inclined to disagree with the latter: a very specific error message can and should be applied here, IMO.

Anyway, the suggested lints are in metabug #3070 and more specifically #10304 and #7526 (a related issue).

@pnkfelix
Copy link
Member

Also PR #12300 will probably help with this (its basically the aforementioned capitalization lint). Though I continue to think a more specific error check is warranted here.

(In particular, automatic FFI binding generators will in general introduce names that do not fit our capitalization conventions. My opinion is that we should not attempt to force binding generators to follow our conventions in all cases. In a case like this, we can provide a better error message, e.g. via the strategy outlined in #4639.)

@pnkfelix
Copy link
Member

closing as duplicate of the issues mentioned in earlier comments.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
internal: Lift out IdentContext from CompletionContext

Makes things a bit messy overall, but with this I can start cleaning up the render functions properly now.
cc rust-lang/rust-analyzer#12571
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 4, 2024
Situation: `let_unit` lints when an expression binds a unit (`()`)
to a variable. In some cases this binding may be passed down to
another function. Currently, the lint removes the binding without
considering usage.

Change: All usages of the elided variable are now replaced with `()`.

fixes: rust-lang#12594
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 4, 2024
Elide unit variables linted by `let_unit` and use `()` directly instead

Situation: `let_unit` lints when an expression binds a unit (`()`) to a variable. In some cases this binding may be passed down to another function. Currently, the lint removes the binding without considering usage.

fixes: rust-lang#12594

changelog: Suggestion Fix [`let_unit`]. Clippy will remove unit bindings and replace all their instances in the body with `()`.
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

No branches or pull requests

2 participants