Skip to content

Commit 4338bd1

Browse files
committed
Move epochs to libsyntax
1 parent 604d4ce commit 4338bd1

File tree

8 files changed

+83
-61
lines changed

8 files changed

+83
-61
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use errors::DiagnosticBuilder;
1818
use lint::{LintPass, LateLintPass, LintArray};
1919
use session::Session;
20-
use session::config::Epoch;
2120
use syntax::codemap::Span;
21+
use syntax::epoch::Epoch;
2222

2323
declare_lint! {
2424
pub EXCEEDING_BITSHIFTS,

src/librustc/lint/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use util::nodemap::FxHashMap;
4242
use std::default::Default as StdDefault;
4343
use std::cell::{Ref, RefCell};
4444
use syntax::ast;
45+
use syntax::epoch;
4546
use syntax_pos::{MultiSpan, Span};
4647
use errors::DiagnosticBuilder;
4748
use hir;
@@ -105,7 +106,7 @@ pub struct FutureIncompatibleInfo {
105106
pub reference: &'static str,
106107
/// If this is an epoch fixing lint, the epoch in which
107108
/// this lint becomes obsolete
108-
pub epoch: Option<config::Epoch>,
109+
pub epoch: Option<epoch::Epoch>,
109110
}
110111

111112
/// The target of the `by_name` map, which accounts for renaming/deprecation.
@@ -201,7 +202,7 @@ impl LintStore {
201202
sess: Option<&Session>,
202203
lints: Vec<FutureIncompatibleInfo>) {
203204

204-
for epoch in config::ALL_EPOCHS {
205+
for epoch in epoch::ALL_EPOCHS {
205206
let lints = lints.iter().filter(|f| f.epoch == Some(*epoch)).map(|f| f.id)
206207
.collect::<Vec<_>>();
207208
if !lints.is_empty() {

src/librustc/lint/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ use hir::def_id::{CrateNum, LOCAL_CRATE};
3838
use hir::intravisit::{self, FnKind};
3939
use hir;
4040
use lint::builtin::BuiltinLintDiagnostics;
41-
use session::{config, Session, DiagnosticMessageId};
41+
use session::{Session, DiagnosticMessageId};
4242
use std::hash;
4343
use syntax::ast;
4444
use syntax::codemap::MultiSpan;
45+
use syntax::epoch::Epoch;
4546
use syntax::symbol::Symbol;
4647
use syntax::visit as ast_visit;
4748
use syntax_pos::Span;
@@ -77,7 +78,7 @@ pub struct Lint {
7778
pub desc: &'static str,
7879

7980
/// Deny lint after this epoch
80-
pub epoch_deny: Option<config::Epoch>,
81+
pub epoch_deny: Option<Epoch>,
8182
}
8283

8384
impl Lint {

src/librustc/session/config.rs

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use middle::cstore;
2828

2929
use syntax::ast::{self, IntTy, UintTy};
3030
use syntax::codemap::{FileName, FilePathMapping};
31+
use syntax::epoch::Epoch;
3132
use syntax::parse::token;
3233
use syntax::parse;
3334
use syntax::symbol::Symbol;
@@ -111,59 +112,6 @@ pub enum OutputType {
111112
DepInfo,
112113
}
113114

114-
/// The epoch of the compiler (RFC 2052)
115-
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
116-
#[non_exhaustive]
117-
pub enum Epoch {
118-
// epochs must be kept in order, newest to oldest
119-
/// The 2015 epoch
120-
Epoch2015,
121-
/// The 2018 epoch
122-
Epoch2018,
123-
// when adding new epochs, be sure to update:
124-
//
125-
// - the list in the `parse_epoch` static
126-
// - the match in the `parse_epoch` function
127-
// - add a `rust_####()` function to the session
128-
// - update the enum in Cargo's sources as well
129-
//
130-
// When -Zepoch becomes --epoch, there will
131-
// also be a check for the epoch being nightly-only
132-
// somewhere. That will need to be updated
133-
// whenever we're stabilizing/introducing a new epoch
134-
// as well as changing the default Cargo template.
135-
}
136-
137-
pub const ALL_EPOCHS: &[Epoch] = &[Epoch::Epoch2015, Epoch::Epoch2018];
138-
139-
impl ToString for Epoch {
140-
fn to_string(&self) -> String {
141-
match *self {
142-
Epoch::Epoch2015 => "2015".into(),
143-
Epoch::Epoch2018 => "2018".into(),
144-
}
145-
}
146-
}
147-
148-
impl Epoch {
149-
pub fn lint_name(&self) -> &'static str {
150-
match *self {
151-
Epoch::Epoch2015 => "epoch_2015",
152-
Epoch::Epoch2018 => "epoch_2018",
153-
}
154-
}
155-
}
156-
157-
impl str::FromStr for Epoch {
158-
type Err = ();
159-
fn from_str(s: &str) -> Result<Self, ()> {
160-
match s {
161-
"2015" => Ok(Epoch::Epoch2015),
162-
"2018" => Ok(Epoch::Epoch2018),
163-
_ => Err(()),
164-
}
165-
}
166-
}
167115

168116
impl_stable_hash_for!(enum self::OutputType {
169117
Bitcode,
@@ -829,9 +777,10 @@ macro_rules! options {
829777

830778
#[allow(dead_code)]
831779
mod $mod_set {
832-
use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer, Lto, Epoch};
780+
use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer, Lto};
833781
use rustc_back::{LinkerFlavor, PanicStrategy, RelroLevel};
834782
use std::path::PathBuf;
783+
use syntax::epoch::Epoch;
835784

836785
$(
837786
pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {

src/librustc/session/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use lint::builtin::BuiltinLintDiagnostics;
2020
use middle::allocator::AllocatorKind;
2121
use middle::dependency_format;
2222
use session::search_paths::PathKind;
23-
use session::config::{DebugInfoLevel, Epoch, OutputType};
23+
use session::config::{DebugInfoLevel, OutputType};
2424
use ty::tls;
2525
use util::nodemap::{FxHashMap, FxHashSet};
2626
use util::common::{duration_to_secs_str, ErrorReported};
@@ -30,6 +30,7 @@ use rustc_data_structures::sync::Lrc;
3030
use syntax::ast::NodeId;
3131
use errors::{self, DiagnosticBuilder, DiagnosticId};
3232
use errors::emitter::{Emitter, EmitterWriter};
33+
use syntax::epoch::Epoch;
3334
use syntax::json::JsonEmitter;
3435
use syntax::feature_gate;
3536
use syntax::symbol::Symbol;

src/librustc_lint/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use rustc::session;
4747
use rustc::util;
4848

4949
use session::Session;
50+
use syntax::epoch::Epoch;
5051
use lint::LintId;
5152
use lint::FutureIncompatibleInfo;
5253

@@ -279,7 +280,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
279280
FutureIncompatibleInfo {
280281
id: LintId::of(lint::builtin::BARE_TRAIT_OBJECT),
281282
reference: "issue #48457 <https://github.com/rust-lang/rust/issues/48457>",
282-
epoch: Some(session::config::Epoch::Epoch2018),
283+
epoch: Some(Epoch::Epoch2018),
283284
}
284285
]);
285286

src/libsyntax/epoch.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
11+
use std::str::FromStr;
12+
13+
/// The epoch of the compiler (RFC 2052)
14+
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
15+
#[non_exhaustive]
16+
pub enum Epoch {
17+
// epochs must be kept in order, newest to oldest
18+
19+
/// The 2015 epoch
20+
Epoch2015,
21+
/// The 2018 epoch
22+
Epoch2018,
23+
24+
// when adding new epochs, be sure to update:
25+
//
26+
// - the list in the `parse_epoch` static in librustc::session::config
27+
// - add a `rust_####()` function to the session
28+
// - update the enum in Cargo's sources as well
29+
//
30+
// When -Zepoch becomes --epoch, there will
31+
// also be a check for the epoch being nightly-only
32+
// somewhere. That will need to be updated
33+
// whenever we're stabilizing/introducing a new epoch
34+
// as well as changing the default Cargo template.
35+
}
36+
37+
// must be in order from oldest to newest
38+
pub const ALL_EPOCHS: &[Epoch] = &[Epoch::Epoch2015, Epoch::Epoch2018];
39+
40+
impl ToString for Epoch {
41+
fn to_string(&self) -> String {
42+
match *self {
43+
Epoch::Epoch2015 => "2015".into(),
44+
Epoch::Epoch2018 => "2018".into(),
45+
}
46+
}
47+
}
48+
49+
impl Epoch {
50+
pub fn lint_name(&self) -> &'static str {
51+
match *self {
52+
Epoch::Epoch2015 => "epoch_2015",
53+
Epoch::Epoch2018 => "epoch_2018",
54+
}
55+
}
56+
}
57+
58+
impl FromStr for Epoch {
59+
type Err = ();
60+
fn from_str(s: &str) -> Result<Self, ()> {
61+
match s {
62+
"2015" => Ok(Epoch::Epoch2015),
63+
"2018" => Ok(Epoch::Epoch2018),
64+
_ => Err(())
65+
}
66+
}
67+
}

src/libsyntax/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(unicode)]
2424
#![feature(rustc_diagnostic_macros)]
2525
#![feature(match_default_bindings)]
26+
#![feature(non_exhaustive)]
2627
#![feature(i128_type)]
2728
#![feature(const_atomic_usize_new)]
2829
#![feature(rustc_attrs)]
@@ -114,6 +115,7 @@ pub mod codemap;
114115
#[macro_use]
115116
pub mod config;
116117
pub mod entry;
118+
pub mod epoch;
117119
pub mod feature_gate;
118120
pub mod fold;
119121
pub mod parse;

0 commit comments

Comments
 (0)