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

Fails to parse existential type in statement position #52631

Closed
dtolnay opened this issue Jul 22, 2018 · 3 comments · Fixed by #52645
Closed

Fails to parse existential type in statement position #52631

dtolnay opened this issue Jul 22, 2018 · 3 comments · Fixed by #52645

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 22, 2018

As of rustc 1.29.0-nightly (874dec2 2018-07-21) the following works:

#![feature(existential_type)]

use std::fmt::Debug;

existential type Existential: Debug;

fn main() {
    fn f() -> Existential {}
    println!("{:?}", f());
}

But the following does not parse. I would expect this to be equivalent to the above except for Existential in scope just within main, but if this is disallowed by the RFC then it should produce a better error message.

#![feature(existential_type)]

use std::fmt::Debug;

fn main() {
    existential type Existential: Debug;

    fn f() -> Existential {}
    println!("{:?}", f());
}
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `type`
 --> src/main.rs:6:17
  |
6 |     existential type Existential: Debug;
  |                 ^^^^ expected one of 8 possible tokens here

error[E0425]: cannot find value `existential` in this scope
 --> src/main.rs:6:5
  |
6 |     existential type Existential: Debug;
  |     ^^^^^^^^^^^ not found in this scope

Mentioning the existential types tracking issue #34511
Mentioning @oli-obk and @cramertj

@dtolnay
Copy link
Member Author

dtolnay commented Jul 22, 2018

Workaround: macros to the rescue.

#![feature(existential_type)]

use std::fmt::Debug;

macro_rules! this_is_an_item {
    ($i:item) => { $i };
}

fn main() {
    this_is_an_item! {
        existential type Existential: Debug;
    }

    fn f() -> Existential {}
    println!("{:?}", f());
}

@oli-obk
Copy link
Contributor

oli-obk commented Jul 22, 2018

hm... this needs some lookahead, but should be doable (existential.foo() needs to still be legal if existential is a value in scope). That said. I'm not sure how important it is to support this in light of existential type being just the prototype syntax that everyone could agree on that we do NOT want as the final syntax.

@dtolnay
Copy link
Member Author

dtolnay commented Jul 22, 2018

I would like this to be fixed even if we know the syntax will change. Some use cases require existential type in statement position -- #52632 (comment) is one example -- and we want people with those use cases to be able to try out existential type and provide feedback that informs the ultimate implementation.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 24, 2018
…tolnay

Allow declaring existential types inside blocks

fixes rust-lang#52631

r? @dtolnay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants