Skip to content

The parser should use some kind of hygiene or lang item for FullRange #20516

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

Closed
nrc opened this issue Jan 4, 2015 · 6 comments
Closed

The parser should use some kind of hygiene or lang item for FullRange #20516

nrc opened this issue Jan 4, 2015 · 6 comments
Labels
A-syntaxext Area: Syntax extensions

Comments

@nrc
Copy link
Member

nrc commented Jan 4, 2015

The parser currently assumes there is a struct called FullRange in scope in order to desugar full slices (&expr[] -> &expr[FullRange]). This is a problem if there is no prelude (where FullRange is defined).

We already have a lang item for FullRange, but unfortunately lang items can only be used from the compiler proper, not from libsyntax. The ideal solution is to fix that. Shorter term we might want to allow a full path to be specified via a macro or something, so we can be a bit more hygenic here.

@emberian
Copy link
Member

emberian commented Jan 5, 2015

I suspect the easiest way to do this would be to add another "special ident", and expand to that.

@nrc
Copy link
Member Author

nrc commented Jan 5, 2015

@cmr I already do that, but it is not as flexible as a lang item

@kmcallister kmcallister added the A-syntaxext Area: Syntax extensions label Jan 14, 2015
@nikomatsakis
Copy link
Contributor

is this a dup of #21263?

@emberian
Copy link
Member

this is one strategy for implementing it.

@kmcallister
Copy link
Contributor

Maybe the libsyntax counterpart to lang items would be "lang macros".

#[lang="range_full"]
// Implicitly exported, but not in the usual way
macro_rules! name_doesnt_matter {
    () => ( $crate::ops::RangeFull )
}

This opens the intriguing possibility of moving more sugar, such as for loops, into the standard library. That could have negative effects on error reporting though; it certainly would until #20923 is fixed.

Any sugar defined through lang macros could be redefined by #![no_std] crates, in a manner similar to GHC's -XRebindableSyntax. We should make sure that they can't be re-defined / shadowed without the lang_items gate.

Whether or not we find lang macros to be widely useful, it seems like a fine solution to the problem at hand.

@alexcrichton
Copy link
Member

FullRange no longer exists and I believe this is no longer an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

5 participants