mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Add support for edition 2021.
This commit is contained in:
parent
d8e0d00377
commit
398d2f96c3
@ -497,8 +497,8 @@ Don't reformat anything
|
||||
|
||||
Specifies which edition is used by the parser.
|
||||
|
||||
- **Default value**: `2015`
|
||||
- **Possible values**: `2015`, `2018`
|
||||
- **Default value**: `"2015"`
|
||||
- **Possible values**: `"2015"`, `"2018"`, `"2021"`
|
||||
- **Stable**: Yes
|
||||
|
||||
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
|
||||
|
@ -388,6 +388,10 @@ pub enum Edition {
|
||||
#[doc_hint = "2018"]
|
||||
/// Edition 2018.
|
||||
Edition2018,
|
||||
#[value = "2021"]
|
||||
#[doc_hint = "2021"]
|
||||
/// Edition 2021.
|
||||
Edition2021,
|
||||
}
|
||||
|
||||
impl Default for Edition {
|
||||
@ -396,15 +400,22 @@ impl Default for Edition {
|
||||
}
|
||||
}
|
||||
|
||||
impl Edition {
|
||||
pub(crate) fn to_libsyntax_pos_edition(self) -> rustc_span::edition::Edition {
|
||||
match self {
|
||||
Edition::Edition2015 => rustc_span::edition::Edition::Edition2015,
|
||||
Edition::Edition2018 => rustc_span::edition::Edition::Edition2018,
|
||||
impl From<Edition> for rustc_span::edition::Edition {
|
||||
fn from(edition: Edition) -> Self {
|
||||
match edition {
|
||||
Edition::Edition2015 => Self::Edition2015,
|
||||
Edition::Edition2018 => Self::Edition2018,
|
||||
Edition::Edition2021 => Self::Edition2021,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Edition {
|
||||
fn partial_cmp(&self, other: &Edition) -> Option<std::cmp::Ordering> {
|
||||
rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Controls how rustfmt should handle leading pipes on match arms.
|
||||
#[config_type]
|
||||
pub enum MatchArmLeadingPipe {
|
||||
|
@ -34,7 +34,7 @@ impl<'b, T: Write + 'b> Session<'b, T> {
|
||||
return Err(ErrorKind::VersionMismatch);
|
||||
}
|
||||
|
||||
rustc_span::with_session_globals(self.config.edition().to_libsyntax_pos_edition(), || {
|
||||
rustc_span::with_session_globals(self.config.edition().into(), || {
|
||||
if self.config.disable_all_formatting() {
|
||||
// When the input is from stdin, echo back the input.
|
||||
if let Input::Text(ref buf) = input {
|
||||
|
@ -331,7 +331,7 @@ impl UseTree {
|
||||
};
|
||||
|
||||
let leading_modsep =
|
||||
context.config.edition() == Edition::Edition2018 && a.prefix.is_global();
|
||||
context.config.edition() >= Edition::Edition2018 && a.prefix.is_global();
|
||||
|
||||
let mut modsep = leading_modsep;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user