Skip to content
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

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

Closed
Dirbaio opened this issue Apr 27, 2022 · 2 comments · Fixed by #96516
Closed

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

Dirbaio opened this issue Apr 27, 2022 · 2 comments · Fixed by #96516
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-inference Area: Type inference P-high High priority

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Apr 27, 2022

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
@compiler-errors
Copy link
Member

I think this is a side-effect of fallback rules

@oli-obk
Copy link
Contributor

oli-obk commented Apr 27, 2022

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

@oli-obk oli-obk self-assigned this Apr 27, 2022
@oli-obk oli-obk added P-high High priority A-inference Area: Type inference A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Apr 27, 2022
@bors bors closed this as completed in 109008a Apr 29, 2022
ehuss pushed a commit to ehuss/rust that referenced this issue May 4, 2022
…ntal_permitted, r=jackh726

Revert diagnostic duplication and accidental stabilization

fixes rust-lang#96460

this is an accidental stabilization that we should put into the beta. I believe it is low-risk, because it was literally what we had before rust-lang#94081

The effect on tests is massive, but mostly deduplication of diagnostics and some minor span changes.
MabezDev pushed a commit to esp-rs/rust that referenced this issue May 17, 2022
…ntal_permitted, r=jackh726

Revert diagnostic duplication and accidental stabilization

fixes rust-lang#96460

this is an accidental stabilization that we should put into the beta. I believe it is low-risk, because it was literally what we had before rust-lang#94081

The effect on tests is massive, but mostly deduplication of diagnostics and some minor span changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-inference Area: Type inference P-high High priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants