false positive "unconstrained opaque type" error on impl trait in trait associated type
Open
Nobody has claimed this yet.
C-bug
F-impl_trait_in_assoc_type
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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;
}
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the reproducer in src/main.rs with a recent nightly and compare it with nightly-2023-12-28. Trace the impl_trait_in_assoc_type handling around the reported unconstrained opaque type diagnostic; done when the example compiles without the false positive error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100