Skip to content

Commit 05f0dee

Browse files
committed
Improve the error messages for missing stability attributes
This makes the capitalisation consistent and provides more context (especially for missing top-level attributes).
1 parent ad43389 commit 05f0dee

9 files changed

+41
-21
lines changed

src/librustc/middle/stability.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,17 @@ struct MissingStabilityAnnotations<'a, 'tcx: 'a> {
322322
}
323323

324324
impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
325-
fn check_missing_stability(&self, id: NodeId, span: Span) {
325+
fn check_missing_stability(&self, id: NodeId, span: Span, name: &str) {
326326
let hir_id = self.tcx.hir().node_to_hir_id(id);
327327
let stab = self.tcx.stability().local_stability(hir_id);
328328
let is_error = !self.tcx.sess.opts.test &&
329329
stab.is_none() &&
330330
self.access_levels.is_reachable(id);
331331
if is_error {
332-
self.tcx.sess.span_err(span, "This node does not have a stability attribute");
332+
self.tcx.sess.span_err(
333+
span,
334+
&format!("{} has missing stability attribute", name),
335+
);
333336
}
334337
}
335338
}
@@ -347,42 +350,44 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
347350
// optional. They inherit stability from their parents when unannotated.
348351
hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {}
349352

350-
_ => self.check_missing_stability(i.id, i.span)
353+
hir::ItemKind::Mod(..) => self.check_missing_stability(i.id, i.span, "module"),
354+
355+
_ => self.check_missing_stability(i.id, i.span, "node")
351356
}
352357

353358
intravisit::walk_item(self, i)
354359
}
355360

356361
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
357-
self.check_missing_stability(ti.id, ti.span);
362+
self.check_missing_stability(ti.id, ti.span, "node");
358363
intravisit::walk_trait_item(self, ti);
359364
}
360365

361366
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
362367
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id));
363368
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
364-
self.check_missing_stability(ii.id, ii.span);
369+
self.check_missing_stability(ii.id, ii.span, "node");
365370
}
366371
intravisit::walk_impl_item(self, ii);
367372
}
368373

369374
fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: NodeId) {
370-
self.check_missing_stability(var.node.data.id(), var.span);
375+
self.check_missing_stability(var.node.data.id(), var.span, "variant");
371376
intravisit::walk_variant(self, var, g, item_id);
372377
}
373378

374379
fn visit_struct_field(&mut self, s: &'tcx StructField) {
375-
self.check_missing_stability(s.id, s.span);
380+
self.check_missing_stability(s.id, s.span, "field");
376381
intravisit::walk_struct_field(self, s);
377382
}
378383

379384
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) {
380-
self.check_missing_stability(i.id, i.span);
385+
self.check_missing_stability(i.id, i.span, "node");
381386
intravisit::walk_foreign_item(self, i);
382387
}
383388

384389
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
385-
self.check_missing_stability(md.id, md.span);
390+
self.check_missing_stability(md.id, md.span, "macro");
386391
}
387392
}
388393

@@ -867,7 +872,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
867872
tcx,
868873
access_levels,
869874
};
870-
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span);
875+
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span, "crate");
871876
intravisit::walk_crate(&mut missing, krate);
872877
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
873878
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![stable(feature = "stable_test_feature", since = "1.0.0")]
77

88
pub fn unmarked() {
9-
//~^ ERROR This node does not have a stability attribute
9+
//~^ ERROR node has missing stability attribute
1010
()
1111
}
1212

@@ -20,5 +20,5 @@ pub mod foo {
2020
pub mod bar {
2121
// #[stable] is not inherited
2222
pub fn unmarked() {}
23-
//~^ ERROR This node does not have a stability attribute
23+
//~^ ERROR node has missing stability attribute
2424
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error: This node does not have a stability attribute
1+
error: node has missing stability attribute
22
--> $DIR/missing-stability.rs:8:1
33
|
44
LL | / pub fn unmarked() {
5-
LL | | //~^ ERROR This node does not have a stability attribute
5+
LL | | //~^ ERROR node has missing stability attribute
66
LL | | ()
77
LL | | }
88
| |_^
99

10-
error: This node does not have a stability attribute
10+
error: node has missing stability attribute
1111
--> $DIR/missing-stability.rs:22:5
1212
|
1313
LL | pub fn unmarked() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(staged_api)]
2+
//~^ ERROR crate has missing stability attribute
3+
4+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: crate has missing stability attribute
2+
--> $DIR/missing-stability-attr-at-top-level.rs:1:1
3+
|
4+
LL | / #![feature(staged_api)]
5+
LL | | //~^ ERROR crate has missing stability attribute
6+
LL | |
7+
LL | | fn main() {}
8+
| |____________^
9+
10+
error: aborting due to previous error
11+

src/test/ui/stability-attribute/stability-attribute-issue-43027.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![stable(feature = "test", since = "0")]
33

44
#[stable(feature = "test", since = "0")]
5-
pub struct Reverse<T>(pub T); //~ ERROR This node does not have a stability attribute
5+
pub struct Reverse<T>(pub T); //~ ERROR field has missing stability attribute
66

77
fn main() {
88
// Make sure the field is used to fill the stability cache

src/test/ui/stability-attribute/stability-attribute-issue-43027.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error: This node does not have a stability attribute
1+
error: field has missing stability attribute
22
--> $DIR/stability-attribute-issue-43027.rs:5:23
33
|
4-
LL | pub struct Reverse<T>(pub T); //~ ERROR This node does not have a stability attribute
4+
LL | pub struct Reverse<T>(pub T); //~ ERROR field has missing stability attribute
55
| ^^^^^
66

77
error: aborting due to previous error

src/test/ui/stability-attribute/stability-attribute-sanity-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![stable(feature = "stable_test_feature", since = "1.0.0")]
66

77
#[macro_export]
8-
macro_rules! mac { //~ ERROR This node does not have a stability attribute
8+
macro_rules! mac { //~ ERROR macro has missing stability attribute
99
() => ()
1010
}
1111

src/test/ui/stability-attribute/stability-attribute-sanity-3.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error: This node does not have a stability attribute
1+
error: macro has missing stability attribute
22
--> $DIR/stability-attribute-sanity-3.rs:8:1
33
|
4-
LL | / macro_rules! mac { //~ ERROR This node does not have a stability attribute
4+
LL | / macro_rules! mac { //~ ERROR macro has missing stability attribute
55
LL | | () => ()
66
LL | | }
77
| |_^

0 commit comments

Comments
 (0)