From 68d099a175334939047b99888b656661f32e13e3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 25 Sep 2019 13:23:53 +0200 Subject: [PATCH 1/4] Create new error code E0734 for stability attributes used outside of standard library --- src/librustc/error_codes.rs | 1 + src/librustc/middle/stability.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs index eee33846139e6..554e1a9ad828d 100644 --- a/src/librustc/error_codes.rs +++ b/src/librustc/error_codes.rs @@ -2247,4 +2247,5 @@ static X: u32 = 42; E0726, // non-explicit (not `'_`) elided lifetime in unsupported position E0727, // `async` generators are not yet supported E0728, // `await` must be in an `async` function or block + E0734, // stability attributes may not be used outside of the standard library } 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(); } } From 0ebb044eb1bc1a930ae777e41347e960b8c419eb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 25 Sep 2019 13:58:42 +0200 Subject: [PATCH 2/4] Add long error explanation for E0734 --- src/librustc/error_codes.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs index 554e1a9ad828d..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 @@ -2247,5 +2264,4 @@ static X: u32 = 42; E0726, // non-explicit (not `'_`) elided lifetime in unsupported position E0727, // `async` generators are not yet supported E0728, // `await` must be in an `async` function or block - E0734, // stability attributes may not be used outside of the standard library } From 2e7868389abca4314d3732efd097d6de1cb498a7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 25 Sep 2019 13:58:52 +0200 Subject: [PATCH 3/4] Update ui tests --- .../issue-43106-gating-of-rustc_deprecated.stderr | 15 ++++++++------- .../issue-43106-gating-of-stable.stderr | 15 ++++++++------- .../issue-43106-gating-of-unstable.stderr | 15 ++++++++------- .../feature-gates/feature-gate-staged_api.stderr | 5 +++-- ...ity-attribute-non-staged-force-unstable.stderr | 7 ++++--- .../stability-attribute-non-staged.stderr | 7 ++++--- 6 files changed, 35 insertions(+), 29 deletions(-) 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`. From ecfe92f75e7f9a6727efb13ea1c666e98de7ca90 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 Sep 2019 13:24:59 +0200 Subject: [PATCH 4/4] Don't check error_codes files for lints --- src/tools/tidy/src/features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; }