Skip to content

A "cannot infer type" compilation error appeared from 1.87.0-nightly (249cb84 2025-03-12) #138937

Closed
@albertog78

Description

@albertog78

A "cannot infer type" compilation error appeared in nightly-2025-03-13, 1.87.0-nightly (249cb84 2025-03-12) and subsequent versions

Code

I tried this code:

pub trait TraitA {}
pub trait TraitB<T> {
    fn f_b(a: T) -> Self;
}
pub trait TraitC: TraitB<Self::Value> {
    type Value: TraitA;
}
pub trait TraitD: TraitC<Value = Self::Scalar> {
    type Scalar: TraitA;
}

pub trait TraitE {
    //This fails compiling in 1.87.0-nightly (249cb8431 2025-03-12)
    fn apply<A: TraitA, PF: TraitD<Scalar = A>>(&self);
}

pub struct StructA;
impl StructA {
    //This compiles correctly
    pub fn apply<A: TraitA, PF: TraitD<Scalar = A>>(&self) {}
}

I expected to see this happen: compiling successfully

Instead, this happened:

error[E0284]: type annotations needed
  --> src/lib.rs:14:5
   |
14 |     fn apply<A: TraitA, PF: TraitD<Scalar = A>>(&self);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
   |
   = note: cannot satisfy `<PF as TraitC>::Value == _`

Version it worked on

It most recently worked on: nightly-2025-03-12 1.87.0-nightly (6650252 2025-03-11)

Version with regression

rustc +nightly-2025-03-13 --version --verbose:

rustc 1.87.0-nightly (249cb8431 2025-03-12)
binary: rustc
commit-hash: 249cb84316401daf040832cdbb8a45e0f5ab6af8
commit-date: 2025-03-12
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Metadata

Metadata

Labels

C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions