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

Type mismatch when using constant with type_alias_impl_trait #77989

Closed
joshlf opened this issue Oct 15, 2020 · 5 comments
Closed

Type mismatch when using constant with type_alias_impl_trait #77989

joshlf opened this issue Oct 15, 2020 · 5 comments
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-needs-decision Issue: In need of a decision. requires-nightly This issue requires a nightly compiler in some way.

Comments

@joshlf
Copy link
Contributor

joshlf commented Oct 15, 2020

I tried this code (playground):

#![feature(type_alias_impl_trait)]

pub type IntoUnit = impl Into<()>;

pub const _: IntoUnit = ();

pub fn infer() -> IntoUnit {
    ()
}

I expected to see this happen: Successful compilation

Instead, this happened: While infer compiled successfully, the anonymous constant did not:

error[E0308]: mismatched types
 --> src/lib.rs:5:25
  |
3 | pub type IntoUnit = impl Into<()>;
  |                     ------------- the expected opaque type
4 | 
5 | pub const _: IntoUnit = ();
  |                         ^^ expected opaque type, found `()`
  |
  = note: expected opaque type `impl Into<()>`
               found unit type `()`

Meta

Rust playground version: 1.49.0-nightly (2020-10-14 e160e5c)

cc @jswrenn

@joshlf joshlf added the C-bug Category: This is a bug. label Oct 15, 2020
@jonas-schievink
Copy link
Contributor

cc #77898, a similar issue

@jonas-schievink jonas-schievink added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Oct 15, 2020
@jackh726
Copy link
Member

This actually works now, even with min_type_alias_impl_trait (though it shouldn't)

@nikomatsakis
Copy link
Contributor

We should decide whether const X: Foo is a "defining use" for TAIT. I think my rule is roughly "if impl Trait can be used there to mean "existential type", it is a defining use". Presently this does not include const, so this should not be accepted by min_type_alias_impl_trait.

However, I would eventually expect this code to compile, yes.

@oli-obk oli-obk added the I-needs-decision Issue: In need of a decision. label May 3, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 3, 2022

This works now, and I expect this to keep working, as there's no implementation reason to forbid it and no language reason that I know of. Theoretically all functions could just be constants that return an impl Fn() type 😆

@nikomatsakis
Copy link
Contributor

Huzzah! @oli-obk is awesome. Closing.

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-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-needs-decision Issue: In need of a decision. requires-nightly This issue requires a nightly compiler in some way.
Development

No branches or pull requests

5 participants