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

[E0023] Incorrect Number of Fields in Pattern Extraction #2325

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

MahadMuhammad
Copy link
Contributor

ErrorCode[E0023]: Incorrect Number of Fields in Pattern Extraction

  • The pattern has x fields, but the corresponding tuple variant has y field.

Code Tested:

// https://doc.rust-lang.org/error_codes/E0023.html
fn main() {
    enum Fruit {
        Apple(u32, u32),
        Pear(u32),
    }

    let x = Fruit::Apple(1, 2);

    match x {
        Fruit::Apple(a) => {} // error! : this pattern has 1 fields but the corresponding tuple variant has 2 field
        _ => {}
    }
}

Output:

mahad@linux:~/Desktop/mahad/gccrs-build$ gcc/crab1 ../mahad-testsuite/E0023.rs -frust-incomplete-and-experimental-compiler-do-not-use
../mahad-testsuite/E0023.rs:11:5: error: this pattern has 1 fields but the corresponding tuple variant has 2 field [E0023]
   11 |     Fruit::Apple(a) => {}, // error!
      |     ^~~~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

Running testcases:

/mahad/gccrs/gcc/testsuite/rust/compile/match1.rs:12:9: error: this pattern has 2 fields but the corresponding tuple variant has 1 field [E0023]
compiler exited with status 1

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): called rust_error_at

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>

ErrorCode[E0023]: Incorrect Number of Fields in Pattern Extraction. 
The pattern has x fields, but the corresponding tuple variant 
has y field

gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): called rust_error_at

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
@philberty philberty self-requested a review June 27, 2023 09:27
@philberty philberty self-assigned this Jun 27, 2023
@philberty philberty added enhancement diagnostic diagnostic static analysis labels Jun 27, 2023
@philberty philberty added this to the GCC 13.2 release milestone Jun 27, 2023
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty
Copy link
Member

While you are doing this can you raise issues if they exist where we could improve our location info? @MahadMuhammad

@philberty philberty added this pull request to the merge queue Jun 27, 2023
@MahadMuhammad
Copy link
Contributor Author

@philberty, Okay :)

Merged via the queue into Rust-GCC:master with commit 5711a2a Jun 27, 2023
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis enhancement
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants