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

Expected tuple struct or tuple variant, found struct variant [E0532] #2324

Closed
MahadMuhammad opened this issue Jun 26, 2023 · 0 comments · Fixed by #3118
Closed

Expected tuple struct or tuple variant, found struct variant [E0532] #2324

MahadMuhammad opened this issue Jun 26, 2023 · 0 comments · Fixed by #3118
Labels
bug diagnostic diagnostic static analysis

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Jun 26, 2023

I tried this code:

  • for testing E0532 error, Arm Does Not Match Expected Kind - expected tuple struct or tuple variant, found struct variant.
  • Godbolt link.
enum State {
    Succeeded,
    Failed(u32),
}

fn print_on_failure(state: &State) {
    match *state {
        // error: expected unit struct, unit variant or constant, found tuple
        //        variant `State::Failed`
        State::Failed => (),
        _ => ()
    }
}

I expected to see this happen:

Abort due to E0532 error

error[E0532]: expected unit struct, unit variant or constant, found tuple variant `State::Failed`
  --> <source>:10:9
   |
3  |     Failed(u32),
   |     ----------- `State::Failed` defined here
...
10 |         State::Failed => (),
   |         ^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `State::Failed(_)`

error: aborting due to previous error

Instead, this happened:

Compiled with warning

<source>:6:1: warning: function is never used: 'print_on_failure'
    6 | fn print_on_failure(state: &State) {
      | ^~
Compiler returned: 0

Meta

  • What version of Rust GCC were you using, git sha : ac43e58.
    • gccrs (Compiler-Explorer-Build-gcc-3ccf008b148455c4800f2a7c70be03e1dd708c59-binutils-2.40) 13.0.1 20230417 (experimental)
@CohenArthur CohenArthur added the diagnostic diagnostic static analysis label Jun 27, 2023
@MahadMuhammad MahadMuhammad moved this to Issues for fixing error code support in Error Code Support & Improving User Errors Jul 15, 2023
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 3, 2024
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* backend/rust-compile-expr.cc:
	remove assert to allow for 0 variants in ADT
	* backend/rust-compile-pattern.cc:
	Add check for trying to reference tuple or struct AST variant
	using simple path
	* backend/rust-compile-pattern.h:
	add checker function for E0532 to header

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324.rs:
	add test for E0532

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* backend/rust-compile-expr.cc:
	remove assert to allow for 0 variants in ADT
	* backend/rust-compile-pattern.cc:
	Add check for trying to reference tuple or struct AST variant
	using simple path
	* backend/rust-compile-pattern.h:
	add checker function for E0532 to header

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324.rs:
	add test for E0532

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324.rs:
	add test for E0532

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324.rs:
	add test for E0532

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with tuple enum variant
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with tuple enum variant
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with tuple enum variant
	* rust/compile/issue-2324-2.rs:
	add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
liamnaddell added a commit to liamnaddell/gccrs that referenced this issue Aug 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with tuple enum variant
	* rust/compile/issue-2324-2.rs:
	add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
github-merge-queue bot pushed a commit that referenced this issue Aug 6, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with tuple enum variant
	* rust/compile/issue-2324-2.rs:
	add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
tschwinge pushed a commit that referenced this issue Dec 4, 2024
gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-pattern.cc:
	Emit E0532 when trying to reference a Tuple or Struct variant
	using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-2324-1.rs:
	add test for E0532 with tuple enum variant
	* rust/compile/issue-2324-2.rs:
	add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug diagnostic diagnostic static analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants