Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ec6086b

Browse files
authored
Merge pull request rust-lang#2984 from mehcode/feature/edition-option
Accept 2015 and 2018 instead of Edition2015 and Edition2018 for edition option
2 parents d881398 + eec7436 commit ec6086b

16 files changed

+47
-32
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ matrix:
3535
- env: INTEGRATION=stdsimd
3636
- env: INTEGRATION=tempdir
3737
allow_failures:
38-
# Needs `edition = "Edition2018"` in rustfmt.toml
38+
# Needs `edition = "2018"` in rustfmt.toml
3939
- env: INTEGRATION=chalk
4040
# Fails tests, don't know why
4141
- env: INTEGRATION=crater

Configurations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,16 +2176,16 @@ ignore = [
21762176

21772177
Specifies which edition is used by the parser.
21782178

2179-
- **Default value**: `Edition2015`
2180-
- **Possible values**: `Edition2015`, `Edition2018`
2179+
- **Default value**: `2015`
2180+
- **Possible values**: `2015`, `2018`
21812181
- **Stable**: No
21822182

21832183
### Example
21842184

21852185
If you want to format code that requires edition 2018, add the following to your config file:
21862186

21872187
```toml
2188-
edition = "Edition2018"
2188+
edition = "2018"
21892189
```
21902190

21912191
## `emit_mode`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ cargo +nightly fmt
3939
To format code that requires edition 2018, create a `rustfmt.toml` [configuration](#configuring-rustfmt) file containing:
4040

4141
```toml
42-
edition = "Edition2018"
42+
edition = "2018"
4343
```
4444

4545
## Limitations

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
error_on_line_overflow = true
22
error_on_unformatted = true
3-
edition = "Edition2018"
3+
edition = "2018"

src/config/options.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ use std::path::{Path, PathBuf};
2020
/// Macro for deriving implementations of Serialize/Deserialize for enums
2121
#[macro_export]
2222
macro_rules! impl_enum_serialize_and_deserialize {
23-
( $e:ident, $( $x:ident ),* ) => {
23+
(@stringify $variant:ident) => (
24+
stringify!($variant)
25+
);
26+
27+
(@stringify $_variant:ident: $value:expr) => (
28+
stringify!($value)
29+
);
30+
31+
( $e:ident, $( $variant:ident $(: $value:expr)* ),* ) => {
2432
impl ::serde::ser::Serialize for $e {
2533
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2634
where S: ::serde::ser::Serializer
@@ -31,7 +39,9 @@ macro_rules! impl_enum_serialize_and_deserialize {
3139
#[allow(unreachable_patterns)]
3240
match *self {
3341
$(
34-
$e::$x => serializer.serialize_str(stringify!($x)),
42+
$e::$variant => serializer.serialize_str(
43+
impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
44+
),
3545
)*
3646
_ => {
3747
Err(S::Error::custom(format!("Cannot serialize {:?}", self)))
@@ -59,11 +69,13 @@ macro_rules! impl_enum_serialize_and_deserialize {
5969
}
6070
let s = d.deserialize_string(StringOnly::<D>(PhantomData))?;
6171
$(
62-
if stringify!($x).eq_ignore_ascii_case(&s) {
63-
return Ok($e::$x);
72+
if impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
73+
.eq_ignore_ascii_case(&s) {
74+
return Ok($e::$variant);
6475
}
6576
)*
66-
static ALLOWED: &'static[&str] = &[$(stringify!($x),)*];
77+
static ALLOWED: &'static[&str] = &[
78+
$(impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*),)*];
6779
Err(D::Error::unknown_variant(&s, ALLOWED))
6880
}
6981
}
@@ -73,8 +85,9 @@ macro_rules! impl_enum_serialize_and_deserialize {
7385

7486
fn from_str(s: &str) -> Result<Self, Self::Err> {
7587
$(
76-
if stringify!($x).eq_ignore_ascii_case(s) {
77-
return Ok($e::$x);
88+
if impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
89+
.eq_ignore_ascii_case(s) {
90+
return Ok($e::$variant);
7891
}
7992
)*
8093
Err("Bad variant")
@@ -85,23 +98,25 @@ macro_rules! impl_enum_serialize_and_deserialize {
8598
fn doc_hint() -> String {
8699
let mut variants = Vec::new();
87100
$(
88-
variants.push(stringify!($x));
101+
variants.push(
102+
impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
103+
);
89104
)*
90105
format!("[{}]", variants.join("|"))
91106
}
92107
}
93108
};
94109
}
95110

96-
macro_rules! configuration_option_enum{
97-
($e:ident: $( $x:ident ),+ $(,)*) => {
111+
macro_rules! configuration_option_enum {
112+
($e:ident: $( $name:ident $(: $value:expr)* ),+ $(,)*) => (
98113
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
99114
pub enum $e {
100-
$( $x ),+
115+
$( $name ),+
101116
}
102117

103-
impl_enum_serialize_and_deserialize!($e, $( $x ),+);
104-
}
118+
impl_enum_serialize_and_deserialize!($e, $( $name $(: $value)* ),+);
119+
);
105120
}
106121

107122
configuration_option_enum! { NewlineStyle:
@@ -412,8 +427,8 @@ pub trait CliOptions {
412427

413428
/// The edition of the compiler (RFC 2052)
414429
configuration_option_enum!{ Edition:
415-
Edition2015,
416-
Edition2018,
430+
Edition2015: 2015,
431+
Edition2018: 2018,
417432
}
418433

419434
impl Edition {

tests/source/async_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22

33
fn main() {
44
let x = async {

tests/source/async_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22

33
async fn bar() -> Result<(), ()> {
44
Ok(())

tests/source/catch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22
#![feature(try_blocks)]
33

44
fn main() {

tests/source/issue-2927-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2015
1+
// rustfmt-edition: 2015
22
#![feature(rust_2018_preview, uniform_paths)]
33
use futures::prelude::*;
44
use http_03::cli::Cli;

tests/source/issue-2927.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22
#![feature(rust_2018_preview, uniform_paths)]
33
use futures::prelude::*;
44
use http_03::cli::Cli;

tests/target/async_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22

33
fn main() {
44
let x = async { Ok(()) };

tests/target/async_closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22

33
fn main() {
44
let async_closure = async {

tests/target/async_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22

33
async fn bar() -> Result<(), ()> {
44
Ok(())

tests/target/catch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22
#![feature(try_blocks)]
33

44
fn main() {

tests/target/issue-2927-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2015
1+
// rustfmt-edition: 2015
22
#![feature(rust_2018_preview, uniform_paths)]
33
use futures::prelude::*;
44
use http_03::cli::Cli;

tests/target/issue-2927.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-edition: Edition2018
1+
// rustfmt-edition: 2018
22
#![feature(rust_2018_preview, uniform_paths)]
33
use ::log::{error, info, log};
44
use futures::prelude::*;

0 commit comments

Comments
 (0)