Rust-GCC / Rust-GCC/gccrs

ICE in visit when resolving conflicting inherent and trait method implementations for dyn T

Open
#3,710 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

Summary

When compiling a Rust program with conflicting method implementations (an inherent method on dyn T + 'a and a trait implementation for a concrete type), GCCRS encounters an internal compiler error (ICE), while Rustc correctly reports an ambiguity error. This indicates a defect in GCCRS's resolution logic for such cases.

Reproducer

I tried this code:

trait T {
    fn foo(&self);
}

impl<'a> dyn T + 'a {
    fn foo(&self) {}
}

impl T for i32 {
    fn foo(&self) {}
}

fn main() {
    let x: &dyn T = &0i32;
    x.foo();
}
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/4cedhq18h

Actual behavior

crab1: internal compiler error: in visit, at rust/resolve/rust-ast-resolve-type.cc:503
0x2e9eb6c internal_error(char const*, ...)
???:0
0xf5e963 fancy_abort(char const*, int, char const*)
???:0
0x87e968 Rust::Resolver::ResolveTypeToCanonicalPath::visit(Rust::AST::TraitObjectType&)
???:0
0x12180ed Rust::Resolver::ResolveTypeToCanonicalPath::go(Rust::AST::Type*, Rust::Resolver::CanonicalPath&)
???:0
0x1203e80 Rust::Resolver::ResolveItem::visit(Rust::AST::InherentImpl&)
???:0
0x1203a47 Rust::Resolver::ResolveItem::go(Rust::AST::Item*, Rust::Resolver::CanonicalPath const&, Rust::Resolver::CanonicalPath const&)
???:0
0x11f856a Rust::Resolver::NameResolution::go(Rust::AST::Crate&)
???:0
0x109a397 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

Expected behavior

A compilation error indicating multiple applicable foo methods (similar to Rustc's error[E0034]).

GCC Version

14.0.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in rust/resolve/rust-ast-resolve-type.cc at ResolveTypeToCanonicalPath::visit(TraitObjectType), where the reproducer triggers the ICE. Compare GCCRS behavior with Rustc for the dyn T method call and add coverage for the conflicting inherent and trait implementations. Done means reporting an ambiguity error instead of crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.