diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs index ed1c15a73c260..6f3e7f4bfb740 100644 --- a/src/librustc/hir/def_id.rs +++ b/src/librustc/hir/def_id.rs @@ -1,10 +1,10 @@ -use crate::ty; -use crate::ty::TyCtxt; +use crate::ty::{self, TyCtxt}; use crate::hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX; use rustc_data_structures::indexed_vec::Idx; use serialize; use std::fmt; use std::u32; +use syntax::symbol; newtype_index! { pub struct CrateId { @@ -252,6 +252,33 @@ impl DefId { format!("module `{}`", tcx.item_path_str(*self)) } } + + /// Check if a `DefId`'s path matches the given absolute type path usage. + // Uplifted from rust-lang/rust-clippy + pub fn match_path(self, tcx: TyCtxt<'_, '_, '_>, path: &[&str]) -> bool { + #[derive(Debug)] + struct AbsolutePathBuffer { + names: Vec, + } + + impl ty::item_path::ItemPathBuffer for AbsolutePathBuffer { + fn root_mode(&self) -> &ty::item_path::RootMode { + const ABSOLUTE: &ty::item_path::RootMode = &ty::item_path::RootMode::Absolute; + ABSOLUTE + } + + fn push(&mut self, text: &str) { + self.names.push(symbol::Symbol::intern(text).as_str()); + } + } + + let mut apb = AbsolutePathBuffer { names: vec![] }; + + tcx.push_item_path(&mut apb, self, false); + + apb.names.len() == path.len() + && apb.names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b) + } } impl serialize::UseSpecializedEncodable for DefId {} diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs new file mode 100644 index 0000000000000..8314bf7ae9d6e --- /dev/null +++ b/src/librustc/lint/internal.rs @@ -0,0 +1,142 @@ +//! Some lints that are only useful in the compiler or crates that use compiler internals, such as +//! Clippy. + +use crate::hir::{HirId, Path, QPath, Ty, TyKind}; +use crate::lint::{ + EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass, +}; +use errors::Applicability; +use rustc_data_structures::fx::FxHashMap; +use syntax::ast::Ident; + +declare_lint! { + pub DEFAULT_HASH_TYPES, + Warn, + "forbid HashMap and HashSet and suggest the FxHash* variants" +} + +pub struct DefaultHashTypes { + map: FxHashMap, +} + +impl DefaultHashTypes { + pub fn new() -> Self { + let mut map = FxHashMap::default(); + map.insert("HashMap".to_string(), "FxHashMap".to_string()); + map.insert("HashSet".to_string(), "FxHashSet".to_string()); + Self { map } + } +} + +impl LintPass for DefaultHashTypes { + fn get_lints(&self) -> LintArray { + lint_array!(DEFAULT_HASH_TYPES) + } + + fn name(&self) -> &'static str { + "DefaultHashTypes" + } +} + +impl EarlyLintPass for DefaultHashTypes { + fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) { + let ident_string = ident.to_string(); + if let Some(replace) = self.map.get(&ident_string) { + let msg = format!( + "Prefer {} over {}, it has better performance", + replace, ident_string + ); + let mut db = cx.struct_span_lint(DEFAULT_HASH_TYPES, ident.span, &msg); + db.span_suggestion( + ident.span, + "use", + replace.to_string(), + Applicability::MaybeIncorrect, // FxHashMap, ... needs another import + ); + db.note(&format!( + "a `use rustc_data_structures::fx::{}` may be necessary", + replace + )) + .emit(); + } + } +} + +declare_lint! { + pub USAGE_OF_TY_TYKIND, + Warn, + "Usage of `ty::TyKind` outside of the `ty::sty` module" +} + +pub struct TyKindUsage; + +impl LintPass for TyKindUsage { + fn get_lints(&self) -> LintArray { + lint_array!(USAGE_OF_TY_TYKIND) + } + + fn name(&self) -> &'static str { + "TyKindUsage" + } +} + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyKindUsage { + fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path, _: HirId) { + let segments_iter = path.segments.iter().rev().skip(1).rev(); + + if let Some(last) = segments_iter.clone().last() { + if last.ident.as_str() == "TyKind" { + let path = Path { + span: path.span.with_hi(last.ident.span.hi()), + def: path.def, + segments: segments_iter.cloned().collect(), + }; + + if let Some(def) = last.def { + if def + .def_id() + .match_path(cx.tcx, &["rustc", "ty", "sty", "TyKind"]) + { + cx.struct_span_lint( + USAGE_OF_TY_TYKIND, + path.span, + "usage of `ty::TyKind::`", + ) + .span_suggestion( + path.span, + "try using ty:: directly", + "ty".to_string(), + Applicability::MaybeIncorrect, // ty maybe needs an import + ) + .emit(); + } + } + } + } + } + + fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &'tcx Ty) { + if let TyKind::Path(qpath) = &ty.node { + if let QPath::Resolved(_, path) = qpath { + if let Some(last) = path.segments.iter().last() { + if last.ident.as_str() == "TyKind" { + if let Some(def) = last.def { + if def + .def_id() + .match_path(cx.tcx, &["rustc", "ty", "sty", "TyKind"]) + { + cx.struct_span_lint( + USAGE_OF_TY_TYKIND, + path.span, + "usage of `ty::TyKind`", + ) + .help("try using `ty::Ty` instead") + .emit(); + } + } + } + } + } + } + } +} diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 6c60f3f5a80a3..cfc800bcd5720 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -563,6 +563,7 @@ impl_stable_hash_for!(enum self::LintSource { pub type LevelSource = (Level, LintSource); pub mod builtin; +pub mod internal; mod context; mod levels; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 65da458efbfff..f4b5cbca2e443 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1410,6 +1410,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, merge_functions: Option = (None, parse_merge_functions, [TRACKED], "control the operation of the MergeFunctions LLVM pass, taking the same values as the target option of the same name"), + internal_lints: bool = (false, parse_bool, [UNTRACKED], + "allow internal rustc lints. These lints are probably only useful in the + compiler directly or in crates, that use rustc internals, such as Clippy."), } pub fn default_lib_output() -> CrateType { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e022d3a3818a5..5eb36169aaa8c 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -498,6 +498,9 @@ fn run_compiler_with_pool<'a>( let codegen_backend = get_codegen_backend(&sess); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess)); + } let mut cfg = config::build_configuration(&sess, cfg); target_features::add_configuration(&mut cfg, &sess, &*codegen_backend); @@ -815,10 +818,16 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { if sopts.describe_lints { let mut ls = lint::LintStore::new(); rustc_lint::register_builtins(&mut ls, Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut ls, Some(&sess)); + } describe_lints(&sess, &ls, false); return None; } rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess)); + } let mut cfg = config::build_configuration(&sess, cfg.clone()); let codegen_backend = get_codegen_backend(&sess); target_features::add_configuration(&mut cfg, &sess, &*codegen_backend); diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 2ec755bd62691..85ab7f8e68f01 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -114,6 +114,9 @@ fn test_env_with_pool( ); let cstore = CStore::new(::get_codegen_backend(&sess).metadata_loader()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess)); + } let input = config::Input::Str { name: FileName::anon_source_code(&source_string), input: source_string.to_string(), diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 5c243e1389073..24da2dc4f3d0d 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -58,6 +58,7 @@ use nonstandard_style::*; use builtin::*; use types::*; use unused::*; +use rustc::lint::internal::*; /// Useful for other parts of the compiler. pub use builtin::SoftLints; @@ -405,3 +406,18 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { store.register_removed("bad_repr", "replaced with a generic attribute input check"); } + +pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { + store.register_early_pass(sess, false, false, box DefaultHashTypes::new()); + store.register_late_pass(sess, false, box TyKindUsage); + store.register_group( + sess, + false, + "internal", + None, + vec![ + LintId::of(DEFAULT_HASH_TYPES), + LintId::of(USAGE_OF_TY_TYKIND), + ], + ); +} diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 4f70751c90537..7d6f00e251887 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -428,6 +428,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let codegen_backend = rustc_driver::get_codegen_backend(&sess); let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader())); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess)); + } let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs)); target_features::add_configuration(&mut cfg, &sess, &*codegen_backend); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 3db65205a2dc4..03e58ac3032f7 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -75,6 +75,9 @@ pub fn run(mut options: Options) -> isize { let codegen_backend = rustc_driver::get_codegen_backend(&sess); let cstore = CStore::new(codegen_backend.metadata_loader()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess)); + } let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(options.cfgs.clone())); @@ -279,6 +282,9 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, let codegen_backend = rustc_driver::get_codegen_backend(&sess); let cstore = CStore::new(codegen_backend.metadata_loader()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); + if sess.opts.debugging_opts.internal_lints { + rustc_lint::register_internals(&mut sess.lint_store.borrow_mut(), Some(&sess)); + } let outdir = Mutex::new( if let Some(mut path) = persist_doctests { diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index b7617ec556d20..26a4a74f05b22 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -12,7 +12,7 @@ error[E0425]: cannot find value `no` in this scope 3 | no | ^^ not found in this scope -thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:351:13 +thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:357:13 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ---- @@ -21,7 +21,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. -', src/librustdoc/test.rs:372:17 +', src/librustdoc/test.rs:378:17 failures: diff --git a/src/test/ui-fulldeps/internal-lints/default_hash_types.rs b/src/test/ui-fulldeps/internal-lints/default_hash_types.rs new file mode 100644 index 0000000000000..a6b0dbafbeb9b --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/default_hash_types.rs @@ -0,0 +1,24 @@ +// compile-flags: -Z internal-lints + +#![feature(rustc_private)] + +extern crate rustc_data_structures; + +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use std::collections::{HashMap, HashSet}; +//~^ WARNING Prefer FxHashMap over HashMap, it has better performance +//~^^ WARNING Prefer FxHashSet over HashSet, it has better performance + +#[deny(default_hash_types)] +fn main() { + let _map: HashMap = HashMap::default(); + //~^ ERROR Prefer FxHashMap over HashMap, it has better performance + //~^^ ERROR Prefer FxHashMap over HashMap, it has better performance + let _set: HashSet = HashSet::default(); + //~^ ERROR Prefer FxHashSet over HashSet, it has better performance + //~^^ ERROR Prefer FxHashSet over HashSet, it has better performance + + // test that the lint doesn't also match the Fx variants themselves + let _fx_map: FxHashMap = FxHashMap::default(); + let _fx_set: FxHashSet = FxHashSet::default(); +} diff --git a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr new file mode 100644 index 0000000000000..323a3880d1cdc --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr @@ -0,0 +1,56 @@ +warning: Prefer FxHashMap over HashMap, it has better performance + --> $DIR/default_hash_types.rs:8:24 + | +LL | use std::collections::{HashMap, HashSet}; + | ^^^^^^^ help: use: `FxHashMap` + | + = note: #[warn(default_hash_types)] on by default + = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary + +warning: Prefer FxHashSet over HashSet, it has better performance + --> $DIR/default_hash_types.rs:8:33 + | +LL | use std::collections::{HashMap, HashSet}; + | ^^^^^^^ help: use: `FxHashSet` + | + = note: a `use rustc_data_structures::fx::FxHashSet` may be necessary + +error: Prefer FxHashMap over HashMap, it has better performance + --> $DIR/default_hash_types.rs:14:15 + | +LL | let _map: HashMap = HashMap::default(); + | ^^^^^^^ help: use: `FxHashMap` + | +note: lint level defined here + --> $DIR/default_hash_types.rs:12:8 + | +LL | #[deny(default_hash_types)] + | ^^^^^^^^^^^^^^^^^^ + = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary + +error: Prefer FxHashMap over HashMap, it has better performance + --> $DIR/default_hash_types.rs:14:41 + | +LL | let _map: HashMap = HashMap::default(); + | ^^^^^^^ help: use: `FxHashMap` + | + = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary + +error: Prefer FxHashSet over HashSet, it has better performance + --> $DIR/default_hash_types.rs:17:15 + | +LL | let _set: HashSet = HashSet::default(); + | ^^^^^^^ help: use: `FxHashSet` + | + = note: a `use rustc_data_structures::fx::FxHashSet` may be necessary + +error: Prefer FxHashSet over HashSet, it has better performance + --> $DIR/default_hash_types.rs:17:33 + | +LL | let _set: HashSet = HashSet::default(); + | ^^^^^^^ help: use: `FxHashSet` + | + = note: a `use rustc_data_structures::fx::FxHashSet` may be necessary + +error: aborting due to 4 previous errors + diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs new file mode 100644 index 0000000000000..a1e08cd3b95bc --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs @@ -0,0 +1,49 @@ +// compile-flags: -Z internal-lints + +#![feature(rustc_private)] + +extern crate rustc; + +use rustc::ty::{self, Ty, TyKind}; + +#[deny(usage_of_ty_tykind)] +fn main() { + let sty = TyKind::Bool; //~ ERROR usage of `ty::TyKind::` + + match sty { + TyKind::Bool => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Char => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Int(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Uint(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Float(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Adt(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Foreign(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Str => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Array(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Slice(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::RawPtr(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Ref(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::FnDef(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Never => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Projection(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::UnnormalizedProjection(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Opaque(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Param(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Infer(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Error => (), //~ ERROR usage of `ty::TyKind::` + } + + if let ty::Int(int_ty) = sty {} + + if let TyKind::Int(int_ty) = sty {} //~ ERROR usage of `ty::TyKind::` + + fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} //~ 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 new file mode 100644 index 0000000000000..d3ad5e1264a4d --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr @@ -0,0 +1,196 @@ +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:11:15 + | +LL | let sty = TyKind::Bool; //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + | +note: lint level defined here + --> $DIR/ty_tykind_usage.rs:9:8 + | +LL | #[deny(usage_of_ty_tykind)] + | ^^^^^^^^^^^^^^^^^^ + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:14:9 + | +LL | TyKind::Bool => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:15:9 + | +LL | TyKind::Char => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:16:9 + | +LL | TyKind::Int(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:17:9 + | +LL | TyKind::Uint(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:18:9 + | +LL | TyKind::Float(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:19:9 + | +LL | TyKind::Adt(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:20:9 + | +LL | TyKind::Foreign(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:21:9 + | +LL | TyKind::Str => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:22:9 + | +LL | TyKind::Array(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:23:9 + | +LL | TyKind::Slice(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:24:9 + | +LL | TyKind::RawPtr(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:25:9 + | +LL | TyKind::Ref(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:26:9 + | +LL | TyKind::FnDef(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:27:9 + | +LL | TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:28:9 + | +LL | TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:29:9 + | +LL | TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:30:9 + | +LL | TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:31:9 + | +LL | TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:32:9 + | +LL | TyKind::Never => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:33:9 + | +LL | TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:34:9 + | +LL | TyKind::Projection(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:35:9 + | +LL | TyKind::UnnormalizedProjection(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:36:9 + | +LL | TyKind::Opaque(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:37:9 + | +LL | TyKind::Param(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:38:9 + | +LL | TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:39:9 + | +LL | TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:40:9 + | +LL | TyKind::Infer(..) => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:41:9 + | +LL | TyKind::Error => (), //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:46:12 + | +LL | if let TyKind::Int(int_ty) = sty {} //~ ERROR usage of `ty::TyKind::` + | ^^^^^^ help: try using ty:: directly: `ty` + +error: usage of `ty::TyKind` + --> $DIR/ty_tykind_usage.rs:48:24 + | +LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} //~ ERROR usage of `ty::TyKind` + | ^^^^^^^^^^ + | + = help: try using `ty::Ty` instead + +error: aborting due to 31 previous errors + diff --git a/src/test/ui-fulldeps/internal-lints/without_compile_flag.rs b/src/test/ui-fulldeps/internal-lints/without_compile_flag.rs new file mode 100644 index 0000000000000..b58f5df5f6829 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/without_compile_flag.rs @@ -0,0 +1,8 @@ +// compile-pass + +#![allow(unused)] + +use std::collections::HashMap; + +#[deny(default_hash_types)] //~ WARNING unknown lint: `default_hash_types` +fn main() {} diff --git a/src/test/ui-fulldeps/internal-lints/without_compile_flag.stderr b/src/test/ui-fulldeps/internal-lints/without_compile_flag.stderr new file mode 100644 index 0000000000000..6815cdc1f2a8d --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/without_compile_flag.stderr @@ -0,0 +1,8 @@ +warning: unknown lint: `default_hash_types` + --> $DIR/without_compile_flag.rs:7:8 + | +LL | #[deny(default_hash_types)] //~ WARNING unknown lint: `default_hash_types` + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[warn(unknown_lints)] on by default +