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

[E0027] struct pattern fails to specify struct's fields #2335

Merged
merged 1 commit into from
Jun 30, 2023

Conversation

MahadMuhammad
Copy link
Contributor

struct pattern fails to specify struct's fields

A pattern for a struct fails to specify a sub-pattern for every one of the struct's fields. - pattern does not mention fields x, y

Code tested:

// https://doc.rust-lang.org/error_codes/E0027.html
#![allow(unused)]
fn main() {
    struct Dog {
        name: u32,
        age: u32,
    }

    let d = Dog { name: 1, age: 8 };

    // This is incorrect.
    match d {
        Dog { age: x } => {}
    }
}

Output:

mahad@linux:~/Desktop/mahad/gccrs-build$ gcc/crab1 ../mahad-testsuite/E0027.rs -frust-incomplete-and-experimental-compiler-do-not-use
../mahad-testsuite/E0027.rs:13:9: error: pattern does not mention fields name [E0027]
   13 |         Dog { age: x } => {}
      |         ^~~

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:

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/match2.rs:13:9: error: pattern does not mention fields x [E0027]
compiler exited with status 1

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/match3.rs:13:18: error: variant D does not have a field named z [E0026]
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/match3.rs:13:9: error: pattern does not mention fields x, y [E0027]
compiler exited with status 1

gcc/rust/ChangeLog:

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

A pattern for a struct fails to specify a sub-pattern
for every one of the struct's fields. - pattern does
not mention fields `x`, `y`

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

Signed-off-by: Muhammad Mahad <[email protected]>
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.

Great stuff :)

@CohenArthur CohenArthur added the diagnostic diagnostic static analysis label Jun 27, 2023
@philberty philberty added this pull request to the merge queue Jun 30, 2023
Merged via the queue into Rust-GCC:master with commit 251348f Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants