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