Skip to content

Commit

Permalink
Tie stability attributes to feature gates
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jan 22, 2015
1 parent 94ca8a3 commit 7b73ec4
Show file tree
Hide file tree
Showing 65 changed files with 299 additions and 212 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![feature(slicing_syntax, unboxed_closures)]
#![feature(box_syntax)]
#![feature(int_uint)]
#![allow(unstable)]
#![feature(unnamed_feature)]

#![deny(warnings)]

Expand Down
3 changes: 2 additions & 1 deletion src/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(unstable)]
#![allow(unknown_features)]
#![feature(unnamed_feature)]

#[cfg(rustdoc)]
extern crate "rustdoc" as this;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ impl<H: Hasher, T: Hash<H>> Hash<H> for Arc<T> {
}

#[cfg(test)]
#[allow(unstable)]
mod tests {
use std::clone::Clone;
use std::sync::mpsc::channel;
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@

#![no_std]
#![allow(unknown_features)]
#![allow(unstable)]
#![feature(lang_items, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(optin_builtin_traits)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]

#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,6 @@ impl<T> RcBoxPtr<T> for Weak<T> {
}

#[cfg(test)]
#[allow(unstable)]
mod tests {
use super::{Rc, Weak, weak_count, strong_count};
use std::cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#![feature(unsafe_destructor)]
#![feature(unboxed_closures)]
#![feature(box_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(missing_docs)]
#![allow(unstable)]

extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#![feature(unsafe_destructor, slicing_syntax)]
#![feature(box_syntax)]
#![feature(unboxed_closures)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![no_std]

#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! provided beyond this module.
//!
//! ```rust
//! #[allow(unstable)];
//!
//! fn main() {
//! use std::simd::f32x4;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,6 @@ pub mod bytes {

impl MutableByteVector for [u8] {
#[inline]
#[allow(unstable)]
fn set_memory(&mut self, value: u8) {
unsafe { ptr::set_memory(self.as_mut_ptr(), value, self.len()) };
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcoretest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#![feature(unsafe_destructor, slicing_syntax)]
#![feature(unboxed_closures)]
#![feature(box_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]

extern crate core;
extern crate test;
Expand Down
2 changes: 1 addition & 1 deletion src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![unstable(feature = "unnamed_feature", since = "1.0.0")]
#![staged_api]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![feature(unnamed_feature)]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
Expand Down
2 changes: 1 addition & 1 deletion src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#![feature(slicing_syntax)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![feature(unnamed_feature)]

pub use self::Piece::*;
pub use self::Position::*;
Expand Down
2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(slicing_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![deny(missing_docs)]

#[cfg(test)] #[macro_use] extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(slicing_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]

use self::LabelText::*;

Expand Down
4 changes: 2 additions & 2 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#![cfg_attr(not(feature = "cargo-build"),
unstable(feature = "unnamed_feature", since = "1.0.0"))]
#![cfg_attr(not(feature = "cargo-build"), staged_api)]
#![cfg_attr(not(feature = "cargo-build"), feature(unnamed_feature))]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![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",
Expand Down Expand Up @@ -74,7 +74,7 @@
//! one from Berkeley after the lawsuits died down and the CSRG dissolved.
#![allow(bad_style, raw_pointer_derive)]

#![cfg_attr(not(feature = "cargo-build"), feature(unnamed_feature))]
#[cfg(feature = "cargo-build")] extern crate "std" as core;
#[cfg(not(feature = "cargo-build"))] extern crate core;

Expand Down
2 changes: 1 addition & 1 deletion src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![deny(missing_docs)]

extern crate regex;
Expand Down
2 changes: 1 addition & 1 deletion src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]
#![no_std]
#![unstable(feature = "unnamed_feature", since = "1.0.0")]
#![staged_api]
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
html_playground_url = "http://play.rust-lang.org/")]
#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![allow(unstable)]

extern crate serialize;
#[macro_use] extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion src/libregex/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
html_playground_url = "http://play.rust-lang.org/")]

#![allow(unknown_features)]
#![allow(unstable)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![deny(missing_docs)]

Expand Down
1 change: 0 additions & 1 deletion src/libregex/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ pub struct Captures<'t> {
}

impl<'t> Captures<'t> {
#[allow(unstable)]
fn new(re: &Regex, search: &'t str, locs: CaptureLocs)
-> Option<Captures<'t>> {
if !has_match(&locs) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#![feature(quote)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(unnamed_feature)]
#![allow(unknown_features)] #![feature(int_uint)]
#![feature(rustc_diagnostic_macros)]
#![allow(unstable)]

extern crate arena;
extern crate flate;
Expand Down
117 changes: 13 additions & 104 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::{abi, ast, ast_map};
use syntax::ast_util::is_shift_binop;
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{Span, DUMMY_SP};
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
use syntax::ast_util;
Expand Down Expand Up @@ -1628,32 +1628,15 @@ declare_lint! {
"detects use of #[deprecated] items"
}

declare_lint! {
UNSTABLE,
Warn,
"detects use of #[unstable] items (incl. items with no stability attribute)"
}

/// Checks for use of items with `#[deprecated]`, `#[unstable]` and
/// `#[unstable]` attributes, or no stability attribute.
/// Checks for use of items with `#[deprecated]` attributes
#[derive(Copy)]
pub struct Stability;

impl Stability {
fn lint(&self, cx: &Context, id: ast::DefId, span: Span) {

if !stability::is_staged_api(cx.tcx, id) { return }
fn lint(&self, cx: &Context, _id: ast::DefId, span: Span, stability: &Option<attr::Stability>) {

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.
// deprecated attributes apply in-crate and cross-crate
let (lint, label) = match *stability {
// no stability attributes == Unstable
None if cross_crate => (UNSTABLE, "unmarked"),
Some(attr::Stability { level: attr::Unstable, .. }) if cross_crate =>
(UNSTABLE, "unstable"),
Some(attr::Stability { level: attr::Deprecated, .. }) =>
(DEPRECATED, "deprecated"),
_ => return
Expand All @@ -1673,100 +1656,26 @@ impl Stability {
cx.span_lint(lint, span, &msg[]);
}
}


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, UNSTABLE)
lint_array!(DEPRECATED)
}

fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
// compiler-generated `extern crate` statements have a dummy span.
if item.span == DUMMY_SP { return }

let id = match item.node {
ast::ViewItemExternCrate(_, _, id) => id,
ast::ViewItemUse(..) => return,
};
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(id) {
Some(cnum) => cnum,
None => return,
};
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
self.lint(cx, id, item.span);
}

fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
if self.is_internal(cx, e.span) { return; }

let mut span = e.span;

let id = match e.node {
ast::ExprPath(..) | ast::ExprQPath(..) | ast::ExprStruct(..) => {
match cx.tcx.def_map.borrow().get(&e.id) {
Some(&def) => def.def_id(),
None => return
}
}
ast::ExprMethodCall(i, _, _) => {
span = i.span;
let method_call = ty::MethodCall::expr(e.id);
match cx.tcx.method_map.borrow().get(&method_call) {
Some(method) => {
match method.origin {
ty::MethodStatic(def_id) => {
def_id
}
ty::MethodStaticUnboxedClosure(def_id) => {
def_id
}
ty::MethodTypeParam(ty::MethodParam {
ref trait_ref,
method_num: index,
..
}) |
ty::MethodTraitObject(ty::MethodObject {
ref trait_ref,
method_num: index,
..
}) => {
ty::trait_item(cx.tcx, trait_ref.def_id, index).def_id()
}
}
}
None => return
}
}
_ => return
};

self.lint(cx, id, span);
stability::check_view_item(cx.tcx, item,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}

fn check_item(&mut self, cx: &Context, item: &ast::Item) {
if self.is_internal(cx, item.span) { return }
stability::check_item(cx.tcx, item,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}

match item.node {
ast::ItemTrait(_, _, ref supertraits, _) => {
for t in supertraits.iter() {
if let ast::TraitTyParamBound(ref t, _) = *t {
let id = ty::trait_ref_to_def_id(cx.tcx, &t.trait_ref);
self.lint(cx, id, t.trait_ref.path.span);
}
}
}
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
let id = ty::trait_ref_to_def_id(cx.tcx, t);
self.lint(cx, id, t.path.span);
}
_ => (/* pass */)
}
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
stability::check_expr(cx.tcx, e,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,6 @@ impl LintStore {
},
None => unreachable!()
}
match self.by_name.get("unstable") {
Some(&Id(lint_id)) => if self.get_level_source(lint_id).0 != Forbid {
self.set_level(lint_id, (lvl, ReleaseChannel))
},
Some(&Renamed(_, lint_id)) => if self.get_level_source(lint_id).0 != Forbid {
self.set_level(lint_id, (lvl, ReleaseChannel))
},
None => unreachable!()
}
}
}

Expand Down
Loading

0 comments on commit 7b73ec4

Please sign in to comment.