]> git.lizzy.rs Git - rust.git/commitdiff
Preliminary feature staging
authorBrian Anderson <banderson@mozilla.com>
Tue, 6 Jan 2015 14:26:08 +0000 (06:26 -0800)
committerBrian Anderson <banderson@mozilla.com>
Wed, 7 Jan 2015 23:34:56 +0000 (15:34 -0800)
This partially implements the feature staging described in the
[release channel RFC][rc]. It does not yet fully conform to the RFC as
written, but does accomplish its goals sufficiently for the 1.0 alpha
release.

It has three primary user-visible effects:

* On the nightly channel, use of unstable APIs generates a warning.
* On the beta channel, use of unstable APIs generates a warning.
* On the beta channel, use of feature gates generates a warning.

Code that does not trigger these warnings is considered 'stable',
modulo pre-1.0 bugs.

Disabling the warnings for unstable APIs continues to be done in the
existing (i.e. old) style, via `#[allow(...)]`, not that specified in
the RFC. I deem this marginally acceptable since any code that must do
this is not using the stable dialect of Rust.

Use of feature gates is itself gated with the new 'unstable_features'
lint, on nightly set to 'allow', and on beta 'warn'.

The attribute scheme used here corresponds to an older version of the
RFC, with the `#[staged_api]` crate attribute toggling the staging
behavior of the stability attributes, but the user impact is only
in-tree so I'm not concerned about having to make design changes later
(and I may ultimately prefer the scheme here after all, with the
`#[staged_api]` crate attribute).

Since the Rust codebase itself makes use of unstable features the
compiler and build system to a midly elaborate dance to allow it to
bootstrap while disobeying these lints (which would otherwise be
errors because Rust builds with `-D warnings`).

This patch includes one significant hack that causes a
regression. Because the `format_args!` macro emits calls to unstable
APIs it would trigger the lint.  I added a hack to the lint to make it
not trigger, but this in turn causes arguments to `println!` not to be
checked for feature gates. I don't presently understand macro
expansion well enough to fix. This is bug #20661.

Closes #16678

[rc]: https://github.com/rust-lang/rfcs/blob/master/text/0507-release-channels.md

43 files changed:
configure
mk/main.mk
src/liballoc/lib.rs
src/libarena/lib.rs
src/libcollections/lib.rs
src/libcore/lib.rs
src/libflate/lib.rs
src/libfmt_macros/lib.rs
src/libgetopts/lib.rs
src/libgraphviz/lib.rs
src/liblibc/lib.rs
src/liblog/lib.rs
src/librand/lib.rs
src/librbml/lib.rs
src/libregex/lib.rs
src/librustc/lib.rs
src/librustc/lint/builtin.rs
src/librustc/lint/context.rs
src/librustc/lint/mod.rs
src/librustc/metadata/csearch.rs
src/librustc/middle/stability.rs
src/librustc/session/config.rs
src/librustc_back/lib.rs
src/librustc_borrowck/lib.rs
src/librustc_driver/lib.rs
src/librustc_llvm/lib.rs
src/librustc_resolve/lib.rs
src/librustc_trans/lib.rs
src/librustc_typeck/lib.rs
src/librustdoc/core.rs
src/librustdoc/lib.rs
src/librustdoc/test.rs
src/libserialize/lib.rs
src/libstd/lib.rs
src/libsyntax/codemap.rs
src/libsyntax/lib.rs
src/libsyntax/std_inject.rs
src/libterm/lib.rs
src/libtest/lib.rs
src/libunicode/lib.rs
src/test/compile-fail/feature-gate-feature-gate.rs [new file with mode: 0644]
src/test/compile-fail/feature-gated-feature-in-macro-arg.rs
src/test/pretty/issue-4264.pp

index ea9320c901b6df97daa2ba947aa1fb58da5ed604..61c737e0fd3afcca25d862fd1d1ac788ca71218a 100755 (executable)
--- a/configure
+++ b/configure
@@ -599,6 +599,18 @@ then
 fi
 putvar CFG_RELEASE_CHANNEL
 
+# A magic value that allows the compiler to use unstable features
+# during the bootstrap even when doing so would normally be an error
+# because of feature staging or because the build turns on
+# warnings-as-errors and unstable features default to warnings.  The
+# build has to match this key in an env var. Meant to be a mild
+# deterrent from users just turning on unstable features on the stable
+# channel.
+# Basing CFG_BOOTSTRAP_KEY on CFG_BOOTSTRAP_KEY lets it get picked up
+# during a Makefile reconfig.
+CFG_BOOTSTRAP_KEY="${CFG_BOOTSTRAP_KEY-`date +%N`}"
+putvar CFG_BOOTSTRAP_KEY
+
 step_msg "looking for build programs"
 
 probe_need CFG_PERL        perl
index a97e68af59b3808062dd5f8fa09b2ea0a1e6358c..e892286f7fd3e1d7a753e4ff75f7011eec4b83c2 100644 (file)
@@ -25,11 +25,13 @@ ifeq ($(CFG_RELEASE_CHANNEL),stable)
 CFG_RELEASE=$(CFG_RELEASE_NUM)
 # This is the string used in dist artifact file names, e.g. "0.12.0", "nightly"
 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
+CFG_DISABLE_UNSTABLE_FEATURES=1
 endif
 ifeq ($(CFG_RELEASE_CHANNEL),beta)
 # The beta channel is temporarily called 'alpha'
 CFG_RELEASE=$(CFG_RELEASE_NUM)-alpha$(CFG_BETA_CYCLE)
 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-alpha$(CFG_BETA_CYCLE)
+CFG_DISABLE_UNSTABLE_FEATURES=1
 endif
 ifeq ($(CFG_RELEASE_CHANNEL),nightly)
 CFG_RELEASE=$(CFG_RELEASE_NUM)-nightly
@@ -319,11 +321,20 @@ export CFG_VERSION_WIN
 export CFG_RELEASE
 export CFG_PACKAGE_NAME
 export CFG_BUILD
+export CFG_RELEASE_CHANNEL
 export CFG_LLVM_ROOT
 export CFG_PREFIX
 export CFG_LIBDIR
 export CFG_LIBDIR_RELATIVE
 export CFG_DISABLE_INJECT_STD_VERSION
+ifdef CFG_DISABLE_UNSTABLE_FEATURES
+CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATURES))
+# Turn on feature-staging
+export CFG_DISABLE_UNSTABLE_FEATURES
+endif
+# Subvert unstable feature lints to do the self-build
+export CFG_BOOTSTRAP_KEY
+export RUSTC_BOOTSTRAP_KEY:=$(CFG_BOOTSTRAP_KEY)
 
 ######################################################################
 # Per-stage targets and runner
index ba6e89cdd768e5016ec408f43c7206e00fa41876..a5153f64aecfb5d99869f8df490a89730ac439f6 100644 (file)
@@ -58,6 +58,7 @@
 
 #![crate_name = "alloc"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
index 423c16bfee8e8f376c106e6cbe23acbb80d2227f..79e43b9cc64d8dacbfb0cd211a0f350dc129286a 100644 (file)
@@ -21,6 +21,7 @@
 
 #![crate_name = "arena"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 6eab36d8844df9372b9e55c567500c007d912bf3..0cf5170b1b69ad774e772190b2426d4f671cbef2 100644 (file)
@@ -15,6 +15,7 @@
 
 #![crate_name = "collections"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
index a7e3b61b0d42bd6ac7be7c94e90af53a216265d0..95b3e59c2c37e562900a3575001d1fb329ab6ee0 100644 (file)
@@ -49,6 +49,7 @@
 
 #![crate_name = "core"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
index f38440d86c6e855a4f171443d9397469adb9d1b3..1896bdd182ae01e3b586ddd10bd495e2a5943d0b 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "flate"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 47cc072a636a147fe81e5b69b537bd28da6cca21..a703bfbb8fe2ad111b5fb059b12003c5c1f3be5c 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "fmt_macros"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index f50e24c6354f184ea6a344be5abe6361c8125482..0dd6a430a88defde895609aa0c18b1299c69f514 100644 (file)
@@ -79,6 +79,7 @@
 
 #![crate_name = "getopts"]
 #![experimental = "use the crates.io `getopts` library instead"]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 83bad70e7b117b05f67ff3a4157e2d21279713be..21a8ba03454f53defd8c5afa85ea41274504de95 100644 (file)
 
 #![crate_name = "graphviz"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 347a958076dff36706f82b14ddd57a45c0e74346..32e635e445d798e81dd8e95907a6845c0a023415 100644 (file)
@@ -11,6 +11,7 @@
 #![crate_name = "libc"]
 #![crate_type = "rlib"]
 #![cfg_attr(not(feature = "cargo-build"), experimental)]
+#![cfg_attr(not(feature = "cargo-build"), staged_api)]
 #![no_std]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
index 08b01e956e1ac83c073524226f8ca2ef5200d41d..6bfbbb99fc7f33347ec77801bcc1e23f62236d48 100644 (file)
 
 #![crate_name = "log"]
 #![experimental = "use the crates.io `log` library instead"]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index ad2a4dbec4e923b98ac91786b1c310cf6d3c941b..3dd0a1e32dfa75880ec7fe5fd3ff805e14f2cdd1 100644 (file)
@@ -25,6 +25,7 @@
 
 #![no_std]
 #![experimental]
+#![staged_api]
 
 #[macro_use]
 extern crate core;
index a66d1dd08c1eb6aac528aa7723cde4a25d46e884..66f4f2321fd4f2254915e3340a7e0565a5d008cb 100644 (file)
@@ -17,6 +17,7 @@
 
 #![crate_name = "rbml"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index c039abc9aff2a8955134bfbcd8181f2a46b85ae9..bd376528a0e5148129ef4134c086af8b2789ef79 100644 (file)
@@ -17,6 +17,7 @@
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![experimental = "use the crates.io `regex` library instead"]
+#![staged_api]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
        html_root_url = "http://doc.rust-lang.org/nightly/",
index a3a041c2497c7a9fed075053374a2127f9e6929a..5525874a614500e7f605b0f92fa52e82074d68ea 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "rustc"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 1af8e2f29ebd7c63faf25b93bc15f9a54bb92dd4..9d7e833e711da7a79c73f70210e0340116f0cb38 100644 (file)
@@ -34,7 +34,7 @@
 use middle::const_eval::{eval_const_expr_partial, const_int, const_uint};
 use util::ppaux::{ty_to_string};
 use util::nodemap::{FnvHashMap, NodeSet};
-use lint::{Context, LintPass, LintArray};
+use lint::{Context, LintPass, LintArray, Lint};
 
 use std::collections::hash_map::Entry::{Occupied, Vacant};
 use std::num::SignedInt;
@@ -1643,6 +1643,13 @@ fn check_item(&mut self, cx: &Context, item: &ast::Item) {
     "detects use of #[unstable] items (incl. items with no stability attribute)"
 }
 
+declare_lint!(STAGED_EXPERIMENTAL, Warn,
+              "detects use of #[experimental] items in staged builds");
+
+declare_lint!(STAGED_UNSTABLE, Warn,
+              "detects use of #[unstable] items (incl. items with no stability attribute) \
+               in staged builds");
+
 /// Checks for use of items with `#[deprecated]`, `#[experimental]` and
 /// `#[unstable]` attributes, or no stability attribute.
 #[derive(Copy)]
@@ -1650,12 +1657,13 @@ fn check_item(&mut self, cx: &Context, item: &ast::Item) {
 
 impl Stability {
     fn lint(&self, cx: &Context, id: ast::DefId, span: Span) {
-        let stability = stability::lookup(cx.tcx, id);
+
+        let ref stability = stability::lookup(cx.tcx, id);
         let cross_crate = !ast_util::is_local(id);
 
         // stability attributes are promises made across crates; only
         // check DEPRECATED for crate-local usage.
-        let (lint, label) = match stability {
+        let (lint, label) = match *stability {
             // no stability attributes == Unstable
             None if cross_crate => (UNSTABLE, "unmarked"),
             Some(attr::Stability { level: attr::Unstable, .. }) if cross_crate =>
@@ -1667,24 +1675,53 @@ fn lint(&self, cx: &Context, id: ast::DefId, span: Span) {
             _ => return
         };
 
-        let msg = match stability {
-            Some(attr::Stability { text: Some(ref s), .. }) => {
-                format!("use of {} item: {}", label, *s)
+        output(cx, span, stability, lint, label);
+        if cross_crate && stability::is_staged_api(cx.tcx, id) {
+            if lint.name == UNSTABLE.name {
+                output(cx, span, stability, STAGED_UNSTABLE, label);
+            } else if lint.name == EXPERIMENTAL.name {
+                output(cx, span, stability, STAGED_EXPERIMENTAL, label);
             }
-            _ => format!("use of {} item", label)
-        };
+        }
 
-        cx.span_lint(lint, span, msg.index(&FullRange));
+        fn output(cx: &Context, span: Span, stability: &Option<attr::Stability>,
+                  lint: &'static Lint, label: &'static str) {
+            let msg = match *stability {
+                Some(attr::Stability { text: Some(ref s), .. }) => {
+                    format!("use of {} item: {}", label, *s)
+                }
+                _ => format!("use of {} item", label)
+            };
+
+            cx.span_lint(lint, span, msg.index(&FullRange));
+        }
     }
 
+
     fn is_internal(&self, cx: &Context, span: Span) -> bool {
         cx.tcx.sess.codemap().span_is_internal(span)
     }
+
 }
 
 impl LintPass for Stability {
     fn get_lints(&self) -> LintArray {
-        lint_array!(DEPRECATED, EXPERIMENTAL, UNSTABLE)
+        lint_array!(DEPRECATED, EXPERIMENTAL, UNSTABLE, STAGED_EXPERIMENTAL, STAGED_UNSTABLE)
+    }
+
+    fn check_crate(&mut self, _: &Context, c: &ast::Crate) {
+        // Just mark the #[staged_api] attribute used, though nothing else is done
+        // with it during this pass over the source.
+        for attr in c.attrs.iter() {
+            if attr.name().get() == "staged_api" {
+                match attr.node.value.node {
+                    ast::MetaWord(_) => {
+                        attr::mark_used(attr);
+                    }
+                    _ => (/*pass*/)
+                }
+            }
+        }
     }
 
     fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
@@ -1746,6 +1783,7 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
             }
             _ => return
         };
+
         self.lint(cx, id, span);
     }
 
@@ -1878,3 +1916,22 @@ fn get_lints(&self) -> LintArray {
         )
     }
 }
+
+/// Forbids using the `#[feature(...)]` attribute
+#[deriving(Copy)]
+pub struct UnstableFeatures;
+
+declare_lint!(UNSTABLE_FEATURES, Allow,
+              "enabling unstable features");
+
+impl LintPass for UnstableFeatures {
+    fn get_lints(&self) -> LintArray {
+        lint_array!(UNSTABLE_FEATURES)
+    }
+    fn check_attribute(&mut self, ctx: &Context, attr: &ast::Attribute) {
+        use syntax::attr;
+        if attr::contains_name(&[attr.node.value.clone()], "feature") {
+            ctx.span_lint(UNSTABLE_FEATURES, attr.span, "unstable feature");
+        }
+    }
+}
index 51998bdbcf299dda29f9bcf011b4c3b051af0d67..7d58b04a7f4903095f6af32b1165f2693afd529a 100644 (file)
@@ -28,8 +28,9 @@
 use middle::privacy::ExportedItems;
 use middle::ty::{self, Ty};
 use session::{early_error, Session};
+use session::config::UnstableFeatures;
 use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
-use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
+use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid, ReleaseChannel};
 use lint::builtin;
 use util::nodemap::FnvHashMap;
 
@@ -210,6 +211,7 @@ macro_rules! add_lint_group {
                      UnusedAllocation,
                      Stability,
                      MissingCopyImplementations,
+                     UnstableFeatures,
         );
 
         add_builtin_with_new!(sess,
@@ -298,6 +300,29 @@ pub fn process_command_line(&mut self, sess: &Session) {
             }
         }
     }
+
+    fn maybe_stage_features(&mut self, sess: &Session) {
+        let lvl = match sess.opts.unstable_features {
+            UnstableFeatures::Default => return,
+            UnstableFeatures::Disallow => Warn,
+            UnstableFeatures::Cheat => Allow
+        };
+        match self.by_name.get("unstable_features") {
+            Some(&Id(lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)),
+            Some(&Renamed(_, lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)),
+            None => unreachable!()
+        }
+        match self.by_name.get("staged_unstable") {
+            Some(&Id(lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)),
+            Some(&Renamed(_, lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)),
+            None => unreachable!()
+        }
+        match self.by_name.get("staged_experimental") {
+            Some(&Id(lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)),
+            Some(&Renamed(_, lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)),
+            None => unreachable!()
+        }
+    }
 }
 
 /// Context for lint checking.
@@ -380,6 +405,7 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
     if level == Allow { return }
 
     let name = lint.name_lower();
+    let mut def = None;
     let mut note = None;
     let msg = match source {
         Default => {
@@ -394,7 +420,13 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
                     }, name.replace("_", "-"))
         },
         Node(src) => {
-            note = Some(src);
+            def = Some(src);
+            msg.to_string()
+        }
+        ReleaseChannel => {
+            let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)");
+            note = Some(format!("this feature may not be used in the {} release channel",
+                                release_channel));
             msg.to_string()
         }
     };
@@ -410,7 +442,11 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
         _ => sess.bug("impossible level in raw_emit_lint"),
     }
 
-    for span in note.into_iter() {
+    for note in note.into_iter() {
+        sess.note(note.index(&FullRange));
+    }
+
+    for span in def.into_iter() {
         sess.span_note(span, "lint level defined here");
     }
 }
@@ -767,6 +803,10 @@ fn check_item(&mut self, cx: &Context, it: &ast::Item) {
 /// Consumes the `lint_store` field of the `Session`.
 pub fn check_crate(tcx: &ty::ctxt,
                    exported_items: &ExportedItems) {
+
+    // If this is a feature-staged build of rustc then flip several lints to 'forbid'
+    tcx.sess.lint_store.borrow_mut().maybe_stage_features(&tcx.sess);
+
     let krate = tcx.map.krate();
     let mut cx = Context::new(tcx, krate, exported_items);
 
index e9778fa05ff1787f419d717d979591d8816a69ef..31cde1cb8a10aa69e75231f77c8671abd891f0cf 100644 (file)
@@ -248,6 +248,9 @@ pub enum LintSource {
 
     /// Lint level was set by a command-line flag.
     CommandLine,
+
+    /// Lint level was set by the release channel.
+    ReleaseChannel
 }
 
 pub type LevelSource = (Level, LintSource);
index 72ce61b133a2bad37f32d9f3296b26c6ddc018f8..39c7f80703d055a3a8b5a9bd4533fcf671c6e91a 100644 (file)
@@ -27,6 +27,7 @@
 use syntax::ast;
 use syntax::ast_map;
 use syntax::attr;
+use syntax::attr::AttrMetaMethods;
 use syntax::diagnostic::expect;
 use syntax::parse::token;
 
@@ -375,6 +376,18 @@ pub fn get_stability(cstore: &cstore::CStore,
     decoder::get_stability(&*cdata, def.node)
 }
 
+pub fn is_staged_api(cstore: &cstore::CStore, def: ast::DefId) -> bool {
+    let cdata = cstore.get_crate_data(def.krate);
+    let attrs = decoder::get_crate_attributes(cdata.data());
+    for attr in attrs.iter() {
+        if attr.name().get() == "staged_api" {
+            match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
+        }
+    }
+
+    return false;
+}
+
 pub fn get_repr_attrs(cstore: &cstore::CStore, def: ast::DefId)
                       -> Vec<attr::ReprAttr> {
     let cdata = cstore.get_crate_data(def.krate);
index 359ad8d394129c09b027f503c0201de8b6827928..e712f510d9dc825c63a5c96e2f2a803c5a81e70a 100644 (file)
@@ -189,3 +189,19 @@ pub fn lookup(tcx: &ty::ctxt, id: DefId) -> Option<Stability> {
         }
     })
 }
+
+pub fn is_staged_api(tcx: &ty::ctxt, id: DefId) -> bool {
+    match ty::trait_item_of_item(tcx, id) {
+        Some(ty::MethodTraitItemId(trait_method_id))
+            if trait_method_id != id => {
+                is_staged_api(tcx, trait_method_id)
+            }
+        _ if is_local(id) => {
+            // Unused case
+            unreachable!()
+        }
+        _ => {
+            csearch::is_staged_api(&tcx.sess.cstore, id)
+        }
+    }
+}
index 4968066f7b696b01ba5807cb4902746e3189dd95..ff0bc69c5bf20b6b724deeaca125cb3cde398f0a 100644 (file)
@@ -111,7 +111,24 @@ pub struct Options {
     /// An optional name to use as the crate for std during std injection,
     /// written `extern crate std = "name"`. Default to "std". Used by
     /// out-of-tree drivers.
-    pub alt_std_name: Option<String>
+    pub alt_std_name: Option<String>,
+    /// Indicates how the compiler should treat unstable features
+    pub unstable_features: UnstableFeatures
+}
+
+#[deriving(Clone, Copy)]
+pub enum UnstableFeatures {
+    /// Hard errors for unstable features are active, as on
+    /// beta/stable channels.
+    Disallow,
+    /// Use the default lint levels
+    Default,
+    /// Errors are bypassed for bootstrapping. This is required any time
+    /// during the build that feature-related lints are set to warn or above
+    /// because the build turns on warnings-as-errors and uses lots of unstable
+    /// features. As a result, this this is always required for building Rust
+    /// itself.
+    Cheat
 }
 
 #[derive(Clone, PartialEq, Eq)]
@@ -217,6 +234,7 @@ pub fn basic_options() -> Options {
         crate_name: None,
         alt_std_name: None,
         libs: Vec::new(),
+        unstable_features: UnstableFeatures::Disallow
     }
 }
 
@@ -1149,6 +1167,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
         crate_name: crate_name,
         alt_std_name: None,
         libs: libs,
+        unstable_features: UnstableFeatures::Disallow
     }
 }
 
index ca39477fbdcb2e9d700d5602f491d7a253108c13..5d863def32e812d9c03f92a858b3d98f9a818471 100644 (file)
@@ -23,6 +23,7 @@
 
 #![crate_name = "rustc_back"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 26bcd5f4c10cd3b82c702dd34fb13e7cb09a2f89..452eaaaa52dab7bb6e4b58f46403a25b5b51e347 100644 (file)
@@ -10,6 +10,7 @@
 
 #![crate_name = "rustc_borrowck"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 5af114abeea77ca85c7cdb7f6c7b79298d27a3d7..1c2d956e2797f08ecb86c5feecf04403ce605c07 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "rustc_driver"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@@ -46,7 +47,7 @@
 
 use rustc_trans::back::link;
 use rustc::session::{config, Session, build_session};
-use rustc::session::config::{Input, PrintRequest};
+use rustc::session::config::{Input, PrintRequest, UnstableFeatures};
 use rustc::lint::Lint;
 use rustc::lint;
 use rustc::metadata;
@@ -132,7 +133,11 @@ fn run_compiler(args: &[String]) {
         _ => early_error("multiple input filenames provided")
     };
 
+    let mut sopts = sopts;
+    sopts.unstable_features = get_unstable_features_setting();
+
     let mut sess = build_session(sopts, input_file_path, descriptions);
+
     let cfg = config::build_configuration(&sess);
     if print_crate_info(&sess, Some(&input), &odir, &ofile) {
         return
@@ -181,6 +186,21 @@ fn run_compiler(args: &[String]) {
     driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
 }
 
+pub fn get_unstable_features_setting() -> UnstableFeatures {
+    // Whether this is a feature-staged build, i.e. on the beta or stable channel
+    let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
+    // The secret key needed to get through the rustc build itself by
+    // subverting the unstable features lints
+    let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
+    // The matching key to the above, only known by the build system
+    let bootstrap_provided_key = os::getenv("RUSTC_BOOTSTRAP_KEY");
+    match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
+        (_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
+        (true, _, _) => UnstableFeatures::Disallow,
+        (false, _, _) => UnstableFeatures::Default
+    }
+}
+
 /// Returns a version string such as "0.12.0-dev".
 pub fn release_str() -> Option<&'static str> {
     option_env!("CFG_RELEASE")
index 0bed754aa3c1bf8cb351377baab05543ae2cb067..961d3a6cfa1ee8891aa93bc6288baf43c1dd0dc4 100644 (file)
@@ -15,6 +15,7 @@
 
 #![crate_name = "rustc_llvm"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 93ad69e03b17f1af3eb84dd1850b74a14e52a266..845db8aa5df9619eb0ea5848f59e476798670854 100644 (file)
@@ -10,6 +10,7 @@
 
 #![crate_name = "rustc_resolve"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index b6f90a4c2f52a9ac7420b588f9f3727051fb87eb..3497ff2221c19c42c289f21ef09146f3cef515e7 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "rustc_trans"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index ae8731dfa476b1e4e20ab0c101f6826906d25b97..85221c2e91315f58388f33470d8402fb651b7741 100644 (file)
@@ -65,6 +65,7 @@
 
 #![crate_name = "rustc_typeck"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 46c212a9f2dbcc4dab77ec64754ce8abf4d07925..4885bd373eb1dfd74e57fa43062be708ec013d0f 100644 (file)
@@ -11,6 +11,7 @@
 
 use rustc_driver::driver;
 use rustc::session::{self, config};
+use rustc::session::config::UnstableFeatures;
 use rustc::session::search_paths::SearchPaths;
 use rustc::middle::{privacy, ty};
 use rustc::lint;
@@ -95,10 +96,11 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
         externs: externs,
         target_triple: triple.unwrap_or(config::host_triple().to_string()),
         cfg: config::parse_cfgspecs(cfgs),
+        // Ensure that rustdoc works even if rustc is feature-staged
+        unstable_features: UnstableFeatures::Default,
         ..config::basic_options().clone()
     };
 
-
     let codemap = codemap::CodeMap::new();
     let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None);
     let span_diagnostic_handler =
index ee65ef0662305a7bf99a4a3cbd145400d8eea2f4..daa930fddcb8cde1df22da4898984cba562f020f 100644 (file)
@@ -10,6 +10,7 @@
 
 #![crate_name = "rustdoc"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index bbe35eb0e9ccc53e8b6c7fe1673ee088323941ec..8e0f4b2d4436486954a80901f54c89a9d46e0f26 100644 (file)
@@ -22,6 +22,7 @@
 use testing;
 use rustc::session::{self, config};
 use rustc::session::search_paths::{SearchPaths, PathKind};
+use rustc_driver::get_unstable_features_setting;
 use rustc_driver::driver;
 use syntax::ast;
 use syntax::codemap::{CodeMap, dummy_spanned};
@@ -52,6 +53,7 @@ pub fn run(input: &str,
         search_paths: libs.clone(),
         crate_types: vec!(config::CrateTypeDylib),
         externs: externs.clone(),
+        unstable_features: get_unstable_features_setting(),
         ..config::basic_options().clone()
     };
 
@@ -128,6 +130,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
             .. config::basic_codegen_options()
         },
         test: as_test_harness,
+        unstable_features: get_unstable_features_setting(),
         ..config::basic_options().clone()
     };
 
index 139170fc012cb59d869ab95f93cde444c84cd778..c45cb515f66283d7a17886521a5748d18019f054 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "serialize"]
 #![unstable = "deprecated in favor of rustc-serialize on crates.io"]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index eef5bdb60eeaae2fe7cc6f448c9739c8237b5165..3d782968a40afc45fc8d4ab629b2802a7afb56a2 100644 (file)
@@ -96,6 +96,7 @@
 
 #![crate_name = "std"]
 #![stable]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 31fe23847d9a8c412820ca399637f42c8d24d6a3..e4460ca865b84df3150387bc306b36ecd8146030 100644 (file)
@@ -590,7 +590,12 @@ pub fn span_is_internal(&self, span: Span) -> bool {
                 Some(ref info) => {
                     // save the parent expn_id for next loop iteration
                     expnid = info.call_site.expn_id;
-                    if info.callee.span.is_none() {
+                    if info.callee.name == "format_args" {
+                        // This is a hack because the format_args builtin calls unstable APIs.
+                        // I spent like 6 hours trying to solve this more generally but am stupid.
+                        is_internal = true;
+                        false
+                    } else if info.callee.span.is_none() {
                         // it's a compiler built-in, we *really* don't want to mess with it
                         // so we skip it, unless it was called by a regular macro, in which case
                         // we will handle the caller macro next turn
index 9e14f9dd1eaae3a0209539edd8e1df3ecb43c0fe..7c8ccf3a1a122ab751544963230765d2509bb39c 100644 (file)
@@ -16,6 +16,7 @@
 
 #![crate_name = "syntax"]
 #![experimental]
+#![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index daa51203287b3744b6b17dcb10c274f454f8e1e3..8e1a58602596b93253b2a7066afc4117b04b028f 100644 (file)
@@ -48,7 +48,7 @@ fn no_prelude(attrs: &[ast::Attribute]) -> bool {
 }
 
 struct StandardLibraryInjector<'a> {
-    alt_std_name: Option<String>,
+    alt_std_name: Option<String>
 }
 
 impl<'a> fold::Folder for StandardLibraryInjector<'a> {
@@ -84,14 +84,13 @@ fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
 
 fn inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>) -> ast::Crate {
     let mut fold = StandardLibraryInjector {
-        alt_std_name: alt_std_name,
+        alt_std_name: alt_std_name
     };
     fold.fold_crate(krate)
 }
 
 struct PreludeInjector<'a>;
 
-
 impl<'a> fold::Folder for PreludeInjector<'a> {
     fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
         // Add #![no_std] here, so we don't re-inject when compiling pretty-printed source.
@@ -104,20 +103,10 @@ fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
         attr::mark_used(&no_std_attr);
         krate.attrs.push(no_std_attr);
 
+        // only add `use std::prelude::*;` if there wasn't a
+        // `#![no_implicit_prelude]` at the crate level.
+        // fold_mod() will insert glob path.
         if !no_prelude(krate.attrs.index(&FullRange)) {
-            // only add `use std::prelude::*;` if there wasn't a
-            // `#![no_implicit_prelude]` at the crate level.
-            // fold_mod() will insert glob path.
-            let globs_attr = attr::mk_attr_inner(attr::mk_attr_id(),
-                                                 attr::mk_list_item(
-                InternedString::new("feature"),
-                vec!(
-                    attr::mk_word_item(InternedString::new("globs")),
-                )));
-            // std_inject runs after feature checking so manually mark this attr
-            attr::mark_used(&globs_attr);
-            krate.attrs.push(globs_attr);
-
             krate.module = self.fold_mod(krate.module);
         }
         krate
index c953f591d805864b8993fd75d8095b915772fca6..44ae00d997c5f70ae36e3e8544bd59a0308d7640 100644 (file)
@@ -40,6 +40,7 @@
 
 #![crate_name = "term"]
 #![experimental = "use the crates.io `term` library instead"]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index 68d06cc4dab6480ec62139050d0e7a39adc896b6..d21a73de6df5f26106bee23ac57dd4dc619642ad 100644 (file)
@@ -25,6 +25,7 @@
 
 #![crate_name = "test"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
index db98b429e40678bd4c140545cca1f3bca8e3fc6f..33b5bc4b5a432e7413e0bf106a0508a1cd850cbc 100644 (file)
@@ -22,6 +22,7 @@
 
 #![crate_name = "unicode"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
diff --git a/src/test/compile-fail/feature-gate-feature-gate.rs b/src/test/compile-fail/feature-gate-feature-gate.rs
new file mode 100644 (file)
index 0000000..b903b29
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2014 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.
+
+#![forbid(unstable_features)]
+#![feature(intrinsics)] //~ ERROR unstable feature
+
+fn main() { }
index cd49c7c016eeb88bd596cf8f4d3baa6b2d4466f4..1e15e67876ed44f140e63b877fae4e5158baba79 100644 (file)
@@ -8,6 +8,14 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// FIXME #20661: format_args! emits calls to the unstable std::fmt::rt
+// module, so the compiler has some hacks to make that possible
+// (in span_is_internal). Unnfortunately those hacks defeat this
+// particular scenario of checking feature gates in arguments to
+// println!().
+
+// ignore-test
+
 // tests that input to a macro is checked for use of gated features. If this
 // test succeeds due to the acceptance of a feature, pick a new feature to
 // test. Not ideal, but oh well :(
index f20087ef677f23a9efca115a008008513a8bb699..dac6e628d10d5421c10823aaba51cd715335de2e 100644 (file)
@@ -1,5 +1,4 @@
 #![no_std]
-#![feature(globs)]
 #[macro_use]
 extern crate "std" as std;
 #[prelude_import]