Skip to content

Commit

Permalink
Require stability annotations on fields of tuple variants
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 14, 2016
1 parent e1f550e commit 8ea7b88
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 41 deletions.
6 changes: 4 additions & 2 deletions src/libcollections/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ pub enum Cow<'a, B: ?Sized + 'a>
{
/// Borrowed data.
#[stable(feature = "rust1", since = "1.0.0")]
Borrowed(&'a B),
Borrowed(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a B),

/// Owned data.
#[stable(feature = "rust1", since = "1.0.0")]
Owned(<B as ToOwned>::Owned),
Owned(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] <B as ToOwned>::Owned
),
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
8 changes: 6 additions & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,15 @@ pub struct RangeMut<'a, K: 'a, V: 'a> {
pub enum Entry<'a, K: 'a, V: 'a> {
/// A vacant Entry
#[stable(feature = "rust1", since = "1.0.0")]
Vacant(VacantEntry<'a, K, V>),
Vacant(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] VacantEntry<'a, K, V>
),

/// An occupied Entry
#[stable(feature = "rust1", since = "1.0.0")]
Occupied(OccupiedEntry<'a, K, V>),
Occupied(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] OccupiedEntry<'a, K, V>
),
}

/// A vacant Entry.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub enum Option<T> {
None,
/// Some value `T`
#[stable(feature = "rust1", since = "1.0.0")]
Some(T)
Some(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] T)
}

/////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ use option::Option::{self, None, Some};
pub enum Result<T, E> {
/// Contains the success value
#[stable(feature = "rust1", since = "1.0.0")]
Ok(T),
Ok(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] T),

/// Contains the error value
#[stable(feature = "rust1", since = "1.0.0")]
Err(E)
Err(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] E)
}

/////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 1 addition & 15 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ struct Annotator<'a, 'tcx: 'a> {
parent_depr: Option<Deprecation>,
access_levels: &'a AccessLevels,
in_trait_impl: bool,
in_enum: bool,
}

impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
Expand Down Expand Up @@ -208,7 +207,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {

fn visit_item(&mut self, i: &Item) {
let orig_in_trait_impl = self.in_trait_impl;
let orig_in_enum = self.in_enum;
let mut kind = AnnotationKind::Required;
match i.node {
// Inherent impls and foreign modules serve only as containers for other items,
Expand All @@ -223,22 +221,17 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
self.in_trait_impl = true;
}
hir::ItemStruct(ref sd, _) => {
self.in_enum = false;
if !sd.is_struct() {
self.annotate(sd.id(), &i.attrs, i.span, AnnotationKind::Required, |_| {})
}
}
hir::ItemEnum(..) => {
self.in_enum = true;
}
_ => {}
}

self.annotate(i.id, &i.attrs, i.span, kind, |v| {
intravisit::walk_item(v, i)
});
self.in_trait_impl = orig_in_trait_impl;
self.in_enum = orig_in_enum;
}

fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
Expand All @@ -265,13 +258,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
}

fn visit_struct_field(&mut self, s: &StructField) {
// FIXME: This is temporary, can't use attributes with tuple variant fields until snapshot
let kind = if self.in_enum && s.node.kind.is_unnamed() {
AnnotationKind::Prohibited
} else {
AnnotationKind::Required
};
self.annotate(s.node.id, &s.node.attrs, s.span, kind, |v| {
self.annotate(s.node.id, &s.node.attrs, s.span, AnnotationKind::Required, |v| {
intravisit::walk_struct_field(v, s);
});
}
Expand Down Expand Up @@ -299,7 +286,6 @@ impl<'tcx> Index<'tcx> {
parent_depr: None,
access_levels: access_levels,
in_trait_impl: false,
in_enum: false,
};
annotator.annotate(ast::CRATE_NODE_ID, &krate.attrs, krate.span, AnnotationKind::Required,
|v| intravisit::walk_crate(v, krate));
Expand Down
8 changes: 6 additions & 2 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,11 +1346,15 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> {
pub enum Entry<'a, K: 'a, V: 'a> {
/// An occupied Entry.
#[stable(feature = "rust1", since = "1.0.0")]
Occupied(OccupiedEntry<'a, K, V>),
Occupied(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] OccupiedEntry<'a, K, V>
),

/// A vacant Entry.
#[stable(feature = "rust1", since = "1.0.0")]
Vacant(VacantEntry<'a, K, V>),
Vacant(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] VacantEntry<'a, K, V>
),
}

/// Possible states of a VacantEntry.
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub enum VarError {
/// valid unicode data. The found data is returned as a payload of this
/// variant.
#[stable(feature = "env", since = "1.0.0")]
NotUnicode(OsString),
NotUnicode(#[cfg_attr(not(stage0), stable(feature = "env", since = "1.0.0"))] OsString),
}

#[stable(feature = "env", since = "1.0.0")]
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,23 +1175,23 @@ pub trait Seek {
pub enum SeekFrom {
/// Set the offset to the provided number of bytes.
#[stable(feature = "rust1", since = "1.0.0")]
Start(u64),
Start(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] u64),

/// Set the offset to the size of this object plus the specified number of
/// bytes.
///
/// It is possible to seek beyond the end of an object, but it's an error to
/// seek before byte 0.
#[stable(feature = "rust1", since = "1.0.0")]
End(i64),
End(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] i64),

/// Set the offset to the current position plus the specified number of
/// bytes.
///
/// It is possible to seek beyond the end of an object, but it's an error to
/// seek before byte 0.
#[stable(feature = "rust1", since = "1.0.0")]
Current(i64),
Current(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] i64),
}

fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ use vec;
pub enum SocketAddr {
/// An IPv4 socket address which is a (ip, port) combination.
#[stable(feature = "rust1", since = "1.0.0")]
V4(SocketAddrV4),
V4(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] SocketAddrV4),
/// An IPv6 socket address
#[stable(feature = "rust1", since = "1.0.0")]
V6(SocketAddrV6),
V6(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] SocketAddrV6),
}

/// An IPv4 socket address which is a (ip, port) combination.
Expand Down
24 changes: 16 additions & 8 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,27 +266,33 @@ mod platform {
pub enum Prefix<'a> {
/// Prefix `\\?\`, together with the given component immediately following it.
#[stable(feature = "rust1", since = "1.0.0")]
Verbatim(&'a OsStr),
Verbatim(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr),

/// Prefix `\\?\UNC\`, with the "server" and "share" components following it.
#[stable(feature = "rust1", since = "1.0.0")]
VerbatimUNC(&'a OsStr, &'a OsStr),
VerbatimUNC(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr,
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr,
),

/// Prefix like `\\?\C:\`, for the given drive letter
#[stable(feature = "rust1", since = "1.0.0")]
VerbatimDisk(u8),
VerbatimDisk(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] u8),

/// Prefix `\\.\`, together with the given component immediately following it.
#[stable(feature = "rust1", since = "1.0.0")]
DeviceNS(&'a OsStr),
DeviceNS(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr),

/// Prefix `\\server\share`, with the given "server" and "share" components.
#[stable(feature = "rust1", since = "1.0.0")]
UNC(&'a OsStr, &'a OsStr),
UNC(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr,
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr,
),

/// Prefix `C:` for the given disk drive.
#[stable(feature = "rust1", since = "1.0.0")]
Disk(u8),
Disk(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] u8),
}

impl<'a> Prefix<'a> {
Expand Down Expand Up @@ -528,7 +534,9 @@ pub enum Component<'a> {
///
/// Does not occur on Unix.
#[stable(feature = "rust1", since = "1.0.0")]
Prefix(PrefixComponent<'a>),
Prefix(
#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] PrefixComponent<'a>
),

/// The root directory component, appears after any prefix and before anything else
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -544,7 +552,7 @@ pub enum Component<'a> {

/// A normal component, i.e. `a` and `b` in `a/b`
#[stable(feature = "rust1", since = "1.0.0")]
Normal(&'a OsStr),
Normal(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] &'a OsStr),
}

impl<'a> Component<'a> {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,12 @@ pub enum TrySendError<T> {
/// this is not a buffered channel, then there is no receiver available to
/// acquire the data.
#[stable(feature = "rust1", since = "1.0.0")]
Full(T),
Full(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] T),

/// This channel's receiving half has disconnected, so the data could not be
/// sent. The data is returned back to the callee in this case.
#[stable(feature = "rust1", since = "1.0.0")]
Disconnected(T),
Disconnected(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] T),
}

enum Flavor<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum TryLockError<T> {
/// The lock could not be acquired because another thread failed while holding
/// the lock.
#[stable(feature = "rust1", since = "1.0.0")]
Poisoned(PoisonError<T>),
Poisoned(#[cfg_attr(not(stage0), stable(feature = "rust1", since = "1.0.0"))] PoisonError<T>),
/// The lock could not be acquired at this time because the operation would
/// otherwise block.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit 8ea7b88

Please sign in to comment.