Skip to content

Fails to parse existential type in statement position #52631

Closed
@dtolnay

Description

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

Activity

dtolnay

dtolnay commented on Jul 22, 2018

@dtolnay
MemberAuthor

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

oli-obk commented on Jul 22, 2018

@oli-obk
Contributor

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

dtolnay commented on Jul 22, 2018

@dtolnay
MemberAuthor

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.

added a commit that references this issue on Jul 24, 2018

Rollup merge of rust-lang#52645 - oli-obk:existential_in_fn_body, r=d…

f930017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Fails to parse existential type in statement position · Issue #52631 · rust-lang/rust