Rollup merge of #54870 - flip1995:stabilize_tool_lints, r=Manishearth

Fixes #47311.
r? @nrc
This commit is contained in:
Manish Goregaokar 2018-10-10 15:59:20 -07:00
commit 50e410c240
13 changed files with 11 additions and 117 deletions

View File

@ -1,35 +0,0 @@
# `tool_lints`
The tracking issue for this feature is: [#44690]
[#44690]: https://github.com/rust-lang/rust/issues/44690
------------------------
Tool lints let you use scoped lints, to `allow`, `warn`, `deny` or `forbid` lints of
certain tools.
Currently `clippy` is the only available lint tool.
It is recommended for lint tools to implement the scoped lints like this:
- `#[_(TOOL_NAME::lintname)]`: for lint names
- `#[_(TOOL_NAME::lintgroup)]`: for groups of lints
- `#[_(TOOL_NAME::all)]`: for (almost[^1]) all lints
## An example
```rust
#![feature(tool_lints)]
#![warn(clippy::pedantic)]
#[allow(clippy::filter_map)]
fn main() {
let v = vec![0; 10];
let _ = v.into_iter().filter(|&x| x < 1).map(|x| x + 1).collect::<Vec<_>>();
println!("No filter_map()!");
}
```
[^1]: Some defined lint groups can be excluded here.

View File

@ -18,11 +18,10 @@ use lint::context::CheckLintNameResult;
use lint::{self, Lint, LintId, Level, LintSource};
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
StableHasher, StableHasherResult};
use session::{config::nightly_options, Session};
use session::Session;
use syntax::ast;
use syntax::attr;
use syntax::source_map::MultiSpan;
use syntax::feature_gate;
use syntax::symbol::Symbol;
use util::nodemap::FxHashMap;
@ -228,18 +227,7 @@ impl<'a> LintLevelsBuilder<'a> {
}
};
let tool_name = if let Some(lint_tool) = word.is_scoped() {
let gate_feature = !self.sess.features_untracked().tool_lints;
let known_tool = attr::is_known_lint_tool(lint_tool);
if gate_feature {
feature_gate::emit_feature_err(
&sess.parse_sess,
"tool_lints",
word.span,
feature_gate::GateIssue::Language,
&format!("scoped lint `{}` is experimental", word.ident),
);
}
if !known_tool {
if !attr::is_known_lint_tool(lint_tool) {
span_err!(
sess,
lint_tool.span,
@ -247,9 +235,6 @@ impl<'a> LintLevelsBuilder<'a> {
"an unknown tool name found in scoped lint: `{}`",
word.ident
);
}
if gate_feature || !known_tool {
continue;
}
@ -299,13 +284,7 @@ impl<'a> LintLevelsBuilder<'a> {
"change it to",
new_lint_name.to_string(),
Applicability::MachineApplicable,
);
if nightly_options::is_nightly_build() {
err.emit();
} else {
err.cancel();
}
).emit();
let src = LintSource::Node(Symbol::intern(&new_lint_name), li.span);
for id in ids {

View File

@ -433,9 +433,6 @@ declare_features! (
// #[doc(alias = "...")]
(active, doc_alias, "1.27.0", Some(50146), None),
// Scoped lints
(active, tool_lints, "1.28.0", Some(44690), None),
// Allows irrefutable patterns in if-let and while-let statements (RFC 2086)
(active, irrefutable_let_patterns, "1.27.0", Some(44495), None),
@ -682,6 +679,8 @@ declare_features! (
(accepted, pattern_parentheses, "1.31.0", Some(51087), None),
// Allows the definition of `const fn` functions.
(accepted, min_const_fn, "1.31.0", Some(53555), None),
// Scoped lints
(accepted, tool_lints, "1.31.0", Some(44690), None),
);
// If you change this, please modify src/doc/unstable-book as well. You must

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tool_lints)]
#![deny(unknown_lints)]
#[allow(clippy::almost_swapped)]

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tool_lints)]
#![feature(rust_2018_preview)]
#![deny(unknown_lints)]

View File

@ -11,8 +11,8 @@
// aux-build:lint_tool_test.rs
// ignore-stage1
// compile-flags: --cfg foo
#![feature(plugin)]
#![feature(tool_lints)]
#![plugin(lint_tool_test)]
#![allow(dead_code)]
#![cfg_attr(foo, warn(test_lint))]

View File

@ -1,12 +0,0 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[warn(clippy::assign_ops)] //~ ERROR scoped lint `clippy::assign_ops` is experimental
fn main() {}

View File

@ -1,11 +0,0 @@
error[E0658]: scoped lint `clippy::assign_ops` is experimental (see issue #44690)
--> $DIR/feature-gate-tool_lints-fail.rs:11:8
|
LL | #[warn(clippy::assign_ops)] //~ ERROR scoped lint `clippy::assign_ops` is experimental
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(tool_lints)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,15 +0,0 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[warn(clippy::decimal_literal_representation)]
//~^ ERROR scoped lint `clippy::decimal_literal_representation` is experimental
fn main() {
let a = 65_535;
}

View File

@ -1,11 +0,0 @@
error[E0658]: scoped lint `clippy::decimal_literal_representation` is experimental (see issue #44690)
--> $DIR/feature-gate-tool_lints.rs:11:8
|
LL | #[warn(clippy::decimal_literal_representation)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(tool_lints)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -10,7 +10,7 @@
// Don't allow tool_lints, which aren't scoped
#![feature(tool_lints)]
#![deny(unknown_lints)]
#![deny(clippy)] //~ ERROR: unknown lint: `clippy`

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tool_lints)]
#[warn(foo::bar)]
//~^ ERROR an unknown tool name found in scoped lint: `foo::bar`

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tool_lints)]
#![deny(foo::bar)] //~ ERROR an unknown tool name found in scoped lint: `foo::bar`