Skip to content

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

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
dingxiangfei2009 opened this issue Apr 2, 2025 · 3 comments
Assignees
Labels
C-bug Category: This is a bug. F-arbitrary_self_types `#![feature(arbitrary_self_types)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dingxiangfei2009
Copy link
Contributor

dingxiangfei2009 commented Apr 2, 2025

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.

@dingxiangfei2009 dingxiangfei2009 added the C-bug Category: This is a bug. label Apr 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 2, 2025
@dingxiangfei2009
Copy link
Contributor Author

@rustbot claim

... since I am looking into it as well.

@dingxiangfei2009
Copy link
Contributor Author

This ticket has connection to #135881

@rustbot labels +F-arbitrary_self_types

@rustbot rustbot added the F-arbitrary_self_types `#![feature(arbitrary_self_types)]` label Apr 2, 2025
@compiler-errors
Copy link
Member

This was fixed by #138941.

@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 10, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. F-arbitrary_self_types `#![feature(arbitrary_self_types)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants