about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-09-29 18:00:50 -0700
committerZack M. Davis <code@zackmdavis.net>2018-10-27 12:31:20 -0700
commitdc0609c2473c01f521c5a3b9959edf7dd11f2d86 (patch)
treeae6d7a34bb14d4bce8364af186c75c7a98693e87
parent630c6a544f91a29f2a1749dd438e7082400295da (diff)
downloadrust-dc0609c2473c01f521c5a3b9959edf7dd11f2d86.tar.gz
rust-dc0609c2473c01f521c5a3b9959edf7dd11f2d86.zip
feature-gate lint reasons
We take stability seriously, so we shy away from making even seemingly
"trivial" features insta-stable.
-rw-r--r--src/librustc/lint/levels.rs14
-rw-r--r--src/libsyntax/feature_gate.rs3
-rw-r--r--src/test/ui/feature-gates/feature-gate-lint-reasons.rs4
-rw-r--r--src/test/ui/feature-gates/feature-gate-lint-reasons.stderr11
-rw-r--r--src/test/ui/lint/reasons-erroneous.rs2
-rw-r--r--src/test/ui/lint/reasons-erroneous.stderr12
-rw-r--r--src/test/ui/lint/reasons-forbidden.rs2
-rw-r--r--src/test/ui/lint/reasons-forbidden.stderr2
-rw-r--r--src/test/ui/lint/reasons.rs2
-rw-r--r--src/test/ui/lint/reasons.stderr8
10 files changed, 48 insertions, 12 deletions
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs
index 86d0a5a4790..ee878da0066 100644
--- a/src/librustc/lint/levels.rs
+++ b/src/librustc/lint/levels.rs
@@ -225,11 +225,23 @@ impl<'a> LintLevelsBuilder<'a> {
                     match item.node {
                         ast::MetaItemKind::Word => {}  // actual lint names handled later
                         ast::MetaItemKind::NameValue(ref name_value) => {
+                            let gate_reasons = !self.sess.features_untracked().lint_reasons;
                             let name_ident = item.ident.segments[0].ident;
                             let name = name_ident.name.as_str();
+
                             if name == "reason" {
                                 if let ast::LitKind::Str(rationale, _) = name_value.node {
-                                    reason = Some(rationale);
+                                    if gate_reasons {
+                                        feature_gate::emit_feature_err(
+                                            &self.sess.parse_sess,
+                                            "lint_reasons",
+                                            item.span,
+                                            feature_gate::GateIssue::Language,
+                                            "lint reasons are experimental"
+                                        );
+                                    } else {
+                                        reason = Some(rationale);
+                                    }
                                 } else {
                                     let mut err = bad_attr(name_value.span);
                                     err.help("reason must be a string literal");
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 2cd4fd92bc8..da0ec33030e 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -504,6 +504,9 @@ declare_features! (
 
     // `extern crate foo as bar;` puts `bar` into extern prelude.
     (active, extern_crate_item_prelude, "1.31.0", Some(54658), None),
+
+    // `reason = ` in lint attributes and `expect` lint attribute
+    (active, lint_reasons, "1.31.0", Some(54503), None),
 );
 
 declare_features! (
diff --git a/src/test/ui/feature-gates/feature-gate-lint-reasons.rs b/src/test/ui/feature-gates/feature-gate-lint-reasons.rs
new file mode 100644
index 00000000000..1a7b9c990fa
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-lint-reasons.rs
@@ -0,0 +1,4 @@
+#![warn(nonstandard_style, reason = "the standard should be respected")]
+//~^ ERROR lint reasons are experimental
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-lint-reasons.stderr b/src/test/ui/feature-gates/feature-gate-lint-reasons.stderr
new file mode 100644
index 00000000000..6a36d9fd5a8
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-lint-reasons.stderr
@@ -0,0 +1,11 @@
+error[E0658]: lint reasons are experimental (see issue #54503)
+  --> $DIR/feature-gate-lint-reasons.rs:1:28
+   |
+LL | #![warn(nonstandard_style, reason = "the standard should be respected")]
+   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: add #![feature(lint_reasons)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/lint/reasons-erroneous.rs b/src/test/ui/lint/reasons-erroneous.rs
index 68f2ce42847..90111a9c4e1 100644
--- a/src/test/ui/lint/reasons-erroneous.rs
+++ b/src/test/ui/lint/reasons-erroneous.rs
@@ -1,3 +1,5 @@
+#![feature(lint_reasons)]
+
 #![warn(absolute_paths_not_starting_with_crate, reason = 0)]
 //~^ ERROR malformed lint attribute
 //~| HELP reason must be a string literal
diff --git a/src/test/ui/lint/reasons-erroneous.stderr b/src/test/ui/lint/reasons-erroneous.stderr
index 25bdda178ee..f66999e9272 100644
--- a/src/test/ui/lint/reasons-erroneous.stderr
+++ b/src/test/ui/lint/reasons-erroneous.stderr
@@ -1,5 +1,5 @@
 error[E0452]: malformed lint attribute
-  --> $DIR/reasons-erroneous.rs:1:58
+  --> $DIR/reasons-erroneous.rs:3:58
    |
 LL | #![warn(absolute_paths_not_starting_with_crate, reason = 0)]
    |                                                          ^
@@ -7,7 +7,7 @@ LL | #![warn(absolute_paths_not_starting_with_crate, reason = 0)]
    = help: reason must be a string literal
 
 error[E0452]: malformed lint attribute
-  --> $DIR/reasons-erroneous.rs:4:40
+  --> $DIR/reasons-erroneous.rs:6:40
    |
 LL | #![warn(anonymous_parameters, reason = b"consider these, for we have condemned them")]
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -15,25 +15,25 @@ LL | #![warn(anonymous_parameters, reason = b"consider these, for we have condem
    = help: reason must be a string literal
 
 error[E0452]: malformed lint attribute
-  --> $DIR/reasons-erroneous.rs:7:29
+  --> $DIR/reasons-erroneous.rs:9:29
    |
 LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0452]: malformed lint attribute
-  --> $DIR/reasons-erroneous.rs:9:23
+  --> $DIR/reasons-erroneous.rs:11:23
    |
 LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0452]: malformed lint attribute
-  --> $DIR/reasons-erroneous.rs:11:36
+  --> $DIR/reasons-erroneous.rs:13:36
    |
 LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unknown lint: `reason`
-  --> $DIR/reasons-erroneous.rs:13:44
+  --> $DIR/reasons-erroneous.rs:15:44
    |
 LL | #![warn(ellipsis_inclusive_range_patterns, reason)]
    |                                            ^^^^^^
diff --git a/src/test/ui/lint/reasons-forbidden.rs b/src/test/ui/lint/reasons-forbidden.rs
index cad62b3a3c1..19ab76707d4 100644
--- a/src/test/ui/lint/reasons-forbidden.rs
+++ b/src/test/ui/lint/reasons-forbidden.rs
@@ -1,3 +1,5 @@
+#![feature(lint_reasons)]
+
 #![forbid(
     unsafe_code,
     //~^ NOTE `forbid` level set here
diff --git a/src/test/ui/lint/reasons-forbidden.stderr b/src/test/ui/lint/reasons-forbidden.stderr
index cc9e787b2d4..ea09e591cba 100644
--- a/src/test/ui/lint/reasons-forbidden.stderr
+++ b/src/test/ui/lint/reasons-forbidden.stderr
@@ -1,5 +1,5 @@
 error[E0453]: allow(unsafe_code) overruled by outer forbid(unsafe_code)
-  --> $DIR/reasons-forbidden.rs:12:13
+  --> $DIR/reasons-forbidden.rs:14:13
    |
 LL |     unsafe_code,
    |     ----------- `forbid` level set here
diff --git a/src/test/ui/lint/reasons.rs b/src/test/ui/lint/reasons.rs
index 9166caf9ebe..eba91d92afb 100644
--- a/src/test/ui/lint/reasons.rs
+++ b/src/test/ui/lint/reasons.rs
@@ -1,5 +1,7 @@
 // compile-pass
 
+#![feature(lint_reasons)]
+
 #![warn(elided_lifetimes_in_paths,
         //~^ NOTE lint level defined here
         reason = "explicit anonymous lifetimes aid reasoning about ownership")]
diff --git a/src/test/ui/lint/reasons.stderr b/src/test/ui/lint/reasons.stderr
index bdaf848c340..df0f9cb9b61 100644
--- a/src/test/ui/lint/reasons.stderr
+++ b/src/test/ui/lint/reasons.stderr
@@ -1,18 +1,18 @@
 warning: hidden lifetime parameters in types are deprecated
-  --> $DIR/reasons.rs:19:29
+  --> $DIR/reasons.rs:21:29
    |
 LL |     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
    |                             ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
    |
    = note: explicit anonymous lifetimes aid reasoning about ownership
 note: lint level defined here
-  --> $DIR/reasons.rs:3:9
+  --> $DIR/reasons.rs:5:9
    |
 LL | #![warn(elided_lifetimes_in_paths,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: variable `Social_exchange_psychology` should have a snake case name such as `social_exchange_psychology`
-  --> $DIR/reasons.rs:28:9
+  --> $DIR/reasons.rs:30:9
    |
 LL |     let Social_exchange_psychology = CheaterDetectionMechanism {};
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,7 +20,7 @@ LL |     let Social_exchange_psychology = CheaterDetectionMechanism {};
    = note: people shouldn't have to change their usual style habits
            to contribute to our project
 note: lint level defined here
-  --> $DIR/reasons.rs:7:5
+  --> $DIR/reasons.rs:9:5
    |
 LL |     nonstandard_style,
    |     ^^^^^^^^^^^^^^^^^