}
);
- // Needs to go *after* expansion to be able to check the results of macro expansion.
- time(time_passes, "complete gated feature checking", (), |_| {
+ // Needs to go *after* expansion to be able to check the results
+ // of macro expansion. This runs before #[cfg] to try to catch as
+ // much as possible (e.g. help the programmer avoid platform
+ // specific differences)
+ time(time_passes, "complete gated feature checking 1", (), |_| {
let features =
syntax::feature_gate::check_crate(sess.codemap(),
- &sess.parse_sess.span_diagnostic,
- &krate);
+ &sess.parse_sess.span_diagnostic,
+ &krate,
+ true);
*sess.features.borrow_mut() = features;
sess.abort_if_errors();
});
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));
+ // One final feature gating of the true AST that gets compiled
+ // later, to make sure we've got everything (e.g. configuration
+ // can insert new attributes via `cfg_attr`)
+ time(time_passes, "complete gated feature checking 2", (), |_| {
+ let features =
+ syntax::feature_gate::check_crate(sess.codemap(),
+ &sess.parse_sess.span_diagnostic,
+ &krate,
+ false);
+ *sess.features.borrow_mut() = features;
+ sess.abort_if_errors();
+ });
+
Some(krate)
}
features: Vec<&'static str>,
span_handler: &'a SpanHandler,
cm: &'a CodeMap,
+ do_warnings: bool,
}
impl<'a> Context<'a> {
}
fn warn_feature(&self, feature: &str, span: Span, explain: &str) {
- if !self.has_feature(feature) {
+ if !self.has_feature(feature) && self.do_warnings {
emit_feature_warn(self.span_handler, feature, span, explain);
}
}
}
fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate,
+ do_warnings: bool,
check: F)
-> Features
where F: FnOnce(&mut Context, &ast::Crate)
let mut cx = Context {
features: Vec::new(),
span_handler: span_handler,
+ do_warnings: do_warnings,
cm: cm,
};
pub fn check_crate_macros(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate)
-> Features {
- check_crate_inner(cm, span_handler, krate,
+ check_crate_inner(cm, span_handler, krate, true,
|ctx, krate| visit::walk_crate(&mut MacroVisitor { context: ctx }, krate))
}
-pub fn check_crate(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate)
--> Features {
- check_crate_inner(cm, span_handler, krate,
+pub fn check_crate(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate,
+ do_warnings: bool) -> Features
+{
+ check_crate_inner(cm, span_handler, krate, do_warnings,
|ctx, krate| visit::walk_crate(&mut PostExpansionVisitor { context: ctx },
krate))
}
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+macro_rules! foo {
+ () => {
+ #[cfg_attr(all(), unknown)] //~ ERROR `unknown` is currently unknown
+ fn foo() {}
+ }
+}
+
+foo!();
+
+fn main() {}