Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
albertog78 opened this issue Mar 25, 2025 · 1 comment · May be fixed by #138941
Open

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

albertog78 opened this issue Mar 25, 2025 · 1 comment · May be fixed by #138941
Assignees
Labels
C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-untriaged Untriaged performance or correctness regression.

Comments

@albertog78
Copy link

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
@albertog78 albertog78 added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Mar 25, 2025
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 25, 2025
@compiler-errors
Copy link
Member

Likely regressed in #138174. I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-untriaged Untriaged performance or correctness regression.
Projects
None yet
3 participants