-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #61347 - Centril:stabilize-underscore_const_names, r=pe…
…trochenkov Stabilize underscore_const_names in 1.37.0 You are now permitted to write: ```rust const _: $type_expression = $term_expression; ``` That is, we change the [grammar of items](https://github.com/rust-lang-nursery/wg-grammar/blob/9d1984d7ae8d6576f943566539a31a5800644c57/grammar/item.lyg#L3-L42), as written in [the *`.lyg`* notation](https://github.com/rust-lang/gll/tree/263bf161dad903e67aa65fc591ced3cab18afa2a#grammar), from: ```java Item = attrs:OuterAttr* vis:Vis? kind:ItemKind; ItemKind = | ... | Const:{ "const" name:IDENT ":" ty:Type "=" value:Expr ";" } | ... ; ``` into: ```java Item = attrs:OuterAttr* vis:Vis? kind:ItemKind; ItemKind = | ... | Const:{ "const" name:IdentOrUnderscore ":" ty:Type "=" value:Expr ";" } | ... ; IdentOrUnderscore = | Named:IDENT | NoName:"_" ; ``` r? @petrochenkov
- Loading branch information
Showing
13 changed files
with
134 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/test/ui/feature-gates/feature-gate-underscore_const_names.rs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/test/ui/feature-gates/feature-gate-underscore_const_names.stderr
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
src/test/ui/feature-gates/underscore_const_names_feature_gate.rs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/test/ui/feature-gates/underscore_const_names_feature_gate.stderr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Test that various non-const items and associated consts do not permit `_` as a name. | ||
|
||
// Associated `const`s: | ||
|
||
pub trait A { | ||
const _: () = (); //~ ERROR expected identifier, found reserved identifier `_` | ||
} | ||
impl A for () { | ||
const _: () = (); //~ ERROR expected identifier, found reserved identifier `_` | ||
} | ||
impl dyn A { | ||
const _: () = (); //~ ERROR expected identifier, found reserved identifier `_` | ||
} | ||
|
||
// Other kinds of items: | ||
|
||
static _: () = (); //~ ERROR expected identifier, found reserved identifier `_` | ||
struct _(); //~ ERROR expected identifier, found reserved identifier `_` | ||
enum _ {} //~ ERROR expected identifier, found reserved identifier `_` | ||
fn _() {} //~ ERROR expected identifier, found reserved identifier `_` | ||
mod _ {} //~ ERROR expected identifier, found reserved identifier `_` | ||
type _ = (); //~ ERROR expected identifier, found reserved identifier `_` | ||
use _; //~ ERROR expected identifier, found reserved identifier `_` | ||
use _ as g; //~ ERROR expected identifier, found reserved identifier `_` | ||
trait _ {} //~ ERROR expected identifier, found reserved identifier `_` | ||
trait _ = Copy; //~ ERROR expected identifier, found reserved identifier `_` | ||
macro_rules! _ { () => {} } //~ ERROR expected identifier, found reserved identifier `_` | ||
union _ { f: u8 } //~ ERROR expected one of `!` or `::`, found `_` | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:6:11 | ||
| | ||
LL | const _: () = (); | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:9:11 | ||
| | ||
LL | const _: () = (); | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:12:11 | ||
| | ||
LL | const _: () = (); | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:17:8 | ||
| | ||
LL | static _: () = (); | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:18:8 | ||
| | ||
LL | struct _(); | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:19:6 | ||
| | ||
LL | enum _ {} | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:20:4 | ||
| | ||
LL | fn _() {} | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:21:5 | ||
| | ||
LL | mod _ {} | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:22:6 | ||
| | ||
LL | type _ = (); | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:23:5 | ||
| | ||
LL | use _; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:24:5 | ||
| | ||
LL | use _ as g; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:25:7 | ||
| | ||
LL | trait _ {} | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:26:7 | ||
| | ||
LL | trait _ = Copy; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/underscore_item_not_const.rs:27:14 | ||
| | ||
LL | macro_rules! _ { () => {} } | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected one of `!` or `::`, found `_` | ||
--> $DIR/underscore_item_not_const.rs:28:7 | ||
| | ||
LL | union _ { f: u8 } | ||
| ^ expected one of `!` or `::` here | ||
|
||
error: aborting due to 15 previous errors | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.