Skip to content

Commit 8415fa2

Browse files
committed
Auto merge of #24399 - brson:stab, r=nrc
2 parents dabf0c6 + 22a9f66 commit 8415fa2

File tree

2 files changed

+57
-28
lines changed

2 files changed

+57
-28
lines changed

src/librustc/middle/stability.rs

+39-28
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,50 @@ impl<'a> Annotator<'a> {
5757
attrs: &Vec<Attribute>, item_sp: Span, f: F, required: bool) where
5858
F: FnOnce(&mut Annotator),
5959
{
60-
debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
61-
match attr::find_stability(self.sess.diagnostic(), attrs, item_sp) {
62-
Some(stab) => {
63-
debug!("annotate: found {:?}", stab);
64-
self.index.local.insert(id, stab.clone());
65-
66-
// Don't inherit #[stable(feature = "rust1", since = "1.0.0")]
67-
if stab.level != attr::Stable {
68-
let parent = replace(&mut self.parent, Some(stab));
69-
f(self);
70-
self.parent = parent;
71-
} else {
60+
if self.index.staged_api {
61+
debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
62+
match attr::find_stability(self.sess.diagnostic(), attrs, item_sp) {
63+
Some(stab) => {
64+
debug!("annotate: found {:?}", stab);
65+
self.index.local.insert(id, stab.clone());
66+
67+
// Don't inherit #[stable(feature = "rust1", since = "1.0.0")]
68+
if stab.level != attr::Stable {
69+
let parent = replace(&mut self.parent, Some(stab));
70+
f(self);
71+
self.parent = parent;
72+
} else {
73+
f(self);
74+
}
75+
}
76+
None => {
77+
debug!("annotate: not found, use_parent = {:?}, parent = {:?}",
78+
use_parent, self.parent);
79+
if use_parent {
80+
if let Some(stab) = self.parent.clone() {
81+
self.index.local.insert(id, stab);
82+
} else if self.index.staged_api && required
83+
&& self.export_map.contains(&id)
84+
&& !self.sess.opts.test {
85+
self.sess.span_err(item_sp,
86+
"This node does not have a stability attribute");
87+
}
88+
}
7289
f(self);
7390
}
7491
}
75-
None => {
76-
debug!("annotate: not found, use_parent = {:?}, parent = {:?}",
77-
use_parent, self.parent);
78-
if use_parent {
79-
if let Some(stab) = self.parent.clone() {
80-
self.index.local.insert(id, stab);
81-
} else if self.index.staged_api && required
82-
&& self.export_map.contains(&id)
83-
&& !self.sess.opts.test {
84-
self.sess.span_err(item_sp,
85-
"This node does not have a stability attribute");
86-
}
92+
} else {
93+
// Emit warnings for non-staged-api crates. These should be errors.
94+
for attr in attrs {
95+
let tag = attr.name();
96+
if tag == "unstable" || tag == "stable" || tag == "deprecated" {
97+
attr::mark_used(attr);
98+
self.sess.span_warn(attr.span(),
99+
"stability attributes are deprecated and \
100+
will soon become errors");
87101
}
88-
f(self);
89102
}
103+
f(self);
90104
}
91105
}
92106
}
@@ -157,9 +171,6 @@ impl<'a, 'v> Visitor<'v> for Annotator<'a> {
157171
impl Index {
158172
/// Construct the stability index for a crate being compiled.
159173
pub fn build(&mut self, sess: &Session, krate: &Crate, export_map: &PublicItems) {
160-
if !self.staged_api {
161-
return;
162-
}
163174
let mut annotator = Annotator {
164175
sess: sess,
165176
index: self,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// These two generate an error to satisfy the compile-fail test
12+
#![deny(warnings)]
13+
#![feature(blah)] //~ ERROR
14+
15+
#[unstable] //~ WARNING: stability attributes are deprecated
16+
#[stable] //~ WARNING: stability attributes are deprecated
17+
#[deprecated] //~ WARNING: stability attributes are deprecated
18+
fn main() { }

0 commit comments

Comments
 (0)