diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..3d31fa7 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,79 @@ +[target.'cfg(all())'] +rustflags = [ + # BEGIN - Embark standard lints v6 for Rust 1.55+ + # do not change or add/remove here, but one can add exceptions after this section + # for more info see: + "-Dunsafe_code", + "-Wclippy::all", + "-Wclippy::await_holding_lock", + "-Wclippy::char_lit_as_u8", + "-Wclippy::checked_conversions", + "-Wclippy::dbg_macro", + "-Wclippy::debug_assert_with_mut_call", + "-Wclippy::doc_markdown", + "-Wclippy::empty_enum", + "-Wclippy::enum_glob_use", + "-Wclippy::exit", + "-Wclippy::expl_impl_clone_on_copy", + "-Wclippy::explicit_deref_methods", + "-Wclippy::explicit_into_iter_loop", + "-Wclippy::fallible_impl_from", + "-Wclippy::filter_map_next", + "-Wclippy::flat_map_option", + "-Wclippy::float_cmp_const", + "-Wclippy::fn_params_excessive_bools", + "-Wclippy::from_iter_instead_of_collect", + "-Wclippy::if_let_mutex", + "-Wclippy::implicit_clone", + "-Wclippy::imprecise_flops", + "-Wclippy::inefficient_to_string", + "-Wclippy::invalid_upcast_comparisons", + "-Wclippy::large_digit_groups", + "-Wclippy::large_stack_arrays", + "-Wclippy::large_types_passed_by_value", + "-Wclippy::let_unit_value", + "-Wclippy::linkedlist", + "-Wclippy::lossy_float_literal", + "-Wclippy::macro_use_imports", + "-Wclippy::manual_ok_or", + "-Wclippy::map_err_ignore", + "-Wclippy::map_flatten", + "-Wclippy::map_unwrap_or", + "-Wclippy::match_on_vec_items", + "-Wclippy::match_same_arms", + "-Wclippy::match_wild_err_arm", + "-Wclippy::match_wildcard_for_single_variants", + "-Wclippy::mem_forget", + "-Wclippy::mismatched_target_os", + "-Wclippy::missing_enforced_import_renames", + "-Wclippy::mut_mut", + "-Wclippy::mutex_integer", + "-Wclippy::needless_borrow", + "-Wclippy::needless_continue", + "-Wclippy::needless_for_each", + "-Wclippy::option_option", + "-Wclippy::path_buf_push_overwrite", + "-Wclippy::ptr_as_ptr", + "-Wclippy::rc_mutex", + "-Wclippy::ref_option_ref", + "-Wclippy::rest_pat_in_fully_bound_structs", + "-Wclippy::same_functions_in_if_condition", + "-Wclippy::semicolon_if_nothing_returned", + "-Wclippy::single_match_else", + "-Wclippy::string_add_assign", + "-Wclippy::string_add", + "-Wclippy::string_lit_as_bytes", + "-Wclippy::string_to_string", + "-Wclippy::todo", + "-Wclippy::trait_duplication_in_bounds", + "-Wclippy::unimplemented", + "-Wclippy::unnested_or_patterns", + "-Wclippy::unused_self", + "-Wclippy::useless_transmute", + "-Wclippy::verbose_file_reads", + "-Wclippy::zero_sized_map_values", + "-Wfuture_incompatible", + "-Wnonstandard_style", + "-Wrust_2018_idioms", + # END - Embark standard lints v6 for Rust 1.55+ +] diff --git a/src/autofix.rs b/src/autofix.rs index 11cf5f3..527b003 100644 --- a/src/autofix.rs +++ b/src/autofix.rs @@ -75,7 +75,7 @@ impl AutoFixer { // DOGSHIT CODE values.sort_by(|a, b| a.as_str().unwrap().cmp(b.as_str().unwrap())); feature.clear(); - for value in values.into_iter() { + for value in values { feature.push_formatted(value.clone()); } } @@ -164,7 +164,7 @@ impl AutoFixer { feature.set_trailing_comma(false); feature.set_trailing(""); feature.clear(); - for value in values.into_iter() { + for value in values { feature.push_formatted(value.clone()); } @@ -211,7 +211,7 @@ impl AutoFixer { } feature.clear(); - for value in values.into_iter() { + for value in values { feature.push_formatted(value.clone()); } feature.set_trailing_comma(false); @@ -275,22 +275,19 @@ impl AutoFixer { for feature_name in features.iter() { let feature = self.get_feature_mut(feature_name).unwrap(); - match mode_per_feature.get(feature_name) { - Some(modes) => { - if modes.contains(&Mode::None) { - continue - } - if modes.contains(&Mode::Sort) { - Self::sort_feature(feature); - } - if modes.contains(&Mode::Canonicalize) { - Self::format_feature(feature_name, feature, line_width)?; - } - }, - None => { + if let Some(modes) = mode_per_feature.get(feature_name) { + if modes.contains(&Mode::None) { + continue + } + if modes.contains(&Mode::Sort) { Self::sort_feature(feature); + } + if modes.contains(&Mode::Canonicalize) { Self::format_feature(feature_name, feature, line_width)?; - }, + } + } else { + Self::sort_feature(feature); + Self::format_feature(feature_name, feature, line_width)?; } } @@ -348,7 +345,7 @@ impl AutoFixer { feature.set_trailing_comma(false); // We need to add this manually later on. let mut new_vals = Vec::new(); - for mut value in values.into_iter() { + for mut value in values { if value.as_str().map_or(false, |s| s.is_empty()) { panic!("Empty value in feature"); } @@ -388,7 +385,7 @@ impl AutoFixer { new_vals[i - 1].decor_mut().set_suffix(""); } - for new_val in new_vals.into_iter() { + for new_val in new_vals { feature.push_formatted(new_val); } diff --git a/src/cmd/lint.rs b/src/cmd/lint.rs index 66f85b8..38882fa 100644 --- a/src/cmd/lint.rs +++ b/src/cmd/lint.rs @@ -201,7 +201,7 @@ impl LintCmd { struct CrateAndFeature(String, String); impl Display for CrateAndFeature { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{}/{}", self.0, self.1) } } @@ -287,7 +287,7 @@ impl NeverEnablesCmd { let Some(enabled) = lhs.features.get(&self.precondition) else { continue }; // TODO do the same in other command. - if enabled.contains(&self.stays_disabled.to_string()) { + if enabled.contains(&self.stays_disabled) { offenders.entry(lhs.id.to_string()).or_default().insert(RenamedPackage::new( (*lhs).clone(), None, @@ -565,9 +565,8 @@ impl OnlyEnablesCmd { for (feat, imply) in pkg.features.iter() { if feat == &self.precondition { continue - } else { - log::info!("{}: {}", feat, imply.join(", ")); } + log::info!("{}: {}", feat, imply.join(", ")); let opt = if dep.optional { "?" } else { "" }; let bad_opt = format!("{}{}/{}", dep.name(), opt, self.only_enables); @@ -726,7 +725,7 @@ fn build_feature_dag(meta: &Metadata, pkgs: &[Package]) -> Dag dag.add_edge( CrateAndFeature(pkg.id.to_string(), feature.clone()), CrateAndFeature(pkg.id.to_string(), dep_feature.into()), - ) + ); } } } diff --git a/src/cmd/trace.rs b/src/cmd/trace.rs index cc32478..f4f3589 100644 --- a/src/cmd/trace.rs +++ b/src/cmd/trace.rs @@ -47,7 +47,7 @@ pub struct TraceCmd { impl TraceCmd { pub fn run(&self, _global: &GlobalArgs) { let meta = self.cargo_args.load_metadata().expect("Loads metadata"); - let (dag, index) = self.build_dag(meta).expect("Builds dependency graph"); + let (dag, index) = Self::build_dag(meta).expect("Builds dependency graph"); let lookup = |id: &str| { index .get(id) @@ -120,14 +120,11 @@ impl TraceCmd { } /// Build a dependency graph over the crates ids and return an index of all crates. - fn build_dag( - &self, - meta: Metadata, - ) -> Result<(Dag, BTreeMap), String> { + fn build_dag(meta: Metadata) -> Result<(Dag, BTreeMap), String> { let mut dag = Dag::new(); let mut index = BTreeMap::new(); - for pkg in meta.packages.clone().into_iter() { + for pkg in meta.packages.clone() { let id = pkg.id.to_string(); dag.add_node(id.clone()); index.insert(pkg.id.to_string(), pkg.clone()); diff --git a/src/dag.rs b/src/dag.rs index 0f16ca7..cc78e62 100644 --- a/src/dag.rs +++ b/src/dag.rs @@ -91,7 +91,7 @@ where F: FnMut(&T), { for e in self.0.iter() { - f(e.as_ref()) + f(e.as_ref()); } } } @@ -143,7 +143,7 @@ where /// /// *Directly* means with via an edge. pub fn connected(&self, from: &T, to: &T) -> bool { - self.edges.get(from).map(|v| v.contains(to)).unwrap_or(false) + self.edges.get(from).map_or(false, |v| v.contains(to)) } /// Whether `from` appears on the lhs of the edge relation. diff --git a/src/mock/mod.rs b/src/mock/mod.rs index 990fed7..1911096 100644 --- a/src/mock/mod.rs +++ b/src/mock/mod.rs @@ -238,7 +238,7 @@ impl Context { /// Convert a crate's name to a file path. /// -/// This is needed for case-insensitive file systems like on MacOS. It prefixes all lower-case +/// This is needed for case-insensitive file systems like on `MacOS`. It prefixes all lower-case /// letters with an `l` and turns the upper case. pub(crate) fn crate_name_to_path(n: &str) -> String { n.chars() @@ -263,9 +263,10 @@ pub enum CrateDependency { impl CrateDependency { fn def(&self) -> String { let option = if self.optional() { ", optional = true".to_string() } else { String::new() }; - let mut ret = match self.rename() { - Some(rename) => format!("{} = {{ package = \"{}\", ", rename, self.name()), - None => format!("{} = {{ ", self.name()), + let mut ret = if let Some(rename) = self.rename() { + format!("{} = {{ package = \"{}\", ", rename, self.name()) + } else { + format!("{} = {{ ", self.name()) }; ret.push_str(&format!("version = \"*\", path = \"../{}\"{}}}\n", self.path(), option)); ret @@ -284,14 +285,14 @@ impl CrateDependency { fn rename(&self) -> Option { match self { Self::Explicit { rename, .. } => rename.clone(), - _ => None, + Self::Implicit(_) => None, } } fn optional(&self) -> bool { match self { Self::Explicit { optional, .. } => optional.unwrap_or_default(), - _ => false, + Self::Implicit(_) => false, } } } diff --git a/tests/tests.rs b/tests/tests.rs index ecdec88..6f41dd0 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -114,10 +114,10 @@ fn integration() { continue } - for (i, stdout) in overwrites.into_iter() { + for (i, stdout) in overwrites { config.case_mut(i).stdout = stdout; } - for (i, diff) in diff_overwrites.into_iter() { + for (i, diff) in diff_overwrites { config.case_mut(i).diff = diff; }