Skip to content

false positive "unconstrained opaque type" error on impl trait in trait associated type #140222

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

Open
glorv opened this issue Apr 23, 2025 · 2 comments
Labels
C-bug Category: This is a bug. F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` requires-nightly This issue requires a nightly compiler in some way. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@glorv
Copy link
Contributor

glorv commented Apr 23, 2025

I tried this code:

#![feature(impl_trait_in_assoc_type)]

use std::future::Future;

trait T {
    type T1;
    type Fut1: Future<Output=Self::T1> + Send + 'static;

    fn foo(&self) -> Self::Fut1;

    type T2;
    type Fut2: Future<Output=Self::T2> + Send + 'static;
    fn foo2(&self) -> Self::Fut2;
}

struct S;

impl T for S {
    type T1 = i32;
    type Fut1 = impl  Future<Output=Self::T1> + Send + 'static;
    fn foo(&self) -> Self::Fut1 {
        async {
            1
        }
    }

    type T2 = Self::T1;
    type Fut2 = Self::Fut1;
    fn foo2(&self) -> Self::Fut2 {
        self.foo()
    }
}

fn main() {
    let _a = S;
}

playground

This code can compile successfully with toolchain nightly-2023-2023-12-28 but fails with recent nightly toolchain.

I expected to see this happen: explanation
The code should compile with no errror.

Instead, this happened: explanation

Compiling playground v0.0.1 (/playground)
error: item does not constrain `<S as T>::Fut1::{opaque#0}`
  --> src/main.rs:29:8
   |
29 |     fn foo2(&self) -> Self::Fut2 {
   |        ^^^^
   |
   = note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]`
note: this opaque type is supposed to be constrained
  --> src/main.rs:20:17
   |
20 |     type Fut1 = impl  Future<Output=Self::T1> + Send + 'static;
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (934880f58 2025-04-09)
binary: rustc
commit-hash: 934880f586f6ac1f952c7090e2a943fcd7775e7b
commit-date: 2025-04-09
host: aarch64-apple-darwin
release: 1.88.0-nightly
LLVM version: 20.1.2
Backtrace

<backtrace>

@glorv glorv added the C-bug Category: This is a bug. label Apr 23, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 23, 2025
@glorv glorv changed the title TAIT: false positive "unconstrained opaque type" error false positive "unconstrained opaque type" error on impl trait in trait associated type Apr 23, 2025
@fmease fmease added F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` T-types Relevant to the types team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 24, 2025
@fmease
Copy link
Member

fmease commented Apr 24, 2025

(For now) ATPIT should still work without #[define_opaque], right?

cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Apr 28, 2025

Yea, and you should be able to use #[define_opaque()] to "remove" the implicitly decided define_opaque list, but that isn't implemented yet

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. F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` requires-nightly This issue requires a nightly compiler in some way. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants