diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 595deb07ec8..242074fec77 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -306,7 +306,20 @@ 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 != "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"); + } + } + } // 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 c4c23428002..b20f7120bbf 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/lint/context.rs b/src/librustc/lint/context.rs index 7f09120bbdd..950f7ad2e08 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(bootstrap), allow(rustc::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(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 86dae579ca7..34899736949 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -7,11 +7,12 @@ 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}; +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" } @@ -22,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)] + #[cfg_attr(not(bootstrap), allow(rustc::default_hash_types))] pub fn new() -> Self { let mut map = FxHashMap::default(); map.insert(sym::HashMap, sym::FxHashMap); @@ -36,10 +37,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,29 +45,26 @@ 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(); } } } -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" } @@ -137,13 +132,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 +214,44 @@ fn gen_args(segment: &PathSegment) -> String { String::new() } + +declare_tool_lint! { + pub rustc::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 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/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 88236a79421..25c2c30feca 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -130,6 +130,7 @@ impl<'tcx> CtxtInterners<'tcx> { } /// Intern a type + #[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))] #[inline(never)] fn intern_ty(&self, st: TyKind<'tcx> @@ -2107,6 +2108,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 @@ -2321,6 +2323,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> { self.interners.intern_ty(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 ad988072512..90c18a7e364 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1,7 +1,5 @@ // ignore-tidy-filelength -#![allow(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; 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 ca63e589a6f..dbcb2031552 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -23,7 +23,6 @@ #![feature(trusted_len)] #![feature(mem_take)] #![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 3c1ab600040..d0f4b0a870b 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -14,7 +14,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_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 98c809f7e25..38dfb675237 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)] +#![cfg_attr(not(bootstrap), allow(rustc::default_hash_types))] #[macro_use] extern crate log; 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 1ffee1cdf69..3269b85d0dd 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 4c6ceb14ca4..fb02782e6d3 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] @@ -487,15 +486,17 @@ 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, false, - "internal", + "rustc::internal", None, 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/librustc_macros/src/lib.rs b/src/librustc_macros/src/lib.rs index e9cf7bca25c..53bbecd0e6a 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)] +#![cfg_attr(not(bootstrap), allow(rustc::default_hash_types))] #![recursion_limit="128"] 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 b85149cf556..4a80534503a 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -29,7 +29,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 339021f511a..20f35c267f2 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 ce5a6b854ea..13b9855dbd7 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 ab82f75f74f..61ce9ed1222 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 88e6c0f579e..9c9e776bfad 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -74,7 +74,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 342264db43c..58777130b7f 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/attr/mod.rs b/src/libsyntax/attr/mod.rs index 453b6ebf3c4..a0c298010b6 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()) + [sym::clippy, sym::rustc].contains(&m_item.name) } impl NestedMetaItem { diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 7f16bb9dc12..a7c5ed158e0 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)] diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 233574dda5d..6a97e5f2127 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -175,6 +175,7 @@ symbols! { cfg_target_thread_local, cfg_target_vendor, char, + clippy, clone, Clone, clone_closures, @@ -216,6 +217,7 @@ symbols! { custom_inner_attributes, custom_test_frameworks, c_variadic, + declare_lint_pass, decl_macro, Default, default_lib_allocator, @@ -326,6 +328,7 @@ symbols! { if_while_or_patterns, ignore, impl_header_lifetime_elision, + impl_lint_pass, impl_trait_in_bindings, import_shadowing, index, @@ -367,6 +370,7 @@ symbols! { link_llvm_intrinsics, link_name, link_section, + LintPass, lint_reasons, literal, local_inner_macros, 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 new file mode 100644 index 00000000000..48dd5b122b5 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs @@ -0,0 +1,53 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_private)] +#![deny(rustc::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" + } +} + +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]); + +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..b439ae2cd14 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr @@ -0,0 +1,26 @@ +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(rustc::lint_pass_impl_without_macro)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead + +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 + 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