Skip to content

ParamEnv normalization in dyn-compatibility check rejects projections too eagerly #139280

Description

@dingxiangfei2009

This looks like a stable-to-nightly regression.

I tried this code:

#![crate_type = "lib"]
use std::marker::PhantomData;

trait Receiver {
    type Target: ?Sized;
}

trait Deref: Receiver<Target = <Self as Deref>::Target> {
    type Target: ?Sized;
}

impl<T: Deref> Receiver for T {
    type Target = <T as Deref>::Target;
}

trait ArrayLike: Deref<Target = [Self::Element]> {
    type Element;
}

trait CuPool<T: ArrayLike> {
    fn copy_from<O>(&self, from: &mut O) -> CuHandle<T>
    where
        O: ArrayLike<Element = T::Element>;
}

#[derive(Clone, Debug)]
struct CuHandle<T: ArrayLike>(PhantomData<T>);

I expected to see this happen: it should compile, which is the case with stable rustc 1.85.0 (4d91de4e4 2025-02-17)

Instead, this happened:

error[E0284]: type annotations needed
  --> test2.rs:22:5
   |
22 | /     fn copy_from<O>(&self, from: &mut O) -> CuHandle<T>
23 | |     where
24 | |         O: ArrayLike<Element = T::Element>;
   | |___________________________________________^ cannot infer type
   |
   = note: cannot satisfy `<O as Deref>::Target == _`

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (e2014e876 2025-04-01)
binary: rustc
commit-hash: e2014e876e3efaa69bf51c19579adb16c3df5f81
commit-date: 2025-04-01
host: <sorry>
release: 1.88.0-nightly
LLVM version: 20.1.1
Backtrace

<backtrace>

My investigation

rustc_trait_selection::traits::do_normalize_predicates generate an ErrorGuaranteed even though it should bubble the unnormalized projection up. I am experimenting a fix, which is to perform the "bubbling". Meanwhile, I would like to hear your verdicts on this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-arbitrary_self_types`#![feature(arbitrary_self_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions