2019-12-22 22:42:04 +00:00
|
|
|
use crate::symbol::{sym, Symbol};
|
2018-03-08 21:16:36 +00:00
|
|
|
use std::fmt;
|
2018-03-06 22:05:03 +00:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
2019-11-09 21:25:30 +00:00
|
|
|
use rustc_macros::HashStable_Generic;
|
|
|
|
|
2020-12-24 07:01:03 +00:00
|
|
|
/// The edition of the compiler. (See [RFC 2052](https://github.com/rust-lang/rfcs/blob/master/text/2052-epochs.md).)
|
2020-06-11 14:49:57 +00:00
|
|
|
#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, Encodable, Decodable, Eq)]
|
2020-03-23 14:48:59 +00:00
|
|
|
#[derive(HashStable_Generic)]
|
2018-03-15 03:30:06 +00:00
|
|
|
pub enum Edition {
|
2020-12-24 07:01:03 +00:00
|
|
|
// When adding new editions, be sure to do the following:
|
|
|
|
//
|
|
|
|
// - update the `ALL_EDITIONS` const
|
|
|
|
// - update the `EDITION_NAME_LIST` const
|
|
|
|
// - add a `rust_####()` function to the session
|
|
|
|
// - update the enum in Cargo's sources as well
|
|
|
|
//
|
|
|
|
// Editions *must* be kept in order, oldest to newest.
|
2018-03-15 03:30:06 +00:00
|
|
|
/// The 2015 edition
|
|
|
|
Edition2015,
|
|
|
|
/// The 2018 edition
|
|
|
|
Edition2018,
|
2021-03-10 01:09:37 +00:00
|
|
|
/// The 2021 edition
|
2020-12-30 13:33:46 +00:00
|
|
|
Edition2021,
|
2018-03-06 22:05:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 07:01:03 +00:00
|
|
|
// Must be in order from oldest to newest.
|
2020-12-30 13:33:46 +00:00
|
|
|
pub const ALL_EDITIONS: &[Edition] =
|
|
|
|
&[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021];
|
2018-03-06 22:05:03 +00:00
|
|
|
|
2020-12-30 13:33:46 +00:00
|
|
|
pub const EDITION_NAME_LIST: &str = "2015|2018|2021";
|
2018-04-20 04:03:21 +00:00
|
|
|
|
2018-04-19 20:56:26 +00:00
|
|
|
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
|
|
|
|
|
2021-08-30 13:33:09 +00:00
|
|
|
pub const LATEST_STABLE_EDITION: Edition = Edition::Edition2021;
|
2020-12-30 13:33:46 +00:00
|
|
|
|
2018-03-15 03:30:06 +00:00
|
|
|
impl fmt::Display for Edition {
|
2019-02-03 18:42:27 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-03-08 21:16:36 +00:00
|
|
|
let s = match *self {
|
2018-03-15 03:30:06 +00:00
|
|
|
Edition::Edition2015 => "2015",
|
|
|
|
Edition::Edition2018 => "2018",
|
2020-12-30 13:33:46 +00:00
|
|
|
Edition::Edition2021 => "2021",
|
2018-03-08 21:16:36 +00:00
|
|
|
};
|
|
|
|
write!(f, "{}", s)
|
2018-03-06 22:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 03:30:06 +00:00
|
|
|
impl Edition {
|
2018-03-06 22:05:03 +00:00
|
|
|
pub fn lint_name(&self) -> &'static str {
|
|
|
|
match *self {
|
2018-05-10 18:28:11 +00:00
|
|
|
Edition::Edition2015 => "rust_2015_compatibility",
|
|
|
|
Edition::Edition2018 => "rust_2018_compatibility",
|
2020-12-30 13:33:46 +00:00
|
|
|
Edition::Edition2021 => "rust_2021_compatibility",
|
2018-03-06 22:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-21 22:48:56 +00:00
|
|
|
|
2019-05-07 06:03:44 +00:00
|
|
|
pub fn feature_name(&self) -> Symbol {
|
2018-03-21 22:48:56 +00:00
|
|
|
match *self {
|
2019-05-07 06:03:44 +00:00
|
|
|
Edition::Edition2015 => sym::rust_2015_preview,
|
|
|
|
Edition::Edition2018 => sym::rust_2018_preview,
|
2020-12-30 13:33:46 +00:00
|
|
|
Edition::Edition2021 => sym::rust_2021_preview,
|
2018-03-21 22:48:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-20 04:03:21 +00:00
|
|
|
|
|
|
|
pub fn is_stable(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
Edition::Edition2015 => true,
|
2018-09-06 16:20:01 +00:00
|
|
|
Edition::Edition2018 => true,
|
2021-08-17 01:42:23 +00:00
|
|
|
Edition::Edition2021 => true,
|
2018-04-20 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-06 22:05:03 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 03:30:06 +00:00
|
|
|
impl FromStr for Edition {
|
2018-03-06 22:05:03 +00:00
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, ()> {
|
|
|
|
match s {
|
2018-03-15 03:30:06 +00:00
|
|
|
"2015" => Ok(Edition::Edition2015),
|
|
|
|
"2018" => Ok(Edition::Edition2018),
|
2020-12-30 13:33:46 +00:00
|
|
|
"2021" => Ok(Edition::Edition2021),
|
2019-12-22 22:42:04 +00:00
|
|
|
_ => Err(()),
|
2018-03-06 22:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|