From 0b33563b1075e2838c564d55ce0011b1f4fa31d7 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Tue, 19 Jul 2022 19:27:28 +0200 Subject: [PATCH] Add `./x.py test rust-analyzer` This adds support for testing `rust-analyzer` in-tree. Test rust-analyzer in CI Set CARGO_WORKSPACE_DIR directly in `prepare_tool_cargo` cf. https://github.com/rust-lang/rust/pull/99444#issuecomment-1188945971 cf. https://github.com/rust-analyzer/expect-test/issues/33 Various x.py changes for Submodule => InTree, and removing toolstate Introduce `rust-analyzer/in-rust-tree` cargo feature This allows skipping ra's "check_merge_commits" test for now. Later, it might be used to link against `extern proc_macro` directly, cf. https://github.com/rust-lang/rust-analyzer/issues/12803 More cleanups around the RustAnalyzer tool in bootstrap Start fixing lints Deny the same warnings x.py does in all RA crates Warn on x.py warnings, don't deny cf. https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/rust-analyzer.20as.20a.20subtree.3A.20experimental.20PR.20status/near/290114101 Fix rust_2018_idioms with cargo fix Add warning groups for more RA crates Fix more 2015 idioms (with 2018_idioms, naming is fun) RA passes all x.py warnings Fix formatting after fixing idioms/additional warnings Enable in-rust-tree feature, RA tests pass Print stdout+stderr when nested cargo invocation fails --- src/bootstrap/builder.rs | 1 + src/bootstrap/test.rs | 47 +++++++++++ src/bootstrap/tool.rs | 10 ++- .../crates/base-db/src/change.rs | 2 +- .../rust-analyzer/crates/base-db/src/input.rs | 4 +- .../rust-analyzer/crates/base-db/src/lib.rs | 5 +- .../rust-analyzer/crates/cfg/src/cfg_expr.rs | 2 +- src/tools/rust-analyzer/crates/cfg/src/lib.rs | 1 + .../rust-analyzer/crates/flycheck/src/lib.rs | 1 + .../crates/hir-def/src/generics.rs | 10 +-- .../rust-analyzer/crates/hir-def/src/lib.rs | 1 + .../crates/hir-def/src/nameres/collector.rs | 2 +- .../rust-analyzer/crates/hir-def/src/path.rs | 7 +- .../crates/hir-def/src/path/lower.rs | 6 +- .../crates/hir-def/src/test_db.rs | 2 +- .../crates/hir-def/src/type_ref.rs | 10 +-- .../crates/hir-expand/src/lib.rs | 1 + .../crates/hir-expand/src/mod_path.rs | 2 +- .../crates/hir-expand/src/name.rs | 6 +- .../crates/hir-ty/src/autoderef.rs | 9 +- .../crates/hir-ty/src/builder.rs | 2 +- .../hir-ty/src/diagnostics/match_check.rs | 6 +- .../match_check/deconstruct_pat.rs | 2 +- .../crates/hir-ty/src/display.rs | 56 +++++++------ .../rust-analyzer/crates/hir-ty/src/infer.rs | 21 +++-- .../crates/hir-ty/src/infer/unify.rs | 4 +- .../crates/hir-ty/src/interner.rs | 2 +- .../rust-analyzer/crates/hir-ty/src/lib.rs | 1 + .../rust-analyzer/crates/hir-ty/src/lower.rs | 4 +- .../crates/hir-ty/src/method_resolution.rs | 14 ++-- .../crates/hir-ty/src/test_db.rs | 2 +- .../rust-analyzer/crates/hir-ty/src/tls.rs | 4 +- .../rust-analyzer/crates/hir-ty/src/utils.rs | 2 +- .../rust-analyzer/crates/hir/src/display.rs | 56 +++++++------ src/tools/rust-analyzer/crates/hir/src/lib.rs | 9 +- .../rust-analyzer/crates/hir/src/semantics.rs | 10 +-- .../rust-analyzer/crates/hir/src/symbols.rs | 2 +- .../crates/ide-assists/src/assist_context.rs | 2 +- .../src/handlers/add_explicit_type.rs | 2 +- .../src/handlers/add_label_to_loop.rs | 2 +- .../src/handlers/add_lifetime_to_type.rs | 2 +- .../src/handlers/add_missing_impl_members.rs | 11 ++- .../src/handlers/add_missing_match_arms.rs | 8 +- .../src/handlers/add_return_type.rs | 4 +- .../src/handlers/add_turbo_fish.rs | 2 +- .../src/handlers/apply_demorgan.rs | 2 +- .../ide-assists/src/handlers/auto_import.rs | 8 +- .../src/handlers/change_visibility.rs | 4 +- .../src/handlers/convert_bool_then.rs | 10 +-- .../src/handlers/convert_comment_block.rs | 2 +- .../src/handlers/convert_integer_literal.rs | 2 +- .../src/handlers/convert_into_to_from.rs | 2 +- .../handlers/convert_iter_for_each_to_for.rs | 16 ++-- .../src/handlers/convert_let_else_to_match.rs | 4 +- .../src/handlers/convert_to_guarded_return.rs | 2 +- .../convert_tuple_struct_to_named_struct.rs | 8 +- .../src/handlers/convert_while_to_loop.rs | 2 +- .../src/handlers/destructure_tuple_binding.rs | 30 +++---- .../src/handlers/expand_glob_import.rs | 14 ++-- .../src/handlers/extract_function.rs | 82 ++++++++++--------- .../src/handlers/extract_module.rs | 14 ++-- .../extract_struct_from_enum_variant.rs | 6 +- .../src/handlers/extract_type_alias.rs | 2 +- .../src/handlers/extract_variable.rs | 4 +- .../src/handlers/fix_visibility.rs | 6 +- .../ide-assists/src/handlers/flip_binexpr.rs | 2 +- .../ide-assists/src/handlers/flip_comma.rs | 2 +- .../src/handlers/flip_trait_bound.rs | 2 +- .../src/handlers/generate_constant.rs | 4 +- .../generate_default_from_enum_variant.rs | 2 +- .../src/handlers/generate_default_from_new.rs | 4 +- .../src/handlers/generate_delegate_methods.rs | 2 +- .../src/handlers/generate_deref.rs | 6 +- .../src/handlers/generate_derive.rs | 2 +- .../generate_documentation_template.rs | 22 ++--- .../src/handlers/generate_enum_is_method.rs | 2 +- .../generate_enum_projection_method.rs | 9 +- .../src/handlers/generate_enum_variant.rs | 4 +- .../handlers/generate_from_impl_for_enum.rs | 5 +- .../src/handlers/generate_function.rs | 30 +++---- .../src/handlers/generate_getter.rs | 6 +- .../ide-assists/src/handlers/generate_impl.rs | 2 +- .../handlers/generate_is_empty_from_len.rs | 4 +- .../ide-assists/src/handlers/generate_new.rs | 2 +- .../src/handlers/generate_setter.rs | 2 +- .../ide-assists/src/handlers/inline_call.rs | 6 +- .../src/handlers/inline_local_variable.rs | 6 +- .../src/handlers/inline_type_alias.rs | 4 +- .../src/handlers/introduce_named_generic.rs | 2 +- .../src/handlers/introduce_named_lifetime.rs | 2 +- .../ide-assists/src/handlers/invert_if.rs | 2 +- .../ide-assists/src/handlers/merge_imports.rs | 2 +- .../src/handlers/merge_match_arms.rs | 8 +- .../ide-assists/src/handlers/move_bounds.rs | 5 +- .../src/handlers/move_from_mod_rs.rs | 2 +- .../ide-assists/src/handlers/move_guard.rs | 7 +- .../src/handlers/move_module_to_file.rs | 2 +- .../src/handlers/move_to_mod_rs.rs | 2 +- .../src/handlers/number_representation.rs | 2 +- .../src/handlers/promote_local_to_const.rs | 4 +- .../src/handlers/pull_assignment_up.rs | 4 +- .../src/handlers/qualify_method_call.rs | 2 +- .../ide-assists/src/handlers/qualify_path.rs | 2 +- .../ide-assists/src/handlers/raw_string.rs | 8 +- .../ide-assists/src/handlers/remove_dbg.rs | 2 +- .../ide-assists/src/handlers/remove_mut.rs | 2 +- .../src/handlers/remove_unused_param.rs | 4 +- .../src/handlers/reorder_fields.rs | 7 +- .../src/handlers/reorder_impl_items.rs | 9 +- .../replace_derive_with_manual_impl.rs | 6 +- .../src/handlers/replace_if_let_with_match.rs | 12 +-- .../src/handlers/replace_let_with_if_let.rs | 2 +- .../replace_qualified_name_with_use.rs | 2 +- .../src/handlers/replace_string_with_char.rs | 4 +- .../handlers/replace_try_expr_with_match.rs | 5 +- .../replace_turbofish_with_explicit_type.rs | 2 +- .../ide-assists/src/handlers/sort_items.rs | 2 +- .../ide-assists/src/handlers/split_import.rs | 2 +- .../ide-assists/src/handlers/toggle_ignore.rs | 2 +- .../ide-assists/src/handlers/unmerge_use.rs | 2 +- .../src/handlers/unnecessary_async.rs | 6 +- .../ide-assists/src/handlers/unwrap_block.rs | 2 +- .../src/handlers/unwrap_result_return_type.rs | 2 +- .../handlers/wrap_return_type_in_result.rs | 2 +- .../crates/ide-assists/src/lib.rs | 3 +- .../crates/ide-assists/src/tests.rs | 2 +- .../crates/ide-assists/src/utils.rs | 22 ++--- .../crates/ide-completion/src/completions.rs | 81 ++++++++++-------- .../src/completions/attribute.rs | 4 +- .../src/completions/attribute/cfg.rs | 2 +- .../src/completions/attribute/derive.rs | 2 +- .../src/completions/attribute/lint.rs | 2 +- .../src/completions/attribute/repr.rs | 6 +- .../ide-completion/src/completions/dot.rs | 12 ++- .../ide-completion/src/completions/expr.rs | 2 +- .../src/completions/extern_abi.rs | 2 +- .../ide-completion/src/completions/field.rs | 7 +- .../src/completions/flyimport.rs | 16 ++-- .../src/completions/fn_param.rs | 8 +- .../src/completions/format_string.rs | 2 +- .../src/completions/item_list.rs | 6 +- .../src/completions/item_list/trait_impl.rs | 22 ++--- .../ide-completion/src/completions/keyword.rs | 2 +- .../src/completions/lifetime.rs | 4 +- .../ide-completion/src/completions/mod_.rs | 2 +- .../ide-completion/src/completions/pattern.rs | 4 +- .../ide-completion/src/completions/postfix.rs | 8 +- .../src/completions/postfix/format_like.rs | 2 +- .../ide-completion/src/completions/record.rs | 10 +-- .../ide-completion/src/completions/snippet.rs | 8 +- .../ide-completion/src/completions/type.rs | 4 +- .../ide-completion/src/completions/use_.rs | 2 +- .../ide-completion/src/completions/vis.rs | 2 +- .../crates/ide-completion/src/context.rs | 2 +- .../ide-completion/src/context/analysis.rs | 16 ++-- .../crates/ide-completion/src/item.rs | 4 +- .../crates/ide-completion/src/lib.rs | 1 + .../crates/ide-completion/src/render.rs | 13 +-- .../ide-completion/src/render/function.rs | 8 +- .../ide-completion/src/render/literal.rs | 2 +- .../src/render/union_literal.rs | 2 +- .../ide-completion/src/render/variant.rs | 2 +- .../crates/ide-completion/src/snippet.rs | 4 +- .../crates/ide-db/src/active_parameter.rs | 6 +- .../rust-analyzer/crates/ide-db/src/defs.rs | 26 +++--- .../crates/ide-db/src/helpers.rs | 2 +- .../ide-db/src/imports/import_assets.rs | 35 ++++---- .../rust-analyzer/crates/ide-db/src/lib.rs | 3 +- .../crates/ide-db/src/path_transform.rs | 2 +- .../rust-analyzer/crates/ide-db/src/rename.rs | 16 ++-- .../rust-analyzer/crates/ide-db/src/search.rs | 6 +- .../crates/ide-db/src/symbol_index.rs | 2 +- .../ide-db/src/syntax_helpers/node_ext.rs | 2 +- .../ide-db/src/tests/sourcegen_lints.rs | 2 +- .../rust-analyzer/crates/ide-db/src/traits.rs | 4 +- .../crates/ide-db/src/ty_filter.rs | 2 +- .../src/handlers/no_such_field.rs | 2 +- .../src/handlers/unlinked_file.rs | 8 +- .../crates/ide-diagnostics/src/lib.rs | 1 + .../crates/ide-ssr/src/from_comment.rs | 5 +- .../rust-analyzer/crates/ide-ssr/src/lib.rs | 1 + .../crates/ide-ssr/src/matching.rs | 24 +++--- .../crates/ide-ssr/src/nester.rs | 10 ++- .../crates/ide-ssr/src/resolving.rs | 2 +- .../rust-analyzer/crates/ide-ssr/src/tests.rs | 2 +- .../rust-analyzer/crates/ide/src/doc_links.rs | 8 +- .../crates/ide/src/doc_links/tests.rs | 4 +- .../crates/ide/src/expand_macro.rs | 11 ++- .../crates/ide/src/extend_selection.rs | 4 +- .../crates/ide/src/goto_definition.rs | 4 +- .../crates/ide/src/goto_implementation.rs | 9 +- .../crates/ide/src/highlight_related.rs | 10 +-- .../rust-analyzer/crates/ide/src/hover.rs | 8 +- .../crates/ide/src/hover/render.rs | 16 ++-- .../crates/ide/src/inlay_hints.rs | 34 ++++---- src/tools/rust-analyzer/crates/ide/src/lib.rs | 2 +- .../crates/ide/src/references.rs | 8 +- .../rust-analyzer/crates/ide/src/rename.rs | 9 +- .../rust-analyzer/crates/ide/src/runnables.rs | 29 ++++--- .../crates/ide/src/signature_help.rs | 4 +- .../crates/ide/src/static_index.rs | 4 +- .../rust-analyzer/crates/ide/src/status.rs | 6 +- .../crates/ide/src/syntax_highlighting.rs | 2 +- .../ide/src/syntax_highlighting/highlight.rs | 28 ++++--- .../ide/src/syntax_highlighting/inject.rs | 4 +- .../rust-analyzer/crates/limit/src/lib.rs | 1 + .../crates/mbe/src/expander/matcher.rs | 6 +- .../crates/mbe/src/expander/transcriber.rs | 6 +- src/tools/rust-analyzer/crates/mbe/src/lib.rs | 3 +- .../rust-analyzer/crates/mbe/src/parser.rs | 4 +- .../crates/mbe/src/to_parser_input.rs | 2 +- .../crates/parser/src/grammar.rs | 54 ++++++------ .../crates/parser/src/grammar/attributes.rs | 8 +- .../crates/parser/src/grammar/expressions.rs | 45 +++++----- .../parser/src/grammar/expressions/atom.rs | 49 +++++------ .../crates/parser/src/grammar/generic_args.rs | 12 +-- .../parser/src/grammar/generic_params.rs | 28 +++---- .../crates/parser/src/grammar/items.rs | 30 +++---- .../crates/parser/src/grammar/items/adt.rs | 18 ++-- .../crates/parser/src/grammar/items/consts.rs | 6 +- .../crates/parser/src/grammar/items/traits.rs | 10 +-- .../parser/src/grammar/items/use_item.rs | 6 +- .../crates/parser/src/grammar/params.rs | 18 ++-- .../crates/parser/src/grammar/paths.rs | 27 +++--- .../crates/parser/src/grammar/patterns.rs | 44 +++++----- .../crates/parser/src/grammar/types.rs | 38 ++++----- .../rust-analyzer/crates/parser/src/lib.rs | 7 +- .../rust-analyzer/crates/parser/src/parser.rs | 8 +- .../crates/parser/src/shortcuts.rs | 2 +- .../rust-analyzer/crates/paths/src/lib.rs | 1 + .../crates/proc-macro-api/src/lib.rs | 1 + .../proc-macro-srv/src/abis/abi_1_58/mod.rs | 2 +- .../proc-macro-srv/src/abis/abi_1_63/mod.rs | 2 +- .../proc-macro-srv/src/abis/abi_1_64/mod.rs | 2 +- .../crates/proc-macro-srv/src/lib.rs | 1 + .../crates/proc-macro-test/build.rs | 7 +- .../crates/proc-macro-test/src/lib.rs | 1 + .../rust-analyzer/crates/profile/src/lib.rs | 1 + .../crates/profile/src/memory_usage.rs | 4 +- .../crates/project-model/src/lib.rs | 1 + .../crates/rust-analyzer/Cargo.toml | 1 + .../crates/rust-analyzer/src/bin/logger.rs | 2 +- .../crates/rust-analyzer/src/bin/main.rs | 1 + .../crates/rust-analyzer/src/config.rs | 6 +- .../crates/rust-analyzer/src/diff.rs | 2 +- .../crates/rust-analyzer/src/lib.rs | 3 +- .../crates/rust-analyzer/src/main_loop.rs | 4 +- .../rust-analyzer/tests/slow-tests/main.rs | 1 + .../rust-analyzer/tests/slow-tests/support.rs | 2 +- .../rust-analyzer/tests/slow-tests/tidy.rs | 1 + .../rust-analyzer/crates/sourcegen/src/lib.rs | 1 + .../rust-analyzer/crates/stdx/src/lib.rs | 1 + .../crates/syntax/src/ast/node_ext.rs | 2 +- .../rust-analyzer/crates/syntax/src/lib.rs | 1 + .../crates/syntax/src/syntax_error.rs | 2 +- .../crates/syntax/src/tests/ast_src.rs | 2 +- .../crates/syntax/src/token_text.rs | 8 +- .../crates/test-utils/src/lib.rs | 3 +- .../rust-analyzer/crates/text-edit/src/lib.rs | 1 + .../rust-analyzer/crates/toolchain/src/lib.rs | 1 + .../rust-analyzer/crates/tt/src/buffer.rs | 6 +- src/tools/rust-analyzer/crates/tt/src/lib.rs | 13 +-- .../crates/vfs-notify/src/lib.rs | 1 + src/tools/rust-analyzer/crates/vfs/src/lib.rs | 1 + .../rust-analyzer/lib/la-arena/src/lib.rs | 6 +- src/tools/rust-analyzer/xtask/src/main.rs | 1 + 266 files changed, 1140 insertions(+), 900 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 1aa79f5566aa6..d80f7c518958f 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -648,6 +648,7 @@ impl<'a> Builder<'a> { test::Cargotest, test::Cargo, test::Rls, + test::RustAnalyzer, test::ErrorIndex, test::Distcheck, test::RunMakeFullDeps, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 4c6b5ba0afc08..451c3360edf57 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -352,6 +352,53 @@ impl Step for Rls { } } +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct RustAnalyzer { + stage: u32, + host: TargetSelection, +} + +impl Step for RustAnalyzer { + type Output = (); + const ONLY_HOSTS: bool = true; + const DEFAULT: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.path("src/tools/rust-analyzer") + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target }); + } + + /// Runs `cargo test` for rust-analyzer. + fn run(self, builder: &Builder<'_>) { + let stage = self.stage; + let host = self.host; + let compiler = builder.compiler(stage, host); + + builder + .ensure(tool::RustAnalyzer { compiler, target: self.host, extra_features: Vec::new() }) + .expect("in-tree tool"); + + let mut cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolStd, + host, + "test", + "src/tools/rust-analyzer", + SourceType::InTree, + &["rust-analyzer/in-rust-tree".to_owned()], + ); + + cargo.add_rustc_lib_path(builder, compiler); + cargo.arg("--").args(builder.config.cmd.test_args()); + + builder.run(&mut cargo.into()); + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Rustfmt { stage: u32, diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index f659ccbe2507f..c5e021d197742 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::env; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process::Command; use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step}; @@ -250,6 +250,10 @@ pub fn prepare_tool_cargo( } } + // cargo doesn't set this env var yet, but it's needed by expect-test + // to build correct absolute paths for test_data files + cargo.env("CARGO_WORKSPACE_DIR", &dir); + // clippy tests need to know about the stage sysroot. Set them consistently while building to // avoid rebuilding when running tests. cargo.env("SYSROOT", builder.sysroot(compiler)); @@ -780,7 +784,9 @@ tool_extended!((self, builder), // and this is close enough for now. RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, tool_std=true, {}; Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {}; - RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, submodule="rust-analyzer", {}; + RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, in_tree=true, tool_std=true, { + self.extra_features.push("in-rust-tree".to_owned()); + }; ); impl<'a> Builder<'a> { diff --git a/src/tools/rust-analyzer/crates/base-db/src/change.rs b/src/tools/rust-analyzer/crates/base-db/src/change.rs index 7e645d0fa8735..b57f2345767d0 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/change.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/change.rs @@ -17,7 +17,7 @@ pub struct Change { } impl fmt::Debug for Change { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let mut d = fmt.debug_struct("Change"); if let Some(roots) = &self.roots { d.field("roots", roots); diff --git a/src/tools/rust-analyzer/crates/base-db/src/input.rs b/src/tools/rust-analyzer/crates/base-db/src/input.rs index 459b82599f39f..9b5a10acfbeaf 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/input.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/input.rs @@ -104,7 +104,7 @@ impl CrateName { } impl fmt::Display for CrateName { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } @@ -187,7 +187,7 @@ impl From for CrateDisplayName { } impl fmt::Display for CrateDisplayName { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.crate_name.fmt(f) } } diff --git a/src/tools/rust-analyzer/crates/base-db/src/lib.rs b/src/tools/rust-analyzer/crates/base-db/src/lib.rs index f5622ecf60706..1c861f4dd8c65 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/lib.rs @@ -1,4 +1,5 @@ //! base_db defines basic database traits. The concrete DB is defined by ide. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod input; mod change; pub mod fixture; @@ -54,7 +55,7 @@ pub const DEFAULT_LRU_CAP: usize = 128; pub trait FileLoader { /// Text of the file. fn file_text(&self, file_id: FileId) -> Arc; - fn resolve_path(&self, path: AnchoredPath) -> Option; + fn resolve_path(&self, path: AnchoredPath<'_>) -> Option; fn relevant_crates(&self, file_id: FileId) -> Arc>; } @@ -113,7 +114,7 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { fn file_text(&self, file_id: FileId) -> Arc { SourceDatabaseExt::file_text(self.0, file_id) } - fn resolve_path(&self, path: AnchoredPath) -> Option { + fn resolve_path(&self, path: AnchoredPath<'_>) -> Option { // FIXME: this *somehow* should be platform agnostic... let source_root = self.0.file_source_root(path.anchor); let source_root = self.0.source_root(source_root); diff --git a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs index 5db5e5d3902f5..fd9e31ed3b4f5 100644 --- a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs +++ b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs @@ -85,7 +85,7 @@ impl CfgExpr { } } -fn next_cfg_expr(it: &mut SliceIter) -> Option { +fn next_cfg_expr(it: &mut SliceIter<'_, tt::TokenTree>) -> Option { let name = match it.next() { None => return None, Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.text.clone(), diff --git a/src/tools/rust-analyzer/crates/cfg/src/lib.rs b/src/tools/rust-analyzer/crates/cfg/src/lib.rs index 837b8d4c9248e..b8669634ed891 100644 --- a/src/tools/rust-analyzer/crates/cfg/src/lib.rs +++ b/src/tools/rust-analyzer/crates/cfg/src/lib.rs @@ -1,4 +1,5 @@ //! cfg defines conditional compiling options, `cfg` attribute parser and evaluator +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod cfg_expr; mod dnf; diff --git a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs index f683fe61fe380..18e1c9d2e17f9 100644 --- a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs +++ b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs @@ -1,6 +1,7 @@ //! Flycheck provides the functionality needed to run `cargo check` or //! another compatible command (f.x. clippy) in a background thread and provide //! LSP diagnostics based on the output of the command. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::{ fmt, io, diff --git a/src/tools/rust-analyzer/crates/hir-def/src/generics.rs b/src/tools/rust-analyzer/crates/hir-def/src/generics.rs index eec960aa7dd00..2397cf5015848 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/generics.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/generics.rs @@ -195,7 +195,7 @@ impl GenericParams { } } - pub(crate) fn fill(&mut self, lower_ctx: &LowerCtx, node: &dyn HasGenericParams) { + pub(crate) fn fill(&mut self, lower_ctx: &LowerCtx<'_>, node: &dyn HasGenericParams) { if let Some(params) = node.generic_param_list() { self.fill_params(lower_ctx, params) } @@ -206,7 +206,7 @@ impl GenericParams { pub(crate) fn fill_bounds( &mut self, - lower_ctx: &LowerCtx, + lower_ctx: &LowerCtx<'_>, node: &dyn ast::HasTypeBounds, target: Either, ) { @@ -217,7 +217,7 @@ impl GenericParams { } } - fn fill_params(&mut self, lower_ctx: &LowerCtx, params: ast::GenericParamList) { + fn fill_params(&mut self, lower_ctx: &LowerCtx<'_>, params: ast::GenericParamList) { for type_or_const_param in params.type_or_const_params() { match type_or_const_param { ast::TypeOrConstParam::Type(type_param) => { @@ -259,7 +259,7 @@ impl GenericParams { } } - fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) { + fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx<'_>, where_clause: ast::WhereClause) { for pred in where_clause.predicates() { let target = if let Some(type_ref) = pred.ty() { Either::Left(TypeRef::from_ast(lower_ctx, type_ref)) @@ -293,7 +293,7 @@ impl GenericParams { fn add_where_predicate_from_bound( &mut self, - lower_ctx: &LowerCtx, + lower_ctx: &LowerCtx<'_>, bound: ast::TypeBound, hrtb_lifetimes: Option<&Box<[Name]>>, target: Either, diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs index 4431d1b3c817e..a602c58cfa4f9 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs @@ -6,6 +6,7 @@ //! //! Note that `hir_def` is a work in progress, so not all of the above is //! actually true. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] #[allow(unused)] macro_rules! eprintln { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs index 317e21538b0da..5f40d26a2ed7e 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs @@ -1509,7 +1509,7 @@ impl ModCollector<'_, '_> { let module = self.def_collector.def_map.module_id(self.module_id); let def_map = &mut self.def_collector.def_map; let update_def = - |def_collector: &mut DefCollector, id, name: &Name, vis, has_constructor| { + |def_collector: &mut DefCollector<'_>, id, name: &Name, vis, has_constructor| { def_collector.def_map.modules[self.module_id].scope.declare(id); def_collector.update( self.module_id, diff --git a/src/tools/rust-analyzer/crates/hir-def/src/path.rs b/src/tools/rust-analyzer/crates/hir-def/src/path.rs index 3aade788d7e87..2f13a9fbf0e40 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/path.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/path.rs @@ -88,7 +88,7 @@ pub enum GenericArg { impl Path { /// Converts an `ast::Path` to `Path`. Works with use trees. /// It correctly handles `$crate` based path from macro call. - pub fn from_src(path: ast::Path, ctx: &LowerCtx) -> Option { + pub fn from_src(path: ast::Path, ctx: &LowerCtx<'_>) -> Option { lower::lower_path(path, ctx) } @@ -188,7 +188,10 @@ impl<'a> PathSegments<'a> { } impl GenericArgs { - pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::GenericArgList) -> Option { + pub(crate) fn from_ast( + lower_ctx: &LowerCtx<'_>, + node: ast::GenericArgList, + ) -> Option { lower::lower_generic_args(lower_ctx, node) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/path/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/path/lower.rs index b6a24cd4ab17a..0428f1a398b1a 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/path/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/path/lower.rs @@ -15,7 +15,7 @@ use crate::{ /// Converts an `ast::Path` to `Path`. Works with use trees. /// It correctly handles `$crate` based path from macro call. -pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { +pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option { let mut kind = PathKind::Plain; let mut type_anchor = None; let mut segments = Vec::new(); @@ -149,7 +149,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { } pub(super) fn lower_generic_args( - lower_ctx: &LowerCtx, + lower_ctx: &LowerCtx<'_>, node: ast::GenericArgList, ) -> Option { let mut args = Vec::new(); @@ -196,7 +196,7 @@ pub(super) fn lower_generic_args( /// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y) /// -> Z` (which desugars to `Fn<(X, Y), Output=Z>`). fn lower_generic_args_from_fn_path( - ctx: &LowerCtx, + ctx: &LowerCtx<'_>, params: Option, ret_type: Option, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/test_db.rs b/src/tools/rust-analyzer/crates/hir-def/src/test_db.rs index baf71731f4970..9cdc18d6b66fd 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/test_db.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/test_db.rs @@ -73,7 +73,7 @@ impl FileLoader for TestDB { fn file_text(&self, file_id: FileId) -> Arc { FileLoaderDelegate(self).file_text(file_id) } - fn resolve_path(&self, path: AnchoredPath) -> Option { + fn resolve_path(&self, path: AnchoredPath<'_>) -> Option { FileLoaderDelegate(self).resolve_path(path) } fn relevant_crates(&self, file_id: FileId) -> Arc> { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/type_ref.rs b/src/tools/rust-analyzer/crates/hir-def/src/type_ref.rs index 6be78745f12d7..97aeed819af0f 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/type_ref.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/type_ref.rs @@ -86,7 +86,7 @@ pub struct TraitRef { impl TraitRef { /// Converts an `ast::PathType` to a `hir::TraitRef`. - pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Option { + pub(crate) fn from_ast(ctx: &LowerCtx<'_>, node: ast::Type) -> Option { // FIXME: Use `Path::from_src` match node { ast::Type::PathType(path) => { @@ -159,7 +159,7 @@ pub enum TraitBoundModifier { impl TypeRef { /// Converts an `ast::TypeRef` to a `hir::TypeRef`. - pub fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { + pub fn from_ast(ctx: &LowerCtx<'_>, node: ast::Type) -> Self { match node { ast::Type::ParenType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()), ast::Type::TupleType(inner) => { @@ -245,7 +245,7 @@ impl TypeRef { } } - pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option) -> Self { + pub(crate) fn from_ast_opt(ctx: &LowerCtx<'_>, node: Option) -> Self { match node { Some(node) => TypeRef::from_ast(ctx, node), None => TypeRef::Error, @@ -320,7 +320,7 @@ impl TypeRef { } pub(crate) fn type_bounds_from_ast( - lower_ctx: &LowerCtx, + lower_ctx: &LowerCtx<'_>, type_bounds_opt: Option, ) -> Vec> { if let Some(type_bounds) = type_bounds_opt { @@ -331,7 +331,7 @@ pub(crate) fn type_bounds_from_ast( } impl TypeBound { - pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeBound) -> Self { + pub(crate) fn from_ast(ctx: &LowerCtx<'_>, node: ast::TypeBound) -> Self { let lower_path_type = |path_type: ast::PathType| ctx.lower_path(path_type.path()?); match node.kind() { diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs index 8fcfad20095f4..abca192b90ed9 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs @@ -3,6 +3,7 @@ //! Specifically, it implements a concept of `MacroFile` -- a file whose syntax //! tree originates not from the text of some `FileId`, but from some macro //! expansion. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] pub mod db; pub mod ast_id_map; diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs b/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs index 05e8c585c9832..fea09521e87cb 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs @@ -102,7 +102,7 @@ impl ModPath { } } - pub fn escaped(&self) -> EscapedModPath { + pub fn escaped(&self) -> EscapedModPath<'_> { EscapedModPath(self) } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/name.rs b/src/tools/rust-analyzer/crates/hir-expand/src/name.rs index 6b48258f37164..85b0a7735fe94 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/name.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/name.rs @@ -21,7 +21,7 @@ enum Repr { } impl fmt::Display for Name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.0 { Repr::Text(text) => fmt::Display::fmt(&text, f), Repr::TupleField(idx) => fmt::Display::fmt(&idx, f), @@ -35,7 +35,7 @@ fn is_raw_identifier(name: &str) -> bool { } impl<'a> fmt::Display for EscapedName<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.0 .0 { Repr::Text(text) => { if is_raw_identifier(text) { @@ -142,7 +142,7 @@ impl Name { } } - pub fn escaped(&self) -> EscapedName { + pub fn escaped(&self) -> EscapedName<'_> { EscapedName(self) } } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs index 22cb856535e45..b6f226dbfd20d 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs @@ -70,7 +70,10 @@ impl Iterator for Autoderef<'_, '_> { } } -pub(crate) fn autoderef_step(table: &mut InferenceTable, ty: Ty) -> Option<(AutoderefKind, Ty)> { +pub(crate) fn autoderef_step( + table: &mut InferenceTable<'_>, + ty: Ty, +) -> Option<(AutoderefKind, Ty)> { if let Some(derefed) = builtin_deref(&ty) { Some((AutoderefKind::Builtin, table.resolve_ty_shallow(derefed))) } else { @@ -94,7 +97,7 @@ pub fn autoderef<'a>( v.into_iter() } -pub(crate) fn deref(table: &mut InferenceTable, ty: Ty) -> Option { +pub(crate) fn deref(table: &mut InferenceTable<'_>, ty: Ty) -> Option { let _p = profile::span("deref"); autoderef_step(table, ty).map(|(_, ty)| ty) } @@ -107,7 +110,7 @@ fn builtin_deref(ty: &Ty) -> Option<&Ty> { } } -fn deref_by_trait(table: &mut InferenceTable, ty: Ty) -> Option { +fn deref_by_trait(table: &mut InferenceTable<'_>, ty: Ty) -> Option { let _p = profile::span("deref_by_trait"); if table.resolve_ty_shallow(&ty).inference_var(Interner).is_some() { // don't try to deref unknown variables diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs b/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs index 23587cc6d0db7..94d7806cb6e8f 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs @@ -111,7 +111,7 @@ impl TyBuilder { this } - pub(crate) fn fill_with_inference_vars(self, table: &mut InferenceTable) -> Self { + pub(crate) fn fill_with_inference_vars(self, table: &mut InferenceTable<'_>) -> Self { self.fill(|x| match x { ParamKind::Type => GenericArgData::Ty(table.new_type_var()).intern(Interner), ParamKind::Const(ty) => { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check.rs index 61cab7be03309..d51ad72bd27b1 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check.rs @@ -292,7 +292,7 @@ impl<'a> PatCtxt<'a> { } impl HirDisplay for Pat { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match &*self.kind { PatKind::Wild => write!(f, "_"), PatKind::Binding { name, subpattern } => { @@ -394,11 +394,11 @@ impl HirDisplay for Pat { struct WriteWith(F) where - F: Fn(&mut HirFormatter) -> Result<(), HirDisplayError>; + F: Fn(&mut HirFormatter<'_>) -> Result<(), HirDisplayError>; impl HirDisplay for WriteWith where - F: Fn(&mut HirFormatter) -> Result<(), HirDisplayError>, + F: Fn(&mut HirFormatter<'_>) -> Result<(), HirDisplayError>, { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { (self.0)(f) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/deconstruct_pat.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/deconstruct_pat.rs index f92d79949d61e..bbbe539c13fbe 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/deconstruct_pat.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/deconstruct_pat.rs @@ -144,7 +144,7 @@ impl IntRange { } } - fn to_pat(&self, _cx: &MatchCheckCtx, ty: Ty) -> Pat { + fn to_pat(&self, _cx: &MatchCheckCtx<'_, '_>, ty: Ty) -> Pat { match ty.kind(Interner) { TyKind::Scalar(Scalar::Bool) => { let kind = match self.boundaries() { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index 2609a60794510..d2f9c2b8b1e1d 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -45,7 +45,7 @@ pub struct HirFormatter<'a> { } pub trait HirDisplay { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError>; + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError>; /// Returns a `Display`able type that is human-readable. fn into_displayable<'a>( @@ -162,7 +162,7 @@ impl<'a> HirFormatter<'a> { } /// This allows using the `write!` macro directly with a `HirFormatter`. - pub fn write_fmt(&mut self, args: fmt::Arguments) -> Result<(), HirDisplayError> { + pub fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<(), HirDisplayError> { // We write to a buffer first to track output size self.buf.clear(); fmt::write(&mut self.buf, args)?; @@ -247,7 +247,7 @@ impl<'a, T> fmt::Display for HirDisplayWrapper<'a, T> where T: HirDisplay, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.t.hir_fmt(&mut HirFormatter { db: self.db, fmt: f, @@ -270,19 +270,19 @@ where const TYPE_HINT_TRUNCATION: &str = "…"; impl HirDisplay for &'_ T { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { HirDisplay::hir_fmt(*self, f) } } impl HirDisplay for Interned { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { HirDisplay::hir_fmt(self.as_ref(), f) } } impl HirDisplay for ProjectionTy { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -302,7 +302,7 @@ impl HirDisplay for ProjectionTy { } impl HirDisplay for OpaqueTy { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -312,7 +312,7 @@ impl HirDisplay for OpaqueTy { } impl HirDisplay for GenericArg { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self.interned() { crate::GenericArgData::Ty(ty) => ty.hir_fmt(f), crate::GenericArgData::Lifetime(lt) => lt.hir_fmt(f), @@ -322,7 +322,7 @@ impl HirDisplay for GenericArg { } impl HirDisplay for Const { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { let data = self.interned(); match data.value { ConstValue::BoundVar(idx) => idx.hir_fmt(f), @@ -339,13 +339,13 @@ impl HirDisplay for Const { } impl HirDisplay for BoundVar { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write!(f, "?{}.{}", self.debruijn.depth(), self.index) } } impl HirDisplay for Ty { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -790,7 +790,7 @@ impl HirDisplay for Ty { } impl HirDisplay for CallableSig { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write!(f, "fn(")?; f.write_joined(self.params(), ", ")?; if self.is_varargs { @@ -839,7 +839,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix( prefix: &str, predicates: &[QuantifiedWhereClause], default_sized: SizedByDefault, - f: &mut HirFormatter, + f: &mut HirFormatter<'_>, ) -> Result<(), HirDisplayError> { write!(f, "{}", prefix)?; if !predicates.is_empty() @@ -855,7 +855,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix( fn write_bounds_like_dyn_trait( predicates: &[QuantifiedWhereClause], default_sized: SizedByDefault, - f: &mut HirFormatter, + f: &mut HirFormatter<'_>, ) -> Result<(), HirDisplayError> { // Note: This code is written to produce nice results (i.e. // corresponding to surface Rust) for types that can occur in @@ -952,7 +952,11 @@ fn write_bounds_like_dyn_trait( Ok(()) } -fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { +fn fmt_trait_ref( + tr: &TraitRef, + f: &mut HirFormatter<'_>, + use_as: bool, +) -> Result<(), HirDisplayError> { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -973,13 +977,13 @@ fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<() } impl HirDisplay for TraitRef { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { fmt_trait_ref(self, f, false) } } impl HirDisplay for WhereClause { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -1007,7 +1011,7 @@ impl HirDisplay for WhereClause { } impl HirDisplay for LifetimeOutlives { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { self.a.hir_fmt(f)?; write!(f, ": ")?; self.b.hir_fmt(f) @@ -1015,13 +1019,13 @@ impl HirDisplay for LifetimeOutlives { } impl HirDisplay for Lifetime { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { self.interned().hir_fmt(f) } } impl HirDisplay for LifetimeData { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { LifetimeData::BoundVar(idx) => idx.hir_fmt(f), LifetimeData::InferenceVar(_) => write!(f, "_"), @@ -1040,7 +1044,7 @@ impl HirDisplay for LifetimeData { } impl HirDisplay for DomainGoal { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { DomainGoal::Holds(wc) => { write!(f, "Holds(")?; @@ -1056,7 +1060,7 @@ impl HirDisplay for DomainGoal { pub fn write_visibility( module_id: ModuleId, vis: Visibility, - f: &mut HirFormatter, + f: &mut HirFormatter<'_>, ) -> Result<(), HirDisplayError> { match vis { Visibility::Public => write!(f, "pub "), @@ -1078,7 +1082,7 @@ pub fn write_visibility( } impl HirDisplay for TypeRef { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { TypeRef::Never => write!(f, "!")?, TypeRef::Placeholder => write!(f, "_")?, @@ -1177,7 +1181,7 @@ impl HirDisplay for TypeRef { } impl HirDisplay for TypeBound { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { TypeBound::Path(path, modifier) => { match modifier { @@ -1197,7 +1201,7 @@ impl HirDisplay for TypeBound { } impl HirDisplay for Path { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match (self.type_anchor(), self.kind()) { (Some(anchor), _) => { write!(f, "<")?; @@ -1301,7 +1305,7 @@ impl HirDisplay for Path { } impl HirDisplay for hir_def::path::GenericArg { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { hir_def::path::GenericArg::Type(ty) => ty.hir_fmt(f), hir_def::path::GenericArg::Const(c) => write!(f, "{}", c), diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs index c7c8deaaeed3b..46eeea0e6fc4e 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs @@ -130,7 +130,7 @@ trait PatLike: Into + Copy { type BindingMode: Copy; fn infer( - this: &mut InferenceContext, + this: &mut InferenceContext<'_>, id: Self, expected_ty: &Ty, default_bm: Self::BindingMode, @@ -140,7 +140,12 @@ trait PatLike: Into + Copy { impl PatLike for ExprId { type BindingMode = (); - fn infer(this: &mut InferenceContext, id: Self, expected_ty: &Ty, _: Self::BindingMode) -> Ty { + fn infer( + this: &mut InferenceContext<'_>, + id: Self, + expected_ty: &Ty, + _: Self::BindingMode, + ) -> Ty { this.infer_assignee_expr(id, expected_ty) } } @@ -149,7 +154,7 @@ impl PatLike for PatId { type BindingMode = BindingMode; fn infer( - this: &mut InferenceContext, + this: &mut InferenceContext<'_>, id: Self, expected_ty: &Ty, default_bm: Self::BindingMode, @@ -971,7 +976,7 @@ impl Expectation { /// which still is useful, because it informs integer literals and the like. /// See the test case `test/ui/coerce-expect-unsized.rs` and #20169 /// for examples of where this comes up,. - fn rvalue_hint(table: &mut unify::InferenceTable, ty: Ty) -> Self { + fn rvalue_hint(table: &mut unify::InferenceTable<'_>, ty: Ty) -> Self { // FIXME: do struct_tail_without_normalization match table.resolve_ty_shallow(&ty).kind(Interner) { TyKind::Slice(_) | TyKind::Str | TyKind::Dyn(_) => Expectation::RValueLikeUnsized(ty), @@ -984,7 +989,7 @@ impl Expectation { Expectation::None } - fn resolve(&self, table: &mut unify::InferenceTable) -> Expectation { + fn resolve(&self, table: &mut unify::InferenceTable<'_>) -> Expectation { match self { Expectation::None => Expectation::None, Expectation::HasType(t) => Expectation::HasType(table.resolve_ty_shallow(t)), @@ -994,7 +999,7 @@ impl Expectation { } } - fn to_option(&self, table: &mut unify::InferenceTable) -> Option { + fn to_option(&self, table: &mut unify::InferenceTable<'_>) -> Option { match self.resolve(table) { Expectation::None => None, Expectation::HasType(t) | @@ -1003,7 +1008,7 @@ impl Expectation { } } - fn only_has_type(&self, table: &mut unify::InferenceTable) -> Option { + fn only_has_type(&self, table: &mut unify::InferenceTable<'_>) -> Option { match self { Expectation::HasType(t) => Some(table.resolve_ty_shallow(t)), // Expectation::Castable(_) | @@ -1028,7 +1033,7 @@ impl Expectation { /// an expected type. Otherwise, we might write parts of the type /// when checking the 'then' block which are incompatible with the /// 'else' branch. - fn adjust_for_branches(&self, table: &mut unify::InferenceTable) -> Expectation { + fn adjust_for_branches(&self, table: &mut unify::InferenceTable<'_>) -> Expectation { match self { Expectation::HasType(ety) => { let ety = table.resolve_ty_shallow(ety); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs index 014109f03d2cd..e77b55670b5e1 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs @@ -43,7 +43,7 @@ where impl> Canonicalized { pub(super) fn apply_solution( &self, - ctx: &mut InferenceTable, + ctx: &mut InferenceTable<'_>, solution: Canonical, ) { // the solution may contain new variables, which we need to convert to new inference vars @@ -391,7 +391,7 @@ impl<'a> InferenceTable<'a> { self.pending_obligations = snapshot.pending_obligations; } - pub(crate) fn run_in_snapshot(&mut self, f: impl FnOnce(&mut InferenceTable) -> T) -> T { + pub(crate) fn run_in_snapshot(&mut self, f: impl FnOnce(&mut InferenceTable<'_>) -> T) -> T { let snapshot = self.snapshot(); let result = f(self); self.rollback_to(snapshot); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/interner.rs b/src/tools/rust-analyzer/crates/hir-ty/src/interner.rs index c34c4b8a7c13e..ca76e08fddb91 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/interner.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/interner.rs @@ -168,7 +168,7 @@ impl chalk_ir::interner::Interner for Interner { } fn debug_separator_trait_ref( - separator_trait_ref: &chalk_ir::SeparatorTraitRef, + separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>, fmt: &mut fmt::Formatter<'_>, ) -> Option { Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner))) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs index 5abbee89711d7..5b5423cc00940 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs @@ -1,5 +1,6 @@ //! The type system. We currently use this to infer types for completion, hover //! information and various assists. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] #[allow(unused)] macro_rules! eprintln { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs index 1605c932d63e0..a9420514a2bc2 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs @@ -106,7 +106,7 @@ impl<'a> TyLoweringContext<'a> { pub fn with_debruijn( &self, debruijn: DebruijnIndex, - f: impl FnOnce(&TyLoweringContext) -> T, + f: impl FnOnce(&TyLoweringContext<'_>) -> T, ) -> T { let opaque_ty_data_vec = self.opaque_type_data.take(); let expander = self.expander.take(); @@ -130,7 +130,7 @@ impl<'a> TyLoweringContext<'a> { pub fn with_shifted_in( &self, debruijn: DebruijnIndex, - f: impl FnOnce(&TyLoweringContext) -> T, + f: impl FnOnce(&TyLoweringContext<'_>) -> T, ) -> T { self.with_debruijn(self.in_binders.shifted_in_from(debruijn), f) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs index d2081d22d79df..b5810ad054439 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs @@ -492,7 +492,7 @@ pub struct ReceiverAdjustments { } impl ReceiverAdjustments { - pub(crate) fn apply(&self, table: &mut InferenceTable, ty: Ty) -> (Ty, Vec) { + pub(crate) fn apply(&self, table: &mut InferenceTable<'_>, ty: Ty) -> (Ty, Vec) { let mut ty = ty; let mut adjust = Vec::new(); for _ in 0..self.autoderefs { @@ -597,7 +597,7 @@ pub fn lookup_impl_method( fn find_matching_impl( mut impls: impl Iterator, - table: &mut InferenceTable, + table: &mut InferenceTable<'_>, self_ty: &Ty, ) -> Option> { let db = table.db; @@ -856,7 +856,7 @@ fn iterate_method_candidates_for_self_ty( fn iterate_trait_method_candidates( self_ty: &Ty, - table: &mut InferenceTable, + table: &mut InferenceTable<'_>, traits_in_scope: &FxHashSet, name: Option<&Name>, receiver_ty: Option<&Ty>, @@ -922,7 +922,7 @@ fn iterate_trait_method_candidates( fn iterate_inherent_methods( self_ty: &Ty, - table: &mut InferenceTable, + table: &mut InferenceTable<'_>, name: Option<&Name>, receiver_ty: Option<&Ty>, receiver_adjustments: Option, @@ -975,7 +975,7 @@ fn iterate_inherent_methods( fn impls_for_self_ty( impls: &InherentImpls, self_ty: &Ty, - table: &mut InferenceTable, + table: &mut InferenceTable<'_>, name: Option<&Name>, receiver_ty: Option<&Ty>, receiver_adjustments: Option, @@ -1017,7 +1017,7 @@ pub fn resolve_indexing_op( } fn is_valid_candidate( - table: &mut InferenceTable, + table: &mut InferenceTable<'_>, name: Option<&Name>, receiver_ty: Option<&Ty>, item: AssocItemId, @@ -1161,7 +1161,7 @@ fn generic_implements_goal( } fn autoderef_method_receiver( - table: &mut InferenceTable, + table: &mut InferenceTable<'_>, ty: Ty, ) -> (Vec>, Vec) { let (mut deref_chain, mut adjustments): (Vec<_>, Vec<_>) = (Vec::new(), Vec::new()); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/test_db.rs b/src/tools/rust-analyzer/crates/hir-ty/src/test_db.rs index ee6c2fa4f8c67..dc7252f7072d8 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/test_db.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/test_db.rs @@ -77,7 +77,7 @@ impl FileLoader for TestDB { fn file_text(&self, file_id: FileId) -> Arc { FileLoaderDelegate(self).file_text(file_id) } - fn resolve_path(&self, path: AnchoredPath) -> Option { + fn resolve_path(&self, path: AnchoredPath<'_>) -> Option { FileLoaderDelegate(self).resolve_path(path) } fn relevant_crates(&self, file_id: FileId) -> Arc> { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tls.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tls.rs index 0600fd7c6d935..547850b021c3c 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tls.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tls.rs @@ -104,7 +104,7 @@ mod unsafe_tls { use crate::db::HirDatabase; use scoped_tls::scoped_thread_local; - scoped_thread_local!(static PROGRAM: DebugContext); + scoped_thread_local!(static PROGRAM: DebugContext<'_>); pub(crate) fn with_current_program( op: impl for<'a> FnOnce(Option<&'a DebugContext<'a>>) -> R, @@ -127,7 +127,7 @@ mod unsafe_tls { // `with_current_program`, which hides the lifetime through the `for` // type. let static_p: &DebugContext<'static> = - unsafe { std::mem::transmute::<&DebugContext, &DebugContext<'static>>(&ctx) }; + unsafe { std::mem::transmute::<&DebugContext<'_>, &DebugContext<'static>>(&ctx) }; PROGRAM.set(static_p, op) } } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs index 2e1447936888d..83319755da73a 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs @@ -130,7 +130,7 @@ pub fn all_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> SmallVec<[Trai /// `all_super_traits` is that we keep track of type parameters; for example if /// we have `Self: Trait` and `Trait: OtherTrait` we'll get /// `Self: OtherTrait`. -pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> SuperTraits { +pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> SuperTraits<'_> { SuperTraits { db, seen: iter::once(trait_ref.trait_id).collect(), stack: vec![trait_ref] } } diff --git a/src/tools/rust-analyzer/crates/hir/src/display.rs b/src/tools/rust-analyzer/crates/hir/src/display.rs index b4fd70d082fc9..0e29c52ade683 100644 --- a/src/tools/rust-analyzer/crates/hir/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir/src/display.rs @@ -23,7 +23,7 @@ use crate::{ }; impl HirDisplay for Function { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { let data = f.db.function_data(self.id); write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; if data.has_default_kw() { @@ -48,7 +48,7 @@ impl HirDisplay for Function { f.write_char('(')?; - let write_self_param = |ty: &TypeRef, f: &mut HirFormatter| match ty { + let write_self_param = |ty: &TypeRef, f: &mut HirFormatter<'_>| match ty { TypeRef::Path(p) if p.is_self_type() => f.write_str("self"), TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner,TypeRef::Path(p) if p.is_self_type()) => { @@ -129,7 +129,7 @@ impl HirDisplay for Function { } impl HirDisplay for Adt { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { Adt::Struct(it) => it.hir_fmt(f), Adt::Union(it) => it.hir_fmt(f), @@ -139,7 +139,7 @@ impl HirDisplay for Adt { } impl HirDisplay for Struct { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; f.write_str("struct ")?; write!(f, "{}", self.name(f.db))?; @@ -151,7 +151,7 @@ impl HirDisplay for Struct { } impl HirDisplay for Enum { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; f.write_str("enum ")?; write!(f, "{}", self.name(f.db))?; @@ -163,7 +163,7 @@ impl HirDisplay for Enum { } impl HirDisplay for Union { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; f.write_str("union ")?; write!(f, "{}", self.name(f.db))?; @@ -175,7 +175,7 @@ impl HirDisplay for Union { } impl HirDisplay for Field { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.parent.module(f.db).id, self.visibility(f.db), f)?; write!(f, "{}: ", self.name(f.db))?; self.ty(f.db).hir_fmt(f) @@ -183,7 +183,7 @@ impl HirDisplay for Field { } impl HirDisplay for Variant { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write!(f, "{}", self.name(f.db))?; let data = self.variant_data(f.db); match &*data { @@ -224,13 +224,13 @@ impl HirDisplay for Variant { } impl HirDisplay for Type { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { self.ty.hir_fmt(f) } } impl HirDisplay for GenericParam { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self { GenericParam::TypeParam(it) => it.hir_fmt(f), GenericParam::ConstParam(it) => it.hir_fmt(f), @@ -240,7 +240,7 @@ impl HirDisplay for GenericParam { } impl HirDisplay for TypeOrConstParam { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self.split(f.db) { either::Either::Left(x) => x.hir_fmt(f), either::Either::Right(x) => x.hir_fmt(f), @@ -249,7 +249,7 @@ impl HirDisplay for TypeOrConstParam { } impl HirDisplay for TypeParam { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write!(f, "{}", self.name(f.db))?; if f.omit_verbose_types() { return Ok(()); @@ -277,19 +277,22 @@ impl HirDisplay for TypeParam { } impl HirDisplay for LifetimeParam { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write!(f, "{}", self.name(f.db)) } } impl HirDisplay for ConstParam { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write!(f, "const {}: ", self.name(f.db))?; self.ty(f.db).hir_fmt(f) } } -fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), HirDisplayError> { +fn write_generic_params( + def: GenericDefId, + f: &mut HirFormatter<'_>, +) -> Result<(), HirDisplayError> { let params = f.db.generic_params(def); if params.lifetimes.is_empty() && params.type_or_consts.iter().all(|x| x.1.const_param().is_none()) @@ -304,7 +307,7 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H f.write_char('<')?; let mut first = true; - let mut delim = |f: &mut HirFormatter| { + let mut delim = |f: &mut HirFormatter<'_>| { if first { first = false; Ok(()) @@ -343,7 +346,7 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H Ok(()) } -fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), HirDisplayError> { +fn write_where_clause(def: GenericDefId, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { let params = f.db.generic_params(def); // unnamed type targets are displayed inline with the argument itself, e.g. `f: impl Y`. @@ -365,7 +368,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir return Ok(()); } - let write_target = |target: &WherePredicateTypeTarget, f: &mut HirFormatter| match target { + let write_target = |target: &WherePredicateTypeTarget, f: &mut HirFormatter<'_>| match target { WherePredicateTypeTarget::TypeRef(ty) => ty.hir_fmt(f), WherePredicateTypeTarget::TypeOrConstParam(id) => { match ¶ms.type_or_consts[*id].name() { @@ -381,8 +384,9 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir let prev_pred = if pred_idx == 0 { None } else { Some(¶ms.where_predicates[pred_idx - 1]) }; - let new_predicate = - |f: &mut HirFormatter| f.write_str(if pred_idx == 0 { "\n " } else { ",\n " }); + let new_predicate = |f: &mut HirFormatter<'_>| { + f.write_str(if pred_idx == 0 { "\n " } else { ",\n " }) + }; match pred { WherePredicate::TypeBound { target, .. } if is_unnamed_type_target(target) => {} @@ -438,7 +442,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir } impl HirDisplay for Const { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; let data = f.db.const_data(self.id); f.write_str("const ")?; @@ -452,7 +456,7 @@ impl HirDisplay for Const { } impl HirDisplay for Static { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; let data = f.db.static_data(self.id); f.write_str("static ")?; @@ -466,7 +470,7 @@ impl HirDisplay for Static { } impl HirDisplay for Trait { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; let data = f.db.trait_data(self.id); if data.is_unsafe { @@ -484,7 +488,7 @@ impl HirDisplay for Trait { } impl HirDisplay for TypeAlias { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; let data = f.db.type_alias_data(self.id); write!(f, "type {}", data.name)?; @@ -501,7 +505,7 @@ impl HirDisplay for TypeAlias { } impl HirDisplay for Module { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { // FIXME: Module doesn't have visibility saved in data. match self.name(f.db) { Some(name) => write!(f, "mod {}", name), @@ -515,7 +519,7 @@ impl HirDisplay for Module { } impl HirDisplay for Macro { - fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { match self.id { hir_def::MacroId::Macro2Id(_) => f.write_str("macro"), hir_def::MacroId::MacroRulesId(_) => f.write_str("macro_rules!"), diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index 7e262b4e4cb2f..fad75c4a7c13f 100644 --- a/src/tools/rust-analyzer/crates/hir/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs @@ -18,6 +18,7 @@ //! . #![recursion_limit = "512"] +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod semantics; mod source_analyzer; @@ -3027,7 +3028,7 @@ impl Type { pub fn iterate_method_candidates( &self, db: &dyn HirDatabase, - scope: &SemanticsScope, + scope: &SemanticsScope<'_>, // FIXME this can be retrieved from `scope`, except autoimport uses this // to specify a different set, so the method needs to be split traits_in_scope: &FxHashSet, @@ -3060,7 +3061,7 @@ impl Type { fn iterate_method_candidates_dyn( &self, db: &dyn HirDatabase, - scope: &SemanticsScope, + scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, with_local_impls: Option, name: Option<&Name>, @@ -3090,7 +3091,7 @@ impl Type { pub fn iterate_path_candidates( &self, db: &dyn HirDatabase, - scope: &SemanticsScope, + scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, with_local_impls: Option, name: Option<&Name>, @@ -3118,7 +3119,7 @@ impl Type { fn iterate_path_candidates_dyn( &self, db: &dyn HirDatabase, - scope: &SemanticsScope, + scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, with_local_impls: Option, name: Option<&Name>, diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs index 744f3865aaa4c..edcb2fc6a7246 100644 --- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs +++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs @@ -124,7 +124,7 @@ impl fmt::Debug for Semantics<'_, DB> { } impl<'db, DB: HirDatabase> Semantics<'db, DB> { - pub fn new(db: &DB) -> Semantics { + pub fn new(db: &DB) -> Semantics<'_, DB> { let impl_ = SemanticsImpl::new(db); Semantics { db, imp: impl_ } } @@ -1056,7 +1056,7 @@ impl<'db> SemanticsImpl<'db> { .unwrap_or_default() } - fn with_ctx T, T>(&self, f: F) -> T { + fn with_ctx) -> T, T>(&self, f: F) -> T { let mut cache = self.s2d_cache.borrow_mut(); let mut ctx = SourceToDefCtx { db: self.db, cache: &mut *cache }; f(&mut ctx) @@ -1280,7 +1280,7 @@ impl<'db> SemanticsImpl<'db> { } fn macro_call_to_macro_id( - ctx: &mut SourceToDefCtx, + ctx: &mut SourceToDefCtx<'_, '_>, db: &dyn AstDatabase, macro_call_id: MacroCallId, ) -> Option { @@ -1302,14 +1302,14 @@ fn macro_call_to_macro_id( pub trait ToDef: AstNode + Clone { type Def; - fn to_def(sema: &SemanticsImpl, src: InFile) -> Option; + fn to_def(sema: &SemanticsImpl<'_>, src: InFile) -> Option; } macro_rules! to_def_impls { ($(($def:path, $ast:path, $meth:ident)),* ,) => {$( impl ToDef for $ast { type Def = $def; - fn to_def(sema: &SemanticsImpl, src: InFile) -> Option { + fn to_def(sema: &SemanticsImpl<'_>, src: InFile) -> Option { sema.with_ctx(|ctx| ctx.$meth(src)).map(<$def>::from) } } diff --git a/src/tools/rust-analyzer/crates/hir/src/symbols.rs b/src/tools/rust-analyzer/crates/hir/src/symbols.rs index 3b84877dd363c..616a406c72758 100644 --- a/src/tools/rust-analyzer/crates/hir/src/symbols.rs +++ b/src/tools/rust-analyzer/crates/hir/src/symbols.rs @@ -32,7 +32,7 @@ pub struct DeclarationLocation { } impl DeclarationLocation { - pub fn syntax(&self, sema: &Semantics) -> Option { + pub fn syntax(&self, sema: &Semantics<'_, DB>) -> Option { let root = sema.parse_or_expand(self.hir_file_id)?; Some(self.ptr.to_node(&root)) } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/assist_context.rs b/src/tools/rust-analyzer/crates/ide-assists/src/assist_context.rs index ec85faaf46da1..f9b4266142574 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/assist_context.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/assist_context.rs @@ -144,7 +144,7 @@ pub(crate) struct Assists { } impl Assists { - pub(crate) fn new(ctx: &AssistContext, resolve: AssistResolveStrategy) -> Assists { + pub(crate) fn new(ctx: &AssistContext<'_>, resolve: AssistResolveStrategy) -> Assists { Assists { resolve, file: ctx.frange.file_id, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_explicit_type.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_explicit_type.rs index 3cdb8df31c407..bfa9759ec84be 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_explicit_type.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_explicit_type.rs @@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // let x: i32 = 92; // } // ``` -pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let (ascribed_ty, expr, pat) = if let Some(let_stmt) = ctx.find_node_at_offset::() { let cursor_in_range = { let eq_range = let_stmt.eq_token()?.text_range(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_label_to_loop.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_label_to_loop.rs index a14cc459899fd..001f1e8bb1585 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_label_to_loop.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_label_to_loop.rs @@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // } // ``` -pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let loop_kw = ctx.find_token_syntax_at_offset(T![loop])?; let loop_expr = loop_kw.parent().and_then(ast::LoopExpr::cast)?; if loop_expr.label().is_some() { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs index 14cdc1cf869d1..12213c8455c77 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs @@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // y: u32, // } // ``` -pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let ref_type_focused = ctx.find_node_at_offset::()?; if ref_type_focused.lifetime().is_some() { return None; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs index 573c362c81855..1b107b4914486 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_impl_members.rs @@ -44,7 +44,7 @@ use crate::{ // } // } // ``` -pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { add_missing_impl_members_inner( acc, ctx, @@ -85,7 +85,10 @@ pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) - // $0fn bar(&self) {} // } // ``` -pub(crate) fn add_missing_default_members(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_missing_default_members( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { add_missing_impl_members_inner( acc, ctx, @@ -97,7 +100,7 @@ pub(crate) fn add_missing_default_members(acc: &mut Assists, ctx: &AssistContext fn add_missing_impl_members_inner( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, mode: DefaultMethods, assist_id: &'static str, label: &'static str, @@ -164,7 +167,7 @@ fn add_missing_impl_members_inner( } fn try_gen_trait_body( - ctx: &AssistContext, + ctx: &AssistContext<'_>, func: &ast::Fn, trait_: &hir::Trait, impl_def: &ast::Impl, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs index 171b3f443262c..b16f6fe03ae8e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs @@ -36,7 +36,7 @@ use crate::{ // } // } // ``` -pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let match_expr = ctx.find_node_at_offset_with_descend::()?; let match_arm_list = match_expr.match_arm_list()?; let target_range = ctx.sema.original_range(match_expr.syntax()).range; @@ -221,7 +221,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) -> } fn cursor_at_trivial_match_arm_list( - ctx: &AssistContext, + ctx: &AssistContext<'_>, match_expr: &MatchExpr, match_arm_list: &MatchArmList, ) -> Option<()> { @@ -321,7 +321,7 @@ impl ExtendedEnum { } } -fn resolve_enum_def(sema: &Semantics, expr: &ast::Expr) -> Option { +fn resolve_enum_def(sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr) -> Option { sema.type_of_expr(expr)?.adjusted().autoderef(sema.db).find_map(|ty| match ty.as_adt() { Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)), _ => ty.is_bool().then(|| ExtendedEnum::Bool), @@ -329,7 +329,7 @@ fn resolve_enum_def(sema: &Semantics, expr: &ast::Expr) -> Option< } fn resolve_tuple_of_enum_def( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr, ) -> Option> { sema.type_of_expr(expr)? diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_return_type.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_return_type.rs index 42a5b8b672fc6..f858d7a15c242 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_return_type.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_return_type.rs @@ -15,7 +15,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // fn foo() -> i32 { 42i32 } // ``` -pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let (fn_type, tail_expr, builder_edit_pos) = extract_tail(ctx)?; let module = ctx.sema.scope(tail_expr.syntax())?.module(); let ty = ctx.sema.type_of_expr(&peel_blocks(tail_expr.clone()))?.original(); @@ -132,7 +132,7 @@ fn peel_blocks(mut expr: ast::Expr) -> ast::Expr { expr } -fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrReplace)> { +fn extract_tail(ctx: &AssistContext<'_>) -> Option<(FnType, ast::Expr, InsertOrReplace)> { let (fn_type, tail_expr, return_type_range, action) = if let Some(closure) = ctx.find_node_at_offset::() { let rpipe = closure.param_list()?.syntax().last_token()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_turbo_fish.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_turbo_fish.rs index a82dca9db0782..c0bf238db7317 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_turbo_fish.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_turbo_fish.rs @@ -24,7 +24,7 @@ use crate::{ // let x = make::<${0:_}>(); // } // ``` -pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let ident = ctx.find_token_syntax_at_offset(SyntaxKind::IDENT).or_else(|| { let arg_list = ctx.find_node_at_offset::()?; if arg_list.args().next().is_some() { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/apply_demorgan.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/apply_demorgan.rs index fd3ae5f78c2f2..2853d1d1be3cd 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/apply_demorgan.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/apply_demorgan.rs @@ -22,7 +22,7 @@ use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKin // if !(x == 4 && y >= 3.14) {} // } // ``` -pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let expr = ctx.find_node_at_offset::()?; let op = expr.op_kind()?; let op_range = expr.op_token()?.text_range(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs index 802449f85884d..949cf3167a8a1 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs @@ -87,7 +87,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; // } // # pub mod std { pub mod collections { pub struct HashMap { } } } // ``` -pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let (import_assets, syntax_under_caret) = find_importable_node(ctx)?; let mut proposed_imports = import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind); @@ -142,7 +142,9 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> Some(()) } -pub(super) fn find_importable_node(ctx: &AssistContext) -> Option<(ImportAssets, SyntaxElement)> { +pub(super) fn find_importable_node( + ctx: &AssistContext<'_>, +) -> Option<(ImportAssets, SyntaxElement)> { if let Some(path_under_caret) = ctx.find_node_at_offset_with_descend::() { ImportAssets::for_exact_path(&path_under_caret, &ctx.sema) .zip(Some(path_under_caret.syntax().clone().into())) @@ -177,7 +179,7 @@ fn group_label(import_candidate: &ImportCandidate) -> GroupLabel { /// Determine how relevant a given import is in the current context. Higher scores are more /// relevant. fn relevance_score( - ctx: &AssistContext, + ctx: &AssistContext<'_>, import: &LocatedImport, current_module: Option<&Module>, ) -> i32 { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/change_visibility.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/change_visibility.rs index 5f15e923ad862..2b1d8f6f0132a 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/change_visibility.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/change_visibility.rs @@ -20,14 +20,14 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists}; // ``` // pub(crate) fn frobnicate() {} // ``` -pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { if let Some(vis) = ctx.find_node_at_offset::() { return change_vis(acc, vis); } add_vis(acc, ctx) } -fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn add_vis(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let item_keyword = ctx.token_at_offset().find(|leaf| { matches!( leaf.kind(), diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_bool_then.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_bool_then.rs index f9ec9326b65ff..db96ad33047fb 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_bool_then.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_bool_then.rs @@ -37,7 +37,7 @@ use crate::{ // cond.then(|| val) // } // ``` -pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { // FIXME applies to match as well let expr = ctx.find_node_at_offset::()?; if !expr.if_token()?.text_range().contains_inclusive(ctx.offset()) { @@ -149,7 +149,7 @@ pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext) -> // } // } // ``` -pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let name_ref = ctx.find_node_at_offset::()?; let mcall = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast)?; let receiver = mcall.receiver()?; @@ -219,7 +219,7 @@ pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext) -> } fn option_variants( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, expr: &SyntaxNode, ) -> Option<(hir::Variant, hir::Variant)> { let fam = FamousDefs(sema, sema.scope(expr)?.krate()); @@ -237,7 +237,7 @@ fn option_variants( /// Traverses the expression checking if it contains `return` or `?` expressions or if any tail is not a `Some(expr)` expression. /// If any of these conditions are met it is impossible to rewrite this as a `bool::then` call. fn is_invalid_body( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, some_variant: hir::Variant, expr: &ast::Expr, ) -> bool { @@ -272,7 +272,7 @@ fn is_invalid_body( } fn block_is_none_variant( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, block: &ast::BlockExpr, none_variant: hir::Variant, ) -> bool { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_comment_block.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_comment_block.rs index 3261f5652592e..f171dd81a811e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_comment_block.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_comment_block.rs @@ -21,7 +21,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // comment // */ // ``` -pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let comment = ctx.find_token_at_offset::()?; // Only allow comments which are alone on their line if let Some(prev) = comment.syntax().prev_token() { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_integer_literal.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_integer_literal.rs index a8a819cfcc4d8..9060696cdc8e9 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_integer_literal.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_integer_literal.rs @@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; // ``` // const _: i32 = 0b1010; // ``` -pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let literal = ctx.find_node_at_offset::()?; let literal = match literal.kind() { ast::LiteralKind::IntNumber(it) => it, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs index 869f76951d228..30f6dd41a1d6d 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs @@ -31,7 +31,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // } // ``` -pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let impl_ = ctx.find_node_at_offset::()?; let src_type = impl_.self_ty()?; let ast_trait = impl_.trait_()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs index 82a67fb51db67..2cf370c090743 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs @@ -32,7 +32,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // } // ``` -pub(crate) fn convert_iter_for_each_to_for(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_iter_for_each_to_for( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { let method = ctx.find_node_at_offset::()?; let closure = match method.arg_list()?.args().next()? { @@ -91,7 +94,10 @@ pub(crate) fn convert_iter_for_each_to_for(acc: &mut Assists, ctx: &AssistContex // }); // } // ``` -pub(crate) fn convert_for_loop_with_for_each(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_for_loop_with_for_each( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { let for_loop = ctx.find_node_at_offset::()?; let iterable = for_loop.iterable()?; let pat = for_loop.pat()?; @@ -136,7 +142,7 @@ pub(crate) fn convert_for_loop_with_for_each(acc: &mut Assists, ctx: &AssistCont /// returning an Iterator called iter or iter_mut (depending on the type of reference) then return /// the expression behind the reference and the method name fn is_ref_and_impls_iter_method( - sema: &hir::Semantics, + sema: &hir::Semantics<'_, ide_db::RootDatabase>, iterable: &ast::Expr, ) -> Option<(ast::Expr, hir::Name)> { let ref_expr = match iterable { @@ -173,7 +179,7 @@ fn is_ref_and_impls_iter_method( } /// Whether iterable implements core::Iterator -fn impls_core_iter(sema: &hir::Semantics, iterable: &ast::Expr) -> bool { +fn impls_core_iter(sema: &hir::Semantics<'_, ide_db::RootDatabase>, iterable: &ast::Expr) -> bool { (|| { let it_typ = sema.type_of_expr(iterable)?.adjusted(); @@ -188,7 +194,7 @@ fn impls_core_iter(sema: &hir::Semantics, iterable: &ast:: } fn validate_method_call_expr( - ctx: &AssistContext, + ctx: &AssistContext<'_>, expr: ast::MethodCallExpr, ) -> Option<(ast::Expr, ast::Expr)> { let name_ref = expr.name_ref()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_let_else_to_match.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_let_else_to_match.rs index 2363aa7cbd909..00095de257d5a 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_let_else_to_match.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_let_else_to_match.rs @@ -9,7 +9,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; fn binders_in_pat( acc: &mut Vec<(Name, bool)>, pat: &Pat, - sem: &Semantics, + sem: &Semantics<'_, RootDatabase>, ) -> Option<()> { use Pat::*; match pat { @@ -115,7 +115,7 @@ fn binders_to_str(binders: &[(Name, bool)], addmut: bool) -> String { // }; // } // ``` -pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { // should focus on else token to trigger let else_token = ctx.find_token_syntax_at_offset(T![else])?; let let_stmt = LetStmt::cast(else_token.parent()?.parent()?)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_to_guarded_return.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_to_guarded_return.rs index 445567b7f90af..cb75619ced9c3 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_to_guarded_return.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_to_guarded_return.rs @@ -40,7 +40,7 @@ use crate::{ // bar(); // } // ``` -pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; if if_expr.else_branch().is_some() { return None; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs index 8093ba2560ccd..4ab8e93a2909f 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs @@ -48,7 +48,7 @@ use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind, // ``` pub(crate) fn convert_tuple_struct_to_named_struct( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let strukt = ctx .find_node_at_offset::() @@ -79,7 +79,7 @@ pub(crate) fn convert_tuple_struct_to_named_struct( } fn edit_struct_def( - ctx: &AssistContext, + ctx: &AssistContext<'_>, edit: &mut AssistBuilder, strukt: &Either, tuple_fields: ast::TupleFieldList, @@ -121,7 +121,7 @@ fn edit_struct_def( } fn edit_struct_references( - ctx: &AssistContext, + ctx: &AssistContext<'_>, edit: &mut AssistBuilder, strukt: Either, names: &[ast::Name], @@ -202,7 +202,7 @@ fn edit_struct_references( } fn edit_field_references( - ctx: &AssistContext, + ctx: &AssistContext<'_>, edit: &mut AssistBuilder, fields: impl Iterator, names: &[ast::Name], diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_while_to_loop.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_while_to_loop.rs index 739097067d0ac..c34b684112aaf 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_while_to_loop.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_while_to_loop.rs @@ -38,7 +38,7 @@ use crate::{ // } // } // ``` -pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let while_kw = ctx.find_token_syntax_at_offset(T![while])?; let while_expr = while_kw.parent().and_then(ast::WhileExpr::cast)?; let while_body = while_expr.loop_body()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_tuple_binding.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_tuple_binding.rs index c36cb3ff109c6..c1f57532bb296 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_tuple_binding.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_tuple_binding.rs @@ -27,7 +27,7 @@ use crate::assist_context::{AssistBuilder, AssistContext, Assists}; // let v = _0; // } // ``` -pub(crate) fn destructure_tuple_binding(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn destructure_tuple_binding(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { destructure_tuple_binding_impl(acc, ctx, false) } @@ -51,7 +51,7 @@ pub(crate) fn destructure_tuple_binding(acc: &mut Assists, ctx: &AssistContext) // ``` pub(crate) fn destructure_tuple_binding_impl( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, with_sub_pattern: bool, ) -> Option<()> { let ident_pat = ctx.find_node_at_offset::()?; @@ -82,7 +82,7 @@ pub(crate) fn destructure_tuple_binding_impl( Some(()) } -fn collect_data(ident_pat: IdentPat, ctx: &AssistContext) -> Option { +fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option { if ident_pat.at_token().is_some() { // Cannot destructure pattern with sub-pattern: // Only IdentPat can have sub-pattern, @@ -126,7 +126,7 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext) -> Option { } fn generate_name( - _ctx: &AssistContext, + _ctx: &AssistContext<'_>, index: usize, _tuple_name: &str, _ident_pat: &IdentPat, @@ -150,7 +150,7 @@ struct TupleData { usages: Option, } fn edit_tuple_assignment( - ctx: &AssistContext, + ctx: &AssistContext<'_>, builder: &mut AssistBuilder, data: &TupleData, in_sub_pattern: bool, @@ -196,7 +196,7 @@ fn edit_tuple_assignment( fn edit_tuple_usages( data: &TupleData, builder: &mut AssistBuilder, - ctx: &AssistContext, + ctx: &AssistContext<'_>, in_sub_pattern: bool, ) { if let Some(usages) = data.usages.as_ref() { @@ -210,7 +210,7 @@ fn edit_tuple_usages( } } fn edit_tuple_usage( - ctx: &AssistContext, + ctx: &AssistContext<'_>, builder: &mut AssistBuilder, usage: &FileReference, data: &TupleData, @@ -238,7 +238,7 @@ fn edit_tuple_usage( } fn edit_tuple_field_usage( - ctx: &AssistContext, + ctx: &AssistContext<'_>, builder: &mut AssistBuilder, data: &TupleData, index: TupleIndex, @@ -321,7 +321,7 @@ impl RefData { } } } -fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefData { +fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> RefData { let s = field_expr.syntax(); let mut ref_data = RefData { range: s.text_range(), needs_deref: true, needs_parentheses: true }; @@ -368,8 +368,8 @@ fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefDat // other combinations (`&value` -> `value`, `&&value` -> `&value`, `&value` -> `&&value`) might or might not be able to auto-ref/deref, // but there might be trait implementations an added `&` might resolve to // -> ONLY handle auto-ref from `value` to `&value` - fn is_auto_ref(ctx: &AssistContext, call_expr: &MethodCallExpr) -> bool { - fn impl_(ctx: &AssistContext, call_expr: &MethodCallExpr) -> Option { + fn is_auto_ref(ctx: &AssistContext<'_>, call_expr: &MethodCallExpr) -> bool { + fn impl_(ctx: &AssistContext<'_>, call_expr: &MethodCallExpr) -> Option { let rec = call_expr.receiver()?; let rec_ty = ctx.sema.type_of_expr(&rec)?.original(); // input must be actual value @@ -426,7 +426,7 @@ mod tests { // Tests for direct tuple destructure: // `let $0t = (1,2);` -> `let (_0, _1) = (1,2);` - fn assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { + fn assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { destructure_tuple_binding_impl(acc, ctx, false) } @@ -1191,10 +1191,10 @@ fn main { use super::*; use crate::tests::check_assist_by_label; - fn assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { + fn assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { destructure_tuple_binding_impl(acc, ctx, true) } - fn in_place_assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { + fn in_place_assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { destructure_tuple_binding_impl(acc, ctx, false) } @@ -1256,7 +1256,7 @@ fn main() { #[test] fn trigger_both_destructure_tuple_assists() { - fn assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { + fn assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { destructure_tuple_binding_impl(acc, ctx, true) } let text = r#" diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/expand_glob_import.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/expand_glob_import.rs index b5a5694d01cd1..943c1d90e6365 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/expand_glob_import.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/expand_glob_import.rs @@ -40,7 +40,7 @@ use crate::{ // // fn qux(bar: Bar, baz: Baz) {} // ``` -pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let star = ctx.find_token_syntax_at_offset(T![*])?; let use_tree = star.parent().and_then(ast::UseTree::cast)?; let (parent, mod_path) = find_parent_and_path(&star)?; @@ -112,7 +112,7 @@ fn find_parent_and_path( } } -fn def_is_referenced_in(def: Definition, ctx: &AssistContext) -> bool { +fn def_is_referenced_in(def: Definition, ctx: &AssistContext<'_>) -> bool { let search_scope = SearchScope::single_file(ctx.file_id()); def.usages(&ctx.sema).in_scope(search_scope).at_least_one() } @@ -139,7 +139,7 @@ impl Ref { struct Refs(Vec); impl Refs { - fn used_refs(&self, ctx: &AssistContext) -> Refs { + fn used_refs(&self, ctx: &AssistContext<'_>) -> Refs { Refs( self.0 .clone() @@ -168,7 +168,7 @@ impl Refs { } } -fn find_refs_in_mod(ctx: &AssistContext, module: Module, visible_from: Module) -> Option { +fn find_refs_in_mod(ctx: &AssistContext<'_>, module: Module, visible_from: Module) -> Option { if !is_mod_visible_from(ctx, module, visible_from) { return None; } @@ -178,7 +178,7 @@ fn find_refs_in_mod(ctx: &AssistContext, module: Module, visible_from: Module) - Some(Refs(refs)) } -fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> bool { +fn is_mod_visible_from(ctx: &AssistContext<'_>, module: Module, from: Module) -> bool { match module.parent(ctx.db()) { Some(parent) => { module.visibility(ctx.db()).is_visible_from(ctx.db(), from.into()) @@ -202,7 +202,7 @@ fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> boo // use foo::*$0; // use baz::Baz; // ↑ --------------- -fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option> { +fn find_imported_defs(ctx: &AssistContext<'_>, star: SyntaxToken) -> Option> { let parent_use_item_syntax = star.parent_ancestors().find_map(|n| { if ast::Use::can_cast(n.kind()) { Some(n) @@ -239,7 +239,7 @@ fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option, refs_in_target: Refs, imported_defs: Vec, ) -> Vec { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs index 94b638d4c600e..52a55ead3af96 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs @@ -60,7 +60,7 @@ use crate::{ // let k = m + n; // } // ``` -pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let range = ctx.selection_trimmed(); if range.is_empty() { return None; @@ -170,7 +170,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option ) } -fn make_function_name(semantics_scope: &hir::SemanticsScope) -> ast::NameRef { +fn make_function_name(semantics_scope: &hir::SemanticsScope<'_>) -> ast::NameRef { let mut names_in_scope = vec![]; semantics_scope.process_all_names(&mut |name, _| names_in_scope.push(name.to_string())); @@ -366,7 +366,7 @@ struct OutlivedLocal { struct LocalUsages(ide_db::search::UsageSearchResult); impl LocalUsages { - fn find_local_usages(ctx: &AssistContext, var: Local) -> Self { + fn find_local_usages(ctx: &AssistContext<'_>, var: Local) -> Self { Self( Definition::Local(var) .usages(&ctx.sema) @@ -381,7 +381,7 @@ impl LocalUsages { } impl Function { - fn return_type(&self, ctx: &AssistContext) -> FunType { + fn return_type(&self, ctx: &AssistContext<'_>) -> FunType { match &self.ret_ty { RetType::Expr(ty) if ty.is_unit() => FunType::Unit, RetType::Expr(ty) => FunType::Single(ty.clone()), @@ -396,7 +396,7 @@ impl Function { } } - fn self_param_adt(&self, ctx: &AssistContext) -> Option { + fn self_param_adt(&self, ctx: &AssistContext<'_>) -> Option { let self_param = self.self_param.as_ref()?; let def = ctx.sema.to_def(self_param)?; let adt = def.ty(ctx.db()).strip_references().as_adt()?; @@ -421,7 +421,7 @@ impl Param { } } - fn to_arg(&self, ctx: &AssistContext) -> ast::Expr { + fn to_arg(&self, ctx: &AssistContext<'_>) -> ast::Expr { let var = path_expr_from_local(ctx, self.var); match self.kind() { ParamKind::Value | ParamKind::MutValue => var, @@ -430,7 +430,7 @@ impl Param { } } - fn to_param(&self, ctx: &AssistContext, module: hir::Module) -> ast::Param { + fn to_param(&self, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Param { let var = self.var.name(ctx.db()).to_string(); let var_name = make::name(&var); let pat = match self.kind() { @@ -452,7 +452,7 @@ impl Param { } impl TryKind { - fn of_ty(ty: hir::Type, ctx: &AssistContext) -> Option { + fn of_ty(ty: hir::Type, ctx: &AssistContext<'_>) -> Option { if ty.is_unknown() { // We favour Result for `expr?` return Some(TryKind::Result { ty }); @@ -485,7 +485,7 @@ impl FlowKind { } } - fn expr_ty(&self, ctx: &AssistContext) -> Option { + fn expr_ty(&self, ctx: &AssistContext<'_>) -> Option { match self { FlowKind::Return(Some(expr)) | FlowKind::Break(_, Some(expr)) => { ctx.sema.type_of_expr(expr).map(TypeInfo::adjusted) @@ -691,7 +691,7 @@ impl FunctionBody { /// whether it contains an await expression. fn analyze( &self, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, ) -> (FxIndexSet, Option) { let mut self_param = None; let mut res = FxIndexSet::default(); @@ -741,7 +741,7 @@ impl FunctionBody { (res, self_param) } - fn analyze_container(&self, sema: &Semantics) -> Option { + fn analyze_container(&self, sema: &Semantics<'_, RootDatabase>) -> Option { let mut ancestors = self.parent()?.ancestors(); let infer_expr_opt = |expr| sema.type_of_expr(&expr?).map(TypeInfo::adjusted); let mut parent_loop = None; @@ -837,7 +837,7 @@ impl FunctionBody { }) } - fn return_ty(&self, ctx: &AssistContext) -> Option { + fn return_ty(&self, ctx: &AssistContext<'_>) -> Option { match self.tail_expr() { Some(expr) => ctx.sema.type_of_expr(&expr).map(TypeInfo::original).map(RetType::Expr), None => Some(RetType::Stmt), @@ -847,7 +847,7 @@ impl FunctionBody { /// Local variables defined inside `body` that are accessed outside of it fn ret_values<'a>( &self, - ctx: &'a AssistContext, + ctx: &'a AssistContext<'_>, parent: &SyntaxNode, ) -> impl Iterator + 'a { let parent = parent.clone(); @@ -860,7 +860,7 @@ impl FunctionBody { /// Analyses the function body for external control flow. fn external_control_flow( &self, - ctx: &AssistContext, + ctx: &AssistContext<'_>, container_info: &ContainerInfo, ) -> Option { let mut ret_expr = None; @@ -950,7 +950,7 @@ impl FunctionBody { /// Computes additional info that affects param type and mutability fn extracted_function_params( &self, - ctx: &AssistContext, + ctx: &AssistContext<'_>, container_info: &ContainerInfo, locals: impl Iterator, ) -> Vec { @@ -1042,7 +1042,11 @@ fn generic_parents(parent: &SyntaxNode) -> Vec { } /// checks if relevant var is used with `&mut` access inside body -fn has_exclusive_usages(ctx: &AssistContext, usages: &LocalUsages, body: &FunctionBody) -> bool { +fn has_exclusive_usages( + ctx: &AssistContext<'_>, + usages: &LocalUsages, + body: &FunctionBody, +) -> bool { usages .iter() .filter(|reference| body.contains_range(reference.range)) @@ -1053,7 +1057,7 @@ fn has_exclusive_usages(ctx: &AssistContext, usages: &LocalUsages, body: &Functi fn reference_is_exclusive( reference: &FileReference, node: &dyn HasTokenAtOffset, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> bool { // we directly modify variable with set: `n = 0`, `n += 1` if reference.category == Some(ReferenceCategory::Write) { @@ -1070,7 +1074,7 @@ fn reference_is_exclusive( } /// checks if this expr requires `&mut` access, recurses on field access -fn expr_require_exclusive_access(ctx: &AssistContext, expr: &ast::Expr) -> Option { +fn expr_require_exclusive_access(ctx: &AssistContext<'_>, expr: &ast::Expr) -> Option { if let ast::Expr::MacroExpr(_) = expr { // FIXME: expand macro and check output for mutable usages of the variable? return None; @@ -1172,7 +1176,7 @@ fn path_element_of_reference( /// list local variables defined inside `body` fn locals_defined_in_body( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, body: &FunctionBody, ) -> FxIndexSet { // FIXME: this doesn't work well with macros @@ -1190,7 +1194,7 @@ fn locals_defined_in_body( /// Returns usage details if local variable is used after(outside of) body fn local_outlives_body( - ctx: &AssistContext, + ctx: &AssistContext<'_>, body_range: TextRange, local: Local, parent: &SyntaxNode, @@ -1215,7 +1219,7 @@ fn local_outlives_body( /// checks if the relevant local was defined before(outside of) body fn is_defined_outside_of_body( - ctx: &AssistContext, + ctx: &AssistContext<'_>, body: &FunctionBody, src: &hir::InFile>, ) -> bool { @@ -1260,7 +1264,7 @@ fn node_to_insert_after(body: &FunctionBody, anchor: Anchor) -> Option String { +fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> String { let ret_ty = fun.return_type(ctx); let args = make::arg_list(fun.params.iter().map(|param| param.to_arg(ctx))); @@ -1429,13 +1433,13 @@ impl FlowHandler { } } -fn path_expr_from_local(ctx: &AssistContext, var: Local) -> ast::Expr { +fn path_expr_from_local(ctx: &AssistContext<'_>, var: Local) -> ast::Expr { let name = var.name(ctx.db()).to_string(); make::expr_path(make::ext::ident_path(&name)) } fn format_function( - ctx: &AssistContext, + ctx: &AssistContext<'_>, module: hir::Module, fun: &Function, old_indent: IndentLevel, @@ -1490,7 +1494,7 @@ fn format_function( } fn make_generic_params_and_where_clause( - ctx: &AssistContext, + ctx: &AssistContext<'_>, fun: &Function, ) -> (Option, Option) { let used_type_params = fun.type_params(ctx); @@ -1502,7 +1506,7 @@ fn make_generic_params_and_where_clause( } fn make_generic_param_list( - ctx: &AssistContext, + ctx: &AssistContext<'_>, fun: &Function, used_type_params: &[TypeParam], ) -> Option { @@ -1525,7 +1529,7 @@ fn make_generic_param_list( } fn param_is_required( - ctx: &AssistContext, + ctx: &AssistContext<'_>, param: &ast::GenericParam, used_type_params: &[TypeParam], ) -> bool { @@ -1539,7 +1543,7 @@ fn param_is_required( } fn make_where_clause( - ctx: &AssistContext, + ctx: &AssistContext<'_>, fun: &Function, used_type_params: &[TypeParam], ) -> Option { @@ -1562,7 +1566,7 @@ fn make_where_clause( } fn pred_is_required( - ctx: &AssistContext, + ctx: &AssistContext<'_>, pred: &ast::WherePred, used_type_params: &[TypeParam], ) -> bool { @@ -1572,7 +1576,7 @@ fn pred_is_required( } } -fn resolved_type_param(ctx: &AssistContext, pred: &ast::WherePred) -> Option { +fn resolved_type_param(ctx: &AssistContext<'_>, pred: &ast::WherePred) -> Option { let path = match pred.ty()? { ast::Type::PathType(path_type) => path_type.path(), _ => None, @@ -1586,7 +1590,7 @@ fn resolved_type_param(ctx: &AssistContext, pred: &ast::WherePred) -> Option Vec { + fn type_params(&self, ctx: &AssistContext<'_>) -> Vec { let type_params_in_descendant_paths = self.body.descendant_paths().filter_map(|it| match ctx.sema.resolve_path(&it) { Some(PathResolution::TypeParam(type_param)) => Some(type_param), @@ -1596,13 +1600,13 @@ impl Function { type_params_in_descendant_paths.chain(type_params_in_params).collect() } - fn make_param_list(&self, ctx: &AssistContext, module: hir::Module) -> ast::ParamList { + fn make_param_list(&self, ctx: &AssistContext<'_>, module: hir::Module) -> ast::ParamList { let self_param = self.self_param.clone(); let params = self.params.iter().map(|param| param.to_param(ctx, module)); make::param_list(self_param, params) } - fn make_ret_ty(&self, ctx: &AssistContext, module: hir::Module) -> Option { + fn make_ret_ty(&self, ctx: &AssistContext<'_>, module: hir::Module) -> Option { let fun_ty = self.return_type(ctx); let handler = if self.mods.is_in_tail { FlowHandler::None @@ -1649,7 +1653,7 @@ impl Function { } impl FunType { - fn make_ty(&self, ctx: &AssistContext, module: hir::Module) -> ast::Type { + fn make_ty(&self, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type { match self { FunType::Unit => make::ty_unit(), FunType::Single(ty) => make_ty(ty, ctx, module), @@ -1672,7 +1676,7 @@ impl FunType { } fn make_body( - ctx: &AssistContext, + ctx: &AssistContext<'_>, old_indent: IndentLevel, new_indent: IndentLevel, fun: &Function, @@ -1821,17 +1825,17 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr make::block_expr(stmts, Some(tail_expr)) } -fn format_type(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> String { +fn format_type(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> String { ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "_".to_string()) } -fn make_ty(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> ast::Type { +fn make_ty(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type { let ty_str = format_type(ty, ctx, module); make::ty(&ty_str) } fn rewrite_body_segment( - ctx: &AssistContext, + ctx: &AssistContext<'_>, params: &[Param], handler: &FlowHandler, syntax: &SyntaxNode, @@ -1842,7 +1846,7 @@ fn rewrite_body_segment( } /// change all usages to account for added `&`/`&mut` for some params -fn fix_param_usages(ctx: &AssistContext, params: &[Param], syntax: &SyntaxNode) -> SyntaxNode { +fn fix_param_usages(ctx: &AssistContext<'_>, params: &[Param], syntax: &SyntaxNode) -> SyntaxNode { let mut usages_for_param: Vec<(&Param, Vec)> = Vec::new(); let tm = TreeMutator::new(syntax); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs index 11349b45d3c3f..cb09d8456a1e0 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs @@ -53,7 +53,7 @@ use super::remove_unused_param::range_to_remove; // name + 2 // } // ``` -pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { if ctx.has_empty_selection() { return None; } @@ -234,7 +234,7 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option, ) -> (HashMap>, Vec) { let mut adt_fields = Vec::new(); let mut refs: HashMap> = HashMap::new(); @@ -318,7 +318,7 @@ impl Module { fn expand_and_group_usages_file_wise( &self, - ctx: &AssistContext, + ctx: &AssistContext<'_>, node_def: Definition, refs_in_files: &mut HashMap>, ) { @@ -387,7 +387,7 @@ impl Module { fn resolve_imports( &mut self, curr_parent_module: Option, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Vec { let mut import_paths_to_be_removed: Vec = vec![]; let mut node_set: HashSet = HashSet::new(); @@ -462,7 +462,7 @@ impl Module { def: Definition, node_syntax: &SyntaxNode, curr_parent_module: &Option, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option { //We only need to find in the current file let selection_range = ctx.selection_trimmed(); @@ -675,7 +675,7 @@ fn check_intersection_and_push( fn does_source_exists_outside_sel_in_same_mod( def: Definition, - ctx: &AssistContext, + ctx: &AssistContext<'_>, curr_parent_module: &Option, selection_range: TextRange, curr_file_id: FileId, @@ -895,7 +895,7 @@ fn add_change_vis(vis: Option, node_or_token_opt: Option, ) -> Option<()> { let hir_mod_name = hir_module.name(ctx.db())?; let ast_mod_name = ast_module.name()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs index ebfd65ae79501..a93648f2d315a 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs @@ -37,7 +37,7 @@ use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind, // ``` pub(crate) fn extract_struct_from_enum_variant( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let variant = ctx.find_node_at_offset::()?; let field_list = extract_field_list_if_applicable(&variant)?; @@ -373,7 +373,7 @@ fn apply_references( } fn process_references( - ctx: &AssistContext, + ctx: &AssistContext<'_>, builder: &mut AssistBuilder, visited_modules: &mut FxHashSet, enum_module_def: &ModuleDef, @@ -407,7 +407,7 @@ fn process_references( } fn reference_to_node( - sema: &hir::Semantics, + sema: &hir::Semantics<'_, RootDatabase>, reference: FileReference, ) -> Option<(ast::PathSegment, SyntaxNode, hir::Module)> { let segment = diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_type_alias.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_type_alias.rs index f664aa6dbf988..af584cdb4384a 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_type_alias.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_type_alias.rs @@ -25,7 +25,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // field: Type, // } // ``` -pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { if ctx.has_empty_selection() { return None; } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs index 500db158e6fab..3596b6f82381b 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs @@ -27,7 +27,7 @@ use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists}; // var_name * 4; // } // ``` -pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { if ctx.has_empty_selection() { return None; } @@ -164,7 +164,7 @@ fn valid_target_expr(node: SyntaxNode) -> Option { } } -fn get_receiver_type(ctx: &AssistContext, expression: &ast::Expr) -> Option { +fn get_receiver_type(ctx: &AssistContext<'_>, expression: &ast::Expr) -> Option { let receiver = get_receiver(expression.clone())?; Some(ctx.sema.type_of_expr(&receiver)?.original()) } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/fix_visibility.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/fix_visibility.rs index b895208f4137b..b33846f546653 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/fix_visibility.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/fix_visibility.rs @@ -30,12 +30,12 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists}; // m::frobnicate() {} // } // ``` -pub(crate) fn fix_visibility(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn fix_visibility(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { add_vis_to_referenced_module_def(acc, ctx) .or_else(|| add_vis_to_referenced_record_field(acc, ctx)) } -fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let path: ast::Path = ctx.find_node_at_offset()?; let path_res = ctx.sema.resolve_path(&path)?; let def = match path_res { @@ -82,7 +82,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O }) } -fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let record_field: ast::RecordExprField = ctx.find_node_at_offset()?; let (record_field_def, _, _) = ctx.sema.resolve_record_field(&record_field)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_binexpr.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_binexpr.rs index 19e85b27f986d..2ea6f58fa0f1e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_binexpr.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_binexpr.rs @@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // let _ = 2 + 90; // } // ``` -pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let expr = ctx.find_node_at_offset::()?; let lhs = expr.lhs()?.syntax().clone(); let rhs = expr.rhs()?.syntax().clone(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_comma.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_comma.rs index 8f3fcaf6fb27c..f40f2713ad131 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_comma.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_comma.rs @@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ((3, 4), (1, 2)); // } // ``` -pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let comma = ctx.find_token_syntax_at_offset(T![,])?; let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_trait_bound.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_trait_bound.rs index a868aa43d6d02..e3ae4970b6a7a 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_trait_bound.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_trait_bound.rs @@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // fn foo() { } // ``` -pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { // We want to replicate the behavior of `flip_binexpr` by only suggesting // the assist when the cursor is on a `+` let plus = ctx.find_token_syntax_at_offset(T![+])?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs index 8932a91ebe660..eaa6de73eb35d 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs @@ -31,7 +31,7 @@ use syntax::{ // } // ``` -pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let constant_token = ctx.find_node_at_offset::()?; if constant_token.to_string().chars().any(|it| !(it.is_uppercase() || it == '_')) { cov_mark::hit!(not_constant_name); @@ -113,7 +113,7 @@ fn get_text_for_generate_constant( } fn target_data_for_generate_constant( - ctx: &AssistContext, + ctx: &AssistContext<'_>, current_module: Module, constant_module: Module, ) -> Option<(TextSize, IndentLevel, Option, String)> { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs index 4d47437f7c1f1..5e9995a986644 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs @@ -30,7 +30,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` pub(crate) fn generate_default_from_enum_variant( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let variant = ctx.find_node_at_offset::()?; let variant_name = variant.name()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs index 119bb6e07b48b..cbd33de19eda0 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs @@ -40,7 +40,7 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let fn_node = ctx.find_node_at_offset::()?; let fn_name = fn_node.name()?; @@ -122,7 +122,7 @@ fn generate_trait_impl_text_from_impl(impl_: &ast::Impl, trait_text: &str, code: buf } -fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool { +fn is_default_implemented(ctx: &AssistContext<'_>, impl_: &Impl) -> bool { let db = ctx.sema.db; let impl_ = ctx.sema.to_def(impl_); let impl_def = match impl_ { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs index 120acde8e5b4d..85b193663a05b 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs @@ -42,7 +42,7 @@ use syntax::ast::edit::AstNodeEdit; // } // } // ``` -pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let strukt = ctx.find_node_at_offset::()?; let strukt_name = strukt.name()?; let current_module = ctx.sema.scope(strukt.syntax())?.module(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs index c102eb1ab3e6f..b9637ee8d7c60 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs @@ -39,11 +39,11 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { generate_record_deref(acc, ctx).or_else(|| generate_tuple_deref(acc, ctx)) } -fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let strukt = ctx.find_node_at_offset::()?; let field = ctx.find_node_at_offset::()?; @@ -80,7 +80,7 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { ) } -fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let strukt = ctx.find_node_at_offset::()?; let field = ctx.find_node_at_offset::()?; let field_list = ctx.find_node_at_offset::()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_derive.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_derive.rs index 28483f795e0f6..339245b94eca4 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_derive.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_derive.rs @@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // y: u32, // } // ``` -pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let cap = ctx.config.snippet_cap?; let nominal = ctx.find_node_at_offset::()?; let node_start = derive_insertion_offset(&nominal)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs index d22d8c831fbe2..c91141f8eb50f 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs @@ -42,7 +42,7 @@ use crate::assist_context::{AssistContext, Assists}; // ``` pub(crate) fn generate_documentation_template( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let name = ctx.find_node_at_offset::()?; let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?; @@ -94,7 +94,7 @@ pub(crate) fn generate_documentation_template( // /// ``` // pub fn add(a: i32, b: i32) -> i32 { a + b } // ``` -pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let tok: ast::Comment = ctx.find_token_at_offset()?; let node = tok.syntax().parent()?; let last_doc_token = @@ -126,7 +126,7 @@ pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext) -> Op ) } -fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext) -> Option { +fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option { if !is_public(ast_func, ctx)? { // Doctests for private items can't actually name the item, so they're pretty useless. return None; @@ -176,7 +176,7 @@ fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext) -> Option Option { +fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option { let hir_func = ctx.sema.to_def(ast_func)?; let container = hir_func.as_assoc_item(ctx.db())?.container(ctx.db()); if let hir::AssocItemContainer::Impl(imp) = container { @@ -270,7 +270,7 @@ fn safety_builder(ast_func: &ast::Fn) -> Option> { } /// Checks if the function is public / exported -fn is_public(ast_func: &ast::Fn, ctx: &AssistContext) -> Option { +fn is_public(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option { let hir_func = ctx.sema.to_def(ast_func)?; Some( hir_func.visibility(ctx.db()) == Visibility::Public @@ -279,7 +279,7 @@ fn is_public(ast_func: &ast::Fn, ctx: &AssistContext) -> Option { } /// Checks that all parent modules of the function are public / exported -fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext) -> bool { +fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext<'_>) -> bool { let mut module = hir_func.module(ctx.db()); loop { if let Some(parent) = module.parent(ctx.db()) { @@ -294,7 +294,7 @@ fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext) -> bool } /// Returns the name of the current crate -fn crate_name(ast_func: &ast::Fn, ctx: &AssistContext) -> Option { +fn crate_name(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option { let krate = ctx.sema.scope(ast_func.syntax())?.krate(); Some(krate.display_name(ctx.db())?.to_string()) } @@ -351,7 +351,7 @@ fn self_partial_type(ast_func: &ast::Fn) -> Option { } /// Helper function to determine if the function is in a trait implementation -fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { +fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool { ctx.sema .to_def(ast_func) .and_then(|hir_func| hir_func.as_assoc_item(ctx.db())) @@ -360,7 +360,7 @@ fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { } /// Helper function to determine if the function definition is in a trait definition -fn is_in_trait_def(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { +fn is_in_trait_def(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool { ctx.sema .to_def(ast_func) .and_then(|hir_func| hir_func.as_assoc_item(ctx.db())) @@ -462,7 +462,7 @@ fn string_vec_from(string_array: &[&str]) -> Vec { } /// Helper function to build the path of the module in the which is the node -fn build_path(ast_func: &ast::Fn, ctx: &AssistContext) -> Option { +fn build_path(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option { let crate_name = crate_name(ast_func, ctx)?; let leaf = self_partial_type(ast_func) .or_else(|| ast_func.name().map(|n| n.to_string())) @@ -480,7 +480,7 @@ fn return_type(ast_func: &ast::Fn) -> Option { } /// Helper function to determine if the function returns some data -fn returns_a_value(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { +fn returns_a_value(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool { ctx.sema .to_def(ast_func) .map(|hir_func| hir_func.ret_type(ctx.db())) diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs index 28e0b433a637c..52d27d8a7d633 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs @@ -37,7 +37,7 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let variant = ctx.find_node_at_offset::()?; let variant_name = variant.name()?; let parent_enum = ast::Adt::Enum(variant.parent_enum()); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs index fe7a3cd535726..b19aa0f652aa7 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs @@ -36,7 +36,10 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_enum_try_into_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_enum_try_into_method( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { generate_enum_projection_method( acc, ctx, @@ -80,7 +83,7 @@ pub(crate) fn generate_enum_try_into_method(acc: &mut Assists, ctx: &AssistConte // } // } // ``` -pub(crate) fn generate_enum_as_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_enum_as_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { generate_enum_projection_method( acc, ctx, @@ -108,7 +111,7 @@ struct ProjectionProps { fn generate_enum_projection_method( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, assist_id: &'static str, assist_description: &str, props: ProjectionProps, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_variant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_variant.rs index b57076d99929e..4461fbd5ac827 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_variant.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_variant.rs @@ -31,7 +31,7 @@ use crate::assist_context::{AssistContext, Assists}; // let country = Countries::Lesotho; // } // ``` -pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let path_expr: ast::PathExpr = ctx.find_node_at_offset()?; let path = path_expr.path()?; @@ -58,7 +58,7 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> O fn add_variant_to_accumulator( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, target: syntax::TextRange, adt: hir::Enum, name_ref: &ast::NameRef, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs index f7be323824169..507ea012babfc 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs @@ -20,7 +20,10 @@ use crate::{utils::generate_trait_impl_text, AssistContext, AssistId, AssistKind // } // } // ``` -pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_from_impl_for_enum( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { let variant = ctx.find_node_at_offset::()?; let variant_name = variant.name()?; let enum_ = ast::Adt::Enum(variant.parent_enum()); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs index 061a4813447d2..d564a0540898e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs @@ -46,11 +46,11 @@ use crate::{ // } // // ``` -pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { gen_fn(acc, ctx).or_else(|| gen_method(acc, ctx)) } -fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn gen_fn(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let path_expr: ast::PathExpr = ctx.find_node_at_offset()?; let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?; let path = path_expr.path()?; @@ -113,7 +113,7 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { ) } -fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +fn gen_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let call: ast::MethodCallExpr = ctx.find_node_at_offset()?; if ctx.sema.resolve_method_call(&call).is_some() { return None; @@ -149,7 +149,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn add_func_to_accumulator( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, text_range: TextRange, function_builder: FunctionBuilder, insert_offset: TextSize, @@ -172,7 +172,7 @@ fn add_func_to_accumulator( } fn get_adt_source( - ctx: &AssistContext, + ctx: &AssistContext<'_>, adt: &hir::Adt, fn_name: &str, ) -> Option<(Option, FileId)> { @@ -229,7 +229,7 @@ impl FunctionBuilder { /// Prepares a generated function that matches `call`. /// The function is generated in `target_module` or next to `call` fn from_call( - ctx: &AssistContext, + ctx: &AssistContext<'_>, call: &ast::CallExpr, fn_name: &str, target_module: Option, @@ -261,7 +261,7 @@ impl FunctionBuilder { } fn from_method_call( - ctx: &AssistContext, + ctx: &AssistContext<'_>, call: &ast::MethodCallExpr, name: &ast::NameRef, target_module: Module, @@ -344,7 +344,7 @@ impl FunctionBuilder { /// * If we could infer the return type, don't focus it (and thus focus the function body) so the /// user can change the `todo!` function body. fn make_return_type( - ctx: &AssistContext, + ctx: &AssistContext<'_>, call: &ast::Expr, target_module: Module, ) -> (Option, bool) { @@ -367,7 +367,7 @@ fn make_return_type( } fn get_fn_target( - ctx: &AssistContext, + ctx: &AssistContext<'_>, target_module: &Option, call: CallExpr, ) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> { @@ -385,7 +385,7 @@ fn get_fn_target( } fn get_method_target( - ctx: &AssistContext, + ctx: &AssistContext<'_>, target_module: &Module, impl_: &Option, ) -> Option<(GeneratedFunctionTarget, TextSize)> { @@ -423,7 +423,7 @@ impl GeneratedFunctionTarget { /// Computes the type variables and arguments required for the generated function fn fn_args( - ctx: &AssistContext, + ctx: &AssistContext<'_>, target_module: hir::Module, call: ast::CallableExpr, ) -> Option<(Option, ast::ParamList)> { @@ -482,7 +482,7 @@ fn deduplicate_arg_names(arg_names: &mut Vec) { } } -fn fn_arg_name(sema: &Semantics, arg_expr: &ast::Expr) -> String { +fn fn_arg_name(sema: &Semantics<'_, RootDatabase>, arg_expr: &ast::Expr) -> String { let name = (|| match arg_expr { ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(sema, &cast_expr.expr()?)), expr => { @@ -510,9 +510,9 @@ fn fn_arg_name(sema: &Semantics, arg_expr: &ast::Expr) -> String { } } -fn fn_arg_type(ctx: &AssistContext, target_module: hir::Module, fn_arg: &ast::Expr) -> String { +fn fn_arg_type(ctx: &AssistContext<'_>, target_module: hir::Module, fn_arg: &ast::Expr) -> String { fn maybe_displayed_type( - ctx: &AssistContext, + ctx: &AssistContext<'_>, target_module: hir::Module, fn_arg: &ast::Expr, ) -> Option { @@ -593,7 +593,7 @@ fn next_space_for_fn_in_impl(impl_: &ast::Impl) -> Option bool { +fn module_is_descendant(module: &hir::Module, ans: &hir::Module, ctx: &AssistContext<'_>) -> bool { if module == ans { return true; } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs index 3702f543aa656..76fcef0cad951 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs @@ -43,7 +43,7 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { generate_getter_impl(acc, ctx, false) } @@ -68,13 +68,13 @@ pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option< // } // } // ``` -pub(crate) fn generate_getter_mut(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_getter_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { generate_getter_impl(acc, ctx, true) } pub(crate) fn generate_getter_impl( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, mutable: bool, ) -> Option<()> { let strukt = ctx.find_node_at_offset::()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs index 58fea103f854a..68287a20bf806 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs @@ -21,7 +21,7 @@ use crate::{utils::generate_impl_text, AssistContext, AssistId, AssistKind, Assi // $0 // } // ``` -pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let nominal = ctx.find_node_at_offset::()?; let name = nominal.name()?; let target = nominal.syntax().text_range(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs index 062b12a50bcd4..9ce525ca375c8 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs @@ -39,7 +39,7 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let fn_node = ctx.find_node_at_offset::()?; let fn_name = fn_node.name()?; @@ -86,7 +86,7 @@ pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext) } fn get_impl_method( - ctx: &AssistContext, + ctx: &AssistContext<'_>, impl_: &ast::Impl, fn_name: &Name, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs index 5f4715bb53d24..f27538259544c 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs @@ -29,7 +29,7 @@ use crate::{ // fn $0new(data: T) -> Self { Self { data } } // } // ``` -pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let strukt = ctx.find_node_at_offset::()?; // We want to only apply this to non-union structs with named fields diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs index 62576a854f92f..2a7ad6ce36811 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs @@ -27,7 +27,7 @@ use crate::{ // } // } // ``` -pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let strukt = ctx.find_node_at_offset::()?; let field = ctx.find_node_at_offset::()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs index c857adf876ef1..658a1aadf53ec 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs @@ -59,7 +59,7 @@ use crate::{ // }; // } // ``` -pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let def_file = ctx.file_id(); let name = ctx.find_node_at_offset::()?; let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?; @@ -174,7 +174,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext) -> Opt // }; // } // ``` -pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let name_ref: ast::NameRef = ctx.find_node_at_offset()?; let call_info = CallInfo::from_name_ref(name_ref.clone())?; let (function, label) = match &call_info.node { @@ -294,7 +294,7 @@ fn get_fn_params( } fn inline( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, function_def_file_id: FileId, function: hir::Function, fn_body: &ast::BlockExpr, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_local_variable.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_local_variable.rs index 3d9242ad71001..7259d67819416 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_local_variable.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_local_variable.rs @@ -32,7 +32,7 @@ use crate::{ // (1 + 2) * 4; // } // ``` -pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let file_id = ctx.file_id(); let range = ctx.selection_trimmed(); let InlineData { let_stmt, delete_let, references, target } = @@ -149,7 +149,7 @@ struct InlineData { } fn inline_let( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, let_stmt: ast::LetStmt, range: TextRange, file_id: FileId, @@ -184,7 +184,7 @@ fn inline_let( } fn inline_usage( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, path_expr: ast::PathExpr, range: TextRange, file_id: FileId, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_type_alias.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_type_alias.rs index d4d840f2236a0..054663a06a115 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_type_alias.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_type_alias.rs @@ -35,7 +35,7 @@ use crate::{ // let a: Vec; // } // ``` -pub(crate) fn inline_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn inline_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { enum Replacement { Generic { lifetime_map: LifetimeMap, const_and_type_map: ConstAndTypeMap }, Plain, @@ -252,7 +252,7 @@ fn create_replacement( updated_concrete_type.to_string() } -fn get_type_alias(ctx: &AssistContext, path: &ast::PathType) -> Option { +fn get_type_alias(ctx: &AssistContext<'_>, path: &ast::PathType) -> Option { let resolved_path = ctx.sema.resolve_path(&path.path()?)?; // We need the generics in the correct order to be able to map any provided diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_generic.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_generic.rs index 636b05dca9aee..062c816aef0da 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_generic.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_generic.rs @@ -16,7 +16,7 @@ use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists}; // ``` // fn foo(bar: B) {} // ``` -pub(crate) fn introduce_named_generic(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn introduce_named_generic(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let impl_trait_type = ctx.find_node_at_offset::()?; let param = impl_trait_type.syntax().parent().and_then(ast::Param::cast)?; let fn_ = param.syntax().ancestors().find_map(ast::Fn::cast)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_lifetime.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_lifetime.rs index fa7635d12323f..ce91dd23703b6 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_lifetime.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/introduce_named_lifetime.rs @@ -33,7 +33,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime"; // } // } // ``` -pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { // FIXME: How can we handle renaming any one of multiple anonymous lifetimes? // FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo let lifetime = diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/invert_if.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/invert_if.rs index 6eed59c9ea4f0..547158e29778e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/invert_if.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/invert_if.rs @@ -26,7 +26,7 @@ use crate::{ // if y { B } else { A } // } // ``` -pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let if_keyword = ctx.find_token_syntax_at_offset(T![if])?; let expr = ast::IfExpr::cast(if_keyword.parent()?)?; let if_range = if_keyword.text_range(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_imports.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_imports.rs index 946e66f1f5092..7e102ceba891a 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_imports.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_imports.rs @@ -22,7 +22,7 @@ use Edit::*; // ``` // use std::{fmt::Formatter, io}; // ``` -pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let (target, edits) = if ctx.has_empty_selection() { // Merge a neighbor let tree: ast::UseTree = ctx.find_node_at_offset()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_match_arms.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_match_arms.rs index c87bd7f1527e8..c24015b1c5175 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_match_arms.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/merge_match_arms.rs @@ -32,7 +32,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, TextRange}; // } // } // ``` -pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let current_arm = ctx.find_node_at_offset::()?; // Don't try to handle arms with guards for now - can add support for this later if current_arm.guard().is_some() { @@ -97,7 +97,7 @@ fn contains_placeholder(a: &ast::MatchArm) -> bool { fn are_same_types( current_arm_types: &HashMap>, arm: &ast::MatchArm, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> bool { let arm_types = get_arm_types(ctx, arm); for (other_arm_type_name, other_arm_type) in arm_types { @@ -112,14 +112,14 @@ fn are_same_types( } fn get_arm_types( - context: &AssistContext, + context: &AssistContext<'_>, arm: &ast::MatchArm, ) -> HashMap> { let mut mapping: HashMap> = HashMap::new(); fn recurse( map: &mut HashMap>, - ctx: &AssistContext, + ctx: &AssistContext<'_>, pat: &Option, ) { if let Some(local_pat) = pat { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_bounds.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_bounds.rs index 425dba1a75fdc..176a3bf5803fc 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_bounds.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_bounds.rs @@ -20,7 +20,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // f(x) // } // ``` -pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn move_bounds_to_where_clause( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { let type_param_list = ctx.find_node_at_offset::()?; let mut type_params = type_param_list.type_or_const_params(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_from_mod_rs.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_from_mod_rs.rs index b49c2e5da588a..a6c85a2b18b34 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_from_mod_rs.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_from_mod_rs.rs @@ -23,7 +23,7 @@ use crate::{ // ``` // fn t() {} // ``` -pub(crate) fn move_from_mod_rs(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn move_from_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let source_file = ctx.find_node_at_offset::()?; let module = ctx.sema.to_module_def(ctx.file_id())?; // Enable this assist if the user select all "meaningful" content in the source file diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_guard.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_guard.rs index f5e8b60ad63a4..b8f1b36deb93c 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_guard.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_guard.rs @@ -32,7 +32,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // } // ``` -pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let match_arm = ctx.find_node_at_offset::()?; let guard = match_arm.guard()?; if ctx.offset() > guard.syntax().text_range().end() { @@ -91,7 +91,10 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) -> // } // } // ``` -pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn move_arm_cond_to_match_guard( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { let match_arm: MatchArm = ctx.find_node_at_offset::()?; let match_pat = match_arm.pat()?; let arm_body = match_arm.expr()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_module_to_file.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_module_to_file.rs index 759494dcf024d..7468318a594af 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_module_to_file.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_module_to_file.rs @@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // mod foo; // ``` -pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let module_ast = ctx.find_node_at_offset::()?; let module_items = module_ast.item_list()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_to_mod_rs.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_to_mod_rs.rs index 887960881a201..a909ce8b26791 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_to_mod_rs.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_to_mod_rs.rs @@ -23,7 +23,7 @@ use crate::{ // ``` // fn t() {} // ``` -pub(crate) fn move_to_mod_rs(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn move_to_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let source_file = ctx.find_node_at_offset::()?; let module = ctx.sema.to_module_def(ctx.file_id())?; // Enable this assist if the user select all "meaningful" content in the source file diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/number_representation.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/number_representation.rs index f77471d80cba9..424db7437a743 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/number_representation.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/number_representation.rs @@ -15,7 +15,7 @@ const MIN_NUMBER_OF_DIGITS_TO_FORMAT: usize = 5; // ``` // const _: i32 = 1_012_345; // ``` -pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let literal = ctx.find_node_at_offset::()?; let literal = match literal.kind() { ast::LiteralKind::IntNumber(it) => it, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/promote_local_to_const.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/promote_local_to_const.rs index 65c14406f98f9..cbbea6c1e6373 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/promote_local_to_const.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/promote_local_to_const.rs @@ -44,7 +44,7 @@ use crate::{ // } // } // ``` -pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let pat = ctx.find_node_at_offset::()?; let name = pat.name()?; if !pat.is_simple_ident() { @@ -95,7 +95,7 @@ pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext) -> ) } -fn is_body_const(sema: &Semantics, expr: &ast::Expr) -> bool { +fn is_body_const(sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr) -> bool { let mut is_const = true; preorder_expr(expr, &mut |ev| { let expr = match ev { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/pull_assignment_up.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/pull_assignment_up.rs index d142397c24f0b..4cfe6c99b23c2 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/pull_assignment_up.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/pull_assignment_up.rs @@ -35,7 +35,7 @@ use crate::{ // }; // } // ``` -pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let assign_expr = ctx.find_node_at_offset::()?; let op_kind = assign_expr.op_kind()?; @@ -151,7 +151,7 @@ impl<'a> AssignmentsCollector<'a> { } fn is_equivalent( - sema: &hir::Semantics, + sema: &hir::Semantics<'_, ide_db::RootDatabase>, expr0: &ast::Expr, expr1: &ast::Expr, ) -> bool { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs index 61cb2f0479271..121f8b4a13683 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs @@ -32,7 +32,7 @@ use crate::{ // Foo::foo(&foo); // } // ``` -pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let name: ast::NameRef = ctx.find_node_at_offset()?; let call = name.syntax().parent().and_then(ast::MethodCallExpr::cast)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs index 8d2293d22475e..0c2e9da38639f 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs @@ -35,7 +35,7 @@ use crate::{ // } // # pub mod std { pub mod collections { pub struct HashMap { } } } // ``` -pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let (import_assets, syntax_under_caret) = find_importable_node(ctx)?; let mut proposed_imports = import_assets.search_for_relative_paths(&ctx.sema); if proposed_imports.is_empty() { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/raw_string.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/raw_string.rs index 41f768c3175d0..dbe8cb7bf031f 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/raw_string.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/raw_string.rs @@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // r#"Hello, World!"#; // } // ``` -pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let token = ctx.find_token_at_offset::()?; if token.is_raw() { return None; @@ -61,7 +61,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option< // "Hello, \"World!\""; // } // ``` -pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let token = ctx.find_token_at_offset::()?; if !token.is_raw() { return None; @@ -103,7 +103,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio // r##"Hello, World!"##; // } // ``` -pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let token = ctx.find_token_at_offset::()?; if !token.is_raw() { return None; @@ -131,7 +131,7 @@ pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { // r"Hello, World!"; // } // ``` -pub(crate) fn remove_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn remove_hash(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let token = ctx.find_token_at_offset::()?; if !token.is_raw() { return None; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_dbg.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_dbg.rs index be91eacbe7caf..afaa7c933c739 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_dbg.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_dbg.rs @@ -21,7 +21,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // 92; // } // ``` -pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let macro_call = ctx.find_node_at_offset::()?; let tt = macro_call.token_tree()?; let r_delim = NodeOrToken::Token(tt.right_delimiter_token()?); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_mut.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_mut.rs index 30d36dacd28a1..0b299e8349ac1 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_mut.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_mut.rs @@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // fn feed(&self, amount: u32) {} // } // ``` -pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let mut_token = ctx.find_token_syntax_at_offset(T![mut])?; let delete_from = mut_token.text_range().start(); let delete_to = match mut_token.next_token() { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs index 80e2ca918b94b..7a4a978825215 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs @@ -30,7 +30,7 @@ use crate::{ // frobnicate(); // } // ``` -pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let param: ast::Param = ctx.find_node_at_offset()?; let ident_pat = match param.pat()? { ast::Pat::IdentPat(it) => it, @@ -87,7 +87,7 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt } fn process_usages( - ctx: &AssistContext, + ctx: &AssistContext<'_>, builder: &mut AssistBuilder, file_id: FileId, references: Vec, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_fields.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_fields.rs index 35c4cb6d64109..a899c7a6457e0 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_fields.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_fields.rs @@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // struct Foo {foo: i32, bar: i32}; // const test: Foo = Foo {foo: 1, bar: 0} // ``` -pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let record = ctx .find_node_at_offset::() .map(Either::Left) @@ -86,7 +86,10 @@ fn replace( }); } -fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option> { +fn compute_fields_ranks( + path: &ast::Path, + ctx: &AssistContext<'_>, +) -> Option> { let strukt = match ctx.sema.resolve_path(path) { Some(hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Struct(it)))) => it, _ => return None, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_impl_items.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_impl_items.rs index 2bda3a1817078..208c3e109ddec 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_impl_items.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_impl_items.rs @@ -42,7 +42,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // fn c() {} // } // ``` -pub(crate) fn reorder_impl_items(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn reorder_impl_items(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let impl_ast = ctx.find_node_at_offset::()?; let items = impl_ast.assoc_item_list()?; let assoc_items = items.assoc_items().collect::>(); @@ -93,7 +93,10 @@ pub(crate) fn reorder_impl_items(acc: &mut Assists, ctx: &AssistContext) -> Opti ) } -fn compute_item_ranks(path: &ast::Path, ctx: &AssistContext) -> Option> { +fn compute_item_ranks( + path: &ast::Path, + ctx: &AssistContext<'_>, +) -> Option> { let td = trait_definition(path, &ctx.sema)?; Some( @@ -106,7 +109,7 @@ fn compute_item_ranks(path: &ast::Path, ctx: &AssistContext) -> Option) -> Option { +fn trait_definition(path: &ast::Path, sema: &Semantics<'_, RootDatabase>) -> Option { match sema.resolve_path(path)? { PathResolution::Def(hir::ModuleDef::Trait(trait_)) => Some(trait_), _ => None, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs index 03e41b43407af..bd50208da5ffd 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs @@ -42,7 +42,7 @@ use crate::{ // ``` pub(crate) fn replace_derive_with_manual_impl( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let attr = ctx.find_node_at_offset_with_descend::()?; let path = attr.path()?; @@ -113,7 +113,7 @@ pub(crate) fn replace_derive_with_manual_impl( fn add_assist( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, attr: &ast::Attr, old_derives: &[ast::Path], old_tree: &ast::TokenTree, @@ -170,7 +170,7 @@ fn add_assist( } fn impl_def_from_trait( - sema: &hir::Semantics, + sema: &hir::Semantics<'_, ide_db::RootDatabase>, adt: &ast::Adt, annotated_name: &ast::Name, trait_: Option, diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs index 2b68b2dc03a04..484c27387da94 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs @@ -47,7 +47,7 @@ use crate::{ // } // } // ``` -pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; let available_range = TextRange::new( if_expr.syntax().text_range().start(), @@ -140,7 +140,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext) } fn make_else_arm( - ctx: &AssistContext, + ctx: &AssistContext<'_>, else_block: Option, conditionals: &[(Either, ast::BlockExpr)], ) -> ast::MatchArm { @@ -197,7 +197,7 @@ fn make_else_arm( // } // } // ``` -pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let match_expr: ast::MatchExpr = ctx.find_node_at_offset()?; let mut arms = match_expr.match_arm_list()?.arms(); @@ -248,7 +248,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext) /// Pick the pattern for the if let condition and return the expressions for the `then` body and `else` body in that order. fn pick_pattern_and_expr_order( - sema: &hir::Semantics, + sema: &hir::Semantics<'_, RootDatabase>, pat: ast::Pat, pat2: ast::Pat, expr: ast::Expr, @@ -281,7 +281,7 @@ fn is_empty_expr(expr: &ast::Expr) -> bool { } } -fn binds_name(sema: &hir::Semantics, pat: &ast::Pat) -> bool { +fn binds_name(sema: &hir::Semantics<'_, RootDatabase>, pat: &ast::Pat) -> bool { let binds_name_v = |pat| binds_name(sema, &pat); match pat { ast::Pat::IdentPat(pat) => !matches!( @@ -303,7 +303,7 @@ fn binds_name(sema: &hir::Semantics, pat: &ast::Pat) -> bool { } } -fn is_sad_pat(sema: &hir::Semantics, pat: &ast::Pat) -> bool { +fn is_sad_pat(sema: &hir::Semantics<'_, RootDatabase>, pat: &ast::Pat) -> bool { sema.type_of_pat(pat) .and_then(|ty| TryEnum::from_ty(sema, &ty.adjusted())) .map_or(false, |it| does_pat_match_variant(pat, &it.sad_pattern())) diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_let_with_if_let.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_let_with_if_let.rs index a5fa8a110d31e..c2be4593b97d0 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_let_with_if_let.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_let_with_if_let.rs @@ -36,7 +36,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // // fn compute() -> Option { None } // ``` -pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let let_kw = ctx.find_token_syntax_at_offset(T![let])?; let let_stmt = let_kw.parent().and_then(ast::LetStmt::cast)?; let init = let_stmt.initializer()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs index 4800d549567b2..2419fa11c1554 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs @@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` pub(crate) fn replace_qualified_name_with_use( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let path: ast::Path = ctx.find_node_at_offset()?; // We don't want to mess with use statements diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_string_with_char.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_string_with_char.rs index a53f865a5e14e..decb5fb62a772 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_string_with_char.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_string_with_char.rs @@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // find('{'); // } // ``` -pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let token = ctx.find_token_syntax_at_offset(STRING).and_then(ast::String::cast)?; let value = token.value()?; let target = token.syntax().text_range(); @@ -63,7 +63,7 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) - // find("{"); // } // ``` -pub(crate) fn replace_char_with_string(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_char_with_string(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let token = ctx.find_token_syntax_at_offset(CHAR)?; let target = token.text_range(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs index a102736124567..38fccb33829a3 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs @@ -34,7 +34,10 @@ use crate::assist_context::{AssistContext, Assists}; // }; // } // ``` -pub(crate) fn replace_try_expr_with_match(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_try_expr_with_match( + acc: &mut Assists, + ctx: &AssistContext<'_>, +) -> Option<()> { let qm_kw = ctx.find_token_syntax_at_offset(T![?])?; let qm_kw_parent = qm_kw.parent().and_then(ast::TryExpr::cast)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs index dc3c860d7ed06..6112e09455a47 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs @@ -28,7 +28,7 @@ use crate::{ // ``` pub(crate) fn replace_turbofish_with_explicit_type( acc: &mut Assists, - ctx: &AssistContext, + ctx: &AssistContext<'_>, ) -> Option<()> { let let_stmt = ctx.find_node_at_offset::()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/sort_items.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/sort_items.rs index f784448471d26..a93704b39474b 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/sort_items.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/sort_items.rs @@ -81,7 +81,7 @@ use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists}; // Cat { name: String, weight: f64 }, // } // ``` -pub(crate) fn sort_items(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn sort_items(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { if ctx.has_empty_selection() { cov_mark::hit!(not_applicable_if_no_selection); return None; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/split_import.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/split_import.rs index ac67874b31bda..775ededecbcc8 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/split_import.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/split_import.rs @@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // use std::{collections::HashMap}; // ``` -pub(crate) fn split_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn split_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let colon_colon = ctx.find_token_syntax_at_offset(T![::])?; let path = ast::Path::cast(colon_colon.parent()?)?.qualifier()?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/toggle_ignore.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/toggle_ignore.rs index feaa24c1fe184..b7d57f02be566 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/toggle_ignore.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/toggle_ignore.rs @@ -23,7 +23,7 @@ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, // assert_eq!(2 + 2, 5); // } // ``` -pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let attr: ast::Attr = ctx.find_node_at_offset()?; let func = attr.syntax().parent().and_then(ast::Fn::cast)?; let attr = test_related_attribute(&func)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs index 7d73632c79945..3ce028e930659 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs @@ -21,7 +21,7 @@ use crate::{ // use std::fmt::{Debug}; // use std::fmt::Display; // ``` -pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let tree: ast::UseTree = ctx.find_node_at_offset::()?.clone_for_update(); let tree_list = tree.syntax().parent().and_then(ast::UseTreeList::cast)?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unnecessary_async.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unnecessary_async.rs index d90fee7809e8a..d5cd2d551349d 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unnecessary_async.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unnecessary_async.rs @@ -26,7 +26,7 @@ use crate::{AssistContext, Assists}; // pub fn foo() {} // pub async fn bar() { foo() } // ``` -pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let function: ast::Fn = ctx.find_node_at_offset()?; // Do nothing if the cursor is not on the prototype. This is so that the check does not pollute @@ -89,7 +89,7 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext) -> Optio } fn find_all_references( - ctx: &AssistContext, + ctx: &AssistContext<'_>, def: &Definition, ) -> impl Iterator { def.usages(&ctx.sema).all().into_iter().flat_map(|(file_id, references)| { @@ -99,7 +99,7 @@ fn find_all_references( /// Finds the await expression for the given `NameRef`. /// If no await expression is found, returns None. -fn find_await_expression(ctx: &AssistContext, nameref: &NameRef) -> Option { +fn find_await_expression(ctx: &AssistContext<'_>, nameref: &NameRef) -> Option { // From the nameref, walk up the tree to the await expression. let await_expr = if let Some(path) = full_path_of_name_ref(&nameref) { // Function calls. diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_block.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_block.rs index 45336d704dff3..7969a491822d1 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_block.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_block.rs @@ -25,7 +25,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // println!("foo"); // } // ``` -pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let assist_id = AssistId("unwrap_block", AssistKind::RefactorRewrite); let assist_label = "Unwrap block"; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_result_return_type.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_result_return_type.rs index ff79c5b82a10b..9ef4ae047ef0e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_result_return_type.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_result_return_type.rs @@ -22,7 +22,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // fn foo() -> i32 { 42i32 } // ``` -pub(crate) fn unwrap_result_return_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn unwrap_result_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let ret_type = ctx.find_node_at_offset::()?; let parent = ret_type.syntax().parent()?; let body = match_ast! { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs index 251b41c84a422..83446387db1cf 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs @@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // fn foo() -> Result { Ok(42i32) } // ``` -pub(crate) fn wrap_return_type_in_result(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn wrap_return_type_in_result(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let ret_type = ctx.find_node_at_offset::()?; let parent = ret_type.syntax().parent()?; let body = match_ast! { diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs b/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs index 7b9134efb48cc..a1812523977e0 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs @@ -57,6 +57,7 @@ //! //! See also this post: //! +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] #[allow(unused)] macro_rules! eprintln { ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; @@ -101,7 +102,7 @@ pub fn assists( mod handlers { use crate::{AssistContext, Assists}; - pub(crate) type Handler = fn(&mut Assists, &AssistContext) -> Option<()>; + pub(crate) type Handler = fn(&mut Assists, &AssistContext<'_>) -> Option<()>; mod add_explicit_type; mod add_label_to_loop; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs b/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs index a8d5f85ba6630..249a56b4ae3c1 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs @@ -113,7 +113,7 @@ enum ExpectedResult<'a> { } #[track_caller] -fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: Option<&str>) { +fn check(handler: Handler, before: &str, expected: ExpectedResult<'_>, assist_label: Option<&str>) { let (mut db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before); db.set_enable_proc_attr_macros(true); let text_without_caret = db.file_text(file_with_caret_id).to_string(); diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs index 1231cf64a017f..3e61d0741d3fe 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs @@ -90,7 +90,7 @@ pub enum DefaultMethods { } pub fn filter_assoc_items( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, items: &[hir::AssocItem], default_methods: DefaultMethods, ) -> Vec { @@ -127,11 +127,11 @@ pub fn filter_assoc_items( } pub fn add_trait_assoc_items_to_impl( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, items: Vec, trait_: hir::Trait, impl_: ast::Impl, - target_scope: hir::SemanticsScope, + target_scope: hir::SemanticsScope<'_>, ) -> (ast::Impl, ast::AssocItem) { let source_scope = sema.scope_for_def(trait_); @@ -183,7 +183,7 @@ impl<'a> Cursor<'a> { } } -pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor) -> String { +pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor<'_>) -> String { assert!(cursor.node().ancestors().any(|it| it == *node)); let range = cursor.node().text_range() - node.text_range().start(); let range: ops::Range = range.into(); @@ -334,7 +334,7 @@ fn calc_depth(pat: &ast::Pat, depth: usize) -> usize { // viable (e.g. we process proc macros, etc) // FIXME: this partially overlaps with `find_impl_block_*` pub(crate) fn find_struct_impl( - ctx: &AssistContext, + ctx: &AssistContext<'_>, adt: &ast::Adt, name: &str, ) -> Option> { @@ -576,7 +576,7 @@ impl ReferenceConversion { pub(crate) fn convert_reference_type( ty: hir::Type, db: &RootDatabase, - famous_defs: &FamousDefs, + famous_defs: &FamousDefs<'_, '_>, ) -> Option { handle_copy(&ty, db) .or_else(|| handle_as_ref_str(&ty, db, famous_defs)) @@ -594,7 +594,7 @@ fn handle_copy(ty: &hir::Type, db: &dyn HirDatabase) -> Option, ) -> Option { let str_type = hir::BuiltinType::str().ty(db); @@ -605,7 +605,7 @@ fn handle_as_ref_str( fn handle_as_ref_slice( ty: &hir::Type, db: &dyn HirDatabase, - famous_defs: &FamousDefs, + famous_defs: &FamousDefs<'_, '_>, ) -> Option { let type_argument = ty.type_arguments().next()?; let slice_type = hir::Type::new_slice(type_argument); @@ -617,7 +617,7 @@ fn handle_as_ref_slice( fn handle_dereferenced( ty: &hir::Type, db: &dyn HirDatabase, - famous_defs: &FamousDefs, + famous_defs: &FamousDefs<'_, '_>, ) -> Option { let type_argument = ty.type_arguments().next()?; @@ -628,7 +628,7 @@ fn handle_dereferenced( fn handle_option_as_ref( ty: &hir::Type, db: &dyn HirDatabase, - famous_defs: &FamousDefs, + famous_defs: &FamousDefs<'_, '_>, ) -> Option { if ty.as_adt() == famous_defs.core_option_Option()?.ty(db).as_adt() { Some(ReferenceConversionType::Option) @@ -640,7 +640,7 @@ fn handle_option_as_ref( fn handle_result_as_ref( ty: &hir::Type, db: &dyn HirDatabase, - famous_defs: &FamousDefs, + famous_defs: &FamousDefs<'_, '_>, ) -> Option { if ty.as_adt() == famous_defs.core_result_Result()?.ty(db).as_adt() { Some(ReferenceConversionType::Result) diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs index 7b90307988f07..149afcac9d478 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs @@ -85,12 +85,12 @@ impl Completions { items.into_iter().for_each(|item| self.add(item.into())) } - pub(crate) fn add_keyword(&mut self, ctx: &CompletionContext, keyword: &'static str) { + pub(crate) fn add_keyword(&mut self, ctx: &CompletionContext<'_>, keyword: &'static str) { let item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), keyword); item.add_to(self); } - pub(crate) fn add_nameref_keywords_with_colon(&mut self, ctx: &CompletionContext) { + pub(crate) fn add_nameref_keywords_with_colon(&mut self, ctx: &CompletionContext<'_>) { ["self::", "crate::"].into_iter().for_each(|kw| self.add_keyword(ctx, kw)); if ctx.depth_from_crate_root > 0 { @@ -98,7 +98,7 @@ impl Completions { } } - pub(crate) fn add_nameref_keywords(&mut self, ctx: &CompletionContext) { + pub(crate) fn add_nameref_keywords(&mut self, ctx: &CompletionContext<'_>) { ["self", "crate"].into_iter().for_each(|kw| self.add_keyword(ctx, kw)); if ctx.depth_from_crate_root > 0 { @@ -108,7 +108,7 @@ impl Completions { pub(crate) fn add_super_keyword( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, super_chain_len: Option, ) { if let Some(len) = super_chain_len { @@ -120,7 +120,7 @@ impl Completions { pub(crate) fn add_keyword_snippet_expr( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, incomplete_let: bool, kw: &str, snippet: &str, @@ -144,7 +144,12 @@ impl Completions { item.add_to(self); } - pub(crate) fn add_keyword_snippet(&mut self, ctx: &CompletionContext, kw: &str, snippet: &str) { + pub(crate) fn add_keyword_snippet( + &mut self, + ctx: &CompletionContext<'_>, + kw: &str, + snippet: &str, + ) { let mut item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), kw); match ctx.config.snippet_cap { @@ -156,7 +161,7 @@ impl Completions { pub(crate) fn add_crate_roots( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, ) { ctx.process_all_names(&mut |name, res| match res { @@ -169,7 +174,7 @@ impl Completions { pub(crate) fn add_path_resolution( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, local_name: hir::Name, resolution: hir::ScopeDef, @@ -192,7 +197,7 @@ impl Completions { pub(crate) fn add_pattern_resolution( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, local_name: hir::Name, resolution: hir::ScopeDef, @@ -215,7 +220,7 @@ impl Completions { pub(crate) fn add_enum_variants( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, e: hir::Enum, ) { @@ -226,7 +231,7 @@ impl Completions { pub(crate) fn add_module( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, module: hir::Module, local_name: hir::Name, @@ -241,7 +246,7 @@ impl Completions { pub(crate) fn add_macro( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, mac: hir::Macro, local_name: hir::Name, @@ -264,7 +269,7 @@ impl Completions { pub(crate) fn add_function( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, func: hir::Function, local_name: Option, @@ -287,7 +292,7 @@ impl Completions { pub(crate) fn add_method( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_access: &DotAccess, func: hir::Function, receiver: Option, @@ -312,7 +317,7 @@ impl Completions { pub(crate) fn add_method_with_import( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_access: &DotAccess, func: hir::Function, import: LocatedImport, @@ -336,7 +341,7 @@ impl Completions { ); } - pub(crate) fn add_const(&mut self, ctx: &CompletionContext, konst: hir::Const) { + pub(crate) fn add_const(&mut self, ctx: &CompletionContext<'_>, konst: hir::Const) { let is_private_editable = match ctx.is_visible(&konst) { Visible::Yes => false, Visible::Editable => true, @@ -348,7 +353,11 @@ impl Completions { )); } - pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { + pub(crate) fn add_type_alias( + &mut self, + ctx: &CompletionContext<'_>, + type_alias: hir::TypeAlias, + ) { let is_private_editable = match ctx.is_visible(&type_alias) { Visible::Yes => false, Visible::Editable => true, @@ -362,7 +371,7 @@ impl Completions { pub(crate) fn add_type_alias_with_eq( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, type_alias: hir::TypeAlias, ) { self.add_opt(render_type_alias_with_eq(RenderContext::new(ctx), type_alias)); @@ -370,7 +379,7 @@ impl Completions { pub(crate) fn add_qualified_enum_variant( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, variant: hir::Variant, path: hir::ModPath, @@ -384,7 +393,7 @@ impl Completions { pub(crate) fn add_enum_variant( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, variant: hir::Variant, local_name: Option, @@ -404,7 +413,7 @@ impl Completions { pub(crate) fn add_field( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_access: &DotAccess, receiver: Option, field: hir::Field, @@ -427,7 +436,7 @@ impl Completions { pub(crate) fn add_struct_literal( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, strukt: hir::Struct, path: Option, @@ -442,7 +451,7 @@ impl Completions { pub(crate) fn add_union_literal( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, un: hir::Union, path: Option, local_name: Option, @@ -453,7 +462,7 @@ impl Completions { pub(crate) fn add_tuple_field( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, receiver: Option, field: usize, ty: &hir::Type, @@ -462,18 +471,18 @@ impl Completions { self.add(item); } - pub(crate) fn add_lifetime(&mut self, ctx: &CompletionContext, name: hir::Name) { + pub(crate) fn add_lifetime(&mut self, ctx: &CompletionContext<'_>, name: hir::Name) { CompletionItem::new(SymbolKind::LifetimeParam, ctx.source_range(), name.to_smol_str()) .add_to(self) } - pub(crate) fn add_label(&mut self, ctx: &CompletionContext, name: hir::Name) { + pub(crate) fn add_label(&mut self, ctx: &CompletionContext<'_>, name: hir::Name) { CompletionItem::new(SymbolKind::Label, ctx.source_range(), name.to_smol_str()).add_to(self) } pub(crate) fn add_variant_pat( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, variant: hir::Variant, local_name: Option, @@ -489,7 +498,7 @@ impl Completions { pub(crate) fn add_qualified_variant_pat( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, variant: hir::Variant, path: hir::ModPath, @@ -500,7 +509,7 @@ impl Completions { pub(crate) fn add_struct_pat( &mut self, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, strukt: hir::Struct, local_name: Option, @@ -513,10 +522,10 @@ impl Completions { /// Skips variants that are visible with single segment paths. fn enum_variants_with_paths( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, enum_: hir::Enum, impl_: &Option, - cb: impl Fn(&mut Completions, &CompletionContext, hir::Variant, hir::ModPath), + cb: impl Fn(&mut Completions, &CompletionContext<'_>, hir::Variant, hir::ModPath), ) { let variants = enum_.variants(ctx.db); @@ -545,7 +554,7 @@ fn enum_variants_with_paths( pub(super) fn complete_name( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, NameContext { name, kind }: &NameContext, ) { match kind { @@ -586,7 +595,7 @@ pub(super) fn complete_name( pub(super) fn complete_name_ref( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, NameRefContext { nameref, kind }: &NameRefContext, ) { match kind { @@ -661,7 +670,11 @@ pub(super) fn complete_name_ref( } } -fn complete_patterns(acc: &mut Completions, ctx: &CompletionContext, pattern_ctx: &PatternContext) { +fn complete_patterns( + acc: &mut Completions, + ctx: &CompletionContext<'_>, + pattern_ctx: &PatternContext, +) { flyimport::import_on_the_fly_pat(acc, ctx, pattern_ctx); fn_param::complete_fn_param(acc, ctx, pattern_ctx); pattern::complete_pattern(acc, ctx, pattern_ctx); diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute.rs index cbf40e913442a..1d8a8c5f20db3 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute.rs @@ -32,7 +32,7 @@ pub(crate) use self::derive::complete_derive_path; /// Complete inputs to known builtin attributes as well as derive attributes pub(crate) fn complete_known_attribute_input( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, &colon_prefix: &bool, fake_attribute_under_caret: &ast::Attr, ) -> Option<()> { @@ -73,7 +73,7 @@ pub(crate) fn complete_known_attribute_input( pub(crate) fn complete_attribute_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, &AttrCtx { kind, annotated_item_kind }: &AttrCtx, ) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/cfg.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/cfg.rs index b0a9fc8d43a97..311060143b06a 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/cfg.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/cfg.rs @@ -8,7 +8,7 @@ use syntax::SyntaxKind; use crate::{completions::Completions, context::CompletionContext, CompletionItem}; -pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) { +pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) { let add_completion = |item: &str| { let mut completion = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), item); completion.insert_text(format!(r#""{}""#, item)); diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/derive.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/derive.rs index b3cc1826a6eb3..14538fef6072c 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/derive.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/derive.rs @@ -12,7 +12,7 @@ use crate::{ pub(crate) fn complete_derive_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, existing_derives: &ExistingDerives, ) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/lint.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/lint.rs index 5c0481031871f..967f6ddd9a83b 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/lint.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/lint.rs @@ -6,7 +6,7 @@ use crate::{context::CompletionContext, item::CompletionItem, Completions}; pub(super) fn complete_lint( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, is_qualified: bool, existing_lints: &[ast::Path], lints_completions: &[Lint], diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/repr.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/repr.rs index 1dcec5f493928..a29417133e68b 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/repr.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute/repr.rs @@ -5,7 +5,11 @@ use syntax::ast; use crate::{context::CompletionContext, item::CompletionItem, Completions}; -pub(super) fn complete_repr(acc: &mut Completions, ctx: &CompletionContext, input: ast::TokenTree) { +pub(super) fn complete_repr( + acc: &mut Completions, + ctx: &CompletionContext<'_>, + input: ast::TokenTree, +) { if let Some(existing_reprs) = super::parse_comma_sep_expr(input) { for &ReprCompletion { label, snippet, lookup, collides } in REPR_COMPLETIONS { let repr_already_annotated = existing_reprs diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs index 727ec6e60853b..cf40ca489c009 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs @@ -8,7 +8,11 @@ use crate::{ }; /// Complete dot accesses, i.e. fields or methods. -pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext, dot_access: &DotAccess) { +pub(crate) fn complete_dot( + acc: &mut Completions, + ctx: &CompletionContext<'_>, + dot_access: &DotAccess, +) { let receiver_ty = match dot_access { DotAccess { receiver_ty: Some(receiver_ty), .. } => &receiver_ty.original, _ => return, @@ -38,7 +42,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext, dot_a pub(crate) fn complete_undotted_self( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, expr_ctx: &ExprCtx, ) { @@ -96,7 +100,7 @@ pub(crate) fn complete_undotted_self( fn complete_fields( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, receiver: &hir::Type, mut named_field: impl FnMut(&mut Completions, hir::Field, hir::Type), mut tuple_index: impl FnMut(&mut Completions, usize, hir::Type), @@ -113,7 +117,7 @@ fn complete_fields( } fn complete_methods( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, receiver: &hir::Type, mut f: impl FnMut(hir::Function), ) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs index df0556ba451c7..d4544dd1d1272 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs @@ -9,7 +9,7 @@ use crate::{ pub(crate) fn complete_expr_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, &ExprCtx { in_block_expr, diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs index 3007b3c319c14..4e89ef6960821 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs @@ -42,7 +42,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[ pub(crate) fn complete_extern_abi( acc: &mut Completions, - _ctx: &CompletionContext, + _ctx: &CompletionContext<'_>, expanded: &ast::String, ) -> Option<()> { if !expanded.syntax().parent().map_or(false, |it| ast::Abi::can_cast(it.kind())) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/field.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/field.rs index 738c24574c997..870df63b7bf2a 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/field.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/field.rs @@ -7,7 +7,7 @@ use crate::{ pub(crate) fn complete_field_list_tuple_variant( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, ) { if ctx.qualifier_ctx.vis_node.is_some() { @@ -30,7 +30,10 @@ pub(crate) fn complete_field_list_tuple_variant( } } -pub(crate) fn complete_field_list_record_variant(acc: &mut Completions, ctx: &CompletionContext) { +pub(crate) fn complete_field_list_record_variant( + acc: &mut Completions, + ctx: &CompletionContext<'_>, +) { if ctx.qualifier_ctx.vis_node.is_none() { let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet); add_keyword("pub(crate)", "pub(crate)"); diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs index 6dbcfb0a5d730..f04cc15d7fabd 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs @@ -113,7 +113,7 @@ use super::Completions; // capability enabled. pub(crate) fn import_on_the_fly_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, ) -> Option<()> { if !ctx.config.enable_imports_on_the_fly { @@ -152,7 +152,7 @@ pub(crate) fn import_on_the_fly_path( pub(crate) fn import_on_the_fly_pat( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, ) -> Option<()> { if !ctx.config.enable_imports_on_the_fly { @@ -177,7 +177,7 @@ pub(crate) fn import_on_the_fly_pat( pub(crate) fn import_on_the_fly_dot( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_access: &DotAccess, ) -> Option<()> { if !ctx.config.enable_imports_on_the_fly { @@ -205,7 +205,7 @@ pub(crate) fn import_on_the_fly_dot( fn import_on_the_fly( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { kind, .. }: &PathCompletionCtx, import_assets: ImportAssets, position: SyntaxNode, @@ -285,7 +285,7 @@ fn import_on_the_fly( fn import_on_the_fly_pat_( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, import_assets: ImportAssets, position: SyntaxNode, @@ -329,7 +329,7 @@ fn import_on_the_fly_pat_( fn import_on_the_fly_method( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_access: &DotAccess, import_assets: ImportAssets, position: SyntaxNode, @@ -362,7 +362,7 @@ fn import_on_the_fly_method( Some(()) } -fn import_name(ctx: &CompletionContext) -> String { +fn import_name(ctx: &CompletionContext<'_>) -> String { let token_kind = ctx.token.kind(); if matches!(token_kind, T![.] | T![::]) { String::new() @@ -372,7 +372,7 @@ fn import_name(ctx: &CompletionContext) -> String { } fn import_assets_for_path( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, potential_import_name: &str, qualifier: Option, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs index cc6c17450b5d1..f0ecc595af33e 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs @@ -21,7 +21,7 @@ use crate::{ /// Also complete parameters for closure or local functions from the surrounding defined locals. pub(crate) fn complete_fn_param( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, ) -> Option<()> { let (ParamContext { param_list, kind, .. }, impl_) = match pattern_ctx { @@ -59,7 +59,7 @@ pub(crate) fn complete_fn_param( } fn fill_fn_params( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, function: &ast::Fn, param_list: &ast::ParamList, impl_: &Option, @@ -113,7 +113,7 @@ fn fill_fn_params( } fn params_from_stmt_list_scope( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, stmt_list: ast::StmtList, mut cb: impl FnMut(hir::Name, String), ) { @@ -170,7 +170,7 @@ fn should_add_self_completions( } } -fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, TextRange)> { +fn comma_wrapper(ctx: &CompletionContext<'_>) -> Option<(impl Fn(&str) -> String, TextRange)> { let param = ctx.token.parent_ancestors().find(|node| node.kind() == SyntaxKind::PARAM)?; let next_token_kind = { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/format_string.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/format_string.rs index f7a75b2dd58e2..038bdb4279e07 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/format_string.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/format_string.rs @@ -9,7 +9,7 @@ use crate::{context::CompletionContext, CompletionItem, CompletionItemKind, Comp /// Complete identifiers in format strings. pub(crate) fn format_string( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, original: &ast::String, expanded: &ast::String, ) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list.rs index 43b48993902e6..4e4c9fba6cc57 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list.rs @@ -9,7 +9,7 @@ pub(crate) mod trait_impl; pub(crate) fn complete_item_list_in_expr( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, expr_ctx: &ExprCtx, ) { @@ -24,7 +24,7 @@ pub(crate) fn complete_item_list_in_expr( pub(crate) fn complete_item_list( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, kind: &ItemListKind, ) { @@ -70,7 +70,7 @@ pub(crate) fn complete_item_list( } } -fn add_keywords(acc: &mut Completions, ctx: &CompletionContext, kind: Option<&ItemListKind>) { +fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option<&ItemListKind>) { let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet); let in_item_list = matches!(kind, Some(ItemListKind::SourceFile | ItemListKind::Module) | None); diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs index 49b8537029da8..e9256803cc4f7 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs @@ -57,7 +57,7 @@ enum ImplCompletionKind { pub(crate) fn complete_trait_impl_const( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, name: &Option, ) -> Option<()> { complete_trait_impl_name(acc, ctx, name, ImplCompletionKind::Const) @@ -65,7 +65,7 @@ pub(crate) fn complete_trait_impl_const( pub(crate) fn complete_trait_impl_type_alias( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, name: &Option, ) -> Option<()> { complete_trait_impl_name(acc, ctx, name, ImplCompletionKind::TypeAlias) @@ -73,7 +73,7 @@ pub(crate) fn complete_trait_impl_type_alias( pub(crate) fn complete_trait_impl_fn( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, name: &Option, ) -> Option<()> { complete_trait_impl_name(acc, ctx, name, ImplCompletionKind::Fn) @@ -81,7 +81,7 @@ pub(crate) fn complete_trait_impl_fn( fn complete_trait_impl_name( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, name: &Option, kind: ImplCompletionKind, ) -> Option<()> { @@ -104,7 +104,7 @@ fn complete_trait_impl_name( pub(crate) fn complete_trait_impl_item_by_name( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, name_ref: &Option, impl_: &Option, @@ -128,7 +128,7 @@ pub(crate) fn complete_trait_impl_item_by_name( fn complete_trait_impl( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, kind: ImplCompletionKind, replacement_range: TextRange, impl_def: &ast::Impl, @@ -154,7 +154,7 @@ fn complete_trait_impl( fn add_function_impl( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, replacement_range: TextRange, func: hir::Function, impl_def: hir::Impl, @@ -204,7 +204,7 @@ fn add_function_impl( /// Transform a relevant associated item to inline generics from the impl, remove attrs and docs, etc. fn get_transformed_assoc_item( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, assoc_item: ast::AssocItem, impl_def: hir::Impl, ) -> Option { @@ -228,7 +228,7 @@ fn get_transformed_assoc_item( fn add_type_alias_impl( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, replacement_range: TextRange, type_alias: hir::TypeAlias, ) { @@ -252,7 +252,7 @@ fn add_type_alias_impl( fn add_const_impl( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, replacement_range: TextRange, const_: hir::Const, impl_def: hir::Impl, @@ -340,7 +340,7 @@ fn function_declaration(node: &ast::Fn, needs_whitespace: bool) -> String { syntax.trim_end().to_owned() } -fn replacement_range(ctx: &CompletionContext, item: &SyntaxNode) -> TextRange { +fn replacement_range(ctx: &CompletionContext<'_>, item: &SyntaxNode) -> TextRange { let first_child = item .children_with_tokens() .find(|child| { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/keyword.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/keyword.rs index 7d8d3a9636deb..0089958ff1d03 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/keyword.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/keyword.rs @@ -6,7 +6,7 @@ use crate::{CompletionContext, Completions}; pub(crate) fn complete_for_and_where( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, keyword_item: &ast::Item, ) { let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet); diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/lifetime.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/lifetime.rs index 76e1c2e510a18..3b79def639df4 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/lifetime.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/lifetime.rs @@ -18,7 +18,7 @@ use crate::{ /// Completes lifetimes. pub(crate) fn complete_lifetime( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, lifetime_ctx: &LifetimeContext, ) { let (lp, lifetime) = match lifetime_ctx { @@ -54,7 +54,7 @@ pub(crate) fn complete_lifetime( /// Completes labels. pub(crate) fn complete_label( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, lifetime_ctx: &LifetimeContext, ) { if !matches!(lifetime_ctx, LifetimeContext { kind: LifetimeKind::LabelRef, .. }) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs index 6f67c38dfdebb..9c975b9295337 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs @@ -14,7 +14,7 @@ use crate::{context::CompletionContext, CompletionItem, Completions}; /// Complete mod declaration, i.e. `mod $0;` pub(crate) fn complete_mod( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, mod_under_caret: &ast::Module, ) -> Option<()> { if mod_under_caret.item_list().is_some() { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs index 8d7fbc6627a4f..17dfe432b3529 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs @@ -11,7 +11,7 @@ use crate::{ /// Completes constants and paths in unqualified patterns. pub(crate) fn complete_pattern( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, ) { match pattern_ctx.parent_pat.as_ref() { @@ -107,7 +107,7 @@ pub(crate) fn complete_pattern( pub(crate) fn complete_pattern_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, ) { match qualified { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs index 5af44aa4b68ac..88092189c2315 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs @@ -20,7 +20,7 @@ use crate::{ pub(crate) fn complete_postfix( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_access: &DotAccess, ) { if !ctx.config.enable_postfix_completions { @@ -213,7 +213,7 @@ fn include_references(initial_element: &ast::Expr) -> ast::Expr { } fn build_postfix_snippet_builder<'ctx>( - ctx: &'ctx CompletionContext, + ctx: &'ctx CompletionContext<'_>, cap: SnippetCap, receiver: &'ctx ast::Expr, ) -> Option Builder + 'ctx> { @@ -228,7 +228,7 @@ fn build_postfix_snippet_builder<'ctx>( // Wrapping impl Fn in an option ruins lifetime inference for the parameters in a way that // can't be annotated for the closure, hence fix it by constructing it without the Option first fn build<'ctx>( - ctx: &'ctx CompletionContext, + ctx: &'ctx CompletionContext<'_>, cap: SnippetCap, delete_range: TextRange, ) -> impl Fn(&str, &str, &str) -> Builder + 'ctx { @@ -254,7 +254,7 @@ fn build_postfix_snippet_builder<'ctx>( fn add_custom_postfix_completions( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, postfix_snippet: impl Fn(&str, &str, &str) -> Builder, receiver_text: &str, ) -> Option<()> { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs index b5ef87b8812c3..2f0e2aa477ebf 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs @@ -38,7 +38,7 @@ static KINDS: &[(&str, &str)] = &[ pub(crate) fn add_format_like_completions( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, dot_receiver: &ast::Expr, cap: SnippetCap, receiver_text: &ast::String, diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs index 9f5922c5b0ba7..1c9042390d3b2 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs @@ -10,7 +10,7 @@ use crate::{ pub(crate) fn complete_record_pattern_fields( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, pattern_ctx: &PatternContext, ) { if let PatternContext { record_pat: Some(record_pat), .. } = pattern_ctx { @@ -20,7 +20,7 @@ pub(crate) fn complete_record_pattern_fields( pub(crate) fn complete_record_expr_fields( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, record_expr: &ast::RecordExpr, &dot_prefix: &bool, ) { @@ -59,7 +59,7 @@ pub(crate) fn complete_record_expr_fields( // FIXME: This should probably be part of complete_path_expr pub(crate) fn complete_record_expr_func_update( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, expr_ctx: &ExprCtx, ) { @@ -81,7 +81,7 @@ pub(crate) fn complete_record_expr_func_update( fn add_default_update( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, ty: Option, missing_fields: &[(hir::Field, hir::Type)], ) { @@ -105,7 +105,7 @@ fn add_default_update( fn complete_fields( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, missing_fields: Vec<(hir::Field, hir::Type)>, ) { for (field, ty) in missing_fields { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/snippet.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/snippet.rs index a530f4262ea98..66adb4286373a 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/snippet.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/snippet.rs @@ -11,7 +11,7 @@ use crate::{ pub(crate) fn complete_expr_snippet( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, &ExprCtx { in_block_expr, .. }: &ExprCtx, ) { @@ -51,7 +51,7 @@ macro_rules! $1 { pub(crate) fn complete_item_snippet( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, kind: &ItemListKind, ) { @@ -118,7 +118,7 @@ macro_rules! $1 { } } -fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { +fn snippet(ctx: &CompletionContext<'_>, cap: SnippetCap, label: &str, snippet: &str) -> Builder { let mut item = CompletionItem::new(CompletionItemKind::Snippet, ctx.source_range(), label); item.insert_snippet(cap, snippet); item @@ -126,7 +126,7 @@ fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) fn add_custom_completions( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, cap: SnippetCap, scope: SnippetScope, ) -> Option<()> { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/type.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/type.rs index 0469d349519a8..87a998dfcce6b 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/type.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/type.rs @@ -11,7 +11,7 @@ use crate::{ pub(crate) fn complete_type_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, location: &TypeLocation, ) { @@ -208,7 +208,7 @@ pub(crate) fn complete_type_path( pub(crate) fn complete_ascribed_type( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, ascription: &TypeAscriptionTarget, ) -> Option<()> { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs index d4827771ad792..bb2ecc9fdde76 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs @@ -12,7 +12,7 @@ use crate::{ pub(crate) fn complete_use_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, use_tree_parent, .. }: &PathCompletionCtx, name_ref: &Option, ) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/vis.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/vis.rs index 39028eca41c6a..ca8303906a800 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/vis.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/vis.rs @@ -7,7 +7,7 @@ use crate::{ pub(crate) fn complete_vis_path( acc: &mut Completions, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx, &has_in_token: &bool, ) { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/context.rs b/src/tools/rust-analyzer/crates/ide-completion/src/context.rs index 7c53db9bf28e8..6a2079b12666e 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/context.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/context.rs @@ -388,7 +388,7 @@ impl<'a> CompletionContext<'a> { } } - pub(crate) fn famous_defs(&self) -> FamousDefs { + pub(crate) fn famous_defs(&self) -> FamousDefs<'_, '_> { FamousDefs(&self.sema, self.krate) } diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs b/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs index fabbbe867ee53..0c8b569b66a32 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs @@ -410,7 +410,7 @@ impl<'a> CompletionContext<'a> { } fn classify_lifetime( - _sema: &Semantics, + _sema: &Semantics<'_, RootDatabase>, original_file: &SyntaxNode, lifetime: ast::Lifetime, ) -> Option { @@ -437,7 +437,7 @@ impl<'a> CompletionContext<'a> { } fn classify_name( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, original_file: &SyntaxNode, name: ast::Name, ) -> Option { @@ -477,7 +477,7 @@ impl<'a> CompletionContext<'a> { } fn classify_name_ref( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, original_file: &SyntaxNode, name_ref: ast::NameRef, parent: SyntaxNode, @@ -987,7 +987,7 @@ impl<'a> CompletionContext<'a> { } fn pattern_context_for( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, original_file: &SyntaxNode, pat: ast::Pat, ) -> PatternContext { @@ -1047,7 +1047,7 @@ fn pattern_context_for( } fn fetch_immediate_impl( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, original_file: &SyntaxNode, node: &SyntaxNode, ) -> Option { @@ -1085,7 +1085,7 @@ fn find_node_in_file(syntax: &SyntaxNode, node: &N) -> Option { /// for the offset introduced by the fake ident. /// This is wrong if `node` comes before the insertion point! Use `find_node_in_file` instead. fn find_node_in_file_compensated( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, in_file: &SyntaxNode, node: &N, ) -> Option { @@ -1093,7 +1093,7 @@ fn find_node_in_file_compensated( } fn ancestors_in_file_compensated<'sema>( - sema: &'sema Semantics, + sema: &'sema Semantics<'_, RootDatabase>, in_file: &SyntaxNode, node: &SyntaxNode, ) -> Option + 'sema> { @@ -1117,7 +1117,7 @@ fn ancestors_in_file_compensated<'sema>( /// for the offset introduced by the fake ident.. /// This is wrong if `node` comes before the insertion point! Use `find_node_in_file` instead. fn find_opt_node_in_file_compensated( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, syntax: &SyntaxNode, node: Option, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs index 2b10dccb8008f..27482ea489be7 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs @@ -76,7 +76,7 @@ pub struct CompletionItem { // We use custom debug for CompletionItem to make snapshot tests more readable. impl fmt::Debug for CompletionItem { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut s = f.debug_struct("CompletionItem"); s.field("label", &self.label()).field("source_range", &self.source_range()); if self.text_edit().len() == 1 { @@ -433,7 +433,7 @@ pub(crate) struct Builder { impl Builder { pub(crate) fn from_resolution( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, path_ctx: &PathCompletionCtx, local_name: hir::Name, resolution: hir::ScopeDef, diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs b/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs index b806d955d99e3..e3e0ecf5d5fec 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs @@ -1,4 +1,5 @@ //! `completions` crate provides utilities for generating completions of user input. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod completions; mod config; diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render.rs index 005ab3a895ce7..0692832dbb827 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render.rs @@ -156,7 +156,10 @@ pub(crate) fn render_tuple_field( item.build() } -pub(crate) fn render_type_inference(ty_string: String, ctx: &CompletionContext) -> CompletionItem { +pub(crate) fn render_type_inference( + ty_string: String, + ctx: &CompletionContext<'_>, +) -> CompletionItem { let mut builder = CompletionItem::new(CompletionItemKind::InferredType, ctx.source_range(), ty_string); builder.set_relevance(CompletionRelevance { is_definite: true, ..Default::default() }); @@ -204,7 +207,7 @@ pub(crate) fn render_resolution_with_import_pat( fn scope_def_to_name( resolution: ScopeDef, - ctx: &RenderContext, + ctx: &RenderContext<'_>, import_edit: &LocatedImport, ) -> Option { Some(match resolution { @@ -398,7 +401,7 @@ fn scope_def_is_deprecated(ctx: &RenderContext<'_>, resolution: ScopeDef) -> boo } fn compute_type_match( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, completion_ty: &hir::Type, ) -> Option { let expected_type = ctx.expected_type.as_ref()?; @@ -418,12 +421,12 @@ fn compute_type_match( } } -fn compute_exact_name_match(ctx: &CompletionContext, completion_name: &str) -> bool { +fn compute_exact_name_match(ctx: &CompletionContext<'_>, completion_name: &str) -> bool { ctx.expected_name.as_ref().map_or(false, |name| name.text() == completion_name) } fn compute_ref_match( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, completion_ty: &hir::Type, ) -> Option { let expected_type = ctx.expected_type.as_ref()?; diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render/function.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render/function.rs index 4a8a5d5c776b5..241de0a1834a0 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render/function.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render/function.rs @@ -44,7 +44,7 @@ fn render( ctx @ RenderContext { completion, .. }: RenderContext<'_>, local_name: Option, func: hir::Function, - func_kind: FuncKind, + func_kind: FuncKind<'_>, ) -> Builder { let db = completion.db; @@ -150,7 +150,7 @@ fn render( pub(super) fn add_call_parens<'b>( builder: &'b mut Builder, - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, cap: SnippetCap, name: SmolStr, escaped_name: SmolStr, @@ -211,7 +211,7 @@ pub(super) fn add_call_parens<'b>( builder.label(SmolStr::from_iter([&name, label_suffix])).insert_snippet(cap, snippet) } -fn ref_of_param(ctx: &CompletionContext, arg: &str, ty: &hir::Type) -> &'static str { +fn ref_of_param(ctx: &CompletionContext<'_>, arg: &str, ty: &hir::Type) -> &'static str { if let Some(derefed_ty) = ty.remove_ref() { for (name, local) in ctx.locals.iter() { if name.as_text().as_deref() == Some(arg) { @@ -278,7 +278,7 @@ fn params_display(db: &dyn HirDatabase, func: hir::Function) -> String { fn params( ctx: &CompletionContext<'_>, func: hir::Function, - func_kind: &FuncKind, + func_kind: &FuncKind<'_>, has_dot_receiver: bool, ) -> Option<(Option, Vec)> { if ctx.config.callable.is_none() { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render/literal.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render/literal.rs index df80fb2fa678c..91a253f8fc8c1 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render/literal.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render/literal.rs @@ -138,7 +138,7 @@ enum Variant { } impl Variant { - fn fields(self, ctx: &CompletionContext) -> Option> { + fn fields(self, ctx: &CompletionContext<'_>) -> Option> { let fields = match self { Variant::Struct(it) => it.fields(ctx.db), Variant::EnumVariant(it) => it.fields(ctx.db), diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render/union_literal.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render/union_literal.rs index fc35381256cd3..9c9540a9bd963 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render/union_literal.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render/union_literal.rs @@ -13,7 +13,7 @@ use crate::{ }; pub(crate) fn render_union_literal( - ctx: RenderContext, + ctx: RenderContext<'_>, un: hir::Union, path: Option, local_name: Option, diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render/variant.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render/variant.rs index 440b9d14ca7e8..003a0c11ed2f8 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render/variant.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render/variant.rs @@ -68,7 +68,7 @@ pub(crate) fn render_tuple_lit( /// fields, plus a boolean for whether the list is comprehensive (contains no /// private fields and its item is not marked `#[non_exhaustive]`). pub(crate) fn visible_fields( - ctx: &CompletionContext, + ctx: &CompletionContext<'_>, fields: &[hir::Field], item: impl HasAttrs + HasCrate + Copy, ) -> Option<(Vec, bool)> { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs b/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs index d2680c7758386..a873c4e71d9a4 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs @@ -154,7 +154,7 @@ impl Snippet { } /// Returns [`None`] if the required items do not resolve. - pub(crate) fn imports(&self, ctx: &CompletionContext) -> Option> { + pub(crate) fn imports(&self, ctx: &CompletionContext<'_>) -> Option> { import_edits(ctx, &self.requires) } @@ -167,7 +167,7 @@ impl Snippet { } } -fn import_edits(ctx: &CompletionContext, requires: &[GreenNode]) -> Option> { +fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option> { let resolve = |import: &GreenNode| { let path = ast::Path::cast(SyntaxNode::new_root(import.clone()))?; let item = match ctx.scope.speculative_resolve(&path)? { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs b/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs index 788a5ed17e63e..7303ef8b7bb58 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs @@ -17,7 +17,7 @@ pub struct ActiveParameter { impl ActiveParameter { /// Returns information about the call argument this token is part of. - pub fn at_token(sema: &Semantics, token: SyntaxToken) -> Option { + pub fn at_token(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> Option { let (signature, active_parameter) = callable_for_token(sema, token)?; let idx = active_parameter?; @@ -40,7 +40,7 @@ impl ActiveParameter { /// Returns a [`hir::Callable`] this token is a part of and its argument index of said callable. pub fn callable_for_token( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: SyntaxToken, ) -> Option<(hir::Callable, Option)> { // Find the calling expression and its NameRef @@ -54,7 +54,7 @@ pub fn callable_for_token( } pub fn callable_for_node( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, calling_node: &ast::CallableExpr, token: &SyntaxToken, ) -> Option<(hir::Callable, Option)> { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs index 540cc70dd5228..692a315720308 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs @@ -130,7 +130,10 @@ pub enum IdentClass { } impl IdentClass { - pub fn classify_node(sema: &Semantics, node: &SyntaxNode) -> Option { + pub fn classify_node( + sema: &Semantics<'_, RootDatabase>, + node: &SyntaxNode, + ) -> Option { match_ast! { match node { ast::Name(name) => NameClass::classify(sema, &name).map(IdentClass::NameClass), @@ -146,7 +149,7 @@ impl IdentClass { } pub fn classify_token( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: &SyntaxToken, ) -> Option { let parent = token.parent()?; @@ -154,7 +157,7 @@ impl IdentClass { } pub fn classify_lifetime( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, lifetime: &ast::Lifetime, ) -> Option { NameRefClass::classify_lifetime(sema, lifetime) @@ -218,7 +221,7 @@ impl NameClass { Some(res) } - pub fn classify(sema: &Semantics, name: &ast::Name) -> Option { + pub fn classify(sema: &Semantics<'_, RootDatabase>, name: &ast::Name) -> Option { let _p = profile::span("classify_name"); let parent = name.syntax().parent()?; @@ -238,7 +241,10 @@ impl NameClass { }; return Some(NameClass::Definition(definition)); - fn classify_item(sema: &Semantics, item: ast::Item) -> Option { + fn classify_item( + sema: &Semantics<'_, RootDatabase>, + item: ast::Item, + ) -> Option { let definition = match item { ast::Item::MacroRules(it) => { Definition::Macro(sema.to_def(&ast::Macro::MacroRules(it))?) @@ -266,7 +272,7 @@ impl NameClass { } fn classify_ident_pat( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, ident_pat: ast::IdentPat, ) -> Option { if let Some(def) = sema.resolve_bind_pat_to_const(&ident_pat) { @@ -289,7 +295,7 @@ impl NameClass { } fn classify_rename( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, rename: ast::Rename, ) -> Option { if let Some(use_tree) = rename.syntax().parent().and_then(ast::UseTree::cast) { @@ -305,7 +311,7 @@ impl NameClass { } pub fn classify_lifetime( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, lifetime: &ast::Lifetime, ) -> Option { let _p = profile::span("classify_lifetime").detail(|| lifetime.to_string()); @@ -338,7 +344,7 @@ impl NameRefClass { // Note: we don't have unit-tests for this rather important function. // It is primarily exercised via goto definition tests in `ide`. pub fn classify( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, name_ref: &ast::NameRef, ) -> Option { let _p = profile::span("classify_name_ref").detail(|| name_ref.to_string()); @@ -418,7 +424,7 @@ impl NameRefClass { } pub fn classify_lifetime( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, lifetime: &ast::Lifetime, ) -> Option { let _p = profile::span("classify_lifetime_ref").detail(|| lifetime.to_string()); diff --git a/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs b/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs index d4fda397d6827..6e56efe344d72 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs @@ -56,7 +56,7 @@ pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path { /// Iterates all `ModuleDef`s and `Impl` blocks of the given file. pub fn visit_file_defs( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, file_id: FileId, cb: &mut dyn FnMut(Definition), ) { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs index 81467ab07a2ff..26ef86155e534 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs @@ -99,7 +99,7 @@ pub struct ImportAssets { impl ImportAssets { pub fn for_method_call( method_call: &ast::MethodCallExpr, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, ) -> Option { let candidate_node = method_call.syntax().clone(); Some(Self { @@ -111,7 +111,7 @@ impl ImportAssets { pub fn for_exact_path( fully_qualified_path: &ast::Path, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, ) -> Option { let candidate_node = fully_qualified_path.syntax().clone(); if let Some(use_tree) = candidate_node.ancestors().find_map(ast::UseTree::cast) { @@ -129,7 +129,7 @@ impl ImportAssets { }) } - pub fn for_ident_pat(sema: &Semantics, pat: &ast::IdentPat) -> Option { + pub fn for_ident_pat(sema: &Semantics<'_, RootDatabase>, pat: &ast::IdentPat) -> Option { if !pat.is_simple_ident() { return None; } @@ -146,7 +146,7 @@ impl ImportAssets { module_with_candidate: Module, qualifier: Option, fuzzy_name: String, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, candidate_node: SyntaxNode, ) -> Option { Some(Self { @@ -210,7 +210,7 @@ impl ImportAssets { pub fn search_for_imports( &self, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, prefix_kind: PrefixKind, ) -> Vec { let _p = profile::span("import_assets::search_for_imports"); @@ -218,7 +218,10 @@ impl ImportAssets { } /// This may return non-absolute paths if a part of the returned path is already imported into scope. - pub fn search_for_relative_paths(&self, sema: &Semantics) -> Vec { + pub fn search_for_relative_paths( + &self, + sema: &Semantics<'_, RootDatabase>, + ) -> Vec { let _p = profile::span("import_assets::search_for_relative_paths"); self.search_for(sema, None) } @@ -237,7 +240,7 @@ impl ImportAssets { fn search_for( &self, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, prefixed: Option, ) -> Vec { let _p = profile::span("import_assets::search_for"); @@ -276,7 +279,7 @@ impl ImportAssets { .collect() } - fn scope_definitions(&self, sema: &Semantics) -> FxHashSet { + fn scope_definitions(&self, sema: &Semantics<'_, RootDatabase>) -> FxHashSet { let _p = profile::span("import_assets::scope_definitions"); let mut scope_definitions = FxHashSet::default(); if let Some(scope) = sema.scope(&self.candidate_node) { @@ -289,7 +292,7 @@ impl ImportAssets { } fn path_applicable_imports( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, current_crate: Crate, path_candidate: &PathImportCandidate, mod_path: impl Fn(ItemInNs) -> Option + Copy, @@ -456,9 +459,9 @@ fn module_with_segment_name( } fn trait_applicable_items( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, current_crate: Crate, - scope: &SemanticsScope, + scope: &SemanticsScope<'_>, trait_candidate: &TraitImportCandidate, trait_assoc_item: bool, mod_path: impl Fn(ItemInNs) -> Option, @@ -571,7 +574,7 @@ fn get_mod_path( impl ImportCandidate { fn for_method_call( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, method_call: &ast::MethodCallExpr, ) -> Option { match sema.resolve_method_call(method_call) { @@ -585,7 +588,7 @@ impl ImportCandidate { } } - fn for_regular_path(sema: &Semantics, path: &ast::Path) -> Option { + fn for_regular_path(sema: &Semantics<'_, RootDatabase>, path: &ast::Path) -> Option { if sema.resolve_path(path).is_some() { return None; } @@ -596,7 +599,7 @@ impl ImportCandidate { ) } - fn for_name(sema: &Semantics, name: &ast::Name) -> Option { + fn for_name(sema: &Semantics<'_, RootDatabase>, name: &ast::Name) -> Option { if sema .scope(name.syntax())? .speculative_resolve(&ast::make::ext::ident_path(&name.text())) @@ -613,14 +616,14 @@ impl ImportCandidate { fn for_fuzzy_path( qualifier: Option, fuzzy_name: String, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, ) -> Option { path_import_candidate(sema, qualifier, NameToImport::Fuzzy(fuzzy_name)) } } fn path_import_candidate( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, qualifier: Option, name: NameToImport, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs index 165b98d72ed67..209a29aeaa2fd 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs @@ -1,6 +1,7 @@ //! This crate defines the core datastructure representing IDE state -- `RootDatabase`. //! //! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod apply_change; @@ -113,7 +114,7 @@ impl FileLoader for RootDatabase { fn file_text(&self, file_id: FileId) -> Arc { FileLoaderDelegate(self).file_text(file_id) } - fn resolve_path(&self, path: AnchoredPath) -> Option { + fn resolve_path(&self, path: AnchoredPath<'_>) -> Option { FileLoaderDelegate(self).resolve_path(path) } fn relevant_crates(&self, file_id: FileId) -> Arc> { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs index 61b2c3f3b8b05..d78b8758d6512 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs @@ -255,7 +255,7 @@ fn get_type_args_from_arg_list(generic_arg_list: ast::GenericArgList) -> Option< } fn find_trait_for_assoc_item( - scope: &SemanticsScope, + scope: &SemanticsScope<'_>, type_param: hir::TypeParam, assoc_item: ast::NameRef, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/rename.rs b/src/tools/rust-analyzer/crates/ide-db/src/rename.rs index c2e7142f52fd1..bb466e43e7521 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/rename.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/rename.rs @@ -66,7 +66,11 @@ macro_rules! _bail { pub use _bail as bail; impl Definition { - pub fn rename(&self, sema: &Semantics, new_name: &str) -> Result { + pub fn rename( + &self, + sema: &Semantics<'_, RootDatabase>, + new_name: &str, + ) -> Result { match *self { Definition::Module(module) => rename_mod(sema, module, new_name), Definition::BuiltinType(_) => { @@ -80,7 +84,7 @@ impl Definition { /// Textual range of the identifier which will change when renaming this /// `Definition`. Note that some definitions, like buitin types, can't be /// renamed. - pub fn range_for_rename(self, sema: &Semantics) -> Option { + pub fn range_for_rename(self, sema: &Semantics<'_, RootDatabase>) -> Option { let res = match self { Definition::Macro(mac) => { let src = mac.source(sema.db)?; @@ -155,7 +159,7 @@ impl Definition { }; return res; - fn name_range(def: D, sema: &Semantics) -> Option + fn name_range(def: D, sema: &Semantics<'_, RootDatabase>) -> Option where D: HasSource, D::Ast: ast::HasName, @@ -168,7 +172,7 @@ impl Definition { } fn rename_mod( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, module: hir::Module, new_name: &str, ) -> Result { @@ -248,7 +252,7 @@ fn rename_mod( } fn rename_reference( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, def: Definition, new_name: &str, ) -> Result { @@ -448,7 +452,7 @@ fn source_edit_from_name_ref( } fn source_edit_from_def( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, def: Definition, new_name: &str, ) -> Result<(FileId, TextEdit)> { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs index 692fce06b0fcb..2133804af1587 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs @@ -307,7 +307,7 @@ impl Definition { } } - pub fn usages<'a>(self, sema: &'a Semantics) -> FindUsages<'a> { + pub fn usages<'a>(self, sema: &'a Semantics<'_, RootDatabase>) -> FindUsages<'a> { FindUsages { local_repr: match self { Definition::Local(local) => Some(local.representative(sema.db)), @@ -423,7 +423,7 @@ impl<'a> FindUsages<'a> { } fn scope_files<'a>( - sema: &'a Semantics, + sema: &'a Semantics<'_, RootDatabase>, scope: &'a SearchScope, ) -> impl Iterator, FileId, TextRange)> + 'a { scope.entries.iter().map(|(&file_id, &search_range)| { @@ -741,7 +741,7 @@ impl<'a> FindUsages<'a> { } } -fn def_to_ty(sema: &Semantics, def: &Definition) -> Option { +fn def_to_ty(sema: &Semantics<'_, RootDatabase>, def: &Definition) -> Option { match def { Definition::Adt(adt) => Some(adt.ty(sema.db)), Definition::TypeAlias(it) => Some(it.ty(sema.db)), diff --git a/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs b/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs index 33e2001934876..bfb0031277105 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs @@ -224,7 +224,7 @@ pub struct SymbolIndex { } impl fmt::Debug for SymbolIndex { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SymbolIndex").field("n_symbols", &self.symbols.len()).finish() } } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs index f011a4a48a36d..84bde4d44dbb3 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs @@ -399,7 +399,7 @@ impl TreeWithDepthIterator { } } -impl<'a> Iterator for TreeWithDepthIterator { +impl Iterator for TreeWithDepthIterator { type Item = (ast::Expr, u32); fn next(&mut self) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/tests/sourcegen_lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/tests/sourcegen_lints.rs index b7db1dd8dbc27..5042f6d815a1e 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/tests/sourcegen_lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/tests/sourcegen_lints.rs @@ -264,7 +264,7 @@ fn push_lint_completion(buf: &mut String, label: &str, description: &str) { ); } -fn push_lint_group<'a>(buf: &mut String, label: &str, description: &str, children: &[String]) { +fn push_lint_group(buf: &mut String, label: &str, description: &str, children: &[String]) { buf.push_str( r###" LintGroup { lint: diff --git a/src/tools/rust-analyzer/crates/ide-db/src/traits.rs b/src/tools/rust-analyzer/crates/ide-db/src/traits.rs index 666499ed7a5e3..d1301e7a8f560 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/traits.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/traits.rs @@ -7,7 +7,7 @@ use syntax::{ast, AstNode}; /// Given the `impl` block, attempts to find the trait this `impl` corresponds to. pub fn resolve_target_trait( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, impl_def: &ast::Impl, ) -> Option { let ast_path = @@ -22,7 +22,7 @@ pub fn resolve_target_trait( /// Given the `impl` block, returns the list of associated items (e.g. functions or types) that are /// missing in this `impl` block. pub fn get_missing_assoc_items( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, impl_def: &ast::Impl, ) -> Vec { let imp = match sema.to_def(impl_def) { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/ty_filter.rs b/src/tools/rust-analyzer/crates/ide-db/src/ty_filter.rs index 2c6b00b1343b3..46f47f258bdb8 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/ty_filter.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/ty_filter.rs @@ -20,7 +20,7 @@ impl TryEnum { const ALL: [TryEnum; 2] = [TryEnum::Option, TryEnum::Result]; /// Returns `Some(..)` if the provided type is an enum that implements `std::ops::Try`. - pub fn from_ty(sema: &Semantics, ty: &hir::Type) -> Option { + pub fn from_ty(sema: &Semantics<'_, RootDatabase>, ty: &hir::Type) -> Option { let enum_ = match ty.as_adt() { Some(hir::Adt::Enum(it)) => it, _ => return None, diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/no_such_field.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/no_such_field.rs index 667a550d1f9c2..e032c578f0282 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/no_such_field.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/no_such_field.rs @@ -30,7 +30,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::NoSuchField) -> Option, + sema: &Semantics<'_, RootDatabase>, usage_file_id: FileId, record_expr_field: &ast::RecordExprField, ) -> Option> { diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unlinked_file.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unlinked_file.rs index 9d46e2b0785d1..c626932f196ba 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unlinked_file.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unlinked_file.rs @@ -18,7 +18,11 @@ use crate::{fix, Assist, Diagnostic, DiagnosticsContext, Severity}; // // This diagnostic is shown for files that are not included in any crate, or files that are part of // crates rust-analyzer failed to discover. The file will not have IDE features available. -pub(crate) fn unlinked_file(ctx: &DiagnosticsContext, acc: &mut Vec, file_id: FileId) { +pub(crate) fn unlinked_file( + ctx: &DiagnosticsContext<'_>, + acc: &mut Vec, + file_id: FileId, +) { // Limit diagnostic to the first few characters in the file. This matches how VS Code // renders it with the full span, but on other editors, and is less invasive. let range = ctx.sema.db.parse(file_id).syntax_node().text_range(); @@ -32,7 +36,7 @@ pub(crate) fn unlinked_file(ctx: &DiagnosticsContext, acc: &mut Vec, ); } -fn fixes(ctx: &DiagnosticsContext, file_id: FileId) -> Option> { +fn fixes(ctx: &DiagnosticsContext<'_>, file_id: FileId) -> Option> { // If there's an existing module that could add `mod` or `pub mod` items to include the unlinked file, // suggest that as a fix. diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs index eeddd36fb5386..c83a84d0bca98 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs @@ -22,6 +22,7 @@ //! //! There are also a couple of ad-hoc diagnostics implemented directly here, we //! don't yet have a great pattern for how to do them properly. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod handlers { pub(crate) mod break_outside_of_loop; diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/from_comment.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/from_comment.rs index c50e74d93a467..5b6e016251b40 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/from_comment.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/from_comment.rs @@ -15,7 +15,10 @@ use crate::MatchFinder; /// Attempts to build an SSR MatchFinder from a comment at the given file /// range. If successful, returns the MatchFinder and a TextRange covering /// comment. -pub fn ssr_from_comment(db: &RootDatabase, frange: FileRange) -> Option<(MatchFinder, TextRange)> { +pub fn ssr_from_comment( + db: &RootDatabase, + frange: FileRange, +) -> Option<(MatchFinder<'_>, TextRange)> { let comment = { let file = db.parse(frange.file_id); file.tree().syntax().token_at_offset(frange.range.start()).find_map(ast::Comment::cast) diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/lib.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/lib.rs index 7b4e53ed24a67..e3d4b75c11b5a 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/lib.rs @@ -66,6 +66,7 @@ // // Place the cursor on the line below to see the assist 💡. // // foo($a, $b) ==>> ($a).foo($b) // ``` +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod from_comment; mod matching; diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs index ba2a99c5d41db..e3a837ddcdb05 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs @@ -89,7 +89,7 @@ pub(crate) fn get_match( rule: &ResolvedRule, code: &SyntaxNode, restrict_range: &Option, - sema: &Semantics, + sema: &Semantics<'_, ide_db::RootDatabase>, ) -> Result { record_match_fails_reasons_scope(debug_active, || { Matcher::try_match(rule, code, restrict_range, sema) @@ -165,7 +165,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_node( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed> { @@ -218,7 +218,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_node_children( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed> { @@ -231,7 +231,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_sequences( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern_it: PatternIterator, mut code_it: SyntaxElementChildren, ) -> Result<(), MatchFailed> { @@ -260,7 +260,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_token( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: &mut Peekable, code: &syntax::SyntaxToken, ) -> Result<(), MatchFailed> { @@ -332,7 +332,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { /// differently. fn attempt_match_path( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed> { @@ -372,7 +372,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_opt( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: Option, code: Option, ) -> Result<(), MatchFailed> { @@ -390,7 +390,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { /// them. fn attempt_match_record_field_list( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed> { @@ -440,7 +440,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { /// expanded the macro. fn attempt_match_token_tree( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &syntax::SyntaxNode, ) -> Result<(), MatchFailed> { @@ -521,7 +521,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_ufcs_to_method_call( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern_ufcs: &UfcsCallInfo, code: &ast::MethodCallExpr, ) -> Result<(), MatchFailed> { @@ -581,7 +581,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { fn attempt_match_ufcs_to_ufcs( &self, - phase: &mut Phase, + phase: &mut Phase<'_>, pattern_ufcs: &UfcsCallInfo, code: &ast::CallExpr, ) -> Result<(), MatchFailed> { @@ -640,7 +640,7 @@ impl Match { fn render_template_paths( &mut self, template: &ResolvedPattern, - sema: &Semantics, + sema: &Semantics<'_, ide_db::RootDatabase>, ) -> Result<(), MatchFailed> { let module = sema .scope(&self.matched_node) diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/nester.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/nester.rs index 0c1b2685b204f..afaaafd1fb491 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/nester.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/nester.rs @@ -14,7 +14,7 @@ use crate::{Match, SsrMatches}; pub(crate) fn nest_and_remove_collisions( mut matches: Vec, - sema: &hir::Semantics, + sema: &hir::Semantics<'_, ide_db::RootDatabase>, ) -> SsrMatches { // We sort the matches by depth then by rule index. Sorting by depth means that by the time we // see a match, any parent matches or conflicting matches will have already been seen. Sorting @@ -37,7 +37,7 @@ impl MatchCollector { /// Attempts to add `m` to matches. If it conflicts with an existing match, it is discarded. If /// it is entirely within the a placeholder of an existing match, then it is added as a child /// match of the existing match. - fn add_match(&mut self, m: Match, sema: &hir::Semantics) { + fn add_match(&mut self, m: Match, sema: &hir::Semantics<'_, ide_db::RootDatabase>) { let matched_node = m.matched_node.clone(); if let Some(existing) = self.matches_by_node.get_mut(&matched_node) { try_add_sub_match(m, existing, sema); @@ -54,7 +54,11 @@ impl MatchCollector { } /// Attempts to add `m` as a sub-match of `existing`. -fn try_add_sub_match(m: Match, existing: &mut Match, sema: &hir::Semantics) { +fn try_add_sub_match( + m: Match, + existing: &mut Match, + sema: &hir::Semantics<'_, ide_db::RootDatabase>, +) { for p in existing.placeholder_values.values_mut() { // Note, no need to check if p.range.file is equal to m.range.file, since we // already know we're within `existing`. diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/resolving.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/resolving.rs index f3b1af8e77fe1..4731f14f4e623 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/resolving.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/resolving.rs @@ -42,7 +42,7 @@ pub(crate) struct UfcsCallInfo { impl ResolvedRule { pub(crate) fn new( rule: parsing::ParsedRule, - resolution_scope: &ResolutionScope, + resolution_scope: &ResolutionScope<'_>, index: usize, ) -> Result { let resolver = diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/tests.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/tests.rs index e86190564cf44..1ecb7aa9aa701 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/tests.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/tests.rs @@ -113,7 +113,7 @@ fn assert_ssr_transforms(rules: &[&str], input: &str, expected: Expect) { expected.assert_eq(&actual); } -fn print_match_debug_info(match_finder: &MatchFinder, file_id: FileId, snippet: &str) { +fn print_match_debug_info(match_finder: &MatchFinder<'_>, file_id: FileId, snippet: &str) { let debug_info = match_finder.debug_where_text_equal(file_id, snippet); println!( "Match debug info: {} nodes had text exactly equal to '{}'", diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs index 0f2ab6d695511..fed327f52be52 100644 --- a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs +++ b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs @@ -75,7 +75,7 @@ pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: Defin pub(crate) fn remove_links(markdown: &str) -> String { let mut drop_link = false; - let mut cb = |_: BrokenLink| { + let mut cb = |_: BrokenLink<'_>| { let empty = InlineStr::try_from("").unwrap(); Some((CowStr::Inlined(empty), CowStr::Inlined(empty))) }; @@ -196,7 +196,7 @@ pub(crate) fn resolve_doc_path_for_def( } pub(crate) fn doc_attributes( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, node: &SyntaxNode, ) -> Option<(hir::AttrsWithOwner, Definition)> { match_ast! { @@ -241,7 +241,7 @@ pub(crate) fn token_as_doc_comment(doc_token: &SyntaxToken) -> Option( self, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, offset: TextSize, // Definition, CommentOwner, range of intra doc link in original file mut cb: impl FnMut(Definition, SyntaxNode, TextRange) -> Option, @@ -360,7 +360,7 @@ fn map_links<'e>( ) -> impl Iterator> { let mut in_link = false; // holds the origin link target on start event and the rewritten one on end event - let mut end_link_target: Option = None; + let mut end_link_target: Option> = None; // normally link's type is determined by the type of link tag in the end event, // however in some cases we want to change the link type, for example, // `Shortcut` type parsed from Start/End tags doesn't make sense for url links diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs index 2cba5081c11d8..c6bfb6b9d0975 100644 --- a/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs +++ b/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs @@ -52,7 +52,7 @@ fn check_doc_links(ra_fixture: &str) { } fn def_under_cursor( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, position: &FilePosition, ) -> (Definition, hir::Documentation) { let (docs, def) = sema @@ -70,7 +70,7 @@ fn def_under_cursor( } fn node_to_def( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, node: &SyntaxNode, ) -> Option, Definition)>> { Some(match_ast! { diff --git a/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs b/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs index fd0a29f64f67c..efa8551a00d5a 100644 --- a/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs +++ b/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs @@ -100,23 +100,26 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< } fn expand_macro_recur( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, macro_call: &ast::MacroCall, ) -> Option { let expanded = sema.expand(macro_call)?.clone_for_update(); expand(sema, expanded, ast::MacroCall::cast, expand_macro_recur) } -fn expand_attr_macro_recur(sema: &Semantics, item: &ast::Item) -> Option { +fn expand_attr_macro_recur( + sema: &Semantics<'_, RootDatabase>, + item: &ast::Item, +) -> Option { let expanded = sema.expand_attr_macro(item)?.clone_for_update(); expand(sema, expanded, ast::Item::cast, expand_attr_macro_recur) } fn expand( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, expanded: SyntaxNode, f: impl FnMut(SyntaxNode) -> Option, - exp: impl Fn(&Semantics, &T) -> Option, + exp: impl Fn(&Semantics<'_, RootDatabase>, &T) -> Option, ) -> Option { let children = expanded.descendants().filter_map(f); let mut replacements = Vec::new(); diff --git a/src/tools/rust-analyzer/crates/ide/src/extend_selection.rs b/src/tools/rust-analyzer/crates/ide/src/extend_selection.rs index 6111bdb94aaaf..45f1fd74841c6 100644 --- a/src/tools/rust-analyzer/crates/ide/src/extend_selection.rs +++ b/src/tools/rust-analyzer/crates/ide/src/extend_selection.rs @@ -33,7 +33,7 @@ pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRang } fn try_extend_selection( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, root: &SyntaxNode, frange: FileRange, ) -> Option { @@ -120,7 +120,7 @@ fn try_extend_selection( } fn extend_tokens_from_range( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, macro_call: ast::MacroCall, original_range: TextRange, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs index e10789fd47aed..d9c97751c95c3 100644 --- a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs +++ b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs @@ -79,7 +79,7 @@ pub(crate) fn goto_definition( } fn try_lookup_include_path( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, tt: ast::TokenTree, token: SyntaxToken, file_id: FileId, @@ -112,7 +112,7 @@ fn try_lookup_include_path( /// impl A for S { type a = i32; } // <-- on this associate type, will get the location of a in the trait /// ``` fn try_filter_trait_item_definition( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, def: &Definition, ) -> Option> { let db = sema.db; diff --git a/src/tools/rust-analyzer/crates/ide/src/goto_implementation.rs b/src/tools/rust-analyzer/crates/ide/src/goto_implementation.rs index 1d2909fa280c3..04b51c839407b 100644 --- a/src/tools/rust-analyzer/crates/ide/src/goto_implementation.rs +++ b/src/tools/rust-analyzer/crates/ide/src/goto_implementation.rs @@ -86,11 +86,14 @@ pub(crate) fn goto_implementation( Some(RangeInfo { range, info: navs }) } -fn impls_for_ty(sema: &Semantics, ty: hir::Type) -> Vec { +fn impls_for_ty(sema: &Semantics<'_, RootDatabase>, ty: hir::Type) -> Vec { Impl::all_for_type(sema.db, ty).into_iter().filter_map(|imp| imp.try_to_nav(sema.db)).collect() } -fn impls_for_trait(sema: &Semantics, trait_: hir::Trait) -> Vec { +fn impls_for_trait( + sema: &Semantics<'_, RootDatabase>, + trait_: hir::Trait, +) -> Vec { Impl::all_for_trait(sema.db, trait_) .into_iter() .filter_map(|imp| imp.try_to_nav(sema.db)) @@ -98,7 +101,7 @@ fn impls_for_trait(sema: &Semantics, trait_: hir::Trait) -> Vec, + sema: &Semantics<'_, RootDatabase>, trait_: hir::Trait, fun_name: hir::Name, ) -> Vec { diff --git a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs index 7c0a7fa1e7243..80577c5d5430f 100644 --- a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs +++ b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs @@ -44,7 +44,7 @@ pub struct HighlightRelatedConfig { // // Note: `?` and `->` do not currently trigger this behavior in the VSCode editor. pub(crate) fn highlight_related( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: HighlightRelatedConfig, FilePosition { offset, file_id }: FilePosition, ) -> Option> { @@ -76,7 +76,7 @@ pub(crate) fn highlight_related( } fn highlight_references( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, node: &SyntaxNode, token: SyntaxToken, file_id: FileId, @@ -136,11 +136,11 @@ fn highlight_references( } fn highlight_exit_points( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: SyntaxToken, ) -> Option> { fn hl( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, body: Option, ) -> Option> { let mut highlights = Vec::new(); @@ -330,7 +330,7 @@ fn cover_range(r0: Option, r1: Option) -> Option, token: SyntaxToken) -> FxHashSet { +fn find_defs(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> FxHashSet { sema.descend_into_macros(token) .into_iter() .filter_map(|token| IdentClass::classify_token(sema, &token).map(IdentClass::definitions)) diff --git a/src/tools/rust-analyzer/crates/ide/src/hover.rs b/src/tools/rust-analyzer/crates/ide/src/hover.rs index 592fff322e531..d8867cf783ad8 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover.rs @@ -163,7 +163,7 @@ pub(crate) fn hover( } pub(crate) fn hover_for_definition( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, file_id: FileId, definition: Definition, node: &SyntaxNode, @@ -189,7 +189,7 @@ pub(crate) fn hover_for_definition( fn hover_ranged( file: &SyntaxNode, range: syntax::TextRange, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &HoverConfig, ) -> Option> { // FIXME: make this work in attributes @@ -222,7 +222,7 @@ fn hover_ranged( } fn hover_type_fallback( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &HoverConfig, token: &SyntaxToken, original_token: &SyntaxToken, @@ -281,7 +281,7 @@ fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option, + sema: &hir::Semantics<'_, RootDatabase>, def: Definition, file_id: FileId, ) -> Option { diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs index 1cb67c6657a83..925aaa61cdd04 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs @@ -26,7 +26,7 @@ use crate::{ }; pub(super) fn type_info( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &HoverConfig, expr_or_pat: &Either, ) -> Option { @@ -71,7 +71,7 @@ pub(super) fn type_info( } pub(super) fn try_expr( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &HoverConfig, try_expr: &ast::TryExpr, ) -> Option { @@ -162,7 +162,7 @@ pub(super) fn try_expr( } pub(super) fn deref_expr( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &HoverConfig, deref_expr: &ast::PrefixExpr, ) -> Option { @@ -226,7 +226,7 @@ pub(super) fn deref_expr( } pub(super) fn keyword( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &HoverConfig, token: &SyntaxToken, ) -> Option { @@ -335,7 +335,7 @@ pub(super) fn path(db: &RootDatabase, module: hir::Module, item_name: Option, + famous_defs: Option<&FamousDefs<'_, '_>>, config: &HoverConfig, ) -> Option { let mod_path = definition_mod_path(db, &def); @@ -460,7 +460,7 @@ fn markup(docs: Option, desc: String, mod_path: Option) -> Optio Some(buf.into()) } -fn builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Option { +fn builtin(famous_defs: &FamousDefs<'_, '_>, builtin: hir::BuiltinType) -> Option { // std exposes prim_{} modules with docstrings on the root to document the builtins let primitive_mod = format!("prim_{}", builtin.name()); let doc_owner = find_std_module(famous_defs, &primitive_mod)?; @@ -468,7 +468,7 @@ fn builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Option Option { +fn find_std_module(famous_defs: &FamousDefs<'_, '_>, name: &str) -> Option { let db = famous_defs.0.db; let std_crate = famous_defs.std()?; let std_root_module = std_crate.root_module(db); @@ -513,7 +513,7 @@ impl KeywordHint { } fn keyword_hints( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: &SyntaxToken, parent: syntax::SyntaxNode, ) -> KeywordHint { diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs index 2c3009abe9004..5aae669aa4d6d 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs @@ -138,7 +138,7 @@ pub(crate) fn inlay_hints( fn hints( hints: &mut Vec, - famous_defs @ FamousDefs(sema, _): &FamousDefs, + famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>, config: &InlayHintsConfig, file_id: FileId, node: SyntaxNode, @@ -185,7 +185,7 @@ fn hints( fn closing_brace_hints( acc: &mut Vec, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, file_id: FileId, node: SyntaxNode, @@ -502,8 +502,8 @@ fn fn_lifetime_fn_hints( fn closure_ret_hints( acc: &mut Vec, - sema: &Semantics, - famous_defs: &FamousDefs, + sema: &Semantics<'_, RootDatabase>, + famous_defs: &FamousDefs<'_, '_>, config: &InlayHintsConfig, file_id: FileId, closure: ast::ClosureExpr, @@ -543,7 +543,7 @@ fn closure_ret_hints( fn reborrow_hints( acc: &mut Vec, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, expr: &ast::Expr, ) -> Option<()> { @@ -570,8 +570,8 @@ fn reborrow_hints( fn chaining_hints( acc: &mut Vec, - sema: &Semantics, - famous_defs: &FamousDefs, + sema: &Semantics<'_, RootDatabase>, + famous_defs: &FamousDefs<'_, '_>, config: &InlayHintsConfig, file_id: FileId, expr: &ast::Expr, @@ -632,7 +632,7 @@ fn chaining_hints( fn param_name_hints( acc: &mut Vec, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, expr: ast::Expr, ) -> Option<()> { @@ -685,7 +685,7 @@ fn param_name_hints( fn binding_mode_hints( acc: &mut Vec, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, pat: &ast::Pat, ) -> Option<()> { @@ -732,7 +732,7 @@ fn binding_mode_hints( fn bind_pat_hints( acc: &mut Vec, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, file_id: FileId, pat: &ast::IdentPat, @@ -783,7 +783,7 @@ fn bind_pat_hints( } fn is_named_constructor( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, pat: &ast::IdentPat, ty_name: &str, ) -> Option<()> { @@ -837,8 +837,8 @@ fn is_named_constructor( /// Checks if the type is an Iterator from std::iter and replaces its hint with an `impl Iterator`. fn hint_iterator( - sema: &Semantics, - famous_defs: &FamousDefs, + sema: &Semantics<'_, RootDatabase>, + famous_defs: &FamousDefs<'_, '_>, config: &InlayHintsConfig, ty: &hir::Type, ) -> Option { @@ -899,7 +899,7 @@ fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &hir } fn should_not_display_type_hint( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, config: &InlayHintsConfig, bind_pat: &ast::IdentPat, pat_ty: &hir::Type, @@ -959,7 +959,7 @@ fn closure_has_block_body(closure: &ast::ClosureExpr) -> bool { } fn should_hide_param_name_hint( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, callable: &hir::Callable, param_name: &str, argument: &ast::Expr, @@ -1048,7 +1048,7 @@ fn is_param_name_suffix_of_fn_name( } fn is_adt_constructor_similar_to_param_name( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, argument: &ast::Expr, param_name: &str, ) -> bool { @@ -1116,7 +1116,7 @@ fn is_obvious_param(param_name: &str) -> bool { } fn get_callable( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr, ) -> Option<(hir::Callable, ast::ArgList)> { match expr { diff --git a/src/tools/rust-analyzer/crates/ide/src/lib.rs b/src/tools/rust-analyzer/crates/ide/src/lib.rs index 88dd103f39264..e2cb988a32586 100644 --- a/src/tools/rust-analyzer/crates/ide/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide/src/lib.rs @@ -6,7 +6,7 @@ //! database, and the `hir` crate, where majority of the analysis happens. //! However, IDE specific bits of the analysis (most notably completion) happen //! in this crate. - +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] // For proving that RootDatabase is RefUnwindSafe. #![recursion_limit = "128"] diff --git a/src/tools/rust-analyzer/crates/ide/src/references.rs b/src/tools/rust-analyzer/crates/ide/src/references.rs index 626e8fe34a9e6..b49483fd8192e 100644 --- a/src/tools/rust-analyzer/crates/ide/src/references.rs +++ b/src/tools/rust-analyzer/crates/ide/src/references.rs @@ -50,7 +50,7 @@ pub struct Declaration { // // image::https://user-images.githubusercontent.com/48062697/113020670-b7c34f00-917a-11eb-8003-370ac5f2b3cb.gif[] pub(crate) fn find_all_refs( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, position: FilePosition, search_scope: Option, ) -> Option> { @@ -111,7 +111,7 @@ pub(crate) fn find_all_refs( } pub(crate) fn find_defs<'a>( - sema: &'a Semantics, + sema: &'a Semantics<'_, RootDatabase>, syntax: &SyntaxNode, offset: TextSize, ) -> Option + 'a> { @@ -177,7 +177,7 @@ pub(crate) fn decl_mutability(def: &Definition, syntax: &SyntaxNode, range: Text fn retain_adt_literal_usages( usages: &mut UsageSearchResult, def: Definition, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, ) { let refs = usages.references.values_mut(); match def { @@ -241,7 +241,7 @@ fn name_for_constructor_search(syntax: &SyntaxNode, position: FilePosition) -> O } fn is_enum_lit_name_ref( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, enum_: hir::Enum, name_ref: &ast::NameRef, ) -> bool { diff --git a/src/tools/rust-analyzer/crates/ide/src/rename.rs b/src/tools/rust-analyzer/crates/ide/src/rename.rs index 23d6f8d8e4e2c..fe44856dcad2a 100644 --- a/src/tools/rust-analyzer/crates/ide/src/rename.rs +++ b/src/tools/rust-analyzer/crates/ide/src/rename.rs @@ -120,7 +120,7 @@ pub(crate) fn will_rename_file( } fn find_definitions( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, syntax: &SyntaxNode, position: FilePosition, ) -> RenameResult> { @@ -201,7 +201,10 @@ fn find_definitions( } } -fn rename_to_self(sema: &Semantics, local: hir::Local) -> RenameResult { +fn rename_to_self( + sema: &Semantics<'_, RootDatabase>, + local: hir::Local, +) -> RenameResult { if never!(local.is_self(sema.db)) { bail!("rename_to_self invoked on self"); } @@ -269,7 +272,7 @@ fn rename_to_self(sema: &Semantics, local: hir::Local) -> RenameRe } fn rename_self_to_param( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, local: hir::Local, self_param: hir::SelfParam, new_name: &str, diff --git a/src/tools/rust-analyzer/crates/ide/src/runnables.rs b/src/tools/rust-analyzer/crates/ide/src/runnables.rs index 8c2219860bdac..bec770ed99f16 100644 --- a/src/tools/rust-analyzer/crates/ide/src/runnables.rs +++ b/src/tools/rust-analyzer/crates/ide/src/runnables.rs @@ -35,7 +35,7 @@ pub enum TestId { } impl fmt::Display for TestId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TestId::Name(name) => name.fmt(f), TestId::Path(path) => path.fmt(f), @@ -219,7 +219,7 @@ pub(crate) fn related_tests( } fn find_related_tests( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, syntax: &SyntaxNode, position: FilePosition, search_scope: Option, @@ -259,7 +259,7 @@ fn find_related_tests( } fn find_related_tests_in_module( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, syntax: &SyntaxNode, fn_def: &ast::Fn, parent_module: &hir::Module, @@ -282,7 +282,7 @@ fn find_related_tests_in_module( find_related_tests(sema, syntax, fn_pos, Some(mod_scope), tests) } -fn as_test_runnable(sema: &Semantics, fn_def: &ast::Fn) -> Option { +fn as_test_runnable(sema: &Semantics<'_, RootDatabase>, fn_def: &ast::Fn) -> Option { if test_related_attribute(fn_def).is_some() { let function = sema.to_def(fn_def)?; runnable_fn(sema, function) @@ -291,7 +291,7 @@ fn as_test_runnable(sema: &Semantics, fn_def: &ast::Fn) -> Option< } } -fn parent_test_module(sema: &Semantics, fn_def: &ast::Fn) -> Option { +fn parent_test_module(sema: &Semantics<'_, RootDatabase>, fn_def: &ast::Fn) -> Option { fn_def.syntax().ancestors().find_map(|node| { let module = ast::Module::cast(node)?; let module = sema.to_def(&module)?; @@ -304,7 +304,10 @@ fn parent_test_module(sema: &Semantics, fn_def: &ast::Fn) -> Optio }) } -pub(crate) fn runnable_fn(sema: &Semantics, def: hir::Function) -> Option { +pub(crate) fn runnable_fn( + sema: &Semantics<'_, RootDatabase>, + def: hir::Function, +) -> Option { let func = def.source(sema.db)?; let name = def.name(sema.db).to_smol_str(); @@ -340,7 +343,10 @@ pub(crate) fn runnable_fn(sema: &Semantics, def: hir::Function) -> Some(Runnable { use_name_in_title: false, nav, kind, cfg }) } -pub(crate) fn runnable_mod(sema: &Semantics, def: hir::Module) -> Option { +pub(crate) fn runnable_mod( + sema: &Semantics<'_, RootDatabase>, + def: hir::Module, +) -> Option { if !has_test_function_or_multiple_test_submodules(sema, &def) { return None; } @@ -353,7 +359,10 @@ pub(crate) fn runnable_mod(sema: &Semantics, def: hir::Module) -> Some(Runnable { use_name_in_title: false, nav, kind: RunnableKind::TestMod { path }, cfg }) } -pub(crate) fn runnable_impl(sema: &Semantics, def: &hir::Impl) -> Option { +pub(crate) fn runnable_impl( + sema: &Semantics<'_, RootDatabase>, + def: &hir::Impl, +) -> Option { let attrs = def.attrs(sema.db); if !has_runnable_doc_test(&attrs) { return None; @@ -375,7 +384,7 @@ pub(crate) fn runnable_impl(sema: &Semantics, def: &hir::Impl) -> /// Creates a test mod runnable for outline modules at the top of their definition. fn runnable_mod_outline_definition( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, def: hir::Module, ) -> Option { if !has_test_function_or_multiple_test_submodules(sema, &def) { @@ -509,7 +518,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool { // We could create runnables for modules with number_of_test_submodules > 0, // but that bloats the runnables for no real benefit, since all tests can be run by the submodule already fn has_test_function_or_multiple_test_submodules( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, module: &hir::Module, ) -> bool { let mut number_of_test_submodules = 0; diff --git a/src/tools/rust-analyzer/crates/ide/src/signature_help.rs b/src/tools/rust-analyzer/crates/ide/src/signature_help.rs index 871c9951223aa..ba287d13aec1d 100644 --- a/src/tools/rust-analyzer/crates/ide/src/signature_help.rs +++ b/src/tools/rust-analyzer/crates/ide/src/signature_help.rs @@ -94,7 +94,7 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio } fn signature_help_for_call( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: SyntaxToken, ) -> Option { // Find the calling expression and its NameRef @@ -198,7 +198,7 @@ fn signature_help_for_call( } fn signature_help_for_generics( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: SyntaxToken, ) -> Option { let parent = token.parent()?; diff --git a/src/tools/rust-analyzer/crates/ide/src/static_index.rs b/src/tools/rust-analyzer/crates/ide/src/static_index.rs index 95a9635a065b9..d74b640415c76 100644 --- a/src/tools/rust-analyzer/crates/ide/src/static_index.rs +++ b/src/tools/rust-analyzer/crates/ide/src/static_index.rs @@ -173,7 +173,7 @@ impl StaticIndex<'_> { self.files.push(result); } - pub fn compute(analysis: &Analysis) -> StaticIndex { + pub fn compute(analysis: &Analysis) -> StaticIndex<'_> { let db = &*analysis.db; let work = all_modules(db).into_iter().filter(|module| { let file_id = module.definition_source(db).file_id.original_file(db); @@ -202,7 +202,7 @@ impl StaticIndex<'_> { } } -fn get_definition(sema: &Semantics, token: SyntaxToken) -> Option { +fn get_definition(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> Option { for token in sema.descend_into_macros(token) { let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions); if let Some(&[x]) = def.as_deref() { diff --git a/src/tools/rust-analyzer/crates/ide/src/status.rs b/src/tools/rust-analyzer/crates/ide/src/status.rs index ea2b7906e9eaa..3191870eb5e8f 100644 --- a/src/tools/rust-analyzer/crates/ide/src/status.rs +++ b/src/tools/rust-analyzer/crates/ide/src/status.rs @@ -75,7 +75,7 @@ struct FilesStats { } impl fmt::Display for FilesStats { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{} of files", self.size) } } @@ -101,7 +101,7 @@ pub(crate) struct SyntaxTreeStats { } impl fmt::Display for SyntaxTreeStats { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{} trees, {} preserved", self.total, self.retained) } } @@ -143,7 +143,7 @@ struct LibrarySymbolsStats { } impl fmt::Display for LibrarySymbolsStats { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{} of index symbols ({})", self.size, self.total) } } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs index b2f6d18553bb2..9fb6a302632e3 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs @@ -196,7 +196,7 @@ pub(crate) fn highlight( fn traverse( hl: &mut Highlights, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, file_id: FileId, root: &SyntaxNode, krate: hir::Crate, diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs index 788cbe9272308..fd3723ed45485 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs @@ -16,7 +16,7 @@ use crate::{ Highlight, HlMod, HlTag, }; -pub(super) fn token(sema: &Semantics, token: SyntaxToken) -> Option { +pub(super) fn token(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> Option { if let Some(comment) = ast::Comment::cast(token.clone()) { let h = HlTag::Comment; return Some(match comment.kind().doc { @@ -46,7 +46,7 @@ pub(super) fn token(sema: &Semantics, token: SyntaxToken) -> Optio } pub(super) fn name_like( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, krate: hir::Crate, bindings_shadow_count: &mut FxHashMap, syntactic_name_ref_highlighting: bool, @@ -79,7 +79,11 @@ pub(super) fn name_like( Some((highlight, binding_hash)) } -fn punctuation(sema: &Semantics, token: SyntaxToken, kind: SyntaxKind) -> Highlight { +fn punctuation( + sema: &Semantics<'_, RootDatabase>, + token: SyntaxToken, + kind: SyntaxKind, +) -> Highlight { let parent = token.parent(); let parent_kind = parent.as_ref().map_or(EOF, SyntaxNode::kind); match (kind, parent_kind) { @@ -151,7 +155,7 @@ fn punctuation(sema: &Semantics, token: SyntaxToken, kind: SyntaxK } fn keyword( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, token: SyntaxToken, kind: SyntaxKind, ) -> Option { @@ -190,7 +194,7 @@ fn keyword( } fn highlight_name_ref( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, krate: hir::Crate, bindings_shadow_count: &mut FxHashMap, binding_hash: &mut Option, @@ -274,7 +278,7 @@ fn highlight_name_ref( } fn highlight_name( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, bindings_shadow_count: &mut FxHashMap, binding_hash: &mut Option, krate: hir::Crate, @@ -321,7 +325,11 @@ fn calc_binding_hash(name: &hir::Name, shadow_count: u32) -> u64 { hash((name, shadow_count)) } -fn highlight_def(sema: &Semantics, krate: hir::Crate, def: Definition) -> Highlight { +fn highlight_def( + sema: &Semantics<'_, RootDatabase>, + krate: hir::Crate, + def: Definition, +) -> Highlight { let db = sema.db; let mut h = match def { Definition::Macro(m) => Highlight::new(HlTag::Symbol(m.kind(sema.db).into())), @@ -486,7 +494,7 @@ fn highlight_def(sema: &Semantics, krate: hir::Crate, def: Definit } fn highlight_method_call_by_name_ref( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, krate: hir::Crate, name_ref: &ast::NameRef, ) -> Option { @@ -495,7 +503,7 @@ fn highlight_method_call_by_name_ref( } fn highlight_method_call( - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, krate: hir::Crate, method_call: &ast::MethodCallExpr, ) -> Option { @@ -584,7 +592,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { fn highlight_name_ref_by_syntax( name: ast::NameRef, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, krate: hir::Crate, ) -> Highlight { let default = HlTag::UnresolvedReference; diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs index 8ac3c2da50b35..94d573a30b041 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs @@ -20,7 +20,7 @@ use crate::{ pub(super) fn ra_fixture( hl: &mut Highlights, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, literal: &ast::String, expanded: &ast::String, ) -> Option<()> { @@ -84,7 +84,7 @@ const RUSTDOC_FENCES: [&str; 2] = ["```", "~~~"]; /// Injection of syntax highlighting of doctests. pub(super) fn doc_comment( hl: &mut Highlights, - sema: &Semantics, + sema: &Semantics<'_, RootDatabase>, InFile { file_id: src_file_id, value: node }: InFile<&SyntaxNode>, ) { let (attributes, def) = match doc_attributes(sema, node) { diff --git a/src/tools/rust-analyzer/crates/limit/src/lib.rs b/src/tools/rust-analyzer/crates/limit/src/lib.rs index 12228e105c1cc..0e85193805ead 100644 --- a/src/tools/rust-analyzer/crates/limit/src/lib.rs +++ b/src/tools/rust-analyzer/crates/limit/src/lib.rs @@ -1,4 +1,5 @@ //! limit defines a struct to enforce limits. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::sync::atomic::AtomicUsize; diff --git a/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs b/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs index 3b857ad794df5..5020e9abaf315 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs @@ -522,7 +522,7 @@ fn match_loop_inner<'t>( fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { let mut src = TtIter::new(src); - let mut stack: SmallVec<[TtIter; 1]> = SmallVec::new(); + let mut stack: SmallVec<[TtIter<'_>; 1]> = SmallVec::new(); let mut res = Match::default(); let mut error_recover_item = None; @@ -656,7 +656,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { } } -fn match_leaf(lhs: &tt::Leaf, src: &mut TtIter) -> Result<(), ExpandError> { +fn match_leaf(lhs: &tt::Leaf, src: &mut TtIter<'_>) -> Result<(), ExpandError> { let rhs = src .expect_leaf() .map_err(|()| ExpandError::binding_error(format!("expected leaf: `{lhs}`")))?; @@ -677,7 +677,7 @@ fn match_leaf(lhs: &tt::Leaf, src: &mut TtIter) -> Result<(), ExpandError> { } } -fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult> { +fn match_meta_var(kind: &str, input: &mut TtIter<'_>) -> ExpandResult> { let fragment = match kind { "path" => parser::PrefixEntryPoint::Path, "ty" => parser::PrefixEntryPoint::Ty, diff --git a/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs b/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs index 93d29b6ffe962..7bcc84740f186 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs @@ -75,7 +75,7 @@ struct ExpandCtx<'a> { } fn expand_subtree( - ctx: &mut ExpandCtx, + ctx: &mut ExpandCtx<'_>, template: &MetaTemplate, delimiter: Option, arena: &mut Vec, @@ -127,7 +127,7 @@ fn expand_subtree( ExpandResult { value: tt::Subtree { delimiter, token_trees: tts }, err } } -fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult { +fn expand_var(ctx: &mut ExpandCtx<'_>, v: &SmolStr, id: tt::TokenId) -> ExpandResult { // We already handle $crate case in mbe parser debug_assert!(v != "crate"); @@ -163,7 +163,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult } fn expand_repeat( - ctx: &mut ExpandCtx, + ctx: &mut ExpandCtx<'_>, template: &MetaTemplate, kind: RepeatKind, separator: &Option, diff --git a/src/tools/rust-analyzer/crates/mbe/src/lib.rs b/src/tools/rust-analyzer/crates/mbe/src/lib.rs index 6402ceadaaae6..d5ba9bc9e4dba 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/lib.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/lib.rs @@ -5,6 +5,7 @@ //! //! The tes for this functionality live in another crate: //! `hir_def::macro_expansion_tests::mbe`. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod parser; mod expander; @@ -266,7 +267,7 @@ impl DeclarativeMacro { } impl Rule { - fn parse(src: &mut TtIter, expect_arrow: bool) -> Result { + fn parse(src: &mut TtIter<'_>, expect_arrow: bool) -> Result { let lhs = src.expect_subtree().map_err(|()| ParseError::expected("expected subtree"))?; if expect_arrow { src.expect_char('=').map_err(|()| ParseError::expected("expected `=`"))?; diff --git a/src/tools/rust-analyzer/crates/mbe/src/parser.rs b/src/tools/rust-analyzer/crates/mbe/src/parser.rs index df3872b3e6ab5..acb4be5846de1 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/parser.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/parser.rs @@ -194,7 +194,7 @@ fn is_boolean_literal(lit: &tt::Literal) -> bool { matches!(lit.text.as_str(), "true" | "false") } -fn parse_repeat(src: &mut TtIter) -> Result<(Option, RepeatKind), ParseError> { +fn parse_repeat(src: &mut TtIter<'_>) -> Result<(Option, RepeatKind), ParseError> { let mut separator = Separator::Puncts(SmallVec::new()); for tt in src { let tt = match tt { @@ -231,7 +231,7 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option, RepeatKind), Par Err(ParseError::InvalidRepeat) } -fn parse_metavar_expr(src: &mut TtIter) -> Result { +fn parse_metavar_expr(src: &mut TtIter<'_>) -> Result { let func = src.expect_ident()?; let args = src.expect_subtree()?; diff --git a/src/tools/rust-analyzer/crates/mbe/src/to_parser_input.rs b/src/tools/rust-analyzer/crates/mbe/src/to_parser_input.rs index 6faa147218e1d..783c3ca4a89f7 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/to_parser_input.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/to_parser_input.rs @@ -4,7 +4,7 @@ use syntax::{SyntaxKind, SyntaxKind::*, T}; use tt::buffer::TokenBuffer; -pub(crate) fn to_parser_input(buffer: &TokenBuffer) -> parser::Input { +pub(crate) fn to_parser_input(buffer: &TokenBuffer<'_>) -> parser::Input { let mut res = parser::Input::default(); let mut current = buffer.begin(); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar.rs b/src/tools/rust-analyzer/crates/parser/src/grammar.rs index 4efbf9a606e19..b7468329610a7 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar.rs @@ -50,36 +50,36 @@ pub(crate) mod entry { pub(crate) mod prefix { use super::*; - pub(crate) fn vis(p: &mut Parser) { + pub(crate) fn vis(p: &mut Parser<'_>) { let _ = opt_visibility(p, false); } - pub(crate) fn block(p: &mut Parser) { + pub(crate) fn block(p: &mut Parser<'_>) { expressions::block_expr(p); } - pub(crate) fn stmt(p: &mut Parser) { + pub(crate) fn stmt(p: &mut Parser<'_>) { expressions::stmt(p, expressions::Semicolon::Forbidden); } - pub(crate) fn pat(p: &mut Parser) { + pub(crate) fn pat(p: &mut Parser<'_>) { patterns::pattern_single(p); } - pub(crate) fn ty(p: &mut Parser) { + pub(crate) fn ty(p: &mut Parser<'_>) { types::type_(p); } - pub(crate) fn expr(p: &mut Parser) { + pub(crate) fn expr(p: &mut Parser<'_>) { let _ = expressions::expr(p); } - pub(crate) fn path(p: &mut Parser) { + pub(crate) fn path(p: &mut Parser<'_>) { let _ = paths::type_path(p); } - pub(crate) fn item(p: &mut Parser) { + pub(crate) fn item(p: &mut Parser<'_>) { items::item_or_macro(p, true); } // Parse a meta item , which excluded [], e.g : #[ MetaItem ] - pub(crate) fn meta_item(p: &mut Parser) { + pub(crate) fn meta_item(p: &mut Parser<'_>) { attributes::meta(p); } } @@ -87,14 +87,14 @@ pub(crate) mod entry { pub(crate) mod top { use super::*; - pub(crate) fn source_file(p: &mut Parser) { + pub(crate) fn source_file(p: &mut Parser<'_>) { let m = p.start(); p.eat(SHEBANG); items::mod_contents(p, false); m.complete(p, SOURCE_FILE); } - pub(crate) fn macro_stmts(p: &mut Parser) { + pub(crate) fn macro_stmts(p: &mut Parser<'_>) { let m = p.start(); while !p.at(EOF) { @@ -104,13 +104,13 @@ pub(crate) mod entry { m.complete(p, MACRO_STMTS); } - pub(crate) fn macro_items(p: &mut Parser) { + pub(crate) fn macro_items(p: &mut Parser<'_>) { let m = p.start(); items::mod_contents(p, false); m.complete(p, MACRO_ITEMS); } - pub(crate) fn pattern(p: &mut Parser) { + pub(crate) fn pattern(p: &mut Parser<'_>) { let m = p.start(); patterns::pattern_top(p); if p.at(EOF) { @@ -123,7 +123,7 @@ pub(crate) mod entry { m.complete(p, ERROR); } - pub(crate) fn type_(p: &mut Parser) { + pub(crate) fn type_(p: &mut Parser<'_>) { let m = p.start(); types::type_(p); if p.at(EOF) { @@ -136,7 +136,7 @@ pub(crate) mod entry { m.complete(p, ERROR); } - pub(crate) fn expr(p: &mut Parser) { + pub(crate) fn expr(p: &mut Parser<'_>) { let m = p.start(); expressions::expr(p); if p.at(EOF) { @@ -149,7 +149,7 @@ pub(crate) mod entry { m.complete(p, ERROR); } - pub(crate) fn meta_item(p: &mut Parser) { + pub(crate) fn meta_item(p: &mut Parser<'_>) { let m = p.start(); attributes::meta(p); if p.at(EOF) { @@ -168,7 +168,7 @@ pub(crate) fn reparser( node: SyntaxKind, first_child: Option, parent: Option, -) -> Option { +) -> Option)> { let res = match node { BLOCK_EXPR => expressions::block_expr, RECORD_FIELD_LIST => items::record_field_list, @@ -200,7 +200,7 @@ impl BlockLike { } } -fn opt_visibility(p: &mut Parser, in_tuple_field: bool) -> bool { +fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool { match p.current() { T![pub] => { let m = p.start(); @@ -262,7 +262,7 @@ fn opt_visibility(p: &mut Parser, in_tuple_field: bool) -> bool { } } -fn opt_rename(p: &mut Parser) { +fn opt_rename(p: &mut Parser<'_>) { if p.at(T![as]) { let m = p.start(); p.bump(T![as]); @@ -273,7 +273,7 @@ fn opt_rename(p: &mut Parser) { } } -fn abi(p: &mut Parser) { +fn abi(p: &mut Parser<'_>) { assert!(p.at(T![extern])); let abi = p.start(); p.bump(T![extern]); @@ -281,7 +281,7 @@ fn abi(p: &mut Parser) { abi.complete(p, ABI); } -fn opt_ret_type(p: &mut Parser) -> bool { +fn opt_ret_type(p: &mut Parser<'_>) -> bool { if p.at(T![->]) { let m = p.start(); p.bump(T![->]); @@ -293,7 +293,7 @@ fn opt_ret_type(p: &mut Parser) -> bool { } } -fn name_r(p: &mut Parser, recovery: TokenSet) { +fn name_r(p: &mut Parser<'_>, recovery: TokenSet) { if p.at(IDENT) { let m = p.start(); p.bump(IDENT); @@ -303,11 +303,11 @@ fn name_r(p: &mut Parser, recovery: TokenSet) { } } -fn name(p: &mut Parser) { +fn name(p: &mut Parser<'_>) { name_r(p, TokenSet::EMPTY); } -fn name_ref(p: &mut Parser) { +fn name_ref(p: &mut Parser<'_>) { if p.at(IDENT) { let m = p.start(); p.bump(IDENT); @@ -317,21 +317,21 @@ fn name_ref(p: &mut Parser) { } } -fn name_ref_or_index(p: &mut Parser) { +fn name_ref_or_index(p: &mut Parser<'_>) { assert!(p.at(IDENT) || p.at(INT_NUMBER)); let m = p.start(); p.bump_any(); m.complete(p, NAME_REF); } -fn lifetime(p: &mut Parser) { +fn lifetime(p: &mut Parser<'_>) { assert!(p.at(LIFETIME_IDENT)); let m = p.start(); p.bump(LIFETIME_IDENT); m.complete(p, LIFETIME); } -fn error_block(p: &mut Parser, message: &str) { +fn error_block(p: &mut Parser<'_>, message: &str) { assert!(p.at(T!['{'])); let m = p.start(); p.error(message); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/attributes.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/attributes.rs index 1efffca515cb4..0cf6a16f86a57 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/attributes.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/attributes.rs @@ -1,18 +1,18 @@ use super::*; -pub(super) fn inner_attrs(p: &mut Parser) { +pub(super) fn inner_attrs(p: &mut Parser<'_>) { while p.at(T![#]) && p.nth(1) == T![!] { attr(p, true); } } -pub(super) fn outer_attrs(p: &mut Parser) { +pub(super) fn outer_attrs(p: &mut Parser<'_>) { while p.at(T![#]) { attr(p, false); } } -fn attr(p: &mut Parser, inner: bool) { +fn attr(p: &mut Parser<'_>, inner: bool) { assert!(p.at(T![#])); let attr = p.start(); @@ -34,7 +34,7 @@ fn attr(p: &mut Parser, inner: bool) { attr.complete(p, ATTR); } -pub(super) fn meta(p: &mut Parser) { +pub(super) fn meta(p: &mut Parser<'_>) { let meta = p.start(); paths::use_path(p); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/expressions.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/expressions.rs index b063c73a9d689..e7402104eb83f 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/expressions.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/expressions.rs @@ -14,17 +14,20 @@ pub(super) enum Semicolon { const EXPR_FIRST: TokenSet = LHS_FIRST; -pub(super) fn expr(p: &mut Parser) -> bool { +pub(super) fn expr(p: &mut Parser<'_>) -> bool { let r = Restrictions { forbid_structs: false, prefer_stmt: false }; expr_bp(p, None, r, 1).is_some() } -pub(super) fn expr_stmt(p: &mut Parser, m: Option) -> Option<(CompletedMarker, BlockLike)> { +pub(super) fn expr_stmt( + p: &mut Parser<'_>, + m: Option, +) -> Option<(CompletedMarker, BlockLike)> { let r = Restrictions { forbid_structs: false, prefer_stmt: true }; expr_bp(p, m, r, 1) } -fn expr_no_struct(p: &mut Parser) { +fn expr_no_struct(p: &mut Parser<'_>) { let r = Restrictions { forbid_structs: true, prefer_stmt: false }; expr_bp(p, None, r, 1); } @@ -33,12 +36,12 @@ fn expr_no_struct(p: &mut Parser) { /// It needs to be parsed with lower precedence than `&&`, so that /// `if let true = true && false` is parsed as `if (let true = true) && (true)` /// and not `if let true = (true && true)`. -fn expr_let(p: &mut Parser) { +fn expr_let(p: &mut Parser<'_>) { let r = Restrictions { forbid_structs: true, prefer_stmt: false }; expr_bp(p, None, r, 5); } -pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) { +pub(super) fn stmt(p: &mut Parser<'_>, semicolon: Semicolon) { if p.eat(T![;]) { return; } @@ -101,7 +104,7 @@ pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) { // test let_stmt // fn f() { let x: i32 = 92; } - fn let_stmt(p: &mut Parser, m: Marker, with_semi: Semicolon) { + fn let_stmt(p: &mut Parser<'_>, m: Marker, with_semi: Semicolon) { p.bump(T![let]); patterns::pattern(p); if p.at(T![:]) { @@ -138,7 +141,7 @@ pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) { } } -pub(super) fn expr_block_contents(p: &mut Parser) { +pub(super) fn expr_block_contents(p: &mut Parser<'_>) { attributes::inner_attrs(p); while !p.at(EOF) && !p.at(T!['}']) { @@ -170,7 +173,7 @@ struct Restrictions { /// /// See #[rustfmt::skip] -fn current_op(p: &Parser) -> (u8, SyntaxKind) { +fn current_op(p: &Parser<'_>) -> (u8, SyntaxKind) { const NOT_AN_OP: (u8, SyntaxKind) = (0, T![@]); match p.current() { T![|] if p.at(T![||]) => (3, T![||]), @@ -214,7 +217,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) { // Parses expression with binding power of at least bp. fn expr_bp( - p: &mut Parser, + p: &mut Parser<'_>, m: Option, mut r: Restrictions, bp: u8, @@ -287,7 +290,7 @@ fn expr_bp( const LHS_FIRST: TokenSet = atom::ATOM_EXPR_FIRST.union(TokenSet::new(&[T![&], T![*], T![!], T![.], T![-]])); -fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> { +fn lhs(p: &mut Parser<'_>, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> { let m; let kind = match p.current() { // test ref_expr @@ -356,7 +359,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> } fn postfix_expr( - p: &mut Parser, + p: &mut Parser<'_>, mut lhs: CompletedMarker, // Calls are disallowed if the type is a block and we prefer statements because the call cannot be disambiguated from a tuple // E.g. `while true {break}();` is parsed as @@ -392,7 +395,7 @@ fn postfix_expr( return (lhs, block_like); fn postfix_dot_expr( - p: &mut Parser, + p: &mut Parser<'_>, lhs: CompletedMarker, ) -> Result { assert!(p.at(T![.])); @@ -428,7 +431,7 @@ fn postfix_expr( // let _ = f(::func()); // f(::func()); // } -fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { +fn call_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T!['('])); let m = lhs.precede(p); arg_list(p); @@ -439,7 +442,7 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // fn foo() { // x[1][2]; // } -fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { +fn index_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T!['['])); let m = lhs.precede(p); p.bump(T!['[']); @@ -453,7 +456,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // x.foo(); // y.bar::(1, 2,); // } -fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { +fn method_call_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth_at(2, T![::]))); let m = lhs.precede(p); p.bump_any(); @@ -471,7 +474,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // x.0.bar; // x.0(); // } -fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { +fn field_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![.])); let m = lhs.precede(p); p.bump(T![.]); @@ -490,7 +493,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // fn foo() { // x?; // } -fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { +fn try_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![?])); let m = lhs.precede(p); p.bump(T![?]); @@ -504,7 +507,7 @@ fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // 79 as i16 - 1; // 0x36 as u8 <= 0x37; // } -fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { +fn cast_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![as])); let m = lhs.precede(p); p.bump(T![as]); @@ -514,7 +517,7 @@ fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { m.complete(p, CAST_EXPR) } -fn arg_list(p: &mut Parser) { +fn arg_list(p: &mut Parser<'_>) { assert!(p.at(T!['('])); let m = p.start(); p.bump(T!['(']); @@ -541,7 +544,7 @@ fn arg_list(p: &mut Parser) { // let _ = ::a::; // let _ = format!(); // } -fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { +fn path_expr(p: &mut Parser<'_>, r: Restrictions) -> (CompletedMarker, BlockLike) { assert!(paths::is_path_start(p)); let m = p.start(); paths::expr_path(p); @@ -565,7 +568,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { // S { x, y: 32, ..Default::default() }; // TupleStruct { 0: 1 }; // } -pub(crate) fn record_expr_field_list(p: &mut Parser) { +pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/expressions/atom.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/expressions/atom.rs index 10e5d897e0781..99f42a2662348 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/expressions/atom.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/expressions/atom.rs @@ -24,7 +24,7 @@ pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[ BYTE_STRING, ]); -pub(crate) fn literal(p: &mut Parser) -> Option { +pub(crate) fn literal(p: &mut Parser<'_>) -> Option { if !p.at_ts(LITERAL_FIRST) { return None; } @@ -60,7 +60,10 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[T![let]]); -pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> { +pub(super) fn atom_expr( + p: &mut Parser<'_>, + r: Restrictions, +) -> Option<(CompletedMarker, BlockLike)> { if let Some(m) = literal(p) { return Some((m, BlockLike::NotBlock)); } @@ -169,7 +172,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar // (1); // (1,); // } -fn tuple_expr(p: &mut Parser) -> CompletedMarker { +fn tuple_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T!['('])); let m = p.start(); p.expect(T!['(']); @@ -201,7 +204,7 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { // [1, 2,]; // [1; 2]; // } -fn array_expr(p: &mut Parser) -> CompletedMarker { +fn array_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T!['['])); let m = p.start(); @@ -248,7 +251,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker { // for<'a> || {}; // for<'a> move || {}; // } -fn closure_expr(p: &mut Parser) -> CompletedMarker { +fn closure_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(match p.current() { T![static] | T![async] | T![move] | T![|] => true, T![for] => p.nth(1) == T![<], @@ -290,7 +293,7 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { // if S {}; // if { true } { } else { }; // } -fn if_expr(p: &mut Parser) -> CompletedMarker { +fn if_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![if])); let m = p.start(); p.bump(T![if]); @@ -313,7 +316,7 @@ fn if_expr(p: &mut Parser) -> CompletedMarker { // 'b: while true {} // 'c: for x in () {} // } -fn label(p: &mut Parser) { +fn label(p: &mut Parser<'_>) { assert!(p.at(LIFETIME_IDENT) && p.nth(1) == T![:]); let m = p.start(); lifetime(p); @@ -325,7 +328,7 @@ fn label(p: &mut Parser) { // fn foo() { // loop {}; // } -fn loop_expr(p: &mut Parser, m: Option) -> CompletedMarker { +fn loop_expr(p: &mut Parser<'_>, m: Option) -> CompletedMarker { assert!(p.at(T![loop])); let m = m.unwrap_or_else(|| p.start()); p.bump(T![loop]); @@ -339,7 +342,7 @@ fn loop_expr(p: &mut Parser, m: Option) -> CompletedMarker { // while let Some(x) = it.next() {}; // while { true } {}; // } -fn while_expr(p: &mut Parser, m: Option) -> CompletedMarker { +fn while_expr(p: &mut Parser<'_>, m: Option) -> CompletedMarker { assert!(p.at(T![while])); let m = m.unwrap_or_else(|| p.start()); p.bump(T![while]); @@ -352,7 +355,7 @@ fn while_expr(p: &mut Parser, m: Option) -> CompletedMarker { // fn foo() { // for x in [] {}; // } -fn for_expr(p: &mut Parser, m: Option) -> CompletedMarker { +fn for_expr(p: &mut Parser<'_>, m: Option) -> CompletedMarker { assert!(p.at(T![for])); let m = m.unwrap_or_else(|| p.start()); p.bump(T![for]); @@ -368,7 +371,7 @@ fn for_expr(p: &mut Parser, m: Option) -> CompletedMarker { // if let Some(_) = None && true {} // while 1 == 5 && (let None = None) {} // } -fn let_expr(p: &mut Parser) -> CompletedMarker { +fn let_expr(p: &mut Parser<'_>) -> CompletedMarker { let m = p.start(); p.bump(T![let]); patterns::pattern_top(p); @@ -384,7 +387,7 @@ fn let_expr(p: &mut Parser) -> CompletedMarker { // match { } { _ => () }; // match { S {} } {}; // } -fn match_expr(p: &mut Parser) -> CompletedMarker { +fn match_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![match])); let m = p.start(); p.bump(T![match]); @@ -397,7 +400,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker { m.complete(p, MATCH_EXPR) } -pub(crate) fn match_arm_list(p: &mut Parser) { +pub(crate) fn match_arm_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.eat(T!['{']); @@ -434,7 +437,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) { // | X => (), // }; // } -fn match_arm(p: &mut Parser) { +fn match_arm(p: &mut Parser<'_>) { let m = p.start(); // test match_arms_outer_attributes // fn foo() { @@ -482,7 +485,7 @@ fn match_arm(p: &mut Parser) { // _ if let foo = bar => (), // } // } -fn match_guard(p: &mut Parser) -> CompletedMarker { +fn match_guard(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![if])); let m = p.start(); p.bump(T![if]); @@ -495,7 +498,7 @@ fn match_guard(p: &mut Parser) -> CompletedMarker { // fn b() { let _ = 1; } // fn c() { 1; 2; } // fn d() { 1; 2 } -pub(crate) fn block_expr(p: &mut Parser) { +pub(crate) fn block_expr(p: &mut Parser<'_>) { if !p.at(T!['{']) { p.error("expected a block"); return; @@ -505,7 +508,7 @@ pub(crate) fn block_expr(p: &mut Parser) { m.complete(p, BLOCK_EXPR); } -fn stmt_list(p: &mut Parser) -> CompletedMarker { +fn stmt_list(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); @@ -519,7 +522,7 @@ fn stmt_list(p: &mut Parser) -> CompletedMarker { // return; // return 92; // } -fn return_expr(p: &mut Parser) -> CompletedMarker { +fn return_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![return])); let m = p.start(); p.bump(T![return]); @@ -533,7 +536,7 @@ fn return_expr(p: &mut Parser) -> CompletedMarker { // yield; // yield 1; // } -fn yield_expr(p: &mut Parser) -> CompletedMarker { +fn yield_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![yield])); let m = p.start(); p.bump(T![yield]); @@ -550,7 +553,7 @@ fn yield_expr(p: &mut Parser) -> CompletedMarker { // continue 'l; // } // } -fn continue_expr(p: &mut Parser) -> CompletedMarker { +fn continue_expr(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![continue])); let m = p.start(); p.bump(T![continue]); @@ -569,7 +572,7 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker { // break 'l 92; // } // } -fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { +fn break_expr(p: &mut Parser<'_>, r: Restrictions) -> CompletedMarker { assert!(p.at(T![break])); let m = p.start(); p.bump(T![break]); @@ -593,7 +596,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { // fn foo() { // let _ = try {}; // } -fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { +fn try_block_expr(p: &mut Parser<'_>, m: Option) -> CompletedMarker { assert!(p.at(T![try])); let m = m.unwrap_or_else(|| p.start()); // Special-case `try!` as macro. @@ -629,7 +632,7 @@ fn try_block_expr(p: &mut Parser, m: Option) -> CompletedMarker { // let y = (box 1i32, box 2i32); // let z = Foo(box 1i32, box 2i32); // } -fn box_expr(p: &mut Parser, m: Option) -> CompletedMarker { +fn box_expr(p: &mut Parser<'_>, m: Option) -> CompletedMarker { assert!(p.at(T![box])); let m = m.unwrap_or_else(|| p.start()); p.bump(T![box]); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/generic_args.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/generic_args.rs index 862d3b259feb6..c438943a00262 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/generic_args.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/generic_args.rs @@ -1,6 +1,6 @@ use super::*; -pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) { +pub(super) fn opt_generic_arg_list(p: &mut Parser<'_>, colon_colon_required: bool) { let m; if p.at(T![::]) && p.nth(2) == T![<] { m = p.start(); @@ -25,7 +25,7 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) { // test generic_arg // type T = S; -fn generic_arg(p: &mut Parser) { +fn generic_arg(p: &mut Parser<'_>) { match p.current() { LIFETIME_IDENT => lifetime_arg(p), T!['{'] | T![true] | T![false] | T![-] => const_arg(p), @@ -74,13 +74,13 @@ fn generic_arg(p: &mut Parser) { // test lifetime_arg // type T = S<'static>; -fn lifetime_arg(p: &mut Parser) { +fn lifetime_arg(p: &mut Parser<'_>) { let m = p.start(); lifetime(p); m.complete(p, LIFETIME_ARG); } -pub(super) fn const_arg_expr(p: &mut Parser) { +pub(super) fn const_arg_expr(p: &mut Parser<'_>) { // The tests in here are really for `const_arg`, which wraps the content // CONST_ARG. match p.current() { @@ -118,13 +118,13 @@ pub(super) fn const_arg_expr(p: &mut Parser) { // test const_arg // type T = S<92>; -pub(super) fn const_arg(p: &mut Parser) { +pub(super) fn const_arg(p: &mut Parser<'_>) { let m = p.start(); const_arg_expr(p); m.complete(p, CONST_ARG); } -fn type_arg(p: &mut Parser) { +fn type_arg(p: &mut Parser<'_>) { let m = p.start(); types::type_(p); m.complete(p, TYPE_ARG); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/generic_params.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/generic_params.rs index 78a75fad1cb69..6db28ef13239c 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/generic_params.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/generic_params.rs @@ -1,6 +1,6 @@ use super::*; -pub(super) fn opt_generic_param_list(p: &mut Parser) { +pub(super) fn opt_generic_param_list(p: &mut Parser<'_>) { if p.at(T![<]) { generic_param_list(p); } @@ -8,7 +8,7 @@ pub(super) fn opt_generic_param_list(p: &mut Parser) { // test generic_param_list // fn f() {} -fn generic_param_list(p: &mut Parser) { +fn generic_param_list(p: &mut Parser<'_>) { assert!(p.at(T![<])); let m = p.start(); p.bump(T![<]); @@ -23,7 +23,7 @@ fn generic_param_list(p: &mut Parser) { m.complete(p, GENERIC_PARAM_LIST); } -fn generic_param(p: &mut Parser) { +fn generic_param(p: &mut Parser<'_>) { let m = p.start(); // test generic_param_attribute // fn foo<#[lt_attr] 'a, #[t_attr] T>() {} @@ -41,7 +41,7 @@ fn generic_param(p: &mut Parser) { // test lifetime_param // fn f<'a: 'b>() {} -fn lifetime_param(p: &mut Parser, m: Marker) { +fn lifetime_param(p: &mut Parser<'_>, m: Marker) { assert!(p.at(LIFETIME_IDENT)); lifetime(p); if p.at(T![:]) { @@ -52,7 +52,7 @@ fn lifetime_param(p: &mut Parser, m: Marker) { // test type_param // fn f() {} -fn type_param(p: &mut Parser, m: Marker) { +fn type_param(p: &mut Parser<'_>, m: Marker) { assert!(p.at(IDENT)); name(p); if p.at(T![:]) { @@ -69,7 +69,7 @@ fn type_param(p: &mut Parser, m: Marker) { // test const_param // struct S; -fn const_param(p: &mut Parser, m: Marker) { +fn const_param(p: &mut Parser<'_>, m: Marker) { p.bump(T![const]); name(p); if p.at(T![:]) { @@ -94,7 +94,7 @@ fn const_param(p: &mut Parser, m: Marker) { m.complete(p, CONST_PARAM); } -fn lifetime_bounds(p: &mut Parser) { +fn lifetime_bounds(p: &mut Parser<'_>) { assert!(p.at(T![:])); p.bump(T![:]); while p.at(LIFETIME_IDENT) { @@ -107,18 +107,18 @@ fn lifetime_bounds(p: &mut Parser) { // test type_param_bounds // struct S; -pub(super) fn bounds(p: &mut Parser) { +pub(super) fn bounds(p: &mut Parser<'_>) { assert!(p.at(T![:])); p.bump(T![:]); bounds_without_colon(p); } -pub(super) fn bounds_without_colon(p: &mut Parser) { +pub(super) fn bounds_without_colon(p: &mut Parser<'_>) { let m = p.start(); bounds_without_colon_m(p, m); } -pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker { +pub(super) fn bounds_without_colon_m(p: &mut Parser<'_>, marker: Marker) -> CompletedMarker { while type_bound(p) { if !p.eat(T![+]) { break; @@ -127,7 +127,7 @@ pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> Complete marker.complete(p, TYPE_BOUND_LIST) } -fn type_bound(p: &mut Parser) -> bool { +fn type_bound(p: &mut Parser<'_>) -> bool { let m = p.start(); let has_paren = p.eat(T!['(']); match p.current() { @@ -172,7 +172,7 @@ fn type_bound(p: &mut Parser) -> bool { // Iterator::Item: 'a, // ::Item: 'a // {} -pub(super) fn opt_where_clause(p: &mut Parser) { +pub(super) fn opt_where_clause(p: &mut Parser<'_>) { if !p.at(T![where]) { return; } @@ -196,7 +196,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) { m.complete(p, WHERE_CLAUSE); - fn is_where_predicate(p: &mut Parser) -> bool { + fn is_where_predicate(p: &mut Parser<'_>) -> bool { match p.current() { LIFETIME_IDENT => true, T![impl] => false, @@ -205,7 +205,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) { } } -fn where_predicate(p: &mut Parser) { +fn where_predicate(p: &mut Parser<'_>) { let m = p.start(); match p.current() { LIFETIME_IDENT => { diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/items.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/items.rs index 7bfd9ef8c8a12..5e0951bf8b50a 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/items.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/items.rs @@ -17,7 +17,7 @@ use super::*; // foo::bar!(); // super::baz! {} // struct S; -pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { +pub(super) fn mod_contents(p: &mut Parser<'_>, stop_on_r_curly: bool) { attributes::inner_attrs(p); while !p.at(EOF) && !(p.at(T!['}']) && stop_on_r_curly) { item_or_macro(p, stop_on_r_curly); @@ -41,7 +41,7 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ T![;], ]); -pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { +pub(super) fn item_or_macro(p: &mut Parser<'_>, stop_on_r_curly: bool) { let m = p.start(); attributes::outer_attrs(p); @@ -84,7 +84,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { } /// Try to parse an item, completing `m` in case of success. -pub(super) fn opt_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { +pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> { // test_err pub_expr // fn foo() { pub 92; } let has_visibility = opt_visibility(p, false); @@ -214,7 +214,7 @@ pub(super) fn opt_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { Ok(()) } -fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { +fn opt_item_without_modifiers(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> { let la = p.nth(1); match p.current() { T![extern] if la == T![crate] => extern_crate(p, m), @@ -239,7 +239,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { // test extern_crate // extern crate foo; -fn extern_crate(p: &mut Parser, m: Marker) { +fn extern_crate(p: &mut Parser<'_>, m: Marker) { p.bump(T![extern]); p.bump(T![crate]); @@ -262,7 +262,7 @@ fn extern_crate(p: &mut Parser, m: Marker) { // test mod_item // mod a; -pub(crate) fn mod_item(p: &mut Parser, m: Marker) { +pub(crate) fn mod_item(p: &mut Parser<'_>, m: Marker) { p.bump(T![mod]); name(p); if p.at(T!['{']) { @@ -277,7 +277,7 @@ pub(crate) fn mod_item(p: &mut Parser, m: Marker) { // test type_alias // type Foo = Bar; -fn type_alias(p: &mut Parser, m: Marker) { +fn type_alias(p: &mut Parser<'_>, m: Marker) { p.bump(T![type]); name(p); @@ -305,7 +305,7 @@ fn type_alias(p: &mut Parser, m: Marker) { m.complete(p, TYPE_ALIAS); } -pub(crate) fn item_list(p: &mut Parser) { +pub(crate) fn item_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); @@ -314,7 +314,7 @@ pub(crate) fn item_list(p: &mut Parser) { m.complete(p, ITEM_LIST); } -pub(crate) fn extern_item_list(p: &mut Parser) { +pub(crate) fn extern_item_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); @@ -323,7 +323,7 @@ pub(crate) fn extern_item_list(p: &mut Parser) { m.complete(p, EXTERN_ITEM_LIST); } -fn macro_rules(p: &mut Parser, m: Marker) { +fn macro_rules(p: &mut Parser<'_>, m: Marker) { assert!(p.at_contextual_kw(T![macro_rules])); p.bump_remap(T![macro_rules]); p.expect(T![!]); @@ -358,7 +358,7 @@ fn macro_rules(p: &mut Parser, m: Marker) { // test macro_def // macro m($i:ident) {} -fn macro_def(p: &mut Parser, m: Marker) { +fn macro_def(p: &mut Parser<'_>, m: Marker) { p.expect(T![macro]); name_r(p, ITEM_RECOVERY_SET); if p.at(T!['{']) { @@ -382,7 +382,7 @@ fn macro_def(p: &mut Parser, m: Marker) { // test fn // fn foo() {} -fn fn_(p: &mut Parser, m: Marker) { +fn fn_(p: &mut Parser<'_>, m: Marker) { p.bump(T![fn]); name_r(p, ITEM_RECOVERY_SET); @@ -414,13 +414,13 @@ fn fn_(p: &mut Parser, m: Marker) { m.complete(p, FN); } -fn macro_call(p: &mut Parser) -> BlockLike { +fn macro_call(p: &mut Parser<'_>) -> BlockLike { assert!(paths::is_use_path_start(p)); paths::use_path(p); macro_call_after_excl(p) } -pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { +pub(super) fn macro_call_after_excl(p: &mut Parser<'_>) -> BlockLike { p.expect(T![!]); match p.current() { @@ -439,7 +439,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { } } -pub(crate) fn token_tree(p: &mut Parser) { +pub(crate) fn token_tree(p: &mut Parser<'_>) { let closing_paren_kind = match p.current() { T!['{'] => T!['}'], T!['('] => T![')'], diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/items/adt.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/items/adt.rs index 83b7ff0578669..e7d30516b9510 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/items/adt.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/items/adt.rs @@ -2,20 +2,20 @@ use super::*; // test struct_item // struct S {} -pub(super) fn strukt(p: &mut Parser, m: Marker) { +pub(super) fn strukt(p: &mut Parser<'_>, m: Marker) { p.bump(T![struct]); struct_or_union(p, m, true); } // test union_item // struct U { i: i32, f: f32 } -pub(super) fn union(p: &mut Parser, m: Marker) { +pub(super) fn union(p: &mut Parser<'_>, m: Marker) { assert!(p.at_contextual_kw(T![union])); p.bump_remap(T![union]); struct_or_union(p, m, false); } -fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { +fn struct_or_union(p: &mut Parser<'_>, m: Marker, is_struct: bool) { name_r(p, ITEM_RECOVERY_SET); generic_params::opt_generic_param_list(p); match p.current() { @@ -50,7 +50,7 @@ fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { m.complete(p, if is_struct { STRUCT } else { UNION }); } -pub(super) fn enum_(p: &mut Parser, m: Marker) { +pub(super) fn enum_(p: &mut Parser<'_>, m: Marker) { p.bump(T![enum]); name_r(p, ITEM_RECOVERY_SET); generic_params::opt_generic_param_list(p); @@ -63,7 +63,7 @@ pub(super) fn enum_(p: &mut Parser, m: Marker) { m.complete(p, ENUM); } -pub(crate) fn variant_list(p: &mut Parser) { +pub(crate) fn variant_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); @@ -80,7 +80,7 @@ pub(crate) fn variant_list(p: &mut Parser) { p.expect(T!['}']); m.complete(p, VARIANT_LIST); - fn variant(p: &mut Parser) { + fn variant(p: &mut Parser<'_>) { let m = p.start(); attributes::outer_attrs(p); if p.at(IDENT) { @@ -106,7 +106,7 @@ pub(crate) fn variant_list(p: &mut Parser) { // test record_field_list // struct S { a: i32, b: f32 } -pub(crate) fn record_field_list(p: &mut Parser) { +pub(crate) fn record_field_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); @@ -123,7 +123,7 @@ pub(crate) fn record_field_list(p: &mut Parser) { p.expect(T!['}']); m.complete(p, RECORD_FIELD_LIST); - fn record_field(p: &mut Parser) { + fn record_field(p: &mut Parser<'_>) { let m = p.start(); // test record_field_attrs // struct S { #[attr] f: f32 } @@ -141,7 +141,7 @@ pub(crate) fn record_field_list(p: &mut Parser) { } } -fn tuple_field_list(p: &mut Parser) { +fn tuple_field_list(p: &mut Parser<'_>) { assert!(p.at(T!['('])); let m = p.start(); p.bump(T!['(']); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/items/consts.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/items/consts.rs index 98064cd98ad6f..9549ec9b4005e 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/items/consts.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/items/consts.rs @@ -2,17 +2,17 @@ use super::*; // test const_item // const C: u32 = 92; -pub(super) fn konst(p: &mut Parser, m: Marker) { +pub(super) fn konst(p: &mut Parser<'_>, m: Marker) { p.bump(T![const]); const_or_static(p, m, true); } -pub(super) fn static_(p: &mut Parser, m: Marker) { +pub(super) fn static_(p: &mut Parser<'_>, m: Marker) { p.bump(T![static]); const_or_static(p, m, false); } -fn const_or_static(p: &mut Parser, m: Marker, is_const: bool) { +fn const_or_static(p: &mut Parser<'_>, m: Marker, is_const: bool) { p.eat(T![mut]); if is_const && p.eat(T![_]) { diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/items/traits.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/items/traits.rs index d6bb3b9b621fc..c982e2d564c90 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/items/traits.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/items/traits.rs @@ -2,7 +2,7 @@ use super::*; // test trait_item // trait T { fn new() -> Self; } -pub(super) fn trait_(p: &mut Parser, m: Marker) { +pub(super) fn trait_(p: &mut Parser<'_>, m: Marker) { p.bump(T![trait]); name_r(p, ITEM_RECOVERY_SET); @@ -44,7 +44,7 @@ pub(super) fn trait_(p: &mut Parser, m: Marker) { // test impl_item // impl S {} -pub(super) fn impl_(p: &mut Parser, m: Marker) { +pub(super) fn impl_(p: &mut Parser<'_>, m: Marker) { p.bump(T![impl]); if p.at(T![<]) && not_a_qualified_path(p) { generic_params::opt_generic_param_list(p); @@ -80,7 +80,7 @@ pub(super) fn impl_(p: &mut Parser, m: Marker) { // fn foo() {} // fn bar(&self) {} // } -pub(crate) fn assoc_item_list(p: &mut Parser) { +pub(crate) fn assoc_item_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); @@ -102,7 +102,7 @@ pub(crate) fn assoc_item_list(p: &mut Parser) { // test impl_type_params // impl Bar {} -fn not_a_qualified_path(p: &Parser) -> bool { +fn not_a_qualified_path(p: &Parser<'_>) -> bool { // There's an ambiguity between generic parameters and qualified paths in impls. // If we see `<` it may start both, so we have to inspect some following tokens. // The following combinations can only start generics, @@ -131,7 +131,7 @@ fn not_a_qualified_path(p: &Parser) -> bool { // impl Trait1 for T {} // impl impl NotType {} // impl Trait2 for impl NotType {} -pub(crate) fn impl_type(p: &mut Parser) { +pub(crate) fn impl_type(p: &mut Parser<'_>) { if p.at(T![impl]) { p.error("expected trait or type"); return; diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/items/use_item.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/items/use_item.rs index ffb147b1fd2a7..69880b7946b69 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/items/use_item.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/items/use_item.rs @@ -2,7 +2,7 @@ use super::*; // test use_item // use std::collections; -pub(super) fn use_(p: &mut Parser, m: Marker) { +pub(super) fn use_(p: &mut Parser<'_>, m: Marker) { p.bump(T![use]); use_tree(p, true); p.expect(T![;]); @@ -11,7 +11,7 @@ pub(super) fn use_(p: &mut Parser, m: Marker) { // test use_tree // use outer::tree::{inner::tree}; -fn use_tree(p: &mut Parser, top_level: bool) { +fn use_tree(p: &mut Parser<'_>, top_level: bool) { let m = p.start(); match p.current() { // test use_tree_star @@ -78,7 +78,7 @@ fn use_tree(p: &mut Parser, top_level: bool) { // test use_tree_list // use {a, b, c}; -pub(crate) fn use_tree_list(p: &mut Parser) { +pub(crate) fn use_tree_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/params.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/params.rs index c2e633fdb0ba1..20e8e95f0662c 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/params.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/params.rs @@ -5,21 +5,21 @@ use super::*; // fn b(x: i32) {} // fn c(x: i32, ) {} // fn d(x: i32, y: ()) {} -pub(super) fn param_list_fn_def(p: &mut Parser) { +pub(super) fn param_list_fn_def(p: &mut Parser<'_>) { list_(p, Flavor::FnDef); } // test param_list_opt_patterns // fn foo)>(){} -pub(super) fn param_list_fn_trait(p: &mut Parser) { +pub(super) fn param_list_fn_trait(p: &mut Parser<'_>) { list_(p, Flavor::FnTrait); } -pub(super) fn param_list_fn_ptr(p: &mut Parser) { +pub(super) fn param_list_fn_ptr(p: &mut Parser<'_>) { list_(p, Flavor::FnPointer); } -pub(super) fn param_list_closure(p: &mut Parser) { +pub(super) fn param_list_closure(p: &mut Parser<'_>) { list_(p, Flavor::Closure); } @@ -31,7 +31,7 @@ enum Flavor { Closure, } -fn list_(p: &mut Parser, flavor: Flavor) { +fn list_(p: &mut Parser<'_>, flavor: Flavor) { use Flavor::*; let (bra, ket) = match flavor { @@ -87,7 +87,7 @@ fn list_(p: &mut Parser, flavor: Flavor) { const PARAM_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST); -fn param(p: &mut Parser, m: Marker, flavor: Flavor) { +fn param(p: &mut Parser<'_>, m: Marker, flavor: Flavor) { match flavor { // test param_list_vararg // extern "C" { fn printf(format: *const i8, ..., _: u8) -> i32; } @@ -146,7 +146,7 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) { m.complete(p, PARAM); } -fn variadic_param(p: &mut Parser) -> bool { +fn variadic_param(p: &mut Parser<'_>) -> bool { if p.at(T![:]) && p.nth_at(1, T![...]) { p.bump(T![:]); p.bump(T![...]); @@ -164,7 +164,7 @@ fn variadic_param(p: &mut Parser) -> bool { // fn d(&'a mut self, x: i32) {} // fn e(mut self) {} // } -fn opt_self_param(p: &mut Parser, m: Marker) -> Result<(), Marker> { +fn opt_self_param(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> { if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { p.eat(T![mut]); self_as_name(p); @@ -202,7 +202,7 @@ fn opt_self_param(p: &mut Parser, m: Marker) -> Result<(), Marker> { Ok(()) } -fn self_as_name(p: &mut Parser) { +fn self_as_name(p: &mut Parser<'_>) { let m = p.start(); p.bump(T![self]); m.complete(p, NAME); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/paths.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/paths.rs index b4a60574e51ed..f9efcef92a610 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/paths.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/paths.rs @@ -3,11 +3,11 @@ use super::*; pub(super) const PATH_FIRST: TokenSet = TokenSet::new(&[IDENT, T![self], T![super], T![crate], T![Self], T![:], T![<]]); -pub(super) fn is_path_start(p: &Parser) -> bool { +pub(super) fn is_path_start(p: &Parser<'_>) -> bool { is_use_path_start(p) || p.at(T![<]) || p.at(T![Self]) } -pub(super) fn is_use_path_start(p: &Parser) -> bool { +pub(super) fn is_use_path_start(p: &Parser<'_>) -> bool { match p.current() { IDENT | T![self] | T![super] | T![crate] => true, T![:] if p.at(T![::]) => true, @@ -15,19 +15,22 @@ pub(super) fn is_use_path_start(p: &Parser) -> bool { } } -pub(super) fn use_path(p: &mut Parser) { +pub(super) fn use_path(p: &mut Parser<'_>) { path(p, Mode::Use); } -pub(crate) fn type_path(p: &mut Parser) { +pub(crate) fn type_path(p: &mut Parser<'_>) { path(p, Mode::Type); } -pub(super) fn expr_path(p: &mut Parser) { +pub(super) fn expr_path(p: &mut Parser<'_>) { path(p, Mode::Expr); } -pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) -> CompletedMarker { +pub(crate) fn type_path_for_qualifier( + p: &mut Parser<'_>, + qual: CompletedMarker, +) -> CompletedMarker { path_for_qualifier(p, Mode::Type, qual) } @@ -38,14 +41,18 @@ enum Mode { Expr, } -fn path(p: &mut Parser, mode: Mode) { +fn path(p: &mut Parser<'_>, mode: Mode) { let path = p.start(); path_segment(p, mode, true); let qual = path.complete(p, PATH); path_for_qualifier(p, mode, qual); } -fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) -> CompletedMarker { +fn path_for_qualifier( + p: &mut Parser<'_>, + mode: Mode, + mut qual: CompletedMarker, +) -> CompletedMarker { loop { let use_tree = matches!(p.nth(2), T![*] | T!['{']); if p.at(T![::]) && !use_tree { @@ -60,7 +67,7 @@ fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) -> } } -fn path_segment(p: &mut Parser, mode: Mode, first: bool) { +fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) { let m = p.start(); // test qual_paths // type X = ::Output; @@ -107,7 +114,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { m.complete(p, PATH_SEGMENT); } -fn opt_path_type_args(p: &mut Parser, mode: Mode) { +fn opt_path_type_args(p: &mut Parser<'_>, mode: Mode) { match mode { Mode::Use => {} Mode::Type => { diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs index 1f622b32e5b1b..4cbf103061497 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/patterns.rs @@ -13,22 +13,22 @@ pub(super) const PATTERN_FIRST: TokenSet = T![.], ])); -pub(crate) fn pattern(p: &mut Parser) { +pub(crate) fn pattern(p: &mut Parser<'_>) { pattern_r(p, PAT_RECOVERY_SET); } /// Parses a pattern list separated by pipes `|`. -pub(super) fn pattern_top(p: &mut Parser) { +pub(super) fn pattern_top(p: &mut Parser<'_>) { pattern_top_r(p, PAT_RECOVERY_SET); } -pub(crate) fn pattern_single(p: &mut Parser) { +pub(crate) fn pattern_single(p: &mut Parser<'_>) { pattern_single_r(p, PAT_RECOVERY_SET); } /// Parses a pattern list separated by pipes `|` /// using the given `recovery_set`. -pub(super) fn pattern_top_r(p: &mut Parser, recovery_set: TokenSet) { +pub(super) fn pattern_top_r(p: &mut Parser<'_>, recovery_set: TokenSet) { p.eat(T![|]); pattern_r(p, recovery_set); } @@ -45,7 +45,7 @@ pub(super) fn pattern_top_r(p: &mut Parser, recovery_set: TokenSet) { // [_ | _,] => (), // } // } -fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { +fn pattern_r(p: &mut Parser<'_>, recovery_set: TokenSet) { let m = p.start(); pattern_single_r(p, recovery_set); @@ -59,7 +59,7 @@ fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { m.complete(p, OR_PAT); } -fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) { +fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) { if let Some(lhs) = atom_pat(p, recovery_set) { // test range_pat // fn main() { @@ -106,7 +106,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) { const PAT_RECOVERY_SET: TokenSet = TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,], T![=]]); -fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { +fn atom_pat(p: &mut Parser<'_>, recovery_set: TokenSet) -> Option { let m = match p.current() { T![box] => box_pat(p), T![ref] | T![mut] => ident_pat(p, true), @@ -139,7 +139,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { Some(m) } -fn is_literal_pat_start(p: &Parser) -> bool { +fn is_literal_pat_start(p: &Parser<'_>) -> bool { p.at(T![-]) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER) || p.at_ts(expressions::LITERAL_FIRST) } @@ -153,7 +153,7 @@ fn is_literal_pat_start(p: &Parser) -> bool { // "hello" => (), // } // } -fn literal_pat(p: &mut Parser) -> CompletedMarker { +fn literal_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(is_literal_pat_start(p)); let m = p.start(); if p.at(T![-]) { @@ -170,7 +170,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker { // let Bar { .. } = (); // let Bar(..) = (); // } -fn path_or_macro_pat(p: &mut Parser) -> CompletedMarker { +fn path_or_macro_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(paths::is_path_start(p)); let m = p.start(); paths::expr_path(p); @@ -203,7 +203,7 @@ fn path_or_macro_pat(p: &mut Parser) -> CompletedMarker { // let S(_,) = (); // let S(_, .. , x) = (); // } -fn tuple_pat_fields(p: &mut Parser) { +fn tuple_pat_fields(p: &mut Parser<'_>) { assert!(p.at(T!['('])); p.bump(T!['(']); pat_list(p, T![')']); @@ -216,7 +216,7 @@ fn tuple_pat_fields(p: &mut Parser) { // let S { x: 1 } = (); // let S { #[cfg(any())] x: 1 } = (); // } -fn record_pat_field(p: &mut Parser) { +fn record_pat_field(p: &mut Parser<'_>) { match p.current() { IDENT | INT_NUMBER if p.nth(1) == T![:] => { name_ref_or_index(p); @@ -244,7 +244,7 @@ fn record_pat_field(p: &mut Parser) { // let S { h: _, } = (); // let S { #[cfg(any())] .. } = (); // } -fn record_pat_field_list(p: &mut Parser) { +fn record_pat_field_list(p: &mut Parser<'_>) { assert!(p.at(T!['{'])); let m = p.start(); p.bump(T!['{']); @@ -277,7 +277,7 @@ fn record_pat_field_list(p: &mut Parser) { // test placeholder_pat // fn main() { let _ = (); } -fn wildcard_pat(p: &mut Parser) -> CompletedMarker { +fn wildcard_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![_])); let m = p.start(); p.bump(T![_]); @@ -310,7 +310,7 @@ fn wildcard_pat(p: &mut Parser) -> CompletedMarker { // let [head, .., mid, tail @ ..] = (); // let [head, .., mid, .., cons] = (); // } -fn rest_pat(p: &mut Parser) -> CompletedMarker { +fn rest_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![..])); let m = p.start(); p.bump(T![..]); @@ -322,7 +322,7 @@ fn rest_pat(p: &mut Parser) -> CompletedMarker { // let &a = (); // let &mut b = (); // } -fn ref_pat(p: &mut Parser) -> CompletedMarker { +fn ref_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![&])); let m = p.start(); p.bump(T![&]); @@ -338,7 +338,7 @@ fn ref_pat(p: &mut Parser) -> CompletedMarker { // let (..) = (); // let () = (); // } -fn tuple_pat(p: &mut Parser) -> CompletedMarker { +fn tuple_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T!['('])); let m = p.start(); p.bump(T!['(']); @@ -368,7 +368,7 @@ fn tuple_pat(p: &mut Parser) -> CompletedMarker { // fn main() { // let [a, b, ..] = []; // } -fn slice_pat(p: &mut Parser) -> CompletedMarker { +fn slice_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T!['['])); let m = p.start(); p.bump(T!['[']); @@ -377,7 +377,7 @@ fn slice_pat(p: &mut Parser) -> CompletedMarker { m.complete(p, SLICE_PAT) } -fn pat_list(p: &mut Parser, ket: SyntaxKind) { +fn pat_list(p: &mut Parser<'_>, ket: SyntaxKind) { while !p.at(EOF) && !p.at(ket) { if !p.at_ts(PATTERN_FIRST) { p.error("expected a pattern"); @@ -400,7 +400,7 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) { // let e @ _ = (); // let ref mut f @ g @ _ = (); // } -fn ident_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { +fn ident_pat(p: &mut Parser<'_>, with_at: bool) -> CompletedMarker { assert!(matches!(p.current(), T![ref] | T![mut] | IDENT)); let m = p.start(); p.eat(T![ref]); @@ -418,7 +418,7 @@ fn ident_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { // let box Outer { box i, j: box Inner(box &x) } = (); // let box ref mut i = (); // } -fn box_pat(p: &mut Parser) -> CompletedMarker { +fn box_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![box])); let m = p.start(); p.bump(T![box]); @@ -431,7 +431,7 @@ fn box_pat(p: &mut Parser) -> CompletedMarker { // let const { 15 } = (); // let const { foo(); bar() } = (); // } -fn const_block_pat(p: &mut Parser) -> CompletedMarker { +fn const_block_pat(p: &mut Parser<'_>) -> CompletedMarker { assert!(p.at(T![const])); let m = p.start(); p.bump(T![const]); diff --git a/src/tools/rust-analyzer/crates/parser/src/grammar/types.rs b/src/tools/rust-analyzer/crates/parser/src/grammar/types.rs index 46db487d02c0c..5c6e18fee8bff 100644 --- a/src/tools/rust-analyzer/crates/parser/src/grammar/types.rs +++ b/src/tools/rust-analyzer/crates/parser/src/grammar/types.rs @@ -25,15 +25,15 @@ const TYPE_RECOVERY_SET: TokenSet = TokenSet::new(&[ T![pub], ]); -pub(crate) fn type_(p: &mut Parser) { +pub(crate) fn type_(p: &mut Parser<'_>) { type_with_bounds_cond(p, true); } -pub(super) fn type_no_bounds(p: &mut Parser) { +pub(super) fn type_no_bounds(p: &mut Parser<'_>) { type_with_bounds_cond(p, false); } -fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { +fn type_with_bounds_cond(p: &mut Parser<'_>, allow_bounds: bool) { match p.current() { T!['('] => paren_or_tuple_type(p), T![!] => never_type(p), @@ -54,7 +54,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { } } -pub(super) fn ascription(p: &mut Parser) { +pub(super) fn ascription(p: &mut Parser<'_>) { assert!(p.at(T![:])); p.bump(T![:]); if p.at(T![=]) { @@ -66,7 +66,7 @@ pub(super) fn ascription(p: &mut Parser) { type_(p); } -fn paren_or_tuple_type(p: &mut Parser) { +fn paren_or_tuple_type(p: &mut Parser<'_>) { assert!(p.at(T!['('])); let m = p.start(); p.bump(T!['(']); @@ -101,14 +101,14 @@ fn paren_or_tuple_type(p: &mut Parser) { // test never_type // type Never = !; -fn never_type(p: &mut Parser) { +fn never_type(p: &mut Parser<'_>) { assert!(p.at(T![!])); let m = p.start(); p.bump(T![!]); m.complete(p, NEVER_TYPE); } -fn ptr_type(p: &mut Parser) { +fn ptr_type(p: &mut Parser<'_>) { assert!(p.at(T![*])); let m = p.start(); p.bump(T![*]); @@ -132,7 +132,7 @@ fn ptr_type(p: &mut Parser) { m.complete(p, PTR_TYPE); } -fn array_or_slice_type(p: &mut Parser) { +fn array_or_slice_type(p: &mut Parser<'_>) { assert!(p.at(T!['['])); let m = p.start(); p.bump(T!['[']); @@ -168,7 +168,7 @@ fn array_or_slice_type(p: &mut Parser) { // type A = &(); // type B = &'static (); // type C = &mut (); -fn ref_type(p: &mut Parser) { +fn ref_type(p: &mut Parser<'_>) { assert!(p.at(T![&])); let m = p.start(); p.bump(T![&]); @@ -182,7 +182,7 @@ fn ref_type(p: &mut Parser) { // test placeholder_type // type Placeholder = _; -fn infer_type(p: &mut Parser) { +fn infer_type(p: &mut Parser<'_>) { assert!(p.at(T![_])); let m = p.start(); p.bump(T![_]); @@ -194,7 +194,7 @@ fn infer_type(p: &mut Parser) { // type B = unsafe fn(); // type C = unsafe extern "C" fn(); // type D = extern "C" fn ( u8 , ... ) -> u8; -fn fn_ptr_type(p: &mut Parser) { +fn fn_ptr_type(p: &mut Parser<'_>) { let m = p.start(); p.eat(T![unsafe]); if p.at(T![extern]) { @@ -218,7 +218,7 @@ fn fn_ptr_type(p: &mut Parser) { m.complete(p, FN_PTR_TYPE); } -pub(super) fn for_binder(p: &mut Parser) { +pub(super) fn for_binder(p: &mut Parser<'_>) { assert!(p.at(T![for])); p.bump(T![for]); if p.at(T![<]) { @@ -232,7 +232,7 @@ pub(super) fn for_binder(p: &mut Parser) { // type A = for<'a> fn() -> (); // type B = for<'a> unsafe extern "C" fn(&'a ()) -> (); // type Obj = for<'a> PartialEq<&'a i32>; -pub(super) fn for_type(p: &mut Parser, allow_bounds: bool) { +pub(super) fn for_type(p: &mut Parser<'_>, allow_bounds: bool) { assert!(p.at(T![for])); let m = p.start(); for_binder(p); @@ -256,7 +256,7 @@ pub(super) fn for_type(p: &mut Parser, allow_bounds: bool) { // test impl_trait_type // type A = impl Iterator> + 'a; -fn impl_trait_type(p: &mut Parser) { +fn impl_trait_type(p: &mut Parser<'_>) { assert!(p.at(T![impl])); let m = p.start(); p.bump(T![impl]); @@ -266,7 +266,7 @@ fn impl_trait_type(p: &mut Parser) { // test dyn_trait_type // type A = dyn Iterator> + 'a; -fn dyn_trait_type(p: &mut Parser) { +fn dyn_trait_type(p: &mut Parser<'_>) { assert!(p.at(T![dyn])); let m = p.start(); p.bump(T![dyn]); @@ -279,14 +279,14 @@ fn dyn_trait_type(p: &mut Parser) { // type B = ::Foo; // type C = self::Foo; // type D = super::Foo; -pub(super) fn path_type(p: &mut Parser) { +pub(super) fn path_type(p: &mut Parser<'_>) { path_type_(p, true); } // test macro_call_type // type A = foo!(); // type B = crate::foo!(); -fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { +fn path_or_macro_type_(p: &mut Parser<'_>, allow_bounds: bool) { assert!(paths::is_path_start(p)); let r = p.start(); let m = p.start(); @@ -309,7 +309,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { } } -pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { +pub(super) fn path_type_(p: &mut Parser<'_>, allow_bounds: bool) { assert!(paths::is_path_start(p)); let m = p.start(); paths::type_path(p); @@ -325,7 +325,7 @@ pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { /// This turns a parsed PATH_TYPE or FOR_TYPE optionally into a DYN_TRAIT_TYPE /// with a TYPE_BOUND_LIST -fn opt_type_bounds_as_dyn_trait_type(p: &mut Parser, type_marker: CompletedMarker) { +fn opt_type_bounds_as_dyn_trait_type(p: &mut Parser<'_>, type_marker: CompletedMarker) { assert!(matches!( type_marker.kind(), SyntaxKind::PATH_TYPE | SyntaxKind::FOR_TYPE | SyntaxKind::MACRO_TYPE diff --git a/src/tools/rust-analyzer/crates/parser/src/lib.rs b/src/tools/rust-analyzer/crates/parser/src/lib.rs index cff4ca4ba294c..b617a654ff153 100644 --- a/src/tools/rust-analyzer/crates/parser/src/lib.rs +++ b/src/tools/rust-analyzer/crates/parser/src/lib.rs @@ -17,6 +17,7 @@ //! //! [`Parser`]: crate::parser::Parser #![allow(rustdoc::private_intra_doc_links)] +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod lexed_str; mod token_set; @@ -77,7 +78,7 @@ pub enum TopEntryPoint { impl TopEntryPoint { pub fn parse(&self, input: &Input) -> Output { - let entry_point: fn(&'_ mut parser::Parser) = match self { + let entry_point: fn(&'_ mut parser::Parser<'_>) = match self { TopEntryPoint::SourceFile => grammar::entry::top::source_file, TopEntryPoint::MacroStmts => grammar::entry::top::macro_stmts, TopEntryPoint::MacroItems => grammar::entry::top::macro_items, @@ -134,7 +135,7 @@ pub enum PrefixEntryPoint { impl PrefixEntryPoint { pub fn parse(&self, input: &Input) -> Output { - let entry_point: fn(&'_ mut parser::Parser) = match self { + let entry_point: fn(&'_ mut parser::Parser<'_>) = match self { PrefixEntryPoint::Vis => grammar::entry::prefix::vis, PrefixEntryPoint::Block => grammar::entry::prefix::block, PrefixEntryPoint::Stmt => grammar::entry::prefix::stmt, @@ -153,7 +154,7 @@ impl PrefixEntryPoint { } /// A parsing function for a specific braced-block. -pub struct Reparser(fn(&mut parser::Parser)); +pub struct Reparser(fn(&mut parser::Parser<'_>)); impl Reparser { /// If the node is a braced block, return the corresponding `Reparser`. diff --git a/src/tools/rust-analyzer/crates/parser/src/parser.rs b/src/tools/rust-analyzer/crates/parser/src/parser.rs index d4aecf9b446a3..48d8350e07ee8 100644 --- a/src/tools/rust-analyzer/crates/parser/src/parser.rs +++ b/src/tools/rust-analyzer/crates/parser/src/parser.rs @@ -259,7 +259,7 @@ impl Marker { /// Finishes the syntax tree node and assigns `kind` to it, /// and mark the create a `CompletedMarker` for possible future /// operation like `.precede()` to deal with forward_parent. - pub(crate) fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { + pub(crate) fn complete(mut self, p: &mut Parser<'_>, kind: SyntaxKind) -> CompletedMarker { self.bomb.defuse(); let idx = self.pos as usize; match &mut p.events[idx] { @@ -274,7 +274,7 @@ impl Marker { /// Abandons the syntax tree node. All its children /// are attached to its parent instead. - pub(crate) fn abandon(mut self, p: &mut Parser) { + pub(crate) fn abandon(mut self, p: &mut Parser<'_>) { self.bomb.defuse(); let idx = self.pos as usize; if idx == p.events.len() - 1 { @@ -309,7 +309,7 @@ impl CompletedMarker { /// Append a new `START` events as `[START, FINISH, NEWSTART]`, /// then mark `NEWSTART` as `START`'s parent with saving its relative /// distance to `NEWSTART` into forward_parent(=2 in this case); - pub(crate) fn precede(self, p: &mut Parser) -> Marker { + pub(crate) fn precede(self, p: &mut Parser<'_>) -> Marker { let new_pos = p.start(); let idx = self.pos as usize; match &mut p.events[idx] { @@ -322,7 +322,7 @@ impl CompletedMarker { } /// Extends this completed marker *to the left* up to `m`. - pub(crate) fn extend_to(self, p: &mut Parser, mut m: Marker) -> CompletedMarker { + pub(crate) fn extend_to(self, p: &mut Parser<'_>, mut m: Marker) -> CompletedMarker { m.bomb.defuse(); let idx = m.pos as usize; match &mut p.events[idx] { diff --git a/src/tools/rust-analyzer/crates/parser/src/shortcuts.rs b/src/tools/rust-analyzer/crates/parser/src/shortcuts.rs index b038d44fe08b2..4b805faddcba9 100644 --- a/src/tools/rust-analyzer/crates/parser/src/shortcuts.rs +++ b/src/tools/rust-analyzer/crates/parser/src/shortcuts.rs @@ -54,7 +54,7 @@ impl<'a> LexedStr<'a> { pub fn intersperse_trivia( &self, output: &crate::Output, - sink: &mut dyn FnMut(StrStep), + sink: &mut dyn FnMut(StrStep<'_>), ) -> bool { let mut builder = Builder { lexed: self, pos: 0, state: State::PendingEnter, sink }; diff --git a/src/tools/rust-analyzer/crates/paths/src/lib.rs b/src/tools/rust-analyzer/crates/paths/src/lib.rs index b4beb40e74698..fc697c0269da1 100644 --- a/src/tools/rust-analyzer/crates/paths/src/lib.rs +++ b/src/tools/rust-analyzer/crates/paths/src/lib.rs @@ -1,5 +1,6 @@ //! Thin wrappers around `std::path`, distinguishing between absolute and //! relative paths. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::{ borrow::Borrow, ffi::OsStr, diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs index 4a30168ca517b..25079507dccce 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs @@ -4,6 +4,7 @@ //! different implementations (e.g. wasm or dylib loading). And this crate //! is used to provide basic infrastructure for communication between two //! processes: Client (RA itself), Server (the external program) +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] pub mod msg; mod process; diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_58/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_58/mod.rs index dd3fd8b642274..41e2e45703d9a 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_58/mod.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_58/mod.rs @@ -25,7 +25,7 @@ impl From for PanicMessage { impl Abi { pub unsafe fn from_lib(lib: &Library, symbol_name: String) -> Result { - let macros: libloading::Symbol<&&[proc_macro::bridge::client::ProcMacro]> = + let macros: libloading::Symbol<'_, &&[proc_macro::bridge::client::ProcMacro]> = lib.get(symbol_name.as_bytes())?; Ok(Self { exported_macros: macros.to_vec() }) } diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_63/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_63/mod.rs index 590712fe6945a..c253b10994dd6 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_63/mod.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_63/mod.rs @@ -27,7 +27,7 @@ impl From for PanicMessage { impl Abi { pub unsafe fn from_lib(lib: &Library, symbol_name: String) -> Result { - let macros: libloading::Symbol<&&[proc_macro::bridge::client::ProcMacro]> = + let macros: libloading::Symbol<'_, &&[proc_macro::bridge::client::ProcMacro]> = lib.get(symbol_name.as_bytes())?; Ok(Self { exported_macros: macros.to_vec() }) } diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_64/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_64/mod.rs index a5c9a1a976e35..0ba4bbbef086e 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_64/mod.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_1_64/mod.rs @@ -27,7 +27,7 @@ impl From for PanicMessage { impl Abi { pub unsafe fn from_lib(lib: &Library, symbol_name: String) -> Result { - let macros: libloading::Symbol<&&[proc_macro::bridge::client::ProcMacro]> = + let macros: libloading::Symbol<'_, &&[proc_macro::bridge::client::ProcMacro]> = lib.get(symbol_name.as_bytes())?; Ok(Self { exported_macros: macros.to_vec() }) } diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs index 52693547e596f..1949084701eb7 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs @@ -9,6 +9,7 @@ //! RA than `proc-macro2` token stream. //! * By **copying** the whole rustc `lib_proc_macro` code, we are able to build this with `stable` //! rustc rather than `unstable`. (Although in general ABI compatibility is still an issue)… +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] #![allow(unreachable_pub)] mod dylib; diff --git a/src/tools/rust-analyzer/crates/proc-macro-test/build.rs b/src/tools/rust-analyzer/crates/proc-macro-test/build.rs index 767a790437e0f..ce49a87a8d927 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-test/build.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-test/build.rs @@ -29,7 +29,12 @@ fn main() { .arg(&target_dir) .output() .unwrap(); - assert!(output.status.success()); + if !output.status.success() { + println!("proc-macro-test failed to build, detailed output follows:"); + println!("=== nested cargo stdout ===\n{}\n", String::from_utf8_lossy(&output.stdout)); + println!("=== nested cargo stderr ===\n{}\n", String::from_utf8_lossy(&output.stderr)); + panic!("proc-macro-test failed to build"); + } let mut artifact_path = None; for message in Message::parse_stream(output.stdout.as_slice()) { diff --git a/src/tools/rust-analyzer/crates/proc-macro-test/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-test/src/lib.rs index 2edf23a634403..d68115887f045 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-test/src/lib.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-test/src/lib.rs @@ -1,4 +1,5 @@ //! Exports a few trivial procedural macros for testing. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] pub static PROC_MACRO_TEST_LOCATION: &str = include_str!(concat!(env!("OUT_DIR"), "/proc_macro_test_location.txt")); diff --git a/src/tools/rust-analyzer/crates/profile/src/lib.rs b/src/tools/rust-analyzer/crates/profile/src/lib.rs index bf9048e935c67..f547acc117e64 100644 --- a/src/tools/rust-analyzer/crates/profile/src/lib.rs +++ b/src/tools/rust-analyzer/crates/profile/src/lib.rs @@ -1,4 +1,5 @@ //! A collection of tools for profiling rust-analyzer. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod stop_watch; mod memory_usage; diff --git a/src/tools/rust-analyzer/crates/profile/src/memory_usage.rs b/src/tools/rust-analyzer/crates/profile/src/memory_usage.rs index 885fe1f1aa08c..ee882b4cb4c68 100644 --- a/src/tools/rust-analyzer/crates/profile/src/memory_usage.rs +++ b/src/tools/rust-analyzer/crates/profile/src/memory_usage.rs @@ -11,7 +11,7 @@ pub struct MemoryUsage { } impl fmt::Display for MemoryUsage { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.allocated.fmt(f) } } @@ -97,7 +97,7 @@ impl Bytes { } impl fmt::Display for Bytes { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let bytes = self.0; let mut value = bytes; let mut suffix = "b"; diff --git a/src/tools/rust-analyzer/crates/project-model/src/lib.rs b/src/tools/rust-analyzer/crates/project-model/src/lib.rs index 1caf6b59bcd87..fdb9856b95d5e 100644 --- a/src/tools/rust-analyzer/crates/project-model/src/lib.rs +++ b/src/tools/rust-analyzer/crates/project-model/src/lib.rs @@ -14,6 +14,7 @@ //! * Custom build steps (`build.rs` code generation and compilation of //! procedural macros). //! * Lowering of concrete model to a [`base_db::CrateGraph`] +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod manifest_path; mod cargo_workspace; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml index c37a0d17491d2..6998209a078e8 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml @@ -84,3 +84,4 @@ mbe = { path = "../mbe" } [features] jemalloc = ["jemallocator", "profile/jemalloc"] force-always-assert = ["always-assert/force"] +in-rust-tree = [] diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs index db00029da291f..0b69f75bc0db0 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs @@ -109,7 +109,7 @@ where fn format_event( &self, ctx: &FmtContext<'_, S, N>, - mut writer: Writer, + mut writer: Writer<'_>, event: &Event<'_>, ) -> fmt::Result { // Write level and target diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs index 45a3a23554884..45c68bbcac541 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs @@ -1,6 +1,7 @@ //! Driver for rust-analyzer. //! //! Based on cli flags, either spawns an LSP server, or runs a batch analysis +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod logger; mod rustc_wrapper; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index 8fa9df4e69a01..ac0fdf85a774e 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -1277,7 +1277,7 @@ macro_rules! create_bool_or_string_de { impl<'de> serde::de::Visitor<'de> for V { type Value = (); - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str(concat!( stringify!($bool), " or \"", @@ -1344,7 +1344,7 @@ macro_rules! named_unit_variant { struct V; impl<'de> serde::de::Visitor<'de> for V { type Value = (); - fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(concat!("\"", stringify!($variant), "\"")) } fn visit_str(self, value: &str) -> Result { @@ -1405,7 +1405,7 @@ where impl<'de> serde::de::Visitor<'de> for SingleOrVec { type Value = Vec; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("string or array of strings") } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/diff.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/diff.rs index 231be58077834..3fcfb4a1b08aa 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/diff.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/diff.rs @@ -7,7 +7,7 @@ pub(crate) fn diff(left: &str, right: &str) -> TextEdit { textedit_from_chunks(chunks) } -fn textedit_from_chunks(chunks: Vec) -> TextEdit { +fn textedit_from_chunks(chunks: Vec>) -> TextEdit { let mut builder = TextEdit::builder(); let mut pos = TextSize::default(); diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs index e04df7dea4218..31370ce160dd5 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs @@ -8,6 +8,7 @@ //! //! The `cli` submodule implements some batch-processing analysis, primarily as //! a debugging aid. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] pub mod cli; @@ -70,7 +71,7 @@ impl LspError { } impl fmt::Display for LspError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Language Server request failed with {}. ({})", self.code, self.message) } } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs index 0579cae4ed0d9..5845cf712c899 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs @@ -75,8 +75,8 @@ pub(crate) enum PrimeCachesProgress { } impl fmt::Debug for Event { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let debug_verbose_not = |not: &Notification, f: &mut fmt::Formatter| { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let debug_verbose_not = |not: &Notification, f: &mut fmt::Formatter<'_>| { f.debug_struct("Notification").field("method", ¬.method).finish() }; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs index 884224960f515..7f8e1558e03ad 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs @@ -7,6 +7,7 @@ //! In particular, it's fine *not* to test that client & server agree on //! specific JSON shapes here -- there's little value in such tests, as we can't //! be sure without a real client anyway. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod sourcegen; mod tidy; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs index 2415abc1d82a7..4fa88c3c6da11 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs @@ -26,7 +26,7 @@ pub(crate) struct Project<'a> { } impl<'a> Project<'a> { - pub(crate) fn with_fixture(fixture: &str) -> Project { + pub(crate) fn with_fixture(fixture: &str) -> Project<'_> { Project { fixture, tmp_dir: None, diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs index 1d666fdf0f3d1..63337214cd621 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs @@ -142,6 +142,7 @@ fn check_cargo_toml(path: &Path, text: String) { } } +#[cfg(not(feature = "in-rust-tree"))] #[test] fn check_merge_commits() { let sh = &Shell::new().unwrap(); diff --git a/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs b/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs index 2972fc45f84b0..48917e41e2b02 100644 --- a/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs +++ b/src/tools/rust-analyzer/crates/sourcegen/src/lib.rs @@ -5,6 +5,7 @@ //! output. See `sourcegen_` tests in various crates. //! //! This crate contains utilities to make this kind of source-gen easy. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::{ fmt, fs, mem, diff --git a/src/tools/rust-analyzer/crates/stdx/src/lib.rs b/src/tools/rust-analyzer/crates/stdx/src/lib.rs index 66fa25ec2318b..4a10a8ff90ce7 100644 --- a/src/tools/rust-analyzer/crates/stdx/src/lib.rs +++ b/src/tools/rust-analyzer/crates/stdx/src/lib.rs @@ -1,4 +1,5 @@ //! Missing batteries for standard libraries. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::process::Command; use std::{cmp::Ordering, ops, time::Instant}; use std::{io as sio, iter}; diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs index 2a41d0a701f57..b143df1f83f2a 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs @@ -432,7 +432,7 @@ impl NameLike { _ => None, } } - pub fn text(&self) -> TokenText { + pub fn text(&self) -> TokenText<'_> { match self { NameLike::NameRef(name_ref) => name_ref.text(), NameLike::Name(name) => name.text(), diff --git a/src/tools/rust-analyzer/crates/syntax/src/lib.rs b/src/tools/rust-analyzer/crates/syntax/src/lib.rs index e0309756b8a05..a5af20077f7e7 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/lib.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/lib.rs @@ -18,6 +18,7 @@ //! //! [RFC]: //! [Swift]: +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] #[allow(unused)] macro_rules! eprintln { diff --git a/src/tools/rust-analyzer/crates/syntax/src/syntax_error.rs b/src/tools/rust-analyzer/crates/syntax/src/syntax_error.rs index 940b7f0a242d4..dc6130bd6415c 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/syntax_error.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/syntax_error.rs @@ -38,7 +38,7 @@ impl SyntaxError { } impl fmt::Display for SyntaxError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } diff --git a/src/tools/rust-analyzer/crates/syntax/src/tests/ast_src.rs b/src/tools/rust-analyzer/crates/syntax/src/tests/ast_src.rs index 2f6932a1addda..cf5be1c30fba2 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/tests/ast_src.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/tests/ast_src.rs @@ -9,7 +9,7 @@ pub(crate) struct KindsSrc<'a> { pub(crate) nodes: &'a [&'a str], } -pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { +pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc { punct: &[ (";", "SEMICOLON"), (",", "COMMA"), diff --git a/src/tools/rust-analyzer/crates/syntax/src/token_text.rs b/src/tools/rust-analyzer/crates/syntax/src/token_text.rs index c8ba638c52311..913b24d42bcfd 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/token_text.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/token_text.rs @@ -42,7 +42,7 @@ impl AsRef for TokenText<'_> { } impl From> for String { - fn from(token_text: TokenText) -> Self { + fn from(token_text: TokenText<'_>) -> Self { token_text.as_str().into() } } @@ -53,7 +53,7 @@ impl PartialEq<&'_ str> for TokenText<'_> { } } impl PartialEq> for &'_ str { - fn eq(&self, other: &TokenText) -> bool { + fn eq(&self, other: &TokenText<'_>) -> bool { other == self } } @@ -63,12 +63,12 @@ impl PartialEq for TokenText<'_> { } } impl PartialEq> for String { - fn eq(&self, other: &TokenText) -> bool { + fn eq(&self, other: &TokenText<'_>) -> bool { other == self } } impl PartialEq for TokenText<'_> { - fn eq(&self, other: &TokenText) -> bool { + fn eq(&self, other: &TokenText<'_>) -> bool { self.as_str() == other.as_str() } } diff --git a/src/tools/rust-analyzer/crates/test-utils/src/lib.rs b/src/tools/rust-analyzer/crates/test-utils/src/lib.rs index 4438a12093a63..1ac975788f462 100644 --- a/src/tools/rust-analyzer/crates/test-utils/src/lib.rs +++ b/src/tools/rust-analyzer/crates/test-utils/src/lib.rs @@ -5,6 +5,7 @@ //! * Rich text comparison, which outputs a diff. //! * Extracting markup (mainly, `$0` markers) out of fixture strings. //! * marks (see the eponymous module). +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] pub mod bench_fixture; mod fixture; @@ -405,7 +406,7 @@ pub fn project_root() -> PathBuf { PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() } -pub fn format_diff(chunks: Vec) -> String { +pub fn format_diff(chunks: Vec>) -> String { let mut buf = String::new(); for chunk in chunks { let formatted = match chunk { diff --git a/src/tools/rust-analyzer/crates/text-edit/src/lib.rs b/src/tools/rust-analyzer/crates/text-edit/src/lib.rs index 922d24bc75499..7d27c800eca15 100644 --- a/src/tools/rust-analyzer/crates/text-edit/src/lib.rs +++ b/src/tools/rust-analyzer/crates/text-edit/src/lib.rs @@ -3,6 +3,7 @@ //! `rust-analyzer` never mutates text itself and only sends diffs to clients, //! so `TextEdit` is the ultimate representation of the work done by //! rust-analyzer. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use itertools::Itertools; use std::cmp::max; diff --git a/src/tools/rust-analyzer/crates/toolchain/src/lib.rs b/src/tools/rust-analyzer/crates/toolchain/src/lib.rs index 3b6886f5b576d..7410fa90986ef 100644 --- a/src/tools/rust-analyzer/crates/toolchain/src/lib.rs +++ b/src/tools/rust-analyzer/crates/toolchain/src/lib.rs @@ -1,4 +1,5 @@ //! Discovery of `cargo` & `rustc` executables. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::{env, iter, path::PathBuf}; pub fn cargo() -> PathBuf { diff --git a/src/tools/rust-analyzer/crates/tt/src/buffer.rs b/src/tools/rust-analyzer/crates/tt/src/buffer.rs index 1fa61c41ddbc5..69226bd4c4805 100644 --- a/src/tools/rust-analyzer/crates/tt/src/buffer.rs +++ b/src/tools/rust-analyzer/crates/tt/src/buffer.rs @@ -109,7 +109,7 @@ impl<'t> TokenBuffer<'t> { Cursor::create(self, EntryPtr(EntryId(0), 0)) } - fn entry(&self, ptr: &EntryPtr) -> Option<&Entry> { + fn entry(&self, ptr: &EntryPtr) -> Option<&Entry<'_>> { let id = ptr.0; self.buffers[id.0].get(ptr.1) } @@ -141,7 +141,7 @@ pub struct Cursor<'a> { } impl<'a> PartialEq for Cursor<'a> { - fn eq(&self, other: &Cursor) -> bool { + fn eq(&self, other: &Cursor<'_>) -> bool { self.ptr == other.ptr && std::ptr::eq(self.buffer, other.buffer) } } @@ -198,7 +198,7 @@ impl<'a> Cursor<'a> { } } - fn create(buffer: &'a TokenBuffer, ptr: EntryPtr) -> Cursor<'a> { + fn create(buffer: &'a TokenBuffer<'_>, ptr: EntryPtr) -> Cursor<'a> { Cursor { buffer, ptr } } diff --git a/src/tools/rust-analyzer/crates/tt/src/lib.rs b/src/tools/rust-analyzer/crates/tt/src/lib.rs index 0316b15038cec..2fda24bb78f94 100644 --- a/src/tools/rust-analyzer/crates/tt/src/lib.rs +++ b/src/tools/rust-analyzer/crates/tt/src/lib.rs @@ -1,6 +1,7 @@ //! `tt` crate defines a `TokenTree` data structure: this is the interface (both //! input and output) of macros. It closely mirrors `proc_macro` crate's //! `TokenTree`. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::fmt; use stdx::impl_from; @@ -153,7 +154,7 @@ impl fmt::Debug for Subtree { } impl fmt::Display for TokenTree { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TokenTree::Leaf(it) => fmt::Display::fmt(it, f), TokenTree::Subtree(it) => fmt::Display::fmt(it, f), @@ -162,7 +163,7 @@ impl fmt::Display for TokenTree { } impl fmt::Display for Subtree { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (l, r) = match self.delimiter_kind() { Some(DelimiterKind::Parenthesis) => ("(", ")"), Some(DelimiterKind::Brace) => ("{", "}"), @@ -190,7 +191,7 @@ impl fmt::Display for Subtree { } impl fmt::Display for Leaf { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Leaf::Ident(it) => fmt::Display::fmt(it, f), Leaf::Literal(it) => fmt::Display::fmt(it, f), @@ -200,19 +201,19 @@ impl fmt::Display for Leaf { } impl fmt::Display for Ident { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.text, f) } } impl fmt::Display for Literal { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.text, f) } } impl fmt::Display for Punct { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.char, f) } } diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index b5783cef21746..9fb334a89ff39 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -6,6 +6,7 @@ //! //! Hopefully, one day a reliable file watching/walking crate appears on //! crates.io, and we can reduce this to trivial glue code. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] use std::fs; use crossbeam_channel::{never, select, unbounded, Receiver, Sender}; diff --git a/src/tools/rust-analyzer/crates/vfs/src/lib.rs b/src/tools/rust-analyzer/crates/vfs/src/lib.rs index e075d752b7ff4..5e64ffa9d1fbf 100644 --- a/src/tools/rust-analyzer/crates/vfs/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs/src/lib.rs @@ -37,6 +37,7 @@ //! [`FileSet`]: file_set::FileSet //! [`Handle`]: loader::Handle //! [`Entries`]: loader::Entry +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod anchored_path; pub mod file_set; pub mod loader; diff --git a/src/tools/rust-analyzer/lib/la-arena/src/lib.rs b/src/tools/rust-analyzer/lib/la-arena/src/lib.rs index 9fe6d60623421..1d3c7a321cbe0 100644 --- a/src/tools/rust-analyzer/lib/la-arena/src/lib.rs +++ b/src/tools/rust-analyzer/lib/la-arena/src/lib.rs @@ -30,13 +30,13 @@ impl From for RawIdx { } impl fmt::Debug for RawIdx { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl fmt::Display for RawIdx { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } @@ -191,7 +191,7 @@ pub struct Arena { } impl fmt::Debug for Arena { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Arena").field("len", &self.len()).field("data", &self.data).finish() } } diff --git a/src/tools/rust-analyzer/xtask/src/main.rs b/src/tools/rust-analyzer/xtask/src/main.rs index df726dc23cbab..89e54bf60550d 100644 --- a/src/tools/rust-analyzer/xtask/src/main.rs +++ b/src/tools/rust-analyzer/xtask/src/main.rs @@ -7,6 +7,7 @@ //! //! This binary is integrated into the `cargo` command line by using an alias in //! `.cargo/config`. +#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod flags; mod install;