Skip to content

'static is accepted as a loop label name #33059

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
petrochenkov opened this issue Apr 17, 2016 · 5 comments
Closed

'static is accepted as a loop label name #33059

petrochenkov opened this issue Apr 17, 2016 · 5 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@petrochenkov
Copy link
Contributor

Compiles on stable/beta/nightly:

fn main() {
    'static: loop {
        break 'static
    }
}

Not sure if it's bad or not, but worth opening an issue.
It may conflict with a possible future block lifetime notation or something.

@brson
Copy link
Contributor

brson commented Apr 18, 2016

Seems bogus.

@steveklabnik
Copy link
Member

They're described as "lifetime names", so like, in a twisted way, it makes sense, but it also makes no sense. Agree that it should probably be removed.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Apr 20, 2016

Should rust keywords not be used as label name (and not just static)?

EDIT: thanks for the remark @alrz, it's updated.

@alrz
Copy link

alrz commented Apr 20, 2016

That's a double-negative right there.

@ghost
Copy link

ghost commented Apr 20, 2016

It seems like the difference in syntax would prevent a conflict, though I could be wrong (I'm new to Rust). It might be worthwhile to at least have the compiler throw a warning for ergonomic reasons.

bors added a commit that referenced this issue May 26, 2016
Add AST validation pass and move some checks to it

The purpose of this pass is to catch constructions that fit into AST data structures, but not permitted by the language. As an example, `impl`s don't have visibilities, but for convenience and uniformity with other items they are represented with a structure `Item` which has `Visibility` field.

This pass is intended to run after expansion of macros and syntax extensions (and before lowering to HIR), so it can catch erroneous constructions that were generated by them. This pass allows to remove ad hoc semantic checks from the parser, which can be overruled by syntax extensions and occasionally macros.

The checks can be put here if they are simple, local, don't require results of any complex analysis like name resolution or type checking and maybe don't logically fall into other passes. I expect most of errors generated by this pass to be non-fatal and allowing the compilation to proceed.

I intend to move some more checks to this pass later and maybe extend it with new checks, like, for example, identifier validity. Given that syntax extensions are going to be stabilized in the measurable future, it's important that they would not be able to subvert usual language rules.

In this patch I've added two new checks - a check for labels named `'static` and a check for lifetimes and labels named `'_`. The first one gives a hard error, the second one - a future compatibility warning.
Fixes #33059 ([breaking-change])
cc rust-lang/rfcs#1177

r? @nrc
bors added a commit that referenced this issue Jun 1, 2016
Add AST validation pass and move some checks to it

The purpose of this pass is to catch constructions that fit into AST data structures, but not permitted by the language. As an example, `impl`s don't have visibilities, but for convenience and uniformity with other items they are represented with a structure `Item` which has `Visibility` field.

This pass is intended to run after expansion of macros and syntax extensions (and before lowering to HIR), so it can catch erroneous constructions that were generated by them. This pass allows to remove ad hoc semantic checks from the parser, which can be overruled by syntax extensions and occasionally macros.

The checks can be put here if they are simple, local, don't require results of any complex analysis like name resolution or type checking and maybe don't logically fall into other passes. I expect most of errors generated by this pass to be non-fatal and allowing the compilation to proceed.

I intend to move some more checks to this pass later and maybe extend it with new checks, like, for example, identifier validity. Given that syntax extensions are going to be stabilized in the measurable future, it's important that they would not be able to subvert usual language rules.

In this patch I've added two new checks - a check for labels named `'static` and a check for lifetimes and labels named `'_`. The first one gives a hard error, the second one - a future compatibility warning.
Fixes #33059 ([breaking-change])
cc rust-lang/rfcs#1177

r? @nrc
@steveklabnik steveklabnik added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants