From 7d0a952e465b6584d2a86d2fca3c8a4b077567cd Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 2 May 2019 16:53:12 +0200 Subject: [PATCH 1/8] Implement initernal lint LINT_PASS_IMPL_WITHOUT_MACRO --- src/librustc/lint/context.rs | 2 + src/librustc/lint/internal.rs | 50 ++++++++++++------- src/librustc_lint/lib.rs | 2 + .../lint_pass_impl_without_macro.rs | 35 +++++++++++++ .../lint_pass_impl_without_macro.stderr | 15 ++++++ 5 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs create mode 100644 src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7f09120bbdd..7203dd9beaa 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1341,6 +1341,7 @@ struct LateLintPassObjects<'a> { lints: &'a mut [LateLintPassObject], } +#[cfg_attr(not(stage0), allow(lint_pass_impl_without_macro))] impl LintPass for LateLintPassObjects<'_> { fn name(&self) -> &'static str { panic!() @@ -1510,6 +1511,7 @@ struct EarlyLintPassObjects<'a> { lints: &'a mut [EarlyLintPassObject], } +#[cfg_attr(not(stage0), allow(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 86dae579ca7..d3996c4e37a 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -7,7 +7,7 @@ use crate::lint::{ }; use errors::Applicability; use rustc_data_structures::fx::FxHashMap; -use syntax::ast::Ident; +use syntax::ast::{Ident, Item, ItemKind}; use syntax::symbol::{sym, Symbol}; declare_lint! { @@ -36,10 +36,7 @@ impl_lint_pass!(DefaultHashTypes => [DEFAULT_HASH_TYPES]); impl EarlyLintPass for DefaultHashTypes { fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) { if let Some(replace) = self.map.get(&ident.name) { - let msg = format!( - "Prefer {} over {}, it has better performance", - replace, ident - ); + let msg = format!("Prefer {} over {}, it has better performance", replace, ident); let mut db = cx.struct_span_lint(DEFAULT_HASH_TYPES, ident.span, &msg); db.span_suggestion( ident.span, @@ -47,11 +44,8 @@ impl EarlyLintPass for DefaultHashTypes { replace.to_string(), Applicability::MaybeIncorrect, // FxHashMap, ... needs another import ); - db.note(&format!( - "a `use rustc_data_structures::fx::{}` may be necessary", - replace - )) - .emit(); + db.note(&format!("a `use rustc_data_structures::fx::{}` may be necessary", replace)) + .emit(); } } } @@ -137,13 +131,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind { } } } - TyKind::Rptr( - _, - MutTy { - ty: inner_ty, - mutbl: Mutability::MutImmutable, - }, - ) => { + TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::MutImmutable }) => { if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) { if cx.tcx.impl_trait_ref(impl_did).is_some() { return; @@ -225,3 +213,31 @@ fn gen_args(segment: &PathSegment) -> String { String::new() } + +declare_lint! { + pub LINT_PASS_IMPL_WITHOUT_MACRO, + Allow, + "`impl LintPass` without the `declare_lint_pass!` or `impl_lint_pass!` macros" +} + +declare_lint_pass!(LintPassImpl => [LINT_PASS_IMPL_WITHOUT_MACRO]); + +impl EarlyLintPass for LintPassImpl { + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + if let ItemKind::Impl(_, _, _, _, Some(lint_pass), _, _) = &item.node { + if !lint_pass.path.span.ctxt().outer_expn_info().is_some() { + if let Some(last) = lint_pass.path.segments.last() { + if last.ident.as_str() == "LintPass" { + cx.struct_span_lint( + LINT_PASS_IMPL_WITHOUT_MACRO, + lint_pass.path.span, + "implementing `LintPass` by hand", + ) + .help("try using `declare_lint_pass!` or `impl_lint_pass!` instead") + .emit(); + } + } + } + } + } +} diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index ec8a9c6fbb2..8a5fde322b2 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -493,6 +493,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { store.register_early_pass(sess, false, false, box DefaultHashTypes::new()); + store.register_early_pass(sess, false, false, box LintPassImpl); store.register_late_pass(sess, false, false, false, box TyTyKind); store.register_group( sess, @@ -502,6 +503,7 @@ pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { vec![ LintId::of(DEFAULT_HASH_TYPES), LintId::of(USAGE_OF_TY_TYKIND), + LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO), LintId::of(TY_PASS_BY_REFERENCE), LintId::of(USAGE_OF_QUALIFIED_TY), ], 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 new file mode 100644 index 00000000000..92f8e8364a7 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs @@ -0,0 +1,35 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_private)] +#![deny(lint_pass_impl_without_macro)] + +extern crate rustc; + +use rustc::lint::{LintArray, LintPass}; +use rustc::{declare_lint, declare_lint_pass, impl_lint_pass, lint_array}; + +declare_lint! { + pub TEST_LINT, + Allow, + "test" +} + +struct Foo; + +impl LintPass for Foo { //~ERROR implementing `LintPass` by hand + fn get_lints(&self) -> LintArray { + lint_array!(TEST_LINT) + } + + fn name(&self) -> &'static str { + "Foo" + } +} + +struct Bar; + +impl_lint_pass!(Bar => [TEST_LINT]); + +declare_lint_pass!(Baz => [TEST_LINT]); + +fn main() {} 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 new file mode 100644 index 00000000000..9ddd6af472a --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr @@ -0,0 +1,15 @@ +error: implementing `LintPass` by hand + --> $DIR/lint_pass_impl_without_macro.rs:19:6 + | +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)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead + +error: aborting due to previous error + From 37f09cb237ebbabdd6889d3c3d707075b8acc29d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 13 Jun 2019 15:49:33 +0200 Subject: [PATCH 2/8] Only allow {declare,impl}_lint_pass macros for implementing LintPass --- src/librustc/lint/internal.rs | 34 +++++++++++++------ src/libsyntax_pos/symbol.rs | 3 ++ .../lint_pass_impl_without_macro.rs | 18 ++++++++++ .../lint_pass_impl_without_macro.stderr | 13 ++++++- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index d3996c4e37a..9763801f0d9 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -9,6 +9,7 @@ use errors::Applicability; use rustc_data_structures::fx::FxHashMap; use syntax::ast::{Ident, Item, ItemKind}; use syntax::symbol::{sym, Symbol}; +use syntax_pos::ExpnInfo; declare_lint! { pub DEFAULT_HASH_TYPES, @@ -225,19 +226,32 @@ declare_lint_pass!(LintPassImpl => [LINT_PASS_IMPL_WITHOUT_MACRO]); impl EarlyLintPass for LintPassImpl { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { if let ItemKind::Impl(_, _, _, _, Some(lint_pass), _, _) = &item.node { - if !lint_pass.path.span.ctxt().outer_expn_info().is_some() { - if let Some(last) = lint_pass.path.segments.last() { - if last.ident.as_str() == "LintPass" { - cx.struct_span_lint( - LINT_PASS_IMPL_WITHOUT_MACRO, - lint_pass.path.span, - "implementing `LintPass` by hand", - ) - .help("try using `declare_lint_pass!` or `impl_lint_pass!` instead") - .emit(); + if let Some(last) = lint_pass.path.segments.last() { + if last.ident.name == sym::LintPass { + match &lint_pass.path.span.ctxt().outer_expn_info() { + Some(info) if is_lint_pass_expansion(info) => {} + _ => { + cx.struct_span_lint( + LINT_PASS_IMPL_WITHOUT_MACRO, + lint_pass.path.span, + "implementing `LintPass` by hand", + ) + .help("try using `declare_lint_pass!` or `impl_lint_pass!` instead") + .emit(); + } } } } } } } + +fn is_lint_pass_expansion(expn_info: &ExpnInfo) -> bool { + if expn_info.format.name() == sym::impl_lint_pass { + true + } else if let Some(info) = expn_info.call_site.ctxt().outer_expn_info() { + info.format.name() == sym::declare_lint_pass + } else { + false + } +} diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 756bc8c29d8..4b8535fa625 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -214,6 +214,7 @@ symbols! { custom_inner_attributes, custom_test_frameworks, c_variadic, + declare_lint_pass, decl_macro, Default, default_lib_allocator, @@ -324,6 +325,7 @@ symbols! { if_while_or_patterns, ignore, impl_header_lifetime_elision, + impl_lint_pass, impl_trait_in_bindings, import_shadowing, index, @@ -365,6 +367,7 @@ symbols! { link_llvm_intrinsics, link_name, link_section, + LintPass, lint_reasons, literal, local_inner_macros, 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 92f8e8364a7..89fa838768e 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 @@ -26,6 +26,24 @@ impl LintPass for Foo { //~ERROR implementing `LintPass` by hand } } +macro_rules! custom_lint_pass_macro { + () => { + struct Custom; + + impl LintPass for Custom { //~ERROR implementing `LintPass` by hand + fn get_lints(&self) -> LintArray { + lint_array!(TEST_LINT) + } + + fn name(&self) -> &'static str { + "Custom" + } + } + }; +} + +custom_lint_pass_macro!(); + struct Bar; impl_lint_pass!(Bar => [TEST_LINT]); 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 9ddd6af472a..a033b0a07e0 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 @@ -11,5 +11,16 @@ LL | #![deny(lint_pass_impl_without_macro)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead -error: aborting due to previous error +error: implementing `LintPass` by hand + --> $DIR/lint_pass_impl_without_macro.rs:33:14 + | +LL | impl LintPass for Custom { + | ^^^^^^^^ +... +LL | custom_lint_pass_macro!(); + | -------------------------- in this macro invocation + | + = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead + +error: aborting due to 2 previous errors From 084c829fb8ee8fc4410169cde0d029b8214e38e0 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 17 Jun 2019 17:04:40 +0200 Subject: [PATCH 3/8] Enable internal lints in bootstrap --- src/bootstrap/bin/rustc.rs | 8 +++++++- src/libarena/lib.rs | 1 - src/libfmt_macros/lib.rs | 1 - src/librustc/lib.rs | 1 - src/librustc_allocator/lib.rs | 1 - src/librustc_borrowck/lib.rs | 1 - src/librustc_codegen_llvm/lib.rs | 1 - src/librustc_codegen_ssa/lib.rs | 1 - src/librustc_codegen_utils/lib.rs | 1 - src/librustc_driver/lib.rs | 1 - src/librustc_errors/lib.rs | 1 - src/librustc_incremental/lib.rs | 1 - src/librustc_interface/lib.rs | 1 - src/librustc_lint/lib.rs | 1 - src/librustc_metadata/lib.rs | 1 - src/librustc_mir/lib.rs | 1 - src/librustc_passes/lib.rs | 1 - src/librustc_privacy/lib.rs | 1 - src/librustc_resolve/lib.rs | 1 - src/librustc_save_analysis/lib.rs | 1 - src/librustc_target/lib.rs | 1 - src/librustc_traits/lib.rs | 1 - src/librustc_typeck/lib.rs | 1 - src/librustdoc/lib.rs | 1 - src/libsyntax/lib.rs | 1 - src/libsyntax_ext/lib.rs | 1 - src/libsyntax_pos/lib.rs | 1 - 27 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 595deb07ec8..34bd62d300d 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -306,7 +306,13 @@ 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"); + cmd.arg("-Winternal"); + } + } // Force all crates compiled by this compiler to (a) be unstable and (b) // allow the `rustc_private` feature to link to other unstable crates diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 3d16e335cd8..a4c6e5b85f9 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -12,7 +12,6 @@ test(no_crate_inject, attr(deny(warnings))))] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(core_intrinsics)] diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index f6e9143dd05..39f130b82ed 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -9,7 +9,6 @@ test(attr(deny(warnings))))] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(nll)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 257d5159f11..4b58f05bd2e 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -29,7 +29,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(arbitrary_self_types)] diff --git a/src/librustc_allocator/lib.rs b/src/librustc_allocator/lib.rs index e7a70895a30..8d380c47bc4 100644 --- a/src/librustc_allocator/lib.rs +++ b/src/librustc_allocator/lib.rs @@ -2,7 +2,6 @@ #![feature(rustc_private)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] pub mod expand; diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index 98e629ce046..b857c625ec2 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -2,7 +2,6 @@ #![allow(non_camel_case_types)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(in_band_lifetimes)] diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 7283aa95b30..2863dacb815 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -22,7 +22,6 @@ #![feature(static_nobundle)] #![feature(trusted_len)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] use back::write::{create_target_machine, create_informational_target_machine}; diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index b76f098773f..3e8bd4ca0b8 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -13,7 +13,6 @@ #![allow(unused_attributes)] #![allow(dead_code)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![recursion_limit="256"] diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 942c2d13fac..f38b672afd9 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -17,7 +17,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 5fb6ed31b06..1cbc542b9ab 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -17,7 +17,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] pub extern crate getopts; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 05cee6dff23..03869e07f55 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -10,7 +10,6 @@ #![feature(nll)] #![feature(optin_builtin_traits)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[allow(unused_extern_crates)] diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index ffea495d3eb..569aa78c9d4 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -9,7 +9,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] extern crate rustc; diff --git a/src/librustc_interface/lib.rs b/src/librustc_interface/lib.rs index 7fc311d40c3..4bc50c24e81 100644 --- a/src/librustc_interface/lib.rs +++ b/src/librustc_interface/lib.rs @@ -7,7 +7,6 @@ #![cfg_attr(unix, feature(libc))] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![allow(unused_imports)] diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 8a5fde322b2..d3e35589652 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -20,7 +20,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index e49ca8acf67..826349362db 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -15,7 +15,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] extern crate libc; diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index cb02e1a778c..d118d66326c 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -28,7 +28,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] extern crate log; diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index 5f3d7159be6..0a96ad3e344 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -14,7 +14,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 0fdc9ac8903..c0cebfe8153 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1,7 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(in_band_lifetimes)] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 3b418d0dbb6..13afc0f006c 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -11,7 +11,6 @@ #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] pub use rustc::hir::def::{Namespace, PerNS}; diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 23fe150c6ff..1294404d098 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -1,7 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(nll)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![allow(unused_attributes)] diff --git a/src/librustc_target/lib.rs b/src/librustc_target/lib.rs index 1bebe420251..b65813fd8e3 100644 --- a/src/librustc_target/lib.rs +++ b/src/librustc_target/lib.rs @@ -16,7 +16,6 @@ #![feature(step_trait)] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] extern crate log; diff --git a/src/librustc_traits/lib.rs b/src/librustc_traits/lib.rs index 7311fd96dad..12b19a2648d 100644 --- a/src/librustc_traits/lib.rs +++ b/src/librustc_traits/lib.rs @@ -2,7 +2,6 @@ //! the guts are broken up into modules; see the comments in those modules. #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(crate_visibility_modifier)] diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index ec0f431d9b2..7063dbbd4b4 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -73,7 +73,6 @@ This API is completely unstable and subject to change. #![recursion_limit="256"] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #[macro_use] extern crate log; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 7a8b088020c..f2e9fc29668 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -1,5 +1,4 @@ #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/", diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 337b8424736..baaaa63f287 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -8,7 +8,6 @@ test(attr(deny(warnings))))] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(bind_by_move_pattern_guards)] diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index b868f5b273c..77b69ddd303 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -3,7 +3,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(in_band_lifetimes)] diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 2dd409bf5be..07b9f609320 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -7,7 +7,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![deny(rust_2018_idioms)] -#![deny(internal)] #![deny(unused_lifetimes)] #![feature(const_fn)] From 65c81dee75a39dc990485f181e3eaf055dc37fa4 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 17 Jun 2019 17:05:45 +0200 Subject: [PATCH 4/8] Allow default_hash_types in some crates --- src/librustc/lint/internal.rs | 2 +- src/librustc_data_structures/lib.rs | 1 + src/librustc_macros/src/lib.rs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index 9763801f0d9..e458e07cda4 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -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(internal)] + #[allow(default_hash_types)] pub fn new() -> Self { let mut map = FxHashMap::default(); map.insert(sym::HashMap, sym::FxHashMap); diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index a1d7ab8856d..96fb8deb2cf 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -27,6 +27,7 @@ #![cfg_attr(test, feature(test))] #![deny(rust_2018_idioms)] +#![allow(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 98fba55218f..cc85ef6717e 100644 --- a/src/librustc_macros/src/lib.rs +++ b/src/librustc_macros/src/lib.rs @@ -1,5 +1,6 @@ #![feature(proc_macro_hygiene)] #![deny(rust_2018_idioms)] +#![allow(default_hash_types)] extern crate proc_macro; From 08b81f2d070fdeb5364c96ccb2fdd8d992dff955 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 17 Jun 2019 17:06:11 +0200 Subject: [PATCH 5/8] Rename internal -> rustc::internal --- src/bootstrap/bin/rustc.rs | 4 +++- src/librustc_lint/lib.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 34bd62d300d..5b5e9e0def2 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -310,7 +310,9 @@ fn main() { let crate_name = crate_name[1].to_string_lossy(); if crate_name.starts_with("rustc") || crate_name.starts_with("syntax") { cmd.arg("-Zunstable-options"); - cmd.arg("-Winternal"); + if stage != "0" { + cmd.arg("-Wrustc::internal"); + } } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index d3e35589652..8053c73849d 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -497,7 +497,7 @@ pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { store.register_group( sess, false, - "internal", + "rustc::internal", None, vec![ LintId::of(DEFAULT_HASH_TYPES), From 7de6f5472812a7dde8ffba399b71a3c558cd44bf Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 24 Jun 2019 10:43:51 +0200 Subject: [PATCH 6/8] 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 From 8e087cdd98850f9bdb998ddfa6c4dfe2d4553260 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 24 Jun 2019 18:14:04 +0200 Subject: [PATCH 7/8] Use symbols in lint tool list --- src/bootstrap/bin/rustc.rs | 11 ++++++----- src/libsyntax/attr/mod.rs | 2 +- src/libsyntax_pos/symbol.rs | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index a1333ff3dc7..242074fec77 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -306,14 +306,15 @@ 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") - || crate_name == "arena" - || crate_name == "fmt_macros" + if crate_name != "rustc_version" + && (crate_name.starts_with("rustc") + || crate_name.starts_with("syntax") + || crate_name == "arena" + || crate_name == "fmt_macros") { + cmd.arg("-Zunstable-options"); if stage != "0" { cmd.arg("-Wrustc::internal"); } diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 08bea08c257..21e0f60a2e7 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", "rustc"].contains(&m_item.as_str().as_ref()) + [sym::clippy, sym::rustc].contains(&m_item.name) } impl NestedMetaItem { diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 4b8535fa625..554512b23bc 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -173,6 +173,7 @@ symbols! { cfg_target_thread_local, cfg_target_vendor, char, + clippy, clone, Clone, clone_closures, From d0625a380b03e83fcfc2f0230986186992d13c71 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 24 Jun 2019 18:14:53 +0200 Subject: [PATCH 8/8] Allow usage_of_ty_tykind only in sty and in some special cases --- src/librustc/ty/codec.rs | 2 ++ src/librustc/ty/context.rs | 3 +++ src/librustc/ty/flags.rs | 2 ++ src/librustc/ty/mod.rs | 37 ++++++++++++++++++------------------- src/librustc/ty/sty.rs | 2 ++ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs index 224f7d5f28d..26e7cc9004d 100644 --- a/src/librustc/ty/codec.rs +++ b/src/librustc/ty/codec.rs @@ -27,6 +27,7 @@ pub trait EncodableWithShorthand: Clone + Eq + Hash { fn variant(&self) -> &Self::Variant; } +#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] impl<'tcx> EncodableWithShorthand for Ty<'tcx> { type Variant = ty::TyKind<'tcx>; fn variant(&self) -> &Self::Variant { @@ -159,6 +160,7 @@ where Ok(decoder.map_encoded_cnum_to_current(cnum)) } +#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] #[inline] pub fn decode_ty(decoder: &mut D) -> Result, D::Error> where diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 28399ed5439..a00eed3fdda 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -135,6 +135,7 @@ impl<'tcx> CtxtInterners<'tcx> { } /// Intern a type + #[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] #[inline(never)] fn intern_ty( local: &CtxtInterners<'tcx>, @@ -2195,6 +2196,7 @@ impl<'tcx> Hash for Interned<'tcx, TyS<'tcx>> { } } +#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] impl<'tcx> Borrow> for Interned<'tcx, TyS<'tcx>> { fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> { &self.0.sty @@ -2429,6 +2431,7 @@ impl<'tcx> TyCtxt<'tcx> { self.mk_fn_ptr(converted_sig) } + #[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] #[inline] pub fn mk_ty(&self, st: TyKind<'tcx>) -> Ty<'tcx> { CtxtInterners::intern_ty(&self.interners, &self.global_interners, st) diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index 8d7e7e16e85..411b18e043a 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -18,6 +18,7 @@ impl FlagComputation { } } + #[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] pub fn for_sty(st: &ty::TyKind<'_>) -> FlagComputation { let mut result = FlagComputation::new(); result.add_sty(st); @@ -61,6 +62,7 @@ impl FlagComputation { } // otherwise, this binder captures nothing } + #[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] fn add_sty(&mut self, st: &ty::TyKind<'_>) { match st { &ty::Bool | diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 796b2b3c1a1..90c18a7e364 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1,7 +1,5 @@ // ignore-tidy-filelength -#![cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] - pub use self::Variance::*; pub use self::AssocItemContainer::*; pub use self::BorrowKind::*; @@ -484,6 +482,7 @@ bitflags! { } } +#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] pub struct TyS<'tcx> { pub sty: TyKind<'tcx>, pub flags: TypeFlags, @@ -541,29 +540,29 @@ impl<'tcx> Hash for TyS<'tcx> { impl<'tcx> TyS<'tcx> { pub fn is_primitive_ty(&self) -> bool { match self.sty { - TyKind::Bool | - TyKind::Char | - TyKind::Int(_) | - TyKind::Uint(_) | - TyKind::Float(_) | - TyKind::Infer(InferTy::IntVar(_)) | - TyKind::Infer(InferTy::FloatVar(_)) | - TyKind::Infer(InferTy::FreshIntTy(_)) | - TyKind::Infer(InferTy::FreshFloatTy(_)) => true, - TyKind::Ref(_, x, _) => x.is_primitive_ty(), + Bool | + Char | + Int(_) | + Uint(_) | + Float(_) | + Infer(InferTy::IntVar(_)) | + Infer(InferTy::FloatVar(_)) | + Infer(InferTy::FreshIntTy(_)) | + Infer(InferTy::FreshFloatTy(_)) => true, + Ref(_, x, _) => x.is_primitive_ty(), _ => false, } } pub fn is_suggestable(&self) -> bool { match self.sty { - TyKind::Opaque(..) | - TyKind::FnDef(..) | - TyKind::FnPtr(..) | - TyKind::Dynamic(..) | - TyKind::Closure(..) | - TyKind::Infer(..) | - TyKind::Projection(..) => false, + Opaque(..) | + FnDef(..) | + FnPtr(..) | + Dynamic(..) | + Closure(..) | + Infer(..) | + Projection(..) => false, _ => true, } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 8bfbd8b854b..5d17080a9b2 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1,5 +1,7 @@ //! This module contains `TyKind` and its major components. +#![cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] + use crate::hir; use crate::hir::def_id::DefId; use crate::infer::canonical::Canonical;