]> git.proxmox.com Git - rustc.git/blame - src/libsyntax_pos/edition.rs
New upstream version 1.29.0+dfsg1
[rustc.git] / src / libsyntax_pos / edition.rs
CommitLineData
0531ce1d
XL
1// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11use std::fmt;
12use std::str::FromStr;
13
14/// The edition of the compiler (RFC 2052)
8faf50e0 15#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable)]
0531ce1d
XL
16#[non_exhaustive]
17pub enum Edition {
94b46f34 18 // editions must be kept in order, oldest to newest
0531ce1d
XL
19
20 /// The 2015 edition
21 Edition2015,
22 /// The 2018 edition
23 Edition2018,
24
25 // when adding new editions, be sure to update:
26 //
83c7162d
XL
27 // - Update the `ALL_EDITIONS` const
28 // - Update the EDITION_NAME_LIST const
0531ce1d
XL
29 // - add a `rust_####()` function to the session
30 // - update the enum in Cargo's sources as well
0531ce1d
XL
31}
32
33// must be in order from oldest to newest
34pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];
35
83c7162d
XL
36pub const EDITION_NAME_LIST: &'static str = "2015|2018";
37
38pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
39
0531ce1d
XL
40impl fmt::Display for Edition {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 let s = match *self {
43 Edition::Edition2015 => "2015",
44 Edition::Edition2018 => "2018",
45 };
46 write!(f, "{}", s)
47 }
48}
49
50impl Edition {
51 pub fn lint_name(&self) -> &'static str {
52 match *self {
94b46f34
XL
53 Edition::Edition2015 => "rust_2015_compatibility",
54 Edition::Edition2018 => "rust_2018_compatibility",
83c7162d
XL
55 }
56 }
57
58 pub fn feature_name(&self) -> &'static str {
59 match *self {
60 Edition::Edition2015 => "rust_2015_preview",
61 Edition::Edition2018 => "rust_2018_preview",
62 }
63 }
64
65 pub fn is_stable(&self) -> bool {
66 match *self {
67 Edition::Edition2015 => true,
68 Edition::Edition2018 => false,
0531ce1d
XL
69 }
70 }
71}
72
73impl FromStr for Edition {
74 type Err = ();
75 fn from_str(s: &str) -> Result<Self, ()> {
76 match s {
77 "2015" => Ok(Edition::Edition2015),
78 "2018" => Ok(Edition::Edition2018),
79 _ => Err(())
80 }
81 }
82}