rust-lang / rust-lang/rust

empty arg lists get ignored when considering whether to apply default args

Open
#136,488 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

struct Foo<T = u32, U = i32>(T, U);

impl<T, U> Foo<T, U> {
    fn foo() -> Self {
        loop {}
    }
}

fn main() {
    let a = Foo::<u32, i32>::foo();
    let b = Foo::<u32>::foo(); // ok
    let c = Foo::<>::foo(); // ambiguity error
    let d = Foo::foo(); // ambiguity error
}

The same way Foo::<u32> instantiates U with i32, so should Foo::<> for T and U.

My expected behavior is that d is ambiguous while c compiles

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 with the Rust reproduction in the issue and trace how the compiler handles Foo::<>() versus omitted generic arguments. Done means Foo::::foo() remains valid, Foo::<>::foo() compiles using defaults, and Foo::foo() remains ambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
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.