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

Neither tuple struct nor a tuple variant was used as a pattern - Internal Compiler Error #2430

Closed
MahadMuhammad opened this issue Jul 15, 2023 · 1 comment · Fixed by #2565

Comments

@MahadMuhammad
Copy link
Contributor

Neither tuple struct nor a tuple variant was used as a pattern - E0164

  • Fixing this issue, help gccrs to emit error code E0164 similiar to rustc.
  • You can view the same on compiler-explorer

I tried this code from E0164:

// https://doc.rust-lang.org/error_codes/E0164.html
#![allow(unused)]
fn main() {
enum A {
    B,
    C,
}

impl A {
    fn new() {}
}

fn bar(foo: A) {
    match foo {
        A::new() => (), // error!
        _ => {}
    }
}
}

I expected to see this happen:

  • Give error like rustc i.e.,
➜  mahad-testsuite rustc E0164.rs 
error[E0164]: expected tuple struct or tuple variant, found associated function `A::new`
  --> E0164.rs:14:9
   |
14 |         A::new() => (), // error!
   |         ^^^^^^^^ `fn` calls are not allowed in patterns
   |
   = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html

error: aborting due to previous error

For more information about this error, try `rustc --explain E0164`.

Instead, this happened:

  • gccrs gives internal compile error.
  • Here is the backtrace of gccrs.
➜  mahad-testsuite ../gccrs-build/gcc/crab1 E0164.rs                                                                                   
crab1: internal compiler error: in get_items, at rust/ast/rust-pattern.h:1182
0x7b8896 Rust::AST::TupleStructPattern::get_items()
	../../gccrs/gcc/rust/ast/rust-pattern.h:1182
0x7b8896 Rust::AST::TupleStructPattern::get_items()
	../../gccrs/gcc/rust/ast/rust-pattern.h:1180
0x7b8896 Rust::Resolver::EarlyNameResolver::visit(Rust::AST::TupleStructPattern&)
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.cc:1108
0xb9d650 operator()
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.cc:561
0xb9d650 __invoke_impl<void, Rust::Resolver::EarlyNameResolver::visit(Rust::AST::MatchExpr&)::<lambda()>::<lambda()>&>
	/usr/include/c++/11/bits/invoke.h:61
0xb9d650 __invoke_r<void, Rust::Resolver::EarlyNameResolver::visit(Rust::AST::MatchExpr&)::<lambda()>::<lambda()>&>
	/usr/include/c++/11/bits/invoke.h:111
0xb9d650 _M_invoke
	/usr/include/c++/11/bits/std_function.h:290
0xb9c6e2 std::function<void ()>::operator()() const
	/usr/include/c++/11/bits/std_function.h:590
0xb9c6e2 Rust::Resolver::EarlyNameResolver::scoped(unsigned int, std::function<void ()>)
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.h:50
0xb9c6e2 operator()
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.cc:556
0xb9c6e2 __invoke_impl<void, Rust::Resolver::EarlyNameResolver::visit(Rust::AST::MatchExpr&)::<lambda()>&>
	/usr/include/c++/11/bits/invoke.h:61
0xb9c6e2 __invoke_r<void, Rust::Resolver::EarlyNameResolver::visit(Rust::AST::MatchExpr&)::<lambda()>&>
	/usr/include/c++/11/bits/invoke.h:111
0xb9c6e2 _M_invoke
	/usr/include/c++/11/bits/std_function.h:290
0xb9ce9a std::function<void ()>::operator()() const
	/usr/include/c++/11/bits/std_function.h:590
0xb9ce9a Rust::Resolver::EarlyNameResolver::scoped(unsigned int, std::function<void ()>)
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.h:50
0xb9ce9a Rust::Resolver::EarlyNameResolver::visit(Rust::AST::MatchExpr&)
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.cc:553
0xb9ca80 std::function<void ()>::operator()() const
	/usr/include/c++/11/bits/std_function.h:590
0xb9ca80 Rust::Resolver::EarlyNameResolver::scoped(unsigned int, std::function<void ()>)
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.h:50
0xb9ca80 Rust::Resolver::EarlyNameResolver::visit(Rust::AST::BlockExpr&)
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.cc:408
0xb9af61 operator()
	../../gccrs/gcc/rust/resolve/rust-early-name-resolver.cc:410
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Meta

  • What version of Rust GCC were you using, git sha 866512c
  • Compiler-Explorer version => gccrs (Compiler-Explorer-Build-gcc-a06cec181de6398231e0662c1ed83d905ad6d1d9-binutils-2.40) 13.0.1 20230417 (experimental)

@philberty
Copy link
Member

philberty commented Jul 31, 2023

There is an assertion in the get_items within the AST we should remove. @dkm has a fix for this in the HIR.

We probably just need a check for pattern.has_items ();

@philberty philberty removed their assignment Jul 31, 2023
MahadMuhammad added a commit to MahadMuhammad/gccrs that referenced this issue Aug 16, 2023
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
github-merge-queue bot pushed a commit that referenced this issue Aug 17, 2023
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes #2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 15, 2023
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 5, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 8, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 11, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 12, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
nstester pushed a commit to nstester/gcc that referenced this issue Jan 16, 2024
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes Rust-GCC/gccrs#2430

gcc/rust/ChangeLog:

	* ast/rust-pattern.h: No need of assertion, we are handling it.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Added check which emits error instead of using assertion.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	Added rich location and error code.

gcc/testsuite/ChangeLog:

	* rust/compile/match5.rs:
	Updated comment for dejagnu.
	* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants