From aad66c7bf1b017980e490ba52a45e2e9373f24bc Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Mon, 10 Mar 2025 12:37:43 +0100 Subject: [PATCH 1/9] Fix 2024 syntax errors --- crates/hir-expand/src/builtin/derive_macro.rs | 26 +++++++++---------- crates/hir-expand/src/builtin/fn_macro.rs | 4 +-- crates/hir-expand/src/builtin/quote.rs | 2 +- crates/hir-ty/src/mir/lower.rs | 4 +-- crates/hir/src/lib.rs | 7 +++-- crates/hir/src/semantics.rs | 2 +- crates/ide-diagnostics/src/lib.rs | 3 ++- crates/ide/src/inlay_hints/lifetime.rs | 4 +-- crates/rust-analyzer/src/bin/main.rs | 6 +++-- .../rust-analyzer/tests/slow-tests/support.rs | 3 ++- crates/syntax/src/ast/node_ext.rs | 2 +- 11 files changed, 35 insertions(+), 28 deletions(-) diff --git a/crates/hir-expand/src/builtin/derive_macro.rs b/crates/hir-expand/src/builtin/derive_macro.rs index ff50ccef0f..149ab73ec5 100644 --- a/crates/hir-expand/src/builtin/derive_macro.rs +++ b/crates/hir-expand/src/builtin/derive_macro.rs @@ -117,7 +117,7 @@ impl VariantShape { quote! {span => #it : #mapped , } }); quote! {span => - #path { ##fields } + #path { # #fields } } } &VariantShape::Tuple(n) => { @@ -128,7 +128,7 @@ impl VariantShape { } }); quote! {span => - #path ( ##fields ) + #path ( # #fields ) } } VariantShape::Unit => path, @@ -523,7 +523,7 @@ fn expand_simple_derive_with_parsed( let name = info.name; quote! {invoc_span => - impl < ##params #extra_impl_params > #trait_path for #name < ##args > where ##where_block { #trait_body } + impl < # #params #extra_impl_params > #trait_path for #name < # #args > where # #where_block { #trait_body } } } @@ -572,7 +572,7 @@ fn clone_expand( quote! {span => fn clone(&self) -> Self { match self { - ##arms + # #arms } } } @@ -650,7 +650,7 @@ fn debug_expand( } }); quote! {span => - f.debug_struct(#name) ##for_fields .finish() + f.debug_struct(#name) # #for_fields .finish() } } VariantShape::Tuple(n) => { @@ -660,7 +660,7 @@ fn debug_expand( } }); quote! {span => - f.debug_tuple(#name) ##for_fields .finish() + f.debug_tuple(#name) # #for_fields .finish() } } VariantShape::Unit => quote! {span => @@ -703,7 +703,7 @@ fn debug_expand( quote! {span => fn fmt(&self, f: &mut #krate::fmt::Formatter) -> #krate::fmt::Result { match self { - ##arms + # #arms } } } @@ -736,7 +736,7 @@ fn hash_expand( let it = names.iter().map(|it| quote! {span => #it . hash(ra_expand_state); }); quote! {span => { - ##it + # #it } } }; let fat_arrow = fat_arrow(span); @@ -754,7 +754,7 @@ fn hash_expand( fn hash(&self, ra_expand_state: &mut H) { #check_discriminant match self { - ##arms + # #arms } } } @@ -803,7 +803,7 @@ fn partial_eq_expand( let t2 = tt::Ident::new(&format!("{}_other", first.sym), first.span); quote!(span =>#t1 .eq( #t2 )) }; - quote!(span =>#first ##rest) + quote!(span =>#first # #rest) } }; quote! {span => ( #pat1 , #pat2 ) #fat_arrow #body , } @@ -814,7 +814,7 @@ fn partial_eq_expand( quote! {span => fn eq(&self, other: &Self) -> bool { match (self, other) { - ##arms + # #arms _unused #fat_arrow false } } @@ -891,7 +891,7 @@ fn ord_expand( let fat_arrow = fat_arrow(span); let mut body = quote! {span => match (self, other) { - ##arms + # #arms _unused #fat_arrow #krate::cmp::Ordering::Equal } }; @@ -961,7 +961,7 @@ fn partial_ord_expand( right, quote! {span => match (self, other) { - ##arms + # #arms _unused #fat_arrow #krate::option::Option::Some(#krate::cmp::Ordering::Equal) } }, diff --git a/crates/hir-expand/src/builtin/fn_macro.rs b/crates/hir-expand/src/builtin/fn_macro.rs index b56ec3d04c..2fb1f96350 100644 --- a/crates/hir-expand/src/builtin/fn_macro.rs +++ b/crates/hir-expand/src/builtin/fn_macro.rs @@ -240,9 +240,9 @@ fn assert_expand( let dollar_crate = dollar_crate(span); let panic_args = rest.iter(); let mac = if use_panic_2021(db, span) { - quote! {call_site_span => #dollar_crate::panic::panic_2021!(##panic_args) } + quote! {call_site_span => #dollar_crate::panic::panic_2021!(# #panic_args) } } else { - quote! {call_site_span => #dollar_crate::panic!(##panic_args) } + quote! {call_site_span => #dollar_crate::panic!(# #panic_args) } }; let value = cond.value; let expanded = quote! {call_site_span =>{ diff --git a/crates/hir-expand/src/builtin/quote.rs b/crates/hir-expand/src/builtin/quote.rs index 4c8eb74486..9dd2b77b52 100644 --- a/crates/hir-expand/src/builtin/quote.rs +++ b/crates/hir-expand/src/builtin/quote.rs @@ -61,7 +61,7 @@ macro_rules! quote_impl__ { $crate::builtin::quote::__quote!($span $builder $($tail)*); }; - ($span:ident $builder:ident ## $first:ident $($tail:tt)* ) => {{ + ($span:ident $builder:ident # # $first:ident $($tail:tt)* ) => {{ ::std::iter::IntoIterator::into_iter($first).for_each(|it| $crate::builtin::quote::ToTokenTree::to_tokens(it, $span, $builder)); $crate::builtin::quote::__quote!($span $builder $($tail)*); }}; diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 102048b3f4..38924d7c95 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -518,7 +518,7 @@ impl<'ctx> MirLowerCtx<'ctx> { let Some(def) = self.owner.as_generic_def_id(self.db.upcast()) else { not_supported!("owner without generic def id"); }; - let gen = generics(self.db.upcast(), def); + let generics = generics(self.db.upcast(), def); let ty = self.expr_ty_without_adjust(expr_id); self.push_assignment( current, @@ -528,7 +528,7 @@ impl<'ctx> MirLowerCtx<'ctx> { ty, value: chalk_ir::ConstValue::BoundVar(BoundVar::new( DebruijnIndex::INNERMOST, - gen.type_or_const_param_idx(p.into()).ok_or( + generics.type_or_const_param_idx(p.into()).ok_or( MirLowerError::TypeError( "fail to lower const generic param", ), diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 9f91f155ea..caf00665a1 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -5261,7 +5261,7 @@ impl Type { /// Returns types that this type dereferences to (including this type itself). The returned /// iterator won't yield the same type more than once even if the deref chain contains a cycle. - pub fn autoderef(&self, db: &dyn HirDatabase) -> impl Iterator + '_ { + pub fn autoderef<'db>(&self, db: &'db dyn HirDatabase) -> impl Iterator + use<'_, 'db> { self.autoderef_(db).map(move |ty| self.derived(ty)) } @@ -5637,7 +5637,10 @@ impl Type { .map(Trait::from) } - pub fn as_impl_traits(&self, db: &dyn HirDatabase) -> Option> { + pub fn as_impl_traits( + &self, + db: &dyn HirDatabase, + ) -> Option + use<>> { self.ty.impl_trait_bounds(db).map(|it| { it.into_iter().filter_map(|pred| match pred.skip_binders() { hir_ty::WhereClause::Implemented(trait_ref) => { diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index b971b2e9f1..a1c0521a5e 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -2087,7 +2087,7 @@ impl SemanticsScope<'_> { ) } - pub fn resolve_mod_path(&self, path: &ModPath) -> impl Iterator { + pub fn resolve_mod_path(&self, path: &ModPath) -> impl Iterator + use<> { let items = self.resolver.resolve_module_path_in_items(self.db.upcast(), path); items.iter_items().map(|(item, _)| item.into()) } diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs index dc6fd1f5ea..c6f60a9a96 100644 --- a/crates/ide-diagnostics/src/lib.rs +++ b/crates/ide-diagnostics/src/lib.rs @@ -780,7 +780,8 @@ fn fill_lint_attrs( } }); - let all_matching_groups = lint_groups(&diag.code, edition) + let lints = lint_groups(&diag.code, edition); + let all_matching_groups = lints .iter() .filter_map(|lint_group| cached.get(lint_group)); let cached_severity = diff --git a/crates/ide/src/inlay_hints/lifetime.rs b/crates/ide/src/inlay_hints/lifetime.rs index 1fdd698991..7b0b3e19f2 100644 --- a/crates/ide/src/inlay_hints/lifetime.rs +++ b/crates/ide/src/inlay_hints/lifetime.rs @@ -268,13 +268,13 @@ fn hints_( ctx.lifetime_stacks.iter().flat_map(|it| it.iter()).cloned().zip(iter::repeat(0)).collect(); // allocate names let mut gen_idx_name = { - let mut gen = (0u8..).map(|idx| match idx { + let mut generic = (0u8..).map(|idx| match idx { idx if idx < 10 => SmolStr::from_iter(['\'', (idx + 48) as char]), idx => format_smolstr!("'{idx}"), }); let ctx = &*ctx; move || { - gen.by_ref() + generic.by_ref() .find(|s| ctx.lifetime_stacks.iter().flat_map(|it| it.iter()).all(|n| n != s)) .unwrap_or_default() } diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 1a9cdef256..f2e96197ec 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -123,13 +123,15 @@ fn setup_logging(log_file_flag: Option) -> anyhow::Result<()> { // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-syminitialize if let Ok(path) = env::current_exe() { if let Some(path) = path.parent() { - env::set_var("_NT_SYMBOL_PATH", path); + // SAFETY: This is safe because this is single-threaded. + unsafe { env::set_var("_NT_SYMBOL_PATH", path); } } } } if env::var("RUST_BACKTRACE").is_err() { - env::set_var("RUST_BACKTRACE", "short"); + // SAFETY: This is safe because this is single-threaded. + unsafe { env::set_var("RUST_BACKTRACE", "short"); } } let log_file = env::var("RA_LOG_FILE").ok().map(PathBuf::from).or(log_file_flag); diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index 1f52f366c5..8496068d67 100644 --- a/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs @@ -148,7 +148,8 @@ impl Project<'_> { let guard = CONFIG_DIR_LOCK.lock(); let test_dir = TestDir::new(); let value = test_dir.path().to_owned(); - env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); + // SAFETY: This is safe because this is single-threaded. + unsafe { env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); } (guard, test_dir) }) } else { diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 56f94b965e..2b330f0858 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -1066,7 +1066,7 @@ impl ast::GenericParamList { ast::GenericParam::TypeParam(_) | ast::GenericParam::ConstParam(_) => None, }) } - pub fn type_or_const_params(&self) -> impl Iterator { + pub fn type_or_const_params(&self) -> impl Iterator + use<> { self.generic_params().filter_map(|param| match param { ast::GenericParam::TypeParam(it) => Some(ast::TypeOrConstParam::Type(it)), ast::GenericParam::LifetimeParam(_) => None, From e70a9c5b9e50cdb3c5196ac95758396d7d1706c8 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Mon, 10 Mar 2025 12:41:24 +0100 Subject: [PATCH 2/9] rust-version = "1.85" --- crates/syntax/fuzz/Cargo.toml | 2 +- lib/la-arena/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/syntax/fuzz/Cargo.toml b/crates/syntax/fuzz/Cargo.toml index c2c6dac72d..4d639777c3 100644 --- a/crates/syntax/fuzz/Cargo.toml +++ b/crates/syntax/fuzz/Cargo.toml @@ -3,7 +3,7 @@ name = "syntax-fuzz" version = "0.0.1" publish = false edition = "2021" -rust-version = "1.78" +rust-version = "1.85" [package.metadata] cargo-fuzz = true diff --git a/lib/la-arena/Cargo.toml b/lib/la-arena/Cargo.toml index 589d026142..5fb53a7a55 100644 --- a/lib/la-arena/Cargo.toml +++ b/lib/la-arena/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/la-aren documentation = "https://docs.rs/la-arena" categories = ["data-structures", "memory-management", "rust-patterns"] edition = "2021" -rust-version = "1.56" +rust-version = "1.85" [lints] workspace = true From 70fc7b98c651422d258b6944648ec054b94fae92 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Mon, 10 Mar 2025 12:41:35 +0100 Subject: [PATCH 3/9] edition = "2024" --- Cargo.toml | 2 +- crates/proc-macro-srv/proc-macro-test/Cargo.toml | 2 +- crates/proc-macro-srv/proc-macro-test/imp/Cargo.toml | 2 +- crates/syntax/fuzz/Cargo.toml | 2 +- docs/book/book.toml | 2 +- lib/la-arena/Cargo.toml | 2 +- lib/line-index/Cargo.toml | 2 +- lib/lsp-server/Cargo.toml | 2 +- xtask/Cargo.toml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e9d70bea34..03ecc8f274 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] rust-version = "1.85" -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" authors = ["rust-analyzer team"] repository = "https://github.com/rust-lang/rust-analyzer" diff --git a/crates/proc-macro-srv/proc-macro-test/Cargo.toml b/crates/proc-macro-srv/proc-macro-test/Cargo.toml index 16fcc92962..2a5bfdd257 100644 --- a/crates/proc-macro-srv/proc-macro-test/Cargo.toml +++ b/crates/proc-macro-srv/proc-macro-test/Cargo.toml @@ -3,7 +3,7 @@ name = "proc-macro-test" version = "0.0.0" publish = false -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" [lib] diff --git a/crates/proc-macro-srv/proc-macro-test/imp/Cargo.toml b/crates/proc-macro-srv/proc-macro-test/imp/Cargo.toml index fb98d758a8..33b7c2bb0a 100644 --- a/crates/proc-macro-srv/proc-macro-test/imp/Cargo.toml +++ b/crates/proc-macro-srv/proc-macro-test/imp/Cargo.toml @@ -2,7 +2,7 @@ name = "proc-macro-test-impl" version = "0.0.0" license = "MIT OR Apache-2.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/crates/syntax/fuzz/Cargo.toml b/crates/syntax/fuzz/Cargo.toml index 4d639777c3..8910911ff0 100644 --- a/crates/syntax/fuzz/Cargo.toml +++ b/crates/syntax/fuzz/Cargo.toml @@ -2,7 +2,7 @@ name = "syntax-fuzz" version = "0.0.1" publish = false -edition = "2021" +edition = "2024" rust-version = "1.85" [package.metadata] diff --git a/docs/book/book.toml b/docs/book/book.toml index a6f6a6ed78..edf11fadf0 100644 --- a/docs/book/book.toml +++ b/docs/book/book.toml @@ -6,7 +6,7 @@ src = "src" title = "rust-analyzer" [rust] -edition = "2021" +edition = "2024" [output.html] edit-url-template = "https://github.com/rust-lang/rust-analyzer/edit/master/docs/book/{path}" diff --git a/lib/la-arena/Cargo.toml b/lib/la-arena/Cargo.toml index 5fb53a7a55..1c330e0e37 100644 --- a/lib/la-arena/Cargo.toml +++ b/lib/la-arena/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/la-arena" documentation = "https://docs.rs/la-arena" categories = ["data-structures", "memory-management", "rust-patterns"] -edition = "2021" +edition = "2024" rust-version = "1.85" [lints] diff --git a/lib/line-index/Cargo.toml b/lib/line-index/Cargo.toml index 14196ba3d0..f15c2e3937 100644 --- a/lib/line-index/Cargo.toml +++ b/lib/line-index/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.2" description = "Maps flat `TextSize` offsets to/from `(line, column)` representation." license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/line-index" -edition = "2021" +edition = "2024" [dependencies] text-size = "1.1.1" diff --git a/lib/lsp-server/Cargo.toml b/lib/lsp-server/Cargo.toml index 2fa3272e65..39b931561b 100644 --- a/lib/lsp-server/Cargo.toml +++ b/lib/lsp-server/Cargo.toml @@ -4,7 +4,7 @@ version = "0.7.8" description = "Generic LSP server scaffold." license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/lsp-server" -edition = "2021" +edition = "2024" [dependencies] log = "0.4.17" diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index ebd8903ad8..01a561dcb9 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -3,7 +3,7 @@ name = "xtask" version = "0.1.0" publish = false license = "MIT OR Apache-2.0" -edition = "2021" +edition = "2024" rust-version.workspace = true [dependencies] From 7f1912c74810490202675ebb8707256e8ae7e6e1 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Mon, 10 Mar 2025 12:41:51 +0100 Subject: [PATCH 4/9] cargo clippy --fix --- crates/hir-def/src/item_tree/lower.rs | 2 +- crates/hir-ty/src/builder.rs | 6 +++--- crates/hir-ty/src/infer/unify.rs | 4 ++-- crates/hir-ty/src/mir/eval.rs | 4 ++-- crates/hir-ty/src/mir/eval/shim/simd.rs | 2 +- crates/ide/src/signature_help.rs | 6 +++--- crates/rust-analyzer/src/lsp/to_proto.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index b0cc7ead8c..3c85d5bacb 100644 --- a/crates/hir-def/src/item_tree/lower.rs +++ b/crates/hir-def/src/item_tree/lower.rs @@ -932,7 +932,7 @@ impl<'a> Ctx<'a> { fn desugar_future_path(ctx: &mut LowerCtx<'_>, orig: TypeRefId) -> PathId { let path = path![core::future::Future]; let mut generic_args: Vec<_> = - std::iter::repeat(None).take(path.segments().len() - 1).collect(); + std::iter::repeat_n(None, path.segments().len() - 1).collect(); let binding = AssociatedTypeBinding { name: Name::new_symbol_root(sym::Output.clone()), args: None, diff --git a/crates/hir-ty/src/builder.rs b/crates/hir-ty/src/builder.rs index 76d9c60f6f..4c35db0c9b 100644 --- a/crates/hir-ty/src/builder.rs +++ b/crates/hir-ty/src/builder.rs @@ -263,7 +263,7 @@ impl TyBuilder<()> { .as_generic_def_id(db.upcast()) .map(|p| generics(db.upcast(), p).placeholder_subst(db)); // These represent resume type, yield type, and return type of coroutine. - let params = std::iter::repeat(ParamKind::Type).take(3).collect(); + let params = std::iter::repeat_n(ParamKind::Type, 3).collect(); TyBuilder::new((), params, parent_subst) } @@ -340,7 +340,7 @@ impl TyBuilder { pub struct Tuple(usize); impl TyBuilder { pub fn tuple(size: usize) -> TyBuilder { - TyBuilder::new(Tuple(size), iter::repeat(ParamKind::Type).take(size).collect(), None) + TyBuilder::new(Tuple(size), std::iter::repeat_n(ParamKind::Type, size).collect(), None) } pub fn build(self) -> Ty { @@ -356,7 +356,7 @@ impl TyBuilder { let elements = elements.into_iter(); let len = elements.len(); let mut b = - TyBuilder::new(Tuple(len), iter::repeat(ParamKind::Type).take(len).collect(), None); + TyBuilder::new(Tuple(len), std::iter::repeat_n(ParamKind::Type, len).collect(), None); for e in elements { b = b.push(e); } diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index e55fc0a9b8..6d80bfc38e 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -1,6 +1,6 @@ //! Unification and canonicalization logic. -use std::{fmt, iter, mem}; +use std::{fmt, mem}; use chalk_ir::{ cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, @@ -386,7 +386,7 @@ impl<'a> InferenceTable<'a> { } fn extend_type_variable_table(&mut self, to_index: usize) { let count = to_index - self.type_variable_table.len() + 1; - self.type_variable_table.extend(iter::repeat(TypeVariableFlags::default()).take(count)); + self.type_variable_table.extend(std::iter::repeat_n(TypeVariableFlags::default(), count)); } fn new_var(&mut self, kind: TyVariableKind, diverging: bool) -> Ty { diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index 45b4385568..be0a79f1dd 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -1119,7 +1119,7 @@ impl Evaluator<'_> { "Stack overflow. Tried to grow stack to {stack_size} bytes" ))); } - self.stack.extend(iter::repeat(0).take(stack_size)); + self.stack.extend(std::iter::repeat_n(0, stack_size)); Ok((locals, prev_stack_pointer)) } @@ -2122,7 +2122,7 @@ impl Evaluator<'_> { return Err(MirEvalError::Panic(format!("Memory allocation of {size} bytes failed"))); } let pos = self.heap.len(); - self.heap.extend(iter::repeat(0).take(size)); + self.heap.extend(std::iter::repeat_n(0, size)); Ok(Address::Heap(pos)) } diff --git a/crates/hir-ty/src/mir/eval/shim/simd.rs b/crates/hir-ty/src/mir/eval/shim/simd.rs index 829ed9efa2..54754045c9 100644 --- a/crates/hir-ty/src/mir/eval/shim/simd.rs +++ b/crates/hir-ty/src/mir/eval/shim/simd.rs @@ -127,7 +127,7 @@ impl Evaluator<'_> { Ordering::Greater => ["ge", "gt", "ne"].contains(&name), }; let result = if result { 255 } else { 0 }; - destination_bytes.extend(std::iter::repeat(result).take(dest_size)); + destination_bytes.extend(std::iter::repeat_n(result, dest_size)); } destination.write_from_bytes(self, &destination_bytes) diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs index 84912f6be6..ce3c4238b5 100644 --- a/crates/ide/src/signature_help.rs +++ b/crates/ide/src/signature_help.rs @@ -695,7 +695,7 @@ fn signature_help_for_tuple_pat_ish( } #[cfg(test)] mod tests { - use std::iter; + use expect_test::{expect, Expect}; use ide_db::FilePosition; @@ -742,11 +742,11 @@ mod tests { let gap = start.checked_sub(offset).unwrap_or_else(|| { panic!("parameter ranges out of order: {:?}", sig_help.parameter_ranges()) }); - rendered.extend(iter::repeat(' ').take(gap as usize)); + rendered.extend(std::iter::repeat_n(' ', gap as usize)); let param_text = &sig_help.signature[*range]; let width = param_text.chars().count(); // … let marker = if is_active { '^' } else { '-' }; - rendered.extend(iter::repeat(marker).take(width)); + rendered.extend(std::iter::repeat_n(marker, width)); offset += gap + u32::from(range.len()); } if !sig_help.parameter_ranges().is_empty() { diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index 70e567ec76..d9fab85df1 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -1549,7 +1549,7 @@ pub(crate) fn runnable( ); let cwd = match runnable.kind { - ide::RunnableKind::Bin { .. } => workspace_root.clone(), + ide::RunnableKind::Bin => workspace_root.clone(), _ => spec.cargo_toml.parent().to_owned(), }; From 87f837cec77ecb90d57f1d58db4a3ebea1609c8a Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Mon, 10 Mar 2025 12:41:59 +0100 Subject: [PATCH 5/9] fix clippy::doc_overindented_list_items --- crates/project-model/src/project_json.rs | 3 +-- crates/toolchain/src/lib.rs | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index 3c14e6e627..d78fa12d81 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -85,8 +85,7 @@ impl ProjectJson { /// /// * `manifest` - The path to the `rust-project.json`. /// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`) - /// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via - /// configuration. + /// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via configuration. pub fn new( manifest: Option, base: &AbsPath, diff --git a/crates/toolchain/src/lib.rs b/crates/toolchain/src/lib.rs index 325b94cc33..e3b30ff9cd 100644 --- a/crates/toolchain/src/lib.rs +++ b/crates/toolchain/src/lib.rs @@ -27,14 +27,14 @@ impl Tool { /// /// The current implementation checks three places for an executable to use: /// 1) `$CARGO_HOME/bin/` - /// where $CARGO_HOME defaults to ~/.cargo (see ) - /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. - /// It seems that this is a reasonable place to try for cargo, rustc, and rustup + /// where $CARGO_HOME defaults to ~/.cargo (see ) + /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. + /// It seems that this is a reasonable place to try for cargo, rustc, and rustup /// 2) Appropriate environment variable (erroring if this is set but not a usable executable) - /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc + /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc /// 3) $PATH/`` - /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the - /// first that exists + /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the + /// first that exists /// 4) If all else fails, we just try to use the executable name directly pub fn prefer_proxy(self) -> Utf8PathBuf { invoke(&[cargo_proxy, lookup_as_env_var, lookup_in_path], self.name()) @@ -44,14 +44,14 @@ impl Tool { /// /// The current implementation checks three places for an executable to use: /// 1) Appropriate environment variable (erroring if this is set but not a usable executable) - /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc + /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc /// 2) $PATH/`` - /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the - /// first that exists + /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the + /// first that exists /// 3) `$CARGO_HOME/bin/` - /// where $CARGO_HOME defaults to ~/.cargo (see ) - /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. - /// It seems that this is a reasonable place to try for cargo, rustc, and rustup + /// where $CARGO_HOME defaults to ~/.cargo (see ) + /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. + /// It seems that this is a reasonable place to try for cargo, rustc, and rustup /// 4) If all else fails, we just try to use the executable name directly pub fn path(self) -> Utf8PathBuf { invoke(&[lookup_as_env_var, lookup_in_path, cargo_proxy], self.name()) From 7535bb4661c74e2fd912bfd209802cac89e3f127 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Mon, 10 Mar 2025 12:42:27 +0100 Subject: [PATCH 6/9] cargo fmt --- crates/base-db/src/change.rs | 6 +- crates/base-db/src/input.rs | 84 +++++++++++-------- crates/base-db/src/lib.rs | 6 +- crates/cfg/src/lib.rs | 2 +- crates/cfg/src/tests.rs | 9 +- crates/hir-def/src/attr.rs | 14 ++-- crates/hir-def/src/builtin_type.rs | 2 +- crates/hir-def/src/data.rs | 14 ++-- crates/hir-def/src/data/adt.rs | 2 +- crates/hir-def/src/db.rs | 44 +++++----- crates/hir-def/src/dyn_map.rs | 6 +- crates/hir-def/src/expander.rs | 16 ++-- crates/hir-def/src/expr_store.rs | 6 +- crates/hir-def/src/expr_store/body.rs | 4 +- crates/hir-def/src/expr_store/lower.rs | 22 ++--- crates/hir-def/src/expr_store/lower/asm.rs | 2 +- crates/hir-def/src/expr_store/scope.rs | 10 +-- crates/hir-def/src/expr_store/tests.rs | 4 +- crates/hir-def/src/find_path.rs | 6 +- crates/hir-def/src/generics.rs | 12 +-- crates/hir-def/src/hir.rs | 10 +-- crates/hir-def/src/hir/format_args.rs | 2 +- crates/hir-def/src/hir/type_ref.rs | 22 ++--- crates/hir-def/src/import_map.rs | 16 ++-- crates/hir-def/src/item_scope.rs | 8 +- crates/hir-def/src/item_tree.rs | 6 +- crates/hir-def/src/item_tree/lower.rs | 11 ++- crates/hir-def/src/item_tree/tests.rs | 2 +- crates/hir-def/src/lang_item.rs | 18 ++-- crates/hir-def/src/lib.rs | 16 ++-- crates/hir-def/src/lower.rs | 2 +- .../hir-def/src/macro_expansion_tests/mod.rs | 6 +- crates/hir-def/src/nameres.rs | 8 +- crates/hir-def/src/nameres/assoc.rs | 10 +-- crates/hir-def/src/nameres/attr_resolution.rs | 6 +- crates/hir-def/src/nameres/collector.rs | 26 +++--- crates/hir-def/src/nameres/diagnostics.rs | 4 +- crates/hir-def/src/nameres/mod_resolution.rs | 4 +- crates/hir-def/src/nameres/path_resolution.rs | 14 ++-- crates/hir-def/src/nameres/tests.rs | 2 +- .../hir-def/src/nameres/tests/incremental.rs | 2 +- crates/hir-def/src/path.rs | 2 +- crates/hir-def/src/path/lower.rs | 2 +- crates/hir-def/src/path/tests.rs | 4 +- crates/hir-def/src/per_ns.rs | 8 +- crates/hir-def/src/resolver.rs | 26 +++--- crates/hir-def/src/src.rs | 6 +- crates/hir-def/src/test_db.rs | 6 +- crates/hir-def/src/visibility.rs | 2 +- crates/hir-expand/src/attrs.rs | 12 +-- crates/hir-expand/src/builtin.rs | 6 +- crates/hir-expand/src/builtin/attr_macro.rs | 4 +- crates/hir-expand/src/builtin/derive_macro.rs | 21 +++-- crates/hir-expand/src/builtin/fn_macro.rs | 33 ++++---- crates/hir-expand/src/builtin/quote.rs | 9 +- crates/hir-expand/src/cfg_process.rs | 10 +-- crates/hir-expand/src/db.rs | 23 +++-- crates/hir-expand/src/declarative.rs | 7 +- crates/hir-expand/src/eager.rs | 6 +- crates/hir-expand/src/files.rs | 9 +- crates/hir-expand/src/fixup.rs | 9 +- crates/hir-expand/src/hygiene.rs | 2 +- crates/hir-expand/src/lib.rs | 14 ++-- crates/hir-expand/src/mod_path.rs | 4 +- crates/hir-expand/src/name.rs | 2 +- .../src/prettify_macro_expansion_.rs | 2 +- crates/hir-expand/src/proc_macro.rs | 6 +- crates/hir-expand/src/span_map.rs | 2 +- crates/hir-ty/src/autoderef.rs | 4 +- crates/hir-ty/src/builder.rs | 12 +-- crates/hir-ty/src/chalk_db.rs | 19 +++-- crates/hir-ty/src/chalk_ext.rs | 12 +-- crates/hir-ty/src/consteval.rs | 11 +-- crates/hir-ty/src/consteval/tests.rs | 6 +- crates/hir-ty/src/db.rs | 16 ++-- crates/hir-ty/src/diagnostics.rs | 8 +- crates/hir-ty/src/diagnostics/decl_check.rs | 10 +-- .../src/diagnostics/decl_check/case_conv.rs | 2 +- crates/hir-ty/src/diagnostics/expr.rs | 8 +- crates/hir-ty/src/diagnostics/match_check.rs | 6 +- .../diagnostics/match_check/pat_analysis.rs | 10 +-- crates/hir-ty/src/diagnostics/unsafe_check.rs | 6 +- crates/hir-ty/src/display.rs | 26 +++--- crates/hir-ty/src/drop.rs | 12 +-- crates/hir-ty/src/dyn_compatibility.rs | 17 ++-- crates/hir-ty/src/generics.rs | 8 +- crates/hir-ty/src/infer.rs | 28 +++---- crates/hir-ty/src/infer/cast.rs | 6 +- crates/hir-ty/src/infer/closure.rs | 12 +-- crates/hir-ty/src/infer/coerce.rs | 6 +- crates/hir-ty/src/infer/diagnostics.rs | 4 +- crates/hir-ty/src/infer/expr.rs | 36 ++++---- crates/hir-ty/src/infer/mutability.rs | 6 +- crates/hir-ty/src/infer/pat.rs | 11 +-- crates/hir-ty/src/infer/path.rs | 11 +-- crates/hir-ty/src/infer/unify.rs | 22 ++--- crates/hir-ty/src/inhabitedness.rs | 6 +- crates/hir-ty/src/interner.rs | 12 +-- crates/hir-ty/src/lang_items.rs | 2 +- crates/hir-ty/src/layout.rs | 8 +- crates/hir-ty/src/layout/adt.rs | 6 +- crates/hir-ty/src/layout/tests.rs | 4 +- crates/hir-ty/src/lib.rs | 56 +++++-------- crates/hir-ty/src/lower.rs | 35 ++++---- crates/hir-ty/src/lower/path.rs | 12 +-- crates/hir-ty/src/mapping.rs | 6 +- crates/hir-ty/src/method_resolution.rs | 36 ++++---- crates/hir-ty/src/mir.rs | 16 ++-- crates/hir-ty/src/mir/borrowck.rs | 8 +- crates/hir-ty/src/mir/eval.rs | 43 +++++----- crates/hir-ty/src/mir/eval/shim.rs | 10 +-- crates/hir-ty/src/mir/eval/shim/simd.rs | 6 +- crates/hir-ty/src/mir/eval/tests.rs | 4 +- crates/hir-ty/src/mir/lower.rs | 36 ++++---- .../hir-ty/src/mir/lower/pattern_matching.rs | 10 +-- crates/hir-ty/src/mir/monomorphization.rs | 6 +- crates/hir-ty/src/mir/pretty.rs | 4 +- crates/hir-ty/src/target_feature.rs | 22 ++--- crates/hir-ty/src/test_db.rs | 2 +- crates/hir-ty/src/tests.rs | 10 +-- crates/hir-ty/src/tests/closure_captures.rs | 6 +- crates/hir-ty/src/tls.rs | 10 +-- crates/hir-ty/src/traits.rs | 18 ++-- crates/hir-ty/src/utils.rs | 18 ++-- crates/hir-ty/src/variance.rs | 8 +- crates/hir/src/attrs.rs | 8 +- crates/hir/src/diagnostics.rs | 15 ++-- crates/hir/src/display.rs | 14 ++-- crates/hir/src/from_id.rs | 2 +- crates/hir/src/has_source.rs | 5 +- crates/hir/src/lib.rs | 76 +++++++---------- crates/hir/src/semantics.rs | 26 +++--- crates/hir/src/semantics/child_by_source.rs | 12 +-- crates/hir/src/semantics/source_to_def.rs | 18 ++-- crates/hir/src/source_analyzer.rs | 45 ++++------ crates/hir/src/symbols.rs | 10 +-- crates/hir/src/term_search/tactics.rs | 2 +- crates/ide-assists/src/assist_config.rs | 2 +- crates/ide-assists/src/assist_context.rs | 8 +- crates/ide-assists/src/handlers/add_braces.rs | 2 +- .../add_explicit_enum_discriminant.rs | 4 +- .../src/handlers/add_label_to_loop.rs | 2 +- .../src/handlers/add_lifetime_to_type.rs | 12 +-- .../src/handlers/add_missing_impl_members.rs | 8 +- .../src/handlers/add_missing_match_arms.rs | 8 +- .../src/handlers/add_return_type.rs | 2 +- .../src/handlers/add_turbo_fish.rs | 8 +- .../src/handlers/apply_demorgan.rs | 11 ++- .../ide-assists/src/handlers/auto_import.rs | 12 +-- .../src/handlers/bind_unused_param.rs | 4 +- .../src/handlers/change_visibility.rs | 4 +- .../src/handlers/convert_bool_then.rs | 10 +-- .../src/handlers/convert_bool_to_enum.rs | 10 +-- .../src/handlers/convert_closure_to_fn.rs | 9 +- .../src/handlers/convert_comment_block.rs | 8 +- .../convert_comment_from_or_to_doc.rs | 2 +- .../src/handlers/convert_for_to_while_let.rs | 6 +- .../src/handlers/convert_from_to_tryfrom.rs | 2 +- .../src/handlers/convert_integer_literal.rs | 2 +- .../handlers/convert_iter_for_each_to_for.rs | 4 +- .../src/handlers/convert_let_else_to_match.rs | 10 +-- .../src/handlers/convert_match_to_let_else.rs | 5 +- .../convert_named_struct_to_tuple_struct.rs | 5 +- .../src/handlers/convert_to_guarded_return.rs | 9 +- .../convert_tuple_return_type_to_struct.rs | 9 +- .../convert_tuple_struct_to_named_struct.rs | 5 +- .../src/handlers/convert_while_to_loop.rs | 12 +-- .../handlers/destructure_struct_binding.rs | 6 +- .../src/handlers/destructure_tuple_binding.rs | 2 +- .../src/handlers/desugar_doc_comment.rs | 4 +- .../src/handlers/expand_glob_import.rs | 7 +- .../src/handlers/expand_rest_pattern.rs | 3 +- .../extract_expressions_from_format_string.rs | 48 ++++++----- .../src/handlers/extract_function.rs | 25 +++--- .../src/handlers/extract_module.rs | 21 ++--- .../extract_struct_from_enum_variant.rs | 17 ++-- .../src/handlers/extract_type_alias.rs | 2 +- .../src/handlers/extract_variable.rs | 10 +-- .../src/handlers/fix_visibility.rs | 4 +- .../ide-assists/src/handlers/flip_binexpr.rs | 2 +- crates/ide-assists/src/handlers/flip_comma.rs | 2 +- .../src/handlers/flip_or_pattern.rs | 2 +- .../src/handlers/flip_trait_bound.rs | 2 +- .../src/handlers/generate_constant.rs | 4 +- .../generate_default_from_enum_variant.rs | 8 +- .../src/handlers/generate_default_from_new.rs | 4 +- .../src/handlers/generate_delegate_methods.rs | 6 +- .../src/handlers/generate_delegate_trait.rs | 14 ++-- .../src/handlers/generate_deref.rs | 6 +- .../src/handlers/generate_derive.rs | 2 +- .../generate_documentation_template.rs | 5 +- .../src/handlers/generate_enum_is_method.rs | 2 +- .../generate_enum_projection_method.rs | 2 +- .../src/handlers/generate_enum_variant.rs | 5 +- .../src/handlers/generate_fn_type_alias.rs | 5 +- .../handlers/generate_from_impl_for_enum.rs | 10 +-- .../src/handlers/generate_function.rs | 16 ++-- .../src/handlers/generate_getter_or_setter.rs | 7 +- .../ide-assists/src/handlers/generate_impl.rs | 4 +- .../handlers/generate_is_empty_from_len.rs | 6 +- .../src/handlers/generate_mut_trait_impl.rs | 3 +- .../ide-assists/src/handlers/generate_new.rs | 4 +- .../src/handlers/generate_trait_from_impl.rs | 6 +- .../ide-assists/src/handlers/inline_call.rs | 14 ++-- .../src/handlers/inline_const_as_literal.rs | 2 +- .../src/handlers/inline_local_variable.rs | 6 +- .../src/handlers/inline_type_alias.rs | 7 +- .../src/handlers/into_to_qualified_from.rs | 2 +- .../src/handlers/introduce_named_lifetime.rs | 6 +- .../introduce_named_type_parameter.rs | 2 +- crates/ide-assists/src/handlers/invert_if.rs | 4 +- .../ide-assists/src/handlers/merge_imports.rs | 7 +- .../src/handlers/merge_match_arms.rs | 2 +- .../src/handlers/merge_nested_if.rs | 4 +- .../ide-assists/src/handlers/move_bounds.rs | 4 +- .../src/handlers/move_const_to_impl.rs | 2 +- .../src/handlers/move_from_mod_rs.rs | 2 +- crates/ide-assists/src/handlers/move_guard.rs | 2 +- .../src/handlers/move_module_to_file.rs | 4 +- .../src/handlers/move_to_mod_rs.rs | 2 +- .../src/handlers/normalize_import.rs | 4 +- .../src/handlers/number_representation.rs | 2 +- .../src/handlers/promote_local_to_const.rs | 5 +- .../src/handlers/pull_assignment_up.rs | 5 +- .../src/handlers/qualify_method_call.rs | 4 +- .../ide-assists/src/handlers/qualify_path.rs | 9 +- crates/ide-assists/src/handlers/raw_string.rs | 4 +- crates/ide-assists/src/handlers/remove_dbg.rs | 5 +- .../src/handlers/remove_parentheses.rs | 2 +- .../src/handlers/remove_unused_imports.rs | 4 +- .../src/handlers/remove_unused_param.rs | 8 +- .../src/handlers/reorder_fields.rs | 2 +- .../src/handlers/reorder_impl_items.rs | 2 +- .../src/handlers/replace_arith_op.rs | 2 +- .../replace_derive_with_manual_impl.rs | 10 +-- .../src/handlers/replace_if_let_with_match.rs | 8 +- .../replace_is_method_with_if_let_method.rs | 2 +- .../src/handlers/replace_let_with_if_let.rs | 2 +- .../src/handlers/replace_method_eager_lazy.rs | 14 +--- .../replace_named_generic_with_impl.rs | 9 +- .../replace_qualified_name_with_use.rs | 7 +- .../src/handlers/replace_string_with_char.rs | 5 +- .../handlers/replace_try_expr_with_match.rs | 2 +- .../replace_turbofish_with_explicit_type.rs | 4 +- crates/ide-assists/src/handlers/sort_items.rs | 4 +- .../ide-assists/src/handlers/split_import.rs | 2 +- .../ide-assists/src/handlers/term_search.rs | 2 +- .../src/handlers/toggle_async_sugar.rs | 2 +- .../ide-assists/src/handlers/toggle_ignore.rs | 4 +- .../src/handlers/toggle_macro_delimiter.rs | 3 +- .../src/handlers/unmerge_match_arm.rs | 6 +- .../ide-assists/src/handlers/unmerge_use.rs | 6 +- .../src/handlers/unnecessary_async.rs | 4 +- .../src/handlers/unqualify_method_call.rs | 2 +- .../ide-assists/src/handlers/unwrap_block.rs | 2 +- .../src/handlers/unwrap_return_type.rs | 5 +- .../ide-assists/src/handlers/unwrap_tuple.rs | 2 +- .../src/handlers/wrap_return_type.rs | 5 +- .../src/handlers/wrap_unwrap_cfg_attr.rs | 11 +-- crates/ide-assists/src/tests.rs | 6 +- crates/ide-assists/src/utils.rs | 26 ++---- .../src/utils/gen_trait_fn_body.rs | 2 +- .../ide-assists/src/utils/ref_field_expr.rs | 2 +- crates/ide-completion/src/completions.rs | 10 +-- .../src/completions/attribute.rs | 8 +- .../src/completions/attribute/cfg.rs | 4 +- .../src/completions/attribute/derive.rs | 4 +- .../src/completions/attribute/lint.rs | 4 +- .../src/completions/attribute/macro_use.rs | 2 +- .../src/completions/attribute/repr.rs | 2 +- crates/ide-completion/src/completions/dot.rs | 2 +- .../src/completions/env_vars.rs | 54 +++++++----- crates/ide-completion/src/completions/expr.rs | 10 +-- .../src/completions/extern_abi.rs | 4 +- .../src/completions/extern_crate.rs | 4 +- .../ide-completion/src/completions/field.rs | 2 +- .../src/completions/flyimport.rs | 12 +-- .../src/completions/fn_param.rs | 6 +- .../src/completions/format_string.rs | 6 +- .../src/completions/item_list.rs | 2 +- .../src/completions/item_list/trait_impl.rs | 15 ++-- .../src/completions/lifetime.rs | 2 +- crates/ide-completion/src/completions/mod_.rs | 6 +- .../ide-completion/src/completions/pattern.rs | 2 +- .../ide-completion/src/completions/postfix.rs | 28 ++++--- .../src/completions/postfix/format_like.rs | 6 +- .../ide-completion/src/completions/record.rs | 6 +- .../ide-completion/src/completions/snippet.rs | 26 +++--- crates/ide-completion/src/completions/type.rs | 4 +- crates/ide-completion/src/completions/use_.rs | 4 +- crates/ide-completion/src/completions/vis.rs | 2 +- crates/ide-completion/src/config.rs | 4 +- crates/ide-completion/src/context.rs | 23 +++-- crates/ide-completion/src/context/analysis.rs | 17 ++-- crates/ide-completion/src/context/tests.rs | 4 +- crates/ide-completion/src/item.rs | 8 +- crates/ide-completion/src/lib.rs | 2 +- crates/ide-completion/src/render.rs | 16 ++-- crates/ide-completion/src/render/function.rs | 16 ++-- crates/ide-completion/src/render/literal.rs | 19 ++--- crates/ide-completion/src/render/macro_.rs | 4 +- crates/ide-completion/src/render/pattern.rs | 8 +- .../src/render/union_literal.rs | 8 +- crates/ide-completion/src/render/variant.rs | 2 +- crates/ide-completion/src/tests.rs | 6 +- crates/ide-completion/src/tests/expression.rs | 8 +- crates/ide-completion/src/tests/flyimport.rs | 6 +- .../src/tests/raw_identifiers.rs | 4 +- crates/ide-completion/src/tests/special.rs | 10 +-- crates/ide-db/src/active_parameter.rs | 3 +- crates/ide-db/src/apply_change.rs | 2 +- crates/ide-db/src/defs.rs | 5 +- crates/ide-db/src/documentation.rs | 11 +-- crates/ide-db/src/famous_defs.rs | 6 +- crates/ide-db/src/helpers.rs | 5 +- crates/ide-db/src/imports/import_assets.rs | 12 +-- crates/ide-db/src/imports/insert_use.rs | 16 ++-- crates/ide-db/src/imports/insert_use/tests.rs | 2 +- crates/ide-db/src/imports/merge_imports.rs | 9 +- crates/ide-db/src/items_locator.rs | 4 +- crates/ide-db/src/lib.rs | 12 +-- crates/ide-db/src/path_transform.rs | 5 +- crates/ide-db/src/prime_caches.rs | 4 +- crates/ide-db/src/rename.rs | 6 +- crates/ide-db/src/search.rs | 14 ++-- crates/ide-db/src/source_change.rs | 19 +++-- crates/ide-db/src/symbol_index.rs | 4 +- .../src/syntax_helpers/format_string.rs | 2 +- .../src/syntax_helpers/format_string_exprs.rs | 2 +- crates/ide-db/src/syntax_helpers/node_ext.rs | 2 +- .../ide-db/src/syntax_helpers/suggest_name.rs | 3 +- crates/ide-db/src/syntax_helpers/tree_diff.rs | 4 +- crates/ide-db/src/traits.rs | 8 +- crates/ide-db/src/ty_filter.rs | 2 +- crates/ide-db/src/use_trivial_constructor.rs | 2 +- .../src/handlers/await_outside_of_async.rs | 2 +- .../src/handlers/field_shorthand.rs | 6 +- .../src/handlers/generic_args_prohibited.rs | 4 +- .../src/handlers/inactive_code.rs | 2 +- .../src/handlers/incoherent_impl.rs | 2 +- .../src/handlers/incorrect_case.rs | 6 +- .../src/handlers/json_is_not_rust.rs | 12 +-- .../src/handlers/macro_error.rs | 2 +- .../src/handlers/mismatched_arg_count.rs | 4 +- .../src/handlers/missing_fields.rs | 20 ++--- .../src/handlers/missing_match_arms.rs | 2 +- .../src/handlers/missing_unsafe.rs | 6 +- .../src/handlers/mutability_errors.rs | 4 +- .../src/handlers/no_such_field.rs | 8 +- .../src/handlers/remove_trailing_return.rs | 6 +- .../src/handlers/remove_unnecessary_else.rs | 6 +- .../replace_filter_map_next_with_find_map.rs | 8 +- .../handlers/trait_impl_incorrect_safety.rs | 2 +- .../handlers/trait_impl_missing_assoc_item.rs | 4 +- .../trait_impl_redundant_assoc_item.rs | 2 +- .../src/handlers/type_mismatch.rs | 15 ++-- .../src/handlers/typed_hole.rs | 10 +-- .../src/handlers/unlinked_file.rs | 12 +-- .../src/handlers/unresolved_field.rs | 19 ++--- .../src/handlers/unresolved_method.rs | 15 ++-- .../src/handlers/unresolved_module.rs | 4 +- .../src/handlers/unused_variables.rs | 2 +- .../src/handlers/useless_braces.rs | 8 +- crates/ide-diagnostics/src/lib.rs | 15 ++-- crates/ide-diagnostics/src/tests.rs | 4 +- crates/ide-ssr/src/fragments.rs | 2 +- crates/ide-ssr/src/from_comment.rs | 4 +- crates/ide-ssr/src/lib.rs | 4 +- crates/ide-ssr/src/matching.rs | 6 +- crates/ide-ssr/src/parsing.rs | 2 +- crates/ide-ssr/src/replacing.rs | 4 +- crates/ide-ssr/src/resolving.rs | 6 +- crates/ide-ssr/src/search.rs | 7 +- crates/ide-ssr/src/tests.rs | 6 +- crates/ide/src/annotations.rs | 14 ++-- crates/ide/src/annotations/fn_references.rs | 4 +- crates/ide/src/call_hierarchy.rs | 8 +- crates/ide/src/doc_links.rs | 17 ++-- crates/ide/src/doc_links/intra_doc_links.rs | 2 +- crates/ide/src/doc_links/tests.rs | 13 +-- crates/ide/src/expand_macro.rs | 8 +- crates/ide/src/extend_selection.rs | 18 ++-- crates/ide/src/fetch_crates.rs | 2 +- crates/ide/src/file_structure.rs | 6 +- crates/ide/src/fixture.rs | 2 +- crates/ide/src/folding_ranges.rs | 7 +- crates/ide/src/goto_declaration.rs | 16 ++-- crates/ide/src/goto_definition.rs | 15 ++-- crates/ide/src/goto_implementation.rs | 4 +- crates/ide/src/goto_type_definition.rs | 4 +- crates/ide/src/highlight_related.rs | 21 ++--- crates/ide/src/hover.rs | 14 ++-- crates/ide/src/hover/render.rs | 25 +++--- crates/ide/src/hover/tests.rs | 6 +- crates/ide/src/inlay_hints.rs | 19 +++-- crates/ide/src/inlay_hints/adjustment.rs | 6 +- crates/ide/src/inlay_hints/bind_pat.rs | 8 +- crates/ide/src/inlay_hints/binding_mode.rs | 2 +- crates/ide/src/inlay_hints/bounds.rs | 4 +- crates/ide/src/inlay_hints/chaining.rs | 9 +- crates/ide/src/inlay_hints/closing_brace.rs | 9 +- .../ide/src/inlay_hints/closure_captures.rs | 4 +- crates/ide/src/inlay_hints/closure_ret.rs | 4 +- crates/ide/src/inlay_hints/discriminant.rs | 4 +- crates/ide/src/inlay_hints/extern_block.rs | 4 +- crates/ide/src/inlay_hints/generic_param.rs | 12 +-- crates/ide/src/inlay_hints/implicit_drop.rs | 9 +- crates/ide/src/inlay_hints/implicit_static.rs | 4 +- crates/ide/src/inlay_hints/lifetime.rs | 15 ++-- crates/ide/src/inlay_hints/param_name.rs | 6 +- crates/ide/src/inlay_hints/range_exclusive.rs | 4 +- crates/ide/src/interpret.rs | 4 +- crates/ide/src/join_lines.rs | 4 +- crates/ide/src/lib.rs | 13 +-- crates/ide/src/matching_brace.rs | 2 +- crates/ide/src/moniker.rs | 12 +-- crates/ide/src/move_item.rs | 6 +- crates/ide/src/navigation_target.rs | 11 +-- crates/ide/src/parent_module.rs | 4 +- crates/ide/src/references.rs | 15 ++-- crates/ide/src/rename.rs | 8 +- crates/ide/src/runnables.rs | 13 +-- crates/ide/src/signature_help.rs | 13 ++- crates/ide/src/ssr.rs | 6 +- crates/ide/src/static_index.rs | 18 ++-- crates/ide/src/status.rs | 2 +- crates/ide/src/syntax_highlighting.rs | 8 +- crates/ide/src/syntax_highlighting/format.rs | 8 +- .../ide/src/syntax_highlighting/highlight.rs | 28 ++----- crates/ide/src/syntax_highlighting/html.rs | 2 +- crates/ide/src/syntax_highlighting/inject.rs | 12 +-- .../ide/src/syntax_highlighting/injector.rs | 6 +- crates/ide/src/syntax_highlighting/tests.rs | 6 +- crates/ide/src/test_explorer.rs | 4 +- crates/ide/src/typing.rs | 6 +- crates/ide/src/typing/on_enter.rs | 6 +- crates/ide/src/view_crate_graph.rs | 2 +- crates/ide/src/view_hir.rs | 2 +- crates/ide/src/view_item_tree.rs | 2 +- crates/ide/src/view_memory_layout.rs | 2 +- crates/ide/src/view_mir.rs | 2 +- crates/ide/src/view_syntax_tree.rs | 4 +- crates/intern/src/lib.rs | 4 +- crates/intern/src/symbol.rs | 6 +- crates/intern/src/symbol/symbols.rs | 2 +- crates/load-cargo/src/lib.rs | 17 ++-- crates/mbe/src/benchmark.rs | 11 +-- crates/mbe/src/expander.rs | 2 +- crates/mbe/src/expander/matcher.rs | 8 +- crates/mbe/src/expander/transcriber.rs | 11 ++- crates/mbe/src/lib.rs | 2 +- crates/mbe/src/parser.rs | 14 ++-- crates/parser/src/event.rs | 2 +- crates/parser/src/grammar.rs | 4 +- crates/parser/src/grammar/expressions.rs | 2 +- crates/parser/src/parser.rs | 6 +- crates/paths/src/lib.rs | 4 +- .../proc-macro-api/src/legacy_protocol/msg.rs | 4 +- crates/proc-macro-api/src/lib.rs | 8 +- crates/proc-macro-api/src/process.rs | 8 +- crates/proc-macro-srv-cli/src/main.rs | 4 +- crates/proc-macro-srv-cli/src/main_loop.rs | 4 +- crates/proc-macro-srv/src/dylib.rs | 2 +- crates/proc-macro-srv/src/lib.rs | 2 +- crates/proc-macro-srv/src/proc_macros.rs | 2 +- .../src/server_impl/rust_analyzer_span.rs | 4 +- .../src/server_impl/token_id.rs | 2 +- .../src/server_impl/token_stream.rs | 2 +- crates/proc-macro-srv/src/tests/utils.rs | 2 +- .../project-model/src/build_dependencies.rs | 6 +- crates/project-model/src/cargo_workspace.rs | 2 +- crates/project-model/src/env.rs | 2 +- crates/project-model/src/lib.rs | 8 +- crates/project-model/src/manifest_path.rs | 6 +- crates/project-model/src/project_json.rs | 2 +- crates/project-model/src/sysroot.rs | 20 ++--- crates/project-model/src/tests.rs | 8 +- .../src/toolchain_info/target_data_layout.rs | 2 +- .../src/toolchain_info/target_tuple.rs | 2 +- crates/project-model/src/workspace.rs | 10 +-- crates/query-group-macro/src/lib.rs | 8 +- crates/query-group-macro/src/queries.rs | 4 +- crates/rust-analyzer/src/bin/main.rs | 10 ++- .../rust-analyzer/src/cli/analysis_stats.rs | 11 +-- crates/rust-analyzer/src/cli/diagnostics.rs | 6 +- crates/rust-analyzer/src/cli/lsif.rs | 4 +- crates/rust-analyzer/src/cli/run_tests.rs | 6 +- crates/rust-analyzer/src/cli/rustc_tests.rs | 6 +- crates/rust-analyzer/src/cli/scip.rs | 2 +- crates/rust-analyzer/src/cli/ssr.rs | 4 +- .../src/cli/unresolved_references.rs | 10 +-- crates/rust-analyzer/src/command.rs | 9 +- crates/rust-analyzer/src/config.rs | 10 +-- .../src/config/patch_old_style.rs | 2 +- .../rust-analyzer/src/diagnostics/to_proto.rs | 8 +- crates/rust-analyzer/src/flycheck.rs | 2 +- crates/rust-analyzer/src/global_state.rs | 8 +- crates/rust-analyzer/src/handlers/dispatch.rs | 2 +- crates/rust-analyzer/src/handlers/request.rs | 23 +++-- .../src/integrated_benchmarks.rs | 4 +- crates/rust-analyzer/src/lsp/capabilities.rs | 2 +- crates/rust-analyzer/src/lsp/ext.rs | 6 +- crates/rust-analyzer/src/lsp/from_proto.rs | 2 +- crates/rust-analyzer/src/lsp/to_proto.rs | 23 ++--- crates/rust-analyzer/src/lsp/utils.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 20 +++-- crates/rust-analyzer/src/reload.rs | 12 +-- crates/rust-analyzer/src/target_spec.rs | 7 +- crates/rust-analyzer/src/tracing/config.rs | 6 +- crates/rust-analyzer/src/tracing/hprof.rs | 5 +- crates/rust-analyzer/src/tracing/json.rs | 4 +- crates/rust-analyzer/tests/slow-tests/main.rs | 12 +-- .../rust-analyzer/tests/slow-tests/ratoml.rs | 2 +- .../rust-analyzer/tests/slow-tests/support.rs | 22 ++--- crates/span/src/ast_id.rs | 2 +- crates/span/src/map.rs | 4 +- crates/stdx/src/lib.rs | 6 +- crates/stdx/src/process.rs | 2 +- crates/stdx/src/thin_vec.rs | 10 +-- crates/stdx/src/thread/pool.rs | 2 +- crates/syntax-bridge/src/lib.rs | 9 +- .../src/prettify_macro_expansion.rs | 6 +- crates/syntax-bridge/src/tests.rs | 9 +- crates/syntax/src/algo.rs | 4 +- crates/syntax/src/ast.rs | 2 +- crates/syntax/src/ast/edit.rs | 5 +- crates/syntax/src/ast/edit_in_place.rs | 6 +- crates/syntax/src/ast/expr_ext.rs | 12 +-- crates/syntax/src/ast/make.rs | 19 ++--- crates/syntax/src/ast/node_ext.rs | 25 ++---- crates/syntax/src/ast/prec.rs | 7 +- .../src/ast/syntax_factory/constructors.rs | 6 +- crates/syntax/src/ast/token_ext.rs | 18 ++-- crates/syntax/src/ast/traits.rs | 10 +-- crates/syntax/src/fuzz.rs | 2 +- crates/syntax/src/hacks.rs | 2 +- crates/syntax/src/lib.rs | 6 +- crates/syntax/src/parsing.rs | 2 +- crates/syntax/src/parsing/reparsing.rs | 6 +- crates/syntax/src/ptr.rs | 4 +- crates/syntax/src/syntax_editor.rs | 13 +-- crates/syntax/src/syntax_editor/edit_algo.rs | 30 ++++--- crates/syntax/src/syntax_editor/edits.rs | 6 +- crates/syntax/src/ted.rs | 2 +- crates/syntax/src/tests.rs | 2 +- crates/syntax/src/validation.rs | 10 +-- crates/syntax/src/validation/block.rs | 2 +- crates/test-fixture/src/lib.rs | 8 +- crates/vfs-notify/src/lib.rs | 2 +- crates/vfs/src/file_set.rs | 6 +- crates/vfs/src/lib.rs | 4 +- crates/vfs/src/vfs_path.rs | 6 +- lib/lsp-server/examples/goto_def.rs | 2 +- lib/lsp-server/src/lib.rs | 6 +- lib/lsp-server/src/socket.rs | 4 +- lib/lsp-server/src/stdio.rs | 2 +- xtask/src/codegen.rs | 2 +- xtask/src/codegen/assists_doc_tests.rs | 2 +- xtask/src/codegen/diagnostics_docs.rs | 2 +- xtask/src/codegen/feature_docs.rs | 2 +- xtask/src/codegen/grammar.rs | 6 +- xtask/src/codegen/lints.rs | 4 +- xtask/src/codegen/parser_inline_tests.rs | 2 +- xtask/src/dist.rs | 6 +- xtask/src/install.rs | 14 +++- xtask/src/main.rs | 2 +- xtask/src/metrics.rs | 2 +- xtask/src/publish.rs | 6 +- xtask/src/release.rs | 11 +-- xtask/src/release/changelog.rs | 12 ++- xtask/src/tidy.rs | 3 +- 571 files changed, 2210 insertions(+), 2458 deletions(-) diff --git a/crates/base-db/src/change.rs b/crates/base-db/src/change.rs index 1f19556a76..b5964ff5b4 100644 --- a/crates/base-db/src/change.rs +++ b/crates/base-db/src/change.rs @@ -82,9 +82,5 @@ impl FileChange { } fn durability(source_root: &SourceRoot) -> Durability { - if source_root.is_library { - Durability::HIGH - } else { - Durability::LOW - } + if source_root.is_library { Durability::HIGH } else { Durability::LOW } } diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index 913dfe6efb..564697facf 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -10,15 +10,15 @@ use std::hash::BuildHasherDefault; use std::{fmt, mem, ops}; use cfg::{CfgOptions, HashableCfgOptions}; -use dashmap::mapref::entry::Entry; use dashmap::DashMap; +use dashmap::mapref::entry::Entry; use intern::Symbol; use la_arena::{Arena, Idx, RawIdx}; use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; use salsa::{Durability, Setter}; use span::{Edition, EditionedFileId}; use triomphe::Arc; -use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath}; +use vfs::{AbsPathBuf, AnchoredPath, FileId, VfsPath, file_set::FileSet}; use crate::{CrateWorkspaceData, RootQueryDb}; @@ -110,11 +110,7 @@ impl CrateName { /// Dashes are not allowed in the crate names, /// hence the input string is returned as `Err` for those cases. pub fn new(name: &str) -> Result { - if name.contains('-') { - Err(name) - } else { - Ok(Self(Symbol::intern(name))) - } + if name.contains('-') { Err(name) } else { Ok(Self(Symbol::intern(name))) } } /// Creates a crate name, unconditionally replacing the dashes with underscores. @@ -922,15 +918,21 @@ mod tests { None, empty_ws_data(), ); - assert!(graph - .add_dep(crate1, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_ok()); - assert!(graph - .add_dep(crate2, DependencyBuilder::new(CrateName::new("crate3").unwrap(), crate3,)) - .is_ok()); - assert!(graph - .add_dep(crate3, DependencyBuilder::new(CrateName::new("crate1").unwrap(), crate1,)) - .is_err()); + assert!( + graph + .add_dep(crate1, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate2, DependencyBuilder::new(CrateName::new("crate3").unwrap(), crate3,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate3, DependencyBuilder::new(CrateName::new("crate1").unwrap(), crate1,)) + .is_err() + ); } #[test] @@ -962,12 +964,16 @@ mod tests { None, empty_ws_data(), ); - assert!(graph - .add_dep(crate1, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_ok()); - assert!(graph - .add_dep(crate2, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_err()); + assert!( + graph + .add_dep(crate1, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate2, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_err() + ); } #[test] @@ -1012,12 +1018,16 @@ mod tests { None, empty_ws_data(), ); - assert!(graph - .add_dep(crate1, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_ok()); - assert!(graph - .add_dep(crate2, DependencyBuilder::new(CrateName::new("crate3").unwrap(), crate3,)) - .is_ok()); + assert!( + graph + .add_dep(crate1, DependencyBuilder::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate2, DependencyBuilder::new(CrateName::new("crate3").unwrap(), crate3,)) + .is_ok() + ); } #[test] @@ -1049,15 +1059,17 @@ mod tests { None, empty_ws_data(), ); - assert!(graph - .add_dep( - crate1, - DependencyBuilder::new( - CrateName::normalize_dashes("crate-name-with-dashes"), - crate2, + assert!( + graph + .add_dep( + crate1, + DependencyBuilder::new( + CrateName::normalize_dashes("crate-name-with-dashes"), + crate2, + ) ) - ) - .is_ok()); + .is_ok() + ); assert_eq!( graph.arena[crate1].basic.dependencies, vec![ diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index b733c4d241..e6059e9e79 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -14,15 +14,15 @@ pub use crate::{ SourceRoot, SourceRootId, TargetLayoutLoadResult, UniqueCrateData, }, }; -use dashmap::{mapref::entry::Entry, DashMap}; +use dashmap::{DashMap, mapref::entry::Entry}; pub use query_group::{self}; use rustc_hash::{FxHashSet, FxHasher}; pub use salsa::{self}; use salsa::{Durability, Setter}; pub use semver::{BuildMetadata, Prerelease, Version, VersionReq}; -use syntax::{ast, Parse, SyntaxError}; +use syntax::{Parse, SyntaxError, ast}; use triomphe::Arc; -pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, FileId, VfsPath}; +pub use vfs::{AnchoredPath, AnchoredPathBuf, FileId, VfsPath, file_set::FileSet}; #[macro_export] macro_rules! impl_intern_key { diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs index 26860fb932..8218a81556 100644 --- a/crates/cfg/src/lib.rs +++ b/crates/cfg/src/lib.rs @@ -9,7 +9,7 @@ use std::fmt; use rustc_hash::FxHashSet; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; pub use cfg_expr::{CfgAtom, CfgExpr}; pub use dnf::DnfExpr; diff --git a/crates/cfg/src/tests.rs b/crates/cfg/src/tests.rs index 6d87d83ad9..6766748097 100644 --- a/crates/cfg/src/tests.rs +++ b/crates/cfg/src/tests.rs @@ -1,10 +1,11 @@ use arbitrary::{Arbitrary, Unstructured}; -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use intern::Symbol; -use syntax::{ast, AstNode, Edition}; +use syntax::{AstNode, Edition, ast}; use syntax_bridge::{ - dummy_test_span_utils::{DummyTestSpanMap, DUMMY}, - syntax_node_to_token_tree, DocCommentDesugarMode, + DocCommentDesugarMode, + dummy_test_span_utils::{DUMMY, DummyTestSpanMap}, + syntax_node_to_token_tree, }; use crate::{CfgAtom, CfgExpr, CfgOptions, DnfExpr}; diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs index 2775e1398c..78f26d6756 100644 --- a/crates/hir-def/src/attr.rs +++ b/crates/hir-def/src/attr.rs @@ -6,28 +6,28 @@ use base_db::Crate; use cfg::{CfgExpr, CfgOptions}; use either::Either; use hir_expand::{ - attrs::{collect_attrs, Attr, AttrId, RawAttrs}, HirFileId, InFile, + attrs::{Attr, AttrId, RawAttrs, collect_attrs}, }; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use la_arena::{ArenaMap, Idx, RawIdx}; use mbe::DelimiterKind; use rustc_abi::ReprOptions; use syntax::{ - ast::{self, HasAttrs}, AstPtr, + ast::{self, HasAttrs}, }; use triomphe::Arc; use tt::iter::{TtElement, TtIter}; use crate::{ + AdtId, AttrDefId, GenericParamId, HasModule, ItemTreeLoc, LocalFieldId, Lookup, MacroId, + VariantId, db::DefDatabase, item_tree::{AttrOwner, FieldParent, ItemTreeNode}, lang_item::LangItem, nameres::{ModuleOrigin, ModuleSource}, src::{HasChildSource, HasSource}, - AdtId, AttrDefId, GenericParamId, HasModule, ItemTreeLoc, LocalFieldId, Lookup, MacroId, - VariantId, }; /// Desugared attributes of an item post `cfg_attr` expansion. @@ -770,8 +770,8 @@ mod tests { use hir_expand::span_map::{RealSpanMap, SpanMap}; use span::FileId; - use syntax::{ast, AstNode, TextRange}; - use syntax_bridge::{syntax_node_to_token_tree, DocCommentDesugarMode}; + use syntax::{AstNode, TextRange, ast}; + use syntax_bridge::{DocCommentDesugarMode, syntax_node_to_token_tree}; use crate::attr::{DocAtom, DocExpr}; diff --git a/crates/hir-def/src/builtin_type.rs b/crates/hir-def/src/builtin_type.rs index 14b9af84e6..6ea21356aa 100644 --- a/crates/hir-def/src/builtin_type.rs +++ b/crates/hir-def/src/builtin_type.rs @@ -6,7 +6,7 @@ use std::fmt; use hir_expand::name::{AsName, Name}; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; /// Different signed int types. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum BuiltinInt { diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs index 1a6bed6cab..b251564016 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -4,19 +4,19 @@ pub mod adt; use base_db::Crate; use hir_expand::name::Name; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use la_arena::{Idx, RawIdx}; use triomphe::Arc; use crate::{ + ConstId, ExternCrateId, FunctionId, HasModule, ImplId, ItemContainerId, ItemLoc, Lookup, + Macro2Id, MacroRulesId, ProcMacroId, StaticId, TraitAliasId, TraitId, TypeAliasId, db::DefDatabase, item_tree::{self, FnFlags, ModItem}, - nameres::proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroKind}, + nameres::proc_macro::{ProcMacroKind, parse_macro_name_and_helper_attrs}, path::ImportAlias, type_ref::{TraitRef, TypeBound, TypeRefId, TypesMap}, visibility::RawVisibility, - ConstId, ExternCrateId, FunctionId, HasModule, ImplId, ItemContainerId, ItemLoc, Lookup, - Macro2Id, MacroRulesId, ProcMacroId, StaticId, TraitAliasId, TraitId, TypeAliasId, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -431,11 +431,7 @@ impl ExternCrateDeclData { Some(krate) } else { krate.data(db).dependencies.iter().find_map(|dep| { - if dep.name.symbol() == name.symbol() { - Some(dep.crate_id) - } else { - None - } + if dep.name.symbol() == name.symbol() { Some(dep.crate_id) } else { None } }) }; diff --git a/crates/hir-def/src/data/adt.rs b/crates/hir-def/src/data/adt.rs index 9db66d6e91..8ea7940653 100644 --- a/crates/hir-def/src/data/adt.rs +++ b/crates/hir-def/src/data/adt.rs @@ -11,6 +11,7 @@ use rustc_abi::{IntegerType, ReprOptions}; use triomphe::Arc; use crate::{ + EnumId, EnumVariantId, LocalFieldId, LocalModuleId, Lookup, StructId, UnionId, VariantId, db::DefDatabase, hir::Expr, item_tree::{ @@ -20,7 +21,6 @@ use crate::{ nameres::diagnostics::{DefDiagnostic, DefDiagnostics}, type_ref::{TypeRefId, TypesMap}, visibility::RawVisibility, - EnumId, EnumVariantId, LocalFieldId, LocalModuleId, Lookup, StructId, UnionId, VariantId, }; /// Note that we use `StructData` for unions as well! diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index 108968fe52..58688d5f41 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -1,33 +1,14 @@ //! Defines database & queries for name resolution. use base_db::{Crate, RootQueryDb, SourceDatabase, Upcast}; use either::Either; -use hir_expand::{db::ExpandDatabase, HirFileId, MacroDefId}; +use hir_expand::{HirFileId, MacroDefId, db::ExpandDatabase}; use intern::sym; use la_arena::ArenaMap; use span::{EditionedFileId, MacroCallId}; -use syntax::{ast, AstPtr}; +use syntax::{AstPtr, ast}; use triomphe::Arc; use crate::{ - attr::{Attrs, AttrsWithOwner}, - data::{ - adt::{EnumData, EnumVariantData, EnumVariants, StructData, VariantData}, - ConstData, ExternCrateDeclData, FunctionData, ImplData, Macro2Data, MacroRulesData, - ProcMacroData, StaticData, TraitAliasData, TraitData, TypeAliasData, - }, - expr_store::{scope::ExprScopes, Body, BodySourceMap}, - generics::GenericParams, - import_map::ImportMap, - item_tree::{AttrOwner, ItemTree, ItemTreeSourceMaps}, - lang_item::{self, LangItem, LangItemTarget, LangItems}, - nameres::{ - assoc::{ImplItems, TraitItems}, - diagnostics::DefDiagnostics, - DefMap, LocalDefMap, - }, - tt, - type_ref::TypesSourceMap, - visibility::{self, Visibility}, AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, InTypeConstId, @@ -35,6 +16,25 @@ use crate::{ MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId, + attr::{Attrs, AttrsWithOwner}, + data::{ + ConstData, ExternCrateDeclData, FunctionData, ImplData, Macro2Data, MacroRulesData, + ProcMacroData, StaticData, TraitAliasData, TraitData, TypeAliasData, + adt::{EnumData, EnumVariantData, EnumVariants, StructData, VariantData}, + }, + expr_store::{Body, BodySourceMap, scope::ExprScopes}, + generics::GenericParams, + import_map::ImportMap, + item_tree::{AttrOwner, ItemTree, ItemTreeSourceMaps}, + lang_item::{self, LangItem, LangItemTarget, LangItems}, + nameres::{ + DefMap, LocalDefMap, + assoc::{ImplItems, TraitItems}, + diagnostics::DefDiagnostics, + }, + tt, + type_ref::TypesSourceMap, + visibility::{self, Visibility}, }; use salsa::plumbing::AsId; @@ -337,7 +337,7 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: Crate) -> bool { for output in segments.skip(1) { match output.flat_tokens() { [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::no_std => { - return true + return true; } _ => {} } diff --git a/crates/hir-def/src/dyn_map.rs b/crates/hir-def/src/dyn_map.rs index 8868bc0cd9..b17a2b0a2e 100644 --- a/crates/hir-def/src/dyn_map.rs +++ b/crates/hir-def/src/dyn_map.rs @@ -27,15 +27,15 @@ pub mod keys { use std::marker::PhantomData; - use hir_expand::{attrs::AttrId, MacroCallId}; + use hir_expand::{MacroCallId, attrs::AttrId}; use rustc_hash::FxHashMap; - use syntax::{ast, AstNode, AstPtr}; + use syntax::{AstNode, AstPtr, ast}; use crate::{ - dyn_map::{DynMap, Policy}, BlockId, ConstId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId, + dyn_map::{DynMap, Policy}, }; pub type Key = crate::dyn_map::Key, V, AstPtrPolicy>; diff --git a/crates/hir-def/src/expander.rs b/crates/hir-def/src/expander.rs index 343d8aa1c9..895b827967 100644 --- a/crates/hir-def/src/expander.rs +++ b/crates/hir-def/src/expander.rs @@ -6,17 +6,17 @@ use base_db::Crate; use cfg::CfgOptions; use drop_bomb::DropBomb; use hir_expand::{ - attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandErrorKind, - ExpandResult, HirFileId, InFile, Lookup, MacroCallId, + ExpandError, ExpandErrorKind, ExpandResult, HirFileId, InFile, Lookup, MacroCallId, + attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, }; use span::{Edition, SyntaxContext}; -use syntax::{ast, Parse}; +use syntax::{Parse, ast}; use triomphe::Arc; use crate::type_ref::{TypesMap, TypesSourceMap}; use crate::{ - attr::Attrs, db::DefDatabase, lower::LowerCtx, path::Path, AsMacroCall, MacroId, ModuleId, - UnresolvedMacro, + AsMacroCall, MacroId, ModuleId, UnresolvedMacro, attr::Attrs, db::DefDatabase, lower::LowerCtx, + path::Path, }; #[derive(Debug)] @@ -84,11 +84,7 @@ impl Expander { } }); - if let Some(err) = unresolved_macro_err { - Err(err) - } else { - Ok(result) - } + if let Some(err) = unresolved_macro_err { Err(err) } else { Ok(result) } } pub fn enter_expand_id( diff --git a/crates/hir-def/src/expr_store.rs b/crates/hir-def/src/expr_store.rs index 7e7ccbfa91..c9a7566c8d 100644 --- a/crates/hir-def/src/expr_store.rs +++ b/crates/hir-def/src/expr_store.rs @@ -12,16 +12,17 @@ use std::ops::{Deref, Index}; use cfg::{CfgExpr, CfgOptions}; use either::Either; -use hir_expand::{name::Name, ExpandError, InFile}; +use hir_expand::{ExpandError, InFile, name::Name}; use la_arena::{Arena, ArenaMap}; use rustc_hash::FxHashMap; use smallvec::SmallVec; use span::{Edition, MacroFileId, SyntaxContext}; -use syntax::{ast, AstPtr, SyntaxNodePtr}; +use syntax::{AstPtr, SyntaxNodePtr, ast}; use triomphe::Arc; use tt::TextRange; use crate::{ + BlockId, DefWithBodyId, Lookup, SyntheticSyntax, db::DefDatabase, hir::{ Array, AsmOperand, Binding, BindingId, Expr, ExprId, ExprOrPatId, Label, LabelId, Pat, @@ -30,7 +31,6 @@ use crate::{ nameres::DefMap, path::{ModPath, Path}, type_ref::{TypeRef, TypeRefId, TypesMap, TypesSourceMap}, - BlockId, DefWithBodyId, Lookup, SyntheticSyntax, }; pub use self::body::{Body, BodySourceMap}; diff --git a/crates/hir-def/src/expr_store/body.rs b/crates/hir-def/src/expr_store/body.rs index 8aca4eb9bc..0295874bd7 100644 --- a/crates/hir-def/src/expr_store/body.rs +++ b/crates/hir-def/src/expr_store/body.rs @@ -9,13 +9,13 @@ use syntax::ast; use triomphe::Arc; use crate::{ + DefWithBodyId, HasModule, db::DefDatabase, expander::Expander, - expr_store::{lower, pretty, ExpressionStore, ExpressionStoreSourceMap, SelfParamPtr}, + expr_store::{ExpressionStore, ExpressionStoreSourceMap, SelfParamPtr, lower, pretty}, hir::{BindingId, ExprId, PatId}, item_tree::AttrOwner, src::HasSource, - DefWithBodyId, HasModule, }; /// The body of an item (function, const etc.). diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs index b9b00108dc..fe1a5e8f29 100644 --- a/crates/hir-def/src/expr_store/lower.rs +++ b/crates/hir-def/src/expr_store/lower.rs @@ -8,26 +8,27 @@ use std::mem; use base_db::Crate; use either::Either; use hir_expand::{ + InFile, MacroDefId, mod_path::tool_path, name::{AsName, Name}, span_map::{ExpansionSpanMap, SpanMap}, - InFile, MacroDefId, }; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use rustc_hash::FxHashMap; use span::AstIdMap; use stdx::never; use syntax::{ + AstNode, AstPtr, AstToken as _, SyntaxNodePtr, ast::{ self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasGenericArgs, HasLoopBody, HasName, RangeItem, SlicePatComponents, }, - AstNode, AstPtr, AstToken as _, SyntaxNodePtr, }; use text_size::TextSize; use triomphe::Arc; use crate::{ + AdtId, BlockId, BlockLoc, ConstBlockLoc, DefWithBodyId, MacroId, ModuleDefId, UnresolvedMacro, attr::Attrs, builtin_type::BuiltinUint, data::adt::StructKind, @@ -38,14 +39,14 @@ use crate::{ ExpressionStoreDiagnostics, ExpressionStoreSourceMap, HygieneId, LabelPtr, PatPtr, }, hir::{ + Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind, + Expr, ExprId, Item, Label, LabelId, Literal, MatchArm, Movability, OffsetOf, Pat, PatId, + RecordFieldPat, RecordLitField, Statement, format_args::{ self, FormatAlignment, FormatArgs, FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArgumentsCollector, FormatCount, FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait, }, - Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind, - Expr, ExprId, Item, Label, LabelId, Literal, MatchArm, Movability, OffsetOf, Pat, PatId, - RecordFieldPat, RecordLitField, Statement, }, item_scope::BuiltinShadowMode, lang_item::LangItem, @@ -53,7 +54,6 @@ use crate::{ nameres::{DefMap, LocalDefMap, MacroSubNs}, path::{GenericArgs, Path}, type_ref::{Mutability, Rawness, TypeRef}, - AdtId, BlockId, BlockLoc, ConstBlockLoc, DefWithBodyId, MacroId, ModuleDefId, UnresolvedMacro, }; type FxIndexSet = indexmap::IndexSet>; @@ -641,11 +641,7 @@ impl ExprCollector<'_> { let expr = self.collect_expr_opt(e.expr()); let raw_tok = e.raw_token().is_some(); let mutability = if raw_tok { - if e.mut_token().is_some() { - Mutability::Mut - } else { - Mutability::Shared - } + if e.mut_token().is_some() { Mutability::Mut } else { Mutability::Shared } } else { Mutability::from_mutable(e.mut_token().is_some()) }; @@ -2041,7 +2037,7 @@ impl ExprCollector<'_> { return match l.kind() { ast::LiteralKind::String(s) => Some((s, true)), _ => None, - } + }; } _ => return None, }; diff --git a/crates/hir-def/src/expr_store/lower/asm.rs b/crates/hir-def/src/expr_store/lower/asm.rs index 032c18688e..633f976a85 100644 --- a/crates/hir-def/src/expr_store/lower/asm.rs +++ b/crates/hir-def/src/expr_store/lower/asm.rs @@ -3,8 +3,8 @@ use hir_expand::name::Name; use intern::Symbol; use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ - ast::{self, HasName, IsString}, AstNode, AstPtr, AstToken, T, + ast::{self, HasName, IsString}, }; use tt::TextRange; diff --git a/crates/hir-def/src/expr_store/scope.rs b/crates/hir-def/src/expr_store/scope.rs index 42a8eae406..43e11508d8 100644 --- a/crates/hir-def/src/expr_store/scope.rs +++ b/crates/hir-def/src/expr_store/scope.rs @@ -1,13 +1,13 @@ //! Name resolution for expressions. -use hir_expand::{name::Name, MacroDefId}; +use hir_expand::{MacroDefId, name::Name}; use la_arena::{Arena, ArenaMap, Idx, IdxRange, RawIdx}; use triomphe::Arc; use crate::{ + BlockId, ConstBlockId, DefWithBodyId, db::DefDatabase, expr_store::{Body, ExpressionStore, HygieneId}, hir::{Binding, BindingId, Expr, ExprId, Item, LabelId, Pat, PatId, Statement}, - BlockId, ConstBlockId, DefWithBodyId, }; pub type ScopeId = Idx; @@ -325,14 +325,14 @@ fn compute_expr_scopes( #[cfg(test)] mod tests { use base_db::RootQueryDb; - use hir_expand::{name::AsName, InFile}; + use hir_expand::{InFile, name::AsName}; use salsa::AsDynDatabase; use span::FileId; - use syntax::{algo::find_node_at_offset, ast, AstNode}; + use syntax::{AstNode, algo::find_node_at_offset, ast}; use test_fixture::WithFixture; use test_utils::{assert_eq_text, extract_offset}; - use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId}; + use crate::{FunctionId, ModuleDefId, db::DefDatabase, test_db::TestDB}; fn find_function(db: &TestDB, file_id: FileId) -> FunctionId { let krate = db.test_crate(); diff --git a/crates/hir-def/src/expr_store/tests.rs b/crates/hir-def/src/expr_store/tests.rs index 7bf27747c4..a6fcfaa445 100644 --- a/crates/hir-def/src/expr_store/tests.rs +++ b/crates/hir-def/src/expr_store/tests.rs @@ -1,7 +1,7 @@ mod block; -use crate::{hir::MatchArm, test_db::TestDB, ModuleDefId}; -use expect_test::{expect, Expect}; +use crate::{ModuleDefId, hir::MatchArm, test_db::TestDB}; +use expect_test::{Expect, expect}; use la_arena::RawIdx; use test_fixture::WithFixture; diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs index 48f31698dd..69c7794327 100644 --- a/crates/hir-def/src/find_path.rs +++ b/crates/hir-def/src/find_path.rs @@ -4,19 +4,19 @@ use std::{cell::Cell, cmp::Ordering, iter}; use base_db::{Crate, CrateOrigin, LangCrateOrigin}; use hir_expand::{ - name::{AsName, Name}, Lookup, + name::{AsName, Name}, }; use intern::sym; use rustc_hash::FxHashSet; use crate::{ + ImportPathConfig, ModuleDefId, ModuleId, db::DefDatabase, item_scope::ItemInNs, nameres::DefMap, path::{ModPath, PathKind}, visibility::{Visibility, VisibilityExplicitness}, - ImportPathConfig, ModuleDefId, ModuleId, }; /// Find a path that can be used to refer to a certain item. This can depend on @@ -651,7 +651,7 @@ fn find_local_import_locations( #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use hir_expand::db::ExpandDatabase; use itertools::Itertools; use span::Edition; diff --git a/crates/hir-def/src/generics.rs b/crates/hir-def/src/generics.rs index 6f1650adeb..ad4a8ba2ed 100644 --- a/crates/hir-def/src/generics.rs +++ b/crates/hir-def/src/generics.rs @@ -7,8 +7,8 @@ use std::{ops, sync::LazyLock}; use either::Either; use hir_expand::{ - name::{AsName, Name}, ExpandResult, + name::{AsName, Name}, }; use intern::sym; use la_arena::{Arena, RawIdx}; @@ -20,6 +20,8 @@ use syntax::ast::{self, HasGenericParams, HasName, HasTypeBounds}; use triomphe::Arc; use crate::{ + AdtId, ConstParamId, GenericDefId, HasModule, ItemTreeLoc, LifetimeParamId, + LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId, db::DefDatabase, expander::Expander, item_tree::{AttrOwner, FileItemTreeId, GenericModItem, GenericsItemTreeNode, ItemTree}, @@ -30,8 +32,6 @@ use crate::{ ArrayType, ConstRef, FnType, LifetimeRef, PathId, RefType, TypeBound, TypeRef, TypeRefId, TypesMap, TypesSourceMap, }, - AdtId, ConstParamId, GenericDefId, HasModule, ItemTreeLoc, LifetimeParamId, - LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId, }; /// The index of the self param in the generic of the non-parent definition. @@ -292,11 +292,7 @@ impl GenericParams { parent: GenericDefId, ) -> Option { self.lifetimes.iter().find_map(|(id, p)| { - if &p.name == name { - Some(LifetimeParamId { local_id: id, parent }) - } else { - None - } + if &p.name == name { Some(LifetimeParamId { local_id: id, parent }) } else { None } }) } diff --git a/crates/hir-def/src/hir.rs b/crates/hir-def/src/hir.rs index 494644d8ef..cd22ae6638 100644 --- a/crates/hir-def/src/hir.rs +++ b/crates/hir-def/src/hir.rs @@ -17,7 +17,7 @@ pub mod type_ref; use std::fmt; -use hir_expand::{name::Name, MacroDefId}; +use hir_expand::{MacroDefId, name::Name}; use intern::Symbol; use la_arena::Idx; use rustc_apfloat::ieee::{Half as f16, Quad as f128}; @@ -25,10 +25,10 @@ use syntax::ast; use type_ref::TypeRefId; use crate::{ + BlockId, ConstBlockId, builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}, path::{GenericArgs, Path}, type_ref::{Mutability, Rawness}, - BlockId, ConstBlockId, }; pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp}; @@ -137,11 +137,7 @@ pub enum LiteralOrConst { impl Literal { pub fn negate(self) -> Option { - if let Literal::Int(i, k) = self { - Some(Literal::Int(-i, k)) - } else { - None - } + if let Literal::Int(i, k) = self { Some(Literal::Int(-i, k)) } else { None } } } diff --git a/crates/hir-def/src/hir/format_args.rs b/crates/hir-def/src/hir/format_args.rs index 6331861a99..821ec565cf 100644 --- a/crates/hir-def/src/hir/format_args.rs +++ b/crates/hir-def/src/hir/format_args.rs @@ -7,8 +7,8 @@ use rustc_parse_format as parse; use span::SyntaxContext; use stdx::TupleExt; use syntax::{ - ast::{self, IsString}, TextRange, + ast::{self, IsString}, }; use crate::hir::ExprId; diff --git a/crates/hir-def/src/hir/type_ref.rs b/crates/hir-def/src/hir/type_ref.rs index 6de4026dff..7bb558d345 100644 --- a/crates/hir-def/src/hir/type_ref.rs +++ b/crates/hir-def/src/hir/type_ref.rs @@ -5,25 +5,25 @@ use core::fmt; use std::{fmt::Write, ops::Index}; use hir_expand::{ + AstId, InFile, db::ExpandDatabase, name::{AsName, Name}, - AstId, InFile, }; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use la_arena::{Arena, ArenaMap, Idx}; use span::Edition; -use stdx::thin_vec::{thin_vec_with_header_struct, EmptyOptimizedThinVec, ThinVec}; +use stdx::thin_vec::{EmptyOptimizedThinVec, ThinVec, thin_vec_with_header_struct}; use syntax::{ - ast::{self, HasGenericArgs, HasName, IsString}, AstPtr, + ast::{self, HasGenericArgs, HasName, IsString}, }; use crate::{ + SyntheticSyntax, builtin_type::{BuiltinInt, BuiltinType, BuiltinUint}, hir::Literal, lower::LowerCtx, path::{GenericArg, Path}, - SyntheticSyntax, }; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] @@ -34,11 +34,7 @@ pub enum Mutability { impl Mutability { pub fn from_mutable(mutable: bool) -> Mutability { - if mutable { - Mutability::Mut - } else { - Mutability::Shared - } + if mutable { Mutability::Mut } else { Mutability::Shared } } pub fn as_keyword_for_ref(self) -> &'static str { @@ -80,11 +76,7 @@ pub enum Rawness { impl Rawness { pub fn from_raw(is_raw: bool) -> Rawness { - if is_raw { - Rawness::RawPtr - } else { - Rawness::Ref - } + if is_raw { Rawness::RawPtr } else { Rawness::Ref } } pub fn is_raw(&self) -> bool { diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs index 9e4479f05b..717566f9d7 100644 --- a/crates/hir-def/src/import_map.rs +++ b/crates/hir-def/src/import_map.rs @@ -3,21 +3,21 @@ use std::fmt; use base_db::Crate; -use fst::{raw::IndexedValue, Automaton, Streamer}; +use fst::{Automaton, Streamer, raw::IndexedValue}; use hir_expand::name::Name; use itertools::Itertools; use rustc_hash::FxHashSet; use smallvec::SmallVec; use span::Edition; -use stdx::{format_to, TupleExt}; +use stdx::{TupleExt, format_to}; use triomphe::Arc; use crate::{ + AssocItemId, FxIndexMap, ModuleDefId, ModuleId, TraitId, db::DefDatabase, item_scope::{ImportOrExternCrate, ItemInNs}, nameres::DefMap, visibility::Visibility, - AssocItemId, FxIndexMap, ModuleDefId, ModuleId, TraitId, }; /// Item import details stored in the `ImportMap`. @@ -155,11 +155,7 @@ impl ImportMap { let visible_items = mod_data.scope.entries().filter_map(|(name, per_ns)| { let per_ns = per_ns.filter_visibility(|vis| vis == Visibility::Public); - if per_ns.is_none() { - None - } else { - Some((name, per_ns)) - } + if per_ns.is_none() { None } else { Some((name, per_ns)) } }); for (name, per_ns) in visible_items { @@ -474,10 +470,10 @@ fn search_maps( #[cfg(test)] mod tests { use base_db::{RootQueryDb, Upcast}; - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use test_fixture::WithFixture; - use crate::{test_db::TestDB, ItemContainerId, Lookup}; + use crate::{ItemContainerId, Lookup, test_db::TestDB}; use super::*; diff --git a/crates/hir-def/src/item_scope.rs b/crates/hir-def/src/item_scope.rs index 0c683f3531..47ad020043 100644 --- a/crates/hir-def/src/item_scope.rs +++ b/crates/hir-def/src/item_scope.rs @@ -4,22 +4,22 @@ use std::sync::LazyLock; use base_db::Crate; -use hir_expand::{attrs::AttrId, db::ExpandDatabase, name::Name, AstId, MacroCallId}; +use hir_expand::{AstId, MacroCallId, attrs::AttrId, db::ExpandDatabase, name::Name}; use indexmap::map::Entry; use itertools::Itertools; use la_arena::Idx; use rustc_hash::{FxHashMap, FxHashSet}; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::Edition; use stdx::format_to; use syntax::ast; use crate::{ + AdtId, BuiltinType, ConstId, ExternBlockId, ExternCrateId, FxIndexMap, HasModule, ImplId, + LocalModuleId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId, db::DefDatabase, per_ns::{Item, MacrosItem, PerNs, TypesItem, ValuesItem}, visibility::{Visibility, VisibilityExplicitness}, - AdtId, BuiltinType, ConstId, ExternBlockId, ExternCrateId, FxIndexMap, HasModule, ImplId, - LocalModuleId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId, }; #[derive(Debug, Default)] diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs index b9fc9c9489..ea87b0f700 100644 --- a/crates/hir-def/src/item_tree.rs +++ b/crates/hir-def/src/item_tree.rs @@ -46,24 +46,24 @@ use std::{ use ast::{AstNode, StructKind}; use base_db::Crate; use either::Either; -use hir_expand::{attrs::RawAttrs, name::Name, ExpandTo, HirFileId, InFile}; +use hir_expand::{ExpandTo, HirFileId, InFile, attrs::RawAttrs, name::Name}; use intern::{Interned, Symbol}; use la_arena::{Arena, Idx, RawIdx}; use rustc_hash::FxHashMap; use smallvec::SmallVec; use span::{AstIdNode, Edition, FileAstId, SyntaxContext}; use stdx::never; -use syntax::{ast, match_ast, SyntaxKind}; +use syntax::{SyntaxKind, ast, match_ast}; use triomphe::Arc; use crate::{ + BlockId, LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, attr::Attrs, db::DefDatabase, generics::GenericParams, path::{GenericArgs, ImportAlias, ModPath, Path, PathKind}, type_ref::{Mutability, TraitRef, TypeBound, TypeRefId, TypesMap, TypesSourceMap}, visibility::{RawVisibility, VisibilityExplicitness}, - BlockId, LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, }; #[derive(Copy, Clone, Eq, PartialEq)] diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index 3c85d5bacb..776ee98f3b 100644 --- a/crates/hir-def/src/item_tree/lower.rs +++ b/crates/hir-def/src/item_tree/lower.rs @@ -3,23 +3,24 @@ use std::{cell::OnceCell, collections::hash_map::Entry}; use hir_expand::{ + HirFileId, mod_path::path, name::AsName, span_map::{SpanMap, SpanMapRef}, - HirFileId, }; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use la_arena::Arena; use rustc_hash::FxHashMap; use span::{AstIdMap, SyntaxContext}; use stdx::thin_vec::ThinVec; use syntax::{ - ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString}, AstNode, + ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString}, }; use triomphe::Arc; use crate::{ + LocalLifetimeParamId, LocalTypeOrConstParamId, db::DefDatabase, generics::{GenericParams, GenericParamsCollector}, item_tree::{ @@ -38,7 +39,6 @@ use crate::{ TypesMap, TypesSourceMap, }, visibility::RawVisibility, - LocalLifetimeParamId, LocalTypeOrConstParamId, }; fn id(index: Idx) -> FileItemTreeId { @@ -931,8 +931,7 @@ impl<'a> Ctx<'a> { fn desugar_future_path(ctx: &mut LowerCtx<'_>, orig: TypeRefId) -> PathId { let path = path![core::future::Future]; - let mut generic_args: Vec<_> = - std::iter::repeat_n(None, path.segments().len() - 1).collect(); + let mut generic_args: Vec<_> = std::iter::repeat_n(None, path.segments().len() - 1).collect(); let binding = AssociatedTypeBinding { name: Name::new_symbol_root(sym::Output.clone()), args: None, diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs index b442e87734..47d374a2be 100644 --- a/crates/hir-def/src/item_tree/tests.rs +++ b/crates/hir-def/src/item_tree/tests.rs @@ -1,4 +1,4 @@ -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use span::Edition; use test_fixture::WithFixture; diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs index 67788576c1..342c3fedb9 100644 --- a/crates/hir-def/src/lang_item.rs +++ b/crates/hir-def/src/lang_item.rs @@ -3,13 +3,13 @@ //! This attribute to tell the compiler about semi built-in std library //! features, such as Fn family of traits. use hir_expand::name::Name; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use rustc_hash::FxHashMap; use triomphe::Arc; use crate::{ - db::DefDatabase, path::Path, AdtId, AssocItemId, AttrDefId, Crate, EnumId, EnumVariantId, - FunctionId, ImplId, ModuleDefId, StaticId, StructId, TraitId, TypeAliasId, UnionId, + AdtId, AssocItemId, AttrDefId, Crate, EnumId, EnumVariantId, FunctionId, ImplId, ModuleDefId, + StaticId, StructId, TraitId, TypeAliasId, UnionId, db::DefDatabase, path::Path, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -164,11 +164,7 @@ impl LangItems { } } - if lang_items.items.is_empty() { - None - } else { - Some(Arc::new(lang_items)) - } + if lang_items.items.is_empty() { None } else { Some(Arc::new(lang_items)) } } /// Salsa query. Look for a lang item, starting from the specified crate and recursively @@ -230,11 +226,7 @@ pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: Crate) -> Option } } - if traits.is_empty() { - None - } else { - Some(traits.into_iter().collect()) - } + if traits.is_empty() { None } else { Some(traits.into_iter().collect()) } } pub enum GenericRequirement { diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs index 209ed46b7a..615bd33feb 100644 --- a/crates/hir-def/src/lib.rs +++ b/crates/hir-def/src/lib.rs @@ -71,25 +71,25 @@ mod test_db; use std::hash::{Hash, Hasher}; -use base_db::{impl_intern_key, Crate}; +use base_db::{Crate, impl_intern_key}; use hir_expand::{ + AstId, ExpandError, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, + MacroDefId, MacroDefKind, builtin::{BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerExpander}, db::ExpandDatabase, eager::expand_eager_macro_input, impl_intern_lookup, name::Name, proc_macro::{CustomProcMacroExpander, ProcMacroKind}, - AstId, ExpandError, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, - MacroDefId, MacroDefKind, }; use item_tree::ExternBlock; use la_arena::Idx; use nameres::DefMap; use span::{AstIdNode, Edition, FileAstId, SyntaxContext}; use stdx::impl_from; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; -pub use hir_expand::{tt, Intern, Lookup}; +pub use hir_expand::{Intern, Lookup, tt}; use crate::{ builtin_type::BuiltinType, @@ -438,11 +438,7 @@ impl ModuleId { let def_map = self.def_map(db); let parent = def_map[self.local_id].parent?; def_map[parent].children.iter().find_map(|(name, module_id)| { - if *module_id == self.local_id { - Some(name.clone()) - } else { - None - } + if *module_id == self.local_id { Some(name.clone()) } else { None } }) } diff --git a/crates/hir-def/src/lower.rs b/crates/hir-def/src/lower.rs index 7cddd48eb1..c0f6e1a686 100644 --- a/crates/hir-def/src/lower.rs +++ b/crates/hir-def/src/lower.rs @@ -1,7 +1,7 @@ //! Context for lowering paths. use std::{cell::OnceCell, mem}; -use hir_expand::{span_map::SpanMap, AstId, HirFileId, InFile}; +use hir_expand::{AstId, HirFileId, InFile, span_map::SpanMap}; use span::{AstIdMap, AstIdNode, Edition, EditionedFileId, FileId, RealSpanMap}; use stdx::thin_vec::ThinVec; use syntax::ast; diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs index 70b512c014..d9fbf4b17c 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -19,10 +19,10 @@ use std::{iter, ops::Range, sync}; use base_db::RootQueryDb; use expect_test::Expect; use hir_expand::{ + InFile, MacroCallKind, MacroFileId, MacroFileIdExt, MacroKind, db::ExpandDatabase, proc_macro::{ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind}, span_map::SpanMapRef, - InFile, MacroCallKind, MacroFileId, MacroFileIdExt, MacroKind, }; use intern::Symbol; use itertools::Itertools; @@ -30,21 +30,21 @@ use salsa::AsDynDatabase; use span::{Edition, Span}; use stdx::{format_to, format_to_acc}; use syntax::{ - ast::{self, edit::IndentLevel}, AstNode, SyntaxKind::{COMMENT, EOF, IDENT, LIFETIME_IDENT}, SyntaxNode, T, + ast::{self, edit::IndentLevel}, }; use test_fixture::WithFixture; use crate::{ + AdtId, AsMacroCall, Lookup, ModuleDefId, db::DefDatabase, nameres::{DefMap, MacroSubNs, ModuleSource}, resolver::HasResolver, src::HasSource, test_db::TestDB, tt::TopSubtree, - AdtId, AsMacroCall, Lookup, ModuleDefId, }; #[track_caller] diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs index a34766ebc1..12293f3a61 100644 --- a/crates/hir-def/src/nameres.rs +++ b/crates/hir-def/src/nameres.rs @@ -62,7 +62,7 @@ use std::ops::Deref; use base_db::Crate; use hir_expand::{ - name::Name, proc_macro::ProcMacroKind, ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId, + ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId, name::Name, proc_macro::ProcMacroKind, }; use intern::Symbol; use itertools::Itertools; @@ -70,11 +70,13 @@ use la_arena::Arena; use rustc_hash::{FxHashMap, FxHashSet}; use span::{Edition, EditionedFileId, FileAstId, FileId, ROOT_ERASED_FILE_AST_ID}; use stdx::format_to; -use syntax::{ast, AstNode, SmolStr, SyntaxNode, ToSmolStr}; +use syntax::{AstNode, SmolStr, SyntaxNode, ToSmolStr, ast}; use triomphe::Arc; use tt::TextRange; use crate::{ + AstId, BlockId, BlockLoc, CrateRootModuleId, EnumId, EnumVariantId, ExternCrateId, FunctionId, + FxIndexMap, LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId, db::DefDatabase, item_scope::{BuiltinShadowMode, ItemScope}, item_tree::{ItemTreeId, Mod, TreeId}, @@ -82,8 +84,6 @@ use crate::{ path::ModPath, per_ns::PerNs, visibility::{Visibility, VisibilityExplicitness}, - AstId, BlockId, BlockLoc, CrateRootModuleId, EnumId, EnumVariantId, ExternCrateId, FunctionId, - FxIndexMap, LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId, }; pub use self::path_resolution::ResolvePathResultPrefixInfo; diff --git a/crates/hir-def/src/nameres/assoc.rs b/crates/hir-def/src/nameres/assoc.rs index dea6d334f8..1b3d10f098 100644 --- a/crates/hir-def/src/nameres/assoc.rs +++ b/crates/hir-def/src/nameres/assoc.rs @@ -1,25 +1,25 @@ //! Expansion of associated items use hir_expand::{ - name::Name, AstId, ExpandResult, InFile, Intern, Lookup, MacroCallKind, MacroDefKind, + AstId, ExpandResult, InFile, Intern, Lookup, MacroCallKind, MacroDefKind, name::Name, }; use smallvec::SmallVec; use span::{HirFileId, MacroCallId}; -use syntax::{ast, Parse}; +use syntax::{Parse, ast}; use triomphe::Arc; use crate::{ + AssocItemId, AstIdWithPath, ConstLoc, FunctionId, FunctionLoc, ImplId, ItemContainerId, + ItemLoc, ModuleId, TraitId, TypeAliasId, TypeAliasLoc, db::DefDatabase, expander::{Expander, Mark}, item_tree::{self, AssocItem, ItemTree, ItemTreeId, MacroCall, ModItem, TreeId}, macro_call_as_call_id, nameres::{ + DefMap, LocalDefMap, MacroSubNs, attr_resolution::ResolvedAttr, diagnostics::{DefDiagnostic, DefDiagnostics}, - DefMap, LocalDefMap, MacroSubNs, }, - AssocItemId, AstIdWithPath, ConstLoc, FunctionId, FunctionLoc, ImplId, ItemContainerId, - ItemLoc, ModuleId, TraitId, TypeAliasId, TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/hir-def/src/nameres/attr_resolution.rs b/crates/hir-def/src/nameres/attr_resolution.rs index c35a7fdc96..7820c6fcbe 100644 --- a/crates/hir-def/src/nameres/attr_resolution.rs +++ b/crates/hir-def/src/nameres/attr_resolution.rs @@ -2,20 +2,20 @@ use base_db::Crate; use hir_expand::{ + MacroCallId, MacroCallKind, MacroDefId, attrs::{Attr, AttrId, AttrInput}, inert_attr_macro::find_builtin_attr_idx, - MacroCallId, MacroCallKind, MacroDefId, }; use span::SyntaxContext; use syntax::ast; use triomphe::Arc; use crate::{ + AstIdWithPath, LocalModuleId, MacroId, UnresolvedMacro, db::DefDatabase, item_scope::BuiltinShadowMode, - nameres::{path_resolution::ResolveMode, LocalDefMap}, + nameres::{LocalDefMap, path_resolution::ResolveMode}, path::{self, ModPath, PathKind}, - AstIdWithPath, LocalModuleId, MacroId, UnresolvedMacro, }; use super::{DefMap, MacroSubNs}; diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 43b011e57f..045a869540 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -9,15 +9,15 @@ use base_db::{BuiltDependency, Crate, CrateOrigin, LangCrateOrigin}; use cfg::{CfgAtom, CfgExpr, CfgOptions}; use either::Either; use hir_expand::{ + ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, + MacroFileIdExt, attrs::{Attr, AttrId}, builtin::{find_builtin_attr, find_builtin_derive, find_builtin_macro}, name::{AsName, Name}, proc_macro::CustomProcMacroExpander, - ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, - MacroFileIdExt, }; -use intern::{sym, Interned}; -use itertools::{izip, Itertools}; +use intern::{Interned, sym}; +use itertools::{Itertools, izip}; use la_arena::Idx; use rustc_hash::{FxHashMap, FxHashSet}; use span::{Edition, EditionedFileId, FileAstId, SyntaxContext}; @@ -25,6 +25,12 @@ use syntax::ast; use triomphe::Arc; use crate::{ + AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantLoc, + ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern, + ItemContainerId, LocalModuleId, Lookup, Macro2Id, Macro2Loc, MacroExpander, MacroId, + MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ModuleDefId, ModuleId, ProcMacroId, + ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, + UnresolvedMacro, UseId, UseLoc, attr::Attrs, db::DefDatabase, item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports}, @@ -34,24 +40,18 @@ use crate::{ }, macro_call_as_call_id, macro_call_as_call_id_with_eager, nameres::{ + BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, ModuleData, ModuleOrigin, ResolveMode, attr_resolution::{attr_macro_as_call_id, derive_macro_as_call_id}, diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, - proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroDef, ProcMacroKind}, - sub_namespace_match, BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, ModuleData, - ModuleOrigin, ResolveMode, + proc_macro::{ProcMacroDef, ProcMacroKind, parse_macro_name_and_helper_attrs}, + sub_namespace_match, }, path::{ImportAlias, ModPath, PathKind}, per_ns::{Item, PerNs}, tt, visibility::{RawVisibility, Visibility}, - AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantLoc, - ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern, - ItemContainerId, LocalModuleId, Lookup, Macro2Id, Macro2Loc, MacroExpander, MacroId, - MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ModuleDefId, ModuleId, ProcMacroId, - ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, - UnresolvedMacro, UseId, UseLoc, }; const GLOB_RECURSION_LIMIT: usize = 100; diff --git a/crates/hir-def/src/nameres/diagnostics.rs b/crates/hir-def/src/nameres/diagnostics.rs index bc1617c55b..1744d3465b 100644 --- a/crates/hir-def/src/nameres/diagnostics.rs +++ b/crates/hir-def/src/nameres/diagnostics.rs @@ -3,15 +3,15 @@ use std::ops::Not; use cfg::{CfgExpr, CfgOptions}; -use hir_expand::{attrs::AttrId, ExpandErrorKind, MacroCallKind}; +use hir_expand::{ExpandErrorKind, MacroCallKind, attrs::AttrId}; use la_arena::Idx; use syntax::ast; use crate::{ + AstId, item_tree::{self, AttrOwner, ItemTreeId, TreeId}, nameres::LocalModuleId, path::ModPath, - AstId, }; #[derive(Debug, PartialEq, Eq)] diff --git a/crates/hir-def/src/nameres/mod_resolution.rs b/crates/hir-def/src/nameres/mod_resolution.rs index a012eb6ff7..97db89d1e7 100644 --- a/crates/hir-def/src/nameres/mod_resolution.rs +++ b/crates/hir-def/src/nameres/mod_resolution.rs @@ -1,10 +1,10 @@ //! This module resolves `mod foo;` declaration to file. use arrayvec::ArrayVec; use base_db::{AnchoredPath, RootQueryDb}; -use hir_expand::{name::Name, HirFileIdExt}; +use hir_expand::{HirFileIdExt, name::Name}; use span::EditionedFileId; -use crate::{db::DefDatabase, HirFileId}; +use crate::{HirFileId, db::DefDatabase}; const MOD_DEPTH_LIMIT: usize = 32; diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs index 977bc16adf..e7cb91300b 100644 --- a/crates/hir-def/src/nameres/path_resolution.rs +++ b/crates/hir-def/src/nameres/path_resolution.rs @@ -11,19 +11,19 @@ //! `ReachedFixedPoint` signals about this. use either::Either; -use hir_expand::{name::Name, Lookup}; +use hir_expand::{Lookup, name::Name}; use span::Edition; use triomphe::Arc; use crate::{ + AdtId, LocalModuleId, ModuleDefId, db::DefDatabase, - item_scope::{ImportOrExternCrate, BUILTIN_SCOPE}, + item_scope::{BUILTIN_SCOPE, ImportOrExternCrate}, item_tree::FieldsShape, - nameres::{sub_namespace_match, BlockInfo, BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs}, + nameres::{BlockInfo, BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, sub_namespace_match}, path::{ModPath, PathKind}, per_ns::PerNs, visibility::{RawVisibility, Visibility}, - AdtId, LocalModuleId, ModuleDefId, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -356,7 +356,7 @@ impl DefMap { PathKind::Abs => match self.resolve_path_abs(local_def_map, &mut segments, path) { Either::Left(it) => it, Either::Right(reached_fixed_point) => { - return ResolvePathResult::empty(reached_fixed_point) + return ResolvePathResult::empty(reached_fixed_point); } }, }; @@ -402,11 +402,11 @@ impl DefMap { PathKind::Abs => match self.resolve_path_abs(local_def_map, &mut segments, path) { Either::Left(it) => it, Either::Right(reached_fixed_point) => { - return ResolvePathResult::empty(reached_fixed_point) + return ResolvePathResult::empty(reached_fixed_point); } }, PathKind::DollarCrate(_) | PathKind::Crate | PathKind::Super(_) => { - return ResolvePathResult::empty(ReachedFixedPoint::Yes) + return ResolvePathResult::empty(ReachedFixedPoint::Yes); } }; diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs index 7c9fad9186..3fd095a9a9 100644 --- a/crates/hir-def/src/nameres/tests.rs +++ b/crates/hir-def/src/nameres/tests.rs @@ -5,7 +5,7 @@ mod mod_resolution; mod primitives; use base_db::RootQueryDb; -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use test_fixture::WithFixture; use triomphe::Arc; diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs index 9a601e0f01..bd25d0bd58 100644 --- a/crates/hir-def/src/nameres/tests/incremental.rs +++ b/crates/hir-def/src/nameres/tests/incremental.rs @@ -7,7 +7,7 @@ use span::Edition; use test_fixture::WithFixture; use triomphe::Arc; -use crate::{db::DefDatabase, nameres::tests::TestDB, AdtId, ModuleDefId}; +use crate::{AdtId, ModuleDefId, db::DefDatabase, nameres::tests::TestDB}; fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) { let (mut db, pos) = TestDB::with_position(ra_fixture_initial); diff --git a/crates/hir-def/src/path.rs b/crates/hir-def/src/path.rs index 713e738973..ec2c8d12aa 100644 --- a/crates/hir-def/src/path.rs +++ b/crates/hir-def/src/path.rs @@ -19,7 +19,7 @@ use span::Edition; use stdx::thin_vec::thin_vec_with_header_struct; use syntax::ast; -pub use hir_expand::mod_path::{path, ModPath, PathKind}; +pub use hir_expand::mod_path::{ModPath, PathKind, path}; pub use lower::hir_segment_to_ast_segment; diff --git a/crates/hir-def/src/path/lower.rs b/crates/hir-def/src/path/lower.rs index 7a6d697329..ef0ef0e823 100644 --- a/crates/hir-def/src/path/lower.rs +++ b/crates/hir-def/src/path/lower.rs @@ -8,7 +8,7 @@ use hir_expand::{ mod_path::resolve_crate_root, name::{AsName, Name}, }; -use intern::{sym, Interned}; +use intern::{Interned, sym}; use stdx::thin_vec::EmptyOptimizedThinVec; use syntax::ast::{self, AstNode, HasGenericArgs, HasTypeBounds}; diff --git a/crates/hir-def/src/path/tests.rs b/crates/hir-def/src/path/tests.rs index 67a27bf85e..c0bfb0c872 100644 --- a/crates/hir-def/src/path/tests.rs +++ b/crates/hir-def/src/path/tests.rs @@ -1,4 +1,4 @@ -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use span::Edition; use syntax::ast::{self, make}; use test_fixture::WithFixture; @@ -6,8 +6,8 @@ use test_fixture::WithFixture; use crate::{ lower::LowerCtx, path::{ - lower::{hir_segment_to_ast_segment, SEGMENT_LOWERING_MAP}, Path, + lower::{SEGMENT_LOWERING_MAP, hir_segment_to_ast_segment}, }, pretty, test_db::TestDB, diff --git a/crates/hir-def/src/per_ns.rs b/crates/hir-def/src/per_ns.rs index c2d3f67f17..1f7dd6f0c4 100644 --- a/crates/hir-def/src/per_ns.rs +++ b/crates/hir-def/src/per_ns.rs @@ -6,9 +6,9 @@ use bitflags::bitflags; use crate::{ + MacroId, ModuleDefId, item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ItemInNs}, visibility::Visibility, - MacroId, ModuleDefId, }; #[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)] @@ -146,11 +146,7 @@ impl PerNs { } pub fn or_else(self, f: impl FnOnce() -> PerNs) -> PerNs { - if self.is_full() { - self - } else { - self.or(f()) - } + if self.is_full() { self } else { self.or(f()) } } pub fn iter_items(self) -> impl Iterator)> { diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs index 997a12a328..28ebaadf4d 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -2,36 +2,36 @@ use std::{fmt, iter, mem}; use base_db::Crate; -use hir_expand::{name::Name, MacroDefId}; -use intern::{sym, Symbol}; +use hir_expand::{MacroDefId, name::Name}; +use intern::{Symbol, sym}; use itertools::Itertools as _; use rustc_hash::FxHashSet; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::SyntaxContext; use triomphe::Arc; use crate::{ + AdtId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, + ExternBlockId, ExternCrateId, FunctionId, FxIndexMap, GenericDefId, GenericParamId, HasModule, + ImplId, ItemContainerId, ItemTreeLoc, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, + MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, + TraitId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId, VariantId, builtin_type::BuiltinType, data::ExternCrateDeclData, db::DefDatabase, expr_store::{ - scope::{ExprScopes, ScopeId}, HygieneId, + scope::{ExprScopes, ScopeId}, }, generics::{GenericParams, TypeOrConstParamData}, hir::{BindingId, ExprId, LabelId}, - item_scope::{BuiltinShadowMode, ImportOrExternCrate, ImportOrGlob, BUILTIN_SCOPE}, + item_scope::{BUILTIN_SCOPE, BuiltinShadowMode, ImportOrExternCrate, ImportOrGlob}, lang_item::LangItemTarget, nameres::{DefMap, LocalDefMap, MacroSubNs, ResolvePathResultPrefixInfo}, path::{ModPath, Path, PathKind}, per_ns::PerNs, type_ref::{LifetimeRef, TypesMap}, visibility::{RawVisibility, Visibility}, - AdtId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, - ExternBlockId, ExternCrateId, FunctionId, FxIndexMap, GenericDefId, GenericParamId, HasModule, - ImplId, ItemContainerId, ItemTreeLoc, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, - MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, - TraitId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId, VariantId, }; #[derive(Debug, Clone)] @@ -209,11 +209,7 @@ impl Resolver { } let remaining_idx = || { - if path.segments().len() == 1 { - None - } else { - Some(1) - } + if path.segments().len() == 1 { None } else { Some(1) } }; for scope in self.scopes() { diff --git a/crates/hir-def/src/src.rs b/crates/hir-def/src/src.rs index 347c4803be..3867f39b8b 100644 --- a/crates/hir-def/src/src.rs +++ b/crates/hir-def/src/src.rs @@ -3,13 +3,13 @@ use either::Either; use hir_expand::InFile; use la_arena::ArenaMap; -use syntax::{ast, AstNode, AstPtr}; +use syntax::{AstNode, AstPtr, ast}; use crate::{ - db::DefDatabase, - item_tree::{AttrOwner, FieldParent, ItemTreeNode}, GenericDefId, ItemTreeLoc, LocalFieldId, LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, UseId, VariantId, + db::DefDatabase, + item_tree::{AttrOwner, FieldParent, ItemTreeNode}, }; pub trait HasSource { diff --git a/crates/hir-def/src/test_db.rs b/crates/hir-def/src/test_db.rs index 0b97e6c9ce..91cadb0e81 100644 --- a/crates/hir-def/src/test_db.rs +++ b/crates/hir-def/src/test_db.rs @@ -6,17 +6,17 @@ use base_db::{ Crate, CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, RootQueryDb, SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast, }; -use hir_expand::{db::ExpandDatabase, files::FilePosition, InFile}; +use hir_expand::{InFile, db::ExpandDatabase, files::FilePosition}; use salsa::{AsDynDatabase, Durability}; use span::{EditionedFileId, FileId}; -use syntax::{algo, ast, AstNode}; +use syntax::{AstNode, algo, ast}; use triomphe::Arc; use crate::{ + LocalModuleId, Lookup, ModuleDefId, ModuleId, db::DefDatabase, nameres::{DefMap, ModuleSource}, src::HasSource, - LocalModuleId, Lookup, ModuleDefId, ModuleId, }; #[salsa::db] diff --git a/crates/hir-def/src/visibility.rs b/crates/hir-def/src/visibility.rs index 86a2d02a9f..f4729a4f8e 100644 --- a/crates/hir-def/src/visibility.rs +++ b/crates/hir-def/src/visibility.rs @@ -9,11 +9,11 @@ use syntax::ast; use triomphe::Arc; use crate::{ + ConstId, FunctionId, HasModule, LocalFieldId, LocalModuleId, ModuleId, VariantId, db::DefDatabase, nameres::DefMap, path::{ModPath, PathKind}, resolver::HasResolver, - ConstId, FunctionId, HasModule, LocalFieldId, LocalModuleId, ModuleId, VariantId, }; /// Visibility of an item, not yet resolved. diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs index 6bfef1d28b..862e3c7305 100644 --- a/crates/hir-expand/src/attrs.rs +++ b/crates/hir-expand/src/attrs.rs @@ -4,23 +4,23 @@ use std::{borrow::Cow, fmt, ops}; use base_db::Crate; use cfg::CfgExpr; use either::Either; -use intern::{sym, Interned, Symbol}; +use intern::{Interned, Symbol, sym}; use mbe::{DelimiterKind, Punct}; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::{Span, SyntaxContext}; use syntax::unescape; -use syntax::{ast, match_ast, AstNode, AstToken, SyntaxNode}; -use syntax_bridge::{desugar_doc_comment_text, syntax_node_to_token_tree, DocCommentDesugarMode}; +use syntax::{AstNode, AstToken, SyntaxNode, ast, match_ast}; +use syntax_bridge::{DocCommentDesugarMode, desugar_doc_comment_text, syntax_node_to_token_tree}; use triomphe::ThinArc; use crate::name::Name; use crate::{ + InFile, db::ExpandDatabase, mod_path::ModPath, span_map::SpanMapRef, - tt::{self, token_to_literal, TopSubtree}, - InFile, + tt::{self, TopSubtree, token_to_literal}, }; /// Syntactical attributes, without filtering of `cfg_attr`s. diff --git a/crates/hir-expand/src/builtin.rs b/crates/hir-expand/src/builtin.rs index 7b9b7f36e2..0bf4943b60 100644 --- a/crates/hir-expand/src/builtin.rs +++ b/crates/hir-expand/src/builtin.rs @@ -7,9 +7,9 @@ mod derive_macro; mod fn_macro; pub use self::{ - attr_macro::{find_builtin_attr, pseudo_derive_attr_expansion, BuiltinAttrExpander}, - derive_macro::{find_builtin_derive, BuiltinDeriveExpander}, + attr_macro::{BuiltinAttrExpander, find_builtin_attr, pseudo_derive_attr_expansion}, + derive_macro::{BuiltinDeriveExpander, find_builtin_derive}, fn_macro::{ - find_builtin_macro, include_input_to_file_id, BuiltinFnLikeExpander, EagerExpander, + BuiltinFnLikeExpander, EagerExpander, find_builtin_macro, include_input_to_file_id, }, }; diff --git a/crates/hir-expand/src/builtin/attr_macro.rs b/crates/hir-expand/src/builtin/attr_macro.rs index e9dc17a28f..0463ce11f6 100644 --- a/crates/hir-expand/src/builtin/attr_macro.rs +++ b/crates/hir-expand/src/builtin/attr_macro.rs @@ -2,7 +2,7 @@ use intern::sym; use span::{MacroCallId, Span}; -use crate::{db::ExpandDatabase, name, tt, ExpandResult, MacroCallKind}; +use crate::{ExpandResult, MacroCallKind, db::ExpandDatabase, name, tt}; use super::quote; @@ -130,7 +130,7 @@ fn derive_expand( return ExpandResult::ok(tt::TopSubtree::empty(tt::DelimSpan { open: span, close: span, - })) + })); } }; pseudo_derive_attr_expansion(tt, derives, span) diff --git a/crates/hir-expand/src/builtin/derive_macro.rs b/crates/hir-expand/src/builtin/derive_macro.rs index 149ab73ec5..b6181e8ce8 100644 --- a/crates/hir-expand/src/builtin/derive_macro.rs +++ b/crates/hir-expand/src/builtin/derive_macro.rs @@ -1,7 +1,7 @@ //! Builtin derives. use intern::sym; -use itertools::{izip, Itertools}; +use itertools::{Itertools, izip}; use parser::SyntaxKind; use rustc_hash::FxHashSet; use span::{Edition, MacroCallId, Span, SyntaxContext}; @@ -10,17 +10,18 @@ use syntax_bridge::DocCommentDesugarMode; use tracing::debug; use crate::{ + ExpandError, ExpandResult, builtin::quote::{dollar_crate, quote}, db::ExpandDatabase, hygiene::span_with_def_site_ctxt, name::{self, AsName, Name}, span_map::ExpansionSpanMap, - tt, ExpandError, ExpandResult, + tt, }; use syntax::{ ast::{ - self, edit_in_place::GenericParamsOwnerEdit, make, AstNode, FieldList, HasAttrs, - HasGenericArgs, HasGenericParams, HasModuleItem, HasName, HasTypeBounds, + self, AstNode, FieldList, HasAttrs, HasGenericArgs, HasGenericParams, HasModuleItem, + HasName, HasTypeBounds, edit_in_place::GenericParamsOwnerEdit, make, }, ted, }; @@ -464,7 +465,7 @@ fn expand_simple_derive( return ExpandResult::new( tt::TopSubtree::empty(tt::DelimSpan { open: invoc_span, close: invoc_span }), e, - ) + ); } }; ExpandResult::ok(expand_simple_derive_with_parsed( @@ -1072,7 +1073,7 @@ fn coerce_pointee_expand( "exactly one generic type parameter must be marked \ as `#[pointee]` to derive `CoercePointee` traits", ), - ) + ); } (Some(_), Some(_)) => { return ExpandResult::new( @@ -1082,7 +1083,7 @@ fn coerce_pointee_expand( "only one type parameter can be marked as `#[pointee]` \ when deriving `CoercePointee` traits", ), - ) + ); } } }; @@ -1120,7 +1121,9 @@ fn coerce_pointee_expand( tt::TopSubtree::empty(tt::DelimSpan::from_single(span)), ExpandError::other( span, - format!("`derive(CoercePointee)` requires `{pointee_param_name}` to be marked `?Sized`"), + format!( + "`derive(CoercePointee)` requires `{pointee_param_name}` to be marked `?Sized`" + ), ), ); } @@ -1335,7 +1338,7 @@ fn coerce_pointee_expand( let info = match parse_adt_from_syntax(&adt, &span_map, span) { Ok(it) => it, Err(err) => { - return ExpandResult::new(tt::TopSubtree::empty(tt::DelimSpan::from_single(span)), err) + return ExpandResult::new(tt::TopSubtree::empty(tt::DelimSpan::from_single(span)), err); } }; diff --git a/crates/hir-expand/src/builtin/fn_macro.rs b/crates/hir-expand/src/builtin/fn_macro.rs index 2fb1f96350..e83d9abf83 100644 --- a/crates/hir-expand/src/builtin/fn_macro.rs +++ b/crates/hir-expand/src/builtin/fn_macro.rs @@ -4,26 +4,26 @@ use base_db::AnchoredPath; use cfg::CfgExpr; use either::Either; use intern::{ - sym::{self}, Symbol, + sym::{self}, }; -use mbe::{expect_fragment, DelimiterKind}; +use mbe::{DelimiterKind, expect_fragment}; use span::{Edition, EditionedFileId, FileId, Span}; use stdx::format_to; use syntax::{ format_smolstr, - unescape::{unescape_byte, unescape_char, unescape_unicode, Mode}, + unescape::{Mode, unescape_byte, unescape_char, unescape_unicode}, }; use syntax_bridge::syntax_node_to_token_tree; use crate::{ - builtin::quote::{dollar_crate, quote, WithDelimiter}, + ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId, + builtin::quote::{WithDelimiter, dollar_crate, quote}, db::ExpandDatabase, hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt}, name, span_map::SpanMap, tt::{self, DelimSpan, TtElement, TtIter}, - ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId, }; macro_rules! register_builtin { @@ -427,12 +427,15 @@ fn compile_error_expand( span: Span, ) -> ExpandResult { let err = match &*tt.0 { - [_, tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { - symbol: text, - span: _, - kind: tt::LitKind::Str | tt::LitKind::StrRaw(_), - suffix: _, - }))] => ExpandError::other(span, Box::from(unescape_str(text).as_str())), + [ + _, + tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { + symbol: text, + span: _, + kind: tt::LitKind::Str | tt::LitKind::StrRaw(_), + suffix: _, + })), + ] => ExpandError::other(span, Box::from(unescape_str(text).as_str())), _ => ExpandError::other(span, "`compile_error!` argument must be a string"), }; @@ -736,7 +739,7 @@ fn include_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: span, close: span }), e, - ) + ); } }; let span_map = db.real_span_map(editioned_file_id); @@ -789,7 +792,7 @@ fn include_str_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: span, close: span }), e, - ) + ); } }; @@ -827,7 +830,7 @@ fn env_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: span, close: span }), e, - ) + ); } }; @@ -865,7 +868,7 @@ fn option_env_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: call_site, close: call_site }), e, - ) + ); } }; let dollar_crate = dollar_crate(call_site); diff --git a/crates/hir-expand/src/builtin/quote.rs b/crates/hir-expand/src/builtin/quote.rs index 9dd2b77b52..859f6f7b14 100644 --- a/crates/hir-expand/src/builtin/quote.rs +++ b/crates/hir-expand/src/builtin/quote.rs @@ -1,7 +1,7 @@ //! A simplified version of quote-crate like quasi quote macro #![allow(clippy::crate_in_macro_def)] -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use span::Span; use syntax::ToSmolStr; use tt::IdentIsRaw; @@ -226,7 +226,7 @@ mod tests { use ::tt::IdentIsRaw; use expect_test::expect; use intern::Symbol; - use span::{Edition, SpanAnchor, SyntaxContext, ROOT_ERASED_FILE_AST_ID}; + use span::{Edition, ROOT_ERASED_FILE_AST_ID, SpanAnchor, SyntaxContext}; use syntax::{TextRange, TextSize}; use super::quote; @@ -324,6 +324,9 @@ mod tests { } }; - assert_eq!(quoted.to_string(), "impl Clone for Foo {fn clone (& self) -> Self {Self {name : self . name . clone () , id : self . id . clone () ,}}}"); + assert_eq!( + quoted.to_string(), + "impl Clone for Foo {fn clone (& self) -> Self {Self {name : self . name . clone () , id : self . id . clone () ,}}}" + ); } } diff --git a/crates/hir-expand/src/cfg_process.rs b/crates/hir-expand/src/cfg_process.rs index 0ceab3c890..c6ea4a3a33 100644 --- a/crates/hir-expand/src/cfg_process.rs +++ b/crates/hir-expand/src/cfg_process.rs @@ -3,15 +3,15 @@ use std::iter::Peekable; use base_db::Crate; use cfg::{CfgAtom, CfgExpr}; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use rustc_hash::FxHashSet; use syntax::{ - ast::{self, Attr, HasAttrs, Meta, TokenTree, VariantList}, AstNode, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, T, + ast::{self, Attr, HasAttrs, Meta, TokenTree, VariantList}, }; use tracing::{debug, warn}; -use crate::{db::ExpandDatabase, proc_macro::ProcMacroKind, MacroCallLoc, MacroDefKind}; +use crate::{MacroCallLoc, MacroDefKind, db::ExpandDatabase, proc_macro::ProcMacroKind}; fn check_cfg(db: &dyn ExpandDatabase, attr: &Attr, krate: Crate) -> Option { if !attr.simple_name().as_deref().map(|v| v == "cfg")? { @@ -344,8 +344,8 @@ where #[cfg(test)] mod tests { use cfg::DnfExpr; - use expect_test::{expect, Expect}; - use syntax::{ast::Attr, AstNode, SourceFile}; + use expect_test::{Expect, expect}; + use syntax::{AstNode, SourceFile, ast::Attr}; use crate::cfg_process::parse_from_attr_token_tree; diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index 85c242a790..2fe251d298 100644 --- a/crates/hir-expand/src/db.rs +++ b/crates/hir-expand/src/db.rs @@ -9,25 +9,26 @@ use span::{ AstIdMap, Edition, EditionedFileId, HirFileId, HirFileIdRepr, MacroCallId, MacroFileId, Span, SyntaxContext, }; -use syntax::{ast, AstNode, Parse, SyntaxElement, SyntaxError, SyntaxNode, SyntaxToken, T}; -use syntax_bridge::{syntax_node_to_token_tree, DocCommentDesugarMode}; +use syntax::{AstNode, Parse, SyntaxElement, SyntaxError, SyntaxNode, SyntaxToken, T, ast}; +use syntax_bridge::{DocCommentDesugarMode, syntax_node_to_token_tree}; use triomphe::Arc; use crate::{ - attrs::{collect_attrs, AttrId}, + AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo, + EagerExpander, ExpandError, ExpandResult, ExpandTo, MacroCallKind, MacroCallLoc, MacroDefId, + MacroDefKind, + attrs::{AttrId, collect_attrs}, builtin::pseudo_derive_attr_expansion, cfg_process, declarative::DeclarativeMacroExpander, fixup::{self, SyntaxFixupUndoInfo}, hygiene::{ - span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt, - SyntaxContextExt as _, + SyntaxContextExt as _, span_with_call_site_ctxt, span_with_def_site_ctxt, + span_with_mixed_site_ctxt, }, proc_macro::{CrateProcMacros, CustomProcMacroExpander, ProcMacros}, span_map::{ExpansionSpanMap, RealSpanMap, SpanMap, SpanMapRef}, - tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo, - EagerExpander, ExpandError, ExpandResult, ExpandTo, MacroCallKind, MacroCallLoc, MacroDefId, - MacroDefKind, + tt, }; /// This is just to ensure the types of smart_macro_arg and macro_arg are the same type MacroArgResult = (Arc, SyntaxFixupUndoInfo, Span); @@ -397,11 +398,7 @@ fn parse_macro_expansion_error( ) -> Option>>> { let e: ExpandResult> = db.parse_macro_expansion(MacroFileId { macro_call_id }).map(|it| Arc::from(it.0.errors())); - if e.value.is_empty() && e.err.is_none() { - None - } else { - Some(Arc::new(e)) - } + if e.value.is_empty() && e.err.is_none() { None } else { Some(Arc::new(e)) } } pub(crate) fn parse_with_map( diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs index a0b614add4..063410230d 100644 --- a/crates/hir-expand/src/declarative.rs +++ b/crates/hir-expand/src/declarative.rs @@ -4,15 +4,16 @@ use base_db::Crate; use intern::sym; use span::{Edition, HirFileIdRepr, MacroCallId, Span, SyntaxContext}; use stdx::TupleExt; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use syntax_bridge::DocCommentDesugarMode; use triomphe::Arc; use crate::{ + AstId, ExpandError, ExpandErrorKind, ExpandResult, Lookup, attrs::RawAttrs, db::ExpandDatabase, - hygiene::{apply_mark, Transparency}, - tt, AstId, ExpandError, ExpandErrorKind, ExpandResult, Lookup, + hygiene::{Transparency, apply_mark}, + tt, }; /// Old-style `macro_rules` or the new macros 2.0 diff --git a/crates/hir-expand/src/eager.rs b/crates/hir-expand/src/eager.rs index fcf3929eaa..dd824e6fd0 100644 --- a/crates/hir-expand/src/eager.rs +++ b/crates/hir-expand/src/eager.rs @@ -20,16 +20,16 @@ //! See the full discussion : use base_db::Crate; use span::SyntaxContext; -use syntax::{ted, Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent}; +use syntax::{Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent, ted}; use syntax_bridge::DocCommentDesugarMode; use triomphe::Arc; use crate::{ + AstId, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, + MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind, ast::{self, AstNode}, db::ExpandDatabase, mod_path::ModPath, - AstId, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, - MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind, }; pub fn expand_eager_macro_input( diff --git a/crates/hir-expand/src/files.rs b/crates/hir-expand/src/files.rs index 3a26c62e1f..c34570fcb5 100644 --- a/crates/hir-expand/src/files.rs +++ b/crates/hir-expand/src/files.rs @@ -9,8 +9,9 @@ use span::{ use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize}; use crate::{ + MacroFileIdExt, MacroKind, db::{self, ExpandDatabase}, - map_node_range_up, map_node_range_up_rooted, span_for_offset, MacroFileIdExt, MacroKind, + map_node_range_up, map_node_range_up_rooted, span_for_offset, }; /// `InFile` stores a value of `T` inside a particular file/syntax tree. @@ -365,11 +366,7 @@ impl InFile { // FIXME: Figure out an API that makes proper use of ctx, this only exists to // keep pre-token map rewrite behaviour. - if ctxt.is_root() { - Some(range) - } else { - None - } + if ctxt.is_root() { Some(range) } else { None } } } } diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs index 076dd75cde..740152892b 100644 --- a/crates/hir-expand/src/fixup.rs +++ b/crates/hir-expand/src/fixup.rs @@ -4,13 +4,14 @@ use intern::sym; use rustc_hash::{FxHashMap, FxHashSet}; use span::{ - ErasedFileAstId, Span, SpanAnchor, SyntaxContext, FIXUP_ERASED_FILE_AST_ID_MARKER, - ROOT_ERASED_FILE_AST_ID, + ErasedFileAstId, FIXUP_ERASED_FILE_AST_ID_MARKER, ROOT_ERASED_FILE_AST_ID, Span, SpanAnchor, + SyntaxContext, }; use stdx::never; use syntax::{ + SyntaxElement, SyntaxKind, SyntaxNode, TextRange, TextSize, ast::{self, AstNode, HasLoopBody}, - match_ast, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, TextSize, + match_ast, }; use syntax_bridge::DocCommentDesugarMode; use triomphe::Arc; @@ -465,7 +466,7 @@ fn reverse_fixups_(tt: &mut TopSubtree, undo_info: &[TopSubtree]) { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use span::{Edition, EditionedFileId, FileId}; use syntax::TextRange; use syntax_bridge::DocCommentDesugarMode; diff --git a/crates/hir-expand/src/hygiene.rs b/crates/hir-expand/src/hygiene.rs index 20694e7d6b..d684a2f9ce 100644 --- a/crates/hir-expand/src/hygiene.rs +++ b/crates/hir-expand/src/hygiene.rs @@ -147,7 +147,7 @@ pub trait SyntaxContextExt { fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext; fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext; fn remove_mark(&mut self, db: &dyn ExpandDatabase) - -> (Option, Transparency); + -> (Option, Transparency); fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option, Transparency); fn marks(self, db: &dyn ExpandDatabase) -> Vec<(span::MacroCallId, Transparency)>; fn is_opaque(self, db: &dyn ExpandDatabase) -> bool; diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index ca5c40c9fa..d089d4c49e 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -40,15 +40,15 @@ use span::{ SyntaxContext, }; use syntax::{ - ast::{self, AstNode}, SyntaxNode, SyntaxToken, TextRange, TextSize, + ast::{self, AstNode}, }; use crate::{ attrs::AttrId, builtin::{ - include_input_to_file_id, BuiltinAttrExpander, BuiltinDeriveExpander, - BuiltinFnLikeExpander, EagerExpander, + BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerExpander, + include_input_to_file_id, }, db::ExpandDatabase, mod_path::ModPath, @@ -67,7 +67,7 @@ pub use span::{HirFileId, MacroCallId, MacroFileId}; pub mod tt { pub use span::Span; - pub use tt::{token_to_literal, DelimiterKind, IdentIsRaw, LitKind, Spacing}; + pub use tt::{DelimiterKind, IdentIsRaw, LitKind, Spacing, token_to_literal}; pub type Delimiter = ::tt::Delimiter; pub type DelimSpan = ::tt::DelimSpan; @@ -207,7 +207,9 @@ impl ExpandErrorKind { kind: RenderedExpandError::GENERAL_KIND, }, None => RenderedExpandError { - message: format!("internal error: proc-macro map is missing error entry for crate {def_crate:?}"), + message: format!( + "internal error: proc-macro map is missing error entry for crate {def_crate:?}" + ), error: true, kind: RenderedExpandError::GENERAL_KIND, }, @@ -389,7 +391,7 @@ impl HirFileIdExt for HirFileId { loop { match call.file_id.repr() { HirFileIdRepr::FileId(file_id) => { - break Some(InRealFile { file_id, value: call.value }) + break Some(InRealFile { file_id, value: call.value }); } HirFileIdRepr::MacroFile(MacroFileId { macro_call_id }) => { call = db.lookup_intern_macro_call(macro_call_id).to_node(db); diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs index 5c160240a2..7f8dc0dba6 100644 --- a/crates/hir-expand/src/mod_path.rs +++ b/crates/hir-expand/src/mod_path.rs @@ -7,7 +7,7 @@ use std::{ use crate::{ db::ExpandDatabase, - hygiene::{marks_rev, SyntaxContextExt, Transparency}, + hygiene::{SyntaxContextExt, Transparency, marks_rev}, name::{AsName, Name}, tt, }; @@ -15,7 +15,7 @@ use base_db::Crate; use intern::sym; use smallvec::SmallVec; use span::{Edition, SyntaxContext}; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ModPath { diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs index 79860a002a..23ca77f5a0 100644 --- a/crates/hir-expand/src/name.rs +++ b/crates/hir-expand/src/name.rs @@ -2,7 +2,7 @@ use std::fmt; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use span::{Edition, SyntaxContext}; use syntax::utils::is_raw_identifier; use syntax::{ast, format_smolstr}; diff --git a/crates/hir-expand/src/prettify_macro_expansion_.rs b/crates/hir-expand/src/prettify_macro_expansion_.rs index f398b070f7..953aea65b2 100644 --- a/crates/hir-expand/src/prettify_macro_expansion_.rs +++ b/crates/hir-expand/src/prettify_macro_expansion_.rs @@ -3,7 +3,7 @@ use base_db::Crate; use rustc_hash::FxHashMap; use syntax::NodeOrToken; -use syntax::{ast::make, SyntaxNode}; +use syntax::{SyntaxNode, ast::make}; use crate::{db::ExpandDatabase, span_map::ExpansionSpanMap}; diff --git a/crates/hir-expand/src/proc_macro.rs b/crates/hir-expand/src/proc_macro.rs index 1330f6af9f..9dcd5ef1ef 100644 --- a/crates/hir-expand/src/proc_macro.rs +++ b/crates/hir-expand/src/proc_macro.rs @@ -10,7 +10,7 @@ use rustc_hash::FxHashMap; use span::Span; use triomphe::Arc; -use crate::{db::ExpandDatabase, tt, ExpandError, ExpandErrorKind, ExpandResult}; +use crate::{ExpandError, ExpandErrorKind, ExpandResult, db::ExpandDatabase, tt}; #[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Debug, Hash)] pub enum ProcMacroKind { @@ -298,7 +298,7 @@ impl CustomProcMacroExpander { call_site, "internal error: no proc macros for crate", ), - ) + ); } }; let proc_macro = match proc_macros.get(id, call_site) { @@ -310,7 +310,7 @@ impl CustomProcMacroExpander { close: call_site, }), e, - ) + ); } }; diff --git a/crates/hir-expand/src/span_map.rs b/crates/hir-expand/src/span_map.rs index 55fe42e271..1965e76707 100644 --- a/crates/hir-expand/src/span_map.rs +++ b/crates/hir-expand/src/span_map.rs @@ -2,7 +2,7 @@ use span::{EditionedFileId, HirFileId, HirFileIdRepr, MacroFileId, Span, SyntaxContext}; use stdx::TupleExt; -use syntax::{ast, AstNode, TextRange}; +use syntax::{AstNode, TextRange, ast}; use triomphe::Arc; pub use span::RealSpanMap; diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs index 2c27f5e3bb..8f3526f1d4 100644 --- a/crates/hir-ty/src/autoderef.rs +++ b/crates/hir-ty/src/autoderef.rs @@ -12,8 +12,8 @@ use intern::sym; use triomphe::Arc; use crate::{ - db::HirDatabase, infer::unify::InferenceTable, Canonical, Goal, Interner, ProjectionTyExt, - TraitEnvironment, Ty, TyBuilder, TyKind, + Canonical, Goal, Interner, ProjectionTyExt, TraitEnvironment, Ty, TyBuilder, TyKind, + db::HirDatabase, infer::unify::InferenceTable, }; const AUTODEREF_RECURSION_LIMIT: usize = 20; diff --git a/crates/hir-ty/src/builder.rs b/crates/hir-ty/src/builder.rs index 4c35db0c9b..2898ab7b49 100644 --- a/crates/hir-ty/src/builder.rs +++ b/crates/hir-ty/src/builder.rs @@ -3,21 +3,21 @@ use std::iter; use chalk_ir::{ + AdtId, DebruijnIndex, Scalar, cast::{Cast, CastTo, Caster}, fold::TypeFoldable, interner::HasInterner, - AdtId, DebruijnIndex, Scalar, }; use hir_def::{ - builtin_type::BuiltinType, DefWithBodyId, GenericDefId, GenericParamId, TraitId, TypeAliasId, + DefWithBodyId, GenericDefId, GenericParamId, TraitId, TypeAliasId, builtin_type::BuiltinType, }; use smallvec::SmallVec; use crate::{ - consteval::unknown_const_as_generic, db::HirDatabase, error_lifetime, generics::generics, - infer::unify::InferenceTable, primitive, to_assoc_type_id, to_chalk_trait_id, Binders, - BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy, Substitution, - TraitRef, Ty, TyDefId, TyExt, TyKind, + Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy, + Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind, consteval::unknown_const_as_generic, + db::HirDatabase, error_lifetime, generics::generics, infer::unify::InferenceTable, primitive, + to_assoc_type_id, to_chalk_trait_id, }; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs index acaca24f54..e0975b5aeb 100644 --- a/crates/hir-ty/src/chalk_db.rs +++ b/crates/hir-ty/src/chalk_db.rs @@ -8,31 +8,32 @@ use intern::sym; use span::Edition; use tracing::debug; -use chalk_ir::{cast::Caster, fold::shift::Shift, CanonicalVarKinds}; +use chalk_ir::{CanonicalVarKinds, cast::Caster, fold::shift::Shift}; use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; use base_db::Crate; use hir_def::{ - data::{adt::StructFlags, TraitFlags}, - hir::Movability, - lang_item::{LangItem, LangItemTarget}, AssocItemId, BlockId, CallableDefId, GenericDefId, HasModule, ItemContainerId, Lookup, TypeAliasId, VariantId, + data::{TraitFlags, adt::StructFlags}, + hir::Movability, + lang_item::{LangItem, LangItemTarget}, }; use crate::{ + AliasEq, AliasTy, BoundVar, DebruijnIndex, FnDefId, Interner, ProjectionTy, ProjectionTyExt, + QuantifiedWhereClause, Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, + WhereClause, db::{HirDatabase, InternedCoroutine}, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, generics::generics, make_binders, make_single_type_binders, - mapping::{from_chalk, ToChalk, TypeAliasAsValue}, - method_resolution::{TraitImpls, TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, + mapping::{ToChalk, TypeAliasAsValue, from_chalk}, + method_resolution::{ALL_FLOAT_FPS, ALL_INT_FPS, TraitImpls, TyFingerprint}, to_assoc_type_id, to_chalk_trait_id, traits::ChalkContext, utils::ClosureSubst, - wrap_empty_binders, AliasEq, AliasTy, BoundVar, DebruijnIndex, FnDefId, Interner, ProjectionTy, - ProjectionTyExt, QuantifiedWhereClause, Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, - TyExt, TyKind, WhereClause, + wrap_empty_binders, }; pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum; diff --git a/crates/hir-ty/src/chalk_ext.rs b/crates/hir-ty/src/chalk_ext.rs index 51c178b90d..49dde30309 100644 --- a/crates/hir-ty/src/chalk_ext.rs +++ b/crates/hir-ty/src/chalk_ext.rs @@ -1,22 +1,22 @@ //! Various extensions traits for Chalk types. use chalk_ir::{ - cast::Cast, FloatTy, IntTy, Mutability, Scalar, TyVariableKind, TypeOutlives, UintTy, + FloatTy, IntTy, Mutability, Scalar, TyVariableKind, TypeOutlives, UintTy, cast::Cast, }; use hir_def::{ + DefWithBodyId, FunctionId, GenericDefId, HasModule, ItemContainerId, Lookup, TraitId, builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType, BuiltinUint}, generics::TypeOrConstParamData, lang_item::LangItem, type_ref::Rawness, - DefWithBodyId, FunctionId, GenericDefId, HasModule, ItemContainerId, Lookup, TraitId, }; use crate::{ - db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, - from_placeholder_idx, generics::generics, to_chalk_trait_id, utils::ClosureSubst, AdtId, - AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, ClosureId, - DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy, + AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, + ClosureId, DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy, QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeFlags, WhereClause, + db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, + from_placeholder_idx, generics::generics, to_chalk_trait_id, utils::ClosureSubst, }; pub trait TyExt { diff --git a/crates/hir-ty/src/consteval.rs b/crates/hir-ty/src/consteval.rs index ec8f9b7c31..48c23aff78 100644 --- a/crates/hir-ty/src/consteval.rs +++ b/crates/hir-ty/src/consteval.rs @@ -1,14 +1,14 @@ //! Constant evaluation details use base_db::Crate; -use chalk_ir::{cast::Cast, BoundVar, DebruijnIndex}; +use chalk_ir::{BoundVar, DebruijnIndex, cast::Cast}; use hir_def::{ + ConstBlockLoc, EnumVariantId, GeneralConstId, HasModule as _, StaticId, expr_store::{Body, HygieneId}, hir::{Expr, ExprId}, path::Path, resolver::{Resolver, ValueNs}, type_ref::LiteralConstRef, - ConstBlockLoc, EnumVariantId, GeneralConstId, HasModule as _, StaticId, }; use hir_expand::Lookup; use salsa::Cycle; @@ -16,17 +16,18 @@ use stdx::never; use triomphe::Arc; use crate::{ + Const, ConstData, ConstScalar, ConstValue, GenericArg, Interner, MemoryMap, Substitution, + TraitEnvironment, Ty, TyBuilder, db::{HirDatabase, HirDatabaseData}, display::DisplayTarget, generics::Generics, infer::InferenceContext, lower::ParamLoweringMode, mir::monomorphize_mir_body_bad, - to_placeholder_idx, Const, ConstData, ConstScalar, ConstValue, GenericArg, Interner, MemoryMap, - Substitution, TraitEnvironment, Ty, TyBuilder, + to_placeholder_idx, }; -use super::mir::{interpret_mir, lower_to_mir, pad16, MirEvalError, MirLowerError}; +use super::mir::{MirEvalError, MirLowerError, interpret_mir, lower_to_mir, pad16}; /// Extension trait for [`Const`] pub trait ConstExt { diff --git a/crates/hir-ty/src/consteval/tests.rs b/crates/hir-ty/src/consteval/tests.rs index d679f9dd7c..8049897f31 100644 --- a/crates/hir-ty/src/consteval/tests.rs +++ b/crates/hir-ty/src/consteval/tests.rs @@ -2,16 +2,16 @@ use base_db::RootQueryDb; use chalk_ir::Substitution; use hir_def::db::DefDatabase; use rustc_apfloat::{ - ieee::{Half as f16, Quad as f128}, Float, + ieee::{Half as f16, Quad as f128}, }; use span::EditionedFileId; use test_fixture::WithFixture; use test_utils::skip_slow_tests; use crate::{ - consteval::try_const_usize, db::HirDatabase, display::DisplayTarget, mir::pad16, - test_db::TestDB, Const, ConstScalar, Interner, MemoryMap, + Const, ConstScalar, Interner, MemoryMap, consteval::try_const_usize, db::HirDatabase, + display::DisplayTarget, mir::pad16, test_db::TestDB, }; use super::{ diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs index 8f48cfc432..6c61979475 100644 --- a/crates/hir-ty/src/db.rs +++ b/crates/hir-ty/src/db.rs @@ -3,11 +3,12 @@ use std::sync; -use base_db::{impl_intern_key, Crate, Upcast}; +use base_db::{Crate, Upcast, impl_intern_key}; use hir_def::{ - db::DefDatabase, hir::ExprId, layout::TargetDataLayout, AdtId, BlockId, CallableDefId, - ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GeneralConstId, GenericDefId, ImplId, - LifetimeParamId, LocalFieldId, StaticId, TraitId, TypeAliasId, TypeOrConstParamId, VariantId, + AdtId, BlockId, CallableDefId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, + GeneralConstId, GenericDefId, ImplId, LifetimeParamId, LocalFieldId, StaticId, TraitId, + TypeAliasId, TypeOrConstParamId, VariantId, db::DefDatabase, hir::ExprId, + layout::TargetDataLayout, }; use hir_expand::name::Name; use la_arena::ArenaMap; @@ -16,7 +17,8 @@ use smallvec::SmallVec; use triomphe::Arc; use crate::{ - chalk_db, + Binders, ClosureId, Const, FnDefId, ImplTraitId, ImplTraits, InferenceResult, Interner, + PolyFnSig, Substitution, TraitEnvironment, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db, consteval::ConstEvalError, drop::DropGlue, dyn_compatibility::DynCompatibilityViolation, @@ -24,8 +26,6 @@ use crate::{ lower::{Diagnostics, GenericDefaults, GenericPredicates}, method_resolution::{InherentImpls, TraitImpls, TyFingerprint}, mir::{BorrowckResult, MirBody, MirLowerError}, - Binders, ClosureId, Const, FnDefId, ImplTraitId, ImplTraits, InferenceResult, Interner, - PolyFnSig, Substitution, TraitEnvironment, TraitRef, Ty, TyDefId, ValueTyDefId, }; #[query_group::query_group] @@ -262,7 +262,7 @@ pub trait HirDatabase: DefDatabase + Upcast + std::fmt::Debug { #[salsa::invoke(chalk_db::impl_datum_query)] fn impl_datum(&self, krate: Crate, impl_id: chalk_db::ImplId) - -> sync::Arc; + -> sync::Arc; #[salsa::invoke(chalk_db::fn_def_datum_query)] fn fn_def_datum(&self, fn_def_id: FnDefId) -> sync::Arc; diff --git a/crates/hir-ty/src/diagnostics.rs b/crates/hir-ty/src/diagnostics.rs index 845d333335..047a348fb0 100644 --- a/crates/hir-ty/src/diagnostics.rs +++ b/crates/hir-ty/src/diagnostics.rs @@ -5,12 +5,12 @@ mod match_check; mod unsafe_check; pub use crate::diagnostics::{ - decl_check::{incorrect_case, CaseType, IncorrectCase}, + decl_check::{CaseType, IncorrectCase, incorrect_case}, expr::{ - record_literal_missing_fields, record_pattern_missing_fields, BodyValidationDiagnostic, + BodyValidationDiagnostic, record_literal_missing_fields, record_pattern_missing_fields, }, unsafe_check::{ - missing_unsafe, unsafe_operations, unsafe_operations_for_body, InsideUnsafeBlock, - UnsafetyReason, + InsideUnsafeBlock, UnsafetyReason, missing_unsafe, unsafe_operations, + unsafe_operations_for_body, }, }; diff --git a/crates/hir-ty/src/diagnostics/decl_check.rs b/crates/hir-ty/src/diagnostics/decl_check.rs index 5106056d40..ce0ffb1792 100644 --- a/crates/hir-ty/src/diagnostics/decl_check.rs +++ b/crates/hir-ty/src/diagnostics/decl_check.rs @@ -16,20 +16,20 @@ mod case_conv; use std::fmt; use hir_def::{ - data::adt::VariantData, db::DefDatabase, hir::Pat, src::HasSource, AdtId, ConstId, EnumId, - EnumVariantId, FunctionId, HasModule, ItemContainerId, Lookup, ModuleDefId, ModuleId, StaticId, - StructId, TraitId, TypeAliasId, + AdtId, ConstId, EnumId, EnumVariantId, FunctionId, HasModule, ItemContainerId, Lookup, + ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, data::adt::VariantData, + db::DefDatabase, hir::Pat, src::HasSource, }; use hir_expand::{ - name::{AsName, Name}, HirFileId, HirFileIdExt, + name::{AsName, Name}, }; use intern::sym; use stdx::{always, never}; use syntax::{ + AstNode, AstPtr, ToSmolStr, ast::{self, HasName}, utils::is_raw_identifier, - AstNode, AstPtr, ToSmolStr, }; use crate::db::HirDatabase; diff --git a/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs b/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs index 348f8a0f4a..234c7e4b03 100644 --- a/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs +++ b/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs @@ -97,7 +97,7 @@ fn is_snake_case bool>(ident: &str, wrong_case: F) -> bool { #[cfg(test)] mod tests { use super::*; - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; fn check Option>(fun: F, input: &str, expect: Expect) { // `None` is translated to empty string, meaning that there is nothing to fix. diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs index 6096439565..51b404be81 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -8,36 +8,36 @@ use base_db::Crate; use chalk_solve::rust_ir::AdtKind; use either::Either; use hir_def::{ + AdtId, AssocItemId, DefWithBodyId, HasModule, ItemContainerId, Lookup, lang_item::LangItem, resolver::{HasResolver, ValueNs}, - AdtId, AssocItemId, DefWithBodyId, HasModule, ItemContainerId, Lookup, }; use intern::sym; use itertools::Itertools; use rustc_hash::FxHashSet; use rustc_pattern_analysis::constructor::Constructor; use syntax::{ - ast::{self, UnaryOp}, AstNode, + ast::{self, UnaryOp}, }; use tracing::debug; use triomphe::Arc; use typed_arena::Arena; use crate::{ + Adjust, InferenceResult, Interner, Ty, TyExt, TyKind, db::HirDatabase, diagnostics::match_check::{ self, pat_analysis::{self, DeconstructedPat, MatchCheckCtx, WitnessPat}, }, display::{DisplayTarget, HirDisplay}, - Adjust, InferenceResult, Interner, Ty, TyExt, TyKind, }; pub(crate) use hir_def::{ + LocalFieldId, VariantId, expr_store::Body, hir::{Expr, ExprId, MatchArm, Pat, PatId, Statement}, - LocalFieldId, VariantId, }; pub enum BodyValidationDiagnostic { diff --git a/crates/hir-ty/src/diagnostics/match_check.rs b/crates/hir-ty/src/diagnostics/match_check.rs index b0f9fc53e2..1c58485eb9 100644 --- a/crates/hir-ty/src/diagnostics/match_check.rs +++ b/crates/hir-ty/src/diagnostics/match_check.rs @@ -11,19 +11,19 @@ pub(crate) mod pat_analysis; use chalk_ir::Mutability; use hir_def::{ - data::adt::VariantData, expr_store::Body, hir::PatId, AdtId, EnumVariantId, LocalFieldId, - VariantId, + AdtId, EnumVariantId, LocalFieldId, VariantId, data::adt::VariantData, expr_store::Body, + hir::PatId, }; use hir_expand::name::Name; use span::Edition; use stdx::{always, never}; use crate::{ + InferenceResult, Interner, Substitution, Ty, TyExt, TyKind, db::HirDatabase, display::{HirDisplay, HirDisplayError, HirFormatter}, infer::BindingMode, lang_items::is_box, - InferenceResult, Interner, Substitution, Ty, TyExt, TyKind, }; use self::pat_util::EnumerateAndAdjustIterator; diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs index b7f8a0c610..683a48bfc9 100644 --- a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs +++ b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs @@ -6,21 +6,21 @@ use std::fmt; use hir_def::{DefWithBodyId, EnumId, EnumVariantId, HasModule, LocalFieldId, ModuleId, VariantId}; use intern::sym; use rustc_pattern_analysis::{ - constructor::{Constructor, ConstructorSet, VariantVisibility}, - usefulness::{compute_match_usefulness, PlaceValidity, UsefulnessReport}, Captures, IndexVec, PatCx, PrivateUninhabitedField, + constructor::{Constructor, ConstructorSet, VariantVisibility}, + usefulness::{PlaceValidity, UsefulnessReport, compute_match_usefulness}, }; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use stdx::never; use crate::{ + AdtId, Interner, Scalar, Ty, TyExt, TyKind, db::HirDatabase, infer::normalize, inhabitedness::{is_enum_variant_uninhabited_from, is_ty_uninhabited_from}, - AdtId, Interner, Scalar, Ty, TyExt, TyKind, }; -use super::{is_box, FieldPat, Pat, PatKind}; +use super::{FieldPat, Pat, PatKind, is_box}; use Constructor::*; diff --git a/crates/hir-ty/src/diagnostics/unsafe_check.rs b/crates/hir-ty/src/diagnostics/unsafe_check.rs index 84dd4be67f..562a9aa085 100644 --- a/crates/hir-ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir-ty/src/diagnostics/unsafe_check.rs @@ -5,18 +5,18 @@ use std::mem; use either::Either; use hir_def::{ + AdtId, DefWithBodyId, FieldId, FunctionId, VariantId, expr_store::Body, hir::{Expr, ExprId, ExprOrPatId, Pat, PatId, Statement, UnaryOp}, path::Path, resolver::{HasResolver, ResolveValueResult, Resolver, ValueNs}, type_ref::Rawness, - AdtId, DefWithBodyId, FieldId, FunctionId, VariantId, }; use span::Edition; use crate::{ - db::HirDatabase, utils::is_fn_unsafe_to_call, InferenceResult, Interner, TargetFeatures, TyExt, - TyKind, + InferenceResult, Interner, TargetFeatures, TyExt, TyKind, db::HirDatabase, + utils::is_fn_unsafe_to_call, }; #[derive(Debug, Default)] diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index 7bce23f398..b2e13ba692 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -11,6 +11,8 @@ use base_db::Crate; use chalk_ir::{BoundVar, Safety, TyKind}; use either::Either; use hir_def::{ + GenericDefId, HasModule, ImportPathConfig, ItemContainerId, LocalFieldId, Lookup, ModuleDefId, + ModuleId, TraitId, data::adt::VariantData, db::DefDatabase, find_path::{self, PrefixKind}, @@ -23,16 +25,14 @@ use hir_def::{ TraitBoundModifier, TypeBound, TypeRef, TypeRefId, TypesMap, TypesSourceMap, UseArgRef, }, visibility::Visibility, - GenericDefId, HasModule, ImportPathConfig, ItemContainerId, LocalFieldId, Lookup, ModuleDefId, - ModuleId, TraitId, }; use hir_expand::name::Name; -use intern::{sym, Internable, Interned}; +use intern::{Internable, Interned, sym}; use itertools::Itertools; use la_arena::ArenaMap; use rustc_apfloat::{ - ieee::{Half as f16, Quad as f128}, Float, + ieee::{Half as f16, Quad as f128}, }; use rustc_hash::FxHashSet; use smallvec::SmallVec; @@ -41,6 +41,11 @@ use stdx::never; use triomphe::Arc; use crate::{ + AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, ConcreteConst, Const, + ConstScalar, ConstValue, DomainGoal, FnAbi, GenericArg, ImplTraitId, Interner, Lifetime, + LifetimeData, LifetimeOutlives, MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, + QuantifiedWhereClause, Scalar, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, + TyExt, WhereClause, consteval::try_const_usize, db::{HirDatabase, InternedClosure}, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, @@ -51,12 +56,7 @@ use crate::{ mapping::from_chalk, mir::pad16, primitive, to_assoc_type_id, - utils::{self, detect_variant_from_bytes, ClosureSubst}, - AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, ConcreteConst, Const, - ConstScalar, ConstValue, DomainGoal, FnAbi, GenericArg, ImplTraitId, Interner, Lifetime, - LifetimeData, LifetimeOutlives, MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, - QuantifiedWhereClause, Scalar, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, - TyExt, WhereClause, + utils::{self, ClosureSubst, detect_variant_from_bytes}, }; pub trait HirWrite: fmt::Write { @@ -529,7 +529,9 @@ where Err(HirDisplayError::FmtError) => Err(fmt::Error), Err(HirDisplayError::DisplaySourceCodeError(_)) => { // This should never happen - panic!("HirDisplay::hir_fmt failed with DisplaySourceCodeError when calling Display::fmt!") + panic!( + "HirDisplay::hir_fmt failed with DisplaySourceCodeError when calling Display::fmt!" + ) } } } @@ -1381,7 +1383,7 @@ impl HirDisplay for Ty { match f.closure_style { ClosureStyle::Hide => return write!(f, "{TYPE_HINT_TRUNCATION}"), ClosureStyle::ClosureWithId => { - return write!(f, "{{closure#{:?}}}", id.0.as_u32()) + return write!(f, "{{closure#{:?}}}", id.0.as_u32()); } ClosureStyle::ClosureWithSubst => { write!(f, "{{closure#{:?}}}", id.0.as_u32())?; diff --git a/crates/hir-ty/src/drop.rs b/crates/hir-ty/src/drop.rs index ab17f86b5b..5484a39324 100644 --- a/crates/hir-ty/src/drop.rs +++ b/crates/hir-ty/src/drop.rs @@ -1,16 +1,16 @@ //! Utilities for computing drop info about types. use chalk_ir::cast::Cast; +use hir_def::AdtId; use hir_def::data::adt::StructFlags; use hir_def::lang_item::LangItem; -use hir_def::AdtId; use stdx::never; use triomphe::Arc; use crate::db::HirDatabaseData; use crate::{ - db::HirDatabase, method_resolution::TyFingerprint, AliasTy, Canonical, CanonicalVarKinds, - InEnvironment, Interner, ProjectionTy, TraitEnvironment, Ty, TyBuilder, TyKind, + AliasTy, Canonical, CanonicalVarKinds, InEnvironment, Interner, ProjectionTy, TraitEnvironment, + Ty, TyBuilder, TyKind, db::HirDatabase, method_resolution::TyFingerprint, }; use crate::{ConcreteConst, ConstScalar, ConstValue}; @@ -176,11 +176,7 @@ fn projection_has_drop_glue( let normalized = db.normalize_projection(projection, env.clone()); match normalized.kind(Interner) { TyKind::Alias(AliasTy::Projection(_)) | TyKind::AssociatedType(..) => { - if is_copy(db, ty, env) { - DropGlue::None - } else { - DropGlue::DependOnParams - } + if is_copy(db, ty, env) { DropGlue::None } else { DropGlue::DependOnParams } } _ => db.has_drop_glue(normalized, env), } diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs index af16a2499b..cb186c45ad 100644 --- a/crates/hir-ty/src/dyn_compatibility.rs +++ b/crates/hir-ty/src/dyn_compatibility.rs @@ -3,28 +3,27 @@ use std::ops::ControlFlow; use chalk_ir::{ + DebruijnIndex, cast::Cast, visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, - DebruijnIndex, }; use chalk_solve::rust_ir::InlineBound; use hir_def::{ - data::TraitFlags, lang_item::LangItem, AssocItemId, ConstId, FunctionId, GenericDefId, - HasModule, TraitId, TypeAliasId, + AssocItemId, ConstId, FunctionId, GenericDefId, HasModule, TraitId, TypeAliasId, + data::TraitFlags, lang_item::LangItem, }; use rustc_hash::FxHashSet; use smallvec::SmallVec; use crate::{ - all_super_traits, + AliasEq, AliasTy, Binders, BoundVar, CallableSig, GoalData, ImplTraitId, Interner, OpaqueTyId, + ProjectionTyExt, Solution, Substitution, TraitRef, Ty, TyKind, WhereClause, all_super_traits, db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, generics::{generics, trait_self_param_idx}, lower::callable_item_sig, to_assoc_type_id, to_chalk_trait_id, utils::elaborate_clause_supertraits, - AliasEq, AliasTy, Binders, BoundVar, CallableSig, GoalData, ImplTraitId, Interner, OpaqueTyId, - ProjectionTyExt, Solution, Substitution, TraitRef, Ty, TyKind, WhereClause, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -558,11 +557,7 @@ fn receiver_for_self_ty(db: &dyn HirDatabase, func: FunctionId, ty: Ty) -> Optio let subst = Substitution::from_iter( Interner, subst.iter(Interner).enumerate().map(|(idx, arg)| { - if idx == trait_self_idx { - ty.clone().cast(Interner) - } else { - arg.clone() - } + if idx == trait_self_idx { ty.clone().cast(Interner) } else { arg.clone() } }), ); let sig = callable_item_sig(db, func.into()); diff --git a/crates/hir-ty/src/generics.rs b/crates/hir-ty/src/generics.rs index 18cf6e5ce3..9ed9817dfa 100644 --- a/crates/hir-ty/src/generics.rs +++ b/crates/hir-ty/src/generics.rs @@ -9,22 +9,22 @@ //! where parent follows the same scheme. use std::ops; -use chalk_ir::{cast::Cast as _, BoundVar, DebruijnIndex}; +use chalk_ir::{BoundVar, DebruijnIndex, cast::Cast as _}; use hir_def::{ + ConstParamId, GenericDefId, GenericParamId, ItemContainerId, LifetimeParamId, + LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId, db::DefDatabase, generics::{ GenericParamDataRef, GenericParams, LifetimeParamData, TypeOrConstParamData, TypeParamProvenance, }, type_ref::TypesMap, - ConstParamId, GenericDefId, GenericParamId, ItemContainerId, LifetimeParamId, - LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId, }; use itertools::chain; use stdx::TupleExt; use triomphe::Arc; -use crate::{db::HirDatabase, lt_to_placeholder_idx, to_placeholder_idx, Interner, Substitution}; +use crate::{Interner, Substitution, db::HirDatabase, lt_to_placeholder_idx, to_placeholder_idx}; pub fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics { let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def))); diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index ecadfccf00..7388d2ab43 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -26,14 +26,16 @@ pub(crate) mod unify; use std::{cell::OnceCell, convert::identity, iter, ops::Index}; use chalk_ir::{ + DebruijnIndex, Mutability, Safety, Scalar, TyKind, TypeFlags, Variance, cast::Cast, fold::TypeFoldable, interner::HasInterner, visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, - DebruijnIndex, Mutability, Safety, Scalar, TyKind, TypeFlags, Variance, }; use either::Either; use hir_def::{ + AdtId, AssocItemId, DefWithBodyId, FieldId, FunctionId, ImplId, ItemContainerId, Lookup, + TraitId, TupleFieldId, TupleId, TypeAliasId, VariantId, builtin_type::{BuiltinInt, BuiltinType, BuiltinUint}, data::{ConstData, StaticData}, expr_store::{Body, HygieneId}, @@ -43,8 +45,6 @@ use hir_def::{ path::{ModPath, Path}, resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs}, type_ref::{LifetimeRef, TypeRefId, TypesMap}, - AdtId, AssocItemId, DefWithBodyId, FieldId, FunctionId, ImplId, ItemContainerId, Lookup, - TraitId, TupleFieldId, TupleId, TypeAliasId, VariantId, }; use hir_expand::name::Name; use indexmap::IndexSet; @@ -55,6 +55,9 @@ use stdx::{always, never}; use triomphe::Arc; use crate::{ + AliasEq, AliasTy, Binders, ClosureId, Const, DomainGoal, GenericArg, Goal, ImplTraitId, + ImplTraitIdx, InEnvironment, Interner, Lifetime, OpaqueTyId, ParamLoweringMode, + PathLoweringDiagnostic, ProjectionTy, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, db::HirDatabase, fold_tys, generics::Generics, @@ -64,14 +67,11 @@ use crate::{ expr::ExprIsRead, unify::InferenceTable, }, - lower::{diagnostics::TyLoweringDiagnostic, ImplTraitLoweringMode}, + lower::{ImplTraitLoweringMode, diagnostics::TyLoweringDiagnostic}, mir::MirSpan, to_assoc_type_id, traits::FnTrait, utils::{InTypeConstIdMetadata, UnevaluatedConstEvaluatorFolder}, - AliasEq, AliasTy, Binders, ClosureId, Const, DomainGoal, GenericArg, Goal, ImplTraitId, - ImplTraitIdx, InEnvironment, Interner, Lifetime, OpaqueTyId, ParamLoweringMode, - PathLoweringDiagnostic, ProjectionTy, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, }; // This lint has a false positive here. See the link below for details. @@ -1190,11 +1190,7 @@ impl<'a> InferenceContext<'a> { if let Some(impl_id) = impl_id { taits.extend(collector.assocs.into_iter().filter_map(|(id, (impl_, ty))| { - if impl_ == impl_id { - Some((id, ty)) - } else { - None - } + if impl_ == impl_id { Some((id, ty)) } else { None } })); } @@ -1914,11 +1910,7 @@ impl Expectation { match self { Expectation::HasType(ety) => { let ety = table.resolve_ty_shallow(ety); - if ety.is_ty_var() { - Expectation::None - } else { - Expectation::HasType(ety) - } + if ety.is_ty_var() { Expectation::None } else { Expectation::HasType(ety) } } Expectation::RValueLikeUnsized(ety) => Expectation::RValueLikeUnsized(ety.clone()), _ => Expectation::None, @@ -2044,7 +2036,7 @@ impl chalk_ir::zip::Zipper for UnknownMismatch<'_> { | (_, TyKind::Error) | (TyKind::Alias(AliasTy::Projection(_)) | TyKind::AssociatedType(_, _), _) | (_, TyKind::Alias(AliasTy::Projection(_)) | TyKind::AssociatedType(_, _)) => { - return Err(chalk_ir::NoSolution) + return Err(chalk_ir::NoSolution); } _ => (), } diff --git a/crates/hir-ty/src/infer/cast.rs b/crates/hir-ty/src/infer/cast.rs index 8b43d0188a..d3de86f038 100644 --- a/crates/hir-ty/src/infer/cast.rs +++ b/crates/hir-ty/src/infer/cast.rs @@ -1,13 +1,13 @@ //! Type cast logic. Basically coercion + additional casts. use chalk_ir::{Mutability, Scalar, TyVariableKind, UintTy}; -use hir_def::{hir::ExprId, AdtId}; +use hir_def::{AdtId, hir::ExprId}; use stdx::never; use crate::{ - infer::{coerce::CoerceNever, unify::InferenceTable}, Adjustment, Binders, DynTy, InferenceDiagnostic, Interner, PlaceholderIndex, QuantifiedWhereClauses, Ty, TyExt, TyKind, TypeFlags, WhereClause, + infer::{coerce::CoerceNever, unify::InferenceTable}, }; #[derive(Debug)] @@ -431,8 +431,8 @@ fn contains_dyn_trait(ty: &Ty) -> bool { use std::ops::ControlFlow; use chalk_ir::{ - visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, DebruijnIndex, + visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, }; struct DynTraitVisitor; diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index 9ae6e0a174..69de555214 100644 --- a/crates/hir-ty/src/infer/closure.rs +++ b/crates/hir-ty/src/infer/closure.rs @@ -3,12 +3,13 @@ use std::{cmp, convert::Infallible, mem}; use chalk_ir::{ + BoundVar, DebruijnIndex, FnSubst, Mutability, TyKind, cast::Cast, fold::{FallibleTypeFolder, TypeFoldable}, - BoundVar, DebruijnIndex, FnSubst, Mutability, TyKind, }; use either::Either; use hir_def::{ + DefWithBodyId, FieldId, HasModule, TupleFieldId, TupleId, VariantId, data::adt::VariantData, hir::{ Array, AsmOperand, BinaryOp, BindingId, CaptureBy, Expr, ExprId, ExprOrPatId, Pat, PatId, @@ -17,16 +18,18 @@ use hir_def::{ lang_item::LangItem, path::Path, resolver::ValueNs, - DefWithBodyId, FieldId, HasModule, TupleFieldId, TupleId, VariantId, }; use hir_expand::name::Name; use intern::sym; use rustc_hash::FxHashMap; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use stdx::{format_to, never}; use syntax::utils::is_raw_identifier; use crate::{ + Adjust, Adjustment, AliasEq, AliasTy, Binders, BindingMode, ChalkTraitId, ClosureId, DynTy, + DynTyExt, FnAbi, FnPointer, FnSig, Interner, OpaqueTy, ProjectionTyExt, Substitution, Ty, + TyExt, WhereClause, db::{HirDatabase, InternedClosure}, error_lifetime, from_chalk_trait_id, from_placeholder_idx, generics::Generics, @@ -36,9 +39,6 @@ use crate::{ to_chalk_trait_id, traits::FnTrait, utils::{self, elaborate_clause_supertraits}, - Adjust, Adjustment, AliasEq, AliasTy, Binders, BindingMode, ChalkTraitId, ClosureId, DynTy, - DynTyExt, FnAbi, FnPointer, FnSig, Interner, OpaqueTy, ProjectionTyExt, Substitution, Ty, - TyExt, WhereClause, }; use super::{Expectation, InferenceContext}; diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs index acd86b1f3e..b0fb01a84d 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -7,7 +7,7 @@ use std::iter; -use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyKind, TyVariableKind}; +use chalk_ir::{BoundVar, Goal, Mutability, TyKind, TyVariableKind, cast::Cast}; use hir_def::{ hir::ExprId, lang_item::{LangItem, LangItemTarget}, @@ -16,6 +16,8 @@ use stdx::always; use triomphe::Arc; use crate::{ + Canonical, DomainGoal, FnAbi, FnPointer, FnSig, Guidance, InEnvironment, Interner, Lifetime, + Solution, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, autoderef::{Autoderef, AutoderefKind}, db::HirDatabase, infer::{ @@ -23,8 +25,6 @@ use crate::{ TypeError, TypeMismatch, }, utils::ClosureSubst, - Canonical, DomainGoal, FnAbi, FnPointer, FnSig, Guidance, InEnvironment, Interner, Lifetime, - Solution, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, }; use super::unify::InferenceTable; diff --git a/crates/hir-ty/src/infer/diagnostics.rs b/crates/hir-ty/src/infer/diagnostics.rs index e4f5b5ed37..563c5699cf 100644 --- a/crates/hir-ty/src/infer/diagnostics.rs +++ b/crates/hir-ty/src/infer/diagnostics.rs @@ -6,13 +6,13 @@ use std::cell::RefCell; use std::ops::{Deref, DerefMut}; use either::Either; -use hir_def::{hir::ExprOrPatId, path::Path, resolver::Resolver, type_ref::TypesMap, TypeOwnerId}; +use hir_def::{TypeOwnerId, hir::ExprOrPatId, path::Path, resolver::Resolver, type_ref::TypesMap}; use la_arena::{Idx, RawIdx}; use crate::{ + InferenceDiagnostic, InferenceTyDiagnosticSource, TyLoweringContext, TyLoweringDiagnostic, db::HirDatabase, lower::path::{PathDiagnosticCallback, PathLoweringContext}, - InferenceDiagnostic, InferenceTyDiagnosticSource, TyLoweringContext, TyLoweringDiagnostic, }; // Unfortunately, this struct needs to use interior mutability (but we encapsulate it) diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index d0cbce70a2..c5a6c21d29 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -5,9 +5,10 @@ use std::{ mem, }; -use chalk_ir::{cast::Cast, fold::Shift, DebruijnIndex, Mutability, TyVariableKind}; +use chalk_ir::{DebruijnIndex, Mutability, TyVariableKind, cast::Cast, fold::Shift}; use either::Either; use hir_def::{ + BlockId, FieldId, GenericDefId, GenericParamId, ItemContainerId, Lookup, TupleFieldId, TupleId, hir::{ ArithOp, Array, AsmOperand, AsmOptions, BinaryOp, ClosureKind, Expr, ExprId, ExprOrPatId, LabelId, Literal, Pat, PatId, Statement, UnaryOp, @@ -15,7 +16,6 @@ use hir_def::{ lang_item::{LangItem, LangItemTarget}, path::{GenericArg, GenericArgs, Path}, resolver::ValueNs, - BlockId, FieldId, GenericDefId, GenericParamId, ItemContainerId, Lookup, TupleFieldId, TupleId, }; use hir_expand::name::Name; use intern::sym; @@ -23,34 +23,34 @@ use stdx::always; use syntax::ast::RangeOp; use crate::{ - autoderef::{builtin_deref, deref_by_trait, Autoderef}, + Adjust, Adjustment, AdtId, AutoBorrow, Binders, CallableDefId, CallableSig, DeclContext, + DeclOrigin, FnAbi, FnPointer, FnSig, FnSubst, Interner, Rawness, Scalar, Substitution, + TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, + autoderef::{Autoderef, builtin_deref, deref_by_trait}, consteval, db::{InternedClosure, InternedCoroutine}, error_lifetime, - generics::{generics, Generics}, + generics::{Generics, generics}, infer::{ + BreakableKind, coerce::{CoerceMany, CoerceNever, CoercionCause}, find_continuable, pat::contains_explicit_ref_binding, - BreakableKind, }, lang_items::lang_items_for_bin_op, lower::{ - const_or_path_to_chalk, generic_arg_to_chalk, lower_to_chalk_mutability, ParamLoweringMode, + ParamLoweringMode, const_or_path_to_chalk, generic_arg_to_chalk, lower_to_chalk_mutability, }, - mapping::{from_chalk, ToChalk}, + mapping::{ToChalk, from_chalk}, method_resolution::{self, VisibleFromModule}, primitive::{self, UintTy}, static_lifetime, to_chalk_trait_id, traits::FnTrait, - Adjust, Adjustment, AdtId, AutoBorrow, Binders, CallableDefId, CallableSig, DeclContext, - DeclOrigin, FnAbi, FnPointer, FnSig, FnSubst, Interner, Rawness, Scalar, Substitution, - TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, }; use super::{ - cast::CastCheck, coerce::auto_deref_adjust_steps, find_breakable, BreakableContext, Diverges, - Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch, + BreakableContext, Diverges, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch, + cast::CastCheck, coerce::auto_deref_adjust_steps, find_breakable, }; #[derive(Clone, Copy, PartialEq, Eq)] @@ -1556,11 +1556,7 @@ impl InferenceContext<'_> { target_is_read, ) }; - if type_ref.is_some() { - decl_ty - } else { - ty - } + if type_ref.is_some() { decl_ty } else { ty } } else { decl_ty }; @@ -2402,11 +2398,7 @@ impl InferenceContext<'_> { BinaryOp::Assignment { .. } => unreachable!("handled above"), }; - if is_assign { - self.result.standard_types.unit.clone() - } else { - output_ty - } + if is_assign { self.result.standard_types.unit.clone() } else { output_ty } } fn is_builtin_binop(&mut self, lhs: &Ty, rhs: &Ty, op: BinaryOp) -> bool { diff --git a/crates/hir-ty/src/infer/mutability.rs b/crates/hir-ty/src/infer/mutability.rs index 96d84cad93..aeaecc2831 100644 --- a/crates/hir-ty/src/infer/mutability.rs +++ b/crates/hir-ty/src/infer/mutability.rs @@ -1,7 +1,7 @@ //! Finds if an expression is an immutable context or a mutable context, which is used in selecting //! between `Deref` and `DerefMut` or `Index` and `IndexMut` or similar. -use chalk_ir::{cast::Cast, Mutability}; +use chalk_ir::{Mutability, cast::Cast}; use hir_def::{ hir::{ Array, AsmOperand, BinaryOp, BindingAnnotation, Expr, ExprId, Pat, PatId, Statement, @@ -13,9 +13,9 @@ use hir_expand::name::Name; use intern::sym; use crate::{ - infer::{expr::ExprIsRead, Expectation, InferenceContext}, - lower::lower_to_chalk_mutability, Adjust, Adjustment, AutoBorrow, Interner, OverloadedDeref, TyBuilder, TyKind, + infer::{Expectation, InferenceContext, expr::ExprIsRead}, + lower::lower_to_chalk_mutability, }; impl InferenceContext<'_> { diff --git a/crates/hir-ty/src/infer/pat.rs b/crates/hir-ty/src/infer/pat.rs index db93116f10..6d2811635e 100644 --- a/crates/hir-ty/src/infer/pat.rs +++ b/crates/hir-ty/src/infer/pat.rs @@ -3,24 +3,25 @@ use std::iter::repeat_with; use hir_def::{ + HasModule, expr_store::Body, hir::{Binding, BindingAnnotation, BindingId, Expr, ExprId, Literal, Pat, PatId}, path::Path, - HasModule, }; use hir_expand::name::Name; use stdx::TupleExt; use crate::{ + DeclContext, DeclOrigin, InferenceDiagnostic, Interner, Mutability, Scalar, Substitution, Ty, + TyBuilder, TyExt, TyKind, consteval::{self, try_const_usize, usize_const}, infer::{ - coerce::CoerceNever, expr::ExprIsRead, BindingMode, Expectation, InferenceContext, - TypeMismatch, + BindingMode, Expectation, InferenceContext, TypeMismatch, coerce::CoerceNever, + expr::ExprIsRead, }, lower::lower_to_chalk_mutability, primitive::UintTy, - static_lifetime, DeclContext, DeclOrigin, InferenceDiagnostic, Interner, Mutability, Scalar, - Substitution, Ty, TyBuilder, TyExt, TyKind, + static_lifetime, }; impl InferenceContext<'_> { diff --git a/crates/hir-ty/src/infer/path.rs b/crates/hir-ty/src/infer/path.rs index 8ff0cf3082..04d1ea97f9 100644 --- a/crates/hir-ty/src/infer/path.rs +++ b/crates/hir-ty/src/infer/path.rs @@ -2,21 +2,22 @@ use chalk_ir::cast::Cast; use hir_def::{ + AdtId, AssocItemId, GenericDefId, ItemContainerId, Lookup, path::{Path, PathSegment}, resolver::{ResolveValueResult, TypeNs, ValueNs}, - AdtId, AssocItemId, GenericDefId, ItemContainerId, Lookup, }; use hir_expand::name::Name; use stdx::never; use crate::{ + InferenceDiagnostic, Interner, Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, + TyKind, ValueTyDefId, builder::ParamKind, consteval, error_lifetime, generics::generics, infer::diagnostics::InferenceTyLoweringContext as TyLoweringContext, method_resolution::{self, VisibleFromModule}, - to_chalk_trait_id, InferenceDiagnostic, Interner, Substitution, TraitRef, TraitRefExt, Ty, - TyBuilder, TyExt, TyKind, ValueTyDefId, + to_chalk_trait_id, }; use super::{ExprOrPatId, InferenceContext, InferenceTyDiagnosticSource}; @@ -63,7 +64,7 @@ impl InferenceContext<'_> { never!("uninferred pattern?"); None } - } + }; } ValueNs::ImplSelf(impl_id) => { let generics = crate::generics::generics(self.db.upcast(), impl_id.into()); @@ -81,7 +82,7 @@ impl InferenceContext<'_> { }; } ValueNs::GenericParam(it) => { - return Some(ValuePathResolution::NonGeneric(self.db.const_param_ty(it))) + return Some(ValuePathResolution::NonGeneric(self.db.const_param_ty(it))); } }; diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 6d80bfc38e..903097ee2f 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -3,13 +3,13 @@ use std::{fmt, mem}; use chalk_ir::{ - cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, - IntTy, TyVariableKind, UniverseIndex, + CanonicalVarKind, FloatTy, IntTy, TyVariableKind, UniverseIndex, cast::Cast, + fold::TypeFoldable, interner::HasInterner, zip::Zip, }; use chalk_solve::infer::ParameterEnaVariableExt; use either::Either; use ena::unify::UnifyKey; -use hir_def::{lang_item::LangItem, AdtId}; +use hir_def::{AdtId, lang_item::LangItem}; use hir_expand::name::Name; use intern::sym; use rustc_hash::FxHashMap; @@ -18,12 +18,12 @@ use triomphe::Arc; use super::{InferOk, InferResult, InferenceContext, TypeError}; use crate::{ + AliasEq, AliasTy, BoundVar, Canonical, Const, ConstValue, DebruijnIndex, DomainGoal, + GenericArg, GenericArgData, Goal, GoalData, Guidance, InEnvironment, InferenceVar, Interner, + Lifetime, OpaqueTyId, ParamKind, ProjectionTy, ProjectionTyExt, Scalar, Solution, Substitution, + TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, VariableKind, WhereClause, consteval::unknown_const, db::HirDatabase, fold_generic_args, fold_tys_and_consts, - to_chalk_trait_id, traits::FnTrait, AliasEq, AliasTy, BoundVar, Canonical, Const, ConstValue, - DebruijnIndex, DomainGoal, GenericArg, GenericArgData, Goal, GoalData, Guidance, InEnvironment, - InferenceVar, Interner, Lifetime, OpaqueTyId, ParamKind, ProjectionTy, ProjectionTyExt, Scalar, - Solution, Substitution, TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, VariableKind, - WhereClause, + to_chalk_trait_id, traits::FnTrait, }; impl InferenceContext<'_> { @@ -890,11 +890,7 @@ impl<'a> InferenceTable<'a> { TyKind::Error => self.new_type_var(), TyKind::InferenceVar(..) => { let ty_resolved = self.resolve_ty_shallow(&ty); - if ty_resolved.is_unknown() { - self.new_type_var() - } else { - ty - } + if ty_resolved.is_unknown() { self.new_type_var() } else { ty } } _ => ty, } diff --git a/crates/hir-ty/src/inhabitedness.rs b/crates/hir-ty/src/inhabitedness.rs index 800ba0d454..c153bf3e34 100644 --- a/crates/hir-ty/src/inhabitedness.rs +++ b/crates/hir-ty/src/inhabitedness.rs @@ -2,14 +2,14 @@ use std::ops::ControlFlow::{self, Break, Continue}; use chalk_ir::{ - visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, DebruijnIndex, + visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, }; -use hir_def::{visibility::Visibility, AdtId, EnumVariantId, ModuleId, VariantId}; +use hir_def::{AdtId, EnumVariantId, ModuleId, VariantId, visibility::Visibility}; use rustc_hash::FxHashSet; use crate::{ - consteval::try_const_usize, db::HirDatabase, Binders, Interner, Substitution, Ty, TyKind, + Binders, Interner, Substitution, Ty, TyKind, consteval::try_const_usize, db::HirDatabase, }; // FIXME: Turn this into a query, it can be quite slow diff --git a/crates/hir-ty/src/interner.rs b/crates/hir-ty/src/interner.rs index 832a00e1e5..bd4a53603d 100644 --- a/crates/hir-ty/src/interner.rs +++ b/crates/hir-ty/src/interner.rs @@ -2,15 +2,15 @@ //! representation of the various objects Chalk deals with (types, goals etc.). use crate::{ - chalk_db, tls, AliasTy, CanonicalVarKind, CanonicalVarKinds, ClosureId, Const, ConstData, - ConstScalar, Constraint, Constraints, FnAbi, FnDefId, GenericArg, GenericArgData, Goal, - GoalData, Goals, InEnvironment, Lifetime, LifetimeData, OpaqueTy, OpaqueTyId, ProgramClause, - ProgramClauseData, ProgramClauses, ProjectionTy, QuantifiedWhereClause, QuantifiedWhereClauses, - Substitution, Ty, TyData, TyKind, VariableKind, VariableKinds, + AliasTy, CanonicalVarKind, CanonicalVarKinds, ClosureId, Const, ConstData, ConstScalar, + Constraint, Constraints, FnAbi, FnDefId, GenericArg, GenericArgData, Goal, GoalData, Goals, + InEnvironment, Lifetime, LifetimeData, OpaqueTy, OpaqueTyId, ProgramClause, ProgramClauseData, + ProgramClauses, ProjectionTy, QuantifiedWhereClause, QuantifiedWhereClauses, Substitution, Ty, + TyData, TyKind, VariableKind, VariableKinds, chalk_db, tls, }; use chalk_ir::{ProgramClauseImplication, SeparatorTraitRef, Variance}; use hir_def::TypeAliasId; -use intern::{impl_internable, Interned}; +use intern::{Interned, impl_internable}; use smallvec::SmallVec; use std::fmt; use triomphe::Arc; diff --git a/crates/hir-ty/src/lang_items.rs b/crates/hir-ty/src/lang_items.rs index ff9c52fbb6..d638d50f8e 100644 --- a/crates/hir-ty/src/lang_items.rs +++ b/crates/hir-ty/src/lang_items.rs @@ -1,6 +1,6 @@ //! Functions to detect special lang items -use hir_def::{data::adt::StructFlags, lang_item::LangItem, AdtId}; +use hir_def::{AdtId, data::adt::StructFlags, lang_item::LangItem}; use hir_expand::name::Name; use intern::sym; diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs index 2f7ad2b99d..0cb868d273 100644 --- a/crates/hir-ty/src/layout.rs +++ b/crates/hir-ty/src/layout.rs @@ -4,11 +4,11 @@ use std::fmt; use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy}; use hir_def::{ + LocalFieldId, StructId, layout::{ Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutData, Primitive, ReprOptions, Scalar, StructKind, TargetDataLayout, WrappingRange, }, - LocalFieldId, StructId, }; use la_arena::{Idx, RawIdx}; use rustc_abi::AddressSpace; @@ -18,11 +18,11 @@ use salsa::Cycle; use triomphe::Arc; use crate::{ + Interner, ProjectionTy, Substitution, TraitEnvironment, Ty, consteval::try_const_usize, db::{HirDatabase, HirDatabaseData, InternedClosure}, infer::normalize, utils::ClosureSubst, - Interner, ProjectionTy, Substitution, TraitEnvironment, Ty, }; pub(crate) use self::adt::layout_of_adt_recover; @@ -320,7 +320,7 @@ pub fn layout_of_ty_query( return Err(LayoutError::NotImplemented); } crate::ImplTraitId::AsyncBlockTypeImplTrait(_, _) => { - return Err(LayoutError::NotImplemented) + return Err(LayoutError::NotImplemented); } } } @@ -342,7 +342,7 @@ pub fn layout_of_ty_query( cx.calc.univariant(&fields, &ReprOptions::default(), StructKind::AlwaysSized)? } TyKind::Coroutine(_, _) | TyKind::CoroutineWitness(_, _) => { - return Err(LayoutError::NotImplemented) + return Err(LayoutError::NotImplemented); } TyKind::Error => return Err(LayoutError::HasErrorType), TyKind::AssociatedType(id, subst) => { diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs index 9f453162e3..efff875dec 100644 --- a/crates/hir-ty/src/layout/adt.rs +++ b/crates/hir-ty/src/layout/adt.rs @@ -3,9 +3,9 @@ use std::{cmp, ops::Bound}; use hir_def::{ + AdtId, VariantId, data::adt::VariantData, layout::{Integer, ReprOptions, TargetDataLayout}, - AdtId, VariantId, }; use intern::sym; use rustc_index::IndexVec; @@ -14,10 +14,10 @@ use smallvec::SmallVec; use triomphe::Arc; use crate::{ + Substitution, TraitEnvironment, db::HirDatabase, lang_items::is_unsafe_cell, - layout::{field_ty, Layout, LayoutError}, - Substitution, TraitEnvironment, + layout::{Layout, LayoutError, field_ty}, }; use super::{HirDatabaseData, LayoutCx}; diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs index 8b74b7328b..f671b30380 100644 --- a/crates/hir-ty/src/layout/tests.rs +++ b/crates/hir-ty/src/layout/tests.rs @@ -1,17 +1,17 @@ use chalk_ir::{AdtId, TyKind}; use either::Either; use hir_def::db::DefDatabase; -use project_model::{toolchain_info::QueryConfig, Sysroot}; +use project_model::{Sysroot, toolchain_info::QueryConfig}; use rustc_hash::FxHashMap; use syntax::ToSmolStr; use test_fixture::WithFixture; use triomphe::Arc; use crate::{ + Interner, Substitution, db::HirDatabase, layout::{Layout, LayoutError}, test_db::TestDB, - Interner, Substitution, }; mod closure; diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index 836319431d..8292e80c1e 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -57,19 +57,19 @@ mod variance; use std::hash::Hash; use chalk_ir::{ + NoSolution, fold::{Shift, TypeFoldable}, interner::HasInterner, - NoSolution, }; use either::Either; -use hir_def::{hir::ExprId, type_ref::Rawness, CallableDefId, GeneralConstId, TypeOrConstParamId}; +use hir_def::{CallableDefId, GeneralConstId, TypeOrConstParamId, hir::ExprId, type_ref::Rawness}; use hir_expand::name::Name; -use indexmap::{map::Entry, IndexMap}; -use intern::{sym, Symbol}; +use indexmap::{IndexMap, map::Entry}; +use intern::{Symbol, sym}; use la_arena::{Arena, Idx}; use mir::{MirEvalError, VTableMap}; use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; -use syntax::ast::{make, ConstArg}; +use syntax::ast::{ConstArg, make}; use traits::FnTrait; use triomphe::Arc; @@ -86,16 +86,16 @@ pub use builder::{ParamKind, TyBuilder}; pub use chalk_ext::*; pub use drop::DropGlue; pub use infer::{ + Adjust, Adjustment, AutoBorrow, BindingMode, InferenceDiagnostic, InferenceResult, + InferenceTyDiagnosticSource, OverloadedDeref, PointerCast, cast::CastError, closure::{CaptureKind, CapturedItem}, - could_coerce, could_unify, could_unify_deeply, Adjust, Adjustment, AutoBorrow, BindingMode, - InferenceDiagnostic, InferenceResult, InferenceTyDiagnosticSource, OverloadedDeref, - PointerCast, + could_coerce, could_unify, could_unify_deeply, }; pub use interner::Interner; pub use lower::{ - associated_type_shorthand_candidates, diagnostics::*, ImplTraitLoweringMode, ParamLoweringMode, - TyDefId, TyLoweringContext, ValueTyDefId, + ImplTraitLoweringMode, ParamLoweringMode, TyDefId, TyLoweringContext, ValueTyDefId, + associated_type_shorthand_candidates, diagnostics::*, }; pub use mapping::{ from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx, @@ -105,13 +105,13 @@ pub use mapping::{ pub use method_resolution::check_orphan_rules; pub use target_feature::TargetFeatures; pub use traits::TraitEnvironment; -pub use utils::{all_super_traits, direct_super_traits, is_fn_unsafe_to_call, Unsafety}; +pub use utils::{Unsafety, all_super_traits, direct_super_traits, is_fn_unsafe_to_call}; pub use variance::Variance; pub use chalk_ir::{ + AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind, cast::Cast, visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, - AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind, }; pub type ForeignDefId = chalk_ir::ForeignDefId; @@ -645,10 +645,8 @@ pub(crate) fn fold_free_vars + TypeFoldable< F1: FnMut(BoundVar, DebruijnIndex) -> Ty, F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const, >(F1, F2); - impl< - F1: FnMut(BoundVar, DebruijnIndex) -> Ty, - F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const, - > TypeFolder for FreeVarFolder + impl Ty, F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const> + TypeFolder for FreeVarFolder { fn as_dyn(&mut self) -> &mut dyn TypeFolder { self @@ -778,8 +776,8 @@ where T: HasInterner + TypeFoldable + Clone, { use chalk_ir::{ - fold::{FallibleTypeFolder, TypeSuperFoldable}, Fallible, + fold::{FallibleTypeFolder, TypeSuperFoldable}, }; struct ErrorReplacer { vars: usize, @@ -840,11 +838,7 @@ where _var: InferenceVar, _outer_binder: DebruijnIndex, ) -> Fallible { - if cfg!(debug_assertions) { - Err(NoSolution) - } else { - Ok(unknown_const(ty)) - } + if cfg!(debug_assertions) { Err(NoSolution) } else { Ok(unknown_const(ty)) } } fn try_fold_free_var_const( @@ -853,11 +847,7 @@ where _bound_var: BoundVar, _outer_binder: DebruijnIndex, ) -> Fallible { - if cfg!(debug_assertions) { - Err(NoSolution) - } else { - Ok(unknown_const(ty)) - } + if cfg!(debug_assertions) { Err(NoSolution) } else { Ok(unknown_const(ty)) } } fn try_fold_inference_lifetime( @@ -865,11 +855,7 @@ where _var: InferenceVar, _outer_binder: DebruijnIndex, ) -> Fallible { - if cfg!(debug_assertions) { - Err(NoSolution) - } else { - Ok(error_lifetime()) - } + if cfg!(debug_assertions) { Err(NoSolution) } else { Ok(error_lifetime()) } } fn try_fold_free_var_lifetime( @@ -877,11 +863,7 @@ where _bound_var: BoundVar, _outer_binder: DebruijnIndex, ) -> Fallible { - if cfg!(debug_assertions) { - Err(NoSolution) - } else { - Ok(error_lifetime()) - } + if cfg!(debug_assertions) { Err(NoSolution) } else { Ok(error_lifetime()) } } } let mut error_replacer = ErrorReplacer { vars: 0 }; diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index 12f3a1138f..e5f3c4cfc8 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -16,16 +16,19 @@ use std::{ use base_db::Crate; use chalk_ir::{ + Mutability, Safety, TypeOutlives, cast::Cast, fold::{Shift, TypeFoldable}, interner::HasInterner, - Mutability, Safety, TypeOutlives, }; use either::Either; use hir_def::{ + AdtId, AssocItemId, CallableDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, + FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstLoc, LocalFieldId, + Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, UnionId, VariantId, builtin_type::BuiltinType, - data::{adt::StructKind, TraitFlags}, + data::{TraitFlags, adt::StructKind}, expander::Expander, generics::{ GenericParamDataRef, TypeOrConstParamData, TypeParamProvenance, WherePredicate, @@ -39,11 +42,8 @@ use hir_def::{ ConstRef, LifetimeRef, PathId, TraitBoundModifier, TraitRef as HirTraitRef, TypeBound, TypeRef, TypeRefId, TypesMap, TypesSourceMap, }, - AdtId, AssocItemId, CallableDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, - FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstLoc, LocalFieldId, - Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, UnionId, VariantId, }; -use hir_expand::{name::Name, ExpandResult}; +use hir_expand::{ExpandResult, name::Name}; use la_arena::{Arena, ArenaMap}; use rustc_hash::FxHashSet; use rustc_pattern_analysis::Captures; @@ -53,27 +53,26 @@ use syntax::ast; use triomphe::{Arc, ThinArc}; use crate::{ - all_super_traits, + AliasTy, Binders, BoundVar, CallableSig, Const, ConstScalar, DebruijnIndex, DynTy, FnAbi, + FnPointer, FnSig, FnSubst, ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime, + LifetimeData, LifetimeOutlives, ParamKind, PolyFnSig, ProgramClause, QuantifiedWhereClause, + QuantifiedWhereClauses, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, + TyKind, WhereClause, all_super_traits, consteval::{ intern_const_ref, intern_const_scalar, path_to_const, unknown_const, unknown_const_as_generic, }, db::{HirDatabase, HirDatabaseData}, error_lifetime, - generics::{generics, trait_self_param_idx, Generics}, + generics::{Generics, generics, trait_self_param_idx}, lower::{ diagnostics::*, path::{PathDiagnosticCallback, PathLoweringContext}, }, make_binders, - mapping::{from_chalk_trait_id, lt_to_placeholder_idx, ToChalk}, + mapping::{ToChalk, from_chalk_trait_id, lt_to_placeholder_idx}, static_lifetime, to_chalk_trait_id, to_placeholder_idx, - utils::{all_super_trait_refs, InTypeConstIdMetadata}, - AliasTy, Binders, BoundVar, CallableSig, Const, ConstScalar, DebruijnIndex, DynTy, FnAbi, - FnPointer, FnSig, FnSubst, ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime, - LifetimeData, LifetimeOutlives, ParamKind, PolyFnSig, ProgramClause, QuantifiedWhereClause, - QuantifiedWhereClauses, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, - TyKind, WhereClause, + utils::{InTypeConstIdMetadata, all_super_trait_refs}, }; #[derive(Debug, Default)] @@ -1301,11 +1300,7 @@ fn implicitly_sized_clauses<'a, 'subst: 'a>( .enumerate() .filter_map( move |(idx, generic_arg)| { - if Some(idx) == trait_self_idx { - None - } else { - Some(generic_arg) - } + if Some(idx) == trait_self_idx { None } else { Some(generic_arg) } }, ) .filter_map(|generic_arg| generic_arg.ty(Interner)) diff --git a/crates/hir-ty/src/lower/path.rs b/crates/hir-ty/src/lower/path.rs index a9e9e83e87..960cb53371 100644 --- a/crates/hir-ty/src/lower/path.rs +++ b/crates/hir-ty/src/lower/path.rs @@ -2,32 +2,32 @@ use std::iter; -use chalk_ir::{cast::Cast, fold::Shift, BoundVar}; +use chalk_ir::{BoundVar, cast::Cast, fold::Shift}; use either::Either; use hir_def::{ + GenericDefId, GenericParamId, ItemContainerId, Lookup, TraitId, data::TraitFlags, expr_store::HygieneId, generics::{TypeParamProvenance, WherePredicate, WherePredicateTypeTarget}, path::{GenericArg, GenericArgs, Path, PathSegment, PathSegments}, resolver::{ResolveValueResult, TypeNs, ValueNs}, type_ref::{TypeBound, TypeRef, TypesMap}, - GenericDefId, GenericParamId, ItemContainerId, Lookup, TraitId, }; use smallvec::SmallVec; use stdx::never; use crate::{ + AliasEq, AliasTy, GenericArgsProhibitedReason, ImplTraitLoweringMode, Interner, + ParamLoweringMode, PathLoweringDiagnostic, ProjectionTy, QuantifiedWhereClause, Substitution, + TraitRef, Ty, TyBuilder, TyDefId, TyKind, TyLoweringContext, ValueTyDefId, WhereClause, consteval::unknown_const_as_generic, error_lifetime, generics::generics, lower::{ - generic_arg_to_chalk, named_associated_type_shorthand_candidates, ImplTraitLoweringState, + ImplTraitLoweringState, generic_arg_to_chalk, named_associated_type_shorthand_candidates, }, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, utils::associated_type_by_name_including_super_traits, - AliasEq, AliasTy, GenericArgsProhibitedReason, ImplTraitLoweringMode, Interner, - ParamLoweringMode, PathLoweringDiagnostic, ProjectionTy, QuantifiedWhereClause, Substitution, - TraitRef, Ty, TyBuilder, TyDefId, TyKind, TyLoweringContext, ValueTyDefId, WhereClause, }; type CallbackData<'a> = Either< diff --git a/crates/hir-ty/src/mapping.rs b/crates/hir-ty/src/mapping.rs index cfa2a49b79..f7511e5f63 100644 --- a/crates/hir-ty/src/mapping.rs +++ b/crates/hir-ty/src/mapping.rs @@ -7,13 +7,13 @@ use chalk_solve::rust_ir; use hir_def::{LifetimeParamId, TraitId, TypeAliasId, TypeOrConstParamId}; use salsa::{ - plumbing::{AsId, FromId}, Id, + plumbing::{AsId, FromId}, }; use crate::{ - chalk_db, db::HirDatabase, AssocTypeId, CallableDefId, ChalkTraitId, FnDefId, ForeignDefId, - Interner, OpaqueTyId, PlaceholderIndex, + AssocTypeId, CallableDefId, ChalkTraitId, FnDefId, ForeignDefId, Interner, OpaqueTyId, + PlaceholderIndex, chalk_db, db::HirDatabase, }; pub(crate) trait ToChalk { diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index bb3aaef20b..d887013b6f 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -6,33 +6,33 @@ use std::ops::ControlFlow; use arrayvec::ArrayVec; use base_db::Crate; -use chalk_ir::{cast::Cast, UniverseIndex, WithKind}; +use chalk_ir::{UniverseIndex, WithKind, cast::Cast}; use hir_def::{ - data::{adt::StructFlags, TraitFlags}, - nameres::{assoc::ImplItems, DefMap}, AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup, ModuleId, TraitId, + data::{TraitFlags, adt::StructFlags}, + nameres::{DefMap, assoc::ImplItems}, }; use hir_expand::name::Name; use intern::sym; use rustc_hash::{FxHashMap, FxHashSet}; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use stdx::never; use triomphe::Arc; use crate::{ - autoderef::{self, AutoderefKind}, - db::HirDatabase, - error_lifetime, from_chalk_trait_id, from_foreign_def_id, - infer::{unify::InferenceTable, Adjust, Adjustment, OverloadedDeref, PointerCast}, - lang_items::is_box, - primitive::{FloatTy, IntTy, UintTy}, - to_chalk_trait_id, - utils::all_super_traits, AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, DynTyExt, ForeignDefId, GenericArgData, Goal, Guidance, InEnvironment, Interner, Mutability, Scalar, Solution, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, TyVariableKind, VariableKind, WhereClause, + autoderef::{self, AutoderefKind}, + db::HirDatabase, + error_lifetime, from_chalk_trait_id, from_foreign_def_id, + infer::{Adjust, Adjustment, OverloadedDeref, PointerCast, unify::InferenceTable}, + lang_items::is_box, + primitive::{FloatTy, IntTy, UintTy}, + to_chalk_trait_id, + utils::all_super_traits, }; /// This is used as a key for indexing impls. @@ -166,11 +166,7 @@ impl TraitImpls { Self::collect_def_map(db, &mut impls, &db.block_def_map(block)); - if impls.is_empty() { - None - } else { - Some(Arc::new(Self::finish(impls))) - } + if impls.is_empty() { None } else { Some(Arc::new(Self::finish(impls))) } } pub(crate) fn trait_impls_in_deps_query( @@ -698,11 +694,7 @@ pub(crate) fn lookup_impl_method_query( let name = &db.function_data(func).name; let Some((impl_fn, impl_subst)) = lookup_impl_assoc_item_for_trait_ref(trait_ref, db, env, name).and_then(|assoc| { - if let (AssocItemId::FunctionId(id), subst) = assoc { - Some((id, subst)) - } else { - None - } + if let (AssocItemId::FunctionId(id), subst) = assoc { Some((id, subst)) } else { None } }) else { return (func, fn_subst); diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs index 7faa23f818..247f0ec429 100644 --- a/crates/hir-ty/src/mir.rs +++ b/crates/hir-ty/src/mir.rs @@ -3,22 +3,22 @@ use std::{collections::hash_map::Entry, fmt::Display, iter}; use crate::{ + CallableDefId, ClosureId, Const, ConstScalar, InferenceResult, Interner, MemoryMap, + Substitution, TraitEnvironment, Ty, TyExt, TyKind, consteval::usize_const, db::HirDatabase, display::{DisplayTarget, HirDisplay}, - infer::{normalize, PointerCast}, + infer::{PointerCast, normalize}, lang_items::is_box, mapping::ToChalk, - CallableDefId, ClosureId, Const, ConstScalar, InferenceResult, Interner, MemoryMap, - Substitution, TraitEnvironment, Ty, TyExt, TyKind, }; use base_db::Crate; use chalk_ir::Mutability; use either::Either; use hir_def::{ + DefWithBodyId, FieldId, StaticId, TupleFieldId, UnionId, VariantId, expr_store::Body, hir::{BindingAnnotation, BindingId, Expr, ExprId, Ordering, PatId}, - DefWithBodyId, FieldId, StaticId, TupleFieldId, UnionId, VariantId, }; use la_arena::{Arena, ArenaMap, Idx, RawIdx}; @@ -28,17 +28,17 @@ mod lower; mod monomorphization; mod pretty; -pub use borrowck::{borrowck_query, BorrowckResult, MutabilityReason}; +pub use borrowck::{BorrowckResult, MutabilityReason, borrowck_query}; pub use eval::{ - interpret_mir, pad16, render_const_using_debug_impl, Evaluator, MirEvalError, VTableMap, + Evaluator, MirEvalError, VTableMap, interpret_mir, pad16, render_const_using_debug_impl, }; -pub use lower::{lower_to_mir, mir_body_for_closure_query, mir_body_query, MirLowerError}; +pub use lower::{MirLowerError, lower_to_mir, mir_body_for_closure_query, mir_body_query}; pub use monomorphization::{ monomorphize_mir_body_bad, monomorphized_mir_body_for_closure_query, monomorphized_mir_body_query, }; use rustc_hash::FxHashMap; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use stdx::{impl_from, never}; pub(crate) use lower::mir_body_recover; diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs index fd1e724ee8..d9938fc60c 100644 --- a/crates/hir-ty/src/mir/borrowck.rs +++ b/crates/hir-ty/src/mir/borrowck.rs @@ -12,11 +12,11 @@ use stdx::never; use triomphe::Arc; use crate::{ + ClosureId, Interner, Substitution, Ty, TyExt, TypeFlags, db::{HirDatabase, InternedClosure}, display::DisplayTarget, mir::Operand, utils::ClosureSubst, - ClosureId, Interner, Substitution, Ty, TyExt, TypeFlags, }; use super::{ @@ -376,11 +376,7 @@ fn place_case(db: &dyn HirDatabase, body: &MirBody, lvalue: &Place) -> Projectio body.owner.module(db.upcast()).krate(), ); } - if is_part_of { - ProjectionCase::DirectPart - } else { - ProjectionCase::Direct - } + if is_part_of { ProjectionCase::DirectPart } else { ProjectionCase::Direct } } /// Returns a map from basic blocks to the set of locals that might be ever initialized before diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index be0a79f1dd..ee412dd00b 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -3,25 +3,25 @@ use std::{borrow::Cow, cell::RefCell, fmt::Write, iter, mem, ops::Range}; use base_db::Crate; -use chalk_ir::{cast::Cast, Mutability}; +use chalk_ir::{Mutability, cast::Cast}; use either::Either; use hir_def::{ + AdtId, DefWithBodyId, EnumVariantId, FunctionId, HasModule, ItemContainerId, Lookup, StaticId, + VariantId, builtin_type::BuiltinType, data::adt::{StructFlags, VariantData}, expr_store::HygieneId, lang_item::LangItem, layout::{TagEncoding, Variants}, resolver::{HasResolver, TypeNs, ValueNs}, - AdtId, DefWithBodyId, EnumVariantId, FunctionId, HasModule, ItemContainerId, Lookup, StaticId, - VariantId, }; -use hir_expand::{mod_path::path, name::Name, HirFileIdExt, InFile}; +use hir_expand::{HirFileIdExt, InFile, mod_path::path, name::Name}; use intern::sym; use la_arena::ArenaMap; use rustc_abi::TargetDataLayout; use rustc_apfloat::{ - ieee::{Half as f16, Quad as f128}, Float, + ieee::{Half as f16, Quad as f128}, }; use rustc_hash::{FxHashMap, FxHashSet}; use span::FileId; @@ -30,7 +30,9 @@ use syntax::{SyntaxNodePtr, TextRange}; use triomphe::Arc; use crate::{ - consteval::{intern_const_scalar, try_const_usize, ConstEvalError}, + CallableDefId, ClosureId, ComplexMemoryMap, Const, ConstData, ConstScalar, FnDefId, Interner, + MemoryMap, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind, + consteval::{ConstEvalError, intern_const_scalar, try_const_usize}, db::{HirDatabase, InternedClosure}, display::{ClosureStyle, DisplayTarget, HirDisplay}, infer::PointerCast, @@ -39,15 +41,13 @@ use crate::{ method_resolution::{is_dyn_method, lookup_impl_const}, static_lifetime, traits::FnTrait, - utils::{detect_variant_from_bytes, ClosureSubst}, - CallableDefId, ClosureId, ComplexMemoryMap, Const, ConstData, ConstScalar, FnDefId, Interner, - MemoryMap, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind, + utils::{ClosureSubst, detect_variant_from_bytes}, }; use super::{ - return_slot, AggregateKind, BasicBlockId, BinOp, CastKind, LocalId, MirBody, MirLowerError, - MirSpan, Operand, Place, PlaceElem, ProjectionElem, ProjectionStore, Rvalue, StatementKind, - TerminatorKind, UnOp, + AggregateKind, BasicBlockId, BinOp, CastKind, LocalId, MirBody, MirLowerError, MirSpan, + Operand, Place, PlaceElem, ProjectionElem, ProjectionStore, Rvalue, StatementKind, + TerminatorKind, UnOp, return_slot, }; mod shim; @@ -825,7 +825,7 @@ impl Evaluator<'_> { _ => { return Err(MirEvalError::InternalError( "mismatched layout".into(), - )) + )); } }] } @@ -1864,7 +1864,7 @@ impl Evaluator<'_> { "encoded tag ({offset}, {size}, {value}) is out of bounds 0..{size}" ) .into(), - )) + )); } } } @@ -1876,7 +1876,7 @@ impl Evaluator<'_> { None => { return Err(MirEvalError::InternalError( format!("field offset ({offset}) is out of bounds 0..{size}").into(), - )) + )); } } } @@ -2054,7 +2054,7 @@ impl Evaluator<'_> { _ => { return Err(MirEvalError::UndefinedBehavior(format!( "invalid memory write at address {addr:?}" - ))) + ))); } } @@ -2618,13 +2618,10 @@ impl Evaluator<'_> { let ty = ty.clone().cast(Interner); let generics_for_target = Substitution::from_iter( Interner, - generic_args.iter(Interner).enumerate().map(|(i, it)| { - if i == self_ty_idx { - &ty - } else { - it - } - }), + generic_args + .iter(Interner) + .enumerate() + .map(|(i, it)| if i == self_ty_idx { &ty } else { it }), ); self.exec_fn_with_args( def, diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs index edd028cdeb..a1cff20f92 100644 --- a/crates/hir-ty/src/mir/eval/shim.rs +++ b/crates/hir-ty/src/mir/eval/shim.rs @@ -10,19 +10,19 @@ use hir_def::{ resolver::HasResolver, }; use hir_expand::name::Name; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use stdx::never; use crate::{ + DropGlue, display::DisplayTarget, error_lifetime, mir::eval::{ - pad16, Address, AdtId, Arc, BuiltinType, Evaluator, FunctionId, HasModule, HirDisplay, + Address, AdtId, Arc, BuiltinType, Evaluator, FunctionId, HasModule, HirDisplay, InternedClosure, Interner, Interval, IntervalAndTy, IntervalOrOwned, ItemContainerId, LangItem, Layout, Locals, Lookup, MirEvalError, MirSpan, Mutability, Result, Substitution, - Ty, TyBuilder, TyExt, + Ty, TyBuilder, TyExt, pad16, }, - DropGlue, }; mod simd; @@ -1357,7 +1357,7 @@ impl Evaluator<'_> { _ => { return Err(MirEvalError::InternalError( "three_way_compare expects an integral type".into(), - )) + )); } }; let rhs = rhs.get(self)?; diff --git a/crates/hir-ty/src/mir/eval/shim/simd.rs b/crates/hir-ty/src/mir/eval/shim/simd.rs index 54754045c9..2387c19cdb 100644 --- a/crates/hir-ty/src/mir/eval/shim/simd.rs +++ b/crates/hir-ty/src/mir/eval/shim/simd.rs @@ -2,8 +2,8 @@ use std::cmp::Ordering; -use crate::consteval::try_const_usize; use crate::TyKind; +use crate::consteval::try_const_usize; use super::*; @@ -164,7 +164,7 @@ impl Evaluator<'_> { None => { return Err(MirEvalError::InternalError( "simd type with unevaluatable len param".into(), - )) + )); } }; let (left_len, _) = self.detect_simd_ty(&left.ty)?; @@ -179,7 +179,7 @@ impl Evaluator<'_> { None => { return Err(MirEvalError::InternalError( "out of bound access in simd shuffle".into(), - )) + )); } }; result.extend(val); diff --git a/crates/hir-ty/src/mir/eval/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs index 084c391d26..cd490c3b48 100644 --- a/crates/hir-ty/src/mir/eval/tests.rs +++ b/crates/hir-ty/src/mir/eval/tests.rs @@ -4,9 +4,9 @@ use syntax::{TextRange, TextSize}; use test_fixture::WithFixture; use crate::display::DisplayTarget; -use crate::{db::HirDatabase, mir::MirLowerError, test_db::TestDB, Interner, Substitution}; +use crate::{Interner, Substitution, db::HirDatabase, mir::MirLowerError, test_db::TestDB}; -use super::{interpret_mir, MirEvalError}; +use super::{MirEvalError, interpret_mir}; fn eval_main(db: &TestDB, file_id: EditionedFileId) -> Result<(String, String), MirEvalError> { let module_id = db.module_for_file(file_id); diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 38924d7c95..95c93b5f3e 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -2,9 +2,11 @@ use std::{fmt::Write, iter, mem}; -use base_db::{salsa::Cycle, Crate}; +use base_db::{Crate, salsa::Cycle}; use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind}; use hir_def::{ + AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId, + Lookup, TraitId, TupleId, TypeOrConstParamId, data::adt::{StructKind, VariantData}, expr_store::{Body, HygieneId}, hir::{ @@ -15,8 +17,6 @@ use hir_def::{ path::Path, resolver::{HasResolver, ResolveValueResult, Resolver, ValueNs}, type_ref::TypesMap, - AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId, - Lookup, TraitId, TupleId, TypeOrConstParamId, }; use hir_expand::name::Name; use la_arena::ArenaMap; @@ -27,27 +27,27 @@ use syntax::TextRange; use triomphe::Arc; use crate::{ + Adjust, Adjustment, AutoBorrow, CallableDefId, TyBuilder, TyExt, consteval::ConstEvalError, db::{HirDatabase, InternedClosure}, - display::{hir_display_with_types_map, DisplayTarget, HirDisplay}, + display::{DisplayTarget, HirDisplay, hir_display_with_types_map}, error_lifetime, generics::generics, - infer::{cast::CastTy, unify::InferenceTable, CaptureKind, CapturedItem, TypeMismatch}, + infer::{CaptureKind, CapturedItem, TypeMismatch, cast::CastTy, unify::InferenceTable}, inhabitedness::is_ty_uninhabited_from, layout::LayoutError, mapping::ToChalk, mir::{ - intern_const_scalar, return_slot, AggregateKind, Arena, BasicBlock, BasicBlockId, BinOp, - BorrowKind, CastKind, ClosureId, ConstScalar, Either, Expr, FieldId, Idx, InferenceResult, - Interner, Local, LocalId, MemoryMap, MirBody, MirSpan, Mutability, Operand, Place, - PlaceElem, PointerCast, ProjectionElem, ProjectionStore, RawIdx, Rvalue, Statement, - StatementKind, Substitution, SwitchTargets, Terminator, TerminatorKind, TupleFieldId, Ty, - UnOp, VariantId, + AggregateKind, Arena, BasicBlock, BasicBlockId, BinOp, BorrowKind, CastKind, ClosureId, + ConstScalar, Either, Expr, FieldId, Idx, InferenceResult, Interner, Local, LocalId, + MemoryMap, MirBody, MirSpan, Mutability, Operand, Place, PlaceElem, PointerCast, + ProjectionElem, ProjectionStore, RawIdx, Rvalue, Statement, StatementKind, Substitution, + SwitchTargets, Terminator, TerminatorKind, TupleFieldId, Ty, UnOp, VariantId, + intern_const_scalar, return_slot, }, static_lifetime, traits::FnTrait, utils::ClosureSubst, - Adjust, Adjustment, AutoBorrow, CallableDefId, TyBuilder, TyExt, }; mod as_place; @@ -1278,7 +1278,7 @@ impl<'ctx> MirLowerCtx<'ctx> { _ => { return Err(MirLowerError::TypeError( "Array expression with non array type", - )) + )); } }; let Some(values) = elements @@ -1310,7 +1310,7 @@ impl<'ctx> MirLowerCtx<'ctx> { _ => { return Err(MirLowerError::TypeError( "Array repeat expression with non array type", - )) + )); } }; let r = Rvalue::Repeat(init, len); @@ -1441,7 +1441,7 @@ impl<'ctx> MirLowerCtx<'ctx> { _ => { return Err(MirLowerError::TypeError( "float with size other than 2, 4, 8 or 16 bytes", - )) + )); } }, }; @@ -2173,11 +2173,7 @@ pub fn lower_to_mir( ctx.result.locals.alloc(Local { ty: ctx.expr_ty_after_adjustments(root_expr) }); let binding_picker = |b: BindingId| { let owner = ctx.body.binding_owners.get(&b).copied(); - if root_expr == body.body_expr { - owner.is_none() - } else { - owner == Some(root_expr) - } + if root_expr == body.body_expr { owner.is_none() } else { owner == Some(root_expr) } }; // 1 to param_len is for params // FIXME: replace with let chain once it becomes stable diff --git a/crates/hir-ty/src/mir/lower/pattern_matching.rs b/crates/hir-ty/src/mir/lower/pattern_matching.rs index 1c6dc4fecd..d6b2100253 100644 --- a/crates/hir-ty/src/mir/lower/pattern_matching.rs +++ b/crates/hir-ty/src/mir/lower/pattern_matching.rs @@ -1,9 +1,11 @@ //! MIR lowering for patterns -use hir_def::{hir::ExprId, AssocItemId}; +use hir_def::{AssocItemId, hir::ExprId}; use crate::{ + BindingMode, mir::{ + LocalId, MutBorrowKind, lower::{ BasicBlockId, BinOp, BindingId, BorrowKind, Either, Expr, FieldId, Idx, Interner, MemoryMap, MirLowerCtx, MirLowerError, MirSpan, Mutability, Operand, Pat, PatId, Place, @@ -11,9 +13,7 @@ use crate::{ Substitution, SwitchTargets, TerminatorKind, TupleFieldId, TupleId, TyBuilder, TyKind, ValueNs, VariantData, VariantId, }, - LocalId, MutBorrowKind, }, - BindingMode, }; macro_rules! not_supported { @@ -139,7 +139,7 @@ impl MirLowerCtx<'_> { _ => { return Err(MirLowerError::TypeError( "non tuple type matched with tuple pattern", - )) + )); } }; self.pattern_match_tuple_like( @@ -615,7 +615,7 @@ impl MirLowerCtx<'_> { mode, )?, VariantId::UnionId(_) => { - return Err(MirLowerError::TypeError("pattern matching on union")) + return Err(MirLowerError::TypeError("pattern matching on union")); } }) } diff --git a/crates/hir-ty/src/mir/monomorphization.rs b/crates/hir-ty/src/mir/monomorphization.rs index 6d1e9a1ea1..c733c7ed84 100644 --- a/crates/hir-ty/src/mir/monomorphization.rs +++ b/crates/hir-ty/src/mir/monomorphization.rs @@ -10,19 +10,19 @@ use std::mem; use chalk_ir::{ - fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}, ConstData, DebruijnIndex, + fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}, }; use hir_def::DefWithBodyId; use triomphe::Arc; use crate::{ + ClosureId, Const, Interner, ProjectionTy, Substitution, TraitEnvironment, Ty, TyKind, consteval::{intern_const_scalar, unknown_const}, db::{HirDatabase, HirDatabaseData, InternedClosure}, from_placeholder_idx, - generics::{generics, Generics}, + generics::{Generics, generics}, infer::normalize, - ClosureId, Const, Interner, ProjectionTy, Substitution, TraitEnvironment, Ty, TyKind, }; use super::{MirBody, MirLowerError, Operand, Rvalue, StatementKind, TerminatorKind}; diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs index 7d7d4106cb..d9c0000fff 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -7,14 +7,14 @@ use std::{ use either::Either; use hir_def::{expr_store::Body, hir::BindingId}; -use hir_expand::{name::Name, Lookup}; +use hir_expand::{Lookup, name::Name}; use la_arena::ArenaMap; use crate::{ + ClosureId, db::HirDatabase, display::{ClosureStyle, DisplayTarget, HirDisplay}, mir::{PlaceElem, ProjectionElem, StatementKind, TerminatorKind}, - ClosureId, }; use super::{ diff --git a/crates/hir-ty/src/target_feature.rs b/crates/hir-ty/src/target_feature.rs index fe9416c6cf..01e4160edb 100644 --- a/crates/hir-ty/src/target_feature.rs +++ b/crates/hir-ty/src/target_feature.rs @@ -4,7 +4,7 @@ use std::sync::LazyLock; use hir_def::attr::Attrs; use hir_def::tt; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use rustc_hash::{FxHashMap, FxHashSet}; #[derive(Debug, Default)] @@ -38,15 +38,17 @@ impl TargetFeatures { let enabled = attrs .by_key(&sym::target_feature) .tt_values() - .filter_map(|tt| { - match tt.token_trees().flat_tokens() { - [ - tt::TokenTree::Leaf(tt::Leaf::Ident(enable_ident)), - tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '=', .. })), - tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { kind: tt::LitKind::Str, symbol: features, .. })), - ] if enable_ident.sym == sym::enable => Some(features), - _ => None, - } + .filter_map(|tt| match tt.token_trees().flat_tokens() { + [ + tt::TokenTree::Leaf(tt::Leaf::Ident(enable_ident)), + tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '=', .. })), + tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { + kind: tt::LitKind::Str, + symbol: features, + .. + })), + ] if enable_ident.sym == sym::enable => Some(features), + _ => None, }) .flat_map(|features| features.as_str().split(',').map(Symbol::intern)) .collect(); diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs index 68d0c8cd5a..5f1bd57af8 100644 --- a/crates/hir-ty/src/test_db.rs +++ b/crates/hir-ty/src/test_db.rs @@ -7,7 +7,7 @@ use base_db::{ SourceRoot, SourceRootId, SourceRootInput, Upcast, }; -use hir_def::{db::DefDatabase, ModuleId}; +use hir_def::{ModuleId, db::DefDatabase}; use hir_expand::db::ExpandDatabase; use rustc_hash::FxHashMap; use salsa::{AsDynDatabase, Durability}; diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs index 13d74264c5..8790a31562 100644 --- a/crates/hir-ty/src/tests.rs +++ b/crates/hir-ty/src/tests.rs @@ -18,33 +18,33 @@ use std::sync::LazyLock; use base_db::{Crate, SourceDatabase}; use expect_test::Expect; use hir_def::{ + AssocItemId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleDefId, SyntheticSyntax, db::DefDatabase, expr_store::{Body, BodySourceMap}, hir::{ExprId, Pat, PatId}, item_scope::ItemScope, nameres::DefMap, src::HasSource, - AssocItemId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleDefId, SyntheticSyntax, }; -use hir_expand::{db::ExpandDatabase, FileRange, InFile}; +use hir_expand::{FileRange, InFile, db::ExpandDatabase}; use itertools::Itertools; use rustc_hash::FxHashMap; use stdx::format_to; use syntax::{ - ast::{self, AstNode, HasName}, SyntaxNode, + ast::{self, AstNode, HasName}, }; use test_fixture::WithFixture; -use tracing_subscriber::{layer::SubscriberExt, Registry}; +use tracing_subscriber::{Registry, layer::SubscriberExt}; use tracing_tree::HierarchicalLayer; use triomphe::Arc; use crate::{ + InferenceResult, Ty, db::HirDatabase, display::{DisplayTarget, HirDisplay}, infer::{Adjustment, TypeMismatch}, test_db::TestDB, - InferenceResult, Ty, }; // These tests compare the inference results for all expressions in a file diff --git a/crates/hir-ty/src/tests/closure_captures.rs b/crates/hir-ty/src/tests/closure_captures.rs index efb1728d05..7d4218939e 100644 --- a/crates/hir-ty/src/tests/closure_captures.rs +++ b/crates/hir-ty/src/tests/closure_captures.rs @@ -1,4 +1,4 @@ -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use hir_def::db::DefDatabase; use hir_expand::files::InFileWrapper; use itertools::Itertools; @@ -384,7 +384,9 @@ fn main() { }; } "#, - expect!["57..149;20..25;78..80,98..100,118..124,134..135 ByRef(Mut { kind: Default }) a &'? mut bool"], + expect![ + "57..149;20..25;78..80,98..100,118..124,134..135 ByRef(Mut { kind: Default }) a &'? mut bool" + ], ); } diff --git a/crates/hir-ty/src/tls.rs b/crates/hir-ty/src/tls.rs index 6cb59491fa..b718556c8a 100644 --- a/crates/hir-ty/src/tls.rs +++ b/crates/hir-ty/src/tls.rs @@ -5,8 +5,8 @@ use itertools::Itertools; use span::Edition; use crate::{ - chalk_db, db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, mapping::from_chalk, - CallableDefId, Interner, ProjectionTyExt, + CallableDefId, Interner, ProjectionTyExt, chalk_db, db::HirDatabase, from_assoc_type_id, + from_chalk_trait_id, mapping::from_chalk, }; use hir_def::{AdtId, ItemContainerId, Lookup, TypeAliasId}; @@ -131,11 +131,7 @@ mod unsafe_tls { pub(crate) fn with_current_program( op: impl for<'a> FnOnce(Option<&'a DebugContext<'a>>) -> R, ) -> R { - if PROGRAM.is_set() { - PROGRAM.with(|prog| op(Some(prog))) - } else { - op(None) - } + if PROGRAM.is_set() { PROGRAM.with(|prog| op(Some(prog))) } else { op(None) } } pub(crate) fn set_current_program(p: &dyn HirDatabase, op: OP) -> R diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs index f8db6a8298..92dea02c7b 100644 --- a/crates/hir-ty/src/traits.rs +++ b/crates/hir-ty/src/traits.rs @@ -3,14 +3,14 @@ use core::fmt; use std::env::var; -use chalk_ir::{fold::TypeFoldable, DebruijnIndex, GoalData}; +use chalk_ir::{DebruijnIndex, GoalData, fold::TypeFoldable}; use chalk_recursive::Cache; -use chalk_solve::{logging_db::LoggingRustIrDatabase, rust_ir, Solver}; +use chalk_solve::{Solver, logging_db::LoggingRustIrDatabase, rust_ir}; use base_db::Crate; use hir_def::{ - lang_item::{LangItem, LangItemTarget}, BlockId, TraitId, + lang_item::{LangItem, LangItemTarget}, }; use hir_expand::name::Name; use intern::sym; @@ -19,9 +19,9 @@ use stdx::{never, panic_context}; use triomphe::Arc; use crate::{ - db::HirDatabase, infer::unify::InferenceTable, utils::UnevaluatedConstEvaluatorFolder, AliasEq, - AliasTy, Canonical, DomainGoal, Goal, Guidance, InEnvironment, Interner, ProjectionTy, - ProjectionTyExt, Solution, TraitRefExt, Ty, TyKind, TypeFlags, WhereClause, + AliasEq, AliasTy, Canonical, DomainGoal, Goal, Guidance, InEnvironment, Interner, ProjectionTy, + ProjectionTyExt, Solution, TraitRefExt, Ty, TyKind, TypeFlags, WhereClause, db::HirDatabase, + infer::unify::InferenceTable, utils::UnevaluatedConstEvaluatorFolder, }; /// This controls how much 'time' we give the Chalk solver before giving up. @@ -190,11 +190,7 @@ fn solve( // don't set the TLS for Chalk unless Chalk debugging is active, to make // extra sure we only use it for debugging - if is_chalk_debug() { - crate::tls::set_current_program(db, solve) - } else { - solve() - } + if is_chalk_debug() { crate::tls::set_current_program(db, solve) } else { solve() } } struct LoggingRustIrDatabaseLoggingOnDrop<'a>(LoggingRustIrDatabase>); diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs index 3bd04b21b2..695527444d 100644 --- a/crates/hir-ty/src/utils.rs +++ b/crates/hir-ty/src/utils.rs @@ -5,33 +5,33 @@ use std::{hash::Hash, iter}; use base_db::Crate; use chalk_ir::{ - fold::{FallibleTypeFolder, Shift}, DebruijnIndex, + fold::{FallibleTypeFolder, Shift}, }; use hir_def::{ + EnumId, EnumVariantId, FunctionId, Lookup, OpaqueInternableThing, TraitId, TypeAliasId, + TypeOrConstParamId, db::DefDatabase, generics::{WherePredicate, WherePredicateTypeTarget}, lang_item::LangItem, resolver::{HasResolver, TypeNs}, type_ref::{TraitBoundModifier, TypeRef}, - EnumId, EnumVariantId, FunctionId, Lookup, OpaqueInternableThing, TraitId, TypeAliasId, - TypeOrConstParamId, }; use hir_expand::name::Name; use intern::sym; use rustc_abi::TargetDataLayout; use rustc_hash::FxHashSet; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::Edition; use stdx::never; use crate::{ + ChalkTraitId, Const, ConstScalar, GenericArg, Interner, Substitution, TargetFeatures, TraitRef, + TraitRefExt, Ty, WhereClause, consteval::unknown_const, db::HirDatabase, layout::{Layout, TagEncoding}, mir::pad16, - ChalkTraitId, Const, ConstScalar, GenericArg, Interner, Substitution, TargetFeatures, TraitRef, - TraitRefExt, Ty, WhereClause, }; pub(crate) fn fn_traits(db: &dyn DefDatabase, krate: Crate) -> impl Iterator + '_ { @@ -315,11 +315,7 @@ pub fn is_fn_unsafe_to_call( } else { // Function in an `extern` block are always unsafe to call, except when // it is marked as `safe`. - if data.is_safe() { - Unsafety::Safe - } else { - Unsafety::Unsafe - } + if data.is_safe() { Unsafety::Safe } else { Unsafety::Unsafe } } } _ => Unsafety::Safe, diff --git a/crates/hir-ty/src/variance.rs b/crates/hir-ty/src/variance.rs index ab3d098908..e8744e4629 100644 --- a/crates/hir-ty/src/variance.rs +++ b/crates/hir-ty/src/variance.rs @@ -14,7 +14,7 @@ //! while installing firewall per item queries to prevent invalidation issues. use crate::db::HirDatabase; -use crate::generics::{generics, Generics}; +use crate::generics::{Generics, generics}; use crate::{ AliasTy, Const, ConstScalar, DynTyExt, GenericArg, GenericArgData, Interner, Lifetime, LifetimeData, Ty, TyKind, @@ -487,13 +487,13 @@ impl Context<'_> { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use hir_def::{ - generics::GenericParamDataRef, src::HasSource, AdtId, GenericDefId, ModuleDefId, + AdtId, GenericDefId, ModuleDefId, generics::GenericParamDataRef, src::HasSource, }; use itertools::Itertools; use stdx::format_to; - use syntax::{ast::HasName, AstNode}; + use syntax::{AstNode, ast::HasName}; use test_fixture::WithFixture; use hir_def::Lookup; diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 1c88e79933..70637028ef 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -3,12 +3,12 @@ use std::ops::ControlFlow; use hir_def::{ + AssocItemId, AttrDefId, ModuleDefId, attr::AttrsWithOwner, item_scope::ItemInNs, path::{ModPath, Path}, per_ns::Namespace, resolver::{HasResolver, Resolver, TypeNs}, - AssocItemId, AttrDefId, ModuleDefId, }; use hir_expand::{mod_path::PathKind, name::Name}; use hir_ty::{db::HirDatabase, method_resolution}; @@ -273,11 +273,7 @@ fn resolve_impl_trait_item( // disambiguation) so we just pick the first one we find as well. result = as_module_def_if_namespace_matches(assoc_item_id.into(), ns); - if result.is_some() { - ControlFlow::Break(()) - } else { - ControlFlow::Continue(()) - } + if result.is_some() { ControlFlow::Break(()) } else { ControlFlow::Continue(()) } }, ); diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 1ed0daa375..a9893e741d 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -6,22 +6,23 @@ use cfg::{CfgExpr, CfgOptions}; use either::Either; use hir_def::{ + DefWithBodyId, SyntheticSyntax, expr_store::ExprOrPatPtr, hir::ExprOrPatId, - path::{hir_segment_to_ast_segment, ModPath}, + path::{ModPath, hir_segment_to_ast_segment}, type_ref::TypesSourceMap, - DefWithBodyId, SyntheticSyntax, }; -use hir_expand::{name::Name, HirFileId, InFile}; +use hir_expand::{HirFileId, InFile, name::Name}; use hir_ty::{ - db::HirDatabase, - diagnostics::{BodyValidationDiagnostic, UnsafetyReason}, CastError, InferenceDiagnostic, InferenceTyDiagnosticSource, PathLoweringDiagnostic, TyLoweringDiagnostic, TyLoweringDiagnosticKind, + db::HirDatabase, + diagnostics::{BodyValidationDiagnostic, UnsafetyReason}, }; use syntax::{ + AstNode, AstPtr, SyntaxError, SyntaxNodePtr, TextRange, ast::{self, HasGenericArgs}, - match_ast, AstNode, AstPtr, SyntaxError, SyntaxNodePtr, TextRange, + match_ast, }; use triomphe::Arc; @@ -29,8 +30,8 @@ use crate::{AssocItem, Field, Function, Local, Trait, Type}; pub use hir_def::VariantId; pub use hir_ty::{ - diagnostics::{CaseType, IncorrectCase}, GenericArgsProhibitedReason, + diagnostics::{CaseType, IncorrectCase}, }; macro_rules! diagnostics { diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 6f4168ab08..ec34fd80ad 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -1,9 +1,10 @@ //! HirDisplay implementations for various hir types. use either::Either; use hir_def::{ + AdtId, GenericDefId, data::{ - adt::{StructKind, VariantData}, TraitFlags, + adt::{StructKind, VariantData}, }, generics::{ GenericParams, TypeOrConstParamData, TypeParamProvenance, WherePredicate, @@ -11,14 +12,13 @@ use hir_def::{ }, lang_item::LangItem, type_ref::{TypeBound, TypeRef}, - AdtId, GenericDefId, }; use hir_ty::{ - display::{ - hir_display_with_types_map, write_bounds_like_dyn_trait_with_prefix, write_visibility, - HirDisplay, HirDisplayError, HirDisplayWithTypesMap, HirFormatter, SizedByDefault, - }, AliasEq, AliasTy, Interner, ProjectionTyExt, TraitRefExt, TyKind, WhereClause, + display::{ + HirDisplay, HirDisplayError, HirDisplayWithTypesMap, HirFormatter, SizedByDefault, + hir_display_with_types_map, write_bounds_like_dyn_trait_with_prefix, write_visibility, + }, }; use itertools::Itertools; @@ -854,7 +854,7 @@ impl HirDisplay for Module { return match self.krate(f.db).display_name(f.db) { Some(name) => write!(f, "extern crate {name}"), None => f.write_str("extern crate {unknown}"), - } + }; } } match self.name(f.db) { diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs index 891d2fd2ba..ab4b4a8dae 100644 --- a/crates/hir/src/from_id.rs +++ b/crates/hir/src/from_id.rs @@ -4,9 +4,9 @@ //! are splitting the hir. use hir_def::{ - hir::{BindingId, LabelId}, AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, GenericDefId, GenericParamId, ModuleDefId, VariantId, + hir::{BindingId, LabelId}, }; use crate::{ diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index b4468178fb..3d9c04d387 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -2,9 +2,9 @@ use either::Either; use hir_def::{ + CallableDefId, Lookup, MacroId, VariantId, nameres::{ModuleOrigin, ModuleSource}, src::{HasChildSource, HasSource as _}, - CallableDefId, Lookup, MacroId, VariantId, }; use hir_expand::{HirFileId, InFile}; use hir_ty::db::InternedClosure; @@ -13,9 +13,10 @@ use syntax::ast; use tt::TextRange; use crate::{ - db::HirDatabase, Adt, Callee, Const, Enum, ExternCrateDecl, Field, FieldSource, Function, Impl, + Adt, Callee, Const, Enum, ExternCrateDecl, Field, FieldSource, Function, Impl, InlineAsmOperand, Label, LifetimeParam, LocalSource, Macro, Module, Param, SelfParam, Static, Struct, Trait, TraitAlias, TypeAlias, TypeOrConstParam, Union, Variant, VariantDef, + db::HirDatabase, }; pub trait HasSource { diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index caf00665a1..b3bb4a0a33 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -42,7 +42,12 @@ use arrayvec::ArrayVec; use base_db::{CrateDisplayName, CrateOrigin, LangCrateOrigin}; use either::Either; use hir_def::{ - data::{adt::VariantData, TraitFlags}, + AdtId, AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId, + CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, + FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstId, ItemContainerId, + LifetimeParamId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, + SyntheticSyntax, TraitAliasId, TupleId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId, + data::{TraitFlags, adt::VariantData}, expr_store::ExpressionStoreDiagnostics, generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, hir::{BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, LabelId, Pat}, @@ -54,30 +59,24 @@ use hir_def::{ per_ns::PerNs, resolver::{HasResolver, Resolver}, type_ref::TypesSourceMap, - AdtId, AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId, - CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, - FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstId, ItemContainerId, - LifetimeParamId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, - SyntheticSyntax, TraitAliasId, TupleId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId, }; use hir_expand::{ - attrs::collect_attrs, proc_macro::ProcMacroKind, AstId, MacroCallKind, RenderedExpandError, - ValueResult, + AstId, MacroCallKind, RenderedExpandError, ValueResult, attrs::collect_attrs, + proc_macro::ProcMacroKind, }; use hir_ty::{ - all_super_traits, autoderef, check_orphan_rules, - consteval::{try_const_usize, unknown_const_as_generic, ConstExt}, + AliasTy, CallableSig, Canonical, CanonicalVarKinds, Cast, ClosureId, GenericArg, + GenericArgData, Interner, ParamKind, QuantifiedWhereClause, Scalar, Substitution, + TraitEnvironment, TraitRefExt, Ty, TyBuilder, TyDefId, TyExt, TyKind, TyLoweringDiagnostic, + ValueTyDefId, WhereClause, all_super_traits, autoderef, check_orphan_rules, + consteval::{ConstExt, try_const_usize, unknown_const_as_generic}, diagnostics::BodyValidationDiagnostic, direct_super_traits, error_lifetime, known_const_to_ast, layout::{Layout as TyLayout, RustcEnumVariantIdx, RustcFieldIdx, TagEncoding}, method_resolution, - mir::{interpret_mir, MutBorrowKind}, + mir::{MutBorrowKind, interpret_mir}, primitive::UintTy, traits::FnTrait, - AliasTy, CallableSig, Canonical, CanonicalVarKinds, Cast, ClosureId, GenericArg, - GenericArgData, Interner, ParamKind, QuantifiedWhereClause, Scalar, Substitution, - TraitEnvironment, TraitRefExt, Ty, TyBuilder, TyDefId, TyExt, TyKind, TyLoweringDiagnostic, - ValueTyDefId, WhereClause, }; use itertools::Itertools; use nameres::diagnostics::DefDiagnosticKind; @@ -86,15 +85,16 @@ use smallvec::SmallVec; use span::{Edition, EditionedFileId, FileId, MacroCallId}; use stdx::{format_to, impl_from, never}; use syntax::{ + AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, T, TextRange, ToSmolStr, ast::{self, HasAttrs as _, HasGenericParams, HasName}, - format_smolstr, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, ToSmolStr, T, + format_smolstr, }; use triomphe::{Arc, ThinArc}; use crate::db::{DefDatabase, HirDatabase}; pub use crate::{ - attrs::{resolve_doc_path_on, HasAttrs}, + attrs::{HasAttrs, resolve_doc_path_on}, diagnostics::*, has_source::HasSource, semantics::{ @@ -114,6 +114,7 @@ pub use crate::{ pub use { cfg::{CfgAtom, CfgExpr, CfgOptions}, hir_def::{ + ImportPathConfig, attr::{AttrSourceMap, Attrs, AttrsWithOwner}, data::adt::StructKind, find_path::PrefixKind, @@ -124,12 +125,12 @@ pub use { per_ns::Namespace, type_ref::{Mutability, TypeRef}, visibility::Visibility, - ImportPathConfig, // FIXME: This is here since some queries take it as input that are used // outside of hir. {ModuleDefId, TraitId}, }, hir_expand::{ + ExpandResult, HirFileId, HirFileIdExt, MacroFileId, MacroFileIdExt, MacroKind, attrs::{Attr, AttrId}, change::ChangeWithProcMacros, files::{ @@ -137,15 +138,16 @@ pub use { HirFileRange, InFile, InFileWrapper, InMacroFile, InRealFile, MacroFilePosition, MacroFileRange, }, - hygiene::{marks_rev, SyntaxContextExt}, + hygiene::{SyntaxContextExt, marks_rev}, inert_attr_macro::AttributeTemplate, mod_path::tool_path, name::Name, prettify_macro_expansion, proc_macro::{ProcMacros, ProcMacrosBuilder}, - tt, ExpandResult, HirFileId, HirFileIdExt, MacroFileId, MacroFileIdExt, MacroKind, + tt, }, hir_ty::{ + CastError, DropGlue, FnAbi, PointerCast, Safety, Variance, consteval::ConstEvalError, diagnostics::UnsafetyReason, display::{ClosureStyle, DisplayTarget, HirDisplay, HirDisplayError, HirWrite}, @@ -153,11 +155,10 @@ pub use { layout::LayoutError, method_resolution::TyFingerprint, mir::{MirEvalError, MirLowerError}, - CastError, DropGlue, FnAbi, PointerCast, Safety, Variance, }, // FIXME: Properly encapsulate mir - hir_ty::{mir, Interner as ChalkTyInterner}, - intern::{sym, Symbol}, + hir_ty::{Interner as ChalkTyInterner, mir}, + intern::{Symbol, sym}, }; // These are negative re-exports: pub using these names is forbidden, they @@ -587,11 +588,7 @@ impl Module { if let Some(m) = visible_from { let filtered = def.filter_visibility(|vis| vis.is_visible_from(db.upcast(), m.id)); - if filtered.is_none() && !def.is_none() { - None - } else { - Some((name, filtered)) - } + if filtered.is_none() && !def.is_none() { None } else { Some((name, filtered)) } } else { Some((name, def)) } @@ -1759,19 +1756,11 @@ impl Adt { } pub fn as_struct(&self) -> Option { - if let Self::Struct(v) = self { - Some(*v) - } else { - None - } + if let Self::Struct(v) = self { Some(*v) } else { None } } pub fn as_enum(&self) -> Option { - if let Self::Enum(v) = self { - Some(*v) - } else { - None - } + if let Self::Enum(v) = self { Some(*v) } else { None } } } @@ -5080,11 +5069,7 @@ impl Type { let projection = TyBuilder::assoc_type_projection(db, alias.id, Some(parent_subst)).build(); let ty = db.normalize_projection(projection, self.env.clone()); - if ty.is_unknown() { - None - } else { - Some(self.derived(ty)) - } + if ty.is_unknown() { None } else { Some(self.derived(ty)) } } pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { @@ -5261,7 +5246,10 @@ impl Type { /// Returns types that this type dereferences to (including this type itself). The returned /// iterator won't yield the same type more than once even if the deref chain contains a cycle. - pub fn autoderef<'db>(&self, db: &'db dyn HirDatabase) -> impl Iterator + use<'_, 'db> { + pub fn autoderef<'db>( + &self, + db: &'db dyn HirDatabase, + ) -> impl Iterator + use<'_, 'db> { self.autoderef_(db).map(move |ty| self.derived(ty)) } diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index a1c0521a5e..604099aaa5 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -12,6 +12,7 @@ use std::{ use either::Either; use hir_def::{ + AsMacroCall, DefWithBodyId, FunctionId, MacroId, StructId, TraitId, VariantId, expr_store::{Body, ExprOrPatSource}, hir::{BindingId, Expr, ExprId, ExprOrPatId, Pat}, lower::LowerCtx, @@ -19,9 +20,9 @@ use hir_def::{ path::ModPath, resolver::{self, HasResolver, Resolver, TypeNs}, type_ref::{Mutability, TypesMap, TypesSourceMap}, - AsMacroCall, DefWithBodyId, FunctionId, MacroId, StructId, TraitId, VariantId, }; use hir_expand::{ + ExpandResult, FileRange, InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt, attrs::collect_attrs, builtin::{BuiltinFnLikeExpander, EagerExpander}, db::ExpandDatabase, @@ -29,32 +30,31 @@ use hir_expand::{ hygiene::SyntaxContextExt as _, inert_attr_macro::find_builtin_attr_idx, name::AsName, - ExpandResult, FileRange, InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt, }; use hir_ty::diagnostics::unsafe_operations_for_body; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::{AstIdMap, EditionedFileId, FileId, HirFileIdRepr, SyntaxContext}; use stdx::TupleExt; use syntax::{ - algo::skip_trivia_token, - ast::{self, HasAttrs as _, HasGenericParams}, AstNode, AstToken, Direction, SyntaxKind, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize, + algo::skip_trivia_token, + ast::{self, HasAttrs as _, HasGenericParams}, }; use triomphe::Arc; use crate::{ - db::HirDatabase, - semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, - source_analyzer::{name_hygiene, resolve_hir_path, SourceAnalyzer}, Adjust, Adjustment, Adt, AutoBorrow, BindingMode, BuiltinAttr, Callable, Const, ConstParam, Crate, DefWithBody, DeriveHelper, Enum, Field, Function, GenericSubstitution, HasSource, HirFileId, Impl, InFile, InlineAsmOperand, ItemInNs, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name, OverloadedDeref, Path, ScopeDef, Static, Struct, ToolModule, Trait, TraitAlias, TupleField, Type, TypeAlias, TypeParam, Union, Variant, VariantDef, + db::HirDatabase, + semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, + source_analyzer::{SourceAnalyzer, name_hygiene, resolve_hir_path}, }; const CONTINUE_NO_BREAKS: ControlFlow = ControlFlow::Continue(()); @@ -963,11 +963,7 @@ impl<'db> SemanticsImpl<'db> { || kind.is_any_identifier() && value.kind().is_any_identifier(); let matches = (kind == mapped_kind || any_ident_match()) && text == value.text(); - if matches { - ControlFlow::Break(value) - } else { - ControlFlow::Continue(()) - } + if matches { ControlFlow::Break(value) } else { ControlFlow::Continue(()) } }, ) } else { @@ -1780,7 +1776,7 @@ impl<'db> SemanticsImpl<'db> { SourceAnalyzer::new_for_body(self.db, def, node, offset) } else { SourceAnalyzer::new_for_body_no_infer(self.db, def, node, offset) - }) + }); } ChildContainer::TraitId(it) => it.resolver(self.db.upcast()), ChildContainer::TraitAliasId(it) => it.resolver(self.db.upcast()), diff --git a/crates/hir/src/semantics/child_by_source.rs b/crates/hir/src/semantics/child_by_source.rs index b89d332238..f172eec32a 100644 --- a/crates/hir/src/semantics/child_by_source.rs +++ b/crates/hir/src/semantics/child_by_source.rs @@ -5,22 +5,22 @@ //! node for a *child*, and get its hir. use either::Either; -use hir_expand::{attrs::collect_attrs, HirFileId}; -use syntax::{ast, AstPtr}; +use hir_expand::{HirFileId, attrs::collect_attrs}; +use syntax::{AstPtr, ast}; use hir_def::{ + AdtId, AssocItemId, DefWithBodyId, EnumId, FieldId, GenericDefId, ImplId, ItemTreeLoc, + LifetimeParamId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, TypeOrConstParamId, + VariantId, db::DefDatabase, dyn_map::{ - keys::{self, Key}, DynMap, + keys::{self, Key}, }, item_scope::ItemScope, item_tree::ItemTreeNode, nameres::DefMap, src::{HasChildSource, HasSource}, - AdtId, AssocItemId, DefWithBodyId, EnumId, FieldId, GenericDefId, ImplId, ItemTreeLoc, - LifetimeParamId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, TypeOrConstParamId, - VariantId, }; pub(crate) trait ChildBySource { diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 4ec0739656..d5695f1c21 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -88,30 +88,30 @@ use base_db::{RootQueryDb, Upcast}; use either::Either; use hir_def::{ - dyn_map::{ - keys::{self, Key}, - DynMap, - }, - hir::{BindingId, Expr, LabelId}, AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, FieldId, FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId, Lookup, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, UseId, VariantId, + dyn_map::{ + DynMap, + keys::{self, Key}, + }, + hir::{BindingId, Expr, LabelId}, }; use hir_expand::{ - attrs::AttrId, name::AsName, ExpansionInfo, HirFileId, HirFileIdExt, InMacroFile, MacroCallId, - MacroFileId, MacroFileIdExt, + ExpansionInfo, HirFileId, HirFileIdExt, InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt, + attrs::AttrId, name::AsName, }; use rustc_hash::FxHashMap; use smallvec::SmallVec; use span::{EditionedFileId, FileId}; use stdx::impl_from; use syntax::{ - ast::{self, HasName}, AstNode, AstPtr, SyntaxNode, + ast::{self, HasName}, }; -use crate::{db::HirDatabase, semantics::child_by_source::ChildBySource, InFile, InlineAsmOperand}; +use crate::{InFile, InlineAsmOperand, db::HirDatabase, semantics::child_by_source::ChildBySource}; #[derive(Default)] pub(super) struct SourceToDefCache { diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index e390fb0b93..ce9f56993e 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -8,48 +8,49 @@ use std::iter::{self, once}; use crate::{ - db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BindingMode, BuiltinAttr, - BuiltinType, Callable, Const, DeriveHelper, Field, Function, GenericSubstitution, Local, Macro, - ModuleDef, Static, Struct, ToolModule, Trait, TraitAlias, TupleField, Type, TypeAlias, Variant, + Adt, AssocItem, BindingMode, BuiltinAttr, BuiltinType, Callable, Const, DeriveHelper, Field, + Function, GenericSubstitution, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait, + TraitAlias, TupleField, Type, TypeAlias, Variant, db::HirDatabase, semantics::PathResolution, }; use either::Either; use hir_def::{ + AsMacroCall, AssocItemId, CallableDefId, ConstId, DefWithBodyId, FieldId, FunctionId, + ItemContainerId, LocalFieldId, Lookup, ModuleDefId, StructId, TraitId, VariantId, expr_store::{ - scope::{ExprScopes, ScopeId}, Body, BodySourceMap, HygieneId, + scope::{ExprScopes, ScopeId}, }, hir::{BindingId, Expr, ExprId, ExprOrPatId, Pat}, lang_item::LangItem, lower::LowerCtx, nameres::MacroSubNs, path::{ModPath, Path, PathKind}, - resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs}, + resolver::{Resolver, TypeNs, ValueNs, resolver_for_scope}, type_ref::{Mutability, TypesMap, TypesSourceMap}, - AsMacroCall, AssocItemId, CallableDefId, ConstId, DefWithBodyId, FieldId, FunctionId, - ItemContainerId, LocalFieldId, Lookup, ModuleDefId, StructId, TraitId, VariantId, }; use hir_expand::{ + HirFileId, InFile, InMacroFile, MacroFileId, MacroFileIdExt, mod_path::path, name::{AsName, Name}, - HirFileId, InFile, InMacroFile, MacroFileId, MacroFileIdExt, }; use hir_ty::{ + Adjustment, InferenceResult, Interner, Substitution, TraitEnvironment, Ty, TyExt, TyKind, + TyLoweringContext, diagnostics::{ - record_literal_missing_fields, record_pattern_missing_fields, unsafe_operations, - InsideUnsafeBlock, + InsideUnsafeBlock, record_literal_missing_fields, record_pattern_missing_fields, + unsafe_operations, }, from_assoc_type_id, lang_items::lang_items_for_bin_op, - method_resolution, Adjustment, InferenceResult, Interner, Substitution, TraitEnvironment, Ty, - TyExt, TyKind, TyLoweringContext, + method_resolution, }; use intern::sym; use itertools::Itertools; use smallvec::SmallVec; use syntax::ast::{RangeItem, RangeOp}; use syntax::{ - ast::{self, AstNode}, SyntaxKind, SyntaxNode, TextRange, TextSize, + ast::{self, AstNode}, }; use triomphe::Arc; @@ -147,11 +148,7 @@ impl SourceAnalyzer { fn binding_id_of_pat(&self, pat: &ast::IdentPat) -> Option { let pat_id = self.pat_id(&pat.clone().into())?; - if let Pat::Bind { id, .. } = self.body()?.pats[pat_id.as_pat()?] { - Some(id) - } else { - None - } + if let Pat::Bind { id, .. } = self.body()?.pats[pat_id.as_pat()?] { Some(id) } else { None } } fn expand_expr( @@ -504,11 +501,7 @@ impl SourceAnalyzer { LangItem::DerefMut, &Name::new_symbol_root(sym::deref_mut.clone()), )?; - if func == deref_mut { - Some((deref_mut_trait, deref_mut)) - } else { - None - } + if func == deref_mut { Some((deref_mut_trait, deref_mut)) } else { None } }) .unwrap_or((deref_trait, deref)) } @@ -550,11 +543,7 @@ impl SourceAnalyzer { LangItem::IndexMut, &Name::new_symbol_root(sym::index_mut.clone()), )?; - if func == index_mut_fn { - Some((index_mut_trait, index_mut_fn)) - } else { - None - } + if func == index_mut_fn { Some((index_mut_trait, index_mut_fn)) } else { None } }) .unwrap_or((index_trait, index_fn)); // HACK: subst for all methods coincides with that for their trait because the methods diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs index 853df7ee2d..ae70f6f0ec 100644 --- a/crates/hir/src/symbols.rs +++ b/crates/hir/src/symbols.rs @@ -2,22 +2,22 @@ use either::Either; use hir_def::{ + AdtId, AssocItemId, DefWithBodyId, ExternCrateId, HasModule, ImplId, Lookup, MacroId, + ModuleDefId, ModuleId, TraitId, db::DefDatabase, item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob}, per_ns::Item, src::{HasChildSource, HasSource}, visibility::{Visibility, VisibilityExplicitness}, - AdtId, AssocItemId, DefWithBodyId, ExternCrateId, HasModule, ImplId, Lookup, MacroId, - ModuleDefId, ModuleId, TraitId, }; -use hir_expand::{name::Name, HirFileId}; +use hir_expand::{HirFileId, name::Name}; use hir_ty::{ db::HirDatabase, - display::{hir_display_with_types_map, DisplayTarget, HirDisplay}, + display::{DisplayTarget, HirDisplay, hir_display_with_types_map}, }; use intern::Symbol; use rustc_hash::FxHashMap; -use syntax::{ast::HasName, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr}; +use syntax::{AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName}; use crate::{Module, ModuleDef, Semantics}; diff --git a/crates/hir/src/term_search/tactics.rs b/crates/hir/src/term_search/tactics.rs index 847304d503..bcff44fcd0 100644 --- a/crates/hir/src/term_search/tactics.rs +++ b/crates/hir/src/term_search/tactics.rs @@ -10,9 +10,9 @@ use std::iter; +use hir_ty::TyBuilder; use hir_ty::db::HirDatabase; use hir_ty::mir::BorrowKind; -use hir_ty::TyBuilder; use itertools::Itertools; use rustc_hash::FxHashSet; use span::Edition; diff --git a/crates/ide-assists/src/assist_config.rs b/crates/ide-assists/src/assist_config.rs index 05105c8c92..2de0013bb1 100644 --- a/crates/ide-assists/src/assist_config.rs +++ b/crates/ide-assists/src/assist_config.rs @@ -5,7 +5,7 @@ //! assists if we are allowed to. use hir::ImportPathConfig; -use ide_db::{imports::insert_use::InsertUseConfig, SnippetCap}; +use ide_db::{SnippetCap, imports::insert_use::InsertUseConfig}; use crate::AssistKind; diff --git a/crates/ide-assists/src/assist_context.rs b/crates/ide-assists/src/assist_context.rs index c4e98c0742..afb2229d3e 100644 --- a/crates/ide-assists/src/assist_context.rs +++ b/crates/ide-assists/src/assist_context.rs @@ -1,18 +1,18 @@ //! See [`AssistContext`]. use hir::{FileRange, Semantics}; -use ide_db::base_db::salsa::AsDynDatabase; use ide_db::EditionedFileId; -use ide_db::{label::Label, FileId, RootDatabase}; +use ide_db::base_db::salsa::AsDynDatabase; +use ide_db::{FileId, RootDatabase, label::Label}; use syntax::Edition; use syntax::{ - algo::{self, find_node_at_offset, find_node_at_range}, AstNode, AstToken, Direction, SourceFile, SyntaxElement, SyntaxKind, SyntaxToken, TextRange, TextSize, TokenAtOffset, + algo::{self, find_node_at_offset, find_node_at_range}, }; use crate::{ - assist_config::AssistConfig, Assist, AssistId, AssistKind, AssistResolveStrategy, GroupLabel, + Assist, AssistId, AssistKind, AssistResolveStrategy, GroupLabel, assist_config::AssistConfig, }; pub(crate) use ide_db::source_change::{SourceChangeBuilder, TreeMutator}; diff --git a/crates/ide-assists/src/handlers/add_braces.rs b/crates/ide-assists/src/handlers/add_braces.rs index 42f615e71d..f9124d2d46 100644 --- a/crates/ide-assists/src/handlers/add_braces.rs +++ b/crates/ide-assists/src/handlers/add_braces.rs @@ -1,6 +1,6 @@ use syntax::{ - ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory}, AstNode, + ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/add_explicit_enum_discriminant.rs b/crates/ide-assists/src/handlers/add_explicit_enum_discriminant.rs index 1a5de9cb07..c8a6f9e65c 100644 --- a/crates/ide-assists/src/handlers/add_explicit_enum_discriminant.rs +++ b/crates/ide-assists/src/handlers/add_explicit_enum_discriminant.rs @@ -1,10 +1,10 @@ use hir::Semantics; use ide_db::{ + RootDatabase, assists::{AssistId, AssistKind}, source_change::SourceChangeBuilder, - RootDatabase, }; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/add_label_to_loop.rs b/crates/ide-assists/src/handlers/add_label_to_loop.rs index 001f1e8bb1..fc10501543 100644 --- a/crates/ide-assists/src/handlers/add_label_to_loop.rs +++ b/crates/ide-assists/src/handlers/add_label_to_loop.rs @@ -1,7 +1,7 @@ use ide_db::syntax_helpers::node_ext::for_each_break_and_continue_expr; use syntax::{ - ast::{self, AstNode, HasLoopBody}, T, + ast::{self, AstNode, HasLoopBody}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/add_lifetime_to_type.rs b/crates/ide-assists/src/handlers/add_lifetime_to_type.rs index 43c0a72fa4..c3e05b8fb0 100644 --- a/crates/ide-assists/src/handlers/add_lifetime_to_type.rs +++ b/crates/ide-assists/src/handlers/add_lifetime_to_type.rs @@ -99,11 +99,7 @@ fn fetch_borrowed_types(node: &ast::Adt) -> Option> { } }; - if ref_types.is_empty() { - None - } else { - Some(ref_types) - } + if ref_types.is_empty() { None } else { Some(ref_types) } } fn find_ref_types_from_field_list(field_list: &ast::FieldList) -> Option> { @@ -134,11 +130,7 @@ fn find_ref_types_from_field_list(field_list: &ast::FieldList) -> Option) -> Opti let def = match NameRefClass::classify(&ctx.sema, &name_ref)? { NameRefClass::Definition(def, _) => def, NameRefClass::FieldShorthand { .. } | NameRefClass::ExternCrateShorthand { .. } => { - return None + return None; } }; let fun = match def { diff --git a/crates/ide-assists/src/handlers/apply_demorgan.rs b/crates/ide-assists/src/handlers/apply_demorgan.rs index 67bf8eed23..e584c709a9 100644 --- a/crates/ide-assists/src/handlers/apply_demorgan.rs +++ b/crates/ide-assists/src/handlers/apply_demorgan.rs @@ -6,19 +6,18 @@ use ide_db::{ syntax_helpers::node_ext::{for_each_tail_expr, walk_expr}, }; use syntax::{ + SyntaxKind, T, ast::{ - self, - prec::{precedence, ExprPrecedence}, - syntax_factory::SyntaxFactory, - AstNode, + self, AstNode, Expr::BinExpr, HasArgList, + prec::{ExprPrecedence, precedence}, + syntax_factory::SyntaxFactory, }, syntax_editor::{Position, SyntaxEditor}, - SyntaxKind, T, }; -use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils::invert_boolean_expression}; // Assist: apply_demorgan // diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs index a92a000c3f..f491b9375c 100644 --- a/crates/ide-assists/src/handlers/auto_import.rs +++ b/crates/ide-assists/src/handlers/auto_import.rs @@ -1,14 +1,14 @@ use std::cmp::Reverse; -use hir::{db::HirDatabase, Module}; +use hir::{Module, db::HirDatabase}; use ide_db::{ helpers::mod_path_to_ast, imports::{ import_assets::{ImportAssets, ImportCandidate, LocatedImport}, - insert_use::{insert_use, insert_use_as_alias, ImportScope}, + insert_use::{ImportScope, insert_use, insert_use_as_alias}, }, }; -use syntax::{ast, AstNode, Edition, NodeOrToken, SyntaxElement}; +use syntax::{AstNode, Edition, NodeOrToken, SyntaxElement, ast}; use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; @@ -279,12 +279,12 @@ mod tests { use super::*; use hir::{FileRange, Semantics}; - use ide_db::{assists::AssistResolveStrategy, RootDatabase}; + use ide_db::{RootDatabase, assists::AssistResolveStrategy}; use test_fixture::WithFixture; use crate::tests::{ - check_assist, check_assist_by_label, check_assist_not_applicable, check_assist_target, - TEST_CONFIG, + TEST_CONFIG, check_assist, check_assist_by_label, check_assist_not_applicable, + check_assist_target, }; fn check_auto_import_order(before: &str, order: &[&str]) { diff --git a/crates/ide-assists/src/handlers/bind_unused_param.rs b/crates/ide-assists/src/handlers/bind_unused_param.rs index 8f053f4df9..5048ff5163 100644 --- a/crates/ide-assists/src/handlers/bind_unused_param.rs +++ b/crates/ide-assists/src/handlers/bind_unused_param.rs @@ -1,12 +1,12 @@ use crate::assist_context::{AssistContext, Assists}; use ide_db::{ + LineIndexDatabase, assists::{AssistId, AssistKind}, defs::Definition, - LineIndexDatabase, }; use syntax::{ - ast::{self, edit_in_place::Indent}, AstNode, + ast::{self, edit_in_place::Indent}, }; // Assist: bind_unused_param diff --git a/crates/ide-assists/src/handlers/change_visibility.rs b/crates/ide-assists/src/handlers/change_visibility.rs index 07fd5e3418..8af9121fc8 100644 --- a/crates/ide-assists/src/handlers/change_visibility.rs +++ b/crates/ide-assists/src/handlers/change_visibility.rs @@ -1,14 +1,14 @@ use syntax::{ - ast::{self, HasName, HasVisibility}, AstNode, SyntaxKind::{ self, ASSOC_ITEM_LIST, CONST, ENUM, FN, MACRO_DEF, MODULE, SOURCE_FILE, STATIC, STRUCT, TRAIT, TYPE_ALIAS, USE, VISIBILITY, }, SyntaxNode, T, + ast::{self, HasName, HasVisibility}, }; -use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils::vis_offset}; // Assist: change_visibility // diff --git a/crates/ide-assists/src/handlers/convert_bool_then.rs b/crates/ide-assists/src/handlers/convert_bool_then.rs index 151c71c0a7..c4a2189f69 100644 --- a/crates/ide-assists/src/handlers/convert_bool_then.rs +++ b/crates/ide-assists/src/handlers/convert_bool_then.rs @@ -1,21 +1,21 @@ -use hir::{sym, AsAssocItem, Semantics}; +use hir::{AsAssocItem, Semantics, sym}; use ide_db::{ + RootDatabase, famous_defs::FamousDefs, syntax_helpers::node_ext::{ block_as_lone_tail, for_each_tail_expr, is_pattern_cond, preorder_expr, }, - RootDatabase, }; use itertools::Itertools; use syntax::{ - ast::{self, edit::AstNodeEdit, syntax_factory::SyntaxFactory, HasArgList}, - syntax_editor::SyntaxEditor, AstNode, SyntaxNode, + ast::{self, HasArgList, edit::AstNodeEdit, syntax_factory::SyntaxFactory}, + syntax_editor::SyntaxEditor, }; use crate::{ - utils::{invert_boolean_expression, unwrap_trivial_block}, AssistContext, AssistId, AssistKind, Assists, + utils::{invert_boolean_expression, unwrap_trivial_block}, }; // Assist: convert_if_to_bool_then diff --git a/crates/ide-assists/src/handlers/convert_bool_to_enum.rs b/crates/ide-assists/src/handlers/convert_bool_to_enum.rs index 9cb14e8d9a..8200ad75df 100644 --- a/crates/ide-assists/src/handlers/convert_bool_to_enum.rs +++ b/crates/ide-assists/src/handlers/convert_bool_to_enum.rs @@ -2,23 +2,23 @@ use either::Either; use hir::ModuleDef; use ide_db::text_edit::TextRange; use ide_db::{ + FxHashSet, assists::{AssistId, AssistKind}, defs::Definition, helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope}, + imports::insert_use::{ImportScope, insert_use}, search::{FileReference, UsageSearchResult}, source_change::SourceChangeBuilder, - FxHashSet, }; use itertools::Itertools; use syntax::{ + AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T, ast::{ - self, + self, HasName, edit::IndentLevel, edit_in_place::{AttrsOwnerEdit, Indent}, - make, HasName, + make, }, - AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T, }; use crate::{ diff --git a/crates/ide-assists/src/handlers/convert_closure_to_fn.rs b/crates/ide-assists/src/handlers/convert_closure_to_fn.rs index 54826f0388..c11a411fb9 100644 --- a/crates/ide-assists/src/handlers/convert_closure_to_fn.rs +++ b/crates/ide-assists/src/handlers/convert_closure_to_fn.rs @@ -1,23 +1,24 @@ use either::Either; use hir::{CaptureKind, ClosureCapture, FileRangeWrapper, HirDisplay}; use ide_db::{ + FxHashSet, assists::{AssistId, AssistKind}, base_db::SourceDatabase, defs::Definition, search::FileReferenceNode, source_change::SourceChangeBuilder, - FxHashSet, }; use stdx::format_to; use syntax::{ + AstNode, Direction, SyntaxKind, SyntaxNode, T, TextSize, ToSmolStr, algo::{skip_trivia_token, skip_whitespace_token}, ast::{ - self, + self, HasArgList, HasGenericParams, HasName, edit::{AstNodeEdit, IndentLevel}, - make, HasArgList, HasGenericParams, HasName, + make, }, hacks::parse_expr_from_str, - ted, AstNode, Direction, SyntaxKind, SyntaxNode, TextSize, ToSmolStr, T, + ted, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/convert_comment_block.rs b/crates/ide-assists/src/handlers/convert_comment_block.rs index fbc0b9f673..92b86cee35 100644 --- a/crates/ide-assists/src/handlers/convert_comment_block.rs +++ b/crates/ide-assists/src/handlers/convert_comment_block.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use syntax::{ - ast::{self, edit::IndentLevel, Comment, CommentKind, CommentShape, Whitespace}, AstToken, Direction, SyntaxElement, TextRange, + ast::{self, Comment, CommentKind, CommentShape, Whitespace, edit::IndentLevel}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -167,11 +167,7 @@ pub(crate) fn line_comment_text(indentation: IndentLevel, comm: ast::Comment) -> let contents = contents_without_prefix.strip_prefix(' ').unwrap_or(contents_without_prefix); // Don't add the indentation if the line is empty - if contents.is_empty() { - contents.to_owned() - } else { - indentation.to_string() + contents - } + if contents.is_empty() { contents.to_owned() } else { indentation.to_string() + contents } } #[cfg(test)] diff --git a/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs b/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs index 5a9db67a5f..7b4d27100f 100644 --- a/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs +++ b/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use syntax::{ - ast::{self, edit::IndentLevel, Comment, CommentPlacement, Whitespace}, AstToken, Direction, SyntaxElement, TextRange, + ast::{self, Comment, CommentPlacement, Whitespace, edit::IndentLevel}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/convert_for_to_while_let.rs b/crates/ide-assists/src/handlers/convert_for_to_while_let.rs index 2d2751de99..03041f3551 100644 --- a/crates/ide-assists/src/handlers/convert_for_to_while_let.rs +++ b/crates/ide-assists/src/handlers/convert_for_to_while_let.rs @@ -1,12 +1,12 @@ use hir::{ - sym::{self}, Name, + sym::{self}, }; use ide_db::{famous_defs::FamousDefs, syntax_helpers::suggest_name}; use syntax::{ - ast::{self, edit::IndentLevel, make, syntax_factory::SyntaxFactory, HasLoopBody}, - syntax_editor::Position, AstNode, + ast::{self, HasLoopBody, edit::IndentLevel, make, syntax_factory::SyntaxFactory}, + syntax_editor::Position, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs b/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs index dd2e9cbcb5..07ad5a695b 100644 --- a/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs +++ b/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs @@ -1,7 +1,7 @@ use ide_db::{famous_defs::FamousDefs, traits::resolve_target_trait}; use itertools::Itertools; use syntax::{ - ast::{self, make, AstNode, HasGenericArgs, HasName}, + ast::{self, AstNode, HasGenericArgs, HasName, make}, ted, }; diff --git a/crates/ide-assists/src/handlers/convert_integer_literal.rs b/crates/ide-assists/src/handlers/convert_integer_literal.rs index fd3378e8c2..270eecd83b 100644 --- a/crates/ide-assists/src/handlers/convert_integer_literal.rs +++ b/crates/ide-assists/src/handlers/convert_integer_literal.rs @@ -1,4 +1,4 @@ -use syntax::{ast, ast::Radix, AstToken}; +use syntax::{AstToken, ast, ast::Radix}; use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; diff --git a/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs b/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs index 3c9a917410..713d215f12 100644 --- a/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs +++ b/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs @@ -1,9 +1,9 @@ -use hir::{sym, Name}; +use hir::{Name, sym}; use ide_db::famous_defs::FamousDefs; use stdx::format_to; use syntax::{ - ast::{self, edit_in_place::Indent, make, HasArgList, HasLoopBody}, AstNode, + ast::{self, HasArgList, HasLoopBody, edit_in_place::Indent, make}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/convert_let_else_to_match.rs b/crates/ide-assists/src/handlers/convert_let_else_to_match.rs index 79c34c14da..9f71031a1e 100644 --- a/crates/ide-assists/src/handlers/convert_let_else_to_match.rs +++ b/crates/ide-assists/src/handlers/convert_let_else_to_match.rs @@ -1,8 +1,8 @@ use hir::Semantics; use ide_db::RootDatabase; -use syntax::ast::RangeItem; -use syntax::ast::{edit::AstNodeEdit, AstNode, HasName, LetStmt, Name, Pat}; use syntax::T; +use syntax::ast::RangeItem; +use syntax::ast::{AstNode, HasName, LetStmt, Name, Pat, edit::AstNodeEdit}; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -162,11 +162,7 @@ fn binders_to_str(binders: &[(Name, bool)], addmut: bool) -> String { .iter() .map( |(ident, ismut)| { - if *ismut && addmut { - format!("mut {ident}") - } else { - ident.to_string() - } + if *ismut && addmut { format!("mut {ident}") } else { ident.to_string() } }, ) .collect::>() diff --git a/crates/ide-assists/src/handlers/convert_match_to_let_else.rs b/crates/ide-assists/src/handlers/convert_match_to_let_else.rs index fd159eb824..2db78f412d 100644 --- a/crates/ide-assists/src/handlers/convert_match_to_let_else.rs +++ b/crates/ide-assists/src/handlers/convert_match_to_let_else.rs @@ -1,12 +1,13 @@ use ide_db::defs::{Definition, NameRefClass}; use syntax::{ + AstNode, SyntaxNode, ast::{self, HasName, Name}, - ted, AstNode, SyntaxNode, + ted, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: convert_match_to_let_else diff --git a/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs b/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs index 8d4ff84084..7b8804e53f 100644 --- a/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs +++ b/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs @@ -2,11 +2,12 @@ use either::Either; use ide_db::{defs::Definition, search::FileReference}; use itertools::Itertools; use syntax::{ + SyntaxKind, ast::{self, AstNode, HasAttrs, HasGenericParams, HasVisibility}, - match_ast, ted, SyntaxKind, + match_ast, ted, }; -use crate::{assist_context::SourceChangeBuilder, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; // Assist: convert_named_struct_to_tuple_struct // diff --git a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs index b7a7764449..bd829d1e24 100644 --- a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs +++ b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs @@ -5,20 +5,21 @@ use ide_db::{ ty_filter::TryEnum, }; use syntax::{ + AstNode, + SyntaxKind::{FN, FOR_EXPR, LOOP_EXPR, WHILE_EXPR, WHITESPACE}, + T, ast::{ self, edit::{AstNodeEdit, IndentLevel}, make, }, - ted, AstNode, - SyntaxKind::{FN, FOR_EXPR, LOOP_EXPR, WHILE_EXPR, WHITESPACE}, - T, + ted, }; use crate::{ + AssistId, AssistKind, assist_context::{AssistContext, Assists}, utils::invert_boolean_expression_legacy, - AssistId, AssistKind, }; // Assist: convert_to_guarded_return diff --git a/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs b/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs index 91af9b05bb..0d79937885 100644 --- a/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs +++ b/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs @@ -1,18 +1,19 @@ use either::Either; use hir::ModuleDef; use ide_db::{ + FxHashSet, assists::{AssistId, AssistKind}, defs::Definition, helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope}, + imports::insert_use::{ImportScope, insert_use}, search::{FileReference, UsageSearchResult}, source_change::SourceChangeBuilder, syntax_helpers::node_ext::{for_each_tail_expr, walk_expr}, - FxHashSet, }; use syntax::{ - ast::{self, edit::IndentLevel, edit_in_place::Indent, make, HasName}, - match_ast, ted, AstNode, SyntaxNode, + AstNode, SyntaxNode, + ast::{self, HasName, edit::IndentLevel, edit_in_place::Indent, make}, + match_ast, ted, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs index f6e516db88..83e4737350 100644 --- a/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs +++ b/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs @@ -1,11 +1,12 @@ use either::Either; use ide_db::defs::{Definition, NameRefClass}; use syntax::{ + SyntaxKind, SyntaxNode, ast::{self, AstNode, HasAttrs, HasGenericParams, HasVisibility}, - match_ast, ted, SyntaxKind, SyntaxNode, + match_ast, ted, }; -use crate::{assist_context::SourceChangeBuilder, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; // Assist: convert_tuple_struct_to_named_struct // diff --git a/crates/ide-assists/src/handlers/convert_while_to_loop.rs b/crates/ide-assists/src/handlers/convert_while_to_loop.rs index beec64d13b..724de1969c 100644 --- a/crates/ide-assists/src/handlers/convert_while_to_loop.rs +++ b/crates/ide-assists/src/handlers/convert_while_to_loop.rs @@ -3,18 +3,18 @@ use std::iter; use either::Either; use ide_db::syntax_helpers::node_ext::is_pattern_cond; use syntax::{ - ast::{ - self, - edit::{AstNodeEdit, IndentLevel}, - make, HasLoopBody, - }, AstNode, T, + ast::{ + self, HasLoopBody, + edit::{AstNodeEdit, IndentLevel}, + make, + }, }; use crate::{ + AssistId, AssistKind, assist_context::{AssistContext, Assists}, utils::invert_boolean_expression_legacy, - AssistId, AssistKind, }; // Assist: convert_while_to_loop diff --git a/crates/ide-assists/src/handlers/destructure_struct_binding.rs b/crates/ide-assists/src/handlers/destructure_struct_binding.rs index e34e509048..a8a3a8c927 100644 --- a/crates/ide-assists/src/handlers/destructure_struct_binding.rs +++ b/crates/ide-assists/src/handlers/destructure_struct_binding.rs @@ -1,14 +1,14 @@ -use hir::{sym, HasVisibility}; +use hir::{HasVisibility, sym}; use ide_db::text_edit::TextRange; use ide_db::{ + FxHashMap, FxHashSet, assists::{AssistId, AssistKind}, defs::Definition, helpers::mod_path_to_ast, search::{FileReference, SearchScope}, - FxHashMap, FxHashSet, }; use itertools::Itertools; -use syntax::{ast, ted, AstNode, Edition, SmolStr, SyntaxNode, ToSmolStr}; +use syntax::{AstNode, Edition, SmolStr, SyntaxNode, ToSmolStr, ast, ted}; use crate::{ assist_context::{AssistContext, Assists, SourceChangeBuilder}, diff --git a/crates/ide-assists/src/handlers/destructure_tuple_binding.rs b/crates/ide-assists/src/handlers/destructure_tuple_binding.rs index 39142d6062..95eb88fa86 100644 --- a/crates/ide-assists/src/handlers/destructure_tuple_binding.rs +++ b/crates/ide-assists/src/handlers/destructure_tuple_binding.rs @@ -7,7 +7,7 @@ use ide_db::{ }; use itertools::Itertools; use syntax::{ - ast::{self, make, AstNode, FieldExpr, HasName, IdentPat}, + ast::{self, AstNode, FieldExpr, HasName, IdentPat, make}, ted, }; diff --git a/crates/ide-assists/src/handlers/desugar_doc_comment.rs b/crates/ide-assists/src/handlers/desugar_doc_comment.rs index d264928046..9d0797d32a 100644 --- a/crates/ide-assists/src/handlers/desugar_doc_comment.rs +++ b/crates/ide-assists/src/handlers/desugar_doc_comment.rs @@ -1,14 +1,14 @@ use either::Either; use itertools::Itertools; use syntax::{ - ast::{self, edit::IndentLevel, CommentPlacement, Whitespace}, AstToken, TextRange, + ast::{self, CommentPlacement, Whitespace, edit::IndentLevel}, }; use crate::{ + AssistContext, AssistId, AssistKind, Assists, handlers::convert_comment_block::{line_comment_text, relevant_line_comments}, utils::required_hashes, - AssistContext, AssistId, AssistKind, Assists, }; // Assist: desugar_doc_comment diff --git a/crates/ide-assists/src/handlers/expand_glob_import.rs b/crates/ide-assists/src/handlers/expand_glob_import.rs index 0b95d6177f..fae5530f99 100644 --- a/crates/ide-assists/src/handlers/expand_glob_import.rs +++ b/crates/ide-assists/src/handlers/expand_glob_import.rs @@ -7,13 +7,14 @@ use ide_db::{ }; use stdx::never; use syntax::{ - ast::{self, make, Use, UseTree, VisibilityKind}, - ted, AstNode, Direction, SyntaxNode, SyntaxToken, T, + AstNode, Direction, SyntaxNode, SyntaxToken, T, + ast::{self, Use, UseTree, VisibilityKind, make}, + ted, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: expand_glob_import diff --git a/crates/ide-assists/src/handlers/expand_rest_pattern.rs b/crates/ide-assists/src/handlers/expand_rest_pattern.rs index c79a982c38..e437e7eb75 100644 --- a/crates/ide-assists/src/handlers/expand_rest_pattern.rs +++ b/crates/ide-assists/src/handlers/expand_rest_pattern.rs @@ -1,8 +1,9 @@ use hir::{PathResolution, StructKind}; use ide_db::syntax_helpers::suggest_name::NameGenerator; use syntax::{ + AstNode, ToSmolStr, ast::{self, make}, - match_ast, AstNode, ToSmolStr, + match_ast, }; use crate::{AssistContext, AssistId, Assists}; diff --git a/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs b/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs index e4d347ef16..c9eb7c5237 100644 --- a/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs +++ b/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs @@ -1,14 +1,15 @@ -use crate::{utils, AssistContext, Assists}; +use crate::{AssistContext, Assists, utils}; use ide_db::{ assists::{AssistId, AssistKind}, - syntax_helpers::format_string_exprs::{parse_format_exprs, Arg}, + syntax_helpers::format_string_exprs::{Arg, parse_format_exprs}, }; use itertools::Itertools; use syntax::{ - ast::{self, make}, - ted, AstNode, AstToken, NodeOrToken, + AstNode, AstToken, NodeOrToken, SyntaxKind::WHITESPACE, T, + ast::{self, make}, + ted, }; // Assist: extract_expressions_from_format_string @@ -61,21 +62,28 @@ pub(crate) fn extract_expressions_from_format_string( // Extract existing arguments in macro let tokens = tt.token_trees_and_tokens().collect_vec(); - let existing_args = if let [_opening_bracket, NodeOrToken::Token(_format_string), _args_start_comma, tokens @ .., NodeOrToken::Token(_end_bracket)] = - tokens.as_slice() + let existing_args = if let [ + _opening_bracket, + NodeOrToken::Token(_format_string), + _args_start_comma, + tokens @ .., + NodeOrToken::Token(_end_bracket), + ] = tokens.as_slice() { - let args = tokens.split(|it| matches!(it, NodeOrToken::Token(t) if t.kind() == T![,])).map(|arg| { - // Strip off leading and trailing whitespace tokens - let arg = match arg.split_first() { - Some((NodeOrToken::Token(t), rest)) if t.kind() == WHITESPACE => rest, - _ => arg, - }; - let arg = match arg.split_last() { - Some((NodeOrToken::Token(t), rest)) if t.kind() == WHITESPACE => rest, - _ => arg, - }; - arg - }); + let args = tokens + .split(|it| matches!(it, NodeOrToken::Token(t) if t.kind() == T![,])) + .map(|arg| { + // Strip off leading and trailing whitespace tokens + let arg = match arg.split_first() { + Some((NodeOrToken::Token(t), rest)) if t.kind() == WHITESPACE => rest, + _ => arg, + }; + let arg = match arg.split_last() { + Some((NodeOrToken::Token(t), rest)) if t.kind() == WHITESPACE => rest, + _ => arg, + }; + arg + }); args.collect() } else { @@ -100,7 +108,8 @@ pub(crate) fn extract_expressions_from_format_string( Arg::Expr(s) => { // insert arg // FIXME: use the crate's edition for parsing - let expr = ast::Expr::parse(&s, syntax::Edition::CURRENT_FIXME).syntax_node(); + let expr = + ast::Expr::parse(&s, syntax::Edition::CURRENT_FIXME).syntax_node(); let mut expr_tt = utils::tt_from_syntax(expr); new_tt_bits.append(&mut expr_tt); } @@ -120,7 +129,6 @@ pub(crate) fn extract_expressions_from_format_string( } } - // Insert new args let new_tt = make::token_tree(tt_delimiter, new_tt_bits).clone_for_update(); ted::replace(tt.syntax(), new_tt.syntax()); diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs index 330587e0db..6b535a2897 100644 --- a/crates/ide-assists/src/handlers/extract_function.rs +++ b/crates/ide-assists/src/handlers/extract_function.rs @@ -7,33 +7,34 @@ use hir::{ TypeInfo, TypeParam, }; use ide_db::{ + FxIndexSet, RootDatabase, assists::GroupLabel, defs::{Definition, NameRefClass}, famous_defs::FamousDefs, helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope}, + imports::insert_use::{ImportScope, insert_use}, search::{FileReference, ReferenceCategory, SearchScope}, source_change::SourceChangeBuilder, syntax_helpers::node_ext::{ for_each_tail_expr, preorder_expr, walk_expr, walk_pat, walk_patterns_in_expr, }, - FxIndexSet, RootDatabase, }; use itertools::Itertools; use syntax::{ - ast::{ - self, edit::IndentLevel, edit_in_place::Indent, AstNode, AstToken, HasGenericParams, - HasName, - }, - match_ast, ted, Edition, SyntaxElement, + Edition, SyntaxElement, SyntaxKind::{self, COMMENT}, - SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, WalkEvent, T, + SyntaxNode, SyntaxToken, T, TextRange, TextSize, TokenAtOffset, WalkEvent, + ast::{ + self, AstNode, AstToken, HasGenericParams, HasName, edit::IndentLevel, + edit_in_place::Indent, + }, + match_ast, ted, }; use crate::{ + AssistId, assist_context::{AssistContext, Assists, TreeMutator}, utils::generate_impl, - AssistId, }; // Assist: extract_function @@ -1689,11 +1690,7 @@ fn make_where_clause( }) .peekable(); - if predicates.peek().is_some() { - Some(make::where_clause(predicates)) - } else { - None - } + if predicates.peek().is_some() { Some(make::where_clause(predicates)) } else { None } } fn pred_is_required( diff --git a/crates/ide-assists/src/handlers/extract_module.rs b/crates/ide-assists/src/handlers/extract_module.rs index b94422b13c..8a7bb5a1f0 100644 --- a/crates/ide-assists/src/handlers/extract_module.rs +++ b/crates/ide-assists/src/handlers/extract_module.rs @@ -4,23 +4,24 @@ use either::Either; use hir::{HasSource, HirFileIdExt, ModuleSource}; use ide_db::base_db::salsa::AsDynDatabase; use ide_db::{ + FileId, FxHashMap, FxHashSet, assists::{AssistId, AssistKind}, defs::{Definition, NameClass, NameRefClass}, search::{FileReference, SearchScope}, - FileId, FxHashMap, FxHashSet, }; use itertools::Itertools; use smallvec::SmallVec; use syntax::{ - algo::find_node_at_range, - ast::{ - self, - edit::{AstNodeEdit, IndentLevel}, - make, HasVisibility, - }, - match_ast, ted, AstNode, + AstNode, SyntaxKind::{self, WHITESPACE}, SyntaxNode, TextRange, TextSize, + algo::find_node_at_range, + ast::{ + self, HasVisibility, + edit::{AstNodeEdit, IndentLevel}, + make, + }, + match_ast, ted, }; use crate::{AssistContext, Assists}; @@ -1167,8 +1168,8 @@ mod modname { } #[test] - fn test_extract_module_for_impl_not_having_corresponding_adt_in_selection_and_not_in_same_mod_but_with_super( - ) { + fn test_extract_module_for_impl_not_having_corresponding_adt_in_selection_and_not_in_same_mod_but_with_super() + { check_assist( extract_module, r" diff --git a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs index d4f2ea3bd9..7fba75f9e5 100644 --- a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs @@ -3,25 +3,26 @@ use std::iter; use either::Either; use hir::{HasCrate, Module, ModuleDef, Name, Variant}; use ide_db::{ + FxHashSet, RootDatabase, defs::Definition, helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope, InsertUseConfig}, + imports::insert_use::{ImportScope, InsertUseConfig, insert_use}, path_transform::PathTransform, search::FileReference, - FxHashSet, RootDatabase, }; use itertools::Itertools; use syntax::{ - ast::{ - self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, HasAttrs, HasGenericParams, - HasName, HasVisibility, - }, - match_ast, ted, Edition, SyntaxElement, + Edition, SyntaxElement, SyntaxKind::*, SyntaxNode, T, + ast::{ + self, AstNode, HasAttrs, HasGenericParams, HasName, HasVisibility, edit::IndentLevel, + edit_in_place::Indent, make, + }, + match_ast, ted, }; -use crate::{assist_context::SourceChangeBuilder, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; // Assist: extract_struct_from_enum_variant // diff --git a/crates/ide-assists/src/handlers/extract_type_alias.rs b/crates/ide-assists/src/handlers/extract_type_alias.rs index 67b8f5e505..e6fb4d40d4 100644 --- a/crates/ide-assists/src/handlers/extract_type_alias.rs +++ b/crates/ide-assists/src/handlers/extract_type_alias.rs @@ -1,7 +1,7 @@ use either::Either; use ide_db::syntax_helpers::node_ext::walk_ty; use syntax::{ - ast::{self, edit::IndentLevel, make, AstNode, HasGenericArgs, HasGenericParams, HasName}, + ast::{self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel, make}, syntax_editor, }; diff --git a/crates/ide-assists/src/handlers/extract_variable.rs b/crates/ide-assists/src/handlers/extract_variable.rs index 7b6f76d004..2e58e62ab0 100644 --- a/crates/ide-assists/src/handlers/extract_variable.rs +++ b/crates/ide-assists/src/handlers/extract_variable.rs @@ -1,19 +1,19 @@ use hir::{HirDisplay, TypeInfo}; use ide_db::{ assists::GroupLabel, - syntax_helpers::{suggest_name, LexedStr}, + syntax_helpers::{LexedStr, suggest_name}, }; use syntax::{ + NodeOrToken, SyntaxKind, SyntaxNode, T, algo::ancestors_at_offset, ast::{ - self, edit::IndentLevel, edit_in_place::Indent, make, syntax_factory::SyntaxFactory, - AstNode, + self, AstNode, edit::IndentLevel, edit_in_place::Indent, make, + syntax_factory::SyntaxFactory, }, syntax_editor::Position, - NodeOrToken, SyntaxKind, SyntaxNode, T, }; -use crate::{utils::is_body_const, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils::is_body_const}; // Assist: extract_variable // diff --git a/crates/ide-assists/src/handlers/fix_visibility.rs b/crates/ide-assists/src/handlers/fix_visibility.rs index 47e4a68293..51dbce2973 100644 --- a/crates/ide-assists/src/handlers/fix_visibility.rs +++ b/crates/ide-assists/src/handlers/fix_visibility.rs @@ -1,10 +1,10 @@ use hir::{ - db::HirDatabase, HasSource, HasVisibility, HirFileIdExt, ModuleDef, PathResolution, ScopeDef, + HasSource, HasVisibility, HirFileIdExt, ModuleDef, PathResolution, ScopeDef, db::HirDatabase, }; use ide_db::FileId; use syntax::{ - ast::{self, edit_in_place::HasVisibilityEdit, make, HasVisibility as _}, AstNode, TextRange, + ast::{self, HasVisibility as _, edit_in_place::HasVisibilityEdit, make}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/flip_binexpr.rs b/crates/ide-assists/src/handlers/flip_binexpr.rs index 818a868fe3..75133c3a02 100644 --- a/crates/ide-assists/src/handlers/flip_binexpr.rs +++ b/crates/ide-assists/src/handlers/flip_binexpr.rs @@ -1,6 +1,6 @@ use syntax::{ - ast::{self, syntax_factory::SyntaxFactory, AstNode, BinExpr}, SyntaxKind, T, + ast::{self, AstNode, BinExpr, syntax_factory::SyntaxFactory}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/flip_comma.rs b/crates/ide-assists/src/handlers/flip_comma.rs index dd27269b00..6900e94bdd 100644 --- a/crates/ide-assists/src/handlers/flip_comma.rs +++ b/crates/ide-assists/src/handlers/flip_comma.rs @@ -1,8 +1,8 @@ use syntax::{ + AstNode, Direction, NodeOrToken, SyntaxKind, SyntaxToken, T, algo::non_trivia_sibling, ast::{self, syntax_factory::SyntaxFactory}, syntax_editor::SyntaxMapping, - AstNode, Direction, NodeOrToken, SyntaxKind, SyntaxToken, T, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/flip_or_pattern.rs b/crates/ide-assists/src/handlers/flip_or_pattern.rs index d9fa03e719..6ef8aa6a73 100644 --- a/crates/ide-assists/src/handlers/flip_or_pattern.rs +++ b/crates/ide-assists/src/handlers/flip_or_pattern.rs @@ -1,7 +1,7 @@ use syntax::{ + Direction, T, algo::non_trivia_sibling, ast::{self, AstNode}, - Direction, T, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/flip_trait_bound.rs b/crates/ide-assists/src/handlers/flip_trait_bound.rs index 3528f5e813..af40b09643 100644 --- a/crates/ide-assists/src/handlers/flip_trait_bound.rs +++ b/crates/ide-assists/src/handlers/flip_trait_bound.rs @@ -1,7 +1,7 @@ use syntax::{ + Direction, T, algo::non_trivia_sibling, ast::{self, AstNode}, - Direction, T, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/generate_constant.rs b/crates/ide-assists/src/handlers/generate_constant.rs index 7f7db07152..2f4b6a0421 100644 --- a/crates/ide-assists/src/handlers/generate_constant.rs +++ b/crates/ide-assists/src/handlers/generate_constant.rs @@ -1,14 +1,14 @@ use crate::assist_context::{AssistContext, Assists}; use hir::{HasVisibility, HirDisplay, HirFileIdExt, Module}; use ide_db::{ + FileId, assists::{AssistId, AssistKind}, base_db::Upcast, defs::{Definition, NameRefClass}, - FileId, }; use syntax::{ - ast::{self, edit::IndentLevel, NameRef}, AstNode, Direction, SyntaxKind, TextSize, + ast::{self, NameRef, edit::IndentLevel}, }; // Assist: generate_constant diff --git a/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs b/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs index a6e3d49e0d..c6725a013e 100644 --- a/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs +++ b/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs @@ -1,4 +1,4 @@ -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use syntax::ast::{self, AstNode, HasName}; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -77,11 +77,7 @@ fn existing_default_impl( let default_trait = FamousDefs(sema, krate).core_default_Default()?; let enum_type = enum_.ty(sema.db); - if enum_type.impls_trait(sema.db, default_trait, &[]) { - Some(()) - } else { - None - } + if enum_type.impls_trait(sema.db, default_trait, &[]) { Some(()) } else { None } } #[cfg(test)] diff --git a/crates/ide-assists/src/handlers/generate_default_from_new.rs b/crates/ide-assists/src/handlers/generate_default_from_new.rs index dc27af5cbe..1a4349cfea 100644 --- a/crates/ide-assists/src/handlers/generate_default_from_new.rs +++ b/crates/ide-assists/src/handlers/generate_default_from_new.rs @@ -1,13 +1,13 @@ use ide_db::famous_defs::FamousDefs; use stdx::format_to; use syntax::{ - ast::{self, make, HasGenericParams, HasName, Impl}, AstNode, + ast::{self, HasGenericParams, HasName, Impl, make}, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, + assist_context::{AssistContext, Assists}, }; // Assist: generate_default_from_new diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs index 220259451e..750f160ec2 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs @@ -1,15 +1,15 @@ use hir::{HasCrate, HasVisibility}; -use ide_db::{path_transform::PathTransform, FxHashSet}; +use ide_db::{FxHashSet, path_transform::PathTransform}; use syntax::{ ast::{ - self, edit_in_place::Indent, make, AstNode, HasGenericParams, HasName, HasVisibility as _, + self, AstNode, HasGenericParams, HasName, HasVisibility as _, edit_in_place::Indent, make, }, ted, }; use crate::{ - utils::{convert_param_list_to_arg_list, find_struct_impl}, AssistContext, AssistId, AssistKind, Assists, GroupLabel, + utils::{convert_param_list_to_arg_list, find_struct_impl}, }; // Assist: generate_delegate_methods diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 55b860d0ff..5c39214617 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -5,25 +5,25 @@ use crate::{ utils::convert_param_list_to_arg_list, }; use either::Either; -use hir::{db::HirDatabase, HasVisibility}; +use hir::{HasVisibility, db::HirDatabase}; use ide_db::{ + FxHashMap, FxHashSet, assists::{AssistId, GroupLabel}, path_transform::PathTransform, syntax_helpers::suggest_name, - FxHashMap, FxHashSet, }; use itertools::Itertools; use syntax::{ + AstNode, Edition, NodeOrToken, SmolStr, SyntaxKind, ToSmolStr, ast::{ - self, - edit::{self, AstNodeEdit}, - edit_in_place::AttrsOwnerEdit, - make, AssocItem, GenericArgList, GenericParamList, HasAttrs, HasGenericArgs, + self, AssocItem, GenericArgList, GenericParamList, HasAttrs, HasGenericArgs, HasGenericParams, HasName, HasTypeBounds, HasVisibility as astHasVisibility, Path, WherePred, + edit::{self, AstNodeEdit}, + edit_in_place::AttrsOwnerEdit, + make, }, ted::{self, Position}, - AstNode, Edition, NodeOrToken, SmolStr, SyntaxKind, ToSmolStr, }; // Assist: generate_delegate_trait diff --git a/crates/ide-assists/src/handlers/generate_deref.rs b/crates/ide-assists/src/handlers/generate_deref.rs index e558bb6da8..7bf2997812 100644 --- a/crates/ide-assists/src/handlers/generate_deref.rs +++ b/crates/ide-assists/src/handlers/generate_deref.rs @@ -1,16 +1,16 @@ use std::fmt::Display; use hir::{ModPath, ModuleDef}; -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use syntax::{ - ast::{self, HasName}, AstNode, Edition, SyntaxNode, + ast::{self, HasName}, }; use crate::{ + AssistId, AssistKind, assist_context::{AssistContext, Assists, SourceChangeBuilder}, utils::generate_trait_impl_text, - AssistId, AssistKind, }; // Assist: generate_deref diff --git a/crates/ide-assists/src/handlers/generate_derive.rs b/crates/ide-assists/src/handlers/generate_derive.rs index 53ba144ba9..8b4dbeff7c 100644 --- a/crates/ide-assists/src/handlers/generate_derive.rs +++ b/crates/ide-assists/src/handlers/generate_derive.rs @@ -1,6 +1,6 @@ use syntax::{ - ast::{self, edit_in_place::AttrsOwnerEdit, make, AstNode, HasAttrs}, T, + ast::{self, AstNode, HasAttrs, edit_in_place::AttrsOwnerEdit, make}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/generate_documentation_template.rs b/crates/ide-assists/src/handlers/generate_documentation_template.rs index 862be791d1..df05c0d6b2 100644 --- a/crates/ide-assists/src/handlers/generate_documentation_template.rs +++ b/crates/ide-assists/src/handlers/generate_documentation_template.rs @@ -3,9 +3,10 @@ use ide_db::assists::{AssistId, AssistKind}; use itertools::Itertools; use stdx::{format_to, to_lower_snake_case}; use syntax::{ + AstNode, AstToken, Edition, algo::skip_whitespace_token, - ast::{self, edit::IndentLevel, HasDocComments, HasGenericArgs, HasName}, - match_ast, AstNode, AstToken, Edition, + ast::{self, HasDocComments, HasGenericArgs, HasName, edit::IndentLevel}, + match_ast, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/generate_enum_is_method.rs b/crates/ide-assists/src/handlers/generate_enum_is_method.rs index b5d3ed4369..78fdca910c 100644 --- a/crates/ide-assists/src/handlers/generate_enum_is_method.rs +++ b/crates/ide-assists/src/handlers/generate_enum_is_method.rs @@ -4,8 +4,8 @@ use syntax::ast::HasVisibility; use syntax::ast::{self, AstNode, HasName}; use crate::{ - utils::{add_method_to_adt, find_struct_impl}, AssistContext, AssistId, AssistKind, Assists, + utils::{add_method_to_adt, find_struct_impl}, }; // Assist: generate_enum_is_method diff --git a/crates/ide-assists/src/handlers/generate_enum_projection_method.rs b/crates/ide-assists/src/handlers/generate_enum_projection_method.rs index ee643ce9a4..e96be673a1 100644 --- a/crates/ide-assists/src/handlers/generate_enum_projection_method.rs +++ b/crates/ide-assists/src/handlers/generate_enum_projection_method.rs @@ -5,8 +5,8 @@ use syntax::ast::HasVisibility; use syntax::ast::{self, AstNode, HasName}; use crate::{ - utils::{add_method_to_adt, find_struct_impl}, AssistContext, AssistId, AssistKind, Assists, + utils::{add_method_to_adt, find_struct_impl}, }; // Assist: generate_enum_try_into_method diff --git a/crates/ide-assists/src/handlers/generate_enum_variant.rs b/crates/ide-assists/src/handlers/generate_enum_variant.rs index bb08cb904e..51b6a4be01 100644 --- a/crates/ide-assists/src/handlers/generate_enum_variant.rs +++ b/crates/ide-assists/src/handlers/generate_enum_variant.rs @@ -1,8 +1,9 @@ use hir::{HasSource, HirDisplay, InRealFile}; use ide_db::assists::{AssistId, AssistKind}; use syntax::{ - ast::{self, syntax_factory::SyntaxFactory, HasArgList}, - match_ast, AstNode, SyntaxNode, + AstNode, SyntaxNode, + ast::{self, HasArgList, syntax_factory::SyntaxFactory}, + match_ast, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/generate_fn_type_alias.rs b/crates/ide-assists/src/handlers/generate_fn_type_alias.rs index 9d01ec00f8..bc890ac53b 100644 --- a/crates/ide-assists/src/handlers/generate_fn_type_alias.rs +++ b/crates/ide-assists/src/handlers/generate_fn_type_alias.rs @@ -1,8 +1,9 @@ use either::Either; use ide_db::assists::{AssistId, AssistKind, GroupLabel}; use syntax::{ - ast::{self, edit::IndentLevel, make, HasGenericParams, HasName}, - syntax_editor, AstNode, + AstNode, + ast::{self, HasGenericParams, HasName, edit::IndentLevel, make}, + syntax_editor, }; use crate::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs index 6091f06b96..88226820cf 100644 --- a/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs @@ -1,8 +1,8 @@ -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use syntax::ast::{self, AstNode, HasName}; use crate::{ - utils::generate_trait_impl_text_intransitive, AssistContext, AssistId, AssistKind, Assists, + AssistContext, AssistId, AssistKind, Assists, utils::generate_trait_impl_text_intransitive, }; // Assist: generate_from_impl_for_enum @@ -92,11 +92,7 @@ fn existing_from_impl( let wrapped_type = variant.fields(sema.db).first()?.ty(sema.db); - if enum_type.impls_trait(sema.db, from_trait, &[wrapped_type]) { - Some(()) - } else { - None - } + if enum_type.impls_trait(sema.db, from_trait, &[wrapped_type]) { Some(()) } else { None } } #[cfg(test)] diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs index 29bd8cf0d1..a74d477ec8 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -4,26 +4,27 @@ use hir::{ }; use ide_db::base_db::salsa::AsDynDatabase; use ide_db::{ + FileId, FxHashMap, FxHashSet, RootDatabase, SnippetCap, defs::{Definition, NameRefClass}, famous_defs::FamousDefs, helpers::is_editable_crate, path_transform::PathTransform, source_change::SourceChangeBuilder, - FileId, FxHashMap, FxHashSet, RootDatabase, SnippetCap, }; use itertools::Itertools; use stdx::to_lower_snake_case; use syntax::{ + Edition, SyntaxKind, SyntaxNode, T, TextRange, ast::{ - self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, BlockExpr, CallExpr, - HasArgList, HasGenericParams, HasModuleItem, HasTypeBounds, + self, AstNode, BlockExpr, CallExpr, HasArgList, HasGenericParams, HasModuleItem, + HasTypeBounds, edit::IndentLevel, edit_in_place::Indent, make, }, - ted, Edition, SyntaxKind, SyntaxNode, TextRange, T, + ted, }; use crate::{ - utils::{convert_reference_type, find_struct_impl}, AssistContext, AssistId, AssistKind, Assists, + utils::{convert_reference_type, find_struct_impl}, }; // Assist: generate_function @@ -179,9 +180,8 @@ fn add_func_to_accumulator( let edition = function_builder.target_edition; let func = function_builder.render(ctx.config.snippet_cap, edit); - if let Some(adt) = - adt_info - .and_then(|adt_info| if adt_info.impl_exists { None } else { Some(adt_info.adt) }) + if let Some(adt) = adt_info + .and_then(|adt_info| if adt_info.impl_exists { None } else { Some(adt_info.adt) }) { let name = make::ty_path(make::ext::ident_path(&format!( "{}", diff --git a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs index 1b16ba5fc8..8183a11e1b 100644 --- a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs +++ b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs @@ -1,13 +1,14 @@ use ide_db::{famous_defs::FamousDefs, source_change::SourceChangeBuilder}; use stdx::{format_to, to_lower_snake_case}; use syntax::{ - ast::{self, edit_in_place::Indent, make, AstNode, HasName, HasVisibility}, - ted, TextRange, + TextRange, + ast::{self, AstNode, HasName, HasVisibility, edit_in_place::Indent, make}, + ted, }; use crate::{ - utils::{convert_reference_type, find_struct_impl, generate_impl}, AssistContext, AssistId, AssistKind, Assists, GroupLabel, + utils::{convert_reference_type, find_struct_impl, generate_impl}, }; // Assist: generate_setter diff --git a/crates/ide-assists/src/handlers/generate_impl.rs b/crates/ide-assists/src/handlers/generate_impl.rs index 4439830947..ff4f388e39 100644 --- a/crates/ide-assists/src/handlers/generate_impl.rs +++ b/crates/ide-assists/src/handlers/generate_impl.rs @@ -1,9 +1,9 @@ use syntax::{ - ast::{self, edit_in_place::Indent, make, AstNode, HasName}, + ast::{self, AstNode, HasName, edit_in_place::Indent, make}, ted, }; -use crate::{utils, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils}; fn insert_impl(impl_: ast::Impl, nominal: &ast::Adt) { let indent = nominal.indent_level(); diff --git a/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs b/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs index ad422b25c3..d9ed8111c6 100644 --- a/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs +++ b/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs @@ -1,12 +1,12 @@ -use hir::{sym, HasSource, Name}; +use hir::{HasSource, Name, sym}; use syntax::{ - ast::{self, HasName}, AstNode, + ast::{self, HasName}, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: generate_is_empty_from_len diff --git a/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs b/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs index 6aa561ad7f..8d107e4128 100644 --- a/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs +++ b/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs @@ -1,7 +1,8 @@ use ide_db::famous_defs::FamousDefs; use syntax::{ + AstNode, ast::{self, make}, - ted, AstNode, + ted, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/generate_new.rs b/crates/ide-assists/src/handlers/generate_new.rs index 70d14d6b95..f14a4c1070 100644 --- a/crates/ide-assists/src/handlers/generate_new.rs +++ b/crates/ide-assists/src/handlers/generate_new.rs @@ -2,13 +2,13 @@ use ide_db::{ imports::import_assets::item_for_path_search, use_trivial_constructor::use_trivial_constructor, }; use syntax::{ - ast::{self, edit_in_place::Indent, make, AstNode, HasName, HasVisibility, StructKind}, + ast::{self, AstNode, HasName, HasVisibility, StructKind, edit_in_place::Indent, make}, ted, }; use crate::{ - utils::{find_struct_impl, generate_impl}, AssistContext, AssistId, AssistKind, Assists, + utils::{find_struct_impl, generate_impl}, }; // Assist: generate_new diff --git a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs index 5f7350bc28..3470a4d660 100644 --- a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs +++ b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs @@ -1,13 +1,13 @@ use crate::assist_context::{AssistContext, Assists}; use ide_db::assists::AssistId; use syntax::{ + AstNode, SyntaxKind, T, ast::{ - self, + self, HasGenericParams, HasName, edit_in_place::{HasVisibilityEdit, Indent}, - make, HasGenericParams, HasName, + make, }, ted::{self, Position}, - AstNode, SyntaxKind, T, }; // NOTES : diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index 5a791c58bf..b8381a8cce 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -3,10 +3,12 @@ use std::collections::BTreeSet; use ast::make; use either::Either; use hir::{ + FileRange, PathResolution, Semantics, TypeInfo, db::{ExpandDatabase, HirDatabase}, - sym, FileRange, PathResolution, Semantics, TypeInfo, + sym, }; use ide_db::{ + EditionedFileId, RootDatabase, base_db::Crate, defs::Definition, imports::insert_use::remove_path_if_in_use_stmt, @@ -14,19 +16,19 @@ use ide_db::{ search::{FileReference, FileReferenceNode, SearchScope}, source_change::SourceChangeBuilder, syntax_helpers::{node_ext::expr_as_name_ref, prettify_macro_expansion}, - EditionedFileId, RootDatabase, }; -use itertools::{izip, Itertools}; +use itertools::{Itertools, izip}; use syntax::{ + AstNode, NodeOrToken, SyntaxKind, ast::{ - self, edit::IndentLevel, edit_in_place::Indent, HasArgList, HasGenericArgs, Pat, PathExpr, + self, HasArgList, HasGenericArgs, Pat, PathExpr, edit::IndentLevel, edit_in_place::Indent, }, - ted, AstNode, NodeOrToken, SyntaxKind, + ted, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: inline_into_callers diff --git a/crates/ide-assists/src/handlers/inline_const_as_literal.rs b/crates/ide-assists/src/handlers/inline_const_as_literal.rs index ca5882d031..10f9652cfe 100644 --- a/crates/ide-assists/src/handlers/inline_const_as_literal.rs +++ b/crates/ide-assists/src/handlers/inline_const_as_literal.rs @@ -1,5 +1,5 @@ use hir::HasCrate; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/inline_local_variable.rs b/crates/ide-assists/src/handlers/inline_local_variable.rs index 36eed290dc..8b7aa8f4af 100644 --- a/crates/ide-assists/src/handlers/inline_local_variable.rs +++ b/crates/ide-assists/src/handlers/inline_local_variable.rs @@ -1,17 +1,17 @@ use hir::{PathResolution, Semantics}; use ide_db::{ + EditionedFileId, RootDatabase, defs::Definition, search::{FileReference, FileReferenceNode, UsageSearchResult}, - EditionedFileId, RootDatabase, }; use syntax::{ - ast::{self, syntax_factory::SyntaxFactory, AstNode, AstToken, HasName}, SyntaxElement, TextRange, + ast::{self, AstNode, AstToken, HasName, syntax_factory::SyntaxFactory}, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: inline_local_variable diff --git a/crates/ide-assists/src/handlers/inline_type_alias.rs b/crates/ide-assists/src/handlers/inline_type_alias.rs index 76d465b011..936b09d5a4 100644 --- a/crates/ide-assists/src/handlers/inline_type_alias.rs +++ b/crates/ide-assists/src/handlers/inline_type_alias.rs @@ -10,13 +10,14 @@ use ide_db::{ }; use itertools::Itertools; use syntax::{ - ast::{self, make, HasGenericParams, HasName}, - ted, AstNode, NodeOrToken, SyntaxNode, + AstNode, NodeOrToken, SyntaxNode, + ast::{self, HasGenericParams, HasName, make}, + ted, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; use super::inline_call::split_refs_and_uses; diff --git a/crates/ide-assists/src/handlers/into_to_qualified_from.rs b/crates/ide-assists/src/handlers/into_to_qualified_from.rs index e405af5533..c8ec3da180 100644 --- a/crates/ide-assists/src/handlers/into_to_qualified_from.rs +++ b/crates/ide-assists/src/handlers/into_to_qualified_from.rs @@ -3,7 +3,7 @@ use ide_db::{ assists::{AssistId, AssistKind}, famous_defs::FamousDefs, }; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/introduce_named_lifetime.rs b/crates/ide-assists/src/handlers/introduce_named_lifetime.rs index 62909c586e..587e76585f 100644 --- a/crates/ide-assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ide-assists/src/handlers/introduce_named_lifetime.rs @@ -1,11 +1,11 @@ use ide_db::FxHashSet; use syntax::{ - ast::{self, edit_in_place::GenericParamsOwnerEdit, make, HasGenericParams}, - ted::{self, Position}, AstNode, TextRange, + ast::{self, HasGenericParams, edit_in_place::GenericParamsOwnerEdit, make}, + ted::{self, Position}, }; -use crate::{assist_context::SourceChangeBuilder, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder}; static ASSIST_NAME: &str = "introduce_named_lifetime"; static ASSIST_LABEL: &str = "Introduce named lifetime"; diff --git a/crates/ide-assists/src/handlers/introduce_named_type_parameter.rs b/crates/ide-assists/src/handlers/introduce_named_type_parameter.rs index 994e4a0edd..d60106cc80 100644 --- a/crates/ide-assists/src/handlers/introduce_named_type_parameter.rs +++ b/crates/ide-assists/src/handlers/introduce_named_type_parameter.rs @@ -1,6 +1,6 @@ use ide_db::syntax_helpers::suggest_name; use itertools::Itertools; -use syntax::ast::{self, syntax_factory::SyntaxFactory, AstNode, HasGenericParams, HasName}; +use syntax::ast::{self, AstNode, HasGenericParams, HasName, syntax_factory::SyntaxFactory}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/invert_if.rs b/crates/ide-assists/src/handlers/invert_if.rs index ac710503d8..4273a85df5 100644 --- a/crates/ide-assists/src/handlers/invert_if.rs +++ b/crates/ide-assists/src/handlers/invert_if.rs @@ -1,13 +1,13 @@ use ide_db::syntax_helpers::node_ext::is_pattern_cond; use syntax::{ - ast::{self, AstNode}, T, + ast::{self, AstNode}, }; use crate::{ + AssistId, AssistKind, assist_context::{AssistContext, Assists}, utils::invert_boolean_expression_legacy, - AssistId, AssistKind, }; // Assist: invert_if diff --git a/crates/ide-assists/src/handlers/merge_imports.rs b/crates/ide-assists/src/handlers/merge_imports.rs index 4171230836..aae007577c 100644 --- a/crates/ide-assists/src/handlers/merge_imports.rs +++ b/crates/ide-assists/src/handlers/merge_imports.rs @@ -1,19 +1,20 @@ use either::Either; use ide_db::imports::{ insert_use::{ImportGranularity, InsertUseConfig}, - merge_imports::{try_merge_imports, try_merge_trees, try_normalize_use_tree, MergeBehavior}, + merge_imports::{MergeBehavior, try_merge_imports, try_merge_trees, try_normalize_use_tree}, }; use itertools::Itertools; use syntax::{ + AstNode, SyntaxElement, SyntaxNode, algo::neighbor, ast::{self, edit_in_place::Removable}, - match_ast, ted, AstNode, SyntaxElement, SyntaxNode, + match_ast, ted, }; use crate::{ + AssistId, AssistKind, assist_context::{AssistContext, Assists}, utils::next_prev, - AssistId, AssistKind, }; use Edit::*; diff --git a/crates/ide-assists/src/handlers/merge_match_arms.rs b/crates/ide-assists/src/handlers/merge_match_arms.rs index f83de931ea..be73377070 100644 --- a/crates/ide-assists/src/handlers/merge_match_arms.rs +++ b/crates/ide-assists/src/handlers/merge_match_arms.rs @@ -2,9 +2,9 @@ use hir::Type; use ide_db::FxHashMap; use std::iter::successors; use syntax::{ + Direction, algo::neighbor, ast::{self, AstNode, HasName}, - Direction, }; use crate::{AssistContext, AssistId, AssistKind, Assists, TextRange}; diff --git a/crates/ide-assists/src/handlers/merge_nested_if.rs b/crates/ide-assists/src/handlers/merge_nested_if.rs index 7a0037fa20..89bd62a084 100644 --- a/crates/ide-assists/src/handlers/merge_nested_if.rs +++ b/crates/ide-assists/src/handlers/merge_nested_if.rs @@ -1,12 +1,12 @@ use ide_db::syntax_helpers::node_ext::is_pattern_cond; use syntax::{ - ast::{self, AstNode, BinaryOp}, T, + ast::{self, AstNode, BinaryOp}, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: merge_nested_if // diff --git a/crates/ide-assists/src/handlers/move_bounds.rs b/crates/ide-assists/src/handlers/move_bounds.rs index 5101d8fa0a..35571ed834 100644 --- a/crates/ide-assists/src/handlers/move_bounds.rs +++ b/crates/ide-assists/src/handlers/move_bounds.rs @@ -1,8 +1,8 @@ use syntax::{ ast::{ - self, + self, AstNode, HasName, HasTypeBounds, edit_in_place::{GenericParamsOwnerEdit, Removable}, - make, AstNode, HasName, HasTypeBounds, + make, }, match_ast, }; diff --git a/crates/ide-assists/src/handlers/move_const_to_impl.rs b/crates/ide-assists/src/handlers/move_const_to_impl.rs index 743ea94761..71b1461a6e 100644 --- a/crates/ide-assists/src/handlers/move_const_to_impl.rs +++ b/crates/ide-assists/src/handlers/move_const_to_impl.rs @@ -1,8 +1,8 @@ use hir::{AsAssocItem, AssocItemContainer, FileRange, HasCrate, HasSource}; use ide_db::{assists::AssistId, defs::Definition, search::SearchScope}; use syntax::{ - ast::{self, edit::IndentLevel, edit_in_place::Indent, AstNode}, SyntaxKind, + ast::{self, AstNode, edit::IndentLevel, edit_in_place::Indent}, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/move_from_mod_rs.rs b/crates/ide-assists/src/handlers/move_from_mod_rs.rs index 10915f8aaf..0d6fc49e5f 100644 --- a/crates/ide-assists/src/handlers/move_from_mod_rs.rs +++ b/crates/ide-assists/src/handlers/move_from_mod_rs.rs @@ -2,7 +2,7 @@ use ide_db::{ assists::{AssistId, AssistKind}, base_db::AnchoredPathBuf, }; -use syntax::{ast, AstNode, ToSmolStr}; +use syntax::{AstNode, ToSmolStr, ast}; use crate::{ assist_context::{AssistContext, Assists}, diff --git a/crates/ide-assists/src/handlers/move_guard.rs b/crates/ide-assists/src/handlers/move_guard.rs index a487960d8d..abba3de4a1 100644 --- a/crates/ide-assists/src/handlers/move_guard.rs +++ b/crates/ide-assists/src/handlers/move_guard.rs @@ -1,6 +1,6 @@ use syntax::{ - ast::{edit::AstNodeEdit, make, AstNode, BlockExpr, ElseBranch, Expr, IfExpr, MatchArm, Pat}, SyntaxKind::WHITESPACE, + ast::{AstNode, BlockExpr, ElseBranch, Expr, IfExpr, MatchArm, Pat, edit::AstNodeEdit, make}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/move_module_to_file.rs b/crates/ide-assists/src/handlers/move_module_to_file.rs index bbf18e2194..5f547593b4 100644 --- a/crates/ide-assists/src/handlers/move_module_to_file.rs +++ b/crates/ide-assists/src/handlers/move_module_to_file.rs @@ -1,13 +1,13 @@ use std::iter; use ast::edit::IndentLevel; -use hir::{sym, HasAttrs}; +use hir::{HasAttrs, sym}; use ide_db::base_db::AnchoredPathBuf; use itertools::Itertools; use stdx::format_to; use syntax::{ - ast::{self, edit::AstNodeEdit, HasName}, AstNode, SmolStr, TextRange, + ast::{self, HasName, edit::AstNodeEdit}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/move_to_mod_rs.rs b/crates/ide-assists/src/handlers/move_to_mod_rs.rs index 7b38c795dc..a19c122ddf 100644 --- a/crates/ide-assists/src/handlers/move_to_mod_rs.rs +++ b/crates/ide-assists/src/handlers/move_to_mod_rs.rs @@ -2,7 +2,7 @@ use ide_db::{ assists::{AssistId, AssistKind}, base_db::AnchoredPathBuf, }; -use syntax::{ast, AstNode, ToSmolStr}; +use syntax::{AstNode, ToSmolStr, ast}; use crate::{ assist_context::{AssistContext, Assists}, diff --git a/crates/ide-assists/src/handlers/normalize_import.rs b/crates/ide-assists/src/handlers/normalize_import.rs index 0b91eb676d..813c2dd191 100644 --- a/crates/ide-assists/src/handlers/normalize_import.rs +++ b/crates/ide-assists/src/handlers/normalize_import.rs @@ -1,9 +1,9 @@ use ide_db::imports::merge_imports::try_normalize_import; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: normalize_import diff --git a/crates/ide-assists/src/handlers/number_representation.rs b/crates/ide-assists/src/handlers/number_representation.rs index a13799f9b1..9b81aecd7d 100644 --- a/crates/ide-assists/src/handlers/number_representation.rs +++ b/crates/ide-assists/src/handlers/number_representation.rs @@ -1,4 +1,4 @@ -use syntax::{ast, ast::Radix, AstToken}; +use syntax::{AstToken, ast, ast::Radix}; use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; diff --git a/crates/ide-assists/src/handlers/promote_local_to_const.rs b/crates/ide-assists/src/handlers/promote_local_to_const.rs index 0cc771ff39..04a19d7869 100644 --- a/crates/ide-assists/src/handlers/promote_local_to_const.rs +++ b/crates/ide-assists/src/handlers/promote_local_to_const.rs @@ -5,8 +5,9 @@ use ide_db::{ }; use stdx::to_upper_snake_case; use syntax::{ - ast::{self, make, HasName}, - ted, AstNode, + AstNode, + ast::{self, HasName, make}, + ted, }; use crate::{ diff --git a/crates/ide-assists/src/handlers/pull_assignment_up.rs b/crates/ide-assists/src/handlers/pull_assignment_up.rs index f222b3eb90..d9e71ec763 100644 --- a/crates/ide-assists/src/handlers/pull_assignment_up.rs +++ b/crates/ide-assists/src/handlers/pull_assignment_up.rs @@ -1,11 +1,12 @@ use syntax::{ + AstNode, ast::{self, make}, - ted, AstNode, + ted, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: pull_assignment_up diff --git a/crates/ide-assists/src/handlers/qualify_method_call.rs b/crates/ide-assists/src/handlers/qualify_method_call.rs index c3600af5a6..d8ade0eb87 100644 --- a/crates/ide-assists/src/handlers/qualify_method_call.rs +++ b/crates/ide-assists/src/handlers/qualify_method_call.rs @@ -1,6 +1,6 @@ -use hir::{db::HirDatabase, AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef}; +use hir::{AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef, db::HirDatabase}; use ide_db::assists::{AssistId, AssistKind}; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::{ assist_context::{AssistContext, Assists}, diff --git a/crates/ide-assists/src/handlers/qualify_path.rs b/crates/ide-assists/src/handlers/qualify_path.rs index 2a8465f634..a4f066ad36 100644 --- a/crates/ide-assists/src/handlers/qualify_path.rs +++ b/crates/ide-assists/src/handlers/qualify_path.rs @@ -7,18 +7,17 @@ use ide_db::{ helpers::mod_path_to_ast, imports::import_assets::{ImportCandidate, LocatedImport}, }; -use syntax::ast::HasGenericArgs; use syntax::Edition; +use syntax::ast::HasGenericArgs; use syntax::{ - ast, - ast::{make, HasArgList}, - AstNode, NodeOrToken, + AstNode, NodeOrToken, ast, + ast::{HasArgList, make}, }; use crate::{ + AssistId, AssistKind, GroupLabel, assist_context::{AssistContext, Assists}, handlers::auto_import::find_importable_node, - AssistId, AssistKind, GroupLabel, }; // Assist: qualify_path diff --git a/crates/ide-assists/src/handlers/raw_string.rs b/crates/ide-assists/src/handlers/raw_string.rs index 5a197f23d0..21c697f538 100644 --- a/crates/ide-assists/src/handlers/raw_string.rs +++ b/crates/ide-assists/src/handlers/raw_string.rs @@ -1,8 +1,8 @@ use std::borrow::Cow; -use syntax::{ast, ast::IsString, AstToken, TextRange, TextSize}; +use syntax::{AstToken, TextRange, TextSize, ast, ast::IsString}; -use crate::{utils::required_hashes, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils::required_hashes}; // Assist: make_raw_string // diff --git a/crates/ide-assists/src/handlers/remove_dbg.rs b/crates/ide-assists/src/handlers/remove_dbg.rs index 1f57f7d3d3..cbc2e4f004 100644 --- a/crates/ide-assists/src/handlers/remove_dbg.rs +++ b/crates/ide-assists/src/handlers/remove_dbg.rs @@ -1,7 +1,8 @@ use itertools::Itertools; use syntax::{ - ast::{self, make, AstNode, AstToken}, - match_ast, ted, Edition, NodeOrToken, SyntaxElement, TextRange, TextSize, T, + Edition, NodeOrToken, SyntaxElement, T, TextRange, TextSize, + ast::{self, AstNode, AstToken, make}, + match_ast, ted, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/remove_parentheses.rs b/crates/ide-assists/src/handlers/remove_parentheses.rs index e7beb23bf8..9bd8decbed 100644 --- a/crates/ide-assists/src/handlers/remove_parentheses.rs +++ b/crates/ide-assists/src/handlers/remove_parentheses.rs @@ -1,7 +1,7 @@ use syntax::{ + AstNode, SyntaxKind, T, ast::{self, syntax_factory::SyntaxFactory}, syntax_editor::Position, - AstNode, SyntaxKind, T, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/remove_unused_imports.rs b/crates/ide-assists/src/handlers/remove_unused_imports.rs index 0570b44778..01c4eedd3e 100644 --- a/crates/ide-assists/src/handlers/remove_unused_imports.rs +++ b/crates/ide-assists/src/handlers/remove_unused_imports.rs @@ -3,13 +3,13 @@ use std::collections::hash_map::Entry; use hir::{FileRange, HirFileIdExt, InFile, InRealFile, Module, ModuleSource}; use ide_db::text_edit::TextRange; use ide_db::{ + FxHashMap, RootDatabase, defs::Definition, search::{FileReference, ReferenceCategory, SearchScope}, - FxHashMap, RootDatabase, }; use syntax::{ - ast::{self, Rename}, AstNode, + ast::{self, Rename}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/remove_unused_param.rs b/crates/ide-assists/src/handlers/remove_unused_param.rs index 2d7722a654..6ebc9007cf 100644 --- a/crates/ide-assists/src/handlers/remove_unused_param.rs +++ b/crates/ide-assists/src/handlers/remove_unused_param.rs @@ -1,18 +1,18 @@ use ide_db::{ - base_db::salsa::AsDynDatabase, defs::Definition, search::FileReference, EditionedFileId, + EditionedFileId, base_db::salsa::AsDynDatabase, defs::Definition, search::FileReference, }; use syntax::{ + AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, T, TextRange, algo::{find_node_at_range, least_common_ancestor_element}, ast::{self, HasArgList}, syntax_editor::Element, - AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, T, }; use SyntaxKind::WHITESPACE; use crate::{ - assist_context::SourceChangeBuilder, utils::next_prev, AssistContext, AssistId, AssistKind, - Assists, + AssistContext, AssistId, AssistKind, Assists, assist_context::SourceChangeBuilder, + utils::next_prev, }; // Assist: remove_unused_param diff --git a/crates/ide-assists/src/handlers/reorder_fields.rs b/crates/ide-assists/src/handlers/reorder_fields.rs index a79a82be45..410e2bbbdf 100644 --- a/crates/ide-assists/src/handlers/reorder_fields.rs +++ b/crates/ide-assists/src/handlers/reorder_fields.rs @@ -1,7 +1,7 @@ use either::Either; use ide_db::FxHashMap; use itertools::Itertools; -use syntax::{ast, syntax_editor::SyntaxEditor, AstNode, SmolStr, SyntaxElement, ToSmolStr}; +use syntax::{AstNode, SmolStr, SyntaxElement, ToSmolStr, ast, syntax_editor::SyntaxEditor}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/reorder_impl_items.rs b/crates/ide-assists/src/handlers/reorder_impl_items.rs index c3404173ea..e254fb9949 100644 --- a/crates/ide-assists/src/handlers/reorder_impl_items.rs +++ b/crates/ide-assists/src/handlers/reorder_impl_items.rs @@ -2,8 +2,8 @@ use hir::{PathResolution, Semantics}; use ide_db::{FxHashMap, RootDatabase}; use itertools::Itertools; use syntax::{ - ast::{self, HasName}, AstNode, SyntaxElement, + ast::{self, HasName}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_arith_op.rs b/crates/ide-assists/src/handlers/replace_arith_op.rs index 4b20b35c44..39f350fb68 100644 --- a/crates/ide-assists/src/handlers/replace_arith_op.rs +++ b/crates/ide-assists/src/handlers/replace_arith_op.rs @@ -1,7 +1,7 @@ use ide_db::assists::{AssistId, AssistKind, GroupLabel}; use syntax::{ - ast::{self, ArithOp, BinaryOp}, AstNode, TextRange, + ast::{self, ArithOp, BinaryOp}, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs index 31e828eae2..7696a14a4f 100644 --- a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs @@ -2,19 +2,19 @@ use hir::{InFile, MacroFileIdExt, ModuleDef}; use ide_db::{helpers::mod_path_to_ast, imports::import_assets::NameToImport, items_locator}; use itertools::Itertools; use syntax::{ - ast::{self, make, AstNode, HasName}, - ted, SyntaxKind::WHITESPACE, T, + ast::{self, AstNode, HasName, make}, + ted, }; use crate::{ + AssistId, AssistKind, assist_context::{AssistContext, Assists, SourceChangeBuilder}, utils::{ - add_trait_assoc_items_to_impl, filter_assoc_items, gen_trait_fn_body, generate_trait_impl, - DefaultMethods, IgnoreAssocItems, + DefaultMethods, IgnoreAssocItems, add_trait_assoc_items_to_impl, filter_assoc_items, + gen_trait_fn_body, generate_trait_impl, }, - AssistId, AssistKind, }; // Assist: replace_derive_with_manual_impl diff --git a/crates/ide-assists/src/handlers/replace_if_let_with_match.rs b/crates/ide-assists/src/handlers/replace_if_let_with_match.rs index e324d6eaaa..c3b753653c 100644 --- a/crates/ide-assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide-assists/src/handlers/replace_if_let_with_match.rs @@ -2,19 +2,19 @@ use std::iter::successors; use either::Either; use ide_db::{ + RootDatabase, defs::NameClass, syntax_helpers::node_ext::{is_pattern_cond, single_let}, ty_filter::TryEnum, - RootDatabase, }; use syntax::{ - ast::{self, edit::IndentLevel, edit_in_place::Indent, syntax_factory::SyntaxFactory, HasName}, - AstNode, TextRange, T, + AstNode, T, TextRange, + ast::{self, HasName, edit::IndentLevel, edit_in_place::Indent, syntax_factory::SyntaxFactory}, }; use crate::{ - utils::{does_pat_match_variant, does_pat_variant_nested_or_literal, unwrap_trivial_block}, AssistContext, AssistId, AssistKind, Assists, + utils::{does_pat_match_variant, does_pat_variant_nested_or_literal, unwrap_trivial_block}, }; // Assist: replace_if_let_with_match diff --git a/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs b/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs index 47972ff619..c49f285d8e 100644 --- a/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs +++ b/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs @@ -1,6 +1,6 @@ use ide_db::syntax_helpers::suggest_name; use syntax::{ - ast::{self, make, AstNode}, + ast::{self, AstNode, make}, ted, }; diff --git a/crates/ide-assists/src/handlers/replace_let_with_if_let.rs b/crates/ide-assists/src/handlers/replace_let_with_if_let.rs index c071d3022d..34bbd6ba5b 100644 --- a/crates/ide-assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/ide-assists/src/handlers/replace_let_with_if_let.rs @@ -1,7 +1,7 @@ use ide_db::ty_filter::TryEnum; use syntax::{ - ast::{self, edit::IndentLevel, edit_in_place::Indent, syntax_factory::SyntaxFactory}, AstNode, T, + ast::{self, edit::IndentLevel, edit_in_place::Indent, syntax_factory::SyntaxFactory}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs b/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs index 12d025f075..88b56ebb4b 100644 --- a/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs +++ b/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs @@ -1,7 +1,7 @@ use ide_db::assists::{AssistId, AssistKind}; use syntax::{ - ast::{self, make, Expr, HasArgList}, AstNode, + ast::{self, Expr, HasArgList, make}, }; use crate::{AssistContext, Assists}; @@ -74,11 +74,7 @@ pub(crate) fn replace_with_lazy_method(acc: &mut Assists, ctx: &AssistContext<'_ fn into_closure(param: &Expr) -> Expr { (|| { if let ast::Expr::CallExpr(call) = param { - if call.arg_list()?.args().count() == 0 { - Some(call.expr()?) - } else { - None - } + if call.arg_list()?.args().count() == 0 { Some(call.expr()?) } else { None } } else { None } @@ -154,11 +150,7 @@ pub(crate) fn replace_with_eager_method(acc: &mut Assists, ctx: &AssistContext<' fn into_call(param: &Expr) -> Expr { (|| { if let ast::Expr::ClosureExpr(closure) = param { - if closure.param_list()?.params().count() == 0 { - Some(closure.body()?) - } else { - None - } + if closure.param_list()?.params().count() == 0 { Some(closure.body()?) } else { None } } else { None } diff --git a/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs b/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs index 26fd887cc9..f99394e877 100644 --- a/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs +++ b/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs @@ -1,16 +1,17 @@ use hir::{FileRange, Semantics}; use ide_db::text_edit::TextRange; use ide_db::{ + EditionedFileId, RootDatabase, defs::Definition, search::{SearchScope, UsageSearchResult}, - EditionedFileId, RootDatabase, }; use syntax::{ + AstNode, ast::{ - self, make::impl_trait_type, HasGenericParams, HasName, HasTypeBounds, Name, NameLike, - PathType, + self, HasGenericParams, HasName, HasTypeBounds, Name, NameLike, PathType, + make::impl_trait_type, }, - match_ast, ted, AstNode, + match_ast, ted, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs index f026b3230d..08a4d28e9f 100644 --- a/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs @@ -1,11 +1,12 @@ use hir::AsAssocItem; use ide_db::{ helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope}, + imports::insert_use::{ImportScope, insert_use}, }; use syntax::{ - ast::{self, make, HasGenericArgs}, - match_ast, ted, AstNode, Edition, SyntaxNode, + AstNode, Edition, SyntaxNode, + ast::{self, HasGenericArgs, make}, + match_ast, ted, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_string_with_char.rs b/crates/ide-assists/src/handlers/replace_string_with_char.rs index a48b20acbc..176b4e4af0 100644 --- a/crates/ide-assists/src/handlers/replace_string_with_char.rs +++ b/crates/ide-assists/src/handlers/replace_string_with_char.rs @@ -1,9 +1,8 @@ use syntax::{ - ast, - ast::IsString, AstToken, SyntaxKind::{CHAR, STRING}, - TextRange, TextSize, + TextRange, TextSize, ast, + ast::IsString, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs b/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs index 88b50543dd..93dfe48ebc 100644 --- a/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs +++ b/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs @@ -5,12 +5,12 @@ use ide_db::{ ty_filter::TryEnum, }; use syntax::{ + AstNode, T, ast::{ self, edit::{AstNodeEdit, IndentLevel}, make, }, - AstNode, T, }; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs b/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs index 3a6391cd38..39ebca25a9 100644 --- a/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs +++ b/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs @@ -1,12 +1,12 @@ use hir::HirDisplay; use syntax::{ - ast::{Expr, GenericArg, GenericArgList, HasGenericArgs, LetStmt, Type::InferType}, AstNode, TextRange, + ast::{Expr, GenericArg, GenericArgList, HasGenericArgs, LetStmt, Type::InferType}, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: replace_turbofish_with_explicit_type diff --git a/crates/ide-assists/src/handlers/sort_items.rs b/crates/ide-assists/src/handlers/sort_items.rs index 54e16d4d80..73dfbf0237 100644 --- a/crates/ide-assists/src/handlers/sort_items.rs +++ b/crates/ide-assists/src/handlers/sort_items.rs @@ -3,11 +3,11 @@ use std::cmp::Ordering; use itertools::Itertools; use syntax::{ - ast::{self, HasName}, AstNode, SyntaxNode, + ast::{self, HasName}, }; -use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils::get_methods}; // Assist: sort_items // diff --git a/crates/ide-assists/src/handlers/split_import.rs b/crates/ide-assists/src/handlers/split_import.rs index 775ededecb..63371ddf9f 100644 --- a/crates/ide-assists/src/handlers/split_import.rs +++ b/crates/ide-assists/src/handlers/split_import.rs @@ -1,4 +1,4 @@ -use syntax::{ast, AstNode, T}; +use syntax::{AstNode, T, ast}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/term_search.rs b/crates/ide-assists/src/handlers/term_search.rs index e10897b3be..7b2598b455 100644 --- a/crates/ide-assists/src/handlers/term_search.rs +++ b/crates/ide-assists/src/handlers/term_search.rs @@ -6,7 +6,7 @@ use ide_db::{ }; use itertools::Itertools; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/toggle_async_sugar.rs b/crates/ide-assists/src/handlers/toggle_async_sugar.rs index 8f937a0412..9f45b2898a 100644 --- a/crates/ide-assists/src/handlers/toggle_async_sugar.rs +++ b/crates/ide-assists/src/handlers/toggle_async_sugar.rs @@ -4,8 +4,8 @@ use ide_db::{ famous_defs::FamousDefs, }; use syntax::{ - ast::{self, HasGenericArgs, HasVisibility}, AstNode, NodeOrToken, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, + ast::{self, HasGenericArgs, HasVisibility}, }; use crate::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/toggle_ignore.rs b/crates/ide-assists/src/handlers/toggle_ignore.rs index 264a2f0326..c1ea7dc4c7 100644 --- a/crates/ide-assists/src/handlers/toggle_ignore.rs +++ b/crates/ide-assists/src/handlers/toggle_ignore.rs @@ -1,9 +1,9 @@ use syntax::{ - ast::{self, HasAttrs}, AstNode, AstToken, + ast::{self, HasAttrs}, }; -use crate::{utils::test_related_attribute_syn, AssistContext, AssistId, AssistKind, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists, utils::test_related_attribute_syn}; // Assist: toggle_ignore // diff --git a/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs b/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs index e452b5f778..80834abecc 100644 --- a/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs +++ b/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs @@ -1,7 +1,8 @@ use ide_db::assists::{AssistId, AssistKind}; use syntax::{ + AstNode, T, ast::{self, make}, - ted, AstNode, T, + ted, }; use crate::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/unmerge_match_arm.rs b/crates/ide-assists/src/handlers/unmerge_match_arm.rs index 6b9f661d4d..8b6aef02ec 100644 --- a/crates/ide-assists/src/handlers/unmerge_match_arm.rs +++ b/crates/ide-assists/src/handlers/unmerge_match_arm.rs @@ -1,8 +1,8 @@ use syntax::{ - algo::neighbor, - ast::{self, edit::IndentLevel, make, AstNode}, - ted::{self, Position}, Direction, SyntaxKind, T, + algo::neighbor, + ast::{self, AstNode, edit::IndentLevel, make}, + ted::{self, Position}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/unmerge_use.rs b/crates/ide-assists/src/handlers/unmerge_use.rs index 38ca572fa6..7f2dd19ce0 100644 --- a/crates/ide-assists/src/handlers/unmerge_use.rs +++ b/crates/ide-assists/src/handlers/unmerge_use.rs @@ -1,12 +1,12 @@ use syntax::{ - ast::{self, edit_in_place::Removable, make, HasVisibility}, - ted::{self, Position}, AstNode, SyntaxKind, + ast::{self, HasVisibility, edit_in_place::Removable, make}, + ted::{self, Position}, }; use crate::{ - assist_context::{AssistContext, Assists}, AssistId, AssistKind, + assist_context::{AssistContext, Assists}, }; // Assist: unmerge_use diff --git a/crates/ide-assists/src/handlers/unnecessary_async.rs b/crates/ide-assists/src/handlers/unnecessary_async.rs index abe7fb132f..f3ae70160b 100644 --- a/crates/ide-assists/src/handlers/unnecessary_async.rs +++ b/crates/ide-assists/src/handlers/unnecessary_async.rs @@ -1,13 +1,13 @@ use ide_db::{ + EditionedFileId, assists::{AssistId, AssistKind}, defs::Definition, search::{FileReference, FileReferenceNode}, syntax_helpers::node_ext::full_path_of_name_ref, - EditionedFileId, }; use syntax::{ - ast::{self, NameRef}, AstNode, SyntaxKind, TextRange, + ast::{self, NameRef}, }; use crate::{AssistContext, Assists}; diff --git a/crates/ide-assists/src/handlers/unqualify_method_call.rs b/crates/ide-assists/src/handlers/unqualify_method_call.rs index baf4ddae2f..712c8c3d14 100644 --- a/crates/ide-assists/src/handlers/unqualify_method_call.rs +++ b/crates/ide-assists/src/handlers/unqualify_method_call.rs @@ -1,7 +1,7 @@ use ide_db::imports::insert_use::ImportScope; use syntax::{ - ast::{self, prec::ExprPrecedence, AstNode, HasArgList}, TextRange, + ast::{self, AstNode, HasArgList, prec::ExprPrecedence}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/unwrap_block.rs b/crates/ide-assists/src/handlers/unwrap_block.rs index fd37140e9c..80d8cebff5 100644 --- a/crates/ide-assists/src/handlers/unwrap_block.rs +++ b/crates/ide-assists/src/handlers/unwrap_block.rs @@ -1,10 +1,10 @@ use syntax::{ + AstNode, SyntaxKind, T, TextRange, ast::{ self, edit::{AstNodeEdit, IndentLevel}, make, }, - AstNode, SyntaxKind, TextRange, T, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/unwrap_return_type.rs b/crates/ide-assists/src/handlers/unwrap_return_type.rs index f647b531b7..f6eb68524f 100644 --- a/crates/ide-assists/src/handlers/unwrap_return_type.rs +++ b/crates/ide-assists/src/handlers/unwrap_return_type.rs @@ -4,8 +4,9 @@ use ide_db::{ syntax_helpers::node_ext::{for_each_tail_expr, walk_expr}, }; use syntax::{ - ast::{self, syntax_factory::SyntaxFactory, HasArgList, HasGenericArgs}, - match_ast, AstNode, NodeOrToken, SyntaxKind, + AstNode, NodeOrToken, SyntaxKind, + ast::{self, HasArgList, HasGenericArgs, syntax_factory::SyntaxFactory}, + match_ast, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/unwrap_tuple.rs b/crates/ide-assists/src/handlers/unwrap_tuple.rs index d09614c511..55053ac97d 100644 --- a/crates/ide-assists/src/handlers/unwrap_tuple.rs +++ b/crates/ide-assists/src/handlers/unwrap_tuple.rs @@ -1,6 +1,6 @@ use syntax::{ - ast::{self, edit::AstNodeEdit}, AstNode, T, + ast::{self, edit::AstNodeEdit}, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/wrap_return_type.rs b/crates/ide-assists/src/handlers/wrap_return_type.rs index 0b145dcb06..8857c446f6 100644 --- a/crates/ide-assists/src/handlers/wrap_return_type.rs +++ b/crates/ide-assists/src/handlers/wrap_return_type.rs @@ -7,8 +7,9 @@ use ide_db::{ syntax_helpers::node_ext::{for_each_tail_expr, walk_expr}, }; use syntax::{ - ast::{self, syntax_factory::SyntaxFactory, Expr, HasGenericArgs, HasGenericParams}, - match_ast, AstNode, + AstNode, + ast::{self, Expr, HasGenericArgs, HasGenericParams, syntax_factory::SyntaxFactory}, + match_ast, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs b/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs index 149cb4c438..717c68d04e 100644 --- a/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs +++ b/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs @@ -1,10 +1,9 @@ use ide_db::source_change::SourceChangeBuilder; use itertools::Itertools; use syntax::{ - algo, - ast::{self, make, AstNode}, + NodeOrToken, SyntaxToken, T, TextRange, algo, + ast::{self, AstNode, make}, ted::{self, Position}, - NodeOrToken, SyntaxToken, TextRange, T, }; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -296,11 +295,7 @@ fn unwrap_cfg_attr(acc: &mut Assists, attr: ast::Attr) -> Option<()> { continue; } let Some(attr_name) = tt.into_token().and_then(|token| { - if token.kind() == T![ident] { - Some(make::ext::ident_path(token.text())) - } else { - None - } + if token.kind() == T![ident] { Some(make::ext::ident_path(token.text())) } else { None } }) else { continue; }; diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 4f751b68e7..a23461e69a 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -3,10 +3,10 @@ mod generated; use expect_test::expect; use hir::{FileRange, Semantics}; use ide_db::{ + EditionedFileId, RootDatabase, SnippetCap, base_db::SourceDatabase, imports::insert_use::{ImportGranularity, InsertUseConfig}, source_change::FileSystemEdit, - EditionedFileId, RootDatabase, SnippetCap, }; use stdx::{format_to, trim_indent}; use syntax::TextRange; @@ -14,8 +14,8 @@ use test_fixture::WithFixture; use test_utils::{assert_eq_text, extract_offset}; use crate::{ - assists, handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, - AssistResolveStrategy, Assists, SingleResolve, + Assist, AssistConfig, AssistContext, AssistKind, AssistResolveStrategy, Assists, SingleResolve, + assists, handlers::Handler, }; pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs index a6fa170671..0806d5feb1 100644 --- a/crates/ide-assists/src/utils.rs +++ b/crates/ide-assists/src/utils.rs @@ -2,29 +2,29 @@ pub(crate) use gen_trait_fn_body::gen_trait_fn_body; use hir::{ - db::{ExpandDatabase, HirDatabase}, DisplayTarget, HasAttrs as HirHasAttrs, HirDisplay, InFile, ModuleDef, PathResolution, Semantics, + db::{ExpandDatabase, HirDatabase}, }; use ide_db::{ + RootDatabase, famous_defs::FamousDefs, path_transform::PathTransform, syntax_helpers::{node_ext::preorder_expr, prettify_macro_expansion}, - RootDatabase, }; use stdx::format_to; use syntax::{ + AstNode, AstToken, Direction, NodeOrToken, SourceFile, + SyntaxKind::*, + SyntaxNode, SyntaxToken, T, TextRange, TextSize, WalkEvent, ast::{ - self, + self, HasArgList, HasAttrs, HasGenericParams, HasName, HasTypeBounds, Whitespace, edit::{AstNodeEdit, IndentLevel}, edit_in_place::{AttrsOwnerEdit, Indent, Removable}, make, syntax_factory::SyntaxFactory, - HasArgList, HasAttrs, HasGenericParams, HasName, HasTypeBounds, Whitespace, }, - ted, AstNode, AstToken, Direction, NodeOrToken, SourceFile, - SyntaxKind::*, - SyntaxNode, SyntaxToken, TextRange, TextSize, WalkEvent, T, + ted, }; use crate::assist_context::{AssistContext, SourceChangeBuilder}; @@ -82,11 +82,7 @@ pub fn test_related_attribute_syn(fn_def: &ast::Fn) -> Option { fn_def.attrs().find_map(|attr| { let path = attr.path()?; let text = path.syntax().text().to_string(); - if text.starts_with("test") || text.ends_with("test") { - Some(attr) - } else { - None - } + if text.starts_with("test") || text.ends_with("test") { Some(attr) } else { None } }) } @@ -498,11 +494,7 @@ pub(crate) fn find_struct_impl( }; let not_trait_impl = blk.trait_(db).is_none(); - if !(same_ty && not_trait_impl) { - None - } else { - Some(impl_blk) - } + if !(same_ty && not_trait_impl) { None } else { Some(impl_blk) } }); if let Some(ref impl_blk) = block { diff --git a/crates/ide-assists/src/utils/gen_trait_fn_body.rs b/crates/ide-assists/src/utils/gen_trait_fn_body.rs index 7a9bdfe1ec..5c2e27b343 100644 --- a/crates/ide-assists/src/utils/gen_trait_fn_body.rs +++ b/crates/ide-assists/src/utils/gen_trait_fn_body.rs @@ -2,7 +2,7 @@ use hir::TraitRef; use syntax::{ - ast::{self, edit::AstNodeEdit, make, AstNode, BinaryOp, CmpOp, HasName, LogicOp}, + ast::{self, AstNode, BinaryOp, CmpOp, HasName, LogicOp, edit::AstNodeEdit, make}, ted, }; diff --git a/crates/ide-assists/src/utils/ref_field_expr.rs b/crates/ide-assists/src/utils/ref_field_expr.rs index d434872ea5..28830cf2f9 100644 --- a/crates/ide-assists/src/utils/ref_field_expr.rs +++ b/crates/ide-assists/src/utils/ref_field_expr.rs @@ -4,8 +4,8 @@ //! It determines whether to deref the new expression and/or wrap it in parentheses, //! based on the parent of the existing expression. use syntax::{ - ast::{self, make, FieldExpr, MethodCallExpr}, AstNode, T, + ast::{self, FieldExpr, MethodCallExpr, make}, }; use crate::AssistContext; diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs index a22e7b272e..c8cdad5949 100644 --- a/crates/ide-completion/src/completions.rs +++ b/crates/ide-completion/src/completions.rs @@ -24,17 +24,19 @@ pub(crate) mod vis; use std::iter; -use hir::{sym, HasAttrs, Name, ScopeDef, Variant}; -use ide_db::{imports::import_assets::LocatedImport, RootDatabase, SymbolKind}; -use syntax::{ast, SmolStr, ToSmolStr}; +use hir::{HasAttrs, Name, ScopeDef, Variant, sym}; +use ide_db::{RootDatabase, SymbolKind, imports::import_assets::LocatedImport}; +use syntax::{SmolStr, ToSmolStr, ast}; use crate::{ + CompletionContext, CompletionItem, CompletionItemKind, context::{ DotAccess, ItemListKind, NameContext, NameKind, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, PatternContext, TypeLocation, Visible, }, item::Builder, render::{ + RenderContext, const_::render_const, function::{render_fn, render_method}, literal::{render_struct_literal, render_variant_lit}, @@ -44,9 +46,7 @@ use crate::{ render_tuple_field, type_alias::{render_type_alias, render_type_alias_with_eq}, union_literal::render_union_literal, - RenderContext, }, - CompletionContext, CompletionItem, CompletionItemKind, }; /// Represents an in-progress set of completions being built. diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs index cf5427bae3..fb7df8cc7f 100644 --- a/crates/ide-completion/src/completions/attribute.rs +++ b/crates/ide-completion/src/completions/attribute.rs @@ -5,22 +5,22 @@ use std::sync::LazyLock; use ide_db::{ + FxHashMap, SymbolKind, generated::lints::{ - Lint, CLIPPY_LINTS, CLIPPY_LINT_GROUPS, DEFAULT_LINTS, FEATURES, RUSTDOC_LINTS, + CLIPPY_LINT_GROUPS, CLIPPY_LINTS, DEFAULT_LINTS, FEATURES, Lint, RUSTDOC_LINTS, }, syntax_helpers::node_ext::parse_tt_as_comma_sep_paths, - FxHashMap, SymbolKind, }; use itertools::Itertools; use syntax::{ - ast::{self, AttrKind}, AstNode, Edition, SyntaxKind, T, + ast::{self, AttrKind}, }; use crate::{ + Completions, context::{AttrCtx, CompletionContext, PathCompletionCtx, Qualified}, item::CompletionItem, - Completions, }; mod cfg; diff --git a/crates/ide-completion/src/completions/attribute/cfg.rs b/crates/ide-completion/src/completions/attribute/cfg.rs index cda0da13b2..1676a8467c 100644 --- a/crates/ide-completion/src/completions/attribute/cfg.rs +++ b/crates/ide-completion/src/completions/attribute/cfg.rs @@ -2,9 +2,9 @@ use ide_db::SymbolKind; use itertools::Itertools; -use syntax::{algo, ast::Ident, AstToken, Direction, NodeOrToken, SyntaxKind}; +use syntax::{AstToken, Direction, NodeOrToken, SyntaxKind, algo, ast::Ident}; -use crate::{completions::Completions, context::CompletionContext, CompletionItem}; +use crate::{CompletionItem, completions::Completions, context::CompletionContext}; pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) { let add_completion = |item: &str| { diff --git a/crates/ide-completion/src/completions/attribute/derive.rs b/crates/ide-completion/src/completions/attribute/derive.rs index 1f8927401b..2fc07e0138 100644 --- a/crates/ide-completion/src/completions/attribute/derive.rs +++ b/crates/ide-completion/src/completions/attribute/derive.rs @@ -1,13 +1,13 @@ //! Completion for derives use hir::ScopeDef; -use ide_db::{documentation::HasDocs, SymbolKind}; +use ide_db::{SymbolKind, documentation::HasDocs}; use itertools::Itertools; use syntax::{SmolStr, ToSmolStr}; use crate::{ + Completions, context::{CompletionContext, ExistingDerives, PathCompletionCtx, Qualified}, item::CompletionItem, - Completions, }; pub(crate) fn complete_derive_path( diff --git a/crates/ide-completion/src/completions/attribute/lint.rs b/crates/ide-completion/src/completions/attribute/lint.rs index 04f40e805a..c87c46d981 100644 --- a/crates/ide-completion/src/completions/attribute/lint.rs +++ b/crates/ide-completion/src/completions/attribute/lint.rs @@ -1,8 +1,8 @@ //! Completion for lints -use ide_db::{documentation::Documentation, generated::lints::Lint, SymbolKind}; +use ide_db::{SymbolKind, documentation::Documentation, generated::lints::Lint}; use syntax::ast; -use crate::{context::CompletionContext, item::CompletionItem, Completions}; +use crate::{Completions, context::CompletionContext, item::CompletionItem}; pub(super) fn complete_lint( acc: &mut Completions, diff --git a/crates/ide-completion/src/completions/attribute/macro_use.rs b/crates/ide-completion/src/completions/attribute/macro_use.rs index deb12282c0..0641a4f6c3 100644 --- a/crates/ide-completion/src/completions/attribute/macro_use.rs +++ b/crates/ide-completion/src/completions/attribute/macro_use.rs @@ -3,7 +3,7 @@ use hir::ModuleDef; use ide_db::SymbolKind; use syntax::ast; -use crate::{context::CompletionContext, item::CompletionItem, Completions}; +use crate::{Completions, context::CompletionContext, item::CompletionItem}; pub(super) fn complete_macro_use( acc: &mut Completions, diff --git a/crates/ide-completion/src/completions/attribute/repr.rs b/crates/ide-completion/src/completions/attribute/repr.rs index 12652b4489..cb7ccf7373 100644 --- a/crates/ide-completion/src/completions/attribute/repr.rs +++ b/crates/ide-completion/src/completions/attribute/repr.rs @@ -3,7 +3,7 @@ use ide_db::SymbolKind; use syntax::ast; -use crate::{context::CompletionContext, item::CompletionItem, Completions}; +use crate::{Completions, context::CompletionContext, item::CompletionItem}; pub(super) fn complete_repr( acc: &mut Completions, diff --git a/crates/ide-completion/src/completions/dot.rs b/crates/ide-completion/src/completions/dot.rs index b38b9ac1f5..dea983b6ea 100644 --- a/crates/ide-completion/src/completions/dot.rs +++ b/crates/ide-completion/src/completions/dot.rs @@ -7,11 +7,11 @@ use ide_db::FxHashSet; use syntax::SmolStr; use crate::{ + CompletionItem, CompletionItemKind, Completions, context::{ CompletionContext, DotAccess, DotAccessExprCtx, DotAccessKind, PathCompletionCtx, PathExprCtx, Qualified, }, - CompletionItem, CompletionItemKind, Completions, }; /// Complete dot accesses, i.e. fields or methods. diff --git a/crates/ide-completion/src/completions/env_vars.rs b/crates/ide-completion/src/completions/env_vars.rs index 40af5203e9..ab8d8a6169 100644 --- a/crates/ide-completion/src/completions/env_vars.rs +++ b/crates/ide-completion/src/completions/env_vars.rs @@ -3,34 +3,46 @@ use hir::MacroFileIdExt; use ide_db::syntax_helpers::node_ext::macro_call_for_string_token; use syntax::{ - ast::{self, IsString}, AstToken, + ast::{self, IsString}, }; use crate::{ - completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind, + CompletionItem, CompletionItemKind, completions::Completions, context::CompletionContext, }; const CARGO_DEFINED_VARS: &[(&str, &str)] = &[ - ("CARGO","Path to the cargo binary performing the build"), - ("CARGO_MANIFEST_DIR","The directory containing the manifest of your package"), - ("CARGO_PKG_VERSION","The full version of your package"), - ("CARGO_PKG_VERSION_MAJOR","The major version of your package"), - ("CARGO_PKG_VERSION_MINOR","The minor version of your package"), - ("CARGO_PKG_VERSION_PATCH","The patch version of your package"), - ("CARGO_PKG_VERSION_PRE","The pre-release version of your package"), - ("CARGO_PKG_AUTHORS","Colon separated list of authors from the manifest of your package"), - ("CARGO_PKG_NAME","The name of your package"), - ("CARGO_PKG_DESCRIPTION","The description from the manifest of your package"), - ("CARGO_PKG_HOMEPAGE","The home page from the manifest of your package"), - ("CARGO_PKG_REPOSITORY","The repository from the manifest of your package"), - ("CARGO_PKG_LICENSE","The license from the manifest of your package"), - ("CARGO_PKG_LICENSE_FILE","The license file from the manifest of your package"), - ("CARGO_PKG_RUST_VERSION","The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version"), - ("CARGO_CRATE_NAME","The name of the crate that is currently being compiled"), - ("CARGO_BIN_NAME","The name of the binary that is currently being compiled (if it is a binary). This name does not include any file extension, such as .exe"), - ("CARGO_PRIMARY_PACKAGE","This environment variable will be set if the package being built is primary. Primary packages are the ones the user selected on the command-line, either with -p flags or the defaults based on the current directory and the default workspace members. This environment variable will not be set when building dependencies. This is only set when compiling the package (not when running binaries or tests)"), - ("CARGO_TARGET_TMPDIR","Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesn't manage its content in any way, this is the responsibility of the test code") + ("CARGO", "Path to the cargo binary performing the build"), + ("CARGO_MANIFEST_DIR", "The directory containing the manifest of your package"), + ("CARGO_PKG_VERSION", "The full version of your package"), + ("CARGO_PKG_VERSION_MAJOR", "The major version of your package"), + ("CARGO_PKG_VERSION_MINOR", "The minor version of your package"), + ("CARGO_PKG_VERSION_PATCH", "The patch version of your package"), + ("CARGO_PKG_VERSION_PRE", "The pre-release version of your package"), + ("CARGO_PKG_AUTHORS", "Colon separated list of authors from the manifest of your package"), + ("CARGO_PKG_NAME", "The name of your package"), + ("CARGO_PKG_DESCRIPTION", "The description from the manifest of your package"), + ("CARGO_PKG_HOMEPAGE", "The home page from the manifest of your package"), + ("CARGO_PKG_REPOSITORY", "The repository from the manifest of your package"), + ("CARGO_PKG_LICENSE", "The license from the manifest of your package"), + ("CARGO_PKG_LICENSE_FILE", "The license file from the manifest of your package"), + ( + "CARGO_PKG_RUST_VERSION", + "The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version", + ), + ("CARGO_CRATE_NAME", "The name of the crate that is currently being compiled"), + ( + "CARGO_BIN_NAME", + "The name of the binary that is currently being compiled (if it is a binary). This name does not include any file extension, such as .exe", + ), + ( + "CARGO_PRIMARY_PACKAGE", + "This environment variable will be set if the package being built is primary. Primary packages are the ones the user selected on the command-line, either with -p flags or the defaults based on the current directory and the default workspace members. This environment variable will not be set when building dependencies. This is only set when compiling the package (not when running binaries or tests)", + ), + ( + "CARGO_TARGET_TMPDIR", + "Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesn't manage its content in any way, this is the responsibility of the test code", + ), ]; pub(crate) fn complete_cargo_env_vars( diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs index b28b6e50e2..eb26543a4b 100644 --- a/crates/ide-completion/src/completions/expr.rs +++ b/crates/ide-completion/src/completions/expr.rs @@ -2,14 +2,14 @@ use std::ops::ControlFlow; -use hir::{sym, Name, PathCandidateCallback, ScopeDef}; +use hir::{Name, PathCandidateCallback, ScopeDef, sym}; use ide_db::FxHashSet; use syntax::ast; use crate::{ + CompletionContext, Completions, completions::record::add_default_update, context::{BreakableKind, PathCompletionCtx, PathExprCtx, Qualified}, - CompletionContext, Completions, }; struct PathCallback<'a, F> { @@ -79,11 +79,7 @@ pub(crate) fn complete_expr_path( let wants_const_token = ref_expr_parent.is_some() && has_raw_token && !has_const_token && !has_mut_token; let wants_mut_token = if ref_expr_parent.is_some() { - if has_raw_token { - !has_const_token && !has_mut_token - } else { - !has_mut_token - } + if has_raw_token { !has_const_token && !has_mut_token } else { !has_mut_token } } else { false }; diff --git a/crates/ide-completion/src/completions/extern_abi.rs b/crates/ide-completion/src/completions/extern_abi.rs index 7c2cc2a6c1..570d1a0a2d 100644 --- a/crates/ide-completion/src/completions/extern_abi.rs +++ b/crates/ide-completion/src/completions/extern_abi.rs @@ -1,11 +1,11 @@ //! Completes function abi strings. use syntax::{ - ast::{self, IsString}, AstNode, AstToken, SmolStr, + ast::{self, IsString}, }; use crate::{ - completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind, + CompletionItem, CompletionItemKind, completions::Completions, context::CompletionContext, }; // Most of these are feature gated, we should filter/add feature gate completions once we have them. diff --git a/crates/ide-completion/src/completions/extern_crate.rs b/crates/ide-completion/src/completions/extern_crate.rs index 7cb710c2d9..71a3e4eb4e 100644 --- a/crates/ide-completion/src/completions/extern_crate.rs +++ b/crates/ide-completion/src/completions/extern_crate.rs @@ -1,10 +1,10 @@ //! Completion for extern crates use hir::Name; -use ide_db::{documentation::HasDocs, SymbolKind}; +use ide_db::{SymbolKind, documentation::HasDocs}; use syntax::ToSmolStr; -use crate::{context::CompletionContext, CompletionItem, CompletionItemKind}; +use crate::{CompletionItem, CompletionItemKind, context::CompletionContext}; use super::Completions; diff --git a/crates/ide-completion/src/completions/field.rs b/crates/ide-completion/src/completions/field.rs index b795bbd872..1441b0e3a0 100644 --- a/crates/ide-completion/src/completions/field.rs +++ b/crates/ide-completion/src/completions/field.rs @@ -1,8 +1,8 @@ //! Completion of field list position. use crate::{ - context::{PathCompletionCtx, Qualified}, CompletionContext, Completions, + context::{PathCompletionCtx, Qualified}, }; pub(crate) fn complete_field_list_tuple_variant( diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs index b5555e6610..b3ba076489 100644 --- a/crates/ide-completion/src/completions/flyimport.rs +++ b/crates/ide-completion/src/completions/flyimport.rs @@ -5,16 +5,16 @@ use ide_db::imports::{ insert_use::ImportScope, }; use itertools::Itertools; -use syntax::{ast, AstNode, SyntaxNode}; +use syntax::{AstNode, SyntaxNode, ast}; use crate::{ + Completions, config::AutoImportExclusionType, context::{ CompletionContext, DotAccess, PathCompletionCtx, PathKind, PatternContext, Qualified, TypeLocation, }, - render::{render_resolution_with_import, render_resolution_with_import_pat, RenderContext}, - Completions, + render::{RenderContext, render_resolution_with_import, render_resolution_with_import_pat}, }; // Feature: Completion With Autoimport @@ -404,11 +404,7 @@ fn import_on_the_fly_method( fn import_name(ctx: &CompletionContext<'_>) -> String { let token_kind = ctx.token.kind(); - if token_kind.is_any_identifier() { - ctx.token.to_string() - } else { - String::new() - } + if token_kind.is_any_identifier() { ctx.token.to_string() } else { String::new() } } fn import_assets_for_path( diff --git a/crates/ide-completion/src/completions/fn_param.rs b/crates/ide-completion/src/completions/fn_param.rs index e86eaad4d0..6d1e973dc4 100644 --- a/crates/ide-completion/src/completions/fn_param.rs +++ b/crates/ide-completion/src/completions/fn_param.rs @@ -3,14 +3,14 @@ use hir::HirDisplay; use ide_db::FxHashMap; use syntax::{ - algo, + AstNode, Direction, SyntaxKind, TextRange, TextSize, algo, ast::{self, HasModuleItem}, - match_ast, AstNode, Direction, SyntaxKind, TextRange, TextSize, + match_ast, }; use crate::{ - context::{ParamContext, ParamKind, PatternContext}, CompletionContext, CompletionItem, CompletionItemKind, Completions, + context::{ParamContext, ParamKind, PatternContext}, }; // FIXME: Make this a submodule of [`pattern`] diff --git a/crates/ide-completion/src/completions/format_string.rs b/crates/ide-completion/src/completions/format_string.rs index dcd40c3412..5ae65b05bc 100644 --- a/crates/ide-completion/src/completions/format_string.rs +++ b/crates/ide-completion/src/completions/format_string.rs @@ -1,11 +1,11 @@ //! Completes identifiers in format string literals. use hir::{ModuleDef, ScopeDef}; -use ide_db::{syntax_helpers::format_string::is_format_string, SymbolKind}; +use ide_db::{SymbolKind, syntax_helpers::format_string::is_format_string}; use itertools::Itertools; -use syntax::{ast, AstToken, TextRange, TextSize, ToSmolStr}; +use syntax::{AstToken, TextRange, TextSize, ToSmolStr, ast}; -use crate::{context::CompletionContext, CompletionItem, CompletionItemKind, Completions}; +use crate::{CompletionItem, CompletionItemKind, Completions, context::CompletionContext}; /// Complete identifiers in format strings. pub(crate) fn format_string( diff --git a/crates/ide-completion/src/completions/item_list.rs b/crates/ide-completion/src/completions/item_list.rs index 3ab341e4ed..4ae00ccd81 100644 --- a/crates/ide-completion/src/completions/item_list.rs +++ b/crates/ide-completion/src/completions/item_list.rs @@ -1,8 +1,8 @@ //! Completion of paths and keywords at item list position. use crate::{ - context::{ItemListKind, PathCompletionCtx, PathExprCtx, Qualified}, CompletionContext, Completions, + context::{ItemListKind, PathCompletionCtx, PathExprCtx, Qualified}, }; pub(crate) mod trait_impl; diff --git a/crates/ide-completion/src/completions/item_list/trait_impl.rs b/crates/ide-completion/src/completions/item_list/trait_impl.rs index 831f5665f4..e08271f39a 100644 --- a/crates/ide-completion/src/completions/item_list/trait_impl.rs +++ b/crates/ide-completion/src/completions/item_list/trait_impl.rs @@ -31,20 +31,21 @@ //! } //! ``` -use hir::{db::ExpandDatabase, MacroFileId, Name}; +use hir::{MacroFileId, Name, db::ExpandDatabase}; use ide_db::text_edit::TextEdit; use ide_db::{ - documentation::HasDocs, path_transform::PathTransform, - syntax_helpers::prettify_macro_expansion, traits::get_missing_assoc_items, SymbolKind, + SymbolKind, documentation::HasDocs, path_transform::PathTransform, + syntax_helpers::prettify_macro_expansion, traits::get_missing_assoc_items, }; use syntax::{ - ast::{self, edit_in_place::AttrsOwnerEdit, make, HasGenericArgs, HasTypeBounds}, - format_smolstr, ted, AstNode, SmolStr, SyntaxElement, SyntaxKind, TextRange, ToSmolStr, T, + AstNode, SmolStr, SyntaxElement, SyntaxKind, T, TextRange, ToSmolStr, + ast::{self, HasGenericArgs, HasTypeBounds, edit_in_place::AttrsOwnerEdit, make}, + format_smolstr, ted, }; use crate::{ - context::PathCompletionCtx, CompletionContext, CompletionItem, CompletionItemKind, - CompletionRelevance, Completions, + CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance, Completions, + context::PathCompletionCtx, }; #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/crates/ide-completion/src/completions/lifetime.rs b/crates/ide-completion/src/completions/lifetime.rs index 53a62fe49c..9bb2bea74b 100644 --- a/crates/ide-completion/src/completions/lifetime.rs +++ b/crates/ide-completion/src/completions/lifetime.rs @@ -7,7 +7,7 @@ //! there is no value in lifting these out into the outline module test since they will either not //! show up for normal completions, or they won't show completions other than lifetimes depending //! on the fixture input. -use hir::{sym, Name, ScopeDef}; +use hir::{Name, ScopeDef, sym}; use crate::{ completions::Completions, diff --git a/crates/ide-completion/src/completions/mod_.rs b/crates/ide-completion/src/completions/mod_.rs index fad7c92d8a..dc81e49c53 100644 --- a/crates/ide-completion/src/completions/mod_.rs +++ b/crates/ide-completion/src/completions/mod_.rs @@ -4,12 +4,12 @@ use std::iter; use hir::{HirFileIdExt, Module}; use ide_db::{ - base_db::{SourceDatabase, VfsPath}, FxHashSet, RootDatabase, SymbolKind, + base_db::{SourceDatabase, VfsPath}, }; -use syntax::{ast, AstNode, SyntaxKind}; +use syntax::{AstNode, SyntaxKind, ast}; -use crate::{context::CompletionContext, CompletionItem, Completions}; +use crate::{CompletionItem, Completions, context::CompletionContext}; /// Complete mod declaration, i.e. `mod $0;` pub(crate) fn complete_mod( diff --git a/crates/ide-completion/src/completions/pattern.rs b/crates/ide-completion/src/completions/pattern.rs index 9df13c5a4e..59ef94d83b 100644 --- a/crates/ide-completion/src/completions/pattern.rs +++ b/crates/ide-completion/src/completions/pattern.rs @@ -5,8 +5,8 @@ use ide_db::syntax_helpers::suggest_name; use syntax::ast::Pat; use crate::{ - context::{PathCompletionCtx, PatternContext, PatternRefutability, Qualified}, CompletionContext, Completions, + context::{PathCompletionCtx, PatternContext, PatternRefutability, Qualified}, }; /// Completes constants and paths in unqualified patterns. diff --git a/crates/ide-completion/src/completions/postfix.rs b/crates/ide-completion/src/completions/postfix.rs index 611f8a2873..eb84debcaf 100644 --- a/crates/ide-completion/src/completions/postfix.rs +++ b/crates/ide-completion/src/completions/postfix.rs @@ -5,24 +5,24 @@ mod format_like; use base_db::SourceDatabase; use hir::{ItemInNs, Semantics}; use ide_db::{ + RootDatabase, SnippetCap, documentation::{Documentation, HasDocs}, imports::insert_use::ImportScope, text_edit::TextEdit, ty_filter::TryEnum, - RootDatabase, SnippetCap, }; use stdx::never; use syntax::{ - ast::{self, AstNode, AstToken}, SyntaxKind::{BLOCK_EXPR, EXPR_STMT, FOR_EXPR, IF_EXPR, LOOP_EXPR, STMT_LIST, WHILE_EXPR}, TextRange, TextSize, + ast::{self, AstNode, AstToken}, }; use crate::{ + CompletionItem, CompletionItemKind, CompletionRelevance, Completions, SnippetScope, completions::postfix::format_like::add_format_like_completions, context::{BreakableKind, CompletionContext, DotAccess, DotAccessKind}, item::{Builder, CompletionRelevancePostfixMatch}, - CompletionItem, CompletionItemKind, CompletionRelevance, Completions, SnippetScope, }; pub(crate) fn complete_postfix( @@ -414,8 +414,8 @@ mod tests { use expect_test::expect; use crate::{ - tests::{check, check_edit, check_edit_with_config, TEST_CONFIG}, CompletionConfig, Snippet, + tests::{TEST_CONFIG, check, check_edit, check_edit_with_config}, }; #[test] @@ -697,15 +697,17 @@ fn main() { #[test] fn custom_postfix_completion() { let config = CompletionConfig { - snippets: vec![Snippet::new( - &[], - &["break".into()], - &["ControlFlow::Break(${receiver})".into()], - "", - &["core::ops::ControlFlow".into()], - crate::SnippetScope::Expr, - ) - .unwrap()], + snippets: vec![ + Snippet::new( + &[], + &["break".into()], + &["ControlFlow::Break(${receiver})".into()], + "", + &["core::ops::ControlFlow".into()], + crate::SnippetScope::Expr, + ) + .unwrap(), + ], ..TEST_CONFIG }; diff --git a/crates/ide-completion/src/completions/postfix/format_like.rs b/crates/ide-completion/src/completions/postfix/format_like.rs index c612170eb5..7faa113959 100644 --- a/crates/ide-completion/src/completions/postfix/format_like.rs +++ b/crates/ide-completion/src/completions/postfix/format_like.rs @@ -17,15 +17,15 @@ // ![Format String Completion](https://user-images.githubusercontent.com/48062697/113020656-b560f500-917a-11eb-87de-02991f61beb8.gif) use ide_db::{ - syntax_helpers::format_string_exprs::{parse_format_exprs, with_placeholders, Arg}, SnippetCap, + syntax_helpers::format_string_exprs::{Arg, parse_format_exprs, with_placeholders}, }; -use syntax::{ast, AstToken}; +use syntax::{AstToken, ast}; use crate::{ + Completions, completions::postfix::{build_postfix_snippet_builder, escape_snippet_bits}, context::CompletionContext, - Completions, }; /// Mapping ("postfix completion item" => "macro to use") diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs index d0c4c24d06..c18aab007b 100644 --- a/crates/ide-completion/src/completions/record.rs +++ b/crates/ide-completion/src/completions/record.rs @@ -1,14 +1,14 @@ //! Complete fields in record literals and patterns. use ide_db::SymbolKind; use syntax::{ - ast::{self, Expr}, SmolStr, + ast::{self, Expr}, }; use crate::{ - context::{DotAccess, DotAccessExprCtx, DotAccessKind, PatternContext}, CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch, Completions, + context::{DotAccess, DotAccessExprCtx, DotAccessKind, PatternContext}, }; pub(crate) fn complete_record_pattern_fields( @@ -144,8 +144,8 @@ mod tests { use ide_db::SnippetCap; use crate::{ - tests::{check_edit, check_edit_with_config, TEST_CONFIG}, CompletionConfig, + tests::{TEST_CONFIG, check_edit, check_edit_with_config}, }; #[test] diff --git a/crates/ide-completion/src/completions/snippet.rs b/crates/ide-completion/src/completions/snippet.rs index 357709e0c1..31aae11676 100644 --- a/crates/ide-completion/src/completions/snippet.rs +++ b/crates/ide-completion/src/completions/snippet.rs @@ -1,11 +1,11 @@ //! This file provides snippet completions, like `pd` => `eprintln!(...)`. -use ide_db::{documentation::Documentation, imports::insert_use::ImportScope, SnippetCap}; +use ide_db::{SnippetCap, documentation::Documentation, imports::insert_use::ImportScope}; use crate::{ + CompletionContext, CompletionItem, CompletionItemKind, Completions, SnippetScope, context::{ItemListKind, PathCompletionCtx, PathExprCtx, Qualified}, item::Builder, - CompletionContext, CompletionItem, CompletionItemKind, Completions, SnippetScope, }; pub(crate) fn complete_expr_snippet( @@ -153,23 +153,25 @@ fn add_custom_completions( #[cfg(test)] mod tests { use crate::{ - tests::{check_edit_with_config, TEST_CONFIG}, CompletionConfig, Snippet, + tests::{TEST_CONFIG, check_edit_with_config}, }; #[test] fn custom_snippet_completion() { check_edit_with_config( CompletionConfig { - snippets: vec![Snippet::new( - &["break".into()], - &[], - &["ControlFlow::Break(())".into()], - "", - &["core::ops::ControlFlow".into()], - crate::SnippetScope::Expr, - ) - .unwrap()], + snippets: vec![ + Snippet::new( + &["break".into()], + &[], + &["ControlFlow::Break(())".into()], + "", + &["core::ops::ControlFlow".into()], + crate::SnippetScope::Expr, + ) + .unwrap(), + ], ..TEST_CONFIG }, "break", diff --git a/crates/ide-completion/src/completions/type.rs b/crates/ide-completion/src/completions/type.rs index b071488093..79db705af4 100644 --- a/crates/ide-completion/src/completions/type.rs +++ b/crates/ide-completion/src/completions/type.rs @@ -1,12 +1,12 @@ //! Completion of names from the current scope in type position. use hir::{HirDisplay, ScopeDef}; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; use crate::{ + CompletionContext, Completions, context::{PathCompletionCtx, Qualified, TypeAscriptionTarget, TypeLocation}, render::render_type_inference, - CompletionContext, Completions, }; pub(crate) fn complete_type_path( diff --git a/crates/ide-completion/src/completions/use_.rs b/crates/ide-completion/src/completions/use_.rs index b384987c51..4d6d0b758a 100644 --- a/crates/ide-completion/src/completions/use_.rs +++ b/crates/ide-completion/src/completions/use_.rs @@ -2,12 +2,12 @@ use hir::ScopeDef; use ide_db::{FxHashSet, SymbolKind}; -use syntax::{ast, format_smolstr, AstNode}; +use syntax::{AstNode, ast, format_smolstr}; use crate::{ + CompletionItem, CompletionItemKind, CompletionRelevance, Completions, context::{CompletionContext, PathCompletionCtx, Qualified}, item::Builder, - CompletionItem, CompletionItemKind, CompletionRelevance, Completions, }; pub(crate) fn complete_use_path( diff --git a/crates/ide-completion/src/completions/vis.rs b/crates/ide-completion/src/completions/vis.rs index 0ea5157fb4..d15c35ac84 100644 --- a/crates/ide-completion/src/completions/vis.rs +++ b/crates/ide-completion/src/completions/vis.rs @@ -1,8 +1,8 @@ //! Completion for visibility specifiers. use crate::{ - context::{CompletionContext, PathCompletionCtx, Qualified}, Completions, + context::{CompletionContext, PathCompletionCtx, Qualified}, }; pub(crate) fn complete_vis_path( diff --git a/crates/ide-completion/src/config.rs b/crates/ide-completion/src/config.rs index 45aab38e8e..844fce5ef8 100644 --- a/crates/ide-completion/src/config.rs +++ b/crates/ide-completion/src/config.rs @@ -5,9 +5,9 @@ //! completions if we are allowed to. use hir::ImportPathConfig; -use ide_db::{imports::insert_use::InsertUseConfig, SnippetCap}; +use ide_db::{SnippetCap, imports::insert_use::InsertUseConfig}; -use crate::{snippet::Snippet, CompletionFieldsToResolve}; +use crate::{CompletionFieldsToResolve, snippet::Snippet}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct CompletionConfig<'a> { diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs index 54620bbad1..aa0b6060f6 100644 --- a/crates/ide-completion/src/context.rs +++ b/crates/ide-completion/src/context.rs @@ -6,26 +6,27 @@ mod tests; use std::{iter, ops::ControlFlow}; -use base_db::{salsa::AsDynDatabase, RootQueryDb as _}; +use base_db::{RootQueryDb as _, salsa::AsDynDatabase}; use hir::{ DisplayTarget, HasAttrs, Local, ModPath, ModuleDef, ModuleSource, Name, PathResolution, ScopeDef, Semantics, SemanticsScope, Symbol, Type, TypeInfo, }; use ide_db::{ - famous_defs::FamousDefs, helpers::is_editable_crate, FilePosition, FxHashMap, FxHashSet, - RootDatabase, + FilePosition, FxHashMap, FxHashSet, RootDatabase, famous_defs::FamousDefs, + helpers::is_editable_crate, }; use syntax::{ - ast::{self, AttrKind, NameOrNameRef}, - match_ast, AstNode, Edition, SmolStr, + AstNode, Edition, SmolStr, SyntaxKind::{self, *}, - SyntaxToken, TextRange, TextSize, T, + SyntaxToken, T, TextRange, TextSize, + ast::{self, AttrKind, NameOrNameRef}, + match_ast, }; use crate::{ - config::AutoImportExclusionType, - context::analysis::{expand_and_analyze, AnalysisResult}, CompletionConfig, + config::AutoImportExclusionType, + context::analysis::{AnalysisResult, expand_and_analyze}, }; const COMPLETION_MARKER: &str = "raCompletionMarker"; @@ -676,11 +677,7 @@ impl CompletionContext<'_> { }; } - if self.is_doc_hidden(attrs, defining_crate) { - Visible::No - } else { - Visible::Yes - } + if self.is_doc_hidden(attrs, defining_crate) { Visible::No } else { Visible::Yes } } pub(crate) fn is_doc_hidden(&self, attrs: &hir::Attrs, defining_crate: hir::Crate) -> bool { diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs index 1a34548f70..8f58c2181e 100644 --- a/crates/ide-completion/src/context/analysis.rs +++ b/crates/ide-completion/src/context/analysis.rs @@ -2,24 +2,25 @@ use std::iter; use hir::{ExpandResult, Semantics, Type, TypeInfo, Variant}; -use ide_db::{active_parameter::ActiveParameter, RootDatabase}; +use ide_db::{RootDatabase, active_parameter::ActiveParameter}; use itertools::Either; use syntax::{ + AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, + T, TextRange, TextSize, algo::{self, ancestors_at_offset, find_node_at_offset, non_trivia_sibling}, ast::{ self, AttrKind, HasArgList, HasGenericArgs, HasGenericParams, HasLoopBody, HasName, NameOrNameRef, }, - match_ast, AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, - SyntaxToken, TextRange, TextSize, T, + match_ast, }; use crate::context::{ - AttrCtx, BreakableKind, CompletionAnalysis, DotAccess, DotAccessExprCtx, DotAccessKind, - ItemListKind, LifetimeContext, LifetimeKind, NameContext, NameKind, NameRefContext, - NameRefKind, ParamContext, ParamKind, PathCompletionCtx, PathExprCtx, PathKind, PatternContext, - PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget, TypeLocation, - COMPLETION_MARKER, + AttrCtx, BreakableKind, COMPLETION_MARKER, CompletionAnalysis, DotAccess, DotAccessExprCtx, + DotAccessKind, ItemListKind, LifetimeContext, LifetimeKind, NameContext, NameKind, + NameRefContext, NameRefKind, ParamContext, ParamKind, PathCompletionCtx, PathExprCtx, PathKind, + PatternContext, PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget, + TypeLocation, }; #[derive(Debug)] diff --git a/crates/ide-completion/src/context/tests.rs b/crates/ide-completion/src/context/tests.rs index a03f632cdf..72bcbf366d 100644 --- a/crates/ide-completion/src/context/tests.rs +++ b/crates/ide-completion/src/context/tests.rs @@ -1,9 +1,9 @@ -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use hir::HirDisplay; use crate::{ context::CompletionContext, - tests::{position, TEST_CONFIG}, + tests::{TEST_CONFIG, position}, }; fn check_expected_type_and_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { diff --git a/crates/ide-completion/src/item.rs b/crates/ide-completion/src/item.rs index 8d6dc4c801..e208b9fd41 100644 --- a/crates/ide-completion/src/item.rs +++ b/crates/ide-completion/src/item.rs @@ -5,17 +5,17 @@ use std::{fmt, mem}; use hir::Mutability; use ide_db::text_edit::TextEdit; use ide_db::{ - documentation::Documentation, imports::import_assets::LocatedImport, RootDatabase, SnippetCap, - SymbolKind, + RootDatabase, SnippetCap, SymbolKind, documentation::Documentation, + imports::import_assets::LocatedImport, }; use itertools::Itertools; use smallvec::SmallVec; use stdx::{format_to, impl_from, never}; -use syntax::{format_smolstr, Edition, SmolStr, TextRange, TextSize}; +use syntax::{Edition, SmolStr, TextRange, TextSize, format_smolstr}; use crate::{ context::{CompletionContext, PathCompletionCtx}, - render::{render_path_resolution, RenderContext}, + render::{RenderContext, render_path_resolution}, }; /// `CompletionItem` describes a single completion entity which expands to 1 or more entries in the diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs index c9fc5ae152..8d8dfb083e 100644 --- a/crates/ide-completion/src/lib.rs +++ b/crates/ide-completion/src/lib.rs @@ -11,11 +11,11 @@ mod snippet; mod tests; use ide_db::{ + FilePosition, FxHashSet, RootDatabase, base_db::salsa::AsDynDatabase, imports::insert_use::{self, ImportScope}, syntax_helpers::tree_diff::diff, text_edit::TextEdit, - FilePosition, FxHashSet, RootDatabase, }; use syntax::ast::make; diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 0f0fa115af..54094a8f8e 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -10,17 +10,19 @@ pub(crate) mod type_alias; pub(crate) mod union_literal; pub(crate) mod variant; -use hir::{sym, AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type}; +use hir::{AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type, sym}; use ide_db::text_edit::TextEdit; use ide_db::{ + RootDatabase, SnippetCap, SymbolKind, documentation::{Documentation, HasDocs}, helpers::item_name, imports::import_assets::LocatedImport, - RootDatabase, SnippetCap, SymbolKind, }; -use syntax::{ast, format_smolstr, AstNode, SmolStr, SyntaxKind, TextRange, ToSmolStr}; +use syntax::{AstNode, SmolStr, SyntaxKind, TextRange, ToSmolStr, ast, format_smolstr}; use crate::{ + CompletionContext, CompletionItem, CompletionItemKind, CompletionItemRefMode, + CompletionRelevance, context::{DotAccess, DotAccessKind, PathCompletionCtx, PathKind, PatternContext}, item::{Builder, CompletionRelevanceTypeMatch}, render::{ @@ -28,8 +30,6 @@ use crate::{ literal::render_variant_lit, macro_::{render_macro, render_macro_pat}, }, - CompletionContext, CompletionItem, CompletionItemKind, CompletionItemRefMode, - CompletionRelevance, }; /// Interface for data and methods required for items rendering. #[derive(Debug, Clone)] @@ -683,14 +683,14 @@ fn path_ref_match( mod tests { use std::cmp; - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::SymbolKind; use itertools::Itertools; use crate::{ - item::CompletionRelevanceTypeMatch, - tests::{check_edit, do_completion, get_all_items, TEST_CONFIG}, CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch, + item::CompletionRelevanceTypeMatch, + tests::{TEST_CONFIG, check_edit, do_completion, get_all_items}, }; #[track_caller] diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs index 4693bdc047..dd0f24522f 100644 --- a/crates/ide-completion/src/render/function.rs +++ b/crates/ide-completion/src/render/function.rs @@ -1,12 +1,13 @@ //! Renderer for function calls. -use hir::{db::HirDatabase, AsAssocItem, HirDisplay}; +use hir::{AsAssocItem, HirDisplay, db::HirDatabase}; use ide_db::{SnippetCap, SymbolKind}; use itertools::Itertools; use stdx::{format_to, to_lower_snake_case}; -use syntax::{format_smolstr, AstNode, SmolStr, ToSmolStr}; +use syntax::{AstNode, SmolStr, ToSmolStr, format_smolstr}; use crate::{ + CallableSnippets, context::{ CompleteSemicolon, CompletionContext, DotAccess, DotAccessKind, PathCompletionCtx, PathKind, }, @@ -15,9 +16,8 @@ use crate::{ CompletionRelevanceReturnType, CompletionRelevanceTraitInfo, }, render::{ - compute_exact_name_match, compute_ref_match, compute_type_match, match_types, RenderContext, + RenderContext, compute_exact_name_match, compute_ref_match, compute_type_match, match_types, }, - CallableSnippets, }; #[derive(Debug)] @@ -293,11 +293,7 @@ fn ref_of_param(ctx: &CompletionContext<'_>, arg: &str, ty: &hir::Type) -> &'sta for (name, local) in ctx.locals.iter().sorted_by_key(|&(k, _)| k.clone()) { if name.as_str() == arg { return if local.ty(ctx.db) == derefed_ty { - if ty.is_mutable_reference() { - "&mut " - } else { - "&" - } + if ty.is_mutable_reference() { "&mut " } else { "&" } } else { "" }; @@ -398,8 +394,8 @@ fn params( #[cfg(test)] mod tests { use crate::{ - tests::{check_edit, check_edit_with_config, TEST_CONFIG}, CallableSnippets, CompletionConfig, + tests::{TEST_CONFIG, check_edit, check_edit_with_config}, }; #[test] diff --git a/crates/ide-completion/src/render/literal.rs b/crates/ide-completion/src/render/literal.rs index ffda52fb47..5a9e35a729 100644 --- a/crates/ide-completion/src/render/literal.rs +++ b/crates/ide-completion/src/render/literal.rs @@ -1,23 +1,22 @@ //! Renderer for `enum` variants. -use hir::{db::HirDatabase, StructKind}; +use hir::{StructKind, db::HirDatabase}; use ide_db::{ - documentation::{Documentation, HasDocs}, SymbolKind, + documentation::{Documentation, HasDocs}, }; use crate::{ + CompletionItemKind, CompletionRelevance, CompletionRelevanceReturnType, context::{CompletionContext, PathCompletionCtx, PathKind}, item::{Builder, CompletionItem, CompletionRelevanceFn}, render::{ - compute_type_match, + RenderContext, compute_type_match, variant::{ - format_literal_label, format_literal_lookup, render_record_lit, render_tuple_lit, - visible_fields, RenderedLiteral, + RenderedLiteral, format_literal_label, format_literal_lookup, render_record_lit, + render_tuple_lit, visible_fields, }, - RenderContext, }, - CompletionItemKind, CompletionRelevance, CompletionRelevanceReturnType, }; pub(crate) fn render_variant_lit( @@ -164,11 +163,7 @@ impl Variant { Variant::Struct(it) => visible_fields(ctx, &fields, it)?, Variant::EnumVariant(it) => visible_fields(ctx, &fields, it)?, }; - if !fields_omitted { - Some(visible_fields) - } else { - None - } + if !fields_omitted { Some(visible_fields) } else { None } } fn kind(self, db: &dyn HirDatabase) -> StructKind { diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs index 8b2476d153..4674dae031 100644 --- a/crates/ide-completion/src/render/macro_.rs +++ b/crates/ide-completion/src/render/macro_.rs @@ -1,8 +1,8 @@ //! Renderer for macro invocations. use hir::HirDisplay; -use ide_db::{documentation::Documentation, SymbolKind}; -use syntax::{format_smolstr, SmolStr, ToSmolStr}; +use ide_db::{SymbolKind, documentation::Documentation}; +use syntax::{SmolStr, ToSmolStr, format_smolstr}; use crate::{ context::{PathCompletionCtx, PathKind, PatternContext}, diff --git a/crates/ide-completion/src/render/pattern.rs b/crates/ide-completion/src/render/pattern.rs index 124abb17b6..93e6c52379 100644 --- a/crates/ide-completion/src/render/pattern.rs +++ b/crates/ide-completion/src/render/pattern.rs @@ -1,17 +1,17 @@ //! Renderer for patterns. -use hir::{db::HirDatabase, Name, StructKind}; -use ide_db::{documentation::HasDocs, SnippetCap}; +use hir::{Name, StructKind, db::HirDatabase}; +use ide_db::{SnippetCap, documentation::HasDocs}; use itertools::Itertools; use syntax::{Edition, SmolStr, ToSmolStr}; use crate::{ + CompletionItem, CompletionItemKind, context::{ParamContext, ParamKind, PathCompletionCtx, PatternContext}, render::{ - variant::{format_literal_label, format_literal_lookup, visible_fields}, RenderContext, + variant::{format_literal_label, format_literal_lookup, visible_fields}, }, - CompletionItem, CompletionItemKind, }; pub(crate) fn render_struct_pat( diff --git a/crates/ide-completion/src/render/union_literal.rs b/crates/ide-completion/src/render/union_literal.rs index 09154e81c0..23f0d4e06f 100644 --- a/crates/ide-completion/src/render/union_literal.rs +++ b/crates/ide-completion/src/render/union_literal.rs @@ -6,11 +6,11 @@ use itertools::Itertools; use syntax::ToSmolStr; use crate::{ - render::{ - variant::{format_literal_label, format_literal_lookup, visible_fields}, - RenderContext, - }, CompletionItem, CompletionItemKind, + render::{ + RenderContext, + variant::{format_literal_label, format_literal_lookup, visible_fields}, + }, }; pub(crate) fn render_union_literal( diff --git a/crates/ide-completion/src/render/variant.rs b/crates/ide-completion/src/render/variant.rs index 83718e5722..5d7d68bb3d 100644 --- a/crates/ide-completion/src/render/variant.rs +++ b/crates/ide-completion/src/render/variant.rs @@ -1,7 +1,7 @@ //! Code common to structs, unions, and enum variants. use crate::context::CompletionContext; -use hir::{sym, HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind}; +use hir::{HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind, sym}; use ide_db::SnippetCap; use itertools::Itertools; use syntax::SmolStr; diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index 2984348a32..85987f0de5 100644 --- a/crates/ide-completion/src/tests.rs +++ b/crates/ide-completion/src/tests.rs @@ -28,8 +28,8 @@ use base_db::SourceDatabase; use expect_test::Expect; use hir::PrefixKind; use ide_db::{ - imports::insert_use::{ImportGranularity, InsertUseConfig}, FilePosition, RootDatabase, SnippetCap, + imports::insert_use::{ImportGranularity, InsertUseConfig}, }; use itertools::Itertools; use stdx::{format_to, trim_indent}; @@ -37,8 +37,8 @@ use test_fixture::ChangeFixture; use test_utils::assert_eq_text; use crate::{ - resolve_completion_edits, CallableSnippets, CompletionConfig, CompletionFieldsToResolve, - CompletionItem, CompletionItemKind, + CallableSnippets, CompletionConfig, CompletionFieldsToResolve, CompletionItem, + CompletionItemKind, resolve_completion_edits, }; /// Lots of basic item definitions diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index 9b3c676c48..61823811dc 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -1,13 +1,13 @@ //! Completion tests for expressions. -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use crate::{ + CompletionConfig, config::AutoImportExclusionType, tests::{ - check, check_edit, check_with_base_items, completion_list_with_config, BASE_ITEMS_FIXTURE, - TEST_CONFIG, + BASE_ITEMS_FIXTURE, TEST_CONFIG, check, check_edit, check_with_base_items, + completion_list_with_config, }, - CompletionConfig, }; fn check_with_config( diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs index 2e7c53def7..8bba44c12b 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -1,9 +1,9 @@ -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use crate::{ - context::{CompletionAnalysis, NameContext, NameKind, NameRefKind}, - tests::{check_edit, check_edit_with_config, TEST_CONFIG}, CompletionConfig, + context::{CompletionAnalysis, NameContext, NameKind, NameRefKind}, + tests::{TEST_CONFIG, check_edit, check_edit_with_config}, }; fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { diff --git a/crates/ide-completion/src/tests/raw_identifiers.rs b/crates/ide-completion/src/tests/raw_identifiers.rs index 823cc8c3d8..00977ea4e5 100644 --- a/crates/ide-completion/src/tests/raw_identifiers.rs +++ b/crates/ide-completion/src/tests/raw_identifiers.rs @@ -1,8 +1,8 @@ use base_db::SourceDatabase; -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use itertools::Itertools; -use crate::tests::{completion_list_with_config_raw, position, TEST_CONFIG}; +use crate::tests::{TEST_CONFIG, completion_list_with_config_raw, position}; fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { let completions = completion_list_with_config_raw(TEST_CONFIG, ra_fixture, true, None); diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs index 005263d100..355f04bf0a 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -1,14 +1,14 @@ //! Tests that don't fit into a specific category. -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use ide_db::SymbolKind; use crate::{ - tests::{ - check, check_edit, check_no_kw, check_with_trigger_character, do_completion_with_config, - TEST_CONFIG, - }, CompletionItemKind, + tests::{ + TEST_CONFIG, check, check_edit, check_no_kw, check_with_trigger_character, + do_completion_with_config, + }, }; #[test] diff --git a/crates/ide-db/src/active_parameter.rs b/crates/ide-db/src/active_parameter.rs index 11808fed3b..06ed4afdf9 100644 --- a/crates/ide-db/src/active_parameter.rs +++ b/crates/ide-db/src/active_parameter.rs @@ -4,8 +4,9 @@ use either::Either; use hir::{InFile, Semantics, Type}; use parser::T; use syntax::{ + AstNode, NodeOrToken, SyntaxToken, ast::{self, AstChildren, HasArgList, HasAttrs, HasName}, - match_ast, AstNode, NodeOrToken, SyntaxToken, + match_ast, }; use crate::RootDatabase; diff --git a/crates/ide-db/src/apply_change.rs b/crates/ide-db/src/apply_change.rs index 4e058bb010..36745b012b 100644 --- a/crates/ide-db/src/apply_change.rs +++ b/crates/ide-db/src/apply_change.rs @@ -6,7 +6,7 @@ use rustc_hash::FxHashSet; use salsa::{Database as _, Durability}; use triomphe::Arc; -use crate::{symbol_index::SymbolsDatabase, ChangeWithProcMacros, RootDatabase}; +use crate::{ChangeWithProcMacros, RootDatabase, symbol_index::SymbolsDatabase}; impl RootDatabase { pub fn request_cancellation(&mut self) { diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 502314ed1e..18126f616c 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -5,9 +5,9 @@ // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). +use crate::RootDatabase; use crate::documentation::{Documentation, HasDocs}; use crate::famous_defs::FamousDefs; -use crate::RootDatabase; use arrayvec::ArrayVec; use either::Either; use hir::{ @@ -21,8 +21,9 @@ use hir::{ use span::Edition; use stdx::{format_to, impl_from}; use syntax::{ + SyntaxKind, SyntaxNode, SyntaxToken, ast::{self, AstNode}, - match_ast, SyntaxKind, SyntaxNode, SyntaxToken, + match_ast, }; // FIXME: a more precise name would probably be `Symbol`? diff --git a/crates/ide-db/src/documentation.rs b/crates/ide-db/src/documentation.rs index b83efcd02f..96654a2416 100644 --- a/crates/ide-db/src/documentation.rs +++ b/crates/ide-db/src/documentation.rs @@ -1,14 +1,15 @@ //! Documentation attribute related utilities. use either::Either; use hir::{ + AttrId, AttrSourceMap, AttrsWithOwner, HasAttrs, InFile, db::{DefDatabase, HirDatabase}, - resolve_doc_path_on, sym, AttrId, AttrSourceMap, AttrsWithOwner, HasAttrs, InFile, + resolve_doc_path_on, sym, }; use itertools::Itertools; use span::{TextRange, TextSize}; use syntax::{ - ast::{self, IsString}, AstToken, + ast::{self, IsString}, }; /// Holds documentation @@ -151,11 +152,7 @@ pub fn docs_from_attrs(attrs: &hir::Attrs) -> Option { buf.push('\n'); } buf.pop(); - if buf.is_empty() { - None - } else { - Some(buf) - } + if buf.is_empty() { None } else { Some(buf) } } macro_rules! impl_has_docs { diff --git a/crates/ide-db/src/famous_defs.rs b/crates/ide-db/src/famous_defs.rs index fe4662785a..994150b1ac 100644 --- a/crates/ide-db/src/famous_defs.rs +++ b/crates/ide-db/src/famous_defs.rs @@ -220,11 +220,7 @@ impl FamousDefs<'_, '_> { for segment in path { module = module.children(db).find_map(|child| { let name = child.name(db)?; - if name.as_str() == segment { - Some(child) - } else { - None - } + if name.as_str() == segment { Some(child) } else { None } })?; } let def = diff --git a/crates/ide-db/src/helpers.rs b/crates/ide-db/src/helpers.rs index ebafc8876f..340429037e 100644 --- a/crates/ide-db/src/helpers.rs +++ b/crates/ide-db/src/helpers.rs @@ -6,13 +6,14 @@ use base_db::SourceDatabase; use hir::{Crate, ItemInNs, ModuleDef, Name, Semantics}; use span::{Edition, FileId}; use syntax::{ - ast::{self, make}, AstToken, SyntaxKind, SyntaxToken, ToSmolStr, TokenAtOffset, + ast::{self, make}, }; use crate::{ + RootDatabase, defs::{Definition, IdentClass}, - generated, RootDatabase, + generated, }; pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option { diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs index 77fc59b4ec..0fc287c57e 100644 --- a/crates/ide-db/src/imports/import_assets.rs +++ b/crates/ide-db/src/imports/import_assets.rs @@ -3,20 +3,20 @@ use std::ops::ControlFlow; use hir::{ - db::HirDatabase, AsAssocItem, AssocItem, AssocItemContainer, Crate, HasCrate, ImportPathConfig, - ItemInNs, ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics, - SemanticsScope, Trait, TyFingerprint, Type, + AsAssocItem, AssocItem, AssocItemContainer, Crate, HasCrate, ImportPathConfig, ItemInNs, + ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics, + SemanticsScope, Trait, TyFingerprint, Type, db::HirDatabase, }; use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ - ast::{self, make, HasName}, AstNode, SyntaxNode, + ast::{self, HasName, make}, }; use crate::{ - items_locator::{self, AssocSearchMode, DEFAULT_QUERY_SEARCH_LIMIT}, FxIndexSet, RootDatabase, + items_locator::{self, AssocSearchMode, DEFAULT_QUERY_SEARCH_LIMIT}, }; /// A candidate for import, derived during various IDE activities: @@ -433,7 +433,7 @@ fn validate_resolvable( false => ControlFlow::Continue(()), }, ) - .map(|item| LocatedImport::new(import_path_candidate, resolved_qualifier, item)) + .map(|item| LocatedImport::new(import_path_candidate, resolved_qualifier, item)); } // FIXME ModuleDef::Trait(_) => return None, diff --git a/crates/ide-db/src/imports/insert_use.rs b/crates/ide-db/src/imports/insert_use.rs index 8e25ad3472..d26e5d62ce 100644 --- a/crates/ide-db/src/imports/insert_use.rs +++ b/crates/ide-db/src/imports/insert_use.rs @@ -6,20 +6,20 @@ use std::cmp::Ordering; use hir::Semantics; use syntax::{ - algo, + Direction, NodeOrToken, SyntaxKind, SyntaxNode, algo, ast::{ - self, edit_in_place::Removable, make, AstNode, HasAttrs, HasModuleItem, HasVisibility, - PathSegmentKind, + self, AstNode, HasAttrs, HasModuleItem, HasVisibility, PathSegmentKind, + edit_in_place::Removable, make, }, - ted, Direction, NodeOrToken, SyntaxKind, SyntaxNode, + ted, }; use crate::{ - imports::merge_imports::{ - common_prefix, eq_attrs, eq_visibility, try_merge_imports, use_tree_cmp, MergeBehavior, - NormalizationStyle, - }, RootDatabase, + imports::merge_imports::{ + MergeBehavior, NormalizationStyle, common_prefix, eq_attrs, eq_visibility, + try_merge_imports, use_tree_cmp, + }, }; pub use hir::PrefixKind; diff --git a/crates/ide-db/src/imports/insert_use/tests.rs b/crates/ide-db/src/imports/insert_use/tests.rs index 39810c615b..541f6c379e 100644 --- a/crates/ide-db/src/imports/insert_use/tests.rs +++ b/crates/ide-db/src/imports/insert_use/tests.rs @@ -1,7 +1,7 @@ use salsa::AsDynDatabase; use stdx::trim_indent; use test_fixture::WithFixture; -use test_utils::{assert_eq_text, CURSOR_MARKER}; +use test_utils::{CURSOR_MARKER, assert_eq_text}; use super::*; diff --git a/crates/ide-db/src/imports/merge_imports.rs b/crates/ide-db/src/imports/merge_imports.rs index 9e89dfe87a..61962e5934 100644 --- a/crates/ide-db/src/imports/merge_imports.rs +++ b/crates/ide-db/src/imports/merge_imports.rs @@ -5,13 +5,12 @@ use itertools::{EitherOrBoth, Itertools}; use parser::T; use stdx::is_upper_snake_case; use syntax::{ - algo, + Direction, SyntaxElement, algo, ast::{ - self, edit_in_place::Removable, make, AstNode, HasAttrs, HasName, HasVisibility, - PathSegmentKind, + self, AstNode, HasAttrs, HasName, HasVisibility, PathSegmentKind, edit_in_place::Removable, + make, }, ted::{self, Position}, - Direction, SyntaxElement, }; use crate::syntax_helpers::node_ext::vis_eq; @@ -191,7 +190,7 @@ fn recursive_merge(lhs: &ast::UseTree, rhs: &ast::UseTree, merge: MergeBehavior) && !use_trees.is_empty() && rhs_t.use_tree_list().is_some() => { - return None + return None; } Err(insert_idx) => { use_trees.insert(insert_idx, rhs_t.clone()); diff --git a/crates/ide-db/src/items_locator.rs b/crates/ide-db/src/items_locator.rs index 4d9c051354..8088182980 100644 --- a/crates/ide-db/src/items_locator.rs +++ b/crates/ide-db/src/items_locator.rs @@ -5,12 +5,12 @@ use std::ops::ControlFlow; use either::Either; -use hir::{import_map, Crate, ItemInNs, Module, Semantics}; +use hir::{Crate, ItemInNs, Module, Semantics, import_map}; use crate::{ + RootDatabase, imports::import_assets::NameToImport, symbol_index::{self, SymbolsDatabase as _}, - RootDatabase, }; /// A value to use, when uncertain which limit to pick. diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 414cc6cd18..c6bd803128 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -51,12 +51,12 @@ use salsa::Durability; use std::{fmt, mem::ManuallyDrop}; use base_db::{ - query_group, CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, RootQueryDb, - SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast, + CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, RootQueryDb, + SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast, query_group, }; use hir::{ - db::{DefDatabase, ExpandDatabase, HirDatabase}, FilePositionWrapper, FileRangeWrapper, + db::{DefDatabase, ExpandDatabase, HirDatabase}, }; use triomphe::Arc; @@ -360,11 +360,7 @@ pub struct SnippetCap { impl SnippetCap { pub const fn new(allow_snippets: bool) -> Option { - if allow_snippets { - Some(SnippetCap { _private: () }) - } else { - None - } + if allow_snippets { Some(SnippetCap { _private: () }) } else { None } } } diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs index a348a4ef7d..5aef2a6e02 100644 --- a/crates/ide-db/src/path_transform.rs +++ b/crates/ide-db/src/path_transform.rs @@ -7,8 +7,9 @@ use itertools::Itertools; use rustc_hash::FxHashMap; use span::Edition; use syntax::{ - ast::{self, make, AstNode, HasGenericArgs}, - ted, NodeOrToken, SyntaxNode, + NodeOrToken, SyntaxNode, + ast::{self, AstNode, HasGenericArgs, make}, + ted, }; #[derive(Default)] diff --git a/crates/ide-db/src/prime_caches.rs b/crates/ide-db/src/prime_caches.rs index cd3099fe93..17c3f75ce1 100644 --- a/crates/ide-db/src/prime_caches.rs +++ b/crates/ide-db/src/prime_caches.rs @@ -6,14 +6,14 @@ mod topologic_sort; use std::time::Duration; -use hir::{db::DefDatabase, Symbol}; +use hir::{Symbol, db::DefDatabase}; use itertools::Itertools; use salsa::{Cancelled, Database}; use crate::{ + FxIndexMap, RootDatabase, base_db::{Crate, RootQueryDb}, symbol_index::SymbolsDatabase, - FxIndexMap, RootDatabase, }; /// We're indexing many crates. diff --git a/crates/ide-db/src/rename.rs b/crates/ide-db/src/rename.rs index 902ead977e..4a5a28e824 100644 --- a/crates/ide-db/src/rename.rs +++ b/crates/ide-db/src/rename.rs @@ -30,20 +30,20 @@ use base_db::AnchoredPathBuf; use either::Either; use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics}; use span::{Edition, EditionedFileId, FileId, SyntaxContext}; -use stdx::{never, TupleExt}; +use stdx::{TupleExt, never}; use syntax::{ + AstNode, SyntaxKind, T, TextRange, ast::{self, HasName}, utils::is_raw_identifier, - AstNode, SyntaxKind, TextRange, T, }; use crate::{ + RootDatabase, defs::Definition, search::{FileReference, FileReferenceNode}, source_change::{FileSystemEdit, SourceChange}, syntax_helpers::node_ext::expr_as_name_ref, traits::convert_to_def_in_trait, - RootDatabase, }; pub type Result = std::result::Result; diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs index 4f9ef05b20..bb4bee91bb 100644 --- a/crates/ide-db/src/search.rs +++ b/crates/ide-db/src/search.rs @@ -10,9 +10,9 @@ use std::{cell::LazyCell, cmp::Reverse}; use base_db::{RootQueryDb, SourceDatabase}; use either::Either; use hir::{ - sym, Adt, AsAssocItem, DefWithBody, FileRange, FileRangeWrapper, HasAttrs, HasContainer, - HasSource, HirFileIdExt, InFile, InFileWrapper, InRealFile, InlineAsmOperand, ItemContainer, - ModuleSource, PathResolution, Semantics, Visibility, + Adt, AsAssocItem, DefWithBody, FileRange, FileRangeWrapper, HasAttrs, HasContainer, HasSource, + HirFileIdExt, InFile, InFileWrapper, InRealFile, InlineAsmOperand, ItemContainer, ModuleSource, + PathResolution, Semantics, Visibility, sym, }; use memchr::memmem::Finder; use parser::SyntaxKind; @@ -20,16 +20,16 @@ use rustc_hash::{FxHashMap, FxHashSet}; use salsa::Database; use span::EditionedFileId; use syntax::{ + AstNode, AstToken, SmolStr, SyntaxElement, SyntaxNode, TextRange, TextSize, ToSmolStr, ast::{self, HasName, Rename}, - match_ast, AstNode, AstToken, SmolStr, SyntaxElement, SyntaxNode, TextRange, TextSize, - ToSmolStr, + match_ast, }; use triomphe::Arc; use crate::{ + RootDatabase, defs::{Definition, NameClass, NameRefClass}, traits::{as_trait_assoc_def, convert_to_def_in_trait}, - RootDatabase, }; #[derive(Debug, Default, Clone)] @@ -1292,7 +1292,7 @@ impl<'a> FindUsages<'a> { if convert_to_def_in_trait(self.sema.db, def) != convert_to_def_in_trait(self.sema.db, self.def) => { - return false + return false; } (Some(_), Definition::TypeAlias(_)) => {} // We looking at an assoc item of a trait definition, so reference all the diff --git a/crates/ide-db/src/source_change.rs b/crates/ide-db/src/source_change.rs index b4d0b0dc9f..741dc6bb3c 100644 --- a/crates/ide-db/src/source_change.rs +++ b/crates/ide-db/src/source_change.rs @@ -6,7 +6,7 @@ use std::{collections::hash_map::Entry, fmt, iter, mem}; use crate::text_edit::{TextEdit, TextEditBuilder}; -use crate::{assists::Command, syntax_helpers::tree_diff::diff, SnippetCap}; +use crate::{SnippetCap, assists::Command, syntax_helpers::tree_diff::diff}; use base_db::AnchoredPathBuf; use itertools::Itertools; use nohash_hasher::IntMap; @@ -14,8 +14,8 @@ use rustc_hash::FxHashMap; use span::FileId; use stdx::never; use syntax::{ - syntax_editor::{SyntaxAnnotation, SyntaxEditor}, AstNode, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize, + syntax_editor::{SyntaxAnnotation, SyntaxEditor}, }; /// An annotation ID associated with an indel, to describe changes. @@ -479,13 +479,14 @@ impl SourceChangeBuilder { self.commit(); // Only one file can have snippet edits - stdx::never!(self - .source_change - .source_file_edits - .iter() - .filter(|(_, (_, snippet_edit))| snippet_edit.is_some()) - .at_most_one() - .is_err()); + stdx::never!( + self.source_change + .source_file_edits + .iter() + .filter(|(_, (_, snippet_edit))| snippet_edit.is_some()) + .at_most_one() + .is_err() + ); mem::take(&mut self.source_change) } diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs index 5fea97b32d..e681a6d17c 100644 --- a/crates/ide-db/src/symbol_index.rs +++ b/crates/ide-db/src/symbol_index.rs @@ -28,12 +28,12 @@ use std::{ }; use base_db::{RootQueryDb, SourceDatabase, SourceRootId, Upcast}; -use fst::{raw::IndexedValue, Automaton, Streamer}; +use fst::{Automaton, Streamer, raw::IndexedValue}; use hir::{ + Crate, Module, db::HirDatabase, import_map::{AssocSearchMode, SearchMode}, symbols::{FileSymbol, SymbolCollector}, - Crate, Module, }; use rayon::prelude::*; use rustc_hash::FxHashSet; diff --git a/crates/ide-db/src/syntax_helpers/format_string.rs b/crates/ide-db/src/syntax_helpers/format_string.rs index 92478ef480..7e8c921d9e 100644 --- a/crates/ide-db/src/syntax_helpers/format_string.rs +++ b/crates/ide-db/src/syntax_helpers/format_string.rs @@ -1,7 +1,7 @@ //! Tools to work with format string literals for the `format_args!` family of macros. use syntax::{ - ast::{self, IsString}, AstNode, AstToken, TextRange, TextSize, + ast::{self, IsString}, }; // FIXME: This can probably be re-implemented via the HIR? diff --git a/crates/ide-db/src/syntax_helpers/format_string_exprs.rs b/crates/ide-db/src/syntax_helpers/format_string_exprs.rs index c104aa5718..8f25833fff 100644 --- a/crates/ide-db/src/syntax_helpers/format_string_exprs.rs +++ b/crates/ide-db/src/syntax_helpers/format_string_exprs.rs @@ -183,7 +183,7 @@ pub fn parse_format_exprs(input: &str) -> Result<(String, Vec), ()> { #[cfg(test)] mod tests { use super::*; - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; fn check(input: &str, expect: &Expect) { let (output, exprs) = parse_format_exprs(input).unwrap_or(("-".to_owned(), vec![])); diff --git a/crates/ide-db/src/syntax_helpers/node_ext.rs b/crates/ide-db/src/syntax_helpers/node_ext.rs index 0b2e8aa683..f0aa3daf55 100644 --- a/crates/ide-db/src/syntax_helpers/node_ext.rs +++ b/crates/ide-db/src/syntax_helpers/node_ext.rs @@ -5,8 +5,8 @@ use itertools::Itertools; use parser::T; use span::Edition; use syntax::{ - ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind}, AstNode, AstToken, Preorder, RustLanguage, WalkEvent, + ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind}, }; pub fn expr_as_name_ref(expr: &ast::Expr) -> Option { diff --git a/crates/ide-db/src/syntax_helpers/suggest_name.rs b/crates/ide-db/src/syntax_helpers/suggest_name.rs index 21dd098781..6801856e5b 100644 --- a/crates/ide-db/src/syntax_helpers/suggest_name.rs +++ b/crates/ide-db/src/syntax_helpers/suggest_name.rs @@ -7,8 +7,9 @@ use itertools::Itertools; use rustc_hash::FxHashMap; use stdx::to_lower_snake_case; use syntax::{ + AstNode, Edition, SmolStr, SmolStrBuilder, ToSmolStr, ast::{self, HasName}, - match_ast, AstNode, Edition, SmolStr, SmolStrBuilder, ToSmolStr, + match_ast, }; use crate::RootDatabase; diff --git a/crates/ide-db/src/syntax_helpers/tree_diff.rs b/crates/ide-db/src/syntax_helpers/tree_diff.rs index 02e24c4776..7163c08e1e 100644 --- a/crates/ide-db/src/syntax_helpers/tree_diff.rs +++ b/crates/ide-db/src/syntax_helpers/tree_diff.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashMap; use syntax::{NodeOrToken, SyntaxElement, SyntaxNode}; -use crate::{text_edit::TextEditBuilder, FxIndexMap}; +use crate::{FxIndexMap, text_edit::TextEditBuilder}; #[derive(Debug, Hash, PartialEq, Eq)] enum TreeDiffInsertPos { @@ -153,7 +153,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use itertools::Itertools; use parser::{Edition, SyntaxKind}; use syntax::{AstNode, SourceFile, SyntaxElement}; diff --git a/crates/ide-db/src/traits.rs b/crates/ide-db/src/traits.rs index fb231393a4..22a695c9a8 100644 --- a/crates/ide-db/src/traits.rs +++ b/crates/ide-db/src/traits.rs @@ -1,9 +1,9 @@ //! Functionality for obtaining data related to traits from the DB. -use crate::{defs::Definition, RootDatabase}; -use hir::{db::HirDatabase, AsAssocItem, Semantics}; +use crate::{RootDatabase, defs::Definition}; +use hir::{AsAssocItem, Semantics, db::HirDatabase}; use rustc_hash::FxHashSet; -use syntax::{ast, AstNode}; +use syntax::{AstNode, ast}; /// Given the `impl` block, attempts to find the trait this `impl` corresponds to. pub fn resolve_target_trait( @@ -113,7 +113,7 @@ fn assoc_item_of_trait( #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use hir::FilePosition; use hir::Semantics; use salsa::AsDynDatabase; diff --git a/crates/ide-db/src/ty_filter.rs b/crates/ide-db/src/ty_filter.rs index 2fdd835863..63ce0ddbb8 100644 --- a/crates/ide-db/src/ty_filter.rs +++ b/crates/ide-db/src/ty_filter.rs @@ -5,7 +5,7 @@ use std::iter; use hir::Semantics; -use syntax::ast::{self, make, Pat}; +use syntax::ast::{self, Pat, make}; use crate::RootDatabase; diff --git a/crates/ide-db/src/use_trivial_constructor.rs b/crates/ide-db/src/use_trivial_constructor.rs index c3f0bf3706..a4a93e36f0 100644 --- a/crates/ide-db/src/use_trivial_constructor.rs +++ b/crates/ide-db/src/use_trivial_constructor.rs @@ -3,8 +3,8 @@ use hir::StructKind; use span::Edition; use syntax::{ - ast::{make, Expr, Path}, ToSmolStr, + ast::{Expr, Path, make}, }; /// given a type return the trivial constructor (if one exists) diff --git a/crates/ide-diagnostics/src/handlers/await_outside_of_async.rs b/crates/ide-diagnostics/src/handlers/await_outside_of_async.rs index 92b6e748ca..92ca7a7418 100644 --- a/crates/ide-diagnostics/src/handlers/await_outside_of_async.rs +++ b/crates/ide-diagnostics/src/handlers/await_outside_of_async.rs @@ -1,4 +1,4 @@ -use crate::{adjusted_display_range, Diagnostic, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticsContext, adjusted_display_range}; // Diagnostic: await-outside-of-async // diff --git a/crates/ide-diagnostics/src/handlers/field_shorthand.rs b/crates/ide-diagnostics/src/handlers/field_shorthand.rs index 876c2ccd49..f7020a2c50 100644 --- a/crates/ide-diagnostics/src/handlers/field_shorthand.rs +++ b/crates/ide-diagnostics/src/handlers/field_shorthand.rs @@ -2,10 +2,10 @@ //! expressions and patterns. use ide_db::text_edit::TextEdit; -use ide_db::{source_change::SourceChange, EditionedFileId, FileRange}; -use syntax::{ast, match_ast, AstNode, SyntaxNode}; +use ide_db::{EditionedFileId, FileRange, source_change::SourceChange}; +use syntax::{AstNode, SyntaxNode, ast, match_ast}; -use crate::{fix, Diagnostic, DiagnosticCode}; +use crate::{Diagnostic, DiagnosticCode, fix}; pub(crate) fn field_shorthand( acc: &mut Vec, diff --git a/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs b/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs index 7d62daf716..3fa8c0133a 100644 --- a/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs +++ b/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs @@ -3,9 +3,9 @@ use hir::GenericArgsProhibitedReason; use ide_db::assists::Assist; use ide_db::source_change::SourceChange; use ide_db::text_edit::TextEdit; -use syntax::{ast, AstNode, TextRange}; +use syntax::{AstNode, TextRange, ast}; -use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, fix}; // Diagnostic: generic-args-prohibited // diff --git a/crates/ide-diagnostics/src/handlers/inactive_code.rs b/crates/ide-diagnostics/src/handlers/inactive_code.rs index 96a368eb0e..80ea6f5893 100644 --- a/crates/ide-diagnostics/src/handlers/inactive_code.rs +++ b/crates/ide-diagnostics/src/handlers/inactive_code.rs @@ -39,7 +39,7 @@ pub(crate) fn inactive_code( #[cfg(test)] mod tests { - use crate::{tests::check_diagnostics_with_config, DiagnosticsConfig}; + use crate::{DiagnosticsConfig, tests::check_diagnostics_with_config}; pub(crate) fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let config = DiagnosticsConfig { diff --git a/crates/ide-diagnostics/src/handlers/incoherent_impl.rs b/crates/ide-diagnostics/src/handlers/incoherent_impl.rs index d3f3020775..0b9a2ec9db 100644 --- a/crates/ide-diagnostics/src/handlers/incoherent_impl.rs +++ b/crates/ide-diagnostics/src/handlers/incoherent_impl.rs @@ -1,7 +1,7 @@ use hir::InFile; use syntax::{AstNode, TextRange}; -use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, adjusted_display_range}; // Diagnostic: incoherent-impl // diff --git a/crates/ide-diagnostics/src/handlers/incorrect_case.rs b/crates/ide-diagnostics/src/handlers/incorrect_case.rs index 246330e6ef..72619445b5 100644 --- a/crates/ide-diagnostics/src/handlers/incorrect_case.rs +++ b/crates/ide-diagnostics/src/handlers/incorrect_case.rs @@ -1,13 +1,13 @@ -use hir::{db::ExpandDatabase, CaseType, InFile}; +use hir::{CaseType, InFile, db::ExpandDatabase}; use ide_db::{assists::Assist, defs::NameClass}; use syntax::AstNode; use crate::{ - // references::rename::rename_with_semantics, - unresolved_fix, Diagnostic, DiagnosticCode, DiagnosticsContext, + // references::rename::rename_with_semantics, + unresolved_fix, }; // Diagnostic: incorrect-ident-case diff --git a/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs b/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs index f22041ebe2..38eeecb29b 100644 --- a/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs +++ b/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs @@ -4,19 +4,19 @@ use hir::{ImportPathConfig, PathResolution, Semantics}; use ide_db::text_edit::TextEdit; use ide_db::{ - helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope}, - source_change::SourceChangeBuilder, EditionedFileId, FileRange, FxHashMap, RootDatabase, + helpers::mod_path_to_ast, + imports::insert_use::{ImportScope, insert_use}, + source_change::SourceChangeBuilder, }; use itertools::Itertools; use stdx::{format_to, never}; use syntax::{ - ast::{self, make}, Edition, SyntaxKind, SyntaxNode, + ast::{self, make}, }; -use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsConfig, Severity}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsConfig, Severity, fix}; #[derive(Default)] struct State { @@ -196,8 +196,8 @@ pub(crate) fn json_in_items( #[cfg(test)] mod tests { use crate::{ - tests::{check_diagnostics_with_config, check_fix, check_no_fix}, DiagnosticsConfig, + tests::{check_diagnostics_with_config, check_fix, check_no_fix}, }; #[test] diff --git a/crates/ide-diagnostics/src/handlers/macro_error.rs b/crates/ide-diagnostics/src/handlers/macro_error.rs index 2f13298589..9efe251c9a 100644 --- a/crates/ide-diagnostics/src/handlers/macro_error.rs +++ b/crates/ide-diagnostics/src/handlers/macro_error.rs @@ -38,8 +38,8 @@ pub(crate) fn macro_def_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroDefErr #[cfg(test)] mod tests { use crate::{ - tests::{check_diagnostics, check_diagnostics_with_config}, DiagnosticsConfig, + tests::{check_diagnostics, check_diagnostics_with_config}, }; #[test] diff --git a/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs b/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs index 0520bb3fe9..63fd9b4e3f 100644 --- a/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs +++ b/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs @@ -2,11 +2,11 @@ use either::Either; use hir::InFile; use ide_db::FileRange; use syntax::{ - ast::{self, HasArgList}, AstNode, AstPtr, + ast::{self, HasArgList}, }; -use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, adjusted_display_range}; // Diagnostic: mismatched-tuple-struct-pat-arg-count // diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index 938b7182bc..ac68f4186c 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -1,20 +1,22 @@ use either::Either; use hir::{ + AssocItem, HirDisplay, HirFileIdExt, ImportPathConfig, InFile, Type, db::{ExpandDatabase, HirDatabase}, - sym, AssocItem, HirDisplay, HirFileIdExt, ImportPathConfig, InFile, Type, + sym, }; use ide_db::{ - assists::Assist, famous_defs::FamousDefs, imports::import_assets::item_for_path_search, - source_change::SourceChange, syntax_helpers::tree_diff::diff, text_edit::TextEdit, - use_trivial_constructor::use_trivial_constructor, FxHashMap, + FxHashMap, assists::Assist, famous_defs::FamousDefs, + imports::import_assets::item_for_path_search, source_change::SourceChange, + syntax_helpers::tree_diff::diff, text_edit::TextEdit, + use_trivial_constructor::use_trivial_constructor, }; use stdx::format_to; use syntax::{ - ast::{self, make}, AstNode, Edition, SyntaxNode, SyntaxNodePtr, ToSmolStr, + ast::{self, make}, }; -use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, fix}; // Diagnostic: missing-fields // @@ -140,11 +142,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option, d: &hir::TypeMismatch) -> Option, d: &hir::TypedHole) -> Option }) .collect(); - if !assists.is_empty() { - Some(assists) - } else { - None - } + if !assists.is_empty() { Some(assists) } else { None } } #[cfg(test)] diff --git a/crates/ide-diagnostics/src/handlers/unlinked_file.rs b/crates/ide-diagnostics/src/handlers/unlinked_file.rs index 550751b6c0..2602aa011f 100644 --- a/crates/ide-diagnostics/src/handlers/unlinked_file.rs +++ b/crates/ide-diagnostics/src/handlers/unlinked_file.rs @@ -2,21 +2,21 @@ use std::iter; -use hir::{db::DefDatabase, DefMap, InFile, ModuleSource}; +use hir::{DefMap, InFile, ModuleSource, db::DefDatabase}; use ide_db::base_db::RootQueryDb; use ide_db::text_edit::TextEdit; use ide_db::{ + FileId, FileRange, LineIndexDatabase, base_db::{SourceDatabase, Upcast}, source_change::SourceChange, - FileId, FileRange, LineIndexDatabase, }; use paths::Utf8Component; use syntax::{ - ast::{self, edit::IndentLevel, HasModuleItem, HasName}, AstNode, TextRange, + ast::{self, HasModuleItem, HasName, edit::IndentLevel}, }; -use crate::{fix, Assist, Diagnostic, DiagnosticCode, DiagnosticsContext, Severity}; +use crate::{Assist, Diagnostic, DiagnosticCode, DiagnosticsContext, Severity, fix}; // Diagnostic: unlinked-file // @@ -37,7 +37,9 @@ pub(crate) fn unlinked_file( "This file is not included anywhere in the module tree, so rust-analyzer can't offer IDE services." }; - let message = format!("{message}\n\nIf you're intentionally working on unowned files, you can silence this warning by adding \"unlinked-file\" to rust-analyzer.diagnostics.disabled in your settings."); + let message = format!( + "{message}\n\nIf you're intentionally working on unowned files, you can silence this warning by adding \"unlinked-file\" to rust-analyzer.diagnostics.disabled in your settings." + ); let mut unused = true; diff --git a/crates/ide-diagnostics/src/handlers/unresolved_field.rs b/crates/ide-diagnostics/src/handlers/unresolved_field.rs index 6ab713a589..7020fce24f 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_field.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_field.rs @@ -1,7 +1,7 @@ use std::iter; use either::Either; -use hir::{db::ExpandDatabase, Adt, FileRange, HasSource, HirDisplay, InFile, Struct, Union}; +use hir::{Adt, FileRange, HasSource, HirDisplay, InFile, Struct, Union, db::ExpandDatabase}; use ide_db::text_edit::TextEdit; use ide_db::{ assists::{Assist, AssistId, AssistKind}, @@ -10,16 +10,15 @@ use ide_db::{ source_change::{SourceChange, SourceChangeBuilder}, }; use syntax::{ - algo, - ast::{self, edit::IndentLevel, make, FieldList, Name, Visibility}, - AstNode, AstPtr, Direction, SyntaxKind, TextSize, + AstNode, AstPtr, Direction, SyntaxKind, TextSize, algo, + ast::{self, FieldList, Name, Visibility, edit::IndentLevel, make}, }; use syntax::{ - ast::{edit::AstNodeEdit, Type}, SyntaxNode, + ast::{Type, edit::AstNodeEdit}, }; -use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, adjusted_display_range}; // Diagnostic: unresolved-field // @@ -62,11 +61,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Option, d: &hir::UnresolvedMethodCall) -> Option< fixes.push(assoc_func_fix); } - if fixes.is_empty() { - None - } else { - Some(fixes) - } + if fixes.is_empty() { None } else { Some(fixes) } } fn field_fix( diff --git a/crates/ide-diagnostics/src/handlers/unresolved_module.rs b/crates/ide-diagnostics/src/handlers/unresolved_module.rs index 2bd8e484f8..7b9dd55e01 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_module.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_module.rs @@ -1,9 +1,9 @@ -use hir::{db::ExpandDatabase, HirFileIdExt}; +use hir::{HirFileIdExt, db::ExpandDatabase}; use ide_db::{assists::Assist, base_db::AnchoredPathBuf, source_change::FileSystemEdit}; use itertools::Itertools; use syntax::AstNode; -use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsContext}; +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, fix}; // Diagnostic: unresolved-module // diff --git a/crates/ide-diagnostics/src/handlers/unused_variables.rs b/crates/ide-diagnostics/src/handlers/unused_variables.rs index d5caf4de33..c412536d74 100644 --- a/crates/ide-diagnostics/src/handlers/unused_variables.rs +++ b/crates/ide-diagnostics/src/handlers/unused_variables.rs @@ -1,10 +1,10 @@ use hir::Name; use ide_db::text_edit::TextEdit; use ide_db::{ + FileRange, RootDatabase, assists::{Assist, AssistId, AssistKind}, label::Label, source_change::SourceChange, - FileRange, RootDatabase, }; use syntax::{Edition, TextRange}; diff --git a/crates/ide-diagnostics/src/handlers/useless_braces.rs b/crates/ide-diagnostics/src/handlers/useless_braces.rs index e5c2eca171..ac9b34f416 100644 --- a/crates/ide-diagnostics/src/handlers/useless_braces.rs +++ b/crates/ide-diagnostics/src/handlers/useless_braces.rs @@ -1,10 +1,10 @@ use hir::InFile; use ide_db::text_edit::TextEdit; -use ide_db::{source_change::SourceChange, EditionedFileId, FileRange}; +use ide_db::{EditionedFileId, FileRange, source_change::SourceChange}; use itertools::Itertools; -use syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr}; +use syntax::{AstNode, SyntaxNode, SyntaxNodePtr, ast}; -use crate::{fix, Diagnostic, DiagnosticCode}; +use crate::{Diagnostic, DiagnosticCode, fix}; // Diagnostic: unnecessary-braces // @@ -56,8 +56,8 @@ pub(crate) fn useless_braces( #[cfg(test)] mod tests { use crate::{ - tests::{check_diagnostics, check_diagnostics_with_config, check_fix}, DiagnosticsConfig, + tests::{check_diagnostics, check_diagnostics_with_config, check_fix}, }; #[test] diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs index c6f60a9a96..e801ec50cf 100644 --- a/crates/ide-diagnostics/src/lib.rs +++ b/crates/ide-diagnostics/src/lib.rs @@ -82,24 +82,24 @@ use std::{collections::hash_map, iter, sync::LazyLock}; use either::Either; use hir::{ - db::ExpandDatabase, diagnostics::AnyDiagnostic, Crate, DisplayTarget, HirFileId, InFile, - Semantics, + Crate, DisplayTarget, HirFileId, InFile, Semantics, db::ExpandDatabase, + diagnostics::AnyDiagnostic, }; use ide_db::base_db::salsa::AsDynDatabase; use ide_db::{ + EditionedFileId, FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, Severity, SnippetCap, assists::{Assist, AssistId, AssistKind, AssistResolveStrategy}, base_db::{ReleaseChannel, RootQueryDb as _}, - generated::lints::{Lint, LintGroup, CLIPPY_LINT_GROUPS, DEFAULT_LINTS, DEFAULT_LINT_GROUPS}, + generated::lints::{CLIPPY_LINT_GROUPS, DEFAULT_LINT_GROUPS, DEFAULT_LINTS, Lint, LintGroup}, imports::insert_use::InsertUseConfig, label::Label, source_change::SourceChange, syntax_helpers::node_ext::parse_tt_as_comma_sep_paths, - EditionedFileId, FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, Severity, SnippetCap, }; use itertools::Itertools; use syntax::{ + AstPtr, Edition, NodeOrToken, SmolStr, SyntaxKind, SyntaxNode, SyntaxNodePtr, T, TextRange, ast::{self, AstNode, HasAttrs}, - AstPtr, Edition, NodeOrToken, SmolStr, SyntaxKind, SyntaxNode, SyntaxNodePtr, TextRange, T, }; // FIXME: Make this an enum @@ -781,9 +781,8 @@ fn fill_lint_attrs( }); let lints = lint_groups(&diag.code, edition); - let all_matching_groups = lints - .iter() - .filter_map(|lint_group| cached.get(lint_group)); + let all_matching_groups = + lints.iter().filter_map(|lint_group| cached.get(lint_group)); let cached_severity = all_matching_groups.min_by_key(|it| it.depth).map(|it| it.severity); diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs index 7b33bbdaa2..6e4ce1ea18 100644 --- a/crates/ide-diagnostics/src/tests.rs +++ b/crates/ide-diagnostics/src/tests.rs @@ -3,12 +3,12 @@ mod overly_long_real_world_cases; use ide_db::{ - assists::AssistResolveStrategy, base_db::SourceDatabase, LineIndexDatabase, RootDatabase, + LineIndexDatabase, RootDatabase, assists::AssistResolveStrategy, base_db::SourceDatabase, }; use itertools::Itertools; use stdx::trim_indent; use test_fixture::WithFixture; -use test_utils::{assert_eq_text, extract_annotations, MiniCore}; +use test_utils::{MiniCore, assert_eq_text, extract_annotations}; use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity}; diff --git a/crates/ide-ssr/src/fragments.rs b/crates/ide-ssr/src/fragments.rs index ca937a03f8..8d6b7c637d 100644 --- a/crates/ide-ssr/src/fragments.rs +++ b/crates/ide-ssr/src/fragments.rs @@ -6,7 +6,7 @@ //! needs to determine it somehow. We do this in a stupid way -- by pasting SSR //! rule into different contexts and checking what works. -use syntax::{ast, AstNode, SyntaxNode}; +use syntax::{AstNode, SyntaxNode, ast}; pub(crate) fn ty(s: &str) -> Result { fragment::("type T = {};", s) diff --git a/crates/ide-ssr/src/from_comment.rs b/crates/ide-ssr/src/from_comment.rs index f6fe705a98..5921a5df53 100644 --- a/crates/ide-ssr/src/from_comment.rs +++ b/crates/ide-ssr/src/from_comment.rs @@ -2,12 +2,12 @@ //! from a comment. use ide_db::{ - base_db::{salsa::AsDynDatabase, RootQueryDb}, EditionedFileId, FilePosition, FileRange, RootDatabase, + base_db::{RootQueryDb, salsa::AsDynDatabase}, }; use syntax::{ - ast::{self, AstNode, AstToken}, TextRange, + ast::{self, AstNode, AstToken}, }; use crate::MatchFinder; diff --git a/crates/ide-ssr/src/lib.rs b/crates/ide-ssr/src/lib.rs index 971547ca1f..757c77b673 100644 --- a/crates/ide-ssr/src/lib.rs +++ b/crates/ide-ssr/src/lib.rs @@ -83,11 +83,11 @@ use hir::{FileRange, Semantics}; use ide_db::symbol_index::SymbolsDatabase; use ide_db::text_edit::TextEdit; use ide_db::{ - base_db::{salsa::AsDynDatabase, SourceDatabase}, EditionedFileId, FileId, FxHashMap, RootDatabase, + base_db::{SourceDatabase, salsa::AsDynDatabase}, }; use resolving::ResolvedRule; -use syntax::{ast, AstNode, SyntaxNode, TextRange}; +use syntax::{AstNode, SyntaxNode, TextRange, ast}; // A structured search replace rule. Create by calling `parse` on a str. #[derive(Debug)] diff --git a/crates/ide-ssr/src/matching.rs b/crates/ide-ssr/src/matching.rs index a76516f44f..0776b8bc5e 100644 --- a/crates/ide-ssr/src/matching.rs +++ b/crates/ide-ssr/src/matching.rs @@ -2,16 +2,16 @@ //! process of matching, placeholder values are recorded. use crate::{ + SsrMatches, parsing::{Constraint, NodeKind, Placeholder, Var}, resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo}, - SsrMatches, }; use hir::{FileRange, ImportPathConfig, Semantics}; -use ide_db::{base_db::RootQueryDb, FxHashMap}; +use ide_db::{FxHashMap, base_db::RootQueryDb}; use std::{cell::Cell, iter::Peekable}; use syntax::{ - ast::{self, AstNode, AstToken, HasGenericArgs}, SmolStr, SyntaxElement, SyntaxElementChildren, SyntaxKind, SyntaxNode, SyntaxToken, + ast::{self, AstNode, AstToken, HasGenericArgs}, }; // Creates a match error. If we're currently attempting to match some code that we thought we were diff --git a/crates/ide-ssr/src/parsing.rs b/crates/ide-ssr/src/parsing.rs index ea40d5b815..2c0f1658d8 100644 --- a/crates/ide-ssr/src/parsing.rs +++ b/crates/ide-ssr/src/parsing.rs @@ -9,7 +9,7 @@ use std::{fmt::Display, str::FromStr}; use syntax::{SmolStr, SyntaxKind, SyntaxNode, T}; use crate::errors::bail; -use crate::{fragments, SsrError, SsrPattern, SsrRule}; +use crate::{SsrError, SsrPattern, SsrRule, fragments}; #[derive(Debug)] pub(crate) struct ParsedRule { diff --git a/crates/ide-ssr/src/replacing.rs b/crates/ide-ssr/src/replacing.rs index 11c1615a56..2ad562f242 100644 --- a/crates/ide-ssr/src/replacing.rs +++ b/crates/ide-ssr/src/replacing.rs @@ -5,11 +5,11 @@ use ide_db::{FxHashMap, FxHashSet}; use itertools::Itertools; use parser::Edition; use syntax::{ - ast::{self, AstNode, AstToken}, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, + ast::{self, AstNode, AstToken}, }; -use crate::{fragments, resolving::ResolvedRule, Match, SsrMatches}; +use crate::{Match, SsrMatches, fragments, resolving::ResolvedRule}; /// Returns a text edit that will replace each match in `matches` with its corresponding replacement /// template. Placeholders in the template will have been substituted with whatever they matched to diff --git a/crates/ide-ssr/src/resolving.rs b/crates/ide-ssr/src/resolving.rs index 8c98d8de91..ba6d981b8c 100644 --- a/crates/ide-ssr/src/resolving.rs +++ b/crates/ide-ssr/src/resolving.rs @@ -1,14 +1,14 @@ //! This module is responsible for resolving paths within rules. use hir::AsAssocItem; -use ide_db::{base_db::salsa::AsDynDatabase, FxHashMap}; +use ide_db::{FxHashMap, base_db::salsa::AsDynDatabase}; use parsing::Placeholder; use syntax::{ - ast::{self, HasGenericArgs}, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken, + ast::{self, HasGenericArgs}, }; -use crate::{errors::error, parsing, SsrError}; +use crate::{SsrError, errors::error, parsing}; pub(crate) struct ResolutionScope<'db> { scope: hir::SemanticsScope<'db>, diff --git a/crates/ide-ssr/src/search.rs b/crates/ide-ssr/src/search.rs index b094712e1b..73dbefb51b 100644 --- a/crates/ide-ssr/src/search.rs +++ b/crates/ide-ssr/src/search.rs @@ -1,18 +1,17 @@ //! Searching for matches. use crate::{ - matching, + Match, MatchFinder, matching, resolving::{ResolvedPath, ResolvedPattern, ResolvedRule}, - Match, MatchFinder, }; use hir::FileRange; use ide_db::{ + EditionedFileId, FileId, FxHashSet, base_db::salsa::AsDynDatabase, defs::Definition, search::{SearchScope, UsageSearchResult}, - EditionedFileId, FileId, FxHashSet, }; -use syntax::{ast, AstNode, SyntaxKind, SyntaxNode}; +use syntax::{AstNode, SyntaxKind, SyntaxNode, ast}; /// A cache for the results of find_usages. This is for when we have multiple patterns that have the /// same path. e.g. if the pattern was `foo::Bar` that can parse as a path, an expression, a type diff --git a/crates/ide-ssr/src/tests.rs b/crates/ide-ssr/src/tests.rs index 0b510c9c6b..b26ea35f02 100644 --- a/crates/ide-ssr/src/tests.rs +++ b/crates/ide-ssr/src/tests.rs @@ -1,8 +1,8 @@ -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use hir::{FilePosition, FileRange}; use ide_db::{ - base_db::{salsa::Durability, SourceDatabase}, EditionedFileId, FxHashSet, + base_db::{SourceDatabase, salsa::Durability}, }; use test_utils::RangeOrOffset; use triomphe::Arc; @@ -67,7 +67,7 @@ fn parser_undefined_placeholder_in_replacement() { /// the start of the file. If there's a second cursor marker, then we'll return a single range. pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Vec) { use ide_db::symbol_index::SymbolsDatabase; - use test_fixture::{WithFixture, WORKSPACE}; + use test_fixture::{WORKSPACE, WithFixture}; let (mut db, file_id, range_or_offset) = if code.contains(test_utils::CURSOR_MARKER) { ide_db::RootDatabase::with_range_or_offset(code) } else { diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index e47891bbdf..d44d4bfd2b 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -1,17 +1,17 @@ use hir::{HasSource, InFile, InRealFile, Semantics}; use ide_db::{ - defs::Definition, helpers::visit_file_defs, FileId, FilePosition, FileRange, FxIndexSet, - RootDatabase, + FileId, FilePosition, FileRange, FxIndexSet, RootDatabase, defs::Definition, + helpers::visit_file_defs, }; use itertools::Itertools; -use syntax::{ast::HasName, AstNode, TextRange}; +use syntax::{AstNode, TextRange, ast::HasName}; use crate::{ + NavigationTarget, RunnableKind, annotations::fn_references::find_all_methods, goto_implementation::goto_implementation, references::find_all_refs, - runnables::{runnables, Runnable}, - NavigationTarget, RunnableKind, + runnables::{Runnable, runnables}, }; mod fn_references; @@ -209,9 +209,9 @@ fn should_skip_runnable(kind: &RunnableKind, binary_target: bool) -> bool { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; - use crate::{fixture, Annotation, AnnotationConfig}; + use crate::{Annotation, AnnotationConfig, fixture}; use super::AnnotationLocation; diff --git a/crates/ide/src/annotations/fn_references.rs b/crates/ide/src/annotations/fn_references.rs index 08cc10509c..427a2eff82 100644 --- a/crates/ide/src/annotations/fn_references.rs +++ b/crates/ide/src/annotations/fn_references.rs @@ -4,7 +4,7 @@ use hir::Semantics; use ide_assists::utils::test_related_attribute_syn; use ide_db::RootDatabase; -use syntax::{ast, ast::HasName, AstNode, SyntaxNode, TextRange}; +use syntax::{AstNode, SyntaxNode, TextRange, ast, ast::HasName}; use crate::FileId; @@ -34,8 +34,8 @@ fn method_range(item: SyntaxNode) -> Option<(TextRange, Option)> { mod tests { use syntax::TextRange; - use crate::fixture; use crate::TextSize; + use crate::fixture; use std::ops::RangeInclusive; #[test] diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index afd6f740c4..5c0e113d5c 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -4,14 +4,14 @@ use std::iter; use hir::Semantics; use ide_db::{ + FileRange, FxIndexMap, RootDatabase, defs::{Definition, NameClass, NameRefClass}, helpers::pick_best_token, search::FileReference, - FileRange, FxIndexMap, RootDatabase, }; -use syntax::{ast, AstNode, SyntaxKind::IDENT}; +use syntax::{AstNode, SyntaxKind::IDENT, ast}; -use crate::{goto_definition, FilePosition, NavigationTarget, RangeInfo, TryToNav}; +use crate::{FilePosition, NavigationTarget, RangeInfo, TryToNav, goto_definition}; #[derive(Debug, Clone)] pub struct CallItem { @@ -165,7 +165,7 @@ impl CallLocations { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::FilePosition; use itertools::Itertools; diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 9bdc2e7d13..a01afd242e 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -6,28 +6,29 @@ mod tests; mod intra_doc_links; use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag}; -use pulldown_cmark_to_cmark::{cmark_resume_with_options, Options as CMarkOptions}; +use pulldown_cmark_to_cmark::{Options as CMarkOptions, cmark_resume_with_options}; use stdx::format_to; use url::Url; -use hir::{db::HirDatabase, sym, Adt, AsAssocItem, AssocItem, AssocItemContainer, HasAttrs}; +use hir::{Adt, AsAssocItem, AssocItem, AssocItemContainer, HasAttrs, db::HirDatabase, sym}; use ide_db::{ + RootDatabase, base_db::{CrateOrigin, LangCrateOrigin, ReleaseChannel, RootQueryDb}, defs::{Definition, NameClass, NameRefClass}, - documentation::{docs_with_rangemap, Documentation, HasDocs}, + documentation::{Documentation, HasDocs, docs_with_rangemap}, helpers::pick_best_token, - RootDatabase, }; use syntax::{ - ast::{self, IsString}, - match_ast, AstNode, AstToken, + AstNode, AstToken, SyntaxKind::*, - SyntaxNode, SyntaxToken, TextRange, TextSize, T, + SyntaxNode, SyntaxToken, T, TextRange, TextSize, + ast::{self, IsString}, + match_ast, }; use crate::{ - doc_links::intra_doc_links::{parse_intra_doc_link, strip_prefixes_suffixes}, FilePosition, Semantics, + doc_links::intra_doc_links::{parse_intra_doc_link, strip_prefixes_suffixes}, }; /// Web and local links to an item's documentation. diff --git a/crates/ide/src/doc_links/intra_doc_links.rs b/crates/ide/src/doc_links/intra_doc_links.rs index 6cc240d652..c331734c78 100644 --- a/crates/ide/src/doc_links/intra_doc_links.rs +++ b/crates/ide/src/doc_links/intra_doc_links.rs @@ -53,7 +53,7 @@ pub(super) fn strip_prefixes_suffixes(s: &str) -> &str { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use super::*; diff --git a/crates/ide/src/doc_links/tests.rs b/crates/ide/src/doc_links/tests.rs index d70a3f9706..91785be8d8 100644 --- a/crates/ide/src/doc_links/tests.rs +++ b/crates/ide/src/doc_links/tests.rs @@ -1,18 +1,19 @@ use std::iter; -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use hir::Semantics; use ide_db::{ + FilePosition, FileRange, RootDatabase, defs::Definition, documentation::{Documentation, HasDocs}, - FilePosition, FileRange, RootDatabase, }; use itertools::Itertools; -use syntax::{ast, match_ast, AstNode, SyntaxNode}; +use syntax::{AstNode, SyntaxNode, ast, match_ast}; use crate::{ + TryToNav, doc_links::{extract_definitions_from_docs, resolve_doc_path_for_def, rewrite_links}, - fixture, TryToNav, + fixture, }; fn check_external_docs( @@ -683,7 +684,9 @@ fn rewrite_intra_doc_link_with_anchor() { //! $0[PartialEq#derivable] fn main() {} "#, - expect!["[PartialEq#derivable](https://doc.rust-lang.org/stable/core/cmp/trait.PartialEq.html#derivable)"], + expect![ + "[PartialEq#derivable](https://doc.rust-lang.org/stable/core/cmp/trait.PartialEq.html#derivable)" + ], ); } diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index a18eb9049f..4811f1f691 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -1,12 +1,12 @@ use hir::db::ExpandDatabase; use hir::{ExpandResult, InFile, MacroFileIdExt, Semantics}; use ide_db::{ - base_db::Crate, helpers::pick_best_token, syntax_helpers::prettify_macro_expansion, FileId, - RootDatabase, + FileId, RootDatabase, base_db::Crate, helpers::pick_best_token, + syntax_helpers::prettify_macro_expansion, }; use span::{Edition, SpanMap, SyntaxContext, TextRange, TextSize}; use stdx::format_to; -use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T}; +use syntax::{AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T, ast, ted}; use crate::FilePosition; @@ -289,7 +289,7 @@ fn _format( #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use crate::fixture; diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs index 76414854e9..a374f9752f 100644 --- a/crates/ide/src/extend_selection.rs +++ b/crates/ide/src/extend_selection.rs @@ -3,11 +3,11 @@ use std::iter::successors; use hir::Semantics; use ide_db::RootDatabase; use syntax::{ - algo::{self, skip_trivia_token}, - ast::{self, AstNode, AstToken}, Direction, NodeOrToken, SyntaxKind::{self, *}, - SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, T, + SyntaxNode, SyntaxToken, T, TextRange, TextSize, TokenAtOffset, + algo::{self, skip_trivia_token}, + ast::{self, AstNode, AstToken}, }; use crate::FileRange; @@ -178,11 +178,7 @@ fn extend_tokens_from_range( .last()?; let range = first.text_range().cover(last.text_range()); - if range.contains_range(original_range) && original_range != range { - Some(range) - } else { - None - } + if range.contains_range(original_range) && original_range != range { Some(range) } else { None } } /// Find the shallowest node with same range, which allows us to traverse siblings. @@ -216,11 +212,7 @@ fn extend_single_word_in_comment_or_string( let to: TextSize = (cursor_position + end_idx).into(); let range = TextRange::new(from, to); - if range.is_empty() { - None - } else { - Some(range + leaf.text_range().start()) - } + if range.is_empty() { None } else { Some(range + leaf.text_range().start()) } } fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextSize) -> TextRange { diff --git a/crates/ide/src/fetch_crates.rs b/crates/ide/src/fetch_crates.rs index b682c4bc0f..956379e722 100644 --- a/crates/ide/src/fetch_crates.rs +++ b/crates/ide/src/fetch_crates.rs @@ -1,6 +1,6 @@ use ide_db::{ - base_db::{CrateOrigin, RootQueryDb}, FileId, FxIndexSet, RootDatabase, + base_db::{CrateOrigin, RootQueryDb}, }; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 52fbab6fa1..347da4e85b 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs @@ -1,8 +1,8 @@ use ide_db::SymbolKind; use syntax::{ + AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, WalkEvent, ast::{self, HasAttrs, HasGenericParams, HasName}, - match_ast, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, - WalkEvent, + match_ast, }; #[derive(Debug, Clone)] @@ -250,7 +250,7 @@ fn structure_token(token: SyntaxToken) -> Option { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use super::*; diff --git a/crates/ide/src/fixture.rs b/crates/ide/src/fixture.rs index a0612f48d3..73b7e771ca 100644 --- a/crates/ide/src/fixture.rs +++ b/crates/ide/src/fixture.rs @@ -1,6 +1,6 @@ //! Utilities for creating `Analysis` instances for tests. use test_fixture::ChangeFixture; -use test_utils::{extract_annotations, RangeOrOffset}; +use test_utils::{RangeOrOffset, extract_annotations}; use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index e5a94ff9fe..194e8c968f 100755 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -1,9 +1,10 @@ -use ide_db::{syntax_helpers::node_ext::vis_eq, FxHashSet}; +use ide_db::{FxHashSet, syntax_helpers::node_ext::vis_eq}; use syntax::{ - ast::{self, AstNode, AstToken}, - match_ast, Direction, NodeOrToken, SourceFile, + Direction, NodeOrToken, SourceFile, SyntaxKind::{self, *}, TextRange, TextSize, + ast::{self, AstNode, AstToken}, + match_ast, }; use std::hash::Hash; diff --git a/crates/ide/src/goto_declaration.rs b/crates/ide/src/goto_declaration.rs index 3742edc8db..a022f1cede 100644 --- a/crates/ide/src/goto_declaration.rs +++ b/crates/ide/src/goto_declaration.rs @@ -1,13 +1,13 @@ use hir::{AsAssocItem, Semantics}; use ide_db::{ - defs::{Definition, NameClass, NameRefClass}, RootDatabase, + defs::{Definition, NameClass, NameRefClass}, }; -use syntax::{ast, match_ast, AstNode, SyntaxKind::*, T}; +use syntax::{AstNode, SyntaxKind::*, T, ast, match_ast}; use crate::{ - goto_definition::goto_definition, navigation_target::TryToNav, FilePosition, NavigationTarget, - RangeInfo, + FilePosition, NavigationTarget, RangeInfo, goto_definition::goto_definition, + navigation_target::TryToNav, }; // Feature: Go to Declaration @@ -52,7 +52,7 @@ pub(crate) fn goto_declaration( }; let assoc = match def? { Definition::Module(module) => { - return Some(NavigationTarget::from_module_to_decl(db, module)) + return Some(NavigationTarget::from_module_to_decl(db, module)); } Definition::Const(c) => c.as_assoc_item(db), Definition::TypeAlias(ta) => ta.as_assoc_item(db), @@ -69,11 +69,7 @@ pub(crate) fn goto_declaration( .flatten() .collect(); - if info.is_empty() { - goto_definition(db, position) - } else { - Some(RangeInfo::new(range, info)) - } + if info.is_empty() { goto_definition(db, position) } else { Some(RangeInfo::new(range, info)) } } #[cfg(test)] diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 84138986f6..e920ff5ab4 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -1,28 +1,29 @@ use std::{iter, mem::discriminant}; use crate::{ + FilePosition, NavigationTarget, RangeInfo, TryToNav, UpmappingResult, doc_links::token_as_doc_comment, navigation_target::{self, ToNav}, - FilePosition, NavigationTarget, RangeInfo, TryToNav, UpmappingResult, }; use hir::{ - sym, AsAssocItem, AssocItem, CallableKind, FileRange, HasCrate, InFile, MacroFileIdExt, - ModuleDef, Semantics, + AsAssocItem, AssocItem, CallableKind, FileRange, HasCrate, InFile, MacroFileIdExt, ModuleDef, + Semantics, sym, }; use ide_db::{ + RootDatabase, SymbolKind, base_db::{AnchoredPath, RootQueryDb, SourceDatabase, Upcast}, defs::{Definition, IdentClass}, famous_defs::FamousDefs, helpers::pick_best_token, - RootDatabase, SymbolKind, }; use itertools::Itertools; use span::{Edition, FileId}; use syntax::{ - ast::{self, HasLoopBody}, - match_ast, AstNode, AstToken, + AstNode, AstToken, SyntaxKind::*, - SyntaxNode, SyntaxToken, TextRange, T, + SyntaxNode, SyntaxToken, T, TextRange, + ast::{self, HasLoopBody}, + match_ast, }; // Feature: Go to Definition diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index e1d834b5d1..1bc28f28b6 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -1,10 +1,10 @@ use hir::{AsAssocItem, Impl, Semantics}; use ide_db::{ + RootDatabase, defs::{Definition, NameClass, NameRefClass}, helpers::pick_best_token, - RootDatabase, }; -use syntax::{ast, AstNode, SyntaxKind::*, T}; +use syntax::{AstNode, SyntaxKind::*, T, ast}; use crate::{FilePosition, NavigationTarget, RangeInfo, TryToNav}; diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index ddc274a830..bf48a6e232 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs @@ -1,6 +1,6 @@ use hir::GenericParam; -use ide_db::{base_db::Upcast, defs::Definition, helpers::pick_best_token, RootDatabase}; -use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, T}; +use ide_db::{RootDatabase, base_db::Upcast, defs::Definition, helpers::pick_best_token}; +use syntax::{AstNode, SyntaxKind::*, SyntaxToken, T, ast, match_ast}; use crate::{FilePosition, NavigationTarget, RangeInfo, TryToNav}; diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index 0ef7eb503f..f367d76a12 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -1,7 +1,8 @@ use std::iter; -use hir::{db, FilePosition, FileRange, HirFileId, InFile, Semantics}; +use hir::{FilePosition, FileRange, HirFileId, InFile, Semantics, db}; use ide_db::{ + FxHashMap, FxHashSet, RootDatabase, base_db::salsa::AsDynDatabase, defs::{Definition, IdentClass}, helpers::pick_best_token, @@ -10,17 +11,17 @@ use ide_db::{ eq_label_lt, for_each_tail_expr, full_path_of_name_ref, is_closure_or_blk_with_modif, preorder_expr_with_ctx_checker, }, - FxHashMap, FxHashSet, RootDatabase, }; use span::EditionedFileId; use syntax::{ - ast::{self, HasLoopBody}, - match_ast, AstNode, + AstNode, SyntaxKind::{self, IDENT, INT_NUMBER}, - SyntaxToken, TextRange, WalkEvent, T, + SyntaxToken, T, TextRange, WalkEvent, + ast::{self, HasLoopBody}, + match_ast, }; -use crate::{goto_definition, navigation_target::ToNav, NavigationTarget, TryToNav}; +use crate::{NavigationTarget, TryToNav, goto_definition, navigation_target::ToNav}; #[derive(PartialEq, Eq, Hash)] pub struct HighlightedRange { @@ -156,7 +157,7 @@ fn highlight_references( match resolution.map(Definition::from) { Some(def) => iter::once(def).collect(), None => { - return Some(vec![HighlightedRange { range, category: ReferenceCategory::empty() }]) + return Some(vec![HighlightedRange { range, category: ReferenceCategory::empty() }]); } } } else { @@ -278,11 +279,7 @@ fn highlight_references( } res.extend(usages); - if res.is_empty() { - None - } else { - Some(res.into_iter().collect()) - } + if res.is_empty() { None } else { Some(res.into_iter().collect()) } } fn hl_exit_points( diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 04189ed52a..ea1f673e5b 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -7,26 +7,26 @@ use std::{iter, ops::Not}; use either::Either; use hir::{ - db::DefDatabase, DisplayTarget, GenericDef, GenericSubstitution, HasCrate, HasSource, LangItem, - Semantics, + DisplayTarget, GenericDef, GenericSubstitution, HasCrate, HasSource, LangItem, Semantics, + db::DefDatabase, }; use ide_db::{ + FileRange, FxIndexSet, Ranker, RootDatabase, defs::{Definition, IdentClass, NameRefClass, OperatorClass}, famous_defs::FamousDefs, helpers::pick_best_token, - FileRange, FxIndexSet, Ranker, RootDatabase, }; -use itertools::{multizip, Itertools}; +use itertools::{Itertools, multizip}; use span::Edition; -use syntax::{ast, AstNode, SyntaxKind::*, SyntaxNode, T}; +use syntax::{AstNode, SyntaxKind::*, SyntaxNode, T, ast}; use crate::{ + FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, TryToNav, doc_links::token_as_doc_comment, markdown_remove::remove_markdown, markup::Markup, navigation_target::UpmappingResult, runnables::{runnable_fn, runnable_mod}, - FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, TryToNav, }; #[derive(Clone, Debug, PartialEq, Eq)] pub struct HoverConfig { @@ -512,7 +512,7 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option { - return it.try_to_nav(db).map(UpmappingResult::call_site).map(to_action) + return it.try_to_nav(db).map(UpmappingResult::call_site).map(to_action); } Definition::Adt(it) => Some(it), Definition::SelfType(it) => it.self_ty(db).as_adt(), diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index 1d807fb14c..cf2ff1c956 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -3,33 +3,34 @@ use std::{env, mem, ops::Not}; use either::Either; use hir::{ - db::ExpandDatabase, Adt, AsAssocItem, AsExternAssocItem, CaptureKind, DisplayTarget, DropGlue, + Adt, AsAssocItem, AsExternAssocItem, CaptureKind, DisplayTarget, DropGlue, DynCompatibilityViolation, HasCrate, HasSource, HirDisplay, Layout, LayoutError, MethodViolationCode, Name, Semantics, Symbol, Trait, Type, TypeInfo, VariantDef, + db::ExpandDatabase, }; use ide_db::{ + RootDatabase, defs::Definition, documentation::HasDocs, famous_defs::FamousDefs, generated::lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES}, syntax_helpers::prettify_macro_expansion, - RootDatabase, }; use itertools::Itertools; use rustc_apfloat::{ - ieee::{Half as f16, Quad as f128}, Float, + ieee::{Half as f16, Quad as f128}, }; use span::Edition; use stdx::format_to; -use syntax::{algo, ast, match_ast, AstNode, AstToken, Direction, SyntaxToken, T}; +use syntax::{AstNode, AstToken, Direction, SyntaxToken, T, algo, ast, match_ast}; use crate::{ - doc_links::{remove_links, rewrite_links}, - hover::{notable_traits, walk_and_push_ty, SubstTyLen}, - interpret::render_const_eval_error, HoverAction, HoverConfig, HoverResult, Markup, MemoryLayoutHoverConfig, MemoryLayoutHoverRenderKind, + doc_links::{remove_links, rewrite_links}, + hover::{SubstTyLen, notable_traits, walk_and_push_ty}, + interpret::render_const_eval_error, }; pub(super) fn type_info_of( @@ -345,11 +346,7 @@ pub(super) fn try_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option return None, }; @@ -417,7 +414,7 @@ fn definition_owner_name(db: &RootDatabase, def: Definition, edition: Edition) - "{}::{}", name.display(db, edition), it.name(db).display(db, edition) - )) + )); } None => Some(it.name(db)), } @@ -435,7 +432,7 @@ fn definition_owner_name(db: &RootDatabase, def: Definition, edition: Edition) - "{}::{}", name.display(db, edition), it.name(db)?.display(db, edition) - )) + )); } None => it.name(db), } diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index afddeb6dea..0266b87499 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -1,9 +1,9 @@ -use expect_test::{expect, Expect}; -use ide_db::{base_db::SourceDatabase, FileRange}; +use expect_test::{Expect, expect}; +use ide_db::{FileRange, base_db::SourceDatabase}; use syntax::TextRange; use crate::{ - fixture, HoverConfig, HoverDocFormat, MemoryLayoutHoverConfig, MemoryLayoutHoverRenderKind, + HoverConfig, HoverDocFormat, MemoryLayoutHoverConfig, MemoryLayoutHoverRenderKind, fixture, }; const HOVER_BASE_CONFIG: HoverConfig = HoverConfig { diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 57adf3e2a4..a260944d05 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -5,21 +5,22 @@ use std::{ use either::Either; use hir::{ - sym, ClosureStyle, DisplayTarget, HasVisibility, HirDisplay, HirDisplayError, HirWrite, - ModuleDef, ModuleDefId, Semantics, + ClosureStyle, DisplayTarget, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef, + ModuleDefId, Semantics, sym, }; -use ide_db::{base_db::salsa::AsDynDatabase, famous_defs::FamousDefs, FileRange, RootDatabase}; -use ide_db::{text_edit::TextEdit, FxHashSet}; +use ide_db::{FileRange, RootDatabase, base_db::salsa::AsDynDatabase, famous_defs::FamousDefs}; +use ide_db::{FxHashSet, text_edit::TextEdit}; use itertools::Itertools; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::EditionedFileId; use stdx::never; use syntax::{ + SmolStr, SyntaxNode, TextRange, TextSize, WalkEvent, ast::{self, AstNode, HasGenericParams}, - format_smolstr, match_ast, SmolStr, SyntaxNode, TextRange, TextSize, WalkEvent, + format_smolstr, match_ast, }; -use crate::{navigation_target::TryToNav, FileId}; +use crate::{FileId, navigation_target::TryToNav}; mod adjustment; mod bind_pat; @@ -843,9 +844,9 @@ mod tests { use itertools::Itertools; use test_utils::extract_annotations; - use crate::inlay_hints::{AdjustmentHints, AdjustmentHintsMode}; use crate::DiscriminantHints; - use crate::{fixture, inlay_hints::InlayHintsConfig, LifetimeElisionHints}; + use crate::inlay_hints::{AdjustmentHints, AdjustmentHintsMode}; + use crate::{LifetimeElisionHints, fixture, inlay_hints::InlayHintsConfig}; use super::{ClosureReturnTypeHints, GenericParameterHints, InlayFieldsToResolve}; diff --git a/crates/ide/src/inlay_hints/adjustment.rs b/crates/ide/src/inlay_hints/adjustment.rs index 91b8187295..f2844a2eaa 100644 --- a/crates/ide/src/inlay_hints/adjustment.rs +++ b/crates/ide/src/inlay_hints/adjustment.rs @@ -13,7 +13,7 @@ use hir::{ use ide_db::famous_defs::FamousDefs; use ide_db::text_edit::TextEditBuilder; -use syntax::ast::{self, prec::ExprPrecedence, AstNode}; +use syntax::ast::{self, AstNode, prec::ExprPrecedence}; use crate::{ AdjustmentHints, AdjustmentHintsMode, InlayHint, InlayHintLabel, InlayHintLabelPart, @@ -224,7 +224,7 @@ fn mode_and_needs_parens_for_adjustment_hints( expr: &ast::Expr, mode: AdjustmentHintsMode, ) -> (bool, bool, bool) { - use {std::cmp::Ordering::*, AdjustmentHintsMode::*}; + use {AdjustmentHintsMode::*, std::cmp::Ordering::*}; match mode { Prefix | Postfix => { @@ -284,8 +284,8 @@ fn needs_parens_for_adjustment_hints(expr: &ast::Expr, postfix: bool) -> (bool, #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, AdjustmentHints, AdjustmentHintsMode, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_with_config}, }; #[test] diff --git a/crates/ide/src/inlay_hints/bind_pat.rs b/crates/ide/src/inlay_hints/bind_pat.rs index aab8a3f873..10cb91713d 100644 --- a/crates/ide/src/inlay_hints/bind_pat.rs +++ b/crates/ide/src/inlay_hints/bind_pat.rs @@ -4,7 +4,7 @@ //! let _x /* i32 */= f(4, 4); //! ``` use hir::{DisplayTarget, Semantics}; -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use itertools::Itertools; use syntax::{ @@ -13,8 +13,8 @@ use syntax::{ }; use crate::{ - inlay_hints::{closure_has_block_body, label_of_ty, ty_to_text_edit}, InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind, + inlay_hints::{closure_has_block_body, label_of_ty, ty_to_text_edit}, }; pub(super) fn hints( @@ -181,10 +181,10 @@ mod tests { use syntax::{TextRange, TextSize}; use test_utils::extract_annotations; - use crate::{fixture, inlay_hints::InlayHintsConfig, ClosureReturnTypeHints}; + use crate::{ClosureReturnTypeHints, fixture, inlay_hints::InlayHintsConfig}; use crate::inlay_hints::tests::{ - check, check_edit, check_no_edit, check_with_config, DISABLED_CONFIG, TEST_CONFIG, + DISABLED_CONFIG, TEST_CONFIG, check, check_edit, check_no_edit, check_with_config, }; #[track_caller] diff --git a/crates/ide/src/inlay_hints/binding_mode.rs b/crates/ide/src/inlay_hints/binding_mode.rs index 5bbb4fe4e6..d291732068 100644 --- a/crates/ide/src/inlay_hints/binding_mode.rs +++ b/crates/ide/src/inlay_hints/binding_mode.rs @@ -128,8 +128,8 @@ mod tests { use expect_test::expect; use crate::{ - inlay_hints::tests::{check_edit, check_with_config, DISABLED_CONFIG}, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_edit, check_with_config}, }; #[test] diff --git a/crates/ide/src/inlay_hints/bounds.rs b/crates/ide/src/inlay_hints/bounds.rs index e9b728bcaa..8ddbfaeffe 100644 --- a/crates/ide/src/inlay_hints/bounds.rs +++ b/crates/ide/src/inlay_hints/bounds.rs @@ -1,7 +1,7 @@ //! Implementation of trait bound hints. //! //! Currently this renders the implied `Sized` bound. -use ide_db::{famous_defs::FamousDefs, FileRange}; +use ide_db::{FileRange, famous_defs::FamousDefs}; use span::EditionedFileId; use syntax::ast::{self, AstNode, HasTypeBounds}; @@ -86,7 +86,7 @@ mod tests { use crate::inlay_hints::InlayHintsConfig; - use crate::inlay_hints::tests::{check_expect, check_with_config, DISABLED_CONFIG}; + use crate::inlay_hints::tests::{DISABLED_CONFIG, check_expect, check_with_config}; #[track_caller] fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) { diff --git a/crates/ide/src/inlay_hints/chaining.rs b/crates/ide/src/inlay_hints/chaining.rs index 604719bc36..ff157fa171 100644 --- a/crates/ide/src/inlay_hints/chaining.rs +++ b/crates/ide/src/inlay_hints/chaining.rs @@ -2,8 +2,8 @@ use hir::DisplayTarget; use ide_db::famous_defs::FamousDefs; use syntax::{ - ast::{self, AstNode}, Direction, NodeOrToken, SyntaxKind, T, + ast::{self, AstNode}, }; use crate::{InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind}; @@ -76,16 +76,15 @@ pub(super) fn hints( #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::text_edit::{TextRange, TextSize}; use crate::{ - fixture, + InlayHintsConfig, fixture, inlay_hints::{ - tests::{check_expect, check_with_config, DISABLED_CONFIG, TEST_CONFIG}, LazyProperty, + tests::{DISABLED_CONFIG, TEST_CONFIG, check_expect, check_with_config}, }, - InlayHintsConfig, }; #[track_caller] diff --git a/crates/ide/src/inlay_hints/closing_brace.rs b/crates/ide/src/inlay_hints/closing_brace.rs index bec6d38ee9..de9ca8c000 100644 --- a/crates/ide/src/inlay_hints/closing_brace.rs +++ b/crates/ide/src/inlay_hints/closing_brace.rs @@ -7,13 +7,14 @@ use hir::{DisplayTarget, HirDisplay, Semantics}; use ide_db::{FileRange, RootDatabase}; use span::EditionedFileId; use syntax::{ + SyntaxKind, SyntaxNode, T, ast::{self, AstNode, HasLoopBody, HasName}, - match_ast, SyntaxKind, SyntaxNode, T, + match_ast, }; use crate::{ - inlay_hints::LazyProperty, InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, - InlayKind, + InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind, + inlay_hints::LazyProperty, }; pub(super) fn hints( @@ -159,8 +160,8 @@ pub(super) fn hints( #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_with_config}, }; #[test] diff --git a/crates/ide/src/inlay_hints/closure_captures.rs b/crates/ide/src/inlay_hints/closure_captures.rs index 9b981c0a3a..07a86b2c9d 100644 --- a/crates/ide/src/inlay_hints/closure_captures.rs +++ b/crates/ide/src/inlay_hints/closure_captures.rs @@ -4,7 +4,7 @@ use ide_db::famous_defs::FamousDefs; use ide_db::text_edit::{TextRange, TextSize}; use span::EditionedFileId; -use stdx::{never, TupleExt}; +use stdx::{TupleExt, never}; use syntax::ast::{self, AstNode}; use crate::{ @@ -96,8 +96,8 @@ pub(super) fn hints( #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_with_config}, }; #[test] diff --git a/crates/ide/src/inlay_hints/closure_ret.rs b/crates/ide/src/inlay_hints/closure_ret.rs index 61c9c25fe7..16551b64f7 100644 --- a/crates/ide/src/inlay_hints/closure_ret.rs +++ b/crates/ide/src/inlay_hints/closure_ret.rs @@ -6,8 +6,8 @@ use ide_db::famous_defs::FamousDefs; use syntax::ast::{self, AstNode}; use crate::{ - inlay_hints::{closure_has_block_body, label_of_ty, ty_to_text_edit}, ClosureReturnTypeHints, InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind, + inlay_hints::{closure_has_block_body, label_of_ty, ty_to_text_edit}, }; pub(super) fn hints( @@ -80,7 +80,7 @@ pub(super) fn hints( #[cfg(test)] mod tests { - use crate::inlay_hints::tests::{check_with_config, DISABLED_CONFIG}; + use crate::inlay_hints::tests::{DISABLED_CONFIG, check_with_config}; use super::*; diff --git a/crates/ide/src/inlay_hints/discriminant.rs b/crates/ide/src/inlay_hints/discriminant.rs index f1e1955d14..827a0438dd 100644 --- a/crates/ide/src/inlay_hints/discriminant.rs +++ b/crates/ide/src/inlay_hints/discriminant.rs @@ -6,7 +6,7 @@ //! ``` use hir::Semantics; use ide_db::text_edit::TextEdit; -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use span::EditionedFileId; use syntax::ast::{self, AstNode, HasName}; @@ -107,8 +107,8 @@ mod tests { use expect_test::expect; use crate::inlay_hints::{ - tests::{check_edit, check_with_config, DISABLED_CONFIG}, DiscriminantHints, InlayHintsConfig, + tests::{DISABLED_CONFIG, check_edit, check_with_config}, }; #[track_caller] diff --git a/crates/ide/src/inlay_hints/extern_block.rs b/crates/ide/src/inlay_hints/extern_block.rs index 652dff0bc5..20f54b2cd1 100644 --- a/crates/ide/src/inlay_hints/extern_block.rs +++ b/crates/ide/src/inlay_hints/extern_block.rs @@ -1,7 +1,7 @@ //! Extern block hints use ide_db::{famous_defs::FamousDefs, text_edit::TextEdit}; use span::EditionedFileId; -use syntax::{ast, AstNode, SyntaxToken}; +use syntax::{AstNode, SyntaxToken, ast}; use crate::{InlayHint, InlayHintsConfig}; @@ -98,7 +98,7 @@ fn item_hint( #[cfg(test)] mod tests { - use crate::inlay_hints::tests::{check_with_config, DISABLED_CONFIG}; + use crate::inlay_hints::tests::{DISABLED_CONFIG, check_with_config}; #[test] fn unadorned() { diff --git a/crates/ide/src/inlay_hints/generic_param.rs b/crates/ide/src/inlay_hints/generic_param.rs index 762a4c2655..fc1083fdca 100644 --- a/crates/ide/src/inlay_hints/generic_param.rs +++ b/crates/ide/src/inlay_hints/generic_param.rs @@ -1,12 +1,12 @@ //! Implementation of inlay hints for generic parameters. use ide_db::{active_parameter::generic_def_for_node, famous_defs::FamousDefs}; use syntax::{ - ast::{self, AnyHasGenericArgs, HasGenericArgs, HasName}, AstNode, + ast::{self, AnyHasGenericArgs, HasGenericArgs, HasName}, }; use crate::{ - inlay_hints::GenericParameterHints, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind, + InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind, inlay_hints::GenericParameterHints, }; use super::param_name::is_argument_similar_to_param_name; @@ -145,11 +145,11 @@ fn get_string_representation(arg: &ast::GenericArg) -> Option { #[cfg(test)] mod tests { use crate::{ - inlay_hints::{ - tests::{check_with_config, DISABLED_CONFIG}, - GenericParameterHints, - }, InlayHintsConfig, + inlay_hints::{ + GenericParameterHints, + tests::{DISABLED_CONFIG, check_with_config}, + }, }; #[track_caller] diff --git a/crates/ide/src/inlay_hints/implicit_drop.rs b/crates/ide/src/inlay_hints/implicit_drop.rs index 390139d214..668232d301 100644 --- a/crates/ide/src/inlay_hints/implicit_drop.rs +++ b/crates/ide/src/inlay_hints/implicit_drop.rs @@ -6,16 +6,17 @@ //! } //! ``` use hir::{ + ChalkTyInterner, DefWithBody, db::{DefDatabase as _, HirDatabase as _}, mir::{MirSpan, TerminatorKind}, - ChalkTyInterner, DefWithBody, }; -use ide_db::{famous_defs::FamousDefs, FileRange}; +use ide_db::{FileRange, famous_defs::FamousDefs}; use span::EditionedFileId; use syntax::{ + ToSmolStr, ast::{self, AstNode}, - match_ast, ToSmolStr, + match_ast, }; use crate::{InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind}; @@ -143,8 +144,8 @@ fn nearest_token_after_node( #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_with_config}, }; const ONLY_DROP_CONFIG: InlayHintsConfig = diff --git a/crates/ide/src/inlay_hints/implicit_static.rs b/crates/ide/src/inlay_hints/implicit_static.rs index ae5b519b43..f3be09f30a 100644 --- a/crates/ide/src/inlay_hints/implicit_static.rs +++ b/crates/ide/src/inlay_hints/implicit_static.rs @@ -7,8 +7,8 @@ use ide_db::famous_defs::FamousDefs; use ide_db::text_edit::TextEdit; use span::EditionedFileId; use syntax::{ - ast::{self, AstNode}, SyntaxKind, + ast::{self, AstNode}, }; use crate::{InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind, LifetimeElisionHints}; @@ -56,8 +56,8 @@ pub(super) fn hints( #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, TEST_CONFIG}, InlayHintsConfig, LifetimeElisionHints, + inlay_hints::tests::{TEST_CONFIG, check_with_config}, }; #[test] diff --git a/crates/ide/src/inlay_hints/lifetime.rs b/crates/ide/src/inlay_hints/lifetime.rs index 7b0b3e19f2..baba49a427 100644 --- a/crates/ide/src/inlay_hints/lifetime.rs +++ b/crates/ide/src/inlay_hints/lifetime.rs @@ -4,18 +4,18 @@ //! ``` use std::iter; -use ide_db::{famous_defs::FamousDefs, syntax_helpers::node_ext::walk_ty, FxHashMap}; +use ide_db::{FxHashMap, famous_defs::FamousDefs, syntax_helpers::node_ext::walk_ty}; use itertools::Itertools; use span::EditionedFileId; +use syntax::{SmolStr, format_smolstr}; use syntax::{ - ast::{self, AstNode, HasGenericParams, HasName}, SyntaxKind, SyntaxToken, + ast::{self, AstNode, HasGenericParams, HasName}, }; -use syntax::{format_smolstr, SmolStr}; use crate::{ - inlay_hints::InlayHintCtx, InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind, - LifetimeElisionHints, + InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind, LifetimeElisionHints, + inlay_hints::InlayHintCtx, }; pub(super) fn fn_hints( @@ -274,7 +274,8 @@ fn hints_( }); let ctx = &*ctx; move || { - generic.by_ref() + generic + .by_ref() .find(|s| ctx.lifetime_stacks.iter().flat_map(|it| it.iter()).all(|n| n != s)) .unwrap_or_default() } @@ -406,8 +407,8 @@ fn hints_( #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check, check_with_config, TEST_CONFIG}, InlayHintsConfig, LifetimeElisionHints, + inlay_hints::tests::{TEST_CONFIG, check, check_with_config}, }; #[test] diff --git a/crates/ide/src/inlay_hints/param_name.rs b/crates/ide/src/inlay_hints/param_name.rs index 8f01b1bd38..44ea5351fb 100644 --- a/crates/ide/src/inlay_hints/param_name.rs +++ b/crates/ide/src/inlay_hints/param_name.rs @@ -6,13 +6,13 @@ use either::Either; use hir::{Callable, Semantics}; -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use span::EditionedFileId; use stdx::to_lower_snake_case; use syntax::{ - ast::{self, AstNode, HasArgList, HasName, UnaryOp}, ToSmolStr, + ast::{self, AstNode, HasArgList, HasName, UnaryOp}, }; use crate::{InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind}; @@ -257,8 +257,8 @@ fn is_adt_constructor_similar_to_param_name( #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_with_config}, }; #[track_caller] diff --git a/crates/ide/src/inlay_hints/range_exclusive.rs b/crates/ide/src/inlay_hints/range_exclusive.rs index de9b0e98a4..d67d845884 100644 --- a/crates/ide/src/inlay_hints/range_exclusive.rs +++ b/crates/ide/src/inlay_hints/range_exclusive.rs @@ -5,7 +5,7 @@ //! ``` use ide_db::famous_defs::FamousDefs; use span::EditionedFileId; -use syntax::{ast, SyntaxToken, T}; +use syntax::{SyntaxToken, T, ast}; use crate::{InlayHint, InlayHintsConfig}; @@ -41,8 +41,8 @@ fn inlay_hint(token: SyntaxToken) -> InlayHint { #[cfg(test)] mod tests { use crate::{ - inlay_hints::tests::{check_with_config, DISABLED_CONFIG}, InlayHintsConfig, + inlay_hints::tests::{DISABLED_CONFIG, check_with_config}, }; #[test] diff --git a/crates/ide/src/interpret.rs b/crates/ide/src/interpret.rs index 0499d8a447..8f9d2d6bf1 100644 --- a/crates/ide/src/interpret.rs +++ b/crates/ide/src/interpret.rs @@ -1,8 +1,8 @@ use hir::{ConstEvalError, DefWithBody, DisplayTarget, Semantics}; -use ide_db::{base_db::SourceDatabase, FilePosition, LineIndexDatabase, RootDatabase}; +use ide_db::{FilePosition, LineIndexDatabase, RootDatabase, base_db::SourceDatabase}; use std::time::{Duration, Instant}; use stdx::format_to; -use syntax::{algo::ancestors_at_offset, ast, AstNode, TextRange}; +use syntax::{AstNode, TextRange, algo::ancestors_at_offset, ast}; // Feature: Interpret A Function, Static Or Const. // diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs index ea18a97070..0188c105fa 100644 --- a/crates/ide/src/join_lines.rs +++ b/crates/ide/src/join_lines.rs @@ -2,10 +2,10 @@ use ide_assists::utils::extract_trivial_expression; use ide_db::syntax_helpers::node_ext::expr_as_name_ref; use itertools::Itertools; use syntax::{ - ast::{self, AstNode, AstToken, IsString}, NodeOrToken, SourceFile, SyntaxElement, SyntaxKind::{self, USE_TREE, WHITESPACE}, - SyntaxToken, TextRange, TextSize, T, + SyntaxToken, T, TextRange, TextSize, + ast::{self, AstNode, AstToken, IsString}, }; use ide_db::text_edit::{TextEdit, TextEditBuilder}; diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 79863f4680..f8eb676bfc 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -61,19 +61,20 @@ use std::panic::UnwindSafe; use cfg::CfgOptions; use fetch_crates::CrateInfo; -use hir::{sym, ChangeWithProcMacros}; +use hir::{ChangeWithProcMacros, sym}; use ide_db::{ + FxHashMap, FxIndexSet, LineIndexDatabase, base_db::{ - salsa::{AsDynDatabase, Cancelled}, CrateOrigin, CrateWorkspaceData, Env, FileSet, RootQueryDb, SourceDatabase, Upcast, VfsPath, + salsa::{AsDynDatabase, Cancelled}, }, - prime_caches, symbol_index, FxHashMap, FxIndexSet, LineIndexDatabase, + prime_caches, symbol_index, }; use span::EditionedFileId; use syntax::SourceFile; use triomphe::Arc; -use view_memory_layout::{view_memory_layout, RecursiveMemoryLayout}; +use view_memory_layout::{RecursiveMemoryLayout, view_memory_layout}; use crate::navigation_target::ToNav; @@ -110,8 +111,8 @@ pub use crate::{ StaticIndex, StaticIndexedFile, TokenId, TokenStaticData, VendoredLibrariesConfig, }, syntax_highlighting::{ - tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag}, HighlightConfig, HlRange, + tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag}, }, test_explorer::{TestItem, TestItemKind}, }; @@ -125,6 +126,7 @@ pub use ide_completion::{ }; pub use ide_db::text_edit::{Indel, TextEdit}; pub use ide_db::{ + FileId, FilePosition, FileRange, RootDatabase, Severity, SymbolKind, base_db::{Crate, CrateGraphBuilder, FileChange, SourceRoot, SourceRootId}, documentation::Documentation, label::Label, @@ -133,7 +135,6 @@ pub use ide_db::{ search::{ReferenceCategory, SearchScope}, source_change::{FileSystemEdit, SnippetEdit, SourceChange}, symbol_index::Query, - FileId, FilePosition, FileRange, RootDatabase, Severity, SymbolKind, }; pub use ide_diagnostics::{Diagnostic, DiagnosticCode, DiagnosticsConfig, ExprFillDefaultMode}; pub use ide_ssr::SsrError; diff --git a/crates/ide/src/matching_brace.rs b/crates/ide/src/matching_brace.rs index 67346ea9cf..b2b91d6e3c 100644 --- a/crates/ide/src/matching_brace.rs +++ b/crates/ide/src/matching_brace.rs @@ -1,6 +1,6 @@ use syntax::{ + SourceFile, SyntaxKind, T, TextSize, ast::{self, AstNode}, - SourceFile, SyntaxKind, TextSize, T, }; // Feature: Matching Brace diff --git a/crates/ide/src/moniker.rs b/crates/ide/src/moniker.rs index 5754b4fa82..4a06cd919f 100644 --- a/crates/ide/src/moniker.rs +++ b/crates/ide/src/moniker.rs @@ -5,15 +5,15 @@ use core::fmt; use hir::{Adt, AsAssocItem, Crate, HirDisplay, MacroKind, Semantics}; use ide_db::{ + FilePosition, RootDatabase, base_db::{CrateOrigin, LangCrateOrigin}, defs::{Definition, IdentClass}, helpers::pick_best_token, - FilePosition, RootDatabase, }; use itertools::Itertools; use syntax::{AstNode, SyntaxKind::*, T}; -use crate::{doc_links::token_as_doc_comment, parent_module::crates_for, RangeInfo}; +use crate::{RangeInfo, doc_links::token_as_doc_comment, parent_module::crates_for}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum MonikerDescriptorKind { @@ -194,11 +194,7 @@ pub(crate) fn def_to_kind(db: &RootDatabase, def: Definition) -> SymbolInformati Definition::Function(it) => { if it.as_assoc_item(db).is_some() { if it.has_self_param(db) { - if it.has_body(db) { - Method - } else { - TraitMethod - } + if it.has_body(db) { Method } else { TraitMethod } } else { StaticMethod } @@ -405,7 +401,7 @@ fn display(db: &RootDatabase, module: hir::Module, it: T) -> Stri #[cfg(test)] mod tests { - use crate::{fixture, MonikerResult}; + use crate::{MonikerResult, fixture}; use super::MonikerKind; diff --git a/crates/ide/src/move_item.rs b/crates/ide/src/move_item.rs index 3fb3a788b9..f3bb3df1cd 100644 --- a/crates/ide/src/move_item.rs +++ b/crates/ide/src/move_item.rs @@ -3,9 +3,9 @@ use std::{iter::once, mem}; use hir::Semantics; use ide_db::syntax_helpers::tree_diff::diff; use ide_db::text_edit::{TextEdit, TextEditBuilder}; -use ide_db::{helpers::pick_best_token, FileRange, RootDatabase}; +use ide_db::{FileRange, RootDatabase, helpers::pick_best_token}; use itertools::Itertools; -use syntax::{ast, match_ast, AstNode, SyntaxElement, SyntaxKind, SyntaxNode, TextRange}; +use syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, ast, match_ast}; #[derive(Copy, Clone, Debug)] pub enum Direction { @@ -174,7 +174,7 @@ fn replace_nodes<'a>( #[cfg(test)] mod tests { use crate::fixture; - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use crate::Direction; diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs index d67aaac06f..4679794287 100644 --- a/crates/ide/src/navigation_target.rs +++ b/crates/ide/src/navigation_target.rs @@ -5,19 +5,20 @@ use std::fmt; use arrayvec::ArrayVec; use either::Either; use hir::{ - db::ExpandDatabase, symbols::FileSymbol, AssocItem, FieldSource, HasContainer, HasCrate, - HasSource, HirDisplay, HirFileId, InFile, LocalSource, ModuleSource, + AssocItem, FieldSource, HasContainer, HasCrate, HasSource, HirDisplay, HirFileId, InFile, + LocalSource, ModuleSource, db::ExpandDatabase, symbols::FileSymbol, }; use ide_db::{ + FileId, FileRange, RootDatabase, SymbolKind, defs::Definition, documentation::{Documentation, HasDocs}, - FileId, FileRange, RootDatabase, SymbolKind, }; use span::Edition; use stdx::never; use syntax::{ + AstNode, SmolStr, SyntaxNode, TextRange, ToSmolStr, ast::{self, HasName}, - format_smolstr, AstNode, SmolStr, SyntaxNode, TextRange, ToSmolStr, + format_smolstr, }; /// `NavigationTarget` represents an element in the editor's UI which you can @@ -953,7 +954,7 @@ fn orig_range_r( mod tests { use expect_test::expect; - use crate::{fixture, Query}; + use crate::{Query, fixture}; #[test] fn test_nav_for_symbol() { diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 06ab4750ac..4e70bf3af3 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -1,7 +1,7 @@ -use hir::{db::DefDatabase, Semantics}; +use hir::{Semantics, db::DefDatabase}; use ide_db::{ - base_db::{Crate, RootQueryDb, Upcast}, FileId, FilePosition, RootDatabase, + base_db::{Crate, RootQueryDb, Upcast}, }; use itertools::Itertools; use syntax::{ diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 069818d50e..71c42cc8b5 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -11,21 +11,22 @@ use hir::{PathResolution, Semantics}; use ide_db::{ + FileId, RootDatabase, defs::{Definition, NameClass, NameRefClass}, search::{ReferenceCategory, SearchScope, UsageSearchResult}, - FileId, RootDatabase, }; use itertools::Itertools; use nohash_hasher::IntMap; use span::Edition; use syntax::{ - ast::{self, HasName}, - match_ast, AstNode, + AstNode, SyntaxKind::*, - SyntaxNode, TextRange, TextSize, T, + SyntaxNode, T, TextRange, TextSize, + ast::{self, HasName}, + match_ast, }; -use crate::{highlight_related, FilePosition, HighlightedRange, NavigationTarget, TryToNav}; +use crate::{FilePosition, HighlightedRange, NavigationTarget, TryToNav, highlight_related}; #[derive(Debug, Clone)] pub struct ReferenceSearchResult { @@ -336,12 +337,12 @@ fn handle_control_flow_keywords( #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::FileId; use span::EditionedFileId; use stdx::format_to; - use crate::{fixture, SearchScope}; + use crate::{SearchScope, fixture}; #[test] fn exclude_tests() { diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index 57d297700a..8fdd460a09 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -6,15 +6,15 @@ use hir::{AsAssocItem, HirFileIdExt, InFile, Semantics}; use ide_db::{ + FileId, FileRange, RootDatabase, base_db::salsa::AsDynDatabase, defs::{Definition, NameClass, NameRefClass}, - rename::{bail, format_err, source_edit_from_references, IdentifierKind}, + rename::{IdentifierKind, bail, format_err, source_edit_from_references}, source_change::SourceChangeBuilder, - FileId, FileRange, RootDatabase, }; use itertools::Itertools; use stdx::{always, never}; -use syntax::{ast, AstNode, SyntaxKind, SyntaxNode, TextRange, TextSize}; +use syntax::{AstNode, SyntaxKind, SyntaxNode, TextRange, TextSize, ast}; use ide_db::text_edit::TextEdit; @@ -446,7 +446,7 @@ fn text_edit_from_self_param(self_param: &ast::SelfParam, new_name: &str) -> Opt #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::source_change::SourceChange; use ide_db::text_edit::TextEdit; use itertools::Itertools; diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index f2cb3c1f99..44dd38ed9c 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -4,28 +4,29 @@ use arrayvec::ArrayVec; use ast::HasName; use cfg::{CfgAtom, CfgExpr}; use hir::{ - db::HirDatabase, sym, symbols::FxIndexSet, AsAssocItem, AttrsWithOwner, HasAttrs, HasCrate, - HasSource, HirFileIdExt, ModPath, Name, PathKind, Semantics, Symbol, + AsAssocItem, AttrsWithOwner, HasAttrs, HasCrate, HasSource, HirFileIdExt, ModPath, Name, + PathKind, Semantics, Symbol, db::HirDatabase, sym, symbols::FxIndexSet, }; use ide_assists::utils::{has_test_related_attribute, test_related_attribute_syn}; use ide_db::{ + FilePosition, FxHashMap, FxIndexMap, RootDatabase, SymbolKind, base_db::RootQueryDb, defs::Definition, documentation::docs_from_attrs, helpers::visit_file_defs, search::{FileReferenceNode, SearchScope}, - FilePosition, FxHashMap, FxIndexMap, RootDatabase, SymbolKind, }; use itertools::Itertools; use smallvec::SmallVec; use span::{Edition, TextSize}; use stdx::format_to; use syntax::{ + SmolStr, SyntaxNode, ToSmolStr, ast::{self, AstNode}, - format_smolstr, SmolStr, SyntaxNode, ToSmolStr, + format_smolstr, }; -use crate::{references, FileId, NavigationTarget, ToNav, TryToNav}; +use crate::{FileId, NavigationTarget, ToNav, TryToNav, references}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct Runnable { @@ -752,7 +753,7 @@ impl UpdateTest { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use crate::fixture; diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs index ce3c4238b5..bd14f830dd 100644 --- a/crates/ide/src/signature_help.rs +++ b/crates/ide/src/signature_help.rs @@ -8,17 +8,17 @@ use hir::{ AssocItem, DisplayTarget, GenericParam, HirDisplay, ModuleDef, PathResolution, Semantics, Trait, }; use ide_db::{ + FilePosition, FxIndexMap, active_parameter::{callable_for_node, generic_def_for_node}, documentation::{Documentation, HasDocs}, - FilePosition, FxIndexMap, }; use span::Edition; use stdx::format_to; use syntax::{ - algo, + AstNode, Direction, NodeOrToken, SyntaxElementChildren, SyntaxNode, SyntaxToken, T, TextRange, + TextSize, ToSmolStr, algo, ast::{self, AstChildren, HasArgList}, - match_ast, AstNode, Direction, NodeOrToken, SyntaxElementChildren, SyntaxNode, SyntaxToken, - TextRange, TextSize, ToSmolStr, T, + match_ast, }; use crate::RootDatabase; @@ -327,7 +327,7 @@ fn signature_help_for_generics( } // These don't have generic args that can be specified hir::GenericDef::Impl(_) | hir::GenericDef::Const(_) | hir::GenericDef::Static(_) => { - return None + return None; } } @@ -695,9 +695,8 @@ fn signature_help_for_tuple_pat_ish( } #[cfg(test)] mod tests { - - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::FilePosition; use stdx::format_to; use test_fixture::ChangeFixture; diff --git a/crates/ide/src/ssr.rs b/crates/ide/src/ssr.rs index 81b5988126..5e439bd38a 100644 --- a/crates/ide/src/ssr.rs +++ b/crates/ide/src/ssr.rs @@ -3,7 +3,7 @@ //! depend on the ide_ssr crate. use ide_assists::{Assist, AssistId, AssistKind, AssistResolveStrategy, GroupLabel}; -use ide_db::{label::Label, source_change::SourceChange, FileRange, RootDatabase}; +use ide_db::{FileRange, RootDatabase, label::Label, source_change::SourceChange}; pub(crate) fn ssr_assists( db: &RootDatabase, @@ -59,8 +59,8 @@ mod tests { use expect_test::expect; use ide_assists::{Assist, AssistResolveStrategy}; use ide_db::{ - base_db::salsa::Durability, symbol_index::SymbolsDatabase, FileRange, FxHashSet, - RootDatabase, + FileRange, FxHashSet, RootDatabase, base_db::salsa::Durability, + symbol_index::SymbolsDatabase, }; use test_fixture::WithFixture; use triomphe::Arc; diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index c156276930..1244132065 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -1,25 +1,25 @@ //! This module provides `StaticIndex` which is used for powering //! read-only code browsers and emitting LSIF -use hir::{db::HirDatabase, Crate, HirFileIdExt, Module, Semantics}; +use hir::{Crate, HirFileIdExt, Module, Semantics, db::HirDatabase}; use ide_db::{ + FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, base_db::{RootQueryDb, SourceDatabase, VfsPath}, defs::Definition, documentation::Documentation, famous_defs::FamousDefs, helpers::get_definition, - FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, }; use span::Edition; -use syntax::{AstNode, SyntaxKind::*, SyntaxNode, TextRange, T}; +use syntax::{AstNode, SyntaxKind::*, SyntaxNode, T, TextRange}; use crate::navigation_target::UpmappingResult; use crate::{ - hover::{hover_for_definition, SubstTyLen}, - inlay_hints::{AdjustmentHintsMode, InlayFieldsToResolve}, - moniker::{def_to_kind, def_to_moniker, MonikerResult, SymbolInformationKind}, - parent_module::crates_for, Analysis, Fold, HoverConfig, HoverResult, InlayHint, InlayHintsConfig, TryToNav, + hover::{SubstTyLen, hover_for_definition}, + inlay_hints::{AdjustmentHintsMode, InlayFieldsToResolve}, + moniker::{MonikerResult, SymbolInformationKind, def_to_kind, def_to_moniker}, + parent_module::crates_for, }; /// A static representation of fully analyzed source code. @@ -307,8 +307,8 @@ impl StaticIndex<'_> { #[cfg(test)] mod tests { - use crate::{fixture, StaticIndex}; - use ide_db::{base_db::VfsPath, FileRange, FxHashSet}; + use crate::{StaticIndex, fixture}; + use ide_db::{FileRange, FxHashSet, base_db::VfsPath}; use syntax::TextSize; use super::VendoredLibrariesConfig; diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs index 52d38041ec..55a0db2d82 100644 --- a/crates/ide/src/status.rs +++ b/crates/ide/src/status.rs @@ -1,5 +1,5 @@ -use ide_db::base_db::{BuiltCrateData, ExtraCrateData}; use ide_db::RootDatabase; +use ide_db::base_db::{BuiltCrateData, ExtraCrateData}; use itertools::Itertools; use span::FileId; use stdx::format_to; diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index ef5d480b49..79e5baf4a7 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -19,24 +19,24 @@ use hir::{ DefWithBody, HirFileIdExt, InFile, InRealFile, MacroFileIdExt, MacroKind, Name, Semantics, }; use ide_db::{ - base_db::salsa::AsDynDatabase, FxHashMap, FxHashSet, Ranker, RootDatabase, SymbolKind, + FxHashMap, FxHashSet, Ranker, RootDatabase, SymbolKind, base_db::salsa::AsDynDatabase, }; use span::EditionedFileId; use syntax::{ - ast::{self, IsString}, AstNode, AstToken, NodeOrToken, SyntaxKind::*, - SyntaxNode, SyntaxToken, TextRange, WalkEvent, T, + SyntaxNode, SyntaxToken, T, TextRange, WalkEvent, + ast::{self, IsString}, }; use crate::{ + FileId, HlMod, HlOperator, HlPunct, HlTag, syntax_highlighting::{ escape::{highlight_escape_byte, highlight_escape_char, highlight_escape_string}, format::highlight_format_string, highlights::Highlights, tags::Highlight, }, - FileId, HlMod, HlOperator, HlPunct, HlTag, }; pub(crate) use html::highlight_as_html; diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index cc02aff2ac..00f5b3264c 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs @@ -1,15 +1,15 @@ //! Syntax highlighting for format macro strings. use ide_db::{ - defs::Definition, - syntax_helpers::format_string::{is_format_string, lex_format_specifiers, FormatSpecifier}, SymbolKind, + defs::Definition, + syntax_helpers::format_string::{FormatSpecifier, is_format_string, lex_format_specifiers}, }; use span::Edition; -use syntax::{ast, AstToken}; +use syntax::{AstToken, ast}; use crate::{ - syntax_highlighting::{highlight::highlight_def, highlights::Highlights}, HlRange, HlTag, + syntax_highlighting::{highlight::highlight_def, highlights::Highlights}, }; pub(super) fn highlight_format_string( diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 2b7c871a38..fb25f00155 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -5,21 +5,21 @@ use std::ops::ControlFlow; use either::Either; use hir::{AsAssocItem, HasVisibility, MacroFileIdExt, Semantics}; use ide_db::{ + FxHashMap, RootDatabase, SymbolKind, defs::{Definition, IdentClass, NameClass, NameRefClass}, syntax_helpers::node_ext::walk_pat, - FxHashMap, RootDatabase, SymbolKind, }; use span::Edition; use stdx::hash_once; use syntax::{ - ast, match_ast, AstNode, AstPtr, AstToken, NodeOrToken, + AstNode, AstPtr, AstToken, NodeOrToken, SyntaxKind::{self, *}, - SyntaxNode, SyntaxNodePtr, SyntaxToken, T, + SyntaxNode, SyntaxNodePtr, SyntaxToken, T, ast, match_ast, }; use crate::{ - syntax_highlighting::tags::{HlOperator, HlPunct}, Highlight, HlMod, HlTag, + syntax_highlighting::tags::{HlOperator, HlPunct}, }; pub(super) fn token( @@ -143,11 +143,7 @@ fn punctuation( let ptr = operator_parent .as_ref() .and_then(|it| AstPtr::try_from_raw(SyntaxNodePtr::new(it))); - if ptr.is_some_and(is_unsafe_node) { - h | HlMod::Unsafe - } else { - h - } + if ptr.is_some_and(is_unsafe_node) { h | HlMod::Unsafe } else { h } } (T![-], PREFIX_EXPR) => { let prefix_expr = @@ -223,11 +219,7 @@ fn punctuation( let is_unsafe = is_unsafe_macro || operator_parent .and_then(|it| { - if ast::ArgList::can_cast(it.kind()) { - it.parent() - } else { - Some(it) - } + if ast::ArgList::can_cast(it.kind()) { it.parent() } else { Some(it) } }) .and_then(|it| AstPtr::try_from_raw(SyntaxNodePtr::new(&it))) .is_some_and(is_unsafe_node); @@ -296,7 +288,7 @@ fn highlight_name_ref( let name_class = match NameRefClass::classify(sema, &name_ref) { Some(name_kind) => name_kind, None if syntactic_name_ref_highlighting => { - return highlight_name_ref_by_syntax(name_ref, sema, krate, is_unsafe_node) + return highlight_name_ref_by_syntax(name_ref, sema, krate, is_unsafe_node); } // FIXME: This is required for helper attributes used by proc-macros, as those do not map down // to anything when used. @@ -818,11 +810,7 @@ fn highlight_name_ref_by_syntax( let h = HlTag::Symbol(SymbolKind::Field); let is_unsafe = ast::Expr::cast(parent) .is_some_and(|it| is_unsafe_node(AstPtr::new(&it).wrap_left())); - if is_unsafe { - h | HlMod::Unsafe - } else { - h.into() - } + if is_unsafe { h | HlMod::Unsafe } else { h.into() } } RECORD_EXPR_FIELD | RECORD_PAT_FIELD => HlTag::Symbol(SymbolKind::Field).into(), PATH_SEGMENT => { diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 6a03da6a6e..cd69a6eb23 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs @@ -8,8 +8,8 @@ use stdx::format_to; use syntax::AstNode; use crate::{ - syntax_highlighting::{highlight, HighlightConfig}, FileId, RootDatabase, + syntax_highlighting::{HighlightConfig, highlight}, }; pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 1be90ad6a1..13922eba19 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -3,21 +3,21 @@ use std::mem; use either::Either; -use hir::{sym, HirFileId, InFile, Semantics}; +use hir::{HirFileId, InFile, Semantics, sym}; use ide_db::{ - active_parameter::ActiveParameter, defs::Definition, documentation::docs_with_rangemap, - rust_doc::is_rust_fence, SymbolKind, + SymbolKind, active_parameter::ActiveParameter, defs::Definition, + documentation::docs_with_rangemap, rust_doc::is_rust_fence, }; use span::EditionedFileId; use syntax::{ - ast::{self, AstNode, IsString, QuoteOffsets}, AstToken, NodeOrToken, SyntaxNode, TextRange, TextSize, + ast::{self, AstNode, IsString, QuoteOffsets}, }; use crate::{ - doc_links::{doc_attributes, extract_definitions_from_docs, resolve_doc_path_for_def}, - syntax_highlighting::{highlights::Highlights, injector::Injector, HighlightConfig}, Analysis, HlMod, HlRange, HlTag, RootDatabase, + doc_links::{doc_attributes, extract_definitions_from_docs, resolve_doc_path_for_def}, + syntax_highlighting::{HighlightConfig, highlights::Highlights, injector::Injector}, }; pub(super) fn ra_fixture( diff --git a/crates/ide/src/syntax_highlighting/injector.rs b/crates/ide/src/syntax_highlighting/injector.rs index a902fd717f..c30f797324 100644 --- a/crates/ide/src/syntax_highlighting/injector.rs +++ b/crates/ide/src/syntax_highlighting/injector.rs @@ -53,11 +53,7 @@ impl Delta { where T: Ord + Sub, { - if to >= from { - Delta::Add(to - from) - } else { - Delta::Sub(from - to) - } + if to >= from { Delta::Add(to - from) } else { Delta::Sub(from - to) } } } diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 9e8af4bac2..4b3fec1d2f 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -1,11 +1,11 @@ use std::time::Instant; -use expect_test::{expect_file, ExpectFile}; +use expect_test::{ExpectFile, expect_file}; use ide_db::SymbolKind; use span::Edition; -use test_utils::{bench, bench_fixture, skip_slow_tests, AssertLinear}; +use test_utils::{AssertLinear, bench, bench_fixture, skip_slow_tests}; -use crate::{fixture, FileRange, HighlightConfig, HlTag, TextRange}; +use crate::{FileRange, HighlightConfig, HlTag, TextRange, fixture}; const HL_CONFIG: HighlightConfig = HighlightConfig { strings: true, diff --git a/crates/ide/src/test_explorer.rs b/crates/ide/src/test_explorer.rs index d22133c856..06cbd50e94 100644 --- a/crates/ide/src/test_explorer.rs +++ b/crates/ide/src/test_explorer.rs @@ -2,10 +2,10 @@ use hir::{Crate, Module, ModuleDef, Semantics}; use ide_db::base_db; -use ide_db::{base_db::RootQueryDb, FileId, RootDatabase}; +use ide_db::{FileId, RootDatabase, base_db::RootQueryDb}; use syntax::TextRange; -use crate::{runnables::runnable_fn, NavigationTarget, Runnable, TryToNav}; +use crate::{NavigationTarget, Runnable, TryToNav, runnables::runnable_fn}; #[derive(Debug)] pub enum TestItemKind { diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs index f583aa801e..bb04fdbe88 100644 --- a/crates/ide/src/typing.rs +++ b/crates/ide/src/typing.rs @@ -16,16 +16,16 @@ mod on_enter; use ide_db::{ - base_db::{salsa::AsDynDatabase, RootQueryDb}, FilePosition, RootDatabase, + base_db::{RootQueryDb, salsa::AsDynDatabase}, }; use span::{Edition, EditionedFileId}; use std::iter; use syntax::{ - algo::{ancestors_at_offset, find_node_at_offset}, - ast::{self, edit::IndentLevel, AstToken}, AstNode, Parse, SourceFile, SyntaxKind, TextRange, TextSize, + algo::{ancestors_at_offset, find_node_at_offset}, + ast::{self, AstToken, edit::IndentLevel}, }; use ide_db::text_edit::TextEdit; diff --git a/crates/ide/src/typing/on_enter.rs b/crates/ide/src/typing/on_enter.rs index 8cadb61040..d684b0efc5 100644 --- a/crates/ide/src/typing/on_enter.rs +++ b/crates/ide/src/typing/on_enter.rs @@ -2,14 +2,14 @@ //! comments, but should handle indent some time in the future as well. use ide_db::base_db::RootQueryDb; -use ide_db::{base_db::salsa::AsDynDatabase, FilePosition, RootDatabase}; +use ide_db::{FilePosition, RootDatabase, base_db::salsa::AsDynDatabase}; use span::EditionedFileId; use syntax::{ - algo::find_node_at_offset, - ast::{self, edit::IndentLevel, AstToken}, AstNode, SmolStr, SourceFile, SyntaxKind::*, SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, + algo::find_node_at_offset, + ast::{self, AstToken, edit::IndentLevel}, }; use ide_db::text_edit::TextEdit; diff --git a/crates/ide/src/view_crate_graph.rs b/crates/ide/src/view_crate_graph.rs index 09f21ecfe4..e878c9afee 100644 --- a/crates/ide/src/view_crate_graph.rs +++ b/crates/ide/src/view_crate_graph.rs @@ -1,9 +1,9 @@ use dot::{Id, LabelText}; use ide_db::{ + FxHashMap, RootDatabase, base_db::{ BuiltCrateData, BuiltDependency, Crate, ExtraCrateData, RootQueryDb, SourceDatabase, }, - FxHashMap, RootDatabase, }; // Feature: View Crate Graph diff --git a/crates/ide/src/view_hir.rs b/crates/ide/src/view_hir.rs index bfdf9d0f33..954917d4c0 100644 --- a/crates/ide/src/view_hir.rs +++ b/crates/ide/src/view_hir.rs @@ -1,6 +1,6 @@ use hir::{DefWithBody, Semantics}; use ide_db::{FilePosition, RootDatabase}; -use syntax::{algo::ancestors_at_offset, ast, AstNode}; +use syntax::{AstNode, algo::ancestors_at_offset, ast}; // Feature: View Hir // diff --git a/crates/ide/src/view_item_tree.rs b/crates/ide/src/view_item_tree.rs index 67c241cbb9..a230b30ed3 100644 --- a/crates/ide/src/view_item_tree.rs +++ b/crates/ide/src/view_item_tree.rs @@ -1,4 +1,4 @@ -use hir::{db::DefDatabase, Semantics}; +use hir::{Semantics, db::DefDatabase}; use ide_db::{FileId, RootDatabase}; use span::EditionedFileId; diff --git a/crates/ide/src/view_memory_layout.rs b/crates/ide/src/view_memory_layout.rs index 02e3b1d500..140ae4265b 100644 --- a/crates/ide/src/view_memory_layout.rs +++ b/crates/ide/src/view_memory_layout.rs @@ -2,9 +2,9 @@ use std::fmt; use hir::{DisplayTarget, Field, HirDisplay, Layout, Semantics, Type}; use ide_db::{ + RootDatabase, defs::Definition, helpers::{get_definition, pick_best_token}, - RootDatabase, }; use syntax::{AstNode, SyntaxKind}; diff --git a/crates/ide/src/view_mir.rs b/crates/ide/src/view_mir.rs index aa4ff64a81..6ca231c7a8 100644 --- a/crates/ide/src/view_mir.rs +++ b/crates/ide/src/view_mir.rs @@ -1,6 +1,6 @@ use hir::{DefWithBody, Semantics}; use ide_db::{FilePosition, RootDatabase}; -use syntax::{algo::ancestors_at_offset, ast, AstNode}; +use syntax::{AstNode, algo::ancestors_at_offset, ast}; // Feature: View Mir // diff --git a/crates/ide/src/view_syntax_tree.rs b/crates/ide/src/view_syntax_tree.rs index 407720864b..ecd93e8b28 100644 --- a/crates/ide/src/view_syntax_tree.rs +++ b/crates/ide/src/view_syntax_tree.rs @@ -1,13 +1,13 @@ use hir::Semantics; use ide_db::{ - line_index::{LineCol, LineIndex}, FileId, LineIndexDatabase, RootDatabase, + line_index::{LineCol, LineIndex}, }; use span::{TextRange, TextSize}; use stdx::format_to; use syntax::{ - ast::{self, IsString}, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, WalkEvent, + ast::{self, IsString}, }; use triomphe::Arc; diff --git a/crates/intern/src/lib.rs b/crates/intern/src/lib.rs index 58327419f6..6548bb1826 100644 --- a/crates/intern/src/lib.rs +++ b/crates/intern/src/lib.rs @@ -10,7 +10,7 @@ use std::{ }; use dashmap::{DashMap, SharedValue}; -use hashbrown::{hash_map::RawEntryMut, HashMap}; +use hashbrown::{HashMap, hash_map::RawEntryMut}; use rustc_hash::FxHasher; use triomphe::Arc; @@ -21,7 +21,7 @@ type Guard = dashmap::RwLockWriteGuard< >; mod symbol; -pub use self::symbol::{symbols as sym, Symbol}; +pub use self::symbol::{Symbol, symbols as sym}; pub struct Interned { arc: Arc, diff --git a/crates/intern/src/symbol.rs b/crates/intern/src/symbol.rs index f6a74d9741..f02fb6d14f 100644 --- a/crates/intern/src/symbol.rs +++ b/crates/intern/src/symbol.rs @@ -11,7 +11,7 @@ use std::{ }; use dashmap::{DashMap, SharedValue}; -use hashbrown::{hash_map::RawEntryMut, HashMap}; +use hashbrown::{HashMap, hash_map::RawEntryMut}; use rustc_hash::FxHasher; use triomphe::Arc; @@ -160,7 +160,7 @@ impl Symbol { SharedValue::new(()), ) .0 - .0, + .0, ), }, } @@ -236,7 +236,7 @@ impl Symbol { RawEntryMut::Vacant(_) => unreachable!(), } .0 - .0; + .0; // SAFETY: We're dropping, we have ownership. ManuallyDrop::into_inner(unsafe { ptr.try_as_arc_owned().unwrap() }); debug_assert_eq!(Arc::count(arc), 1); diff --git a/crates/intern/src/symbol/symbols.rs b/crates/intern/src/symbol/symbols.rs index 6b77c72cee..cc9b3ef457 100644 --- a/crates/intern/src/symbol/symbols.rs +++ b/crates/intern/src/symbol/symbols.rs @@ -7,8 +7,8 @@ use dashmap::{DashMap, SharedValue}; use rustc_hash::FxHasher; use crate::{ - symbol::{SymbolProxy, TaggedArcPtr}, Symbol, + symbol::{SymbolProxy, TaggedArcPtr}, }; macro_rules! define_symbols { diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index 01d29d88df..243619bb09 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -4,23 +4,24 @@ // to run rust-analyzer as a library. use std::{collections::hash_map::Entry, mem, path::Path, sync}; -use crossbeam_channel::{unbounded, Receiver}; +use crossbeam_channel::{Receiver, unbounded}; use hir_expand::proc_macro::{ ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacroLoadResult, ProcMacrosBuilder, }; use ide_db::{ + ChangeWithProcMacros, FxHashMap, RootDatabase, base_db::{CrateGraphBuilder, Env, SourceRoot, SourceRootId}, - prime_caches, ChangeWithProcMacros, FxHashMap, RootDatabase, + prime_caches, }; use itertools::Itertools; use proc_macro_api::{MacroDylib, ProcMacroClient}; use project_model::{CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace}; use span::Span; use vfs::{ + AbsPath, AbsPathBuf, VfsPath, file_set::FileSetConfig, loader::{Handle, LoadingProgress}, - AbsPath, AbsPathBuf, VfsPath, }; #[derive(Debug)] @@ -626,7 +627,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 2, 3] }; let mut vc = src.source_root_parent_map().into_iter().collect::>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(2), SourceRootId(1)), (SourceRootId(3), SourceRootId(1))]) } @@ -641,7 +642,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 3] }; let mut vc = src.source_root_parent_map().into_iter().collect::>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(3), SourceRootId(1)),]) } @@ -656,7 +657,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 3] }; let mut vc = src.source_root_parent_map().into_iter().collect::>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(3), SourceRootId(1)),]) } @@ -672,7 +673,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1] }; let mut vc = src.source_root_parent_map().into_iter().collect::>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(1), SourceRootId(0)),]) } @@ -688,7 +689,7 @@ mod tests { let fsc = builder.build(); let src = SourceRootConfig { fsc, local_filesets: vec![0, 1] }; let mut vc = src.source_root_parent_map().into_iter().collect::>(); - vc.sort_by(|x, y| x.0 .0.cmp(&y.0 .0)); + vc.sort_by(|x, y| x.0.0.cmp(&y.0.0)); assert_eq!(vc, vec![(SourceRootId(1), SourceRootId(0)),]) } diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs index 89c3003003..db75dceae1 100644 --- a/crates/mbe/src/benchmark.rs +++ b/crates/mbe/src/benchmark.rs @@ -5,18 +5,19 @@ use rustc_hash::FxHashMap; use span::{Edition, Span}; use stdx::itertools::Itertools; use syntax::{ - ast::{self, HasName}, AstNode, + ast::{self, HasName}, }; use syntax_bridge::{ - dummy_test_span_utils::{DummyTestSpanMap, DUMMY}, - syntax_node_to_token_tree, DocCommentDesugarMode, + DocCommentDesugarMode, + dummy_test_span_utils::{DUMMY, DummyTestSpanMap}, + syntax_node_to_token_tree, }; use test_utils::{bench, bench_fixture, skip_slow_tests}; use crate::{ - parser::{MetaVarKind, Op, RepeatKind, Separator}, DeclarativeMacro, + parser::{MetaVarKind, Op, RepeatKind, Separator}, }; #[test] @@ -53,7 +54,7 @@ fn benchmark_expand_macro_rules() { .map(|(id, tt)| { let res = rules[&id].expand(&tt, |_| (), DUMMY, Edition::CURRENT); assert!(res.err.is_none()); - res.value.0 .0.len() + res.value.0.0.len() }) .sum() }; diff --git a/crates/mbe/src/expander.rs b/crates/mbe/src/expander.rs index 5539a88c70..f910f9f9d7 100644 --- a/crates/mbe/src/expander.rs +++ b/crates/mbe/src/expander.rs @@ -9,7 +9,7 @@ use intern::Symbol; use rustc_hash::FxHashMap; use span::{Edition, Span}; -use crate::{parser::MetaVarKind, ExpandError, ExpandErrorKind, ExpandResult, MatchedArmIndex}; +use crate::{ExpandError, ExpandErrorKind, ExpandResult, MatchedArmIndex, parser::MetaVarKind}; pub(crate) fn expand_rules( rules: &[crate::Rule], diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index b7f25aa380..940aaacb02 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -61,19 +61,19 @@ use std::{rc::Rc, sync::Arc}; -use intern::{sym, Symbol}; -use smallvec::{smallvec, SmallVec}; +use intern::{Symbol, sym}; +use smallvec::{SmallVec, smallvec}; use span::{Edition, Span}; use tt::{ - iter::{TtElement, TtIter}, DelimSpan, + iter::{TtElement, TtIter}, }; use crate::{ + ExpandError, ExpandErrorKind, MetaTemplate, ValueResult, expander::{Binding, Bindings, ExpandResult, Fragment}, expect_fragment, parser::{ExprKind, MetaVarKind, Op, RepeatKind, Separator}, - ExpandError, ExpandErrorKind, MetaTemplate, ValueResult, }; impl<'a> Bindings<'a> { diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs index 7710ea7938..b1f542eac7 100644 --- a/crates/mbe/src/expander/transcriber.rs +++ b/crates/mbe/src/expander/transcriber.rs @@ -1,14 +1,14 @@ //! Transcriber takes a template, like `fn $ident() {}`, a set of bindings like //! `$ident => foo`, interpolates variables in the template, to get `fn foo() {}` -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use span::{Edition, Span}; -use tt::{iter::TtElement, Delimiter, TopSubtreeBuilder}; +use tt::{Delimiter, TopSubtreeBuilder, iter::TtElement}; use crate::{ + ExpandError, ExpandErrorKind, ExpandResult, MetaTemplate, expander::{Binding, Bindings, Fragment}, parser::{ConcatMetaVarExprElem, MetaVarKind, Op, RepeatKind, Separator}, - ExpandError, ExpandErrorKind, ExpandResult, MetaTemplate, }; impl<'t> Bindings<'t> { @@ -331,7 +331,10 @@ fn expand_subtree( } _ => { if err.is_none() { - err = Some(ExpandError::binding_error(var.span, "metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`")) + err = Some(ExpandError::binding_error( + var.span, + "metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`", + )) } continue; } diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 6bc019bf33..9f9fa36abd 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -23,8 +23,8 @@ mod tests; use span::{Edition, Span, SyntaxContext}; use syntax_bridge::to_parser_input; -use tt::iter::TtIter; use tt::DelimSpan; +use tt::iter::TtIter; use std::fmt; use std::sync::Arc; diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs index 9d91387a07..7be49cbc7e 100644 --- a/crates/mbe/src/parser.rs +++ b/crates/mbe/src/parser.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use arrayvec::ArrayVec; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use span::{Edition, Span, SyntaxContext}; use tt::iter::{TtElement, TtIter}; @@ -194,7 +194,7 @@ fn next_op( let mut res = ArrayVec::new(); res.push(*p); Box::new(res) - })) + })); } Some(it) => it, }; @@ -212,13 +212,13 @@ fn next_op( Mode::Pattern => { return Err(ParseError::unexpected( "`${}` metavariable expressions are not allowed in matchers", - )) + )); } }, _ => { return Err(ParseError::expected( "expected `$()` repetition or `${}` expression", - )) + )); } }, TtElement::Leaf(leaf) => match leaf { @@ -246,7 +246,7 @@ fn next_op( Mode::Pattern => { return Err(ParseError::unexpected( "`$$` is not allowed on the pattern side", - )) + )); } Mode::Template => Op::Punct({ let mut res = ArrayVec::new(); @@ -255,7 +255,7 @@ fn next_op( }), }, tt::Leaf::Punct(_) | tt::Leaf::Literal(_) => { - return Err(ParseError::expected("expected ident")) + return Err(ParseError::expected("expected ident")); } }, } @@ -348,7 +348,7 @@ fn parse_repeat(src: &mut TtIter<'_, Span>) -> Result<(Option, Repeat }; match tt { tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { - return Err(ParseError::InvalidRepeat) + return Err(ParseError::InvalidRepeat); } tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), diff --git a/crates/parser/src/event.rs b/crates/parser/src/event.rs index b197b086f3..5be9cb2a24 100644 --- a/crates/parser/src/event.rs +++ b/crates/parser/src/event.rs @@ -5,8 +5,8 @@ use std::mem; use crate::{ - output::Output, SyntaxKind::{self, *}, + output::Output, }; /// `Parser` produces a flat list of `Event`s. diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index fe6b904bd8..8ddf50db04 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -39,9 +39,9 @@ mod patterns; mod types; use crate::{ - parser::{CompletedMarker, Marker, Parser}, SyntaxKind::{self, *}, - TokenSet, T, + T, TokenSet, + parser::{CompletedMarker, Marker, Parser}, }; pub(crate) mod entry { diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index fe1316c9bf..5b0085fc2a 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -4,8 +4,8 @@ use crate::grammar::attributes::ATTRIBUTE_FIRST; use super::*; +pub(super) use atom::{LITERAL_FIRST, literal}; pub(crate) use atom::{block_expr, match_arm_list}; -pub(super) use atom::{literal, LITERAL_FIRST}; #[derive(PartialEq, Eq)] pub(super) enum Semicolon { diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index b058686276..36a363afe9 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -5,11 +5,11 @@ use std::cell::Cell; use drop_bomb::DropBomb; use crate::{ - event::Event, - input::Input, Edition, SyntaxKind::{self, EOF, ERROR, TOMBSTONE}, - TokenSet, T, + T, TokenSet, + event::Event, + input::Input, }; /// `Parser` struct provides the low-level API for diff --git a/crates/paths/src/lib.rs b/crates/paths/src/lib.rs index 3d722b1ff1..2c6a82bf0c 100644 --- a/crates/paths/src/lib.rs +++ b/crates/paths/src/lib.rs @@ -248,7 +248,9 @@ impl AbsPath { } pub fn canonicalize(&self) -> ! { - panic!("We explicitly do not provide canonicalization API, as that is almost always a wrong solution, see #14430") + panic!( + "We explicitly do not provide canonicalization API, as that is almost always a wrong solution, see #14430" + ) } /// Equivalent of [`Utf8Path::strip_prefix`] for `AbsPath`. diff --git a/crates/proc-macro-api/src/legacy_protocol/msg.rs b/crates/proc-macro-api/src/legacy_protocol/msg.rs index 4178b04767..3d84dc8b24 100644 --- a/crates/proc-macro-api/src/legacy_protocol/msg.rs +++ b/crates/proc-macro-api/src/legacy_protocol/msg.rs @@ -10,7 +10,7 @@ use serde_derive::{Deserialize, Serialize}; use crate::ProcMacroKind; pub use self::flat::{ - deserialize_span_data_index_map, serialize_span_data_index_map, FlatTree, SpanDataIndexMap, + FlatTree, SpanDataIndexMap, deserialize_span_data_index_map, serialize_span_data_index_map, }; pub use span::TokenId; @@ -158,7 +158,7 @@ type ProtocolWrite = for<'o, 'msg> fn(out: &'o mut W, msg: &'msg str) #[cfg(test)] mod tests { - use intern::{sym, Symbol}; + use intern::{Symbol, sym}; use span::{Edition, ErasedFileAstId, Span, SpanAnchor, SyntaxContext, TextRange, TextSize}; use tt::{ Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, Spacing, TopSubtree, diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs index 571ceaabe6..11acbd4e64 100644 --- a/crates/proc-macro-api/src/lib.rs +++ b/crates/proc-macro-api/src/lib.rs @@ -17,9 +17,9 @@ use std::{fmt, io, sync::Arc, time::SystemTime}; use crate::{ legacy_protocol::msg::{ - deserialize_span_data_index_map, flat::serialize_span_data_index_map, ExpandMacro, - ExpandMacroData, ExpnGlobals, FlatTree, PanicMessage, Request, Response, SpanDataIndexMap, - HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT, + ExpandMacro, ExpandMacroData, ExpnGlobals, FlatTree, HAS_GLOBAL_SPANS, PanicMessage, + RUST_ANALYZER_SPAN_SUPPORT, Request, Response, SpanDataIndexMap, + deserialize_span_data_index_map, flat::serialize_span_data_index_map, }, process::ProcMacroServerProcess, }; @@ -102,7 +102,7 @@ impl ProcMacroClient { pub fn spawn( process_path: &AbsPath, env: impl IntoIterator, impl AsRef)> - + Clone, + + Clone, ) -> io::Result { let process = ProcMacroServerProcess::run(process_path, env)?; Ok(ProcMacroClient { process: Arc::new(process), path: process_path.to_owned() }) diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs index d998b23d3b..dd1f5a2420 100644 --- a/crates/proc-macro-api/src/process.rs +++ b/crates/proc-macro-api/src/process.rs @@ -11,14 +11,14 @@ use paths::AbsPath; use stdx::JodChild; use crate::{ + ProcMacroKind, ServerError, legacy_protocol::{ json::{read_json, write_json}, msg::{ - Message, Request, Response, ServerConfig, SpanMode, CURRENT_API_VERSION, - RUST_ANALYZER_SPAN_SUPPORT, + CURRENT_API_VERSION, Message, RUST_ANALYZER_SPAN_SUPPORT, Request, Response, + ServerConfig, SpanMode, }, }, - ProcMacroKind, ServerError, }; #[derive(Debug)] @@ -43,7 +43,7 @@ impl ProcMacroServerProcess { pub(crate) fn run( process_path: &AbsPath, env: impl IntoIterator, impl AsRef)> - + Clone, + + Clone, ) -> io::Result { let create_srv = || { let mut process = Process::run(process_path, env.clone())?; diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs index de59e88aac..0e6b18ecae 100644 --- a/crates/proc-macro-srv-cli/src/main.rs +++ b/crates/proc-macro-srv-cli/src/main.rs @@ -14,7 +14,9 @@ use main_loop::run; fn main() -> std::io::Result<()> { let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE"); if v.is_err() { - eprintln!("This is an IDE implementation detail, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE."); + eprintln!( + "This is an IDE implementation detail, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE." + ); eprintln!( "Note that this tool's API is highly unstable and may break without prior notice" ); diff --git a/crates/proc-macro-srv-cli/src/main_loop.rs b/crates/proc-macro-srv-cli/src/main_loop.rs index 569070766f..f54dff1f2d 100644 --- a/crates/proc-macro-srv-cli/src/main_loop.rs +++ b/crates/proc-macro-srv-cli/src/main_loop.rs @@ -4,8 +4,8 @@ use std::io; use proc_macro_api::legacy_protocol::{ json::{read_json, write_json}, msg::{ - self, deserialize_span_data_index_map, serialize_span_data_index_map, ExpandMacroData, - ExpnGlobals, Message, SpanMode, TokenId, CURRENT_API_VERSION, + self, CURRENT_API_VERSION, ExpandMacroData, ExpnGlobals, Message, SpanMode, TokenId, + deserialize_span_data_index_map, serialize_span_data_index_map, }, }; use proc_macro_srv::EnvSnapshot; diff --git a/crates/proc-macro-srv/src/dylib.rs b/crates/proc-macro-srv/src/dylib.rs index cbf7a277bf..245b064387 100644 --- a/crates/proc-macro-srv/src/dylib.rs +++ b/crates/proc-macro-srv/src/dylib.rs @@ -9,7 +9,7 @@ use libloading::Library; use object::Object; use paths::{Utf8Path, Utf8PathBuf}; -use crate::{proc_macros::ProcMacros, server_impl::TopSubtree, ProcMacroKind, ProcMacroSrvSpan}; +use crate::{ProcMacroKind, ProcMacroSrvSpan, proc_macros::ProcMacros, server_impl::TopSubtree}; /// Loads dynamic library in platform dependent manner. /// diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs index f28821b4af..4f817b6bc0 100644 --- a/crates/proc-macro-srv/src/lib.rs +++ b/crates/proc-macro-srv/src/lib.rs @@ -30,7 +30,7 @@ mod proc_macros; mod server_impl; use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, env, ffi::OsString, fs, diff --git a/crates/proc-macro-srv/src/proc_macros.rs b/crates/proc-macro-srv/src/proc_macros.rs index 58f5e80dc4..a5fa7f6e71 100644 --- a/crates/proc-macro-srv/src/proc_macros.rs +++ b/crates/proc-macro-srv/src/proc_macros.rs @@ -5,7 +5,7 @@ use proc_macro::bridge; use libloading::Library; use crate::{ - dylib::LoadProcMacroDylibError, server_impl::TopSubtree, ProcMacroKind, ProcMacroSrvSpan, + ProcMacroKind, ProcMacroSrvSpan, dylib::LoadProcMacroDylibError, server_impl::TopSubtree, }; #[repr(transparent)] diff --git a/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs b/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs index f7cb0ab465..62540183cb 100644 --- a/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs +++ b/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs @@ -11,10 +11,10 @@ use std::{ use intern::Symbol; use proc_macro::bridge::{self, server}; -use span::{FileId, Span, FIXUP_ERASED_FILE_AST_ID_MARKER}; +use span::{FIXUP_ERASED_FILE_AST_ID_MARKER, FileId, Span}; use tt::{TextRange, TextSize}; -use crate::server_impl::{literal_kind_to_internal, token_stream::TokenStreamBuilder, TopSubtree}; +use crate::server_impl::{TopSubtree, literal_kind_to_internal, token_stream::TokenStreamBuilder}; mod tt { pub use tt::*; diff --git a/crates/proc-macro-srv/src/server_impl/token_id.rs b/crates/proc-macro-srv/src/server_impl/token_id.rs index 409cf3cc78..d0c7f23a38 100644 --- a/crates/proc-macro-srv/src/server_impl/token_id.rs +++ b/crates/proc-macro-srv/src/server_impl/token_id.rs @@ -5,7 +5,7 @@ use std::ops::{Bound, Range}; use intern::Symbol; use proc_macro::bridge::{self, server}; -use crate::server_impl::{literal_kind_to_internal, token_stream::TokenStreamBuilder, TopSubtree}; +use crate::server_impl::{TopSubtree, literal_kind_to_internal, token_stream::TokenStreamBuilder}; mod tt { pub use span::TokenId; diff --git a/crates/proc-macro-srv/src/server_impl/token_stream.rs b/crates/proc-macro-srv/src/server_impl/token_stream.rs index 645f7e7c59..a3cf76d37b 100644 --- a/crates/proc-macro-srv/src/server_impl/token_stream.rs +++ b/crates/proc-macro-srv/src/server_impl/token_stream.rs @@ -2,7 +2,7 @@ use proc_macro::bridge; -use crate::server_impl::{delim_to_external, literal_kind_to_external, TopSubtree}; +use crate::server_impl::{TopSubtree, delim_to_external, literal_kind_to_external}; #[derive(Clone)] pub struct TokenStream { diff --git a/crates/proc-macro-srv/src/tests/utils.rs b/crates/proc-macro-srv/src/tests/utils.rs index 584a27468f..a476a70a74 100644 --- a/crates/proc-macro-srv/src/tests/utils.rs +++ b/crates/proc-macro-srv/src/tests/utils.rs @@ -4,7 +4,7 @@ use expect_test::Expect; use span::{EditionedFileId, ErasedFileAstId, FileId, Span, SpanAnchor, SyntaxContext, TokenId}; use tt::TextRange; -use crate::{dylib, proc_macro_test_dylib_path, EnvSnapshot, ProcMacroSrv}; +use crate::{EnvSnapshot, ProcMacroSrv, dylib, proc_macro_test_dylib_path}; fn parse_string(call_site: TokenId, src: &str) -> crate::server_impl::TokenStream { crate::server_impl::TokenStream::with_subtree(crate::server_impl::TopSubtree( diff --git a/crates/project-model/src/build_dependencies.rs b/crates/project-model/src/build_dependencies.rs index b0939229f9..aa0099d0e5 100644 --- a/crates/project-model/src/build_dependencies.rs +++ b/crates/project-model/src/build_dependencies.rs @@ -9,7 +9,7 @@ use std::{cell::RefCell, io, mem, process::Command}; use base_db::Env; -use cargo_metadata::{camino::Utf8Path, Message}; +use cargo_metadata::{Message, camino::Utf8Path}; use cfg::CfgAtom; use itertools::Itertools; use la_arena::ArenaMap; @@ -19,8 +19,8 @@ use serde::Deserialize as _; use toolchain::Tool; use crate::{ - utf8_stdout, CargoConfig, CargoFeatures, CargoWorkspace, InvocationStrategy, ManifestPath, - Package, Sysroot, TargetKind, + CargoConfig, CargoFeatures, CargoWorkspace, InvocationStrategy, ManifestPath, Package, Sysroot, + TargetKind, utf8_stdout, }; /// Output of the build script and proc-macro building steps for a workspace. diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index 014028a0b6..054312835a 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -596,7 +596,7 @@ impl CargoWorkspace { // this pkg is inside this cargo workspace, fallback to workspace root if found { return Some(vec![ - ManifestPath::try_from(self.workspace_root().join("Cargo.toml")).ok()? + ManifestPath::try_from(self.workspace_root().join("Cargo.toml")).ok()?, ]); } diff --git a/crates/project-model/src/env.rs b/crates/project-model/src/env.rs index 37fffba295..08d51c0d08 100644 --- a/crates/project-model/src/env.rs +++ b/crates/project-model/src/env.rs @@ -4,7 +4,7 @@ use paths::Utf8Path; use rustc_hash::FxHashMap; use toolchain::Tool; -use crate::{utf8_stdout, ManifestPath, PackageData, Sysroot, TargetKind}; +use crate::{ManifestPath, PackageData, Sysroot, TargetKind, utf8_stdout}; /// Recreates the compile-time environment variables that Cargo sets. /// diff --git a/crates/project-model/src/lib.rs b/crates/project-model/src/lib.rs index 21a993c5a5..436af64cf1 100644 --- a/crates/project-model/src/lib.rs +++ b/crates/project-model/src/lib.rs @@ -48,12 +48,12 @@ mod tests; use std::{ fmt, - fs::{self, read_dir, ReadDir}, + fs::{self, ReadDir, read_dir}, io, process::Command, }; -use anyhow::{bail, format_err, Context}; +use anyhow::{Context, bail, format_err}; use paths::{AbsPath, AbsPathBuf, Utf8PathBuf}; use rustc_hash::FxHashSet; @@ -102,7 +102,9 @@ impl ProjectManifest { if path.extension().unwrap_or_default() == "rs" { return Ok(ProjectManifest::CargoScript(path)); } - bail!("project root must point to a Cargo.toml, rust-project.json or