compiletest/
edition.rs

1use crate::fatal;
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
4pub enum Edition {
5    // Note that the ordering here is load-bearing, as we want the future edition to be greater than
6    // any year-based edition.
7    Year(u32),
8    Future,
9}
10
11impl std::fmt::Display for Edition {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        match self {
14            Edition::Year(year) => write!(f, "{year}"),
15            Edition::Future => f.write_str("future"),
16        }
17    }
18}
19
20impl From<u32> for Edition {
21    fn from(value: u32) -> Self {
22        Edition::Year(value)
23    }
24}
25
26pub fn parse_edition(mut input: &str) -> Edition {
27    input = input.trim();
28    if input == "future" {
29        Edition::Future
30    } else {
31        Edition::Year(input.parse().unwrap_or_else(|_| {
32            fatal!("`{input}` doesn't look like an edition");
33        }))
34    }
35}