Auto merge of #29014 - petrochenkov:stability, r=brson

Stricter checking of stability attributes + enforcement of their invariants at compile time
(+ removed dead file librustc_front/attr.rs)
I intended to enforce use of `reason` for unstable items as well (it normally presents for new items), but it turned out too intrusive, many older unstable items don't have `reason`s.

r? @aturon 
I'm studying how stability works and do some refactoring along the way, so it's probably not the last PR.
This commit is contained in:
bors 2015-10-16 17:47:01 +00:00
commit 747d951e88
18 changed files with 337 additions and 894 deletions

View file

@ -29,7 +29,7 @@ pub mod stable_mod {
#[unstable(feature = "test_feature", issue = "0")]
pub mod unstable_mod {
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn deprecated() {}
pub fn unstable() {}

View file

@ -15,7 +15,7 @@
#![unstable(feature = "test_feature", issue = "0")]
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn foo() -> usize {
20
}

View file

@ -14,14 +14,14 @@
#![stable(feature = "lint_stability", since = "1.0.0")]
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn deprecated() {}
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn deprecated_text() {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn deprecated_unstable() {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
@ -34,7 +34,7 @@ pub fn unstable_text() {}
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stable() {}
#[stable(feature = "rust1", since = "1.0.0", reason = "text")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stable_text() {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -42,14 +42,14 @@ pub struct MethodTester;
impl MethodTester {
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn method_deprecated(&self) {}
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn method_deprecated_text(&self) {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn method_deprecated_unstable(&self) {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
@ -62,21 +62,21 @@ impl MethodTester {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn method_stable(&self) {}
#[stable(feature = "rust1", since = "1.0.0", reason = "text")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn method_stable_text(&self) {}
}
#[stable(feature = "test_feature", since = "1.0.0")]
pub trait Trait {
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn trait_deprecated(&self) {}
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn trait_deprecated_text(&self) {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn trait_deprecated_unstable(&self) {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
@ -89,7 +89,7 @@ pub trait Trait {
#[stable(feature = "rust1", since = "1.0.0")]
fn trait_stable(&self) {}
#[stable(feature = "rust1", since = "1.0.0", reason = "text")]
#[stable(feature = "rust1", since = "1.0.0")]
fn trait_stable_text(&self) {}
}
@ -99,12 +99,12 @@ impl Trait for MethodTester {}
pub trait UnstableTrait { fn dummy(&self) { } }
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedStruct {
#[stable(feature = "test_feature", since = "1.0.0")] pub i: isize
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedUnstableStruct {
#[stable(feature = "test_feature", since = "1.0.0")] pub i: isize
}
@ -118,10 +118,10 @@ pub struct StableStruct {
}
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedUnitStruct;
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedUnstableUnitStruct;
#[unstable(feature = "test_feature", issue = "0")]
pub struct UnstableUnitStruct;
@ -131,10 +131,10 @@ pub struct StableUnitStruct;
#[stable(feature = "test_feature", since = "1.0.0")]
pub enum Enum {
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
DeprecatedVariant,
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
DeprecatedUnstableVariant,
#[unstable(feature = "test_feature", issue = "0")]
UnstableVariant,
@ -144,10 +144,10 @@ pub enum Enum {
}
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedTupleStruct(#[stable(feature = "rust1", since = "1.0.0")] pub isize);
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedUnstableTupleStruct(#[stable(feature = "rust1", since = "1.0.0")] pub isize);
#[unstable(feature = "test_feature", issue = "0")]
pub struct UnstableTupleStruct(#[stable(feature = "rust1", since = "1.0.0")] pub isize);

View file

@ -18,7 +18,7 @@ pub struct Stable {
pub inherit: u8, // it's a lie (stable doesn't inherit)
#[unstable(feature = "test_feature", issue = "0")]
pub override1: u8,
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
#[unstable(feature = "test_feature", issue = "0")]
pub override2: u8,
}
@ -27,14 +27,14 @@ pub struct Stable {
pub struct Stable2(#[stable(feature = "rust1", since = "1.0.0")] pub u8,
#[unstable(feature = "test_feature", issue = "0")] pub u8,
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")] pub u8);
#[deprecated(since = "1.0.0", reason = "text")] pub u8);
#[unstable(feature = "test_feature", issue = "0")]
pub struct Unstable {
pub inherit: u8,
#[stable(feature = "rust1", since = "1.0.0")]
pub override1: u8,
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
#[unstable(feature = "test_feature", issue = "0")]
pub override2: u8,
}
@ -43,10 +43,10 @@ pub struct Unstable {
pub struct Unstable2(pub u8,
#[stable(feature = "rust1", since = "1.0.0")] pub u8,
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")] pub u8);
#[deprecated(since = "1.0.0", reason = "text")] pub u8);
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct Deprecated {
pub inherit: u8,
#[stable(feature = "rust1", since = "1.0.0")]
@ -56,7 +56,7 @@ pub struct Deprecated {
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct Deprecated2(pub u8,
#[stable(feature = "rust1", since = "1.0.0")] pub u8,
#[unstable(feature = "test_feature", issue = "0")] pub u8);

View file

@ -15,8 +15,8 @@
struct Foo;
impl Foo {
#[unstable(feature = "test_feature")]
#[deprecated(since = "1.0.0")]
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn foo(self) {}
}

View file

@ -15,7 +15,7 @@
extern crate lint_output_format; //~ ERROR use of unstable library feature
use lint_output_format::{foo, bar}; //~ ERROR use of unstable library feature
//~^ WARNING use of deprecated item,
//~^ WARNING use of deprecated item: text,
fn main() {
let _x = foo(); //~ WARNING #[warn(deprecated)] on by default

View file

@ -189,7 +189,7 @@ mod this_crate {
inherit: u8,
#[unstable(feature = "test_feature", issue = "0")]
override1: u8,
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
#[unstable(feature = "test_feature", issue = "0")]
override2: u8,
}
@ -198,14 +198,14 @@ mod this_crate {
struct Stable2(u8,
#[stable(feature = "rust1", since = "1.0.0")] u8,
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")] u8);
#[deprecated(since = "1.0.0", reason = "text")] u8);
#[unstable(feature = "test_feature", issue = "0")]
struct Unstable {
inherit: u8,
#[stable(feature = "rust1", since = "1.0.0")]
override1: u8,
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
#[unstable(feature = "test_feature", issue = "0")]
override2: u8,
}
@ -214,10 +214,10 @@ mod this_crate {
struct Unstable2(u8,
#[stable(feature = "rust1", since = "1.0.0")] u8,
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")] u8);
#[deprecated(since = "1.0.0", reason = "text")] u8);
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
struct Deprecated {
inherit: u8,
#[stable(feature = "rust1", since = "1.0.0")]
@ -227,7 +227,7 @@ mod this_crate {
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
struct Deprecated2(u8,
#[stable(feature = "rust1", since = "1.0.0")] u8,
#[unstable(feature = "test_feature", issue = "0")] u8);

View file

@ -258,7 +258,7 @@ mod inheritance {
mod this_crate {
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn deprecated() {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
@ -271,7 +271,7 @@ mod this_crate {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stable() {}
#[stable(feature = "rust1", since = "1.0.0", reason = "text")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stable_text() {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -279,7 +279,7 @@ mod this_crate {
impl MethodTester {
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub fn method_deprecated(&self) {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
@ -292,13 +292,13 @@ mod this_crate {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn method_stable(&self) {}
#[stable(feature = "rust1", since = "1.0.0", reason = "text")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn method_stable_text(&self) {}
}
pub trait Trait {
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn trait_deprecated(&self) {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0", reason = "text")]
@ -311,14 +311,14 @@ mod this_crate {
#[stable(feature = "rust1", since = "1.0.0")]
fn trait_stable(&self) {}
#[stable(feature = "rust1", since = "1.0.0", reason = "text")]
#[stable(feature = "rust1", since = "1.0.0")]
fn trait_stable_text(&self) {}
}
impl Trait for MethodTester {}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedStruct {
#[stable(feature = "test_feature", since = "1.0.0")] i: isize
}
@ -332,7 +332,7 @@ mod this_crate {
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedUnitStruct;
#[unstable(feature = "test_feature", issue = "0")]
pub struct UnstableUnitStruct;
@ -341,7 +341,7 @@ mod this_crate {
pub enum Enum {
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
DeprecatedVariant,
#[unstable(feature = "test_feature", issue = "0")]
UnstableVariant,
@ -351,7 +351,7 @@ mod this_crate {
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub struct DeprecatedTupleStruct(isize);
#[unstable(feature = "test_feature", issue = "0")]
pub struct UnstableTupleStruct(isize);
@ -472,7 +472,7 @@ mod this_crate {
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn test_fn_body() {
fn fn_in_body() {}
fn_in_body();
@ -480,7 +480,7 @@ mod this_crate {
impl MethodTester {
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
fn test_method_body(&self) {
fn fn_in_body() {}
fn_in_body();
@ -488,7 +488,7 @@ mod this_crate {
}
#[unstable(feature = "test_feature", issue = "0")]
#[deprecated(since = "1.0.0")]
#[deprecated(since = "1.0.0", reason = "text")]
pub trait DeprecatedTrait {
fn dummy(&self) { }
}

View file

@ -0,0 +1,25 @@
// 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.
// More checks that stability attributes are used correctly
#![feature(staged_api)]
#![staged_api]
#[stable(feature = "a", feature = "b", since = "1.0.0")] //~ ERROR multiple 'feature' items
fn f1() { }
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
fn f2() { }
#[unstable(feature = "a", issue = "no")] //~ ERROR incorrect 'issue'
fn f3() { }
fn main() { }

View file

@ -14,22 +14,19 @@
#![staged_api]
mod bogus_attribute_types_1 {
#[stable(feature = "a", since = "a", reason)] //~ ERROR incorrect meta item
#[stable(feature = "a", since = "a", reason)] //~ ERROR unknown meta item 'reason'
fn f1() { }
#[stable(feature = "a", since, reason = "a")] //~ ERROR incorrect meta item
#[stable(feature = "a", since)] //~ ERROR incorrect meta item
fn f2() { }
#[stable(feature, since = "a", reason = "a")] //~ ERROR incorrect meta item
#[stable(feature, since = "a")] //~ ERROR incorrect meta item
fn f3() { }
#[stable(feature = "a", since = "a", reason(b))] //~ ERROR incorrect meta item
fn f4() { }
#[stable(feature = "a", since(b), reason = "a")] //~ ERROR incorrect meta item
#[stable(feature = "a", since(b))] //~ ERROR incorrect meta item
fn f5() { }
#[stable(feature(b), since = "a", reason = "a")] //~ ERROR incorrect meta item
#[stable(feature(b), since = "a")] //~ ERROR incorrect meta item
fn f6() { }
}
@ -56,11 +53,11 @@ mod bogus_attribute_types_2 {
}
mod missing_feature_names {
#[unstable(since = "a", issue = "0")] //~ ERROR missing 'feature'
#[unstable(issue = "0")] //~ ERROR missing 'feature'
fn f1() { }
#[unstable(feature = "a")]
fn f2() { } //~ ERROR need to point to an issue
#[unstable(feature = "a")] //~ ERROR missing 'issue'
fn f2() { }
#[stable(since = "a")] //~ ERROR missing 'feature'
fn f3() { }
@ -75,12 +72,12 @@ mod missing_version {
fn f2() { }
}
#[unstable(feature = "a", since = "b", issue = "0")]
#[unstable(feature = "a", issue = "0")]
#[stable(feature = "a", since = "b")]
fn multiple1() { } //~ ERROR multiple stability levels
#[unstable(feature = "a", since = "b", issue = "0")]
#[unstable(feature = "a", since = "b", issue = "0")]
#[unstable(feature = "a", issue = "0")]
#[unstable(feature = "a", issue = "0")]
fn multiple2() { } //~ ERROR multiple stability levels
#[stable(feature = "a", since = "b")]
@ -88,12 +85,12 @@ fn multiple2() { } //~ ERROR multiple stability levels
fn multiple3() { } //~ ERROR multiple stability levels
#[stable(feature = "a", since = "b")]
#[deprecated(since = "b")]
#[deprecated(since = "b")]
#[deprecated(since = "b", reason = "text")]
#[deprecated(since = "b", reason = "text")]
fn multiple4() { } //~ ERROR multiple deprecated attributes
//~^ ERROR Invalid stability or deprecation version found
#[deprecated(since = "a")]
#[deprecated(since = "a", reason = "text")]
fn deprecated_without_unstable_or_stable() { } //~ ERROR deprecated attribute must be paired
fn main() { }