diff options
| author | bors <bors@rust-lang.org> | 2017-08-22 11:15:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-22 11:15:10 +0000 |
| commit | 1177911790def5b20f2e4bdfa8bd59df0a51f4e7 (patch) | |
| tree | 98d605deb5c901a8fd27f8ffbba93b8b497ff0b3 | |
| parent | 7e5578da8c76fafcb1d7ca9f0643127da76f0879 (diff) | |
| parent | 472e7e3ee22993d7dd64bdba21304334e0e977c9 (diff) | |
| download | rust-1177911790def5b20f2e4bdfa8bd59df0a51f4e7.tar.gz rust-1177911790def5b20f2e4bdfa8bd59df0a51f4e7.zip | |
Auto merge of #44008 - RalfJung:staged1, r=alexcrichton
Make sure crates not opting in to staged_api don't use staged_api This also fixes the problem that with `-Zforce-unstable-if-unmarked` set, crates could not use `#[deprecated]`. If you prefer, I can instead submit another version which just fixes this problem, but still allows the staged API attributes for all crates when `-Zforce-unstable-if-unmarked` is set. I have prepared that at <https://github.com/RalfJung/rust/tree/staged2>. As yet another alternative, @alexcrichton suggested to turn this error into a lint, but that seems to be much more work, so is it worth it? Cc @alexcrichton #43975
| -rw-r--r-- | src/librustc/middle/stability.rs | 12 | ||||
| -rw-r--r-- | src/librustc_plugin/lib.rs | 1 | ||||
| -rw-r--r-- | src/libtest/lib.rs | 1 | ||||
| -rw-r--r-- | src/test/compile-fail/stability-attribute-non-staged-force-unstable.rs | 16 | ||||
| -rw-r--r-- | src/test/run-pass/deprecation-in-force-unstable.rs | 14 |
5 files changed, 43 insertions, 1 deletions
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 5158c7e94af..d2ed29a3a0f 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -123,7 +123,8 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { item_sp: Span, kind: AnnotationKind, visit_children: F) where F: FnOnce(&mut Self) { - if self.index.staged_api[&LOCAL_CRATE] { + if self.tcx.sess.features.borrow().staged_api { + // This crate explicitly wants staged API. debug!("annotate(id = {:?}, attrs = {:?})", id, attrs); if let Some(..) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) { self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged api, \ @@ -204,6 +205,15 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } } + // Propagate unstability. This can happen even for non-staged-api crates in case + // -Zforce-unstable-if-unmarked is set. + if let Some(stab) = self.parent_stab { + if stab.level.is_unstable() { + let def_id = self.tcx.hir.local_def_id(id); + self.index.stab_map.insert(def_id, Some(stab)); + } + } + if let Some(depr) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) { if kind == AnnotationKind::Prohibited { self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless"); diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index 1020cec9a86..602b71dca05 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -69,6 +69,7 @@ #![deny(warnings)] #![feature(rustc_diagnostic_macros)] +#![feature(staged_api)] #[macro_use] extern crate syntax; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 5451ec24aa8..5e34688f8cb 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -37,6 +37,7 @@ #![feature(libc)] #![feature(set_stdio)] #![feature(panic_unwind)] +#![feature(staged_api)] extern crate getopts; extern crate term; diff --git a/src/test/compile-fail/stability-attribute-non-staged-force-unstable.rs b/src/test/compile-fail/stability-attribute-non-staged-force-unstable.rs new file mode 100644 index 00000000000..512fb24a0c2 --- /dev/null +++ b/src/test/compile-fail/stability-attribute-non-staged-force-unstable.rs @@ -0,0 +1,16 @@ +// 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. + +// compile-flags:-Zforce-unstable-if-unmarked + +#[unstable] //~ ERROR: stability attributes may not be used +#[stable] //~ ERROR: stability attributes may not be used +#[rustc_deprecated] //~ ERROR: stability attributes may not be used +fn main() { } diff --git a/src/test/run-pass/deprecation-in-force-unstable.rs b/src/test/run-pass/deprecation-in-force-unstable.rs new file mode 100644 index 00000000000..542117eca12 --- /dev/null +++ b/src/test/run-pass/deprecation-in-force-unstable.rs @@ -0,0 +1,14 @@ +// 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. + +// compile-flags:-Zforce-unstable-if-unmarked + +#[deprecated] // should work even with -Zforce-unstable-if-unmarked +fn main() { } |
