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

Avoid type mismatch error where a variable is bound with different ref-ness #30418

Open
nrc opened this issue Dec 16, 2015 · 2 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nrc
Copy link
Member

nrc commented Dec 16, 2015

e.g.,

match x {
      opts::a(ref i) | opts::b(i) => {}
      //~^ ERROR variable `i` is bound with different mode in pattern #2 than in pattern #1
      //~^^ ERROR mismatched types

Where the field of a and b has the same type

cc #30320

@nrc nrc added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 16, 2015
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 24, 2017
@estebank
Copy link
Contributor

Current output, no change:

error[E0409]: variable `i` is bound in inconsistent ways within the same match arm
 --> src/main.rs:8:32
  |
8 |       opts::a(ref i) | opts::b(i) => {}
  |                   -            ^ bound in different ways
  |                   |
  |                   first binding

error[E0308]: mismatched types
 --> src/main.rs:8:32
  |
8 |       opts::a(ref i) | opts::b(i) => {}
  |                                ^ expected &isize, found isize
  |
  = note: expected type `&isize`
             found type `isize`

@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Jan 26, 2020
@estebank
Copy link
Contributor

Current output:

error[E0409]: variable `i` is bound inconsistently across alternatives separated by `|`
 --> src/lib.rs:8:32
  |
8 |       opts::a(ref i) | opts::b(i) => {}
  |                   -            ^ bound in different ways
  |                   |
  |                   first binding

error[E0308]: mismatched types
 --> src/lib.rs:8:32
  |
7 |     match x {
  |           - this expression has type `opts`
8 |       opts::a(ref i) | opts::b(i) => {}
  |               -----            ^ expected `&isize`, found `isize`
  |               |
  |               first introduced with type `&isize` here
  |
  = note: in the same arm, a binding must have the same type in all alternatives
help: consider adding `ref`
  |
8 |       opts::a(ref i) | opts::b(ref i) => {}
  |                                +++

I don't know what else we can do here beyond silencing the E0409.

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants