Skip to content

Commit 1177911

Browse files
committed
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
2 parents 7e5578d + 472e7e3 commit 1177911

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

src/librustc/middle/stability.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
123123
item_sp: Span, kind: AnnotationKind, visit_children: F)
124124
where F: FnOnce(&mut Self)
125125
{
126-
if self.index.staged_api[&LOCAL_CRATE] {
126+
if self.tcx.sess.features.borrow().staged_api {
127+
// This crate explicitly wants staged API.
127128
debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
128129
if let Some(..) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
129130
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> {
204205
}
205206
}
206207

208+
// Propagate unstability. This can happen even for non-staged-api crates in case
209+
// -Zforce-unstable-if-unmarked is set.
210+
if let Some(stab) = self.parent_stab {
211+
if stab.level.is_unstable() {
212+
let def_id = self.tcx.hir.local_def_id(id);
213+
self.index.stab_map.insert(def_id, Some(stab));
214+
}
215+
}
216+
207217
if let Some(depr) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
208218
if kind == AnnotationKind::Prohibited {
209219
self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless");

src/librustc_plugin/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#![deny(warnings)]
7070

7171
#![feature(rustc_diagnostic_macros)]
72+
#![feature(staged_api)]
7273

7374
#[macro_use] extern crate syntax;
7475

src/libtest/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(libc)]
3838
#![feature(set_stdio)]
3939
#![feature(panic_unwind)]
40+
#![feature(staged_api)]
4041

4142
extern crate getopts;
4243
extern crate term;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-Zforce-unstable-if-unmarked
12+
13+
#[unstable] //~ ERROR: stability attributes may not be used
14+
#[stable] //~ ERROR: stability attributes may not be used
15+
#[rustc_deprecated] //~ ERROR: stability attributes may not be used
16+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-Zforce-unstable-if-unmarked
12+
13+
#[deprecated] // should work even with -Zforce-unstable-if-unmarked
14+
fn main() { }

0 commit comments

Comments
 (0)