From b8ddcb0652f3ec8683023afc1e1f5166d6a712f4 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 18 Feb 2020 14:53:02 +0200 Subject: Run cargo +nightly fix --clippy -Z unstable-options --- crates/ra_assists/src/handlers/add_custom_impl.rs | 4 +- crates/ra_assists/src/handlers/add_new.rs | 2 +- .../src/handlers/replace_if_let_with_match.rs | 2 +- crates/ra_assists/src/lib.rs | 4 +- crates/ra_cargo_watch/src/conv.rs | 2 +- crates/ra_db/src/input.rs | 2 +- crates/ra_hir/src/code_model.rs | 10 ++--- crates/ra_hir/src/source_analyzer.rs | 5 +-- crates/ra_hir_def/src/body/lower.rs | 2 +- crates/ra_hir_def/src/generics.rs | 2 +- crates/ra_hir_def/src/item_scope.rs | 2 +- crates/ra_hir_def/src/nameres.rs | 2 +- crates/ra_hir_def/src/nameres/raw.rs | 4 +- crates/ra_hir_def/src/nameres/tests/incremental.rs | 4 +- crates/ra_hir_def/src/path/lower/lower_use.rs | 4 +- crates/ra_hir_def/src/resolver.rs | 6 +-- crates/ra_hir_expand/src/builtin_derive.rs | 2 +- crates/ra_hir_expand/src/builtin_macro.rs | 4 +- crates/ra_hir_expand/src/quote.rs | 3 +- crates/ra_hir_ty/src/infer.rs | 11 +++-- crates/ra_hir_ty/src/infer/coerce.rs | 6 +-- crates/ra_hir_ty/src/infer/expr.rs | 20 ++++----- crates/ra_hir_ty/src/infer/pat.rs | 4 +- crates/ra_hir_ty/src/infer/path.rs | 47 +++++++++++----------- crates/ra_hir_ty/src/lib.rs | 4 +- crates/ra_hir_ty/src/lower.rs | 22 +++++----- crates/ra_hir_ty/src/method_resolution.rs | 12 +++--- crates/ra_hir_ty/src/traits/builtin.rs | 6 +-- crates/ra_hir_ty/src/traits/chalk.rs | 10 ++--- crates/ra_ide_db/src/change.rs | 2 +- crates/ra_mbe/src/mbe_expander/matcher.rs | 2 +- crates/ra_mbe/src/parser.rs | 12 +++--- crates/ra_mbe/src/subtree_source.rs | 2 +- crates/ra_parser/src/grammar/expressions/atom.rs | 6 +-- crates/ra_parser/src/grammar/paths.rs | 2 +- crates/ra_prof/src/lib.rs | 2 +- crates/ra_project_model/src/cargo_workspace.rs | 2 +- crates/ra_project_model/src/lib.rs | 2 +- crates/ra_syntax/src/algo.rs | 9 +++-- crates/ra_syntax/src/ast/expr_extensions.rs | 12 +++--- crates/ra_syntax/src/ast/make.rs | 2 +- crates/ra_syntax/src/parsing/text_token_source.rs | 2 +- crates/rust-analyzer/src/bin/main.rs | 2 +- crates/rust-analyzer/src/cli/analysis_stats.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 6 +-- crates/rust-analyzer/tests/heavy_tests/main.rs | 2 +- crates/rust-analyzer/tests/heavy_tests/support.rs | 2 +- crates/test_utils/src/lib.rs | 2 +- 48 files changed, 132 insertions(+), 149 deletions(-) diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 7fdd816bf..4d3a72c18 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -45,7 +45,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { let trait_token = ctx.token_at_offset().filter(|t| t.kind() == IDENT && *t.text() != attr_name).next()?; - let annotated = attr.syntax().siblings(Direction::Next).find_map(|s| ast::Name::cast(s))?; + let annotated = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; let annotated_name = annotated.syntax().text().to_string(); let start_offset = annotated.syntax().parent()?.text_range().end(); @@ -62,7 +62,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { .filter_map(|t| t.into_token().map(|t| t.text().clone())) .filter(|t| t != trait_token.text()) .collect::>(); - let has_more_derives = new_attr_input.len() > 0; + let has_more_derives = !new_attr_input.is_empty(); let new_attr_input = join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); let new_attr_input_len = new_attr_input.len(); diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 2701eddb8..dd070e8ec 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -53,7 +53,7 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option { } let vis = strukt.visibility().map(|v| format!("{} ", v.syntax())); - let vis = vis.as_ref().map(String::as_str).unwrap_or(""); + let vis = vis.as_deref().unwrap_or(""); write!(&mut buf, " {}fn new(", vis).unwrap(); join(field_list.fields().filter_map(|f| { diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index e6cd50bc1..0a0a88f3d 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs @@ -61,7 +61,7 @@ pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option { edit.target(if_expr.syntax().text_range()); edit.set_cursor(if_expr.syntax().text_range().start()); - edit.replace_ast::(if_expr.into(), match_expr.into()); + edit.replace_ast::(if_expr.into(), match_expr); }) } diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index cb124eaf0..a0e7fe17e 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -38,8 +38,8 @@ pub struct GroupLabel(pub String); impl AssistLabel { pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { // FIXME: make fields private, so that this invariant can't be broken - assert!(label.chars().nth(0).unwrap().is_uppercase()); - AssistLabel { label: label.into(), id } + assert!(label.chars().next().unwrap().is_uppercase()); + AssistLabel { label, id } } } diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index 506370535..0246adfb5 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs @@ -234,7 +234,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( let child = map_rust_child_diagnostic(&child, workspace_root); match child { MappedRustChildDiagnostic::Related(related) => related_information.push(related), - MappedRustChildDiagnostic::SuggestedFix(code_action) => fixes.push(code_action.into()), + MappedRustChildDiagnostic::SuggestedFix(code_action) => fixes.push(code_action), MappedRustChildDiagnostic::MessageLine(message_line) => { write!(&mut message, "\n{}", message_line).unwrap(); diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 1b4b47215..78d121683 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -249,7 +249,7 @@ impl FromStr for Edition { let res = match s { "2015" => Edition::Edition2015, "2018" => Edition::Edition2018, - _ => Err(ParseEditionError { invalid_input: s.to_string() })?, + _ => return Err(ParseEditionError { invalid_input: s.to_string() }), }; Ok(res) } diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index b6adb7589..fe9149c9d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -283,7 +283,7 @@ impl StructField { }; let substs = Substs::type_params(db, generic_def_id); let ty = db.field_types(var_id)[self.id].clone().subst(&substs); - Type::new(db, self.parent.module(db).id.krate.into(), var_id, ty) + Type::new(db, self.parent.module(db).id.krate, var_id, ty) } pub fn parent_def(&self, _db: &impl HirDatabase) -> VariantDef { @@ -315,11 +315,11 @@ impl Struct { } pub fn name(self, db: &impl DefDatabase) -> Name { - db.struct_data(self.id.into()).name.clone() + db.struct_data(self.id).name.clone() } pub fn fields(self, db: &impl HirDatabase) -> Vec { - db.struct_data(self.id.into()) + db.struct_data(self.id) .variant_data .fields() .iter() @@ -332,7 +332,7 @@ impl Struct { } fn variant_data(self, db: &impl DefDatabase) -> Arc { - db.struct_data(self.id.into()).variant_data.clone() + db.struct_data(self.id).variant_data.clone() } } @@ -1049,7 +1049,7 @@ impl Type { // FIXME check that? let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; let environment = self.ty.environment.clone(); - let ty = InEnvironment { value: canonical, environment: environment.clone() }; + let ty = InEnvironment { value: canonical, environment }; autoderef(db, Some(self.krate), ty) .map(|canonical| canonical.value) .map(move |ty| self.derived(ty)) diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 94d5b4cfd..efa3f8a79 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs @@ -361,9 +361,8 @@ impl SourceAnalyzer { db: &impl HirDatabase, macro_call: InFile<&ast::MacroCall>, ) -> Option { - let macro_call_id = macro_call.as_call_id(db, |path| { - self.resolver.resolve_path_as_macro(db, &path).map(|it| it.into()) - })?; + let macro_call_id = + macro_call.as_call_id(db, |path| self.resolver.resolve_path_as_macro(db, &path))?; Some(Expansion { macro_call_id }) } } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 1fc892362..b1626fa11 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -448,7 +448,7 @@ where // FIXME expand to statements in statement position ast::Expr::MacroCall(e) => { let macro_call = self.expander.to_source(AstPtr::new(&e)); - match self.expander.enter_expand(self.db, e.clone()) { + match self.expander.enter_expand(self.db, e) { Some((mark, expansion)) => { self.source_map .expansions diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index f765e6edc..e07a4f947 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -71,7 +71,7 @@ impl GenericParams { db: &impl DefDatabase, def: GenericDefId, ) -> Arc { - let (params, _source_map) = GenericParams::new(db, def.into()); + let (params, _source_map) = GenericParams::new(db, def); Arc::new(params) } diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index d74a1cef2..f8dc06d10 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs @@ -138,7 +138,7 @@ impl ItemScope { pub(crate) fn push_res(&mut self, name: Name, def: PerNs) -> bool { let mut changed = false; - let existing = self.visible.entry(name.clone()).or_default(); + let existing = self.visible.entry(name).or_default(); if existing.types.is_none() && def.types.is_some() { existing.types = def.types; diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 852304dd0..c5137a0ab 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -156,7 +156,7 @@ impl ModuleOrigin { ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => { let file_id = *definition; let sf = db.parse(file_id).tree(); - return InFile::new(file_id.into(), ModuleSource::SourceFile(sf)); + InFile::new(file_id.into(), ModuleSource::SourceFile(sf)) } ModuleOrigin::Inline { definition } => { InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 650cf1f98..0e8c9da76 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -357,9 +357,7 @@ impl RawItemsCollector { let visibility = RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); let alias = extern_crate.alias().map(|a| { - a.name() - .map(|it| it.as_name()) - .map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a)) + a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) }); let attrs = self.parse_attrs(&extern_crate); // FIXME: cfg_attr diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs index faeb7aa4d..83f429c29 100644 --- a/crates/ra_hir_def/src/nameres/tests/incremental.rs +++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs @@ -116,7 +116,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { let events = db.log_executed(|| { let crate_def_map = db.crate_def_map(krate); let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); - assert_eq!(module_data.scope.resolutions().collect::>().len(), 1); + assert_eq!(module_data.scope.resolutions().count(), 1); }); assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) } @@ -126,7 +126,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { let events = db.log_executed(|| { let crate_def_map = db.crate_def_map(krate); let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); - assert_eq!(module_data.scope.resolutions().collect::>().len(), 1); + assert_eq!(module_data.scope.resolutions().count(), 1); }); assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) } diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index d2bc9d193..b6d1125e2 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs @@ -32,9 +32,7 @@ pub(crate) fn lower_use_tree( } } else { let alias = tree.alias().map(|a| { - a.name() - .map(|it| it.as_name()) - .map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a)) + a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) }); let is_glob = tree.has_star(); if let Some(ast_path) = tree.path() { diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index e2b228e80..5365b80e2 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -474,7 +474,7 @@ impl Scope { f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); }); m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { - f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into(), Visibility::Public))); + f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); }); if let Some(prelude) = m.crate_def_map.prelude { let prelude_def_map = db.crate_def_map(prelude.krate); @@ -499,10 +499,10 @@ impl Scope { } } Scope::ImplBlockScope(i) => { - f(name![Self], ScopeDef::ImplSelfType((*i).into())); + f(name![Self], ScopeDef::ImplSelfType(*i)); } Scope::AdtScope(i) => { - f(name![Self], ScopeDef::AdtSelfType((*i).into())); + f(name![Self], ScopeDef::AdtSelfType(*i)); } Scope::ExprScope(scope) => { scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| { diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index 62c60e336..d0e3eaf7e 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs @@ -235,7 +235,7 @@ mod tests { let (db, file_id) = TestDB::with_single_file(&s); let parsed = db.parse(file_id); let items: Vec<_> = - parsed.syntax_node().descendants().filter_map(|it| ast::ModuleItem::cast(it)).collect(); + parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect(); let ast_id_map = db.ast_id_map(file_id.into()); diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index f3f959ac6..4adaa9b07 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs @@ -158,7 +158,7 @@ fn compile_error_expand( match &tt.token_trees[0] { tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => { let s = it.text.as_str(); - if s.contains(r#"""#) { + if s.contains('"') { return Ok(quote! { loop { #it }}); } } @@ -222,7 +222,7 @@ mod tests { let (db, file_id) = TestDB::with_single_file(&s); let parsed = db.parse(file_id); let macro_calls: Vec<_> = - parsed.syntax_node().descendants().filter_map(|it| ast::MacroCall::cast(it)).collect(); + parsed.syntax_node().descendants().filter_map(ast::MacroCall::cast).collect(); let ast_id_map = db.ast_id_map(file_id.into()); diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs index 4de219ce4..b54e00b68 100644 --- a/crates/ra_hir_expand/src/quote.rs +++ b/crates/ra_hir_expand/src/quote.rs @@ -259,8 +259,7 @@ mod tests { // } let struct_name = mk_ident("Foo"); let fields = [mk_ident("name"), mk_ident("id")]; - let fields = - fields.iter().map(|it| quote!(#it: self.#it.clone(), ).token_trees.clone()).flatten(); + let fields = fields.iter().map(|it| quote!(#it: self.#it.clone(), ).token_trees).flatten(); let list = tt::Subtree { delimiter: Some(tt::Delimiter { diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index a9d958c8b..76069eb9c 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -225,14 +225,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver), db, owner, - body: db.body(owner.into()), + body: db.body(owner), resolver, } } fn resolve_all(mut self) -> InferenceResult { // FIXME resolve obligations as well (use Guidance if necessary) - let mut result = mem::replace(&mut self.result, InferenceResult::default()); + let mut result = std::mem::take(&mut self.result); for ty in result.type_of_expr.values_mut() { let resolved = self.table.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); *ty = resolved; @@ -261,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: AssocItemId) { - self.result.assoc_resolutions.insert(id, item.into()); + self.result.assoc_resolutions.insert(id, item); } fn write_pat_ty(&mut self, pat: PatId, ty: Ty) { @@ -312,9 +312,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { for obligation in obligations { let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); - let solution = self - .db - .trait_solve(self.resolver.krate().unwrap().into(), canonicalized.value.clone()); + let solution = + self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); match solution { Some(Solution::Unique(substs)) => { diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index f68a1439f..4a0eabdfc 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -44,10 +44,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { resolver: &Resolver, ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { let krate = resolver.krate().unwrap(); - let impls = match db.lang_item(krate.into(), "coerce_unsized".into()) { - Some(LangItemTarget::TraitId(trait_)) => { - db.impls_for_trait(krate.into(), trait_.into()) - } + let impls = match db.lang_item(krate, "coerce_unsized".into()) { + Some(LangItemTarget::TraitId(trait_)) => db.impls_for_trait(krate, trait_), _ => return FxHashMap::default(), }; diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 39d8bc0ca..0af94ae32 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -127,10 +127,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, Substs(sig_tys.into()), ); - let closure_ty = Ty::apply_one( - TypeCtor::Closure { def: self.owner.into(), expr: tgt_expr }, - sig_ty, - ); + let closure_ty = + Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty); // Eagerly try to relate the closure type with the expected // type, otherwise we often won't have enough information to @@ -165,7 +163,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Expr::Match { expr, arms } => { let input_ty = self.infer_expr(*expr, &Expectation::none()); - let mut result_ty = if arms.len() == 0 { + let mut result_ty = if arms.is_empty() { Ty::simple(TypeCtor::Never) } else { self.table.new_type_var() @@ -188,7 +186,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } Expr::Path(p) => { // FIXME this could be more efficient... - let resolver = resolver_for_expr(self.db, self.owner.into(), tgt_expr); + let resolver = resolver_for_expr(self.db, self.owner, tgt_expr); self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) } Expr::Continue => Ty::simple(TypeCtor::Never), @@ -217,8 +215,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.unify(&ty, &expected.ty); let substs = ty.substs().unwrap_or_else(Substs::empty); - let field_types = - def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default(); + let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); let variant_data = def_id.map(|it| variant_data(self.db, it)); for (field_idx, field) in fields.iter().enumerate() { let field_def = @@ -264,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), TypeCtor::Adt(AdtId::StructId(s)) => { self.db.struct_data(s).variant_data.field(name).map(|local_id| { - let field = StructFieldId { parent: s.into(), local_id }.into(); + let field = StructFieldId { parent: s.into(), local_id }; self.write_field_resolution(tgt_expr, field); self.db.field_types(s.into())[field.local_id] .clone() @@ -700,10 +697,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // construct a TraitDef let substs = a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); - self.obligations.push(Obligation::Trait(TraitRef { - trait_: trait_.into(), - substs, - })); + self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } } CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index a5dfdf6c4..a495ecbfe 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -28,7 +28,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let substs = ty.substs().unwrap_or_else(Substs::empty); - let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); + let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); for (i, &subpat) in subpats.iter().enumerate() { let expected_ty = var_data @@ -60,7 +60,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let substs = ty.substs().unwrap_or_else(Substs::empty); - let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); + let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); for subpat in subpats { let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); let expected_ty = diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 686ce7a21..471d60342 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -104,8 +104,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let segment = remaining_segments.last().expect("there should be at least one segment here"); let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); - let trait_ref = - TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); + let trait_ref = TraitRef::from_resolved_path(&ctx, trait_, resolved_segment, None); self.resolve_trait_assoc_item(trait_ref, segment, id) } (def, _) => { @@ -144,30 +143,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { id: ExprOrPatId, ) -> Option<(ValueNs, Option)> { let trait_ = trait_ref.trait_; - let item = self - .db - .trait_data(trait_) - .items - .iter() - .map(|(_name, id)| (*id).into()) - .find_map(|item| match item { - AssocItemId::FunctionId(func) => { - if segment.name == &self.db.function_data(func).name { - Some(AssocItemId::FunctionId(func)) - } else { - None + let item = + self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { + match item { + AssocItemId::FunctionId(func) => { + if segment.name == &self.db.function_data(func).name { + Some(AssocItemId::FunctionId(func)) + } else { + None + } } - } - AssocItemId::ConstId(konst) => { - if self.db.const_data(konst).name.as_ref().map_or(false, |n| n == segment.name) - { - Some(AssocItemId::ConstId(konst)) - } else { - None + AssocItemId::ConstId(konst) => { + if self + .db + .const_data(konst) + .name + .as_ref() + .map_or(false, |n| n == segment.name) + { + Some(AssocItemId::ConstId(konst)) + } else { + None + } } + AssocItemId::TypeAliasId(_) => None, } - AssocItemId::TypeAliasId(_) => None, })?; let def = match item { AssocItemId::FunctionId(f) => ValueNs::FunctionId(f), @@ -233,7 +234,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { AssocContainerId::ContainerId(_) => None, }; - self.write_assoc_resolution(id, item.into()); + self.write_assoc_resolution(id, item); Some((def, substs)) }, ) diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 571579cc4..302bb8aa2 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -167,7 +167,7 @@ impl TypeCtor { | TypeCtor::Closure { .. } // 1 param representing the signature of the closure => 1, TypeCtor::Adt(adt) => { - let generic_params = generics(db, AdtId::from(adt).into()); + let generic_params = generics(db, adt.into()); generic_params.len() } TypeCtor::FnDef(callable) => { @@ -247,7 +247,7 @@ pub struct ProjectionTy { impl ProjectionTy { pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { - TraitRef { trait_: self.trait_(db).into(), substs: self.parameters.clone() } + TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } } fn trait_(&self, db: &impl HirDatabase) -> TraitId { diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index c2a3703fa..52da34574 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -361,10 +361,8 @@ impl Ty { for t in traits { if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) { - let substs = Substs::build_for_def(ctx.db, t) - .push(self_ty.clone()) - .fill_with_unknown() - .build(); + let substs = + Substs::build_for_def(ctx.db, t).push(self_ty).fill_with_unknown().build(); // FIXME handle type parameters on the segment return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); } @@ -428,7 +426,7 @@ pub(super) fn substs_from_path_segment( _add_self_param: bool, ) -> Substs { let mut substs = Vec::new(); - let def_generics = def_generic.map(|def| generics(ctx.db, def.into())); + let def_generics = def_generic.map(|def| generics(ctx.db, def)); let (parent_params, self_params, type_params, impl_trait_params) = def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); @@ -459,7 +457,7 @@ pub(super) fn substs_from_path_segment( // handle defaults if let Some(def_generic) = def_generic { - let default_substs = ctx.db.generic_defaults(def_generic.into()); + let default_substs = ctx.db.generic_defaults(def_generic); assert_eq!(substs.len(), default_substs.len()); for (i, default_ty) in default_substs.iter().enumerate() { @@ -483,7 +481,7 @@ impl TraitRef { _ => return None, }; let segment = path.segments().last().expect("path should have at least one segment"); - Some(TraitRef::from_resolved_path(ctx, resolved.into(), segment, explicit_self_ty)) + Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty)) } pub(crate) fn from_resolved_path( @@ -728,7 +726,7 @@ pub(crate) fn generic_predicates_query( pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { let resolver = def.resolver(db); let ctx = TyLoweringContext::new(db, &resolver); - let generic_params = generics(db, def.into()); + let generic_params = generics(db, def); let defaults = generic_params .iter() @@ -792,7 +790,7 @@ fn type_for_builtin(def: BuiltinType) -> Ty { } fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { - let struct_data = db.struct_data(def.into()); + let struct_data = db.struct_data(def); let fields = struct_data.variant_data.fields(); let resolver = def.resolver(db); let ctx = @@ -805,7 +803,7 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn /// Build the type of a tuple struct constructor. fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders { - let struct_data = db.struct_data(def.into()); + let struct_data = db.struct_data(def); if let StructKind::Unit = struct_data.variant_data.kind() { return type_for_adt(db, def.into()); } @@ -836,7 +834,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) } let generics = generics(db, def.parent.into()); let substs = Substs::bound_vars(&generics); - Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(EnumVariantId::from(def).into()), substs)) + Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) } fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders { @@ -964,6 +962,6 @@ pub(crate) fn impl_trait_query( let target_trait = impl_data.target_trait.as_ref()?; Some(Binders::new( self_ty.num_binders, - TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value.clone()))?, + TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value))?, )) } diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 4f8c52433..964acdb09 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs @@ -214,7 +214,7 @@ pub fn iterate_method_candidates( // the methods by autoderef order of *receiver types*, not *self // types*. - let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty.clone()).collect(); + let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect(); for i in 0..deref_chain.len() { if let Some(result) = iterate_method_candidates_with_autoref( &deref_chain[i..], @@ -290,7 +290,7 @@ fn iterate_method_candidates_with_autoref( &ref_muted, deref_chain, db, - env.clone(), + env, krate, &traits_in_scope, name, @@ -391,17 +391,17 @@ fn iterate_trait_method_candidates( // iteration let mut known_implemented = false; for (_name, item) in data.items.iter() { - if !is_valid_candidate(db, name, receiver_ty, (*item).into(), self_ty) { + if !is_valid_candidate(db, name, receiver_ty, *item, self_ty) { continue; } if !known_implemented { let goal = generic_implements_goal(db, env.clone(), t, self_ty.clone()); - if db.trait_solve(krate.into(), goal).is_none() { + if db.trait_solve(krate, goal).is_none() { continue 'traits; } } known_implemented = true; - if let Some(result) = callback(&self_ty.value, (*item).into()) { + if let Some(result) = callback(&self_ty.value, *item) { return Some(result); } } @@ -521,7 +521,7 @@ pub fn implements_trait( return true; } let goal = generic_implements_goal(db, env, trait_, ty.clone()); - let solution = db.trait_solve(krate.into(), goal); + let solution = db.trait_solve(krate, goal); solution.is_some() } diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index dd41176f0..67120abf6 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -98,7 +98,7 @@ fn closure_fn_trait_impl_datum( // the existence of the Fn trait has been checked before .expect("fn trait for closure impl missing"); - let num_args: u16 = match &db.body(data.def.into())[data.expr] { + let num_args: u16 = match &db.body(data.def)[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, _ => { log::warn!("closure for closure type {:?} not found", data); @@ -118,7 +118,7 @@ fn closure_fn_trait_impl_datum( let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); let trait_ref = TraitRef { - trait_: trait_.into(), + trait_, substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), }; @@ -139,7 +139,7 @@ fn closure_fn_trait_output_assoc_ty_value( ) -> BuiltinImplAssocTyValueData { let impl_ = Impl::ClosureFnTraitImpl(data.clone()); - let num_args: u16 = match &db.body(data.def.into())[data.expr] { + let num_args: u16 = match &db.body(data.def)[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, _ => { log::warn!("closure for closure type {:?} not found", data); diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 882160fa8..306909ec2 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -565,10 +565,10 @@ where // and will panic if the trait can't be resolved. let mut result: Vec<_> = self .db - .impls_for_trait(self.krate, trait_.into()) + .impls_for_trait(self.krate, trait_) .iter() .copied() - .map(|it| Impl::ImplBlock(it.into())) + .map(Impl::ImplBlock) .map(|impl_| impl_.to_chalk(self.db)) .collect(); @@ -586,7 +586,7 @@ where false // FIXME } fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc { - self.db.associated_ty_value(self.krate.into(), id) + self.db.associated_ty_value(self.krate, id) } fn custom_clauses(&self) -> Vec> { vec![] @@ -674,7 +674,7 @@ pub(crate) fn struct_datum_query( let where_clauses = type_ctor .as_generic_def() .map(|generic_def| { - let generic_params = generics(db, generic_def.into()); + let generic_params = generics(db, generic_def); let bound_vars = Substs::bound_vars(&generic_params); convert_where_clauses(db, generic_def, &bound_vars) }) @@ -805,7 +805,7 @@ fn type_alias_associated_ty_value( let ty = db.ty(type_alias.into()); let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; let value = chalk_rust_ir::AssociatedTyValue { - impl_id: Impl::ImplBlock(impl_id.into()).to_chalk(db), + impl_id: Impl::ImplBlock(impl_id).to_chalk(db), associated_ty_id: assoc_ty.to_chalk(db), value: make_binders(value_bound, ty.num_binders), }; diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs index 4668784d3..7e9310005 100644 --- a/crates/ra_ide_db/src/change.rs +++ b/crates/ra_ide_db/src/change.rs @@ -44,7 +44,7 @@ impl fmt::Debug for AnalysisChange { if !self.libraries_added.is_empty() { d.field("libraries_added", &self.libraries_added.len()); } - if !self.crate_graph.is_none() { + if self.crate_graph.is_some() { d.field("crate_graph", &self.crate_graph); } d.finish() diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index e36b5a412..2bdea11e1 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs @@ -101,7 +101,7 @@ fn match_subtree( tt::Leaf::Literal(tt::Literal { text: lhs, .. }), tt::Leaf::Literal(tt::Literal { text: rhs, .. }), ) if lhs == rhs => (), - _ => Err(ExpandError::UnexpectedToken)?, + _ => return Err(ExpandError::UnexpectedToken), } } Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs index 50b8011a9..1cdebc216 100644 --- a/crates/ra_mbe/src/parser.rs +++ b/crates/ra_mbe/src/parser.rs @@ -100,7 +100,7 @@ fn next_op<'a>( Op::Repeat { subtree, separator, kind } } tt::TokenTree::Leaf(leaf) => match leaf { - tt::Leaf::Punct(..) => Err(ExpandError::UnexpectedToken)?, + tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken), tt::Leaf::Ident(ident) => { let name = &ident.text; let kind = eat_fragment_kind(src, mode)?; @@ -147,15 +147,15 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option, RepeatKind), Exp for tt in src { let tt = match tt { tt::TokenTree::Leaf(leaf) => leaf, - tt::TokenTree::Subtree(_) => Err(ExpandError::InvalidRepeat)?, + tt::TokenTree::Subtree(_) => return Err(ExpandError::InvalidRepeat), }; let has_sep = match &separator { - Separator::Puncts(puncts) => puncts.len() != 0, + Separator::Puncts(puncts) => !puncts.is_empty(), _ => true, }; match tt { tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { - Err(ExpandError::InvalidRepeat)? + return Err(ExpandError::InvalidRepeat) } tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), @@ -168,11 +168,11 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option, RepeatKind), Exp match &mut separator { Separator::Puncts(puncts) => { if puncts.len() == 3 { - Err(ExpandError::InvalidRepeat)? + return Err(ExpandError::InvalidRepeat); } puncts.push(punct.clone()) } - _ => Err(ExpandError::InvalidRepeat)?, + _ => return Err(ExpandError::InvalidRepeat), } continue; } diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs index c9f42b3dd..eb8b79e9a 100644 --- a/crates/ra_mbe/src/subtree_source.rs +++ b/crates/ra_mbe/src/subtree_source.rs @@ -124,7 +124,7 @@ fn convert_delim(d: Option, closing: bool) -> TtToken { let idx = closing as usize; let kind = kinds[idx]; - let text = if texts.len() > 0 { &texts[idx..texts.len() - (1 - idx)] } else { "" }; + let text = if !texts.is_empty() { &texts[idx..texts.len() - (1 - idx)] } else { "" }; TtToken { kind, is_joint_to_next: false, text: SmolStr::new(text) } } diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index b72d2e9e6..b77b683b5 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -230,10 +230,8 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { p.eat(T![async]); p.eat(T![move]); params::param_list_closure(p); - if opt_fn_ret_type(p) { - if !p.at(T!['{']) { - p.error("expected `{`"); - } + if opt_fn_ret_type(p) && !p.at(T!['{']) { + p.error("expected `{`"); } if p.at_ts(EXPR_FIRST) { diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index f5bf3d7ce..332acc1a0 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs @@ -94,7 +94,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { fn opt_path_type_args(p: &mut Parser, mode: Mode) { match mode { - Mode::Use => return, + Mode::Use => {} Mode::Type => { // test path_fn_trait_args // type F = Box ()>; diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index c267bc85f..660d85b42 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -214,7 +214,7 @@ impl Drop for Profiler { let start = stack.starts.pop().unwrap(); let duration = start.elapsed(); let level = stack.starts.len(); - stack.messages.push(Message { level, duration, label: label }); + stack.messages.push(Message { level, duration, label }); if level == 0 { let stdout = stderr(); let longer_than = stack.filter_data.longer_than; diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 22d226a74..34fd73bb7 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -164,7 +164,7 @@ impl CargoWorkspace { // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` // https://github.com/oli-obk/cargo_metadata/issues/79 meta.features(CargoOpt::NoDefaultFeatures); - } else if cargo_features.features.len() > 0 { + } else if !cargo_features.features.is_empty() { meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); } if let Some(parent) = cargo_toml.parent() { diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 250255813..9e67d2498 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -409,7 +409,7 @@ fn find_cargo_toml(path: &Path) -> Result { } curr = path.parent(); } - Err(CargoTomlNotFoundError(path.to_path_buf()))? + Err(CargoTomlNotFoundError(path.to_path_buf()).into()) } pub fn get_rustc_cfg_options() -> CfgOptions { diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index acf677e7d..21fca99a6 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs @@ -95,16 +95,17 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff { lhs: SyntaxElement, rhs: SyntaxElement, ) { - if lhs.kind() == rhs.kind() && lhs.text_range().len() == rhs.text_range().len() { - if match (&lhs, &rhs) { + if lhs.kind() == rhs.kind() + && lhs.text_range().len() == rhs.text_range().len() + && match (&lhs, &rhs) { (NodeOrToken::Node(lhs), NodeOrToken::Node(rhs)) => { lhs.green() == rhs.green() || lhs.text() == rhs.text() } (NodeOrToken::Token(lhs), NodeOrToken::Token(rhs)) => lhs.text() == rhs.text(), _ => false, - } { - return; } + { + return; } if let (Some(lhs), Some(rhs)) = (lhs.as_node(), rhs.as_node()) { if lhs.children_with_tokens().count() == rhs.children_with_tokens().count() { diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 2e50a095c..77cceb382 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -30,7 +30,7 @@ pub enum ElseBranch { impl ast::IfExpr { pub fn then_branch(&self) -> Option { - self.blocks().nth(0) + self.blocks().next() } pub fn else_branch(&self) -> Option { let res = match self.blocks().nth(1) { @@ -208,7 +208,7 @@ impl ast::BinExpr { } pub fn lhs(&self) -> Option { - children(self).nth(0) + children(self).next() } pub fn rhs(&self) -> Option { @@ -271,7 +271,7 @@ impl ast::RangeExpr { impl ast::IndexExpr { pub fn base(&self) -> Option { - children(self).nth(0) + children(self).next() } pub fn index(&self) -> Option { children(self).nth(1) @@ -287,7 +287,7 @@ impl ast::ArrayExpr { pub fn kind(&self) -> ArrayExprKind { if self.is_repeat() { ArrayExprKind::Repeat { - initializer: children(self).nth(0), + initializer: children(self).next(), repeat: children(self).nth(1), } } else { @@ -328,10 +328,10 @@ impl ast::Literal { } pub fn kind(&self) -> LiteralKind { - const INT_SUFFIXES: [&'static str; 12] = [ + const INT_SUFFIXES: [&str; 12] = [ "u64", "u32", "u16", "u8", "usize", "isize", "i64", "i32", "i16", "i8", "u128", "i128", ]; - const FLOAT_SUFFIXES: [&'static str; 2] = ["f32", "f64"]; + const FLOAT_SUFFIXES: [&str; 2] = ["f32", "f64"]; let token = self.token(); diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 89d1403e7..7c20fcc10 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -152,7 +152,7 @@ pub fn match_arm_list(arms: impl IntoIterator) -> ast::Mat format!(" {}{}\n", arm.syntax(), comma) }) .collect::(); - return from_text(&format!("{}", arms_str)); + return from_text(&arms_str); fn from_text(text: &str) -> ast::MatchArmList { ast_from_text(&format!("fn f() {{ match () {{\n{}}} }}", text)) diff --git a/crates/ra_syntax/src/parsing/text_token_source.rs b/crates/ra_syntax/src/parsing/text_token_source.rs index e793f93a4..e2433913c 100644 --- a/crates/ra_syntax/src/parsing/text_token_source.rs +++ b/crates/ra_syntax/src/parsing/text_token_source.rs @@ -48,7 +48,7 @@ impl<'t> TokenSource for TextTokenSource<'t> { fn is_keyword(&self, kw: &str) -> bool { let pos = self.curr.1; - if !(pos < self.tokens.len()) { + if pos >= self.tokens.len() { return false; } let range = TextRange::offset_len(self.start_offsets[pos], self.tokens[pos].len); diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 69e709a25..dd15b3458 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -4,7 +4,7 @@ mod args; use lsp_server::Connection; -use ra_prof; + use rust_analyzer::{cli, from_json, show_message, Result, ServerConfig}; use crate::args::HelpPrinted; diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 99ab6e443..4d59db1ee 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -130,7 +130,7 @@ pub fn analysis_stats( write!(msg, " ({:?} {})", path, syntax_range).unwrap(); } if verbosity.is_spammy() { - bar.println(format!("{}", msg)); + bar.println(msg.to_string()); } bar.set_message(&msg); let f_id = FunctionId::from(f); diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index dc16a234d..71917a62e 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -206,17 +206,17 @@ pub fn main_loop( let event = select! { recv(&connection.receiver) -> msg => match msg { Ok(msg) => Event::Msg(msg), - Err(RecvError) => Err("client exited without shutdown")?, + Err(RecvError) => return Err("client exited without shutdown".into()), }, recv(task_receiver) -> task => Event::Task(task.unwrap()), recv(world_state.task_receiver) -> task => match task { Ok(task) => Event::Vfs(task), - Err(RecvError) => Err("vfs died")?, + Err(RecvError) => return Err("vfs died".into()), }, recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), recv(world_state.check_watcher.task_recv) -> task => match task { Ok(task) => Event::CheckWatcher(task), - Err(RecvError) => Err("check watcher died")?, + Err(RecvError) => return Err("check watcher died".into()), } }; if let Event::Msg(Message::Request(req)) = &event { diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index 3af63d9cf..970185dec 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs @@ -17,7 +17,7 @@ use test_utils::skip_slow_tests; use crate::support::{project, Project}; -const PROFILE: &'static str = ""; +const PROFILE: &str = ""; // const PROFILE: &'static str = "*@3>100"; #[test] diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index 5b90b3218..e28ae61fe 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs @@ -52,7 +52,7 @@ impl<'a> Project<'a> { let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); static INIT: Once = Once::new(); INIT.call_once(|| { - let _ = env_logger::builder().is_test(true).try_init().unwrap(); + env_logger::builder().is_test(true).try_init().unwrap(); ra_prof::set_filter(if crate::PROFILE.is_empty() { ra_prof::Filter::disabled() } else { diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 336c594a6..e6e8d7110 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -279,7 +279,7 @@ pub fn find_mismatch<'a>(expected: &'a Value, actual: &'a Value) -> Option<(&'a return Some((expected, actual)); } - l.values().zip(r.values()).filter_map(|(l, r)| find_mismatch(l, r)).nth(0) + l.values().zip(r.values()).filter_map(|(l, r)| find_mismatch(l, r)).next() } (&Null, &Null) => None, // magic string literal "{...}" acts as wildcard for any sub-JSON -- cgit v1.2.3