diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 1c7f372af6b..7fad43029ac 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -47,7 +47,7 @@ impl Lint { name: name.to_lowercase(), group: group.to_string(), desc: NL_ESCAPE_RE.replace(&desc.replace("\\\"", "\""), "").to_string(), - deprecation: deprecation.map(|d| d.to_string()), + deprecation: deprecation.map(std::string::ToString::to_string), module: module.to_string(), } } @@ -178,7 +178,7 @@ fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> { // Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`. WalkDir::new("../clippy_lints/src") .into_iter() - .filter_map(|f| f.ok()) + .filter_map(std::result::Result::ok) .filter(|f| f.path().extension() == Some(OsStr::new("rs"))) } diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 89dbba56130..a72944bbe02 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -326,7 +326,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) { lint.span, &format!("unknown clippy lint: clippy::{}", name), |db| { - if name.as_str().chars().any(|c| c.is_uppercase()) { + if name.as_str().chars().any(char::is_uppercase) { let name_lower = name.as_str().to_lowercase(); match lint_store.check_lint_name( &name_lower, diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index 124b11cc78c..1d37c03ff45 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -53,7 +53,7 @@ fn is_empty_str(value: &Option<String>) -> bool { fn is_empty_vec(value: &[String]) -> bool { // This works because empty iterators return true - value.iter().all(|v| v.is_empty()) + value.iter().all(std::string::String::is_empty) } pub struct Pass; diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5a9364eddb6..759b3173978 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -267,7 +267,7 @@ pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf { } }); - let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref())); + let (conf, errors) = utils::conf::read(file_name.as_ref().map(std::convert::AsRef::as_ref)); // all conf errors are non-fatal, we just use the default conf in case of error for error in errors { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 4ce2ae03b9f..c9b27ef1615 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -829,7 +829,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let (method_names, arg_lists) = method_calls(expr, 2); let method_names: Vec<LocalInternedString> = method_names.iter().map(|s| s.as_str()).collect(); - let method_names: Vec<&str> = method_names.iter().map(|s| s.as_ref()).collect(); + let method_names: Vec<&str> = method_names.iter().map(std::convert::AsRef::as_ref).collect(); match method_names.as_slice() { ["unwrap", "get"] => lint_get_unwrap(cx, expr, arg_lists[1], false), @@ -1695,7 +1695,7 @@ fn derefs_to_slice(cx: &LateContext<'_, '_>, expr: &hir::Expr, ty: Ty<'_>) -> Op if let hir::ExprKind::MethodCall(ref path, _, ref args) = expr.node { if path.ident.name == "iter" && may_slice(cx, cx.tables.expr_ty(&args[0])) { - sugg::Sugg::hir_opt(cx, &args[0]).map(|sugg| sugg.addr()) + sugg::Sugg::hir_opt(cx, &args[0]).map(sugg::Sugg::addr) } else { None } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index fbf60db28ee..b1cd1910f5b 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -241,7 +241,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { // or too many chars differ (x_foo, y_boo) or (xfoo, yboo) continue; } - split_at = interned_name.chars().next().map(|c| c.len_utf8()); + split_at = interned_name.chars().next().map(char::len_utf8); } } span_lint_and_then( diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index b0b4394ebb8..ff802dbb3a8 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -14,7 +14,7 @@ use toml; pub fn file_from_args( args: &[source_map::Spanned<ast::NestedMetaItemKind>], ) -> Result<Option<path::PathBuf>, (&'static str, source_map::Span)> { - for arg in args.iter().filter_map(|a| a.meta_item()) { + for arg in args.iter().filter_map(syntax::source_map::Spanned::meta_item) { if arg.name() == "conf_file" { return match arg.node { ast::MetaItemKind::Word | ast::MetaItemKind::List(_) => { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index a8b6a756b78..b5221bca007 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -142,7 +142,10 @@ pub fn match_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId, path: &[&str]) -> pub fn get_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Vec<&'static str> { let mut apb = AbsolutePathBuffer { names: vec![] }; tcx.push_item_path(&mut apb, def_id, false); - apb.names.iter().map(|n| n.get()).collect() + apb.names + .iter() + .map(syntax_pos::symbol::LocalInternedString::get) + .collect() } /// Check if type is struct, enum or union type with given def path. diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index f13fa12ccca..19c27754839 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -9,8 +9,8 @@ macro_rules! get_version_info { let crate_name = String::from(env!("CARGO_PKG_NAME")); let host_compiler = $crate::get_channel(); - let commit_hash = option_env!("GIT_HASH").map(|s| s.to_string()); - let commit_date = option_env!("COMMIT_DATE").map(|s| s.to_string()); + let commit_hash = option_env!("GIT_HASH").map(str::to_string); + let commit_date = option_env!("COMMIT_DATE").map(str::to_string); VersionInfo { major, diff --git a/src/driver.rs b/src/driver.rs index fbff693f887..34fc6fc7f9f 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -47,7 +47,7 @@ fn arg_value<'a>( fn test_arg_value() { let args: Vec<_> = ["--bar=bar", "--foobar", "123", "--foo"] .iter() - .map(|s| s.to_string()) + .map(std::string::ToString::to_string) .collect(); assert_eq!(arg_value(None, "--foobar", |_| true), None); @@ -84,7 +84,7 @@ pub fn main() { let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true); let have_sys_root_arg = sys_root_arg.is_some(); let sys_root = sys_root_arg - .map(|s| s.to_string()) + .map(std::string::ToString::to_string) .or_else(|| std::env::var("SYSROOT").ok()) .or_else(|| { let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); diff --git a/tests/missing-test-files.rs b/tests/missing-test-files.rs index bd0cee75644..d87bb4be3c3 100644 --- a/tests/missing-test-files.rs +++ b/tests/missing-test-files.rs @@ -32,7 +32,7 @@ fn explore_directory(dir: &Path) -> Vec<String> { let mut missing_files: Vec<String> = Vec::new(); let mut current_file = String::new(); let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect(); - files.sort_by_key(|e| e.path()); + files.sort_by_key(std::fs::DirEntry::path); for entry in &files { let path = entry.path(); if path.is_dir() { diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index af417815ed1..d804e838d5a 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -3,6 +3,7 @@ #![allow(clippy::iter_cloned_collect)] #![allow(clippy::clone_on_copy)] #![allow(clippy::missing_docs_in_private_items)] +#![allow(clippy::redundant_closure)] fn main() { let _: Vec<i8> = vec![5_i8; 6].iter().cloned().collect(); diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 7dd2ce30202..d98cd939d8c 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -3,6 +3,7 @@ #![allow(clippy::iter_cloned_collect)] #![allow(clippy::clone_on_copy)] #![allow(clippy::missing_docs_in_private_items)] +#![allow(clippy::redundant_closure)] fn main() { let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect(); diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index 504f4a01a4c..db7fa4f52fc 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -1,5 +1,5 @@ error: You are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:8:22 + --> $DIR/map_clone.rs:9:22 | LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![5_i8; 6].iter().cloned()` @@ -7,19 +7,19 @@ LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect(); = note: `-D clippy::map-clone` implied by `-D warnings` error: You are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:9:26 + --> $DIR/map_clone.rs:10:26 | LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()` error: You are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:10:23 + --> $DIR/map_clone.rs:11:23 | LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![42, 43].iter().cloned()` error: You are needlessly cloning iterator elements - --> $DIR/map_clone.rs:22:29 + --> $DIR/map_clone.rs:23:29 | LL | let _ = std::env::args().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^ help: Remove the map call