Closed
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
Metadata
Assignees
Labels
No labels
Activity
dtolnay commentedon Jul 22, 2018
Workaround: macros to the rescue.
oli-obk commentedon Jul 22, 2018
hm... this needs some lookahead, but should be doable (
existential.foo()
needs to still be legal ifexistential
is a value in scope). That said. I'm not sure how important it is to support this in light ofexistential type
being just the prototype syntax that everyone could agree on that we do NOT want as the final syntax.dtolnay commentedon 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.
Rollup merge of rust-lang#52645 - oli-obk:existential_in_fn_body, r=d…