Skip to content

Commit 04243e3

Browse files
varkorAvi-D-coder
authored andcommitted
Various cleanup on stability code
1 parent e0bbe79 commit 04243e3

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

src/librustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::hash::Hash;
1212
// Accessibility levels, sorted in ascending order
1313
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, HashStable)]
1414
pub enum AccessLevel {
15-
/// Superset of `AccessLevel::Reachable` used to mark impl Trait items.
15+
/// Superset of `AccessLevel::Reachable` used to mark `impl Trait` items.
1616
ReachableFromImplTrait,
1717
/// Exported items + items participating in various kinds of public interfaces,
1818
/// but not directly nameable. For example, if function `fn f() -> T {...}` is

src/librustc_passes/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
303303
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(.., body, _, _), .. }) => {
304304
self.visit_nested_body(body);
305305
}
306-
// Nothing to recurse on for these
306+
// Nothing to recurse on for these.
307307
Node::ForeignItem(_)
308308
| Node::Variant(_)
309309
| Node::Ctor(..)

src/librustc_passes/stability.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ use std::num::NonZeroU32;
2828

2929
#[derive(PartialEq)]
3030
enum AnnotationKind {
31-
// Annotation is required if not inherited from unstable parents
31+
// Annotation is required if not inherited from unstable parents.
3232
Required,
33-
// Annotation is useless, reject it
33+
// Annotation is useless: reject it.
3434
Prohibited,
35-
// Annotation itself is useless, but it can be propagated to children
35+
// Annotation itself is useless, but it can be propagated to children.
3636
Container,
3737
}
3838

39-
// A private tree-walker for producing an Index.
39+
// A private tree-walker for producing an index.
4040
struct Annotator<'a, 'tcx> {
4141
tcx: TyCtxt<'tcx>,
4242
index: &'a mut Index<'tcx>,
@@ -65,7 +65,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
6565
self.tcx.sess.span_err(
6666
item_sp,
6767
"`#[deprecated]` cannot be used in staged API; \
68-
use `#[rustc_deprecated]` instead",
68+
use `#[rustc_deprecated]` instead",
6969
);
7070
}
7171
let (stab, const_stab) =
@@ -81,7 +81,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
8181
&& stab.level.is_stable()
8282
&& stab.rustc_depr.is_none())
8383
{
84-
self.tcx.sess.span_err(item_sp, "This stability annotation is useless");
84+
self.tcx.sess.span_err(item_sp, "item does not require a stability annotation");
8585
}
8686

8787
debug!("annotate: found {:?}", stab);
@@ -102,7 +102,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
102102
&attr::Stable { since: stab_since },
103103
) = (&stab.rustc_depr, &stab.level)
104104
{
105-
// Explicit version of iter::order::lt to handle parse errors properly
105+
// Explicit version of `iter::order::lt` to handle parse errors properly.
106106
for (dep_v, stab_v) in
107107
dep_since.as_str().split('.').zip(stab_since.as_str().split('.'))
108108
{
@@ -111,8 +111,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
111111
Ordering::Less => {
112112
self.tcx.sess.span_err(
113113
item_sp,
114-
"An API can't be stabilized \
115-
after it is deprecated",
114+
"an API cannot be stabilized after it has been deprecated",
116115
);
117116
break;
118117
}
@@ -124,8 +123,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
124123
// and this makes us not do anything else interesting.
125124
self.tcx.sess.span_err(
126125
item_sp,
127-
"Invalid stability or deprecation \
128-
version found",
126+
"item has an invalid stability or deprecation version",
129127
);
130128
break;
131129
}
@@ -140,6 +138,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
140138
} else {
141139
debug!("annotate: not found, parent = {:?}", self.parent_stab);
142140
if let Some(stab) = self.parent_stab {
141+
// Instability (but not stability) is inherited from the parent.
142+
// If something is unstable, everything inside it should also be
143+
// considered unstable.
143144
if stab.level.is_unstable() {
144145
self.index.stab_map.insert(hir_id, stab);
145146
}
@@ -179,7 +180,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
179180

180181
if let Some(depr) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
181182
if kind == AnnotationKind::Prohibited {
182-
self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless");
183+
self.tcx
184+
.sess
185+
.span_err(item_sp, "item does not require a deprecation annotation");
183186
}
184187

185188
// `Deprecation` is just two pointers, no need to intern it

src/test/ui/missing/missing-stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod foo {
1616
pub fn unmarked() {}
1717
}
1818

19-
#[stable(feature = "stable_test_feature", since="1.0.0")]
19+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
2020
pub mod bar {
2121
// #[stable] is not inherited
2222
pub fn unmarked() {}

0 commit comments

Comments
 (0)