1
Fork 0

make emit_feature_err take a ParseSess

This commit is contained in:
Tim Neumann 2016-09-24 18:42:54 +02:00
parent 9966397b61
commit b0dba7439d
12 changed files with 26 additions and 24 deletions

View file

@ -411,8 +411,8 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
&feature, &r), &feature, &r),
None => format!("use of unstable library feature '{}'", &feature) None => format!("use of unstable library feature '{}'", &feature)
}; };
emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic, emit_feature_err(&self.tcx.sess.parse_sess, &feature, span,
&feature, span, GateIssue::Library(Some(issue)), &msg); GateIssue::Library(Some(issue)), &msg);
} }
} }
Some(&Stability { ref level, ref feature, .. }) => { Some(&Stability { ref level, ref feature, .. }) => {

View file

@ -143,7 +143,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
}); });
if any_static { if any_static {
if !self.sess.features.borrow().static_recursion { if !self.sess.features.borrow().static_recursion {
emit_feature_err(&self.sess.parse_sess.span_diagnostic, emit_feature_err(&self.sess.parse_sess,
"static_recursion", "static_recursion",
*self.root_span, *self.root_span,
GateIssue::Language, GateIssue::Language,

View file

@ -795,7 +795,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// For now, require that parenthetical notation be used // For now, require that parenthetical notation be used
// only with `Fn()` etc. // only with `Fn()` etc.
if !self.tcx().sess.features.borrow().unboxed_closures && trait_def.paren_sugar { if !self.tcx().sess.features.borrow().unboxed_closures && trait_def.paren_sugar {
emit_feature_err(&self.tcx().sess.parse_sess.span_diagnostic, emit_feature_err(&self.tcx().sess.parse_sess,
"unboxed_closures", span, GateIssue::Language, "unboxed_closures", span, GateIssue::Language,
"\ "\
the precise format of `Fn`-family traits' \ the precise format of `Fn`-family traits' \
@ -807,7 +807,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// For now, require that parenthetical notation be used // For now, require that parenthetical notation be used
// only with `Fn()` etc. // only with `Fn()` etc.
if !self.tcx().sess.features.borrow().unboxed_closures && !trait_def.paren_sugar { if !self.tcx().sess.features.borrow().unboxed_closures && !trait_def.paren_sugar {
emit_feature_err(&self.tcx().sess.parse_sess.span_diagnostic, emit_feature_err(&self.tcx().sess.parse_sess,
"unboxed_closures", span, GateIssue::Language, "unboxed_closures", span, GateIssue::Language,
"\ "\
parenthetical notation is only stable when used with `Fn`-family traits"); parenthetical notation is only stable when used with `Fn`-family traits");

View file

@ -3256,7 +3256,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some((def_id, variant)) = variant { if let Some((def_id, variant)) = variant {
if variant.kind == ty::VariantKind::Tuple && if variant.kind == ty::VariantKind::Tuple &&
!self.tcx.sess.features.borrow().relaxed_adts { !self.tcx.sess.features.borrow().relaxed_adts {
emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic, emit_feature_err(&self.tcx.sess.parse_sess,
"relaxed_adts", span, GateIssue::Language, "relaxed_adts", span, GateIssue::Language,
"tuple structs and variants in struct patterns are unstable"); "tuple structs and variants in struct patterns are unstable");
} }

View file

@ -157,7 +157,7 @@ impl<'a> StripUnconfigured<'a> {
// flag the offending attributes // flag the offending attributes
for attr in attrs.iter() { for attr in attrs.iter() {
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) { if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
emit_feature_err(&self.sess.span_diagnostic, emit_feature_err(&self.sess,
"stmt_expr_attributes", "stmt_expr_attributes",
attr.span, attr.span,
GateIssue::Language, GateIssue::Language,

View file

@ -344,7 +344,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
// Detect use of feature-gated or invalid attributes on macro invoations // Detect use of feature-gated or invalid attributes on macro invoations
// since they will not be detected after macro expansion. // since they will not be detected after macro expansion.
for attr in attrs.iter() { for attr in attrs.iter() {
feature_gate::check_attribute(&attr, &self.cx.parse_sess.span_diagnostic, feature_gate::check_attribute(&attr, &self.cx.parse_sess,
&self.cx.parse_sess.codemap(), &self.cx.parse_sess.codemap(),
&self.cx.ecfg.features.unwrap()); &self.cx.ecfg.features.unwrap());
} }

View file

@ -679,16 +679,15 @@ impl GatedCfg {
pub fn check_and_emit(&self, sess: &ParseSess, features: &Features) { pub fn check_and_emit(&self, sess: &ParseSess, features: &Features) {
let (cfg, feature, has_feature) = GATED_CFGS[self.index]; let (cfg, feature, has_feature) = GATED_CFGS[self.index];
if !has_feature(features) && !sess.codemap().span_allows_unstable(self.span) { if !has_feature(features) && !sess.codemap().span_allows_unstable(self.span) {
let diagnostic = &sess.span_diagnostic;
let explain = format!("`cfg({})` is experimental and subject to change", cfg); let explain = format!("`cfg({})` is experimental and subject to change", cfg);
emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain); emit_feature_err(sess, feature, self.span, GateIssue::Language, &explain);
} }
} }
} }
struct Context<'a> { struct Context<'a> {
features: &'a Features, features: &'a Features,
span_handler: &'a Handler, parse_sess: &'a ParseSess,
cm: &'a CodeMap, cm: &'a CodeMap,
plugin_attributes: &'a [(String, AttributeType)], plugin_attributes: &'a [(String, AttributeType)],
} }
@ -699,7 +698,7 @@ macro_rules! gate_feature_fn {
let has_feature: bool = has_feature(&$cx.features); let has_feature: bool = has_feature(&$cx.features);
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature); debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
if !has_feature && !cx.cm.span_allows_unstable(span) { if !has_feature && !cx.cm.span_allows_unstable(span) {
emit_feature_err(cx.span_handler, name, span, GateIssue::Language, explain); emit_feature_err(cx.parse_sess, name, span, GateIssue::Language, explain);
} }
}} }}
} }
@ -756,10 +755,10 @@ impl<'a> Context<'a> {
} }
} }
pub fn check_attribute(attr: &ast::Attribute, handler: &Handler, pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess,
cm: &CodeMap, features: &Features) { cm: &CodeMap, features: &Features) {
let cx = Context { let cx = Context {
features: features, span_handler: handler, features: features, parse_sess: parse_sess,
cm: cm, plugin_attributes: &[] cm: cm, plugin_attributes: &[]
}; };
cx.check_attribute(attr, true); cx.check_attribute(attr, true);
@ -788,8 +787,10 @@ pub enum GateIssue {
Library(Option<u32>) Library(Option<u32>)
} }
pub fn emit_feature_err(diag: &Handler, feature: &str, span: Span, issue: GateIssue, pub fn emit_feature_err(sess: &ParseSess, feature: &str, span: Span, issue: GateIssue,
explain: &str) { explain: &str) {
let diag = &sess.span_diagnostic;
let issue = match issue { let issue = match issue {
GateIssue::Language => find_lang_feature_issue(feature), GateIssue::Language => find_lang_feature_issue(feature),
GateIssue::Library(lib) => lib, GateIssue::Library(lib) => lib,
@ -962,9 +963,10 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
if attr::contains_name(&i.attrs[..], "simd") { if attr::contains_name(&i.attrs[..], "simd") {
gate_feature_post!(&self, simd, i.span, gate_feature_post!(&self, simd, i.span,
"SIMD types are experimental and possibly buggy"); "SIMD types are experimental and possibly buggy");
self.context.span_handler.span_warn(i.span, self.context.parse_sess.span_diagnostic.span_warn(i.span,
"the `#[simd]` attribute is deprecated, \ "the `#[simd]` attribute \
use `#[repr(simd)]` instead"); is deprecated, use \
`#[repr(simd)]` instead");
} }
for attr in &i.attrs { for attr in &i.attrs {
if attr.name() == "repr" { if attr.name() == "repr" {
@ -1273,7 +1275,7 @@ pub fn check_crate(krate: &ast::Crate,
maybe_stage_features(&sess.span_diagnostic, krate, unstable); maybe_stage_features(&sess.span_diagnostic, krate, unstable);
let ctx = Context { let ctx = Context {
features: features, features: features,
span_handler: &sess.span_diagnostic, parse_sess: sess,
cm: sess.codemap(), cm: sess.codemap(),
plugin_attributes: plugin_attributes, plugin_attributes: plugin_attributes,
}; };

View file

@ -53,7 +53,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<base::MacResult + 'cx> { -> Box<base::MacResult + 'cx> {
if !cx.ecfg.enable_asm() { if !cx.ecfg.enable_asm() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, feature_gate::emit_feature_err(&cx.parse_sess,
"asm", "asm",
sp, sp,
feature_gate::GateIssue::Language, feature_gate::GateIssue::Language,

View file

@ -23,7 +23,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
tts: &[TokenTree]) tts: &[TokenTree])
-> Box<base::MacResult + 'cx> { -> Box<base::MacResult + 'cx> {
if !cx.ecfg.enable_concat_idents() { if !cx.ecfg.enable_concat_idents() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, feature_gate::emit_feature_err(&cx.parse_sess,
"concat_idents", "concat_idents",
sp, sp,
feature_gate::GateIssue::Language, feature_gate::GateIssue::Language,

View file

@ -221,7 +221,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
// the old custom derive mechanism. If the feature isn't enabled, we // the old custom derive mechanism. If the feature isn't enabled, we
// issue an error, otherwise manufacture the `derive_Foo` attribute. // issue an error, otherwise manufacture the `derive_Foo` attribute.
} else if !cx.ecfg.enable_custom_derive() { } else if !cx.ecfg.enable_custom_derive() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, feature_gate::emit_feature_err(&cx.parse_sess,
"custom_derive", "custom_derive",
titem.span, titem.span,
feature_gate::GateIssue::Language, feature_gate::GateIssue::Language,

View file

@ -19,7 +19,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<base::MacResult + 'cx> { -> Box<base::MacResult + 'cx> {
if !cx.ecfg.enable_log_syntax() { if !cx.ecfg.enable_log_syntax() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, feature_gate::emit_feature_err(&cx.parse_sess,
"log_syntax", "log_syntax",
sp, sp,
feature_gate::GateIssue::Language, feature_gate::GateIssue::Language,

View file

@ -20,7 +20,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
tt: &[TokenTree]) tt: &[TokenTree])
-> Box<base::MacResult + 'static> { -> Box<base::MacResult + 'static> {
if !cx.ecfg.enable_trace_macros() { if !cx.ecfg.enable_trace_macros() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, feature_gate::emit_feature_err(&cx.parse_sess,
"trace_macros", "trace_macros",
sp, sp,
feature_gate::GateIssue::Language, feature_gate::GateIssue::Language,