about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-01-01 17:00:40 +0100
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-01-09 12:11:52 -0600
commit398d2f96c3f04ba0b1413eb4b47250c7a8f51884 (patch)
tree3d3d42dc89dd07e5bee82557c6cb91123e5da859
parentd8e0d00377a77a721c2bae4cf64ce3d5bfcccc42 (diff)
downloadrust-398d2f96c3f04ba0b1413eb4b47250c7a8f51884.tar.gz
rust-398d2f96c3f04ba0b1413eb4b47250c7a8f51884.zip
Add support for edition 2021.
-rw-r--r--Configurations.md4
-rw-r--r--src/config/options.rs21
-rw-r--r--src/formatting.rs2
-rw-r--r--src/imports.rs2
4 files changed, 20 insertions, 9 deletions
diff --git a/Configurations.md b/Configurations.md
index 3b993f3fd48..e9035c6ff24 100644
--- a/Configurations.md
+++ b/Configurations.md
@@ -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
diff --git a/src/config/options.rs b/src/config/options.rs
index ae120a475f4..e7a6c414354 100644
--- a/src/config/options.rs
+++ b/src/config/options.rs
@@ -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 {
diff --git a/src/formatting.rs b/src/formatting.rs
index 26ae494227d..289e58cf693 100644
--- a/src/formatting.rs
+++ b/src/formatting.rs
@@ -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 {
diff --git a/src/imports.rs b/src/imports.rs
index 0b3d844ea14..d7082d50f88 100644
--- a/src/imports.rs
+++ b/src/imports.rs
@@ -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;