Skip to content

Commit d18e4f0

Browse files
authored
Rollup merge of rust-lang#58276 - varkor:missing-stability-attr-top-level, r=davidtwco
Improve the error messages for missing stability attributes This makes the capitalisation consistent and provides more context (especially for missing top-level attributes).
2 parents dfd8454 + bb1eed0 commit d18e4f0

10 files changed

+40
-22
lines changed

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ impl ItemKind {
22902290
ItemKind::Union(..) => "union",
22912291
ItemKind::Trait(..) => "trait",
22922292
ItemKind::TraitAlias(..) => "trait alias",
2293-
ItemKind::Impl(..) => "item",
2293+
ItemKind::Impl(..) => "impl",
22942294
}
22952295
}
22962296

src/librustc/middle/stability.rs

Lines changed: 13 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,42 @@ 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+
_ => self.check_missing_stability(i.id, i.span, i.node.descriptive_variant())
351354
}
352355

353356
intravisit::walk_item(self, i)
354357
}
355358

356359
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
357-
self.check_missing_stability(ti.id, ti.span);
360+
self.check_missing_stability(ti.id, ti.span, "item");
358361
intravisit::walk_trait_item(self, ti);
359362
}
360363

361364
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
362365
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id));
363366
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
364-
self.check_missing_stability(ii.id, ii.span);
367+
self.check_missing_stability(ii.id, ii.span, "item");
365368
}
366369
intravisit::walk_impl_item(self, ii);
367370
}
368371

369372
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);
373+
self.check_missing_stability(var.node.data.id(), var.span, "variant");
371374
intravisit::walk_variant(self, var, g, item_id);
372375
}
373376

374377
fn visit_struct_field(&mut self, s: &'tcx StructField) {
375-
self.check_missing_stability(s.id, s.span);
378+
self.check_missing_stability(s.id, s.span, "field");
376379
intravisit::walk_struct_field(self, s);
377380
}
378381

379382
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) {
380-
self.check_missing_stability(i.id, i.span);
383+
self.check_missing_stability(i.id, i.span, i.node.descriptive_variant());
381384
intravisit::walk_foreign_item(self, i);
382385
}
383386

384387
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
385-
self.check_missing_stability(md.id, md.span);
388+
self.check_missing_stability(md.id, md.span, "macro");
386389
}
387390
}
388391

@@ -840,7 +843,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
840843
tcx,
841844
access_levels,
842845
};
843-
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span);
846+
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span, "crate");
844847
intravisit::walk_crate(&mut missing, krate);
845848
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
846849
}

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 function 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 function 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: function 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 function has missing stability attribute
66
LL | | ()
77
LL | | }
88
| |_^
99

10-
error: This node does not have a stability attribute
10+
error: function 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)