Rollup merge of #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).
This commit is contained in:
commit
c6590e7dc7
@ -2290,7 +2290,7 @@ pub fn descriptive_variant(&self) -> &str {
|
|||||||
ItemKind::Union(..) => "union",
|
ItemKind::Union(..) => "union",
|
||||||
ItemKind::Trait(..) => "trait",
|
ItemKind::Trait(..) => "trait",
|
||||||
ItemKind::TraitAlias(..) => "trait alias",
|
ItemKind::TraitAlias(..) => "trait alias",
|
||||||
ItemKind::Impl(..) => "item",
|
ItemKind::Impl(..) => "impl",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,14 +322,17 @@ struct MissingStabilityAnnotations<'a, 'tcx: 'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
|
impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
|
||||||
fn check_missing_stability(&self, id: NodeId, span: Span) {
|
fn check_missing_stability(&self, id: NodeId, span: Span, name: &str) {
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||||
let stab = self.tcx.stability().local_stability(hir_id);
|
let stab = self.tcx.stability().local_stability(hir_id);
|
||||||
let is_error = !self.tcx.sess.opts.test &&
|
let is_error = !self.tcx.sess.opts.test &&
|
||||||
stab.is_none() &&
|
stab.is_none() &&
|
||||||
self.access_levels.is_reachable(id);
|
self.access_levels.is_reachable(id);
|
||||||
if is_error {
|
if is_error {
|
||||||
self.tcx.sess.span_err(span, "This node does not have a stability attribute");
|
self.tcx.sess.span_err(
|
||||||
|
span,
|
||||||
|
&format!("{} has missing stability attribute", name),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,42 +350,42 @@ fn visit_item(&mut self, i: &'tcx Item) {
|
|||||||
// optional. They inherit stability from their parents when unannotated.
|
// optional. They inherit stability from their parents when unannotated.
|
||||||
hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {}
|
hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {}
|
||||||
|
|
||||||
_ => self.check_missing_stability(i.id, i.span)
|
_ => self.check_missing_stability(i.id, i.span, i.node.descriptive_variant())
|
||||||
}
|
}
|
||||||
|
|
||||||
intravisit::walk_item(self, i)
|
intravisit::walk_item(self, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
|
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
|
||||||
self.check_missing_stability(ti.id, ti.span);
|
self.check_missing_stability(ti.id, ti.span, "item");
|
||||||
intravisit::walk_trait_item(self, ti);
|
intravisit::walk_trait_item(self, ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
|
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
|
||||||
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id));
|
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id));
|
||||||
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
||||||
self.check_missing_stability(ii.id, ii.span);
|
self.check_missing_stability(ii.id, ii.span, "item");
|
||||||
}
|
}
|
||||||
intravisit::walk_impl_item(self, ii);
|
intravisit::walk_impl_item(self, ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: NodeId) {
|
fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: NodeId) {
|
||||||
self.check_missing_stability(var.node.data.id(), var.span);
|
self.check_missing_stability(var.node.data.id(), var.span, "variant");
|
||||||
intravisit::walk_variant(self, var, g, item_id);
|
intravisit::walk_variant(self, var, g, item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_struct_field(&mut self, s: &'tcx StructField) {
|
fn visit_struct_field(&mut self, s: &'tcx StructField) {
|
||||||
self.check_missing_stability(s.id, s.span);
|
self.check_missing_stability(s.id, s.span, "field");
|
||||||
intravisit::walk_struct_field(self, s);
|
intravisit::walk_struct_field(self, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) {
|
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) {
|
||||||
self.check_missing_stability(i.id, i.span);
|
self.check_missing_stability(i.id, i.span, i.node.descriptive_variant());
|
||||||
intravisit::walk_foreign_item(self, i);
|
intravisit::walk_foreign_item(self, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
|
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
|
||||||
self.check_missing_stability(md.id, md.span);
|
self.check_missing_stability(md.id, md.span, "macro");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,7 +843,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
|||||||
tcx,
|
tcx,
|
||||||
access_levels,
|
access_levels,
|
||||||
};
|
};
|
||||||
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span);
|
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span, "crate");
|
||||||
intravisit::walk_crate(&mut missing, krate);
|
intravisit::walk_crate(&mut missing, krate);
|
||||||
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#![stable(feature = "stable_test_feature", since = "1.0.0")]
|
#![stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||||
|
|
||||||
pub fn unmarked() {
|
pub fn unmarked() {
|
||||||
//~^ ERROR This node does not have a stability attribute
|
//~^ ERROR function has missing stability attribute
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,5 +20,5 @@ pub fn unmarked() {}
|
|||||||
pub mod bar {
|
pub mod bar {
|
||||||
// #[stable] is not inherited
|
// #[stable] is not inherited
|
||||||
pub fn unmarked() {}
|
pub fn unmarked() {}
|
||||||
//~^ ERROR This node does not have a stability attribute
|
//~^ ERROR function has missing stability attribute
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
error: This node does not have a stability attribute
|
error: function has missing stability attribute
|
||||||
--> $DIR/missing-stability.rs:8:1
|
--> $DIR/missing-stability.rs:8:1
|
||||||
|
|
|
|
||||||
LL | / pub fn unmarked() {
|
LL | / pub fn unmarked() {
|
||||||
LL | | //~^ ERROR This node does not have a stability attribute
|
LL | | //~^ ERROR function has missing stability attribute
|
||||||
LL | | ()
|
LL | | ()
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: This node does not have a stability attribute
|
error: function has missing stability attribute
|
||||||
--> $DIR/missing-stability.rs:22:5
|
--> $DIR/missing-stability.rs:22:5
|
||||||
|
|
|
|
||||||
LL | pub fn unmarked() {}
|
LL | pub fn unmarked() {}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
#![feature(staged_api)]
|
||||||
|
//~^ ERROR crate has missing stability attribute
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,11 @@
|
|||||||
|
error: crate has missing stability attribute
|
||||||
|
--> $DIR/missing-stability-attr-at-top-level.rs:1:1
|
||||||
|
|
|
||||||
|
LL | / #![feature(staged_api)]
|
||||||
|
LL | | //~^ ERROR crate has missing stability attribute
|
||||||
|
LL | |
|
||||||
|
LL | | fn main() {}
|
||||||
|
| |____________^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
#![stable(feature = "test", since = "0")]
|
#![stable(feature = "test", since = "0")]
|
||||||
|
|
||||||
#[stable(feature = "test", since = "0")]
|
#[stable(feature = "test", since = "0")]
|
||||||
pub struct Reverse<T>(pub T); //~ ERROR This node does not have a stability attribute
|
pub struct Reverse<T>(pub T); //~ ERROR field has missing stability attribute
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Make sure the field is used to fill the stability cache
|
// Make sure the field is used to fill the stability cache
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
error: This node does not have a stability attribute
|
error: field has missing stability attribute
|
||||||
--> $DIR/stability-attribute-issue-43027.rs:5:23
|
--> $DIR/stability-attribute-issue-43027.rs:5:23
|
||||||
|
|
|
|
||||||
LL | pub struct Reverse<T>(pub T); //~ ERROR This node does not have a stability attribute
|
LL | pub struct Reverse<T>(pub T); //~ ERROR field has missing stability attribute
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#![stable(feature = "stable_test_feature", since = "1.0.0")]
|
#![stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! mac { //~ ERROR This node does not have a stability attribute
|
macro_rules! mac { //~ ERROR macro has missing stability attribute
|
||||||
() => ()
|
() => ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
error: This node does not have a stability attribute
|
error: macro has missing stability attribute
|
||||||
--> $DIR/stability-attribute-sanity-3.rs:8:1
|
--> $DIR/stability-attribute-sanity-3.rs:8:1
|
||||||
|
|
|
|
||||||
LL | / macro_rules! mac { //~ ERROR This node does not have a stability attribute
|
LL | / macro_rules! mac { //~ ERROR macro has missing stability attribute
|
||||||
LL | | () => ()
|
LL | | () => ()
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
Loading…
Reference in New Issue
Block a user