Skip to content

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

@MahadMuhammad

Description

@MahadMuhammad

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions