Skip to content

Commit 48be29e

Browse files
committed
feature-gate lint reasons
We take stability seriously, so we shy away from making even seemingly "trivial" features insta-stable.
1 parent 16e3ea2 commit 48be29e

10 files changed

+48
-12
lines changed

src/librustc/lint/levels.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,23 @@ impl<'a> LintLevelsBuilder<'a> {
225225
match item.node {
226226
ast::MetaItemKind::Word => {} // actual lint names handled later
227227
ast::MetaItemKind::NameValue(ref name_value) => {
228+
let gate_reasons = !self.sess.features_untracked().lint_reasons;
228229
let name_ident = item.ident.segments[0].ident;
229230
let name = name_ident.name.as_str();
231+
230232
if name == "reason" {
231233
if let ast::LitKind::Str(rationale, _) = name_value.node {
232-
reason = Some(rationale);
234+
if gate_reasons {
235+
feature_gate::emit_feature_err(
236+
&self.sess.parse_sess,
237+
"lint_reasons",
238+
item.span,
239+
feature_gate::GateIssue::Language,
240+
"lint reasons are experimental"
241+
);
242+
} else {
243+
reason = Some(rationale);
244+
}
233245
} else {
234246
let mut err = bad_attr(name_value.span);
235247
err.help("reason must be a string literal");

src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ declare_features! (
502502

503503
// Allows `const _: TYPE = VALUE`
504504
(active, underscore_const_names, "1.31.0", Some(54912), None),
505+
506+
// `reason = ` in lint attributes and `expect` lint attribute
507+
(active, lint_reasons, "1.31.0", Some(54503), None),
505508
);
506509

507510
declare_features! (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![warn(nonstandard_style, reason = "the standard should be respected")]
2+
//~^ ERROR lint reasons are experimental
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: lint reasons are experimental (see issue #54503)
2+
--> $DIR/feature-gate-lint-reasons.rs:1:28
3+
|
4+
LL | #![warn(nonstandard_style, reason = "the standard should be respected")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add #![feature(lint_reasons)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/lint/reasons-erroneous.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(lint_reasons)]
2+
13
#![warn(absolute_paths_not_starting_with_crate, reason = 0)]
24
//~^ ERROR malformed lint attribute
35
//~| HELP reason must be a string literal

src/test/ui/lint/reasons-erroneous.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
error[E0452]: malformed lint attribute
2-
--> $DIR/reasons-erroneous.rs:1:58
2+
--> $DIR/reasons-erroneous.rs:3:58
33
|
44
LL | #![warn(absolute_paths_not_starting_with_crate, reason = 0)]
55
| ^
66
|
77
= help: reason must be a string literal
88

99
error[E0452]: malformed lint attribute
10-
--> $DIR/reasons-erroneous.rs:4:40
10+
--> $DIR/reasons-erroneous.rs:6:40
1111
|
1212
LL | #![warn(anonymous_parameters, reason = b"consider these, for we have condemned them")]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
|
1515
= help: reason must be a string literal
1616

1717
error[E0452]: malformed lint attribute
18-
--> $DIR/reasons-erroneous.rs:7:29
18+
--> $DIR/reasons-erroneous.rs:9:29
1919
|
2020
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222

2323
error[E0452]: malformed lint attribute
24-
--> $DIR/reasons-erroneous.rs:9:23
24+
--> $DIR/reasons-erroneous.rs:11:23
2525
|
2626
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2828

2929
error[E0452]: malformed lint attribute
30-
--> $DIR/reasons-erroneous.rs:11:36
30+
--> $DIR/reasons-erroneous.rs:13:36
3131
|
3232
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434

3535
warning: unknown lint: `reason`
36-
--> $DIR/reasons-erroneous.rs:13:44
36+
--> $DIR/reasons-erroneous.rs:15:44
3737
|
3838
LL | #![warn(ellipsis_inclusive_range_patterns, reason)]
3939
| ^^^^^^

src/test/ui/lint/reasons-forbidden.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(lint_reasons)]
2+
13
#![forbid(
24
unsafe_code,
35
//~^ NOTE `forbid` level set here

src/test/ui/lint/reasons-forbidden.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0453]: allow(unsafe_code) overruled by outer forbid(unsafe_code)
2-
--> $DIR/reasons-forbidden.rs:12:13
2+
--> $DIR/reasons-forbidden.rs:14:13
33
|
44
LL | unsafe_code,
55
| ----------- `forbid` level set here

src/test/ui/lint/reasons.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// compile-pass
22

3+
#![feature(lint_reasons)]
4+
35
#![warn(elided_lifetimes_in_paths,
46
//~^ NOTE lint level defined here
57
reason = "explicit anonymous lifetimes aid reasoning about ownership")]

src/test/ui/lint/reasons.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
warning: hidden lifetime parameters in types are deprecated
2-
--> $DIR/reasons.rs:19:29
2+
--> $DIR/reasons.rs:21:29
33
|
44
LL | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
55
| ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
66
|
77
= note: explicit anonymous lifetimes aid reasoning about ownership
88
note: lint level defined here
9-
--> $DIR/reasons.rs:3:9
9+
--> $DIR/reasons.rs:5:9
1010
|
1111
LL | #![warn(elided_lifetimes_in_paths,
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1313

1414
warning: variable `Social_exchange_psychology` should have a snake case name such as `social_exchange_psychology`
15-
--> $DIR/reasons.rs:28:9
15+
--> $DIR/reasons.rs:30:9
1616
|
1717
LL | let Social_exchange_psychology = CheaterDetectionMechanism {};
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
|
2020
= note: people shouldn't have to change their usual style habits
2121
to contribute to our project
2222
note: lint level defined here
23-
--> $DIR/reasons.rs:7:5
23+
--> $DIR/reasons.rs:9:5
2424
|
2525
LL | nonstandard_style,
2626
| ^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)