Skip to content

impl trait: code that doesn't constrain a RPIT infers ()?  #96460

@Dirbaio

Description

@Dirbaio
Contributor
use core::marker::PhantomData;

fn weird() -> PhantomData<impl Sized> {
    PhantomData
}

The above code [playground] fails on stable with the following error, but compiles on nightlies after #94081 . It seems to me it shouldn't, the type is not constrained at all.

error[[E0720]](https://doc.rust-lang.org/nightly/error-index.html#E0720): cannot resolve opaque type
 [--> src/lib.rs:3:27
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
3 | fn weird() -> PhantomData<impl Sized> {
  |                           ^^^^^^^^^^ recursive opaque type
4 |     PhantomData
  |     ----------- returning here with type `PhantomData<impl Sized>`

It seems to be inferring the opaque type to be (). For example, if you change it to impl Future:

error[E0277]: `()` is not a future
 --> src/lib.rs:4:27
  |
4 | fn weird() -> PhantomData<impl Future> {
  |                           ^^^^^^^^^^^ `()` is not a future

Activity

compiler-errors

compiler-errors commented on Apr 27, 2022

@compiler-errors
Member

I think this is a side-effect of fallback rules

oli-obk

oli-obk commented on Apr 27, 2022

@oli-obk
Contributor

😱 oh no. I tried to avoid doing more implicit fallback. I think i can undo this accidental stabilization in a beta backportable way

self-assigned this
on Apr 27, 2022
added
P-highHigh priority
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
on Apr 27, 2022
added a commit that references this issue on Apr 29, 2022
109008a
added a commit that references this issue on May 17, 2022
2ef5103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-inferenceArea: Type inferenceP-highHigh priority

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @oli-obk@Dirbaio@compiler-errors

    Issue actions

      impl trait: code that doesn't constrain a RPIT infers `()`? · Issue #96460 · rust-lang/rust