Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 17, 2015
1 parent 7e2ffc7 commit 5cdfd84
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/libcollections/fmt.rs
Expand Up @@ -475,8 +475,10 @@

#![stable(feature = "rust1", since = "1.0.0")]

#[unstable(feature = "fmt_internals", issue = "0")]
pub use core::fmt::rt;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Formatter, Result, Write, rt};
pub use core::fmt::{Formatter, Result, Write};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Octal, Binary};
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/fmt/mod.rs
Expand Up @@ -24,13 +24,13 @@ use slice;
use str;
use self::rt::v1::Alignment;

#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "fmt_radix", issue = "27728")]
pub use self::num::radix;
#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "fmt_radix", issue = "27728")]
pub use self::num::Radix;
#[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "fmt_radix", issue = "27728")]
pub use self::num::RadixFmt;
#[stable(feature = "rust1", since = "1.0.0")]
#[stable(feature = "debug_builders", since = "1.2.0")]
pub use self::builders::{DebugStruct, DebugTuple, DebugSet, DebugList, DebugMap};

mod num;
Expand Down
41 changes: 23 additions & 18 deletions src/librustc/middle/stability.rs
Expand Up @@ -12,7 +12,6 @@
//! propagating default levels lexically from parent to children ast nodes.

pub use self::StabilityLevel::*;
use self::AnnotationKind::*;

use session::Session;
use lint;
Expand Down Expand Up @@ -52,11 +51,11 @@ impl StabilityLevel {
#[derive(PartialEq)]
enum AnnotationKind {
// Annotation is required if not inherited from unstable parents
AnnRequired,
Required,
// Annotation is useless, reject it
AnnProhibited,
Prohibited,
// Annotation itself is useless, but it can be propagated to children
AnnContainer,
Container,
}

/// A stability index, giving the stability level for items and methods.
Expand Down Expand Up @@ -91,8 +90,10 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
if let Some(mut stab) = attr::find_stability(self.tcx.sess.diagnostic(),
attrs, item_sp) {
// Error if prohibited, or can't inherit anything from a container
if kind == AnnProhibited ||
kind == AnnContainer && stab.level.is_stable() && stab.depr.is_none() {
if kind == AnnotationKind::Prohibited ||
(kind == AnnotationKind::Container &&
stab.level.is_stable() &&
stab.depr.is_none()) {
self.tcx.sess.span_err(item_sp, "This stability annotation is useless");
}

Expand Down Expand Up @@ -141,7 +142,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
self.parent = parent;
} else {
debug!("annotate: not found, parent = {:?}", self.parent);
let mut is_error = kind == AnnRequired &&
let mut is_error = kind == AnnotationKind::Required &&
self.export_map.contains(&id) &&
!self.tcx.sess.opts.test;
if let Some(stab) = self.parent {
Expand Down Expand Up @@ -176,23 +177,23 @@ 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 = AnnRequired;
let mut kind = AnnotationKind::Required;
match i.node {
// Inherent impls and foreign modules serve only as containers for other items,
// they don't have their own stability. They still can be annotated as unstable
// and propagate this unstability to children, but this annotation is completely
// optional. They inherit stability from their parents when unannotated.
hir::ItemImpl(_, _, _, None, _, _) | hir::ItemForeignMod(..) => {
self.in_trait_impl = false;
kind = AnnContainer;
kind = AnnotationKind::Container;
}
hir::ItemImpl(_, _, _, Some(_), _, _) => {
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, AnnRequired, |_| {})
self.annotate(sd.id(), &i.attrs, i.span, AnnotationKind::Required, |_| {})
}
}
hir::ItemEnum(..) => {
Expand All @@ -209,45 +210,49 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
}

fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
self.annotate(ti.id, &ti.attrs, ti.span, AnnRequired, |v| {
self.annotate(ti.id, &ti.attrs, ti.span, AnnotationKind::Required, |v| {
visit::walk_trait_item(v, ti);
});
}

fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
let kind = if self.in_trait_impl { AnnProhibited } else { AnnRequired };
let kind = if self.in_trait_impl {
AnnotationKind::Prohibited
} else {
AnnotationKind::Required
};
self.annotate(ii.id, &ii.attrs, ii.span, kind, |v| {
visit::walk_impl_item(v, ii);
});
}

fn visit_variant(&mut self, var: &Variant, g: &'v Generics, item_id: NodeId) {
self.annotate(var.node.data.id(), &var.node.attrs, var.span, AnnRequired, |v| {
self.annotate(var.node.data.id(), &var.node.attrs, var.span, AnnotationKind::Required, |v| {
visit::walk_variant(v, var, g, item_id);
})
}

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() {
AnnProhibited
AnnotationKind::Prohibited
} else {
AnnRequired
AnnotationKind::Required
};
self.annotate(s.node.id, &s.node.attrs, s.span, kind, |v| {
visit::walk_struct_field(v, s);
});
}

fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
self.annotate(i.id, &i.attrs, i.span, AnnRequired, |v| {
self.annotate(i.id, &i.attrs, i.span, AnnotationKind::Required, |v| {
visit::walk_foreign_item(v, i);
});
}

fn visit_macro_def(&mut self, md: &'v hir::MacroDef) {
if md.imported_from.is_none() {
self.annotate(md.id, &md.attrs, md.span, AnnRequired, |_| {});
self.annotate(md.id, &md.attrs, md.span, AnnotationKind::Required, |_| {});
}
}
}
Expand All @@ -263,7 +268,7 @@ impl<'tcx> Index<'tcx> {
in_trait_impl: false,
in_enum: false,
};
annotator.annotate(ast::CRATE_NODE_ID, &krate.attrs, krate.span, AnnRequired,
annotator.annotate(ast::CRATE_NODE_ID, &krate.attrs, krate.span, AnnotationKind::Required,
|v| visit::walk_crate(v, krate));
}

Expand Down

0 comments on commit 5cdfd84

Please sign in to comment.