Accept 2015 and 2018 instead of Edition2015 and Edition2018 for edition option
This commit is contained in:
parent
d88139893f
commit
eec74360dc
@ -35,7 +35,7 @@ matrix:
|
||||
- env: INTEGRATION=stdsimd
|
||||
- env: INTEGRATION=tempdir
|
||||
allow_failures:
|
||||
# Needs `edition = "Edition2018"` in rustfmt.toml
|
||||
# Needs `edition = "2018"` in rustfmt.toml
|
||||
- env: INTEGRATION=chalk
|
||||
# Fails tests, don't know why
|
||||
- env: INTEGRATION=crater
|
||||
|
@ -2176,8 +2176,8 @@ ignore = [
|
||||
|
||||
Specifies which edition is used by the parser.
|
||||
|
||||
- **Default value**: `Edition2015`
|
||||
- **Possible values**: `Edition2015`, `Edition2018`
|
||||
- **Default value**: `2015`
|
||||
- **Possible values**: `2015`, `2018`
|
||||
- **Stable**: No
|
||||
|
||||
### Example
|
||||
@ -2185,7 +2185,7 @@ Specifies which edition is used by the parser.
|
||||
If you want to format code that requires edition 2018, add the following to your config file:
|
||||
|
||||
```toml
|
||||
edition = "Edition2018"
|
||||
edition = "2018"
|
||||
```
|
||||
|
||||
## `emit_mode`
|
||||
|
@ -39,7 +39,7 @@ cargo +nightly fmt
|
||||
To format code that requires edition 2018, create a `rustfmt.toml` [configuration](#configuring-rustfmt) file containing:
|
||||
|
||||
```toml
|
||||
edition = "Edition2018"
|
||||
edition = "2018"
|
||||
```
|
||||
|
||||
## Limitations
|
||||
|
@ -1,3 +1,3 @@
|
||||
error_on_line_overflow = true
|
||||
error_on_unformatted = true
|
||||
edition = "Edition2018"
|
||||
edition = "2018"
|
||||
|
@ -20,7 +20,15 @@
|
||||
/// Macro for deriving implementations of Serialize/Deserialize for enums
|
||||
#[macro_export]
|
||||
macro_rules! impl_enum_serialize_and_deserialize {
|
||||
( $e:ident, $( $x:ident ),* ) => {
|
||||
(@stringify $variant:ident) => (
|
||||
stringify!($variant)
|
||||
);
|
||||
|
||||
(@stringify $_variant:ident: $value:expr) => (
|
||||
stringify!($value)
|
||||
);
|
||||
|
||||
( $e:ident, $( $variant:ident $(: $value:expr)* ),* ) => {
|
||||
impl ::serde::ser::Serialize for $e {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ::serde::ser::Serializer
|
||||
@ -31,7 +39,9 @@ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
#[allow(unreachable_patterns)]
|
||||
match *self {
|
||||
$(
|
||||
$e::$x => serializer.serialize_str(stringify!($x)),
|
||||
$e::$variant => serializer.serialize_str(
|
||||
impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
|
||||
),
|
||||
)*
|
||||
_ => {
|
||||
Err(S::Error::custom(format!("Cannot serialize {:?}", self)))
|
||||
@ -59,11 +69,13 @@ fn visit_str<E>(self, value: &str) -> Result<String, E> {
|
||||
}
|
||||
let s = d.deserialize_string(StringOnly::<D>(PhantomData))?;
|
||||
$(
|
||||
if stringify!($x).eq_ignore_ascii_case(&s) {
|
||||
return Ok($e::$x);
|
||||
if impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
|
||||
.eq_ignore_ascii_case(&s) {
|
||||
return Ok($e::$variant);
|
||||
}
|
||||
)*
|
||||
static ALLOWED: &'static[&str] = &[$(stringify!($x),)*];
|
||||
static ALLOWED: &'static[&str] = &[
|
||||
$(impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*),)*];
|
||||
Err(D::Error::unknown_variant(&s, ALLOWED))
|
||||
}
|
||||
}
|
||||
@ -73,8 +85,9 @@ impl ::std::str::FromStr for $e {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
$(
|
||||
if stringify!($x).eq_ignore_ascii_case(s) {
|
||||
return Ok($e::$x);
|
||||
if impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
|
||||
.eq_ignore_ascii_case(s) {
|
||||
return Ok($e::$variant);
|
||||
}
|
||||
)*
|
||||
Err("Bad variant")
|
||||
@ -85,7 +98,9 @@ impl ConfigType for $e {
|
||||
fn doc_hint() -> String {
|
||||
let mut variants = Vec::new();
|
||||
$(
|
||||
variants.push(stringify!($x));
|
||||
variants.push(
|
||||
impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
|
||||
);
|
||||
)*
|
||||
format!("[{}]", variants.join("|"))
|
||||
}
|
||||
@ -93,15 +108,15 @@ fn doc_hint() -> String {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! configuration_option_enum{
|
||||
($e:ident: $( $x:ident ),+ $(,)*) => {
|
||||
macro_rules! configuration_option_enum {
|
||||
($e:ident: $( $name:ident $(: $value:expr)* ),+ $(,)*) => (
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum $e {
|
||||
$( $x ),+
|
||||
$( $name ),+
|
||||
}
|
||||
|
||||
impl_enum_serialize_and_deserialize!($e, $( $x ),+);
|
||||
}
|
||||
impl_enum_serialize_and_deserialize!($e, $( $name $(: $value)* ),+);
|
||||
);
|
||||
}
|
||||
|
||||
configuration_option_enum! { NewlineStyle:
|
||||
@ -412,8 +427,8 @@ pub trait CliOptions {
|
||||
|
||||
/// The edition of the compiler (RFC 2052)
|
||||
configuration_option_enum!{ Edition:
|
||||
Edition2015,
|
||||
Edition2018,
|
||||
Edition2015: 2015,
|
||||
Edition2018: 2018,
|
||||
}
|
||||
|
||||
impl Edition {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
|
||||
fn main() {
|
||||
let x = async {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
|
||||
async fn bar() -> Result<(), ()> {
|
||||
Ok(())
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
#![feature(try_blocks)]
|
||||
|
||||
fn main() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2015
|
||||
// rustfmt-edition: 2015
|
||||
#![feature(rust_2018_preview, uniform_paths)]
|
||||
use futures::prelude::*;
|
||||
use http_03::cli::Cli;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
#![feature(rust_2018_preview, uniform_paths)]
|
||||
use futures::prelude::*;
|
||||
use http_03::cli::Cli;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
|
||||
fn main() {
|
||||
let x = async { Ok(()) };
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
|
||||
fn main() {
|
||||
let async_closure = async {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
|
||||
async fn bar() -> Result<(), ()> {
|
||||
Ok(())
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
#![feature(try_blocks)]
|
||||
|
||||
fn main() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2015
|
||||
// rustfmt-edition: 2015
|
||||
#![feature(rust_2018_preview, uniform_paths)]
|
||||
use futures::prelude::*;
|
||||
use http_03::cli::Cli;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
// rustfmt-edition: 2018
|
||||
#![feature(rust_2018_preview, uniform_paths)]
|
||||
use ::log::{error, info, log};
|
||||
use futures::prelude::*;
|
||||
|
Loading…
Reference in New Issue
Block a user