Rollup merge of #61545 - flip1995:internal_lints, r=oli-obk
Implement another internal lints cc #49509 This adds ~~two~~ one internal lint~~s~~: 1. LINT_PASS_IMPL_WITHOUT_MACRO: Make sure, that the `{declare,impl}_lint_pass` macro is used to implement lint passes. cc #59669 2. ~~USAGE_OF_TYCTXT_AND_SPAN_ARGS: item 2 on the list in #49509~~ ~~With 2. I wasn't sure, if this lint should be applied everywhere. That means a careful review of 0955835 would be great. Also 73fb9b4 allows this lint on some functions. Should I also apply this lint there?~~ TODO (not directly relevant for review): - [ ] https://github.com/rust-lang/rust/pull/59316#discussion_r280186517 (not sure yet, if this works or how to query for `rustc_private`, since it's not in [`Features`](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/feature_gate/struct.Features.html) 🤔 cc @eddyb) - [x] https://github.com/rust-lang/rust/pull/61735#discussion_r292389870 - [x] Check explicitly for the `{declare,impl}_lint_pass!` macros r? @oli-obk
This commit is contained in:
commit
485a084b45
49 changed files with 209 additions and 89 deletions
|
@ -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
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
test(no_crate_inject, attr(deny(warnings))))]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![feature(core_intrinsics)]
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
test(attr(deny(warnings))))]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![feature(nll)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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!()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
|
||||
where
|
||||
|
|
|
@ -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<TyKind<'tcx>> 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)
|
||||
|
|
|
@ -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 |
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#![feature(rustc_private)]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
pub mod expand;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#![allow(non_camel_case_types)]
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![feature(in_band_lifetimes)]
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#![allow(unused_attributes)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
pub extern crate getopts;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#![feature(nll)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#[allow(unused_extern_crates)]
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#[macro_use] extern crate rustc;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#![cfg_attr(unix, feature(libc))]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
|
|
@ -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),
|
||||
],
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![feature(proc_macro_hygiene)]
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::default_hash_types))]
|
||||
|
||||
#![recursion_limit="128"]
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
extern crate libc;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
pub use rustc::hir::def::{Namespace, PerNS};
|
||||
|
|
|
@ -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)]
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#![feature(step_trait)]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
test(attr(deny(warnings))))]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(internal)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
||||
#![feature(bind_by_move_pattern_guards)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<String, String> = HashMap::default();
|
||||
//~^ ERROR Prefer FxHashMap over HashMap, it has better performance
|
||||
|
|
|
@ -7,8 +7,8 @@ LL | let _map: HashMap<String, String> = 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
|
||||
|
|
|
@ -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() {}
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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::<kind>`
|
||||
|
||||
|
|
|
@ -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::<kind>`
|
||||
--> $DIR/ty_tykind_usage.rs:14:9
|
||||
|
|
Loading…
Add table
Reference in a new issue