Skip to content

ICE when using associated types #2015

Closed
Closed
@CohenArthur

Description

@CohenArthur

I tried this code:

macro_rules! impl_foo {
	() => { impl Foo }
}

pub trait Foo {}

pub trait Bar {
    type Baz;
}

pub fn foo(_value: impl Bar<Baz = impl_foo!()>) -> i32 {
    15
}

pub fn bar(_value: impl Bar<Baz = impl Foo>) -> i32 {
    16
}

I expected to see this happen: no errors

Instead, this happened: internal compiler error when lowering the type:

crab1: internal compiler error: in translate, at rust/hir/rust-ast-lower-type.h:71
0x20fe2c8 Rust::HIR::ASTLoweringType::translate(Rust::AST::Type*)
	../../gcc/rust/hir/rust-ast-lower-type.h:71
0x211211f Rust::HIR::ASTLoweringItem::visit(Rust::AST::Function&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-item.cc:428
0x1ed9240 Rust::AST::Function::accept_vis(Rust::AST::ASTVisitor&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:5395
0x210f362 Rust::HIR::ASTLoweringItem::translate(Rust::AST::Item*)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-item.cc:37
0x20fa70e Rust::HIR::ASTLowering::go()
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower.cc:79
0x20fa625 Rust::HIR::ASTLowering::Resolve(Rust::AST::Crate&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower.cc:69
0x1fd77d4 Rust::Session::compile_crate(char const*)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/rust-session-manager.cc:591
0x1fd6f87 Rust::Session::handle_input_files(int, char const**)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/rust-session-manager.cc:375
0x1e78586 grs_langhook_parse_file()
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/rust-lang.cc:185
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.

9024d99

A different case with simpler associated types:

macro_rules! foo {
    () => {
        u32
    };
}

pub trait Bar {
    type Baz;
}

pub fn foo<T: Bar<Baz = foo!()>>(_value: T) -> i32 {
    15
}

pub fn bar<T: Bar<Baz = u32>>(_value: T) -> i32 {
    16
}

Same error, same hash

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions