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