From b36b74ed2752c76a374dc11c9e15c5dbb579cfe1 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 9 Jan 2026 10:21:45 +1100 Subject: [PATCH] Edition::EditionFuture for forwards compatibility --- crates/edition/src/lib.rs | 15 +++++++++++++++ crates/hir-def/src/nameres/collector.rs | 6 ++++-- crates/project-model/src/project_json.rs | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/edition/src/lib.rs b/crates/edition/src/lib.rs index f1a1fe596493..989146bd7f7f 100644 --- a/crates/edition/src/lib.rs +++ b/crates/edition/src/lib.rs @@ -10,6 +10,8 @@ pub enum Edition { Edition2018, Edition2021, Edition2024, + /// For forwards-compatibility, i.e. old rust-analyzer with newer rustc + EditionFuture, } impl Edition { @@ -21,10 +23,12 @@ impl Edition { pub fn from_u32(u32: u32) -> Edition { match u32 { + // Match enum order. EditionFuture should stay at the bottom and be updated to latest+1. 0 => Edition::Edition2015, 1 => Edition::Edition2018, 2 => Edition::Edition2021, 3 => Edition::Edition2024, + 4 => Edition::EditionFuture, _ => panic!("invalid edition"), } } @@ -41,15 +45,25 @@ impl Edition { self >= Edition::Edition2018 } + /// Replaces EditionFuture with the latest known edition. + pub fn or_latest(self) -> Edition { + match self { + Edition::EditionFuture => Edition::LATEST, + _ => self, + } + } + pub fn number(&self) -> usize { match self { Edition::Edition2015 => 2015, Edition::Edition2018 => 2018, Edition::Edition2021 => 2021, Edition::Edition2024 => 2024, + Edition::EditionFuture => 9999, } } + /// Iterate the known editions. Excludes EditionFuture pub fn iter() -> impl Iterator { [Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024] .iter() @@ -91,6 +105,7 @@ impl fmt::Display for Edition { Edition::Edition2018 => "2018", Edition::Edition2021 => "2021", Edition::Edition2024 => "2024", + Edition::EditionFuture => "future", }) } } diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 323060f61d15..a36f09b96767 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -545,14 +545,16 @@ impl<'db> DefCollector<'db> { Name::new_symbol_root(sym::core) }; - let edition = match self.def_map.data.edition { + let edition_or_latest = self.def_map.data.edition.or_latest(); + let edition = match edition_or_latest { Edition::Edition2015 => Name::new_symbol_root(sym::rust_2015), Edition::Edition2018 => Name::new_symbol_root(sym::rust_2018), Edition::Edition2021 => Name::new_symbol_root(sym::rust_2021), Edition::Edition2024 => Name::new_symbol_root(sym::rust_2024), + Edition::EditionFuture => unreachable!("Replaced with latest"), }; - let path_kind = match self.def_map.data.edition { + let path_kind = match edition_or_latest { Edition::Edition2015 => PathKind::Plain, _ => PathKind::Abs, }; diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index 6938010cbd70..6d2c9f7662cb 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -454,6 +454,8 @@ enum EditionData { Edition2021, #[serde(rename = "2024")] Edition2024, + #[serde(other)] + EditionFuture, } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] @@ -529,6 +531,7 @@ impl From for Edition { EditionData::Edition2018 => Edition::Edition2018, EditionData::Edition2021 => Edition::Edition2021, EditionData::Edition2024 => Edition::Edition2024, + EditionData::EditionFuture => Edition::EditionFuture, } } }