Add edition to expansion info
This commit is contained in:
parent
ee5b1e15aa
commit
640884bad0
|
@ -593,6 +593,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
span: Some(span),
|
span: Some(span),
|
||||||
allow_internal_unstable: true,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: codemap::hygiene::default_edition(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
|
|
|
@ -131,6 +131,15 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability {
|
||||||
rustc_const_unstable
|
rustc_const_unstable
|
||||||
});
|
});
|
||||||
|
|
||||||
|
impl<'a> HashStable<StableHashingContext<'a>>
|
||||||
|
for ::syntax::edition::Edition {
|
||||||
|
fn hash_stable<W: StableHasherResult>(&self,
|
||||||
|
hcx: &mut StableHashingContext<'a>,
|
||||||
|
hasher: &mut StableHasher<W>) {
|
||||||
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> HashStable<StableHashingContext<'a>>
|
impl<'a> HashStable<StableHashingContext<'a>>
|
||||||
for ::syntax::attr::StabilityLevel {
|
for ::syntax::attr::StabilityLevel {
|
||||||
fn hash_stable<W: StableHasherResult>(&self,
|
fn hash_stable<W: StableHasherResult>(&self,
|
||||||
|
@ -389,6 +398,7 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::NameAndSpan {
|
||||||
format,
|
format,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
allow_internal_unsafe,
|
allow_internal_unsafe,
|
||||||
|
edition,
|
||||||
span
|
span
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::ext::base::Resolver;
|
use syntax::ext::base::Resolver;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ext::expand::ExpansionConfig;
|
use syntax::ext::expand::ExpansionConfig;
|
||||||
use syntax::ext::hygiene::{Mark, SyntaxContext};
|
use syntax::ext::hygiene::{self, Mark, SyntaxContext};
|
||||||
use syntax::fold::{self, Folder};
|
use syntax::fold::{self, Folder};
|
||||||
use syntax::parse::ParseSess;
|
use syntax::parse::ParseSess;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
@ -86,6 +86,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
||||||
|
|
|
@ -108,7 +108,7 @@ use syntax::ast;
|
||||||
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
|
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
|
||||||
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
|
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
|
||||||
use syntax::parse::{self, PResult};
|
use syntax::parse::{self, PResult};
|
||||||
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
|
use syntax_pos::{hygiene, DUMMY_SP, MultiSpan, FileName};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
@ -466,6 +466,7 @@ pub fn run_compiler<'a>(args: &[String],
|
||||||
};
|
};
|
||||||
|
|
||||||
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
|
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
|
||||||
|
hygiene::set_default_edition(sopts.edition);
|
||||||
|
|
||||||
driver::spawn_thread_pool(sopts, |sopts| {
|
driver::spawn_thread_pool(sopts, |sopts| {
|
||||||
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)
|
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use attr::HasAttrs;
|
use attr::HasAttrs;
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::{ExpnInfo, NameAndSpan, ExpnFormat};
|
use codemap::{hygiene, ExpnInfo, NameAndSpan, ExpnFormat};
|
||||||
use ext::base::ExtCtxt;
|
use ext::base::ExtCtxt;
|
||||||
use ext::build::AstBuilder;
|
use ext::build::AstBuilder;
|
||||||
use parse::parser::PathStyle;
|
use parse::parser::PathStyle;
|
||||||
|
@ -65,6 +65,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path]
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use config::{is_test_or_bench, StripUnconfigured};
|
||||||
use errors::FatalError;
|
use errors::FatalError;
|
||||||
use ext::base::*;
|
use ext::base::*;
|
||||||
use ext::derive::{add_derived_markers, collect_derives};
|
use ext::derive::{add_derived_markers, collect_derives};
|
||||||
use ext::hygiene::{Mark, SyntaxContext};
|
use ext::hygiene::{self, Mark, SyntaxContext};
|
||||||
use ext::placeholders::{placeholder, PlaceholderExpander};
|
use ext::placeholders::{placeholder, PlaceholderExpander};
|
||||||
use feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
|
use feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
|
||||||
use fold;
|
use fold;
|
||||||
|
@ -502,6 +502,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: false,
|
allow_internal_unstable: false,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -642,6 +643,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
span: def_site_span,
|
span: def_site_span,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
allow_internal_unsafe,
|
allow_internal_unsafe,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -688,6 +690,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
span: tt_span,
|
span: tt_span,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -728,6 +731,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
// FIXME probably want to follow macro_rules macros here.
|
// FIXME probably want to follow macro_rules macros here.
|
||||||
allow_internal_unstable: false,
|
allow_internal_unstable: false,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -802,6 +806,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: false,
|
allow_internal_unstable: false,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::cell::Cell;
|
||||||
use ext::hygiene::{Mark, SyntaxContext};
|
use ext::hygiene::{Mark, SyntaxContext};
|
||||||
use symbol::{Symbol, keywords};
|
use symbol::{Symbol, keywords};
|
||||||
use syntax_pos::{DUMMY_SP, Span};
|
use syntax_pos::{DUMMY_SP, Span};
|
||||||
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, respan};
|
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, hygiene, respan};
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
use tokenstream::TokenStream;
|
use tokenstream::TokenStream;
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ fn ignored_span(sp: Span) -> Span {
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
|
|
|
@ -29,7 +29,7 @@ use entry::{self, EntryPointType};
|
||||||
use ext::base::{ExtCtxt, Resolver};
|
use ext::base::{ExtCtxt, Resolver};
|
||||||
use ext::build::AstBuilder;
|
use ext::build::AstBuilder;
|
||||||
use ext::expand::ExpansionConfig;
|
use ext::expand::ExpansionConfig;
|
||||||
use ext::hygiene::{Mark, SyntaxContext};
|
use ext::hygiene::{self, Mark, SyntaxContext};
|
||||||
use fold::Folder;
|
use fold::Folder;
|
||||||
use feature_gate::Features;
|
use feature_gate::Features;
|
||||||
use util::move_map::MoveMap;
|
use util::move_map::MoveMap;
|
||||||
|
@ -300,6 +300,7 @@ fn generate_test_harness(sess: &ParseSess,
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ use errors;
|
||||||
|
|
||||||
use syntax::ast::{self, Ident, NodeId};
|
use syntax::ast::{self, Ident, NodeId};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, respan};
|
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, hygiene, respan};
|
||||||
use syntax::ext::base::ExtCtxt;
|
use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ext::expand::ExpansionConfig;
|
use syntax::ext::expand::ExpansionConfig;
|
||||||
|
@ -369,6 +369,7 @@ fn mk_registrar(cx: &mut ExtCtxt,
|
||||||
span: None,
|
span: None,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
edition: hygiene::default_edition(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let span = DUMMY_SP.apply_mark(mark);
|
let span = DUMMY_SP.apply_mark(mark);
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// The edition of the compiler (RFC 2052)
|
/// The edition of the compiler (RFC 2052)
|
||||||
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
|
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug, RustcEncodable, RustcDecodable)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Edition {
|
pub enum Edition {
|
||||||
// editions must be kept in order, newest to oldest
|
// editions must be kept in order, newest to oldest
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
use GLOBALS;
|
use GLOBALS;
|
||||||
use Span;
|
use Span;
|
||||||
|
use edition::Edition;
|
||||||
use symbol::{Ident, Symbol};
|
use symbol::{Ident, Symbol};
|
||||||
|
|
||||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||||
|
@ -151,6 +152,7 @@ pub struct HygieneData {
|
||||||
syntax_contexts: Vec<SyntaxContextData>,
|
syntax_contexts: Vec<SyntaxContextData>,
|
||||||
markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
|
markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
|
||||||
gensym_to_ctxt: HashMap<Symbol, Span>,
|
gensym_to_ctxt: HashMap<Symbol, Span>,
|
||||||
|
default_edition: Edition,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HygieneData {
|
impl HygieneData {
|
||||||
|
@ -168,6 +170,7 @@ impl HygieneData {
|
||||||
}],
|
}],
|
||||||
markings: HashMap::new(),
|
markings: HashMap::new(),
|
||||||
gensym_to_ctxt: HashMap::new(),
|
gensym_to_ctxt: HashMap::new(),
|
||||||
|
default_edition: Edition::Edition2015,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +179,14 @@ impl HygieneData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_edition() -> Edition {
|
||||||
|
HygieneData::with(|data| data.default_edition)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_default_edition(edition: Edition) {
|
||||||
|
HygieneData::with(|data| data.default_edition = edition);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clear_markings() {
|
pub fn clear_markings() {
|
||||||
HygieneData::with(|data| data.markings = HashMap::new());
|
HygieneData::with(|data| data.markings = HashMap::new());
|
||||||
}
|
}
|
||||||
|
@ -443,6 +454,8 @@ pub struct NameAndSpan {
|
||||||
/// Whether the macro is allowed to use `unsafe` internally
|
/// Whether the macro is allowed to use `unsafe` internally
|
||||||
/// even if the user crate has `#![forbid(unsafe_code)]`.
|
/// even if the user crate has `#![forbid(unsafe_code)]`.
|
||||||
pub allow_internal_unsafe: bool,
|
pub allow_internal_unsafe: bool,
|
||||||
|
/// Edition of the crate in which the macro is defined.
|
||||||
|
pub edition: Edition,
|
||||||
/// The span of the macro definition itself. The macro may not
|
/// The span of the macro definition itself. The macro may not
|
||||||
/// have a sensible definition span (e.g. something defined
|
/// have a sensible definition span (e.g. something defined
|
||||||
/// completely inside libsyntax) in which case this is None.
|
/// completely inside libsyntax) in which case this is None.
|
||||||
|
|
Loading…
Reference in a new issue