From 7de6f5472812a7dde8ffba399b71a3c558cd44bf Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 24 Jun 2019 10:43:51 +0200 Subject: [PATCH] Turn internal lints into tool lints --- src/bootstrap/bin/rustc.rs | 8 +++++-- src/librustc/lint/context.rs | 4 ++-- src/librustc/lint/internal.rs | 22 +++++++++---------- src/librustc/ty/mod.rs | 2 +- src/librustc_data_structures/lib.rs | 2 +- src/librustc_macros/src/lib.rs | 2 +- src/libsyntax/attr/mod.rs | 2 +- .../ui-fulldeps/auxiliary/lint-tool-test.rs | 12 +++++++--- .../internal-lints/default_hash_types.rs | 2 +- .../internal-lints/default_hash_types.stderr | 4 ++-- .../lint_pass_impl_without_macro.rs | 2 +- .../lint_pass_impl_without_macro.stderr | 4 ++-- .../internal-lints/pass_ty_by_ref.rs | 2 +- .../internal-lints/pass_ty_by_ref.stderr | 4 ++-- .../internal-lints/qualified_ty_ty_ctxt.rs | 2 +- .../qualified_ty_ty_ctxt.stderr | 4 ++-- .../internal-lints/ty_tykind_usage.rs | 2 +- .../internal-lints/ty_tykind_usage.stderr | 4 ++-- 18 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 5b5e9e0def2..a1333ff3dc7 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -306,10 +306,14 @@ fn main() { } // This is required for internal lints. + cmd.arg("-Zunstable-options"); if let Some(crate_name) = args.windows(2).find(|a| &*a[0] == "--crate-name") { let crate_name = crate_name[1].to_string_lossy(); - if crate_name.starts_with("rustc") || crate_name.starts_with("syntax") { - cmd.arg("-Zunstable-options"); + if crate_name.starts_with("rustc") + || crate_name.starts_with("syntax") + || crate_name == "arena" + || crate_name == "fmt_macros" + { if stage != "0" { cmd.arg("-Wrustc::internal"); } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7203dd9beaa..950f7ad2e08 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1341,7 +1341,7 @@ struct LateLintPassObjects<'a> { lints: &'a mut [LateLintPassObject], } -#[cfg_attr(not(stage0), allow(lint_pass_impl_without_macro))] +#[cfg_attr(not(bootstrap), allow(rustc::lint_pass_impl_without_macro))] impl LintPass for LateLintPassObjects<'_> { fn name(&self) -> &'static str { panic!() @@ -1511,7 +1511,7 @@ struct EarlyLintPassObjects<'a> { lints: &'a mut [EarlyLintPassObject], } -#[cfg_attr(not(stage0), allow(lint_pass_impl_without_macro))] +#[cfg_attr(not(bootstrap), allow(rustc::lint_pass_impl_without_macro))] impl LintPass for EarlyLintPassObjects<'_> { fn name(&self) -> &'static str { panic!() diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index e458e07cda4..34899736949 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -11,8 +11,8 @@ use syntax::ast::{Ident, Item, ItemKind}; use syntax::symbol::{sym, Symbol}; use syntax_pos::ExpnInfo; -declare_lint! { - pub DEFAULT_HASH_TYPES, +declare_tool_lint! { + pub rustc::DEFAULT_HASH_TYPES, Allow, "forbid HashMap and HashSet and suggest the FxHash* variants" } @@ -23,7 +23,7 @@ pub struct DefaultHashTypes { impl DefaultHashTypes { // we are allowed to use `HashMap` and `HashSet` as identifiers for implementing the lint itself - #[allow(default_hash_types)] + #[cfg_attr(not(bootstrap), allow(rustc::default_hash_types))] pub fn new() -> Self { let mut map = FxHashMap::default(); map.insert(sym::HashMap, sym::FxHashMap); @@ -51,20 +51,20 @@ impl EarlyLintPass for DefaultHashTypes { } } -declare_lint! { - pub USAGE_OF_TY_TYKIND, +declare_tool_lint! { + pub rustc::USAGE_OF_TY_TYKIND, Allow, "usage of `ty::TyKind` outside of the `ty::sty` module" } -declare_lint! { - pub TY_PASS_BY_REFERENCE, +declare_tool_lint! { + pub rustc::TY_PASS_BY_REFERENCE, Allow, "passing `Ty` or `TyCtxt` by reference" } -declare_lint! { - pub USAGE_OF_QUALIFIED_TY, +declare_tool_lint! { + pub rustc::USAGE_OF_QUALIFIED_TY, Allow, "using `ty::{Ty,TyCtxt}` instead of importing it" } @@ -215,8 +215,8 @@ fn gen_args(segment: &PathSegment) -> String { String::new() } -declare_lint! { - pub LINT_PASS_IMPL_WITHOUT_MACRO, +declare_tool_lint! { + pub rustc::LINT_PASS_IMPL_WITHOUT_MACRO, Allow, "`impl LintPass` without the `declare_lint_pass!` or `impl_lint_pass!` macros" } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index ad988072512..796b2b3c1a1 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1,6 +1,6 @@ // ignore-tidy-filelength -#![allow(usage_of_ty_tykind)] +#![cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] pub use self::Variance::*; pub use self::AssocItemContainer::*; diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 96fb8deb2cf..7609e9591fb 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -27,7 +27,7 @@ #![cfg_attr(test, feature(test))] #![deny(rust_2018_idioms)] -#![allow(default_hash_types)] +#![cfg_attr(not(bootstrap), allow(rustc::default_hash_types))] #[macro_use] extern crate log; diff --git a/src/librustc_macros/src/lib.rs b/src/librustc_macros/src/lib.rs index cc85ef6717e..28996f93312 100644 --- a/src/librustc_macros/src/lib.rs +++ b/src/librustc_macros/src/lib.rs @@ -1,6 +1,6 @@ #![feature(proc_macro_hygiene)] #![deny(rust_2018_idioms)] -#![allow(default_hash_types)] +#![cfg_attr(not(bootstrap), allow(rustc::default_hash_types))] extern crate proc_macro; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 436620ae729..08bea08c257 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -60,7 +60,7 @@ pub fn is_known(attr: &Attribute) -> bool { } pub fn is_known_lint_tool(m_item: Ident) -> bool { - ["clippy"].contains(&m_item.as_str().as_ref()) + ["clippy", "rustc"].contains(&m_item.as_str().as_ref()) } impl NestedMetaItem { diff --git a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs index 64664377cd9..2a57876f464 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs @@ -8,8 +8,7 @@ extern crate syntax; extern crate rustc; extern crate rustc_plugin; -use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass, - LintArray}; +use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; use rustc_plugin::Registry; use syntax::ast; declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff"); @@ -19,7 +18,14 @@ declare_tool_lint!( Warn, "Warn about other stuff" ); -declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP]); +declare_tool_lint!( + /// Some docs + pub rustc::TEST_RUSTC_TOOL_LINT, + Deny, + "Deny internal stuff" +); + +declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]); impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { diff --git a/src/test/ui-fulldeps/internal-lints/default_hash_types.rs b/src/test/ui-fulldeps/internal-lints/default_hash_types.rs index 3264099c876..3786c6de7e7 100644 --- a/src/test/ui-fulldeps/internal-lints/default_hash_types.rs +++ b/src/test/ui-fulldeps/internal-lints/default_hash_types.rs @@ -7,7 +7,7 @@ extern crate rustc_data_structures; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use std::collections::{HashMap, HashSet}; -#[deny(default_hash_types)] +#[deny(rustc::default_hash_types)] fn main() { let _map: HashMap = HashMap::default(); //~^ ERROR Prefer FxHashMap over HashMap, it has better performance diff --git a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr index 64f322cb0c1..c1762d31323 100644 --- a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr +++ b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr @@ -7,8 +7,8 @@ LL | let _map: HashMap = HashMap::default(); note: lint level defined here --> $DIR/default_hash_types.rs:10:8 | -LL | #[deny(default_hash_types)] - | ^^^^^^^^^^^^^^^^^^ +LL | #[deny(rustc::default_hash_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary error: Prefer FxHashMap over HashMap, it has better performance diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs index 89fa838768e..48dd5b122b5 100644 --- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs @@ -1,7 +1,7 @@ // compile-flags: -Z unstable-options #![feature(rustc_private)] -#![deny(lint_pass_impl_without_macro)] +#![deny(rustc::lint_pass_impl_without_macro)] extern crate rustc; diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr index a033b0a07e0..b439ae2cd14 100644 --- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr @@ -7,8 +7,8 @@ LL | impl LintPass for Foo { note: lint level defined here --> $DIR/lint_pass_impl_without_macro.rs:4:9 | -LL | #![deny(lint_pass_impl_without_macro)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustc::lint_pass_impl_without_macro)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead error: implementing `LintPass` by hand diff --git a/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs index 9534ddbbc64..7564c024580 100644 --- a/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs +++ b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs @@ -1,7 +1,7 @@ // compile-flags: -Z unstable-options #![feature(rustc_private)] -#![deny(ty_pass_by_reference)] +#![deny(rustc::ty_pass_by_reference)] #![allow(unused)] extern crate rustc; diff --git a/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr index 0f9f24b98a0..d2ed6b6a19c 100644 --- a/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr +++ b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr @@ -7,8 +7,8 @@ LL | ty_ref: &Ty<'_>, note: lint level defined here --> $DIR/pass_ty_by_ref.rs:4:9 | -LL | #![deny(ty_pass_by_reference)] - | ^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustc::ty_pass_by_reference)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: passing `TyCtxt<'_>` by reference --> $DIR/pass_ty_by_ref.rs:15:18 diff --git a/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs index 56033100344..0040230ec7d 100644 --- a/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs +++ b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs @@ -1,7 +1,7 @@ // compile-flags: -Z unstable-options #![feature(rustc_private)] -#![deny(usage_of_qualified_ty)] +#![deny(rustc::usage_of_qualified_ty)] #![allow(unused)] extern crate rustc; diff --git a/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr index c3642e6a4ba..72c23f8cd3c 100644 --- a/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr +++ b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr @@ -7,8 +7,8 @@ LL | ty_q: ty::Ty<'_>, note: lint level defined here --> $DIR/qualified_ty_ty_ctxt.rs:4:9 | -LL | #![deny(usage_of_qualified_ty)] - | ^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustc::usage_of_qualified_ty)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of qualified `ty::TyCtxt<'_>` --> $DIR/qualified_ty_ty_ctxt.rs:27:16 diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs index dba0db69b7f..c6bd122f4e5 100644 --- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs @@ -6,7 +6,7 @@ extern crate rustc; use rustc::ty::{self, Ty, TyKind}; -#[deny(usage_of_ty_tykind)] +#[deny(rustc::usage_of_ty_tykind)] fn main() { let sty = TyKind::Bool; //~ ERROR usage of `ty::TyKind::` diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr index 10229a331c2..8add4252c41 100644 --- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr @@ -7,8 +7,8 @@ LL | let sty = TyKind::Bool; note: lint level defined here --> $DIR/ty_tykind_usage.rs:9:8 | -LL | #[deny(usage_of_ty_tykind)] - | ^^^^^^^^^^^^^^^^^^ +LL | #[deny(rustc::usage_of_ty_tykind)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:14:9