gccrs icon indicating copy to clipboard operation
gccrs copied to clipboard

Unused parentheses in parameters causes internal compiler error

Open 0xn4utilus opened this issue 1 year ago • 2 comments

The unused parentheses in parameters causes internal compiler error however it is perfectly fine in the body. rustc provides a nice warning and compiles the code.

Code

https://godbolt.org/z/xM4Mnvohr

// error
fn increment(x: i32) -> i32{
    ((x+1))
}

fn increment1((x): (i32)) -> (i32){
    ((x+1))
}

fn increment2(x: i32) -> (i32){
    ((x+1))
}

// correct
fn increment3(x: i32) -> i32{
    ((x+1))
}

Backtrace

crab1: internal compiler error: in resolve_path_to_trait, at rust/typecheck/rust-hir-trait-resolve.cc:128
0x236776c internal_error(char const*, ...)
	???:0
0x9fc178 fancy_abort(char const*, int, char const*)
	???:0
0xcfb1b7 Rust::Resolver::TraitResolver::Resolve(Rust::HIR::TypePath&)
	???:0
0xcf4c17 Rust::Resolver::TypeCheckBase::get_predicate_from_bound(Rust::HIR::TypePath&, Rust::HIR::Type*, Rust::BoundPolarity)
	???:0
0xd0eda4 Rust::Resolver::TypeCheckType::visit(Rust::HIR::TraitObjectType&)
	???:0
0xd0b675 Rust::Resolver::TypeCheckType::Resolve(Rust::HIR::Type*)
	???:0
0xd07352 Rust::Resolver::TypeCheckItem::visit(Rust::HIR::Function&)
	???:0
0xd00b90 Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
	???:0
0xcc16bb Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
	???:0
0xb37894 Rust::Session::compile_crate(char const*)
	???:0
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.
Compiler returned: 1

0xn4utilus avatar Feb 28 '24 01:02 0xn4utilus

This is funny its actually parsing this function wrongly:

fn increment1((x): (i32)) -> (i32){
    ((x+1))
}

The parameter is getting parsed as:

crab1: note: Preparing to parse files.
crab1: note: inferred crate name: test
crab1: note: Attempting to parse file: test.rs
crab1: note: PARSED PATTERN: [(x)]
crab1: note: PARSED PARAMETER: [(x) : TraitObjectTypeOneBound: Has dyn dispatch: false
TraitBound: TraitBound:
Has opening question mark: false
For lifetimes: none
Type path: i32]

philberty avatar Nov 10 '24 16:11 philberty

After todays call lets go for enforcing the dyn keyword

philberty avatar Nov 12 '24 21:11 philberty