Skip to content

Commit 640884b

Browse files
committed
Add edition to expansion info
1 parent ee5b1e1 commit 640884b

File tree

11 files changed

+43
-8
lines changed

11 files changed

+43
-8
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ impl<'a> LoweringContext<'a> {
593593
span: Some(span),
594594
allow_internal_unstable: true,
595595
allow_internal_unsafe: false,
596+
edition: codemap::hygiene::default_edition(),
596597
},
597598
});
598599
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))

src/librustc/ich/impls_syntax.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability {
131131
rustc_const_unstable
132132
});
133133

134+
impl<'a> HashStable<StableHashingContext<'a>>
135+
for ::syntax::edition::Edition {
136+
fn hash_stable<W: StableHasherResult>(&self,
137+
hcx: &mut StableHashingContext<'a>,
138+
hasher: &mut StableHasher<W>) {
139+
mem::discriminant(self).hash_stable(hcx, hasher);
140+
}
141+
}
142+
134143
impl<'a> HashStable<StableHashingContext<'a>>
135144
for ::syntax::attr::StabilityLevel {
136145
fn hash_stable<W: StableHasherResult>(&self,
@@ -389,6 +398,7 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::NameAndSpan {
389398
format,
390399
allow_internal_unstable,
391400
allow_internal_unsafe,
401+
edition,
392402
span
393403
});
394404

src/librustc_allocator/expand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use syntax::ext::base::ExtCtxt;
2121
use syntax::ext::base::Resolver;
2222
use syntax::ext::build::AstBuilder;
2323
use syntax::ext::expand::ExpansionConfig;
24-
use syntax::ext::hygiene::{Mark, SyntaxContext};
24+
use syntax::ext::hygiene::{self, Mark, SyntaxContext};
2525
use syntax::fold::{self, Folder};
2626
use syntax::parse::ParseSess;
2727
use syntax::ptr::P;
@@ -86,6 +86,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
8686
span: None,
8787
allow_internal_unstable: true,
8888
allow_internal_unsafe: false,
89+
edition: hygiene::default_edition(),
8990
},
9091
});
9192
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));

src/librustc_driver/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use syntax::ast;
108108
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
109109
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
110110
use syntax::parse::{self, PResult};
111-
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
111+
use syntax_pos::{hygiene, DUMMY_SP, MultiSpan, FileName};
112112

113113
#[cfg(test)]
114114
mod test;
@@ -466,6 +466,7 @@ pub fn run_compiler<'a>(args: &[String],
466466
};
467467

468468
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
469+
hygiene::set_default_edition(sopts.edition);
469470

470471
driver::spawn_thread_pool(sopts, |sopts| {
471472
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)

src/libsyntax/ext/derive.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use attr::HasAttrs;
1212
use ast;
13-
use codemap::{ExpnInfo, NameAndSpan, ExpnFormat};
13+
use codemap::{hygiene, ExpnInfo, NameAndSpan, ExpnFormat};
1414
use ext::base::ExtCtxt;
1515
use ext::build::AstBuilder;
1616
use parse::parser::PathStyle;
@@ -65,6 +65,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path]
6565
span: None,
6666
allow_internal_unstable: true,
6767
allow_internal_unsafe: false,
68+
edition: hygiene::default_edition(),
6869
},
6970
});
7071

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use config::{is_test_or_bench, StripUnconfigured};
1616
use errors::FatalError;
1717
use ext::base::*;
1818
use ext::derive::{add_derived_markers, collect_derives};
19-
use ext::hygiene::{Mark, SyntaxContext};
19+
use ext::hygiene::{self, Mark, SyntaxContext};
2020
use ext::placeholders::{placeholder, PlaceholderExpander};
2121
use feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
2222
use fold;
@@ -502,6 +502,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
502502
span: None,
503503
allow_internal_unstable: false,
504504
allow_internal_unsafe: false,
505+
edition: hygiene::default_edition(),
505506
}
506507
});
507508

@@ -642,6 +643,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
642643
span: def_site_span,
643644
allow_internal_unstable,
644645
allow_internal_unsafe,
646+
edition: hygiene::default_edition(),
645647
},
646648
});
647649
Ok(())
@@ -688,6 +690,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
688690
span: tt_span,
689691
allow_internal_unstable,
690692
allow_internal_unsafe: false,
693+
edition: hygiene::default_edition(),
691694
}
692695
});
693696

@@ -728,6 +731,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
728731
// FIXME probably want to follow macro_rules macros here.
729732
allow_internal_unstable: false,
730733
allow_internal_unsafe: false,
734+
edition: hygiene::default_edition(),
731735
},
732736
});
733737

@@ -802,6 +806,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
802806
span: None,
803807
allow_internal_unstable: false,
804808
allow_internal_unsafe: false,
809+
edition: hygiene::default_edition(),
805810
}
806811
};
807812

src/libsyntax/std_inject.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::cell::Cell;
1414
use ext::hygiene::{Mark, SyntaxContext};
1515
use symbol::{Symbol, keywords};
1616
use syntax_pos::{DUMMY_SP, Span};
17-
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, respan};
17+
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, hygiene, respan};
1818
use ptr::P;
1919
use tokenstream::TokenStream;
2020

@@ -30,6 +30,7 @@ fn ignored_span(sp: Span) -> Span {
3030
span: None,
3131
allow_internal_unstable: true,
3232
allow_internal_unsafe: false,
33+
edition: hygiene::default_edition(),
3334
}
3435
});
3536
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))

src/libsyntax/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use entry::{self, EntryPointType};
2929
use ext::base::{ExtCtxt, Resolver};
3030
use ext::build::AstBuilder;
3131
use ext::expand::ExpansionConfig;
32-
use ext::hygiene::{Mark, SyntaxContext};
32+
use ext::hygiene::{self, Mark, SyntaxContext};
3333
use fold::Folder;
3434
use feature_gate::Features;
3535
use util::move_map::MoveMap;
@@ -300,6 +300,7 @@ fn generate_test_harness(sess: &ParseSess,
300300
span: None,
301301
allow_internal_unstable: true,
302302
allow_internal_unsafe: false,
303+
edition: hygiene::default_edition(),
303304
}
304305
});
305306

src/libsyntax_ext/proc_macro_registrar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use errors;
1414

1515
use syntax::ast::{self, Ident, NodeId};
1616
use syntax::attr;
17-
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, respan};
17+
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, hygiene, respan};
1818
use syntax::ext::base::ExtCtxt;
1919
use syntax::ext::build::AstBuilder;
2020
use syntax::ext::expand::ExpansionConfig;
@@ -369,6 +369,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
369369
span: None,
370370
allow_internal_unstable: true,
371371
allow_internal_unsafe: false,
372+
edition: hygiene::default_edition(),
372373
}
373374
});
374375
let span = DUMMY_SP.apply_mark(mark);

src/libsyntax_pos/edition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::fmt;
1212
use std::str::FromStr;
1313

1414
/// The edition of the compiler (RFC 2052)
15-
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
15+
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug, RustcEncodable, RustcDecodable)]
1616
#[non_exhaustive]
1717
pub enum Edition {
1818
// editions must be kept in order, newest to oldest

src/libsyntax_pos/hygiene.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1818
use GLOBALS;
1919
use Span;
20+
use edition::Edition;
2021
use symbol::{Ident, Symbol};
2122

2223
use serialize::{Encodable, Decodable, Encoder, Decoder};
@@ -151,6 +152,7 @@ pub struct HygieneData {
151152
syntax_contexts: Vec<SyntaxContextData>,
152153
markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
153154
gensym_to_ctxt: HashMap<Symbol, Span>,
155+
default_edition: Edition,
154156
}
155157

156158
impl HygieneData {
@@ -168,6 +170,7 @@ impl HygieneData {
168170
}],
169171
markings: HashMap::new(),
170172
gensym_to_ctxt: HashMap::new(),
173+
default_edition: Edition::Edition2015,
171174
}
172175
}
173176

@@ -176,6 +179,14 @@ impl HygieneData {
176179
}
177180
}
178181

182+
pub fn default_edition() -> Edition {
183+
HygieneData::with(|data| data.default_edition)
184+
}
185+
186+
pub fn set_default_edition(edition: Edition) {
187+
HygieneData::with(|data| data.default_edition = edition);
188+
}
189+
179190
pub fn clear_markings() {
180191
HygieneData::with(|data| data.markings = HashMap::new());
181192
}
@@ -443,6 +454,8 @@ pub struct NameAndSpan {
443454
/// Whether the macro is allowed to use `unsafe` internally
444455
/// even if the user crate has `#![forbid(unsafe_code)]`.
445456
pub allow_internal_unsafe: bool,
457+
/// Edition of the crate in which the macro is defined.
458+
pub edition: Edition,
446459
/// The span of the macro definition itself. The macro may not
447460
/// have a sensible definition span (e.g. something defined
448461
/// completely inside libsyntax) in which case this is None.

0 commit comments

Comments
 (0)