Skip to content

Commit 3ec0c76

Browse files
committed
Add support for edition 2021.
1 parent 9a19515 commit 3ec0c76

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Configurations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ fn main() {
569569
Specifies which edition is used by the parser.
570570

571571
- **Default value**: `"2015"`
572-
- **Possible values**: `"2015"`, `"2018"`
572+
- **Possible values**: `"2015"`, `"2018"`, `"2021"`
573573
- **Stable**: Yes
574574

575575
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed

src/config/options.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ pub enum Edition {
343343
#[doc_hint = "2018"]
344344
/// Edition 2018.
345345
Edition2018,
346+
#[value = "2021"]
347+
#[doc_hint = "2021"]
348+
/// Edition 2021.
349+
Edition2021,
346350
}
347351

348352
impl Default for Edition {
@@ -356,10 +360,17 @@ impl From<Edition> for rustc_span::edition::Edition {
356360
match edition {
357361
Edition::Edition2015 => Self::Edition2015,
358362
Edition::Edition2018 => Self::Edition2018,
363+
Edition::Edition2021 => Self::Edition2021,
359364
}
360365
}
361366
}
362367

368+
impl PartialOrd for Edition {
369+
fn partial_cmp(&self, other: &Edition) -> Option<std::cmp::Ordering> {
370+
rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into())
371+
}
372+
}
373+
363374
/// Controls how rustfmt should handle leading pipes on match arms.
364375
#[config_type]
365376
pub enum MatchArmLeadingPipe {

src/formatting/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl UseTree {
333333
};
334334

335335
let leading_modsep =
336-
context.config.edition() == Edition::Edition2018 && a.prefix.is_global();
336+
context.config.edition() >= Edition::Edition2018 && a.prefix.is_global();
337337

338338
let mut modsep = leading_modsep;
339339

0 commit comments

Comments
 (0)