Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/edition/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum Edition {
Edition2018,
Edition2021,
Edition2024,
/// For forwards-compatibility, i.e. old rust-analyzer with newer rustc
EditionFuture,
}

impl Edition {
Expand All @@ -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"),
}
}
Expand All @@ -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<Item = Edition> {
[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024]
.iter()
Expand Down Expand Up @@ -91,6 +105,7 @@ impl fmt::Display for Edition {
Edition::Edition2018 => "2018",
Edition::Edition2021 => "2021",
Edition::Edition2024 => "2024",
Edition::EditionFuture => "future",
})
}
}
6 changes: 4 additions & 2 deletions crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
3 changes: 3 additions & 0 deletions crates/project-model/src/project_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ enum EditionData {
Edition2021,
#[serde(rename = "2024")]
Edition2024,
#[serde(other)]
EditionFuture,
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
Expand Down Expand Up @@ -529,6 +531,7 @@ impl From<EditionData> for Edition {
EditionData::Edition2018 => Edition::Edition2018,
EditionData::Edition2021 => Edition::Edition2021,
EditionData::Edition2024 => Edition::Edition2024,
EditionData::EditionFuture => Edition::EditionFuture,
}
}
}
Expand Down