]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_pos/edition.rs
Fix rebase fallout.
[rust.git] / src / libsyntax_pos / edition.rs
1 use crate::symbol::{Symbol, sym};
2 use std::fmt;
3 use std::str::FromStr;
4
5 use rustc_macros::HashStable_Generic;
6
7 /// The edition of the compiler (RFC 2052)
8 #[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug,
9          RustcEncodable, RustcDecodable, Eq, HashStable_Generic)]
10 pub enum Edition {
11     // editions must be kept in order, oldest to newest
12
13     /// The 2015 edition
14     Edition2015,
15     /// The 2018 edition
16     Edition2018,
17
18     // when adding new editions, be sure to update:
19     //
20     // - Update the `ALL_EDITIONS` const
21     // - Update the EDITION_NAME_LIST const
22     // - add a `rust_####()` function to the session
23     // - update the enum in Cargo's sources as well
24 }
25
26 // must be in order from oldest to newest
27 pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];
28
29 pub const EDITION_NAME_LIST: &str = "2015|2018";
30
31 pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
32
33 impl fmt::Display for Edition {
34     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35         let s = match *self {
36             Edition::Edition2015 => "2015",
37             Edition::Edition2018 => "2018",
38         };
39         write!(f, "{}", s)
40     }
41 }
42
43 impl Edition {
44     pub fn lint_name(&self) -> &'static str {
45         match *self {
46             Edition::Edition2015 => "rust_2015_compatibility",
47             Edition::Edition2018 => "rust_2018_compatibility",
48         }
49     }
50
51     pub fn feature_name(&self) -> Symbol {
52         match *self {
53             Edition::Edition2015 => sym::rust_2015_preview,
54             Edition::Edition2018 => sym::rust_2018_preview,
55         }
56     }
57
58     pub fn is_stable(&self) -> bool {
59         match *self {
60             Edition::Edition2015 => true,
61             Edition::Edition2018 => true,
62         }
63     }
64 }
65
66 impl FromStr for Edition {
67     type Err = ();
68     fn from_str(s: &str) -> Result<Self, ()> {
69         match s {
70             "2015" => Ok(Edition::Edition2015),
71             "2018" => Ok(Edition::Edition2018),
72             _ => Err(())
73         }
74     }
75 }