diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs index eee33846139e6..f01efedd659cd 100644 --- a/src/librustc/error_codes.rs +++ b/src/librustc/error_codes.rs @@ -2184,6 +2184,23 @@ Examples of erroneous code: static X: u32 = 42; ``` "##, + +E0734: r##" +A stability attribute has been used outside of the standard library. + +Erroneous code examples: + +```compile_fail,E0734 +#[rustc_deprecated(since = "b", reason = "text")] // invalid +#[stable(feature = "a", since = "b")] // invalid +#[unstable(feature = "b", issue = "0")] // invalid +fn foo(){} +``` + +These attributes are meant to only be used by the standard library and are +rejected in your own crates. +"##, + ; // E0006, // merged with E0005 // E0101, // replaced with E0282 diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index c06a0feb6a993..c45ae854e99eb 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -199,8 +199,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { let name = attr.name_or_empty(); if [sym::unstable, sym::stable, sym::rustc_deprecated].contains(&name) { attr::mark_used(attr); - self.tcx.sess.span_err(attr.span, "stability attributes may not be used \ - outside of the standard library"); + struct_span_err!( + self.tcx.sess, + attr.span, + E0734, + "stability attributes may not be used outside of the standard library", + ).emit(); } } diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr index 4eead36910356..8c6c26f7b2d81 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr @@ -1,40 +1,40 @@ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:7:1 | LL | #![rustc_deprecated()] | ^^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:10:1 | LL | #[rustc_deprecated()] | ^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:13:17 | LL | mod inner { #![rustc_deprecated()] } | ^^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:16:5 | LL | #[rustc_deprecated()] fn f() { } | ^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:19:5 | LL | #[rustc_deprecated()] struct S; | ^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:22:5 | LL | #[rustc_deprecated()] type T = S; | ^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-rustc_deprecated.rs:25:5 | LL | #[rustc_deprecated()] impl S { } @@ -42,3 +42,4 @@ LL | #[rustc_deprecated()] impl S { } error: aborting due to 7 previous errors +For more information about this error, try `rustc --explain E0734`. diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr index 03410eabe3652..09dabd293ff97 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr @@ -1,40 +1,40 @@ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:7:1 | LL | #![stable()] | ^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:10:1 | LL | #[stable()] | ^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:13:17 | LL | mod inner { #![stable()] } | ^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:16:5 | LL | #[stable()] fn f() { } | ^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:19:5 | LL | #[stable()] struct S; | ^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:22:5 | LL | #[stable()] type T = S; | ^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-stable.rs:25:5 | LL | #[stable()] impl S { } @@ -42,3 +42,4 @@ LL | #[stable()] impl S { } error: aborting due to 7 previous errors +For more information about this error, try `rustc --explain E0734`. diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr index 5952b3836aac8..49da2c59580e7 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr @@ -1,40 +1,40 @@ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:7:1 | LL | #![unstable()] | ^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:10:1 | LL | #[unstable()] | ^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:13:17 | LL | mod inner { #![unstable()] } | ^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:16:5 | LL | #[unstable()] fn f() { } | ^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:19:5 | LL | #[unstable()] struct S; | ^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:22:5 | LL | #[unstable()] type T = S; | ^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/issue-43106-gating-of-unstable.rs:25:5 | LL | #[unstable()] impl S { } @@ -42,3 +42,4 @@ LL | #[unstable()] impl S { } error: aborting due to 7 previous errors +For more information about this error, try `rustc --explain E0734`. diff --git a/src/test/ui/feature-gates/feature-gate-staged_api.stderr b/src/test/ui/feature-gates/feature-gate-staged_api.stderr index f0db47fe8a875..a71d26ce16f5b 100644 --- a/src/test/ui/feature-gates/feature-gate-staged_api.stderr +++ b/src/test/ui/feature-gates/feature-gate-staged_api.stderr @@ -1,10 +1,10 @@ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/feature-gate-staged_api.rs:1:1 | LL | #![stable(feature = "a", since = "b")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/feature-gate-staged_api.rs:8:1 | LL | #[stable(feature = "a", since = "b")] @@ -12,3 +12,4 @@ LL | #[stable(feature = "a", since = "b")] error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0734`. diff --git a/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr b/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr index 77f896a86d58a..32b0f405d6fb0 100644 --- a/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-non-staged-force-unstable.stderr @@ -1,16 +1,16 @@ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/stability-attribute-non-staged-force-unstable.rs:3:1 | LL | #[unstable()] | ^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/stability-attribute-non-staged-force-unstable.rs:4:1 | LL | #[stable()] | ^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/stability-attribute-non-staged-force-unstable.rs:5:1 | LL | #[rustc_deprecated()] @@ -18,3 +18,4 @@ LL | #[rustc_deprecated()] error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0734`. diff --git a/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr b/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr index e98f789f54c7d..7648effc480b5 100644 --- a/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-non-staged.stderr @@ -1,16 +1,16 @@ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/stability-attribute-non-staged.rs:1:1 | LL | #[unstable()] | ^^^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/stability-attribute-non-staged.rs:2:1 | LL | #[stable()] | ^^^^^^^^^^^ -error: stability attributes may not be used outside of the standard library +error[E0734]: stability attributes may not be used outside of the standard library --> $DIR/stability-attribute-non-staged.rs:3:1 | LL | #[rustc_deprecated()] @@ -18,3 +18,4 @@ LL | #[rustc_deprecated()] error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0734`. diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 50e9116c778ea..309f3c3ecd581 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -384,7 +384,7 @@ fn map_lib_features(base_src_path: &Path, let file = entry.path(); let filename = file.file_name().unwrap().to_string_lossy(); if !filename.ends_with(".rs") || filename == "features.rs" || - filename == "diagnostic_list.rs" { + filename == "diagnostic_list.rs" || filename == "error_codes.rs" { return; }