Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
albertog78 opened this issue Mar 25, 2025 · 2 comments · Fixed by #138941
Closed
Assignees
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

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.

@compiler-errors compiler-errors self-assigned this Mar 25, 2025
@bors bors closed this as completed in 7812409 Apr 2, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 2, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 2, 2025
Rollup merge of rust-lang#138941 - compiler-errors:receiver-is-dispatchable-bounds, r=BoxyUwU

Do not mix normalized and unnormalized caller bounds when constructing param-env for `receiver_is_dispatchable`

See comments in code and in test I added.

r? `@BoxyUwU` since you reviewed the last PR, or reassign

Fixes rust-lang#138937
@albertog78
Copy link
Author

Thanks!

@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 2, 2025
DDT92 added a commit to telosnetwork/plonky2_goldibear that referenced this issue Apr 3, 2025
Because issue rust-lang/rust#138937 was solved and merged.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants