Skip to content

Conversation

@ShoyuVanilla
Copy link
Member

@ShoyuVanilla ShoyuVanilla commented Jan 15, 2026

Fixes #148121

When we have the following code:

trait Foo<T> {}

impl Foo<T: Default> for String {}

we delay E0107: wrong number of generic args to suggest moving T: Default bound to the impl block's param declaration.

The delay is determined by whether all the missing generic parameters are mentioned by those wrong assoc item constraints.

But this delay is wrong when there exist any correct assoc item constraints, i.e. when we have an assoc type whose identifier is same with a missing generic parameter like in the following code:

pub trait Super<X> {
    type X;
}
pub trait A {}
impl A for dyn Super<X = ()> {}

@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2026

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tiif
Copy link
Member

tiif commented Jan 16, 2026

r? tiif

@rustbot rustbot assigned tiif and unassigned davidtwco Jan 16, 2026
@tiif
Copy link
Member

tiif commented Jan 16, 2026

This looks correct to me, thanks!

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 16, 2026

📌 Commit 08362d3 has been approved by tiif

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 16, 2026
fix: Do not delay E0107 when there exists an assoc ty with the same name

Fixes rust-lang#148121

When we have the following code:

```rust
trait Foo<T> {}

impl Foo<T: Default> for String {}
```

we delay `E0107: wrong number of generic args` to suggest moving `T: Default` bound to the impl block's param declaration.

The delay is determined by whether all the missing generic parameters are mentioned by those *wrong* assoc item constraints.

But this delay is wrong when there exist any *correct* assoc item constraints, i.e. when we have an assoc type whose identifier is same with a missing generic parameter like in the following code:

```rust
pub trait Super<X> {
    type X;
}
pub trait A {}
impl A for dyn Super<X = ()> {}
```
rust-bors bot pushed a commit that referenced this pull request Jan 16, 2026
Rollup of 4 pull requests

Successful merges:

 - #151155 (THIR patterns: Always use type `str` for string-constant-value nodes)
 - #151166 (fix: Do not delay E0107 when there exists an assoc ty with the same name)
 - #151172 (Use default field values in a few more cases)
 - #151185 (Disable `dump-ice-to-disk` on `i686-pc-windows-msvc`)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 16, 2026
Rollup of 2 pull requests

Successful merges:

 - #151166 (fix: Do not delay E0107 when there exists an assoc ty with the same name)
 - #151185 (Disable `dump-ice-to-disk` on `i686-pc-windows-msvc`)

r? @ghost
@rust-bors rust-bors bot merged commit 0cfe78f into rust-lang:main Jan 16, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 16, 2026
rust-timer added a commit that referenced this pull request Jan 16, 2026
Rollup merge of #151166 - issue-148121, r=tiif

fix: Do not delay E0107 when there exists an assoc ty with the same name

Fixes #148121

When we have the following code:

```rust
trait Foo<T> {}

impl Foo<T: Default> for String {}
```

we delay `E0107: wrong number of generic args` to suggest moving `T: Default` bound to the impl block's param declaration.

The delay is determined by whether all the missing generic parameters are mentioned by those *wrong* assoc item constraints.

But this delay is wrong when there exist any *correct* assoc item constraints, i.e. when we have an assoc type whose identifier is same with a missing generic parameter like in the following code:

```rust
pub trait Super<X> {
    type X;
}
pub trait A {}
impl A for dyn Super<X = ()> {}
```
@ShoyuVanilla ShoyuVanilla deleted the issue-148121 branch January 16, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: trait takes 1 generic argument but 0 generic arguments were supplied

4 participants