diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 2c768db47f1..ccab4279232 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -411,8 +411,8 @@ fn check(&mut self, id: DefId, span: Span, &feature, &r), None => format!("use of unstable library feature '{}'", &feature) }; - emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic, - &feature, span, GateIssue::Library(Some(issue)), &msg); + emit_feature_err(&self.tcx.sess.parse_sess, &feature, span, + GateIssue::Library(Some(issue)), &msg); } } Some(&Stability { ref level, ref feature, .. }) => { diff --git a/src/librustc_passes/static_recursion.rs b/src/librustc_passes/static_recursion.rs index 0ab8e2d7fcd..0336c3063d8 100644 --- a/src/librustc_passes/static_recursion.rs +++ b/src/librustc_passes/static_recursion.rs @@ -143,7 +143,7 @@ fn with_item_id_pushed(&mut self, id: ast::NodeId, f: F, span: Span) }); if any_static { 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", *self.root_span, GateIssue::Language, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index cbdce3229c7..f5e289c3302 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -795,7 +795,7 @@ fn create_substs_for_ast_trait_ref(&self, // For now, require that parenthetical notation be used // only with `Fn()` etc. 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, "\ the precise format of `Fn`-family traits' \ @@ -807,7 +807,7 @@ fn create_substs_for_ast_trait_ref(&self, // For now, require that parenthetical notation be used // only with `Fn()` etc. 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, "\ parenthetical notation is only stable when used with `Fn`-family traits"); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e406807b51c..47f545a6726 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3256,7 +3256,7 @@ pub fn check_struct_path(&self, if let Some((def_id, variant)) = variant { if variant.kind == ty::VariantKind::Tuple && !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, "tuple structs and variants in struct patterns are unstable"); } diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index abbbbe1e3d1..78d047c7651 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -157,7 +157,7 @@ fn visit_stmt_or_expr_attrs(&mut self, attrs: &[ast::Attribute]) { // flag the offending attributes for attr in attrs.iter() { 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", attr.span, GateIssue::Language, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 7359c21eccc..43c62218963 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -344,7 +344,7 @@ fn expand_bang_invoc(&mut self, invoc: Invocation, ext: Rc) -> // Detect use of feature-gated or invalid attributes on macro invoations // since they will not be detected after macro expansion. 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.ecfg.features.unwrap()); } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 75cfa587ab1..f8eb4508b16 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -679,16 +679,15 @@ pub fn gate(cfg: &ast::MetaItem) -> Option { pub fn check_and_emit(&self, sess: &ParseSess, features: &Features) { let (cfg, feature, has_feature) = GATED_CFGS[self.index]; 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); - emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain); + emit_feature_err(sess, feature, self.span, GateIssue::Language, &explain); } } } struct Context<'a> { features: &'a Features, - span_handler: &'a Handler, + parse_sess: &'a ParseSess, cm: &'a CodeMap, plugin_attributes: &'a [(String, AttributeType)], } @@ -699,7 +698,7 @@ macro_rules! gate_feature_fn { let has_feature: bool = has_feature(&$cx.features); debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature); 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 @@ fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) { } } -pub fn check_attribute(attr: &ast::Attribute, handler: &Handler, +pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, cm: &CodeMap, features: &Features) { let cx = Context { - features: features, span_handler: handler, + features: features, parse_sess: parse_sess, cm: cm, plugin_attributes: &[] }; cx.check_attribute(attr, true); @@ -788,8 +787,10 @@ pub enum GateIssue { Library(Option) } -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) { + let diag = &sess.span_diagnostic; + let issue = match issue { GateIssue::Language => find_lang_feature_issue(feature), GateIssue::Library(lib) => lib, @@ -962,9 +963,10 @@ fn visit_item(&mut self, i: &ast::Item) { if attr::contains_name(&i.attrs[..], "simd") { gate_feature_post!(&self, simd, i.span, "SIMD types are experimental and possibly buggy"); - self.context.span_handler.span_warn(i.span, - "the `#[simd]` attribute is deprecated, \ - use `#[repr(simd)]` instead"); + self.context.parse_sess.span_diagnostic.span_warn(i.span, + "the `#[simd]` attribute \ + is deprecated, use \ + `#[repr(simd)]` instead"); } for attr in &i.attrs { if attr.name() == "repr" { @@ -1273,7 +1275,7 @@ pub fn check_crate(krate: &ast::Crate, maybe_stage_features(&sess.span_diagnostic, krate, unstable); let ctx = Context { features: features, - span_handler: &sess.span_diagnostic, + parse_sess: sess, cm: sess.codemap(), plugin_attributes: plugin_attributes, }; diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 77425b809de..cc4fb604d6c 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -53,7 +53,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, tts: &[tokenstream::TokenTree]) -> Box { if !cx.ecfg.enable_asm() { - feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, + feature_gate::emit_feature_err(&cx.parse_sess, "asm", sp, feature_gate::GateIssue::Language, diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 15aaf3c7823..e56c6e2229a 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -23,7 +23,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, tts: &[TokenTree]) -> Box { 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", sp, feature_gate::GateIssue::Language, diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index c3c2f7eabb9..e3a38d568d3 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -221,7 +221,7 @@ pub fn expand_derive(cx: &mut ExtCtxt, // the old custom derive mechanism. If the feature isn't enabled, we // issue an error, otherwise manufacture the `derive_Foo` attribute. } 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", titem.span, feature_gate::GateIssue::Language, diff --git a/src/libsyntax_ext/log_syntax.rs b/src/libsyntax_ext/log_syntax.rs index 7242b9865a9..71f1951d5d4 100644 --- a/src/libsyntax_ext/log_syntax.rs +++ b/src/libsyntax_ext/log_syntax.rs @@ -19,7 +19,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, tts: &[tokenstream::TokenTree]) -> Box { 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", sp, feature_gate::GateIssue::Language, diff --git a/src/libsyntax_ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs index 794169ae342..9578af68100 100644 --- a/src/libsyntax_ext/trace_macros.rs +++ b/src/libsyntax_ext/trace_macros.rs @@ -20,7 +20,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, tt: &[TokenTree]) -> Box { 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", sp, feature_gate::GateIssue::Language,