From 29619c07c2113f5c6d4650587d2601a0b2436a28 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Wed, 26 Feb 2025 19:29:37 +0100 Subject: [PATCH 1/5] 2024 --- Cargo.toml | 34 ++++---- crates/hir-def/src/expr_store/pretty.rs | 2 +- crates/hir-def/src/item_tree/lower.rs | 11 ++- crates/hir-def/src/test_db.rs | 14 ++-- crates/hir-expand/src/builtin/derive_macro.rs | 47 ++++++----- crates/hir-expand/src/builtin/fn_macro.rs | 37 +++++---- crates/hir-expand/src/builtin/quote.rs | 11 ++- crates/hir-ty/src/autoderef.rs | 6 +- crates/hir-ty/src/builder.rs | 18 ++-- crates/hir-ty/src/chalk_db.rs | 21 ++--- crates/hir-ty/src/infer/unify.rs | 26 +++--- crates/hir-ty/src/mir/eval.rs | 47 +++++------ crates/hir-ty/src/mir/eval/shim/simd.rs | 8 +- crates/hir-ty/src/mir/lower.rs | 38 ++++----- crates/hir/src/lib.rs | 83 +++++++++---------- crates/hir/src/semantics.rs | 28 +++---- crates/ide-diagnostics/src/lib.rs | 10 +-- crates/ide/src/inlay_hints/lifetime.rs | 17 ++-- crates/ide/src/signature_help.rs | 18 ++-- .../proc-macro-srv/proc-macro-test/Cargo.toml | 2 +- .../proc-macro-test/imp/Cargo.toml | 2 +- crates/project-model/src/project_json.rs | 4 +- crates/project-model/src/sysroot.rs | 22 ++--- crates/ra-salsa/Cargo.toml | 2 +- crates/ra-salsa/ra-salsa-macros/Cargo.toml | 2 +- crates/ra-salsa/tests/parallel/stress.rs | 20 ++--- crates/rust-analyzer/src/bin/main.rs | 10 ++- crates/rust-analyzer/src/lsp/to_proto.rs | 24 ++---- .../rust-analyzer/tests/slow-tests/support.rs | 22 ++--- crates/syntax/fuzz/Cargo.toml | 4 +- crates/syntax/src/ast/node_ext.rs | 31 +++---- crates/syntax/src/ast/token_ext.rs | 22 ++--- crates/toolchain/src/lib.rs | 24 +++--- docs/book/book.toml | 2 +- lib/la-arena/Cargo.toml | 4 +- lib/line-index/Cargo.toml | 3 +- lib/lsp-server/Cargo.toml | 3 +- xtask/Cargo.toml | 7 +- xtask/src/dist.rs | 11 ++- xtask/src/release.rs | 2 +- 40 files changed, 327 insertions(+), 372 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 19ae35142fa2..8ec642ee3aa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"] resolver = "2" [workspace.package] -rust-version = "1.84" -edition = "2021" +rust-version = "1.85" +edition = "2024" license = "MIT OR Apache-2.0" authors = ["rust-analyzer team"] repository = "https://github.com/rust-lang/rust-analyzer" @@ -115,7 +115,7 @@ dot = "0.1.4" either = "1.9.0" expect-test = "1.4.0" hashbrown = { version = "0.14", features = [ - "inline-more", + "inline-more", ], default-features = false } indexmap = "2.1.0" itertools = "0.12.0" @@ -125,11 +125,11 @@ memmap2 = "0.5.4" nohash-hasher = "0.2.0" oorandom = "11.1.3" object = { version = "0.33.0", default-features = false, features = [ - "std", - "read_core", - "elf", - "macho", - "pe", + "std", + "read_core", + "elf", + "macho", + "pe", ] } process-wrap = { version = "8.0.2", features = ["std"] } pulldown-cmark-to-cmark = "10.0.4" @@ -141,21 +141,21 @@ serde = { version = "1.0.192" } serde_derive = { version = "1.0.192" } serde_json = "1.0.108" smallvec = { version = "1.10.0", features = [ - "const_new", - "union", - "const_generics", + "const_new", + "union", + "const_generics", ] } smol_str = "0.3.2" text-size = "1.1.1" tracing = "0.1.40" tracing-tree = "0.3.0" tracing-subscriber = { version = "0.3.18", default-features = false, features = [ - "registry", - "fmt", - "local-time", - "std", - "time", - "tracing-log", + "registry", + "fmt", + "local-time", + "std", + "time", + "tracing-log", ] } triomphe = { version = "0.1.14", default-features = false, features = ["std"] } url = "2.3.1" diff --git a/crates/hir-def/src/expr_store/pretty.rs b/crates/hir-def/src/expr_store/pretty.rs index 82ad756dc2c6..cc6d200051c3 100644 --- a/crates/hir-def/src/expr_store/pretty.rs +++ b/crates/hir-def/src/expr_store/pretty.rs @@ -82,7 +82,7 @@ pub(super) fn print_body_hir( p.buf.push_str(", "); }); // remove the last ", " in param list - if body.params.len() > 0 { + if !body.params.is_empty() { p.buf.truncate(p.buf.len() - 2); } p.buf.push(')'); diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index 71848845a84d..30f1e0aaaba7 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, SyntaxContextId}; 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, TypeParamData, TypeParamProvenance}, item_tree::{ @@ -38,7 +39,6 @@ use crate::{ TypesMap, TypesSourceMap, }, visibility::RawVisibility, - LocalLifetimeParamId, LocalTypeOrConstParamId, }; fn id(index: Idx) -> FileItemTreeId { @@ -938,8 +938,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(); + 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/test_db.rs b/crates/hir-def/src/test_db.rs index 54e6c1fd206d..67a3dfa31af3 100644 --- a/crates/hir-def/src/test_db.rs +++ b/crates/hir-def/src/test_db.rs @@ -3,19 +3,19 @@ use std::{fmt, panic, sync::Mutex}; use base_db::{ - ra_salsa::{self, Durability}, AnchoredPath, CrateId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, + ra_salsa::{self, Durability}, }; -use hir_expand::{db::ExpandDatabase, files::FilePosition, InFile}; +use hir_expand::{InFile, db::ExpandDatabase, files::FilePosition}; 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, }; #[ra_salsa::database( @@ -205,10 +205,10 @@ impl TestDB { let def_with_body = fn_def?.into(); let (_, source_map) = self.body_with_source_map(def_with_body); let scopes = self.expr_scopes(def_with_body); - let root = self.parse(position.file_id); + let root_syntax_node = self.parse(position.file_id).syntax_node(); - let scope_iter = algo::ancestors_at_offset(&root.syntax_node(), position.offset) - .filter_map(|node| { + let scope_iter = + algo::ancestors_at_offset(&root_syntax_node, position.offset).filter_map(|node| { let block = ast::BlockExpr::cast(node)?; let expr = ast::Expr::from(block); let expr_id = source_map diff --git a/crates/hir-expand/src/builtin/derive_macro.rs b/crates/hir-expand/src/builtin/derive_macro.rs index 28b681213944..5a54d1ed138e 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, SyntaxContextId}; @@ -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, }; @@ -117,7 +118,7 @@ impl VariantShape { quote! {span => #it : #mapped , } }); quote! {span => - #path { ##fields } + #path { # #fields } } } &VariantShape::Tuple(n) => { @@ -128,7 +129,7 @@ impl VariantShape { } }); quote! {span => - #path ( ##fields ) + #path ( # #fields ) } } VariantShape::Unit => path, @@ -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( @@ -523,7 +524,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 +573,7 @@ fn clone_expand( quote! {span => fn clone(&self) -> Self { match self { - ##arms + # #arms } } } @@ -650,7 +651,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 +661,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 +704,7 @@ fn debug_expand( quote! {span => fn fmt(&self, f: &mut #krate::fmt::Formatter) -> #krate::fmt::Result { match self { - ##arms + # #arms } } } @@ -736,7 +737,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 +755,7 @@ fn hash_expand( fn hash(&self, ra_expand_state: &mut H) { #check_discriminant match self { - ##arms + # #arms } } } @@ -803,7 +804,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 +815,7 @@ fn partial_eq_expand( quote! {span => fn eq(&self, other: &Self) -> bool { match (self, other) { - ##arms + # #arms _unused #fat_arrow false } } @@ -891,7 +892,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 +962,7 @@ fn partial_ord_expand( right, quote! {span => match (self, other) { - ##arms + # #arms _unused #fat_arrow #krate::option::Option::Some(#krate::cmp::Ordering::Equal) } }, @@ -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 55242ab3e57d..796d10d48da0 100644 --- a/crates/hir-expand/src/builtin/fn_macro.rs +++ b/crates/hir-expand/src/builtin/fn_macro.rs @@ -3,24 +3,24 @@ use base_db::AnchoredPath; use cfg::CfgExpr; use either::Either; -use intern::{sym, Symbol}; -use mbe::{expect_fragment, DelimiterKind}; +use intern::{Symbol, sym}; +use mbe::{DelimiterKind, expect_fragment}; use span::{Edition, EditionedFileId, 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 { @@ -237,9 +237,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 =>{ @@ -424,12 +424,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"), }; @@ -731,7 +734,7 @@ fn include_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: span, close: span }), e, - ) + ); } }; let span_map = db.real_span_map(file_id); @@ -784,7 +787,7 @@ fn include_str_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: span, close: span }), e, - ) + ); } }; @@ -822,7 +825,7 @@ fn env_expand( return ExpandResult::new( tt::TopSubtree::empty(DelimSpan { open: span, close: span }), e, - ) + ); } }; @@ -860,7 +863,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 9b637fc76844..c9b56ff59513 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; @@ -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)*); }}; @@ -226,7 +226,7 @@ mod tests { use ::tt::IdentIsRaw; use expect_test::expect; use intern::Symbol; - use span::{Edition, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID}; + use span::{Edition, ROOT_ERASED_FILE_AST_ID, SpanAnchor, SyntaxContextId}; 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-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs index 171ba001c4a7..17f4990ce7d7 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; @@ -35,7 +35,7 @@ pub fn autoderef( db: &dyn HirDatabase, env: Arc, ty: Canonical, -) -> impl Iterator { +) -> impl Iterator + use<'_> { let mut table = InferenceTable::new(db, env); let ty = table.instantiate_canonical(ty); let mut autoderef = Autoderef::new_no_tracking(&mut table, ty, false, false); diff --git a/crates/hir-ty/src/builder.rs b/crates/hir-ty/src/builder.rs index 76d9c60f6f90..2898ab7b49f5 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)] @@ -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/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs index c8ff6cba3dd1..43daa9d4ca8f 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::CrateId; 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; @@ -137,7 +138,7 @@ impl chalk_solve::RustIrDatabase for ChalkContext<'_> { let fps: &[TyFingerprint] = match binder_kind(&ty, binders) { Some(chalk_ir::TyVariableKind::Integer) => &ALL_INT_FPS, Some(chalk_ir::TyVariableKind::Float) => &ALL_FLOAT_FPS, - _ => self_ty_fp.as_ref().map(std::slice::from_ref).unwrap_or(&[]), + _ => self_ty_fp.as_slice(), }; let id_to_chalk = |id: hir_def::ImplId| id.to_chalk(self.db); diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 8a8992cf372d..30d6121a54f8 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -1,15 +1,15 @@ //! 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, - 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<'_> { @@ -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 { @@ -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/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index 6b20522cf34c..f67ae643bba4 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::CrateId; -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::{Edition, 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, 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; @@ -822,7 +822,7 @@ impl Evaluator<'_> { _ => { return Err(MirEvalError::InternalError( "mismatched layout".into(), - )) + )); } }] } @@ -1116,7 +1116,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)) } @@ -1860,7 +1860,7 @@ impl Evaluator<'_> { "encoded tag ({offset}, {size}, {value}) is out of bounds 0..{size}" ) .into(), - )) + )); } } } @@ -1872,7 +1872,7 @@ impl Evaluator<'_> { None => { return Err(MirEvalError::InternalError( format!("field offset ({offset}) is out of bounds 0..{size}").into(), - )) + )); } } } @@ -2050,7 +2050,7 @@ impl Evaluator<'_> { _ => { return Err(MirEvalError::UndefinedBehavior(format!( "invalid memory write at address {addr:?}" - ))) + ))); } } @@ -2118,7 +2118,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)) } @@ -2613,13 +2613,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/simd.rs b/crates/hir-ty/src/mir/eval/shim/simd.rs index e229a4ab3172..c4408088d31d 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::*; @@ -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) @@ -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/lower.rs b/crates/hir-ty/src/mir/lower.rs index f88696692e6a..dee7c2d90ed7 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -5,6 +5,8 @@ use std::{fmt::Write, iter, mem}; use base_db::ra_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, HirDisplay}, + display::{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; @@ -515,7 +515,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, @@ -525,7 +525,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", ), @@ -1276,7 +1276,7 @@ impl<'ctx> MirLowerCtx<'ctx> { _ => { return Err(MirLowerError::TypeError( "Array expression with non array type", - )) + )); } }; let Some(values) = elements @@ -1308,7 +1308,7 @@ impl<'ctx> MirLowerCtx<'ctx> { _ => { return Err(MirLowerError::TypeError( "Array repeat expression with non array type", - )) + )); } }; let r = Rvalue::Repeat(init, len); @@ -1432,7 +1432,7 @@ impl<'ctx> MirLowerCtx<'ctx> { _ => { return Err(MirLowerError::TypeError( "float with size other than 2, 4, 8 or 16 bytes", - )) + )); } }, }; @@ -2157,11 +2157,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/src/lib.rs b/crates/hir/src/lib.rs index 727d31cffb51..9f331733312f 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -42,7 +42,12 @@ use arrayvec::ArrayVec; use base_db::{CrateDisplayName, CrateId, CrateOrigin}; 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, attrs::{Attr, AttrId}, change::ChangeWithProcMacros, files::{ @@ -137,14 +138,15 @@ pub use { HirFileRange, InFile, InFileWrapper, InMacroFile, InRealFile, MacroFilePosition, MacroFileRange, }, - hygiene::{marks_rev, SyntaxContextExt}, + hygiene::{SyntaxContextExt, marks_rev}, inert_attr_macro::AttributeTemplate, name::Name, prettify_macro_expansion, proc_macro::{ProcMacros, ProcMacrosBuilder}, - tt, ExpandResult, HirFileId, HirFileIdExt, MacroFileId, MacroFileIdExt, + tt, }, hir_ty::{ + CastError, DropGlue, FnAbi, PointerCast, Safety, Variance, consteval::ConstEvalError, diagnostics::UnsafetyReason, display::{ClosureStyle, HirDisplay, HirDisplayError, HirWrite}, @@ -152,11 +154,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 @@ -560,11 +561,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)) } @@ -1725,19 +1722,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 } } } @@ -5047,11 +5036,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 { @@ -5228,11 +5213,14 @@ 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)) } - fn autoderef_(&self, db: &dyn HirDatabase) -> impl Iterator { + fn autoderef_<'db>(&self, db: &'db dyn HirDatabase) -> impl Iterator + use<'_, 'db> { // There should be no inference vars in types passed here let canonical = hir_ty::replace_errors_with_variables(&self.ty); autoderef(db, self.env.clone(), canonical) @@ -5604,7 +5592,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 c9145f7d212d..e00e57ad3377 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -12,15 +12,16 @@ use std::{ use either::Either; use hir_def::{ + AsMacroCall, DefWithBodyId, FunctionId, MacroId, StructId, TraitId, VariantId, hir::{Expr, ExprOrPatId}, lower::LowerCtx, nameres::{MacroSubNs, ModuleOrigin}, 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, @@ -28,31 +29,30 @@ use hir_expand::{ hygiene::SyntaxContextExt as _, inert_attr_macro::find_builtin_attr_idx, name::AsName, - ExpandResult, FileRange, InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt, }; -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, SyntaxContextId}; 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}, Access, Adjust, Adjustment, Adt, AutoBorrow, BindingMode, BuiltinAttr, Callable, Const, ConstParam, Crate, 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(()); @@ -928,11 +928,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 { @@ -1718,7 +1714,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()), @@ -2106,7 +2102,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 3ea41aa7e859..c53b9ab22b42 100644 --- a/crates/ide-diagnostics/src/lib.rs +++ b/crates/ide-diagnostics/src/lib.rs @@ -81,21 +81,21 @@ mod tests; use std::{collections::hash_map, iter, sync::LazyLock}; use either::Either; -use hir::{db::ExpandDatabase, diagnostics::AnyDiagnostic, Crate, HirFileId, InFile, Semantics}; +use hir::{Crate, HirFileId, InFile, Semantics, db::ExpandDatabase, diagnostics::AnyDiagnostic}; use ide_db::{ + EditionedFileId, FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, Severity, SnippetCap, assists::{Assist, AssistId, AssistKind, AssistResolveStrategy}, base_db::{ReleaseChannel, SourceDatabase}, - 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 @@ -931,7 +931,7 @@ impl LintGroups { self.groups.contains(&group) || (self.inside_warnings && group == "warnings") } - fn iter(&self) -> impl Iterator { + fn iter(&self) -> impl Iterator + use<> { self.groups.iter().copied().chain(self.inside_warnings.then_some("warnings")) } } diff --git a/crates/ide/src/inlay_hints/lifetime.rs b/crates/ide/src/inlay_hints/lifetime.rs index 1fdd69899171..baba49a427d1 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( @@ -268,13 +268,14 @@ 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() } @@ -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/signature_help.rs b/crates/ide/src/signature_help.rs index f99721160041..4835eb7fe51d 100644 --- a/crates/ide/src/signature_help.rs +++ b/crates/ide/src/signature_help.rs @@ -6,17 +6,17 @@ use std::collections::BTreeSet; use either::Either; use hir::{AssocItem, 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; @@ -322,7 +322,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; } } @@ -684,9 +684,7 @@ fn signature_help_for_tuple_pat_ish( } #[cfg(test)] mod tests { - use std::iter; - - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide_db::FilePosition; use stdx::format_to; use test_fixture::ChangeFixture; @@ -731,11 +729,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/proc-macro-srv/proc-macro-test/Cargo.toml b/crates/proc-macro-srv/proc-macro-test/Cargo.toml index 7c6a1ba46b5f..253d8e3a4810 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 fa189752b76f..e1678bddff8a 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/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index 2f9612e3a478..056b0f664157 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -53,7 +53,7 @@ use base_db::{CrateDisplayName, CrateName}; use cfg::CfgAtom; use paths::{AbsPath, AbsPathBuf, Utf8PathBuf}; use rustc_hash::{FxHashMap, FxHashSet}; -use serde::{de, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de}; use span::Edition; use crate::{ManifestPath, TargetKind}; @@ -84,7 +84,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. + /// configuration. pub fn new( manifest: Option, base: &AbsPath, diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs index fb752fe47b37..1dace3c35bf4 100644 --- a/crates/project-model/src/sysroot.rs +++ b/crates/project-model/src/sysroot.rs @@ -11,18 +11,18 @@ use std::{ process::Command, }; -use anyhow::{format_err, Result}; +use anyhow::{Result, format_err}; use base_db::CrateName; use itertools::Itertools; use la_arena::{Arena, Idx}; use paths::{AbsPath, AbsPathBuf, Utf8PathBuf}; use rustc_hash::FxHashMap; use stdx::format_to; -use toolchain::{probe_for_binary, Tool}; +use toolchain::{Tool, probe_for_binary}; use crate::{ - cargo_workspace::CargoMetadataConfig, utf8_stdout, CargoWorkspace, ManifestPath, - RustSourceWorkspaceConfig, + CargoWorkspace, ManifestPath, RustSourceWorkspaceConfig, cargo_workspace::CargoMetadataConfig, + utf8_stdout, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -258,7 +258,7 @@ impl Sysroot { let mut stitched = Stitched { crates: Arena::default() }; for path in SYSROOT_CRATES.trim().lines() { - let name = path.split('/').last().unwrap(); + let name = path.split('/').next_back().unwrap(); let root = [format!("{path}/src/lib.rs"), format!("lib{path}/lib.rs")] .into_iter() .map(|it| src_root.join(it)) @@ -468,21 +468,13 @@ fn get_rustc_src(sysroot_path: &AbsPath) -> Option { let rustc_src = sysroot_path.join("lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml"); let rustc_src = ManifestPath::try_from(rustc_src).ok()?; tracing::debug!("checking for rustc source code: {rustc_src}"); - if fs::metadata(&rustc_src).is_ok() { - Some(rustc_src) - } else { - None - } + if fs::metadata(&rustc_src).is_ok() { Some(rustc_src) } else { None } } fn get_rust_lib_src(sysroot_path: &AbsPath) -> Option { let rust_lib_src = sysroot_path.join("lib/rustlib/src/rust/library"); tracing::debug!("checking sysroot library: {rust_lib_src}"); - if fs::metadata(&rust_lib_src).is_ok() { - Some(rust_lib_src) - } else { - None - } + if fs::metadata(&rust_lib_src).is_ok() { Some(rust_lib_src) } else { None } } const SYSROOT_CRATES: &str = " diff --git a/crates/ra-salsa/Cargo.toml b/crates/ra-salsa/Cargo.toml index 57a20be0cadd..63079d20171c 100644 --- a/crates/ra-salsa/Cargo.toml +++ b/crates/ra-salsa/Cargo.toml @@ -2,7 +2,7 @@ name = "salsa" version = "0.0.0" authors = ["Salsa developers"] -edition = "2021" +edition = "2024" license = "Apache-2.0 OR MIT" repository = "https://github.com/salsa-rs/salsa" description = "A generic framework for on-demand, incrementalized computation (experimental)" diff --git a/crates/ra-salsa/ra-salsa-macros/Cargo.toml b/crates/ra-salsa/ra-salsa-macros/Cargo.toml index 5613d75c7522..b39350819930 100644 --- a/crates/ra-salsa/ra-salsa-macros/Cargo.toml +++ b/crates/ra-salsa/ra-salsa-macros/Cargo.toml @@ -2,7 +2,7 @@ name = "salsa-macros" version = "0.0.0" authors = ["Salsa developers"] -edition = "2021" +edition = "2024" license = "Apache-2.0 OR MIT" repository = "https://github.com/salsa-rs/salsa" description = "Procedural macros for the salsa crate" diff --git a/crates/ra-salsa/tests/parallel/stress.rs b/crates/ra-salsa/tests/parallel/stress.rs index f3a435b47f14..0ada1006e575 100644 --- a/crates/ra-salsa/tests/parallel/stress.rs +++ b/crates/ra-salsa/tests/parallel/stress.rs @@ -1,5 +1,5 @@ -use rand::seq::SliceRandom; use rand::Rng; +use rand::seq::SliceRandom; use ra_salsa::ParallelDatabase; use ra_salsa::Snapshot; @@ -72,12 +72,12 @@ impl rand::distributions::Distribution for rand::distributions::Standard impl rand::distributions::Distribution for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> MutatorOp { - if rng.gen_bool(0.5) { - MutatorOp::WriteOp(rng.gen()) + if rng.r#gen_bool(0.5) { + MutatorOp::WriteOp(rng.r#gen()) } else { MutatorOp::LaunchReader { - ops: (0..N_READER_OPS).map(|_| rng.gen()).collect(), - check_cancellation: rng.gen(), + ops: (0..N_READER_OPS).map(|_| rng.r#gen()).collect(), + check_cancellation: rng.r#gen(), } } } @@ -85,16 +85,16 @@ impl rand::distributions::Distribution for rand::distributions::Stand impl rand::distributions::Distribution for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> WriteOp { - let key = rng.gen::() % 10; - let value = rng.gen::() % 10; + let key = rng.r#gen::() % 10; + let value = rng.r#gen::() % 10; WriteOp::SetA(key, value) } } impl rand::distributions::Distribution for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> ReadOp { - let query = rng.gen::(); - let key = rng.gen::() % 10; + let query = rng.r#gen::(); + let key = rng.r#gen::() % 10; ReadOp::Get(query, key) } } @@ -146,7 +146,7 @@ fn stress_test() { let mut rng = rand::thread_rng(); // generate the ops that the mutator thread will perform - let write_ops: Vec = (0..N_MUTATOR_OPS).map(|_| rng.gen()).collect(); + let write_ops: Vec = (0..N_MUTATOR_OPS).map(|_| rng.r#gen()).collect(); // execute the "main thread", which sometimes snapshots off other threads let mut all_threads = vec![]; diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 1a9cdef256d2..fa9ccb4db398 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -123,13 +123,17 @@ 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); + unsafe { + env::set_var("_NT_SYMBOL_PATH", path); + } } } } if env::var("RUST_BACKTRACE").is_err() { - env::set_var("RUST_BACKTRACE", "short"); + unsafe { + env::set_var("RUST_BACKTRACE", "short"); + } } let log_file = env::var("RA_LOG_FILE").ok().map(PathBuf::from).or(log_file_flag); @@ -253,8 +257,8 @@ fn run_server() -> anyhow::Result<()> { if !error_sink.is_empty() { use lsp_types::{ - notification::{Notification, ShowMessage}, MessageType, ShowMessageParams, + notification::{Notification, ShowMessage}, }; let not = lsp_server::Notification::new( ShowMessage::METHOD.to_owned(), diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index 446549c90700..2cf05cf5597c 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -6,7 +6,7 @@ use std::{ sync::atomic::{AtomicU32, Ordering}, }; -use base64::{prelude::BASE64_STANDARD, Engine}; +use base64::{Engine, prelude::BASE64_STANDARD}; use ide::{ Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionFieldsToResolve, CompletionItem, CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, @@ -16,7 +16,7 @@ use ide::{ SnippetEdit, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize, UpdateTest, }; -use ide_db::{assists, rust_doc::format_docs, FxHasher}; +use ide_db::{FxHasher, assists, rust_doc::format_docs}; use itertools::Itertools; use paths::{Utf8Component, Utf8Prefix}; use semver::VersionReq; @@ -29,10 +29,10 @@ use crate::{ global_state::GlobalStateSnapshot, line_index::{LineEndings, LineIndex, PositionEncoding}, lsp::{ + LspError, ext::ShellRunnableArgs, semantic_tokens::{self, standard_fallback_type}, utils::invalid_params_error, - LspError, }, lsp_ext::{self, SnippetTextEdit}, target_spec::{CargoTargetSpec, TargetSpec}, @@ -734,7 +734,7 @@ pub(crate) fn semantic_tokens( | HlTag::None if highlight_range.highlight.mods.is_empty() => { - continue + continue; } _ => (), } @@ -1500,7 +1500,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(), }; @@ -1891,19 +1891,11 @@ pub(crate) fn make_update_runnable( } pub(crate) fn implementation_title(count: usize) -> String { - if count == 1 { - "1 implementation".into() - } else { - format!("{count} implementations") - } + if count == 1 { "1 implementation".into() } else { format!("{count} implementations") } } pub(crate) fn reference_title(count: usize) -> String { - if count == 1 { - "1 reference".into() - } else { - format!("{count} references") - } + if count == 1 { "1 reference".into() } else { format!("{count} references") } } pub(crate) fn markup_content( @@ -1926,7 +1918,7 @@ pub(crate) fn rename_error(err: RenameError) -> LspError { #[cfg(test)] mod tests { - use expect_test::{expect, Expect}; + use expect_test::{Expect, expect}; use ide::{Analysis, FilePosition}; use ide_db::source_change::Snippet; use test_utils::extract_offset; diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index 1f52f366c546..8246de489197 100644 --- a/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs @@ -5,10 +5,10 @@ use std::{ time::Duration, }; -use crossbeam_channel::{after, select, Receiver}; +use crossbeam_channel::{Receiver, after, select}; use itertools::Itertools; use lsp_server::{Connection, Message, Notification, Request}; -use lsp_types::{notification::Exit, request::Shutdown, TextDocumentIdentifier, Url}; +use lsp_types::{TextDocumentIdentifier, Url, notification::Exit, request::Shutdown}; use parking_lot::{Mutex, MutexGuard}; use paths::{Utf8Path, Utf8PathBuf}; use rust_analyzer::{ @@ -17,7 +17,7 @@ use rust_analyzer::{ lsp, main_loop, }; use serde::Serialize; -use serde_json::{json, to_string_pretty, Value}; +use serde_json::{Value, json, to_string_pretty}; use test_utils::FixtureWithProjectMeta; use tracing_subscriber::fmt::TestWriter; use vfs::AbsPathBuf; @@ -88,11 +88,7 @@ impl Project<'_> { pub(crate) fn run_lsif(self) -> String { let tmp_dir = self.tmp_dir.unwrap_or_else(|| { - if self.root_dir_contains_symlink { - TestDir::new_symlink() - } else { - TestDir::new() - } + if self.root_dir_contains_symlink { TestDir::new_symlink() } else { TestDir::new() } }); let FixtureWithProjectMeta { @@ -148,7 +144,9 @@ 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); + unsafe { + env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); + } (guard, test_dir) }) } else { @@ -156,11 +154,7 @@ impl Project<'_> { }; let tmp_dir = self.tmp_dir.unwrap_or_else(|| { - if self.root_dir_contains_symlink { - TestDir::new_symlink() - } else { - TestDir::new() - } + if self.root_dir_contains_symlink { TestDir::new_symlink() } else { TestDir::new() } }); static INIT: Once = Once::new(); diff --git a/crates/syntax/fuzz/Cargo.toml b/crates/syntax/fuzz/Cargo.toml index c2c6dac72de1..a16f5e5d59b5 100644 --- a/crates/syntax/fuzz/Cargo.toml +++ b/crates/syntax/fuzz/Cargo.toml @@ -2,8 +2,8 @@ name = "syntax-fuzz" version = "0.0.1" publish = false -edition = "2021" -rust-version = "1.78" +edition = "2024" +rust-version.workspace = true [package.metadata] cargo-fuzz = true diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 56f94b965e32..855a7a06121a 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -10,11 +10,12 @@ use parser::SyntaxKind; use rowan::{GreenNodeData, GreenTokenData}; use crate::{ + NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, T, TokenText, ast::{ - self, support, AstNode, AstToken, HasAttrs, HasGenericArgs, HasGenericParams, HasName, - SyntaxNode, + self, AstNode, AstToken, HasAttrs, HasGenericArgs, HasGenericParams, HasName, SyntaxNode, + support, }, - ted, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T, + ted, }; use super::{GenericParam, RangeItem, RangeOp}; @@ -317,11 +318,7 @@ impl ast::Path { let path_range = self.syntax().text_range(); successors(self.first_segment(), move |p| { p.parent_path().parent_path().and_then(|p| { - if path_range.contains_range(p.syntax().text_range()) { - p.segment() - } else { - None - } + if path_range.contains_range(p.syntax().text_range()) { p.segment() } else { None } }) }) } @@ -506,11 +503,7 @@ impl ast::Union { impl ast::RecordExprField { pub fn for_field_name(field_name: &ast::NameRef) -> Option { let candidate = Self::for_name_ref(field_name)?; - if candidate.field_name().as_ref() == Some(field_name) { - Some(candidate) - } else { - None - } + if candidate.field_name().as_ref() == Some(field_name) { Some(candidate) } else { None } } pub fn for_name_ref(name_ref: &ast::NameRef) -> Option { @@ -785,11 +778,7 @@ pub enum SelfParamKind { impl ast::SelfParam { pub fn kind(&self) -> SelfParamKind { if self.amp_token().is_some() { - if self.mut_token().is_some() { - SelfParamKind::MutRef - } else { - SelfParamKind::Ref - } + if self.mut_token().is_some() { SelfParamKind::MutRef } else { SelfParamKind::Ref } } else { SelfParamKind::Owned } @@ -1051,7 +1040,7 @@ impl ast::Meta { } impl ast::GenericArgList { - pub fn lifetime_args(&self) -> impl Iterator { + pub fn lifetime_args(&self) -> impl Iterator + use<> { self.generic_args().filter_map(|arg| match arg { ast::GenericArg::LifetimeArg(it) => Some(it), _ => None, @@ -1060,13 +1049,13 @@ impl ast::GenericArgList { } impl ast::GenericParamList { - pub fn lifetime_params(&self) -> impl Iterator { + pub fn lifetime_params(&self) -> impl Iterator + use<> { self.generic_params().filter_map(|param| match param { ast::GenericParam::LifetimeParam(it) => Some(it), 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, diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 7d5ca2704354..2a31a10b2a0b 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs @@ -3,13 +3,13 @@ use std::{borrow::Cow, num::ParseIntError}; use rustc_lexer::unescape::{ - unescape_byte, unescape_char, unescape_mixed, unescape_unicode, EscapeError, MixedUnit, Mode, + EscapeError, MixedUnit, Mode, unescape_byte, unescape_char, unescape_mixed, unescape_unicode, }; use stdx::always; use crate::{ - ast::{self, AstToken}, TextRange, TextSize, + ast::{self, AstToken}, }; impl ast::Comment { @@ -269,7 +269,7 @@ impl ast::ByteString { } (Ok(c), true) => { buf.reserve_exact(text.len()); - buf.extend_from_slice(text[..prev_end].as_bytes()); + buf.extend_from_slice(&text.as_bytes()[..prev_end]); buf.push(c as u8); } (Err(e), _) => has_error = Some(e), @@ -333,7 +333,7 @@ impl ast::CString { } (Ok(u), true) => { buf.reserve_exact(text.len()); - buf.extend(text[..prev_end].as_bytes()); + buf.extend(&text.as_bytes()[..prev_end]); extend_unit(&mut buf, u); } (Err(e), _) => has_error = Some(e), @@ -383,11 +383,7 @@ impl ast::IntNumber { pub fn suffix(&self) -> Option<&str> { let (_, _, suffix) = self.split_into_parts(); - if suffix.is_empty() { - None - } else { - Some(suffix) - } + if suffix.is_empty() { None } else { Some(suffix) } } pub fn value_string(&self) -> String { @@ -422,11 +418,7 @@ impl ast::FloatNumber { pub fn suffix(&self) -> Option<&str> { let (_, suffix) = self.split_into_parts(); - if suffix.is_empty() { - None - } else { - Some(suffix) - } + if suffix.is_empty() { None } else { Some(suffix) } } pub fn value_string(&self) -> String { @@ -491,7 +483,7 @@ impl ast::Byte { mod tests { use rustc_apfloat::ieee::Quad as f128; - use crate::ast::{self, make, FloatNumber, IntNumber}; + use crate::ast::{self, FloatNumber, IntNumber, make}; fn check_float_suffix<'a>(lit: &str, expected: impl Into>) { assert_eq!(FloatNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into()); diff --git a/crates/toolchain/src/lib.rs b/crates/toolchain/src/lib.rs index 325b94cc33ba..e3b30ff9cdec 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()) diff --git a/docs/book/book.toml b/docs/book/book.toml index a6f6a6ed784d..edf11fadf083 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 589d026142bb..45f5231fec5d 100644 --- a/lib/la-arena/Cargo.toml +++ b/lib/la-arena/Cargo.toml @@ -6,8 +6,8 @@ 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" -rust-version = "1.56" +edition = "2024" +rust-version.workspace = true [lints] workspace = true diff --git a/lib/line-index/Cargo.toml b/lib/line-index/Cargo.toml index 14196ba3d097..b05b7708f510 100644 --- a/lib/line-index/Cargo.toml +++ b/lib/line-index/Cargo.toml @@ -4,7 +4,8 @@ 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" +rust-version.workspace = true [dependencies] text-size = "1.1.1" diff --git a/lib/lsp-server/Cargo.toml b/lib/lsp-server/Cargo.toml index 2fa3272e6593..fb666002e399 100644 --- a/lib/lsp-server/Cargo.toml +++ b/lib/lsp-server/Cargo.toml @@ -4,7 +4,8 @@ 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" +rust-version.workspace = true [dependencies] log = "0.4.17" diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index ebd8903ad8ac..0cf1045f368f 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] @@ -14,7 +14,10 @@ write-json = "0.1.2" xshell.workspace = true xflags = "0.3.0" time = { version = "0.3", default-features = false } -zip = { version = "0.6", default-features = false, features = ["deflate", "time"] } +zip = { version = "0.6", default-features = false, features = [ + "deflate", + "time", +] } stdx.workspace = true proc-macro2 = "1.0.93" quote = "1.0.20" diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index c6a0be8aeb99..c8e72a9e5022 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -5,10 +5,10 @@ use std::{ path::{Path, PathBuf}, }; -use flate2::{write::GzEncoder, Compression}; +use flate2::{Compression, write::GzEncoder}; use time::OffsetDateTime; -use xshell::{cmd, Shell}; -use zip::{write::FileOptions, DateTime, ZipWriter}; +use xshell::{Shell, cmd}; +use zip::{DateTime, ZipWriter, write::FileOptions}; use crate::{ date_iso, @@ -93,7 +93,10 @@ fn dist_server( // let _e = sh.push_env("CARGO_PROFILE_RELEASE_DEBUG", "1"); if target.name.contains("-linux-") { - env::set_var("CC", "clang"); + // SAFETY: this program is single-threaded + unsafe { + env::set_var("CC", "clang"); + } } let target_name = &target.name; diff --git a/xtask/src/release.rs b/xtask/src/release.rs index 8e56ce439c55..9f65c4029536 100644 --- a/xtask/src/release.rs +++ b/xtask/src/release.rs @@ -50,7 +50,7 @@ impl flags::Release { .unwrap_or_default(); let tags = cmd!(sh, "git tag --list").read()?; - let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap(); + let prev_tag = tags.lines().filter(|line| is_release_tag(line)).next_back().unwrap(); let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?; let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc")); From 477c7af5711f0b4539f1eb3252ffbf1b458169d0 Mon Sep 17 00:00:00 2001 From: BenjaminBrienen Date: Wed, 26 Feb 2025 21:43:55 +0100 Subject: [PATCH 2/5] fix doc tests and fmt --- crates/base-db/src/change.rs | 6 +- crates/base-db/src/input.rs | 88 +++++++++++-------- crates/base-db/src/lib.rs | 4 +- 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 | 22 ++--- crates/hir-def/src/data/adt.rs | 2 +- crates/hir-def/src/db.rs | 28 +++--- crates/hir-def/src/dyn_map.rs | 18 ++-- 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 | 12 +-- crates/hir-def/src/item_tree/tests.rs | 2 +- crates/hir-def/src/lang_item.rs | 18 ++-- crates/hir-def/src/lib.rs | 17 ++-- 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/attr_resolution.rs | 4 +- crates/hir-def/src/nameres/collector.rs | 26 +++--- crates/hir-def/src/nameres/diagnostics.rs | 4 +- crates/hir-def/src/nameres/mod_resolution.rs | 6 +- 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 | 25 +++--- crates/hir-def/src/src.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 | 6 +- crates/hir-expand/src/cfg_process.rs | 10 +-- crates/hir-expand/src/change.rs | 4 +- crates/hir-expand/src/db.rs | 29 +++--- crates/hir-expand/src/declarative.rs | 7 +- crates/hir-expand/src/eager.rs | 6 +- crates/hir-expand/src/files.rs | 13 ++- crates/hir-expand/src/fixup.rs | 9 +- crates/hir-expand/src/lib.rs | 16 ++-- 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 | 4 +- crates/hir-expand/src/span_map.rs | 2 +- crates/hir-ty/src/chalk_ext.rs | 12 +-- crates/hir-ty/src/consteval.rs | 14 +-- crates/hir-ty/src/consteval/tests.rs | 6 +- crates/hir-ty/src/db.rs | 15 ++-- crates/hir-ty/src/diagnostics.rs | 6 +- 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 | 28 +++--- 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 | 37 ++++---- 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/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 | 37 ++++---- crates/hir-ty/src/lower/path.rs | 12 +-- crates/hir-ty/src/mapping.rs | 4 +- crates/hir-ty/src/method_resolution.rs | 30 +++---- crates/hir-ty/src/mir.rs | 16 ++-- crates/hir-ty/src/mir/borrowck.rs | 8 +- crates/hir-ty/src/mir/eval/shim.rs | 11 ++- crates/hir-ty/src/mir/eval/tests.rs | 4 +- .../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 | 4 +- 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 | 10 +-- crates/hir/src/from_id.rs | 2 +- crates/hir/src/has_source.rs | 6 +- crates/hir/src/semantics/child_by_source.rs | 12 +-- crates/hir/src/semantics/source_to_def.rs | 20 ++--- crates/hir/src/source_analyzer.rs | 45 ++++------ crates/hir/src/symbols.rs | 10 +-- crates/hir/src/term_search/expr.rs | 2 +- crates/hir/src/term_search/tactics.rs | 2 +- crates/ide-assists/src/assist_config.rs | 2 +- crates/ide-assists/src/assist_context.rs | 6 +- crates/ide-assists/src/handlers/add_braces.rs | 2 +- .../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 | 6 +- .../ide-assists/src/handlers/auto_import.rs | 12 +-- .../src/handlers/bind_unused_param.rs | 4 +- .../ide-assists/src/handlers/bool_to_enum.rs | 10 +-- .../src/handlers/change_visibility.rs | 4 +- .../src/handlers/convert_bool_then.rs | 11 +-- .../src/handlers/convert_closure_to_fn.rs | 9 +- .../src/handlers/convert_comment_block.rs | 8 +- .../convert_comment_from_or_to_doc.rs | 8 +- .../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 | 8 +- .../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 +- .../handlers/explicit_enum_discriminant.rs | 4 +- .../extract_expressions_from_format_string.rs | 48 +++++----- .../src/handlers/extract_function.rs | 27 +++--- .../src/handlers/extract_module.rs | 17 ++-- .../extract_struct_from_enum_variant.rs | 17 ++-- .../src/handlers/extract_type_alias.rs | 2 +- .../src/handlers/extract_variable.rs | 10 +-- .../handlers/fill_record_pattern_fields.rs | 2 +- .../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_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 | 18 ++-- .../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 | 9 +- .../src/handlers/into_to_qualified_from.rs | 2 +- .../src/handlers/introduce_named_generic.rs | 2 +- .../src/handlers/introduce_named_lifetime.rs | 6 +- 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 | 4 +- .../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 | 4 +- .../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 | 25 +++--- crates/ide-completion/src/context/analysis.rs | 22 ++--- crates/ide-completion/src/context/tests.rs | 4 +- crates/ide-completion/src/item.rs | 22 ++--- crates/ide-completion/src/lib.rs | 4 +- 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 | 4 +- 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 | 8 +- crates/ide-db/src/active_parameter.rs | 3 +- crates/ide-db/src/apply_change.rs | 8 +- 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 | 14 +-- 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 | 7 +- crates/ide-db/src/prime_caches.rs | 6 +- crates/ide-db/src/rename.rs | 6 +- crates/ide-db/src/search.rs | 16 ++-- crates/ide-db/src/source_change.rs | 21 ++--- crates/ide-db/src/symbol_index.rs | 6 +- .../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 | 7 +- 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 | 10 +-- .../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 | 3 +- 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 | 4 +- crates/ide-ssr/src/parsing.rs | 2 +- crates/ide-ssr/src/replacing.rs | 4 +- crates/ide-ssr/src/resolving.rs | 4 +- 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 | 6 +- 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 | 24 ++--- crates/ide/src/hover.rs | 12 +-- crates/ide/src/hover/render.rs | 28 +++--- 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 | 8 +- crates/ide/src/inlay_hints/implicit_drop.rs | 9 +- crates/ide/src/inlay_hints/implicit_static.rs | 4 +- 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/ssr.rs | 6 +- crates/ide/src/static_index.rs | 16 ++-- crates/ide/src/status.rs | 24 ++--- crates/ide/src/syntax_highlighting.rs | 6 +- crates/ide/src/syntax_highlighting/format.rs | 8 +- .../ide/src/syntax_highlighting/highlight.rs | 26 ++---- 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/macro_.rs | 2 +- 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 | 16 ++-- crates/parser/src/event.rs | 2 +- crates/parser/src/grammar.rs | 4 +- crates/parser/src/grammar/expressions.rs | 2 +- crates/parser/src/input.rs | 2 +- crates/parser/src/lib.rs | 2 +- crates/parser/src/output.rs | 5 +- 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/tests.rs | 9 +- .../src/toolchain_info/target_data_layout.rs | 2 +- .../src/toolchain_info/target_tuple.rs | 2 +- crates/project-model/src/workspace.rs | 10 +-- .../ra-salsa-macros/src/query_group.rs | 4 +- crates/ra-salsa/src/debug.rs | 4 +- crates/ra-salsa/src/derived.rs | 3 +- crates/ra-salsa/src/derived/slot.rs | 30 +++---- crates/ra-salsa/src/derived_lru.rs | 2 +- crates/ra-salsa/src/derived_lru/slot.rs | 34 +++---- crates/ra-salsa/src/input.rs | 6 +- crates/ra-salsa/src/interned.rs | 4 +- crates/ra-salsa/src/plumbing.rs | 6 +- crates/ra-salsa/src/runtime/local_state.rs | 4 +- crates/ra-salsa/src/storage.rs | 2 +- .../ra-salsa/tests/incremental/constants.rs | 2 +- crates/ra-salsa/tests/lru.rs | 2 +- crates/ra-salsa/tests/parallel/frozen.rs | 10 ++- crates/ra-salsa/tests/parallel/setup.rs | 2 +- .../rust-analyzer/src/cli/analysis_stats.rs | 13 +-- 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 | 8 +- 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 | 24 +++-- .../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/utils.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 20 +++-- crates/rust-analyzer/src/op_queue.rs | 2 +- crates/rust-analyzer/src/reload.rs | 12 +-- crates/rust-analyzer/src/target_spec.rs | 7 +- crates/rust-analyzer/src/tracing/config.rs | 12 +-- crates/rust-analyzer/src/tracing/hprof.rs | 8 +- crates/rust-analyzer/src/tracing/json.rs | 7 +- crates/rust-analyzer/tests/slow-tests/main.rs | 12 +-- .../rust-analyzer/tests/slow-tests/ratoml.rs | 2 +- crates/span/src/ast_id.rs | 2 +- crates/span/src/map.rs | 4 +- crates/stdx/src/anymap.rs | 3 +- crates/stdx/src/lib.rs | 6 +- crates/stdx/src/macros.rs | 2 +- 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 | 7 +- .../src/prettify_macro_expansion.rs | 6 +- crates/syntax-bridge/src/tests.rs | 9 +- crates/syntax/src/algo.rs | 6 +- crates/syntax/src/ast.rs | 2 +- crates/syntax/src/ast/edit.rs | 11 ++- 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/prec.rs | 5 +- .../src/ast/syntax_factory/constructors.rs | 6 +- 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/test-utils/src/assert_linear.rs | 2 +- crates/test-utils/src/fixture.rs | 12 ++- crates/vfs-notify/src/lib.rs | 2 +- crates/vfs/src/anchored_path.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 +- rustfmt.toml | 1 + 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/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 +- 569 files changed, 2111 insertions(+), 2282 deletions(-) diff --git a/crates/base-db/src/change.rs b/crates/base-db/src/change.rs index 7e40f5408f14..674e9b522823 100644 --- a/crates/base-db/src/change.rs +++ b/crates/base-db/src/change.rs @@ -90,9 +90,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 bd08387b5821..53b96961be69 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -14,7 +14,7 @@ use la_arena::{Arena, Idx, RawIdx}; use rustc_hash::{FxHashMap, FxHashSet}; 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}; pub type ProcMacroPaths = FxHashMap>; @@ -59,7 +59,7 @@ impl SourceRoot { self.file_set.resolve_path(path) } - pub fn iter(&self) -> impl Iterator + '_ { + pub fn iter(&self) -> impl Iterator + use<'_> { self.file_set.iter() } } @@ -105,11 +105,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. @@ -413,19 +409,19 @@ impl CrateGraph { self.arena.len() } - pub fn iter(&self) -> impl Iterator + '_ { + pub fn iter(&self) -> impl Iterator + use<'_> { self.arena.iter().map(|(idx, _)| idx) } // FIXME: used for fixing up the toolchain sysroot, should be removed and done differently #[doc(hidden)] - pub fn iter_mut(&mut self) -> impl Iterator + '_ { + pub fn iter_mut(&mut self) -> impl Iterator + use<'_> { self.arena.iter_mut() } /// Returns an iterator over all transitive dependencies of the given crate, /// including the crate itself. - pub fn transitive_deps(&self, of: CrateId) -> impl Iterator { + pub fn transitive_deps(&self, of: CrateId) -> impl Iterator + use<> { let mut worklist = vec![of]; let mut deps = FxHashSet::default(); @@ -442,7 +438,7 @@ impl CrateGraph { /// Returns all transitive reverse dependencies of the given crate, /// including the crate itself. - pub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator { + pub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator + use<> { let mut worklist = vec![of]; let mut rev_deps = FxHashSet::default(); rev_deps.insert(of); @@ -731,15 +727,21 @@ mod tests { false, None, ); - assert!(graph - .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_ok()); - assert!(graph - .add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,)) - .is_ok()); - assert!(graph - .add_dep(crate3, Dependency::new(CrateName::new("crate1").unwrap(), crate1,)) - .is_err()); + assert!( + graph + .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate3, Dependency::new(CrateName::new("crate1").unwrap(), crate1,)) + .is_err() + ); } #[test] @@ -769,12 +771,16 @@ mod tests { false, None, ); - assert!(graph - .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_ok()); - assert!(graph - .add_dep(crate2, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_err()); + assert!( + graph + .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate2, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_err() + ); } #[test] @@ -816,12 +822,16 @@ mod tests { false, None, ); - assert!(graph - .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) - .is_ok()); - assert!(graph - .add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,)) - .is_ok()); + assert!( + graph + .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) + .is_ok() + ); + assert!( + graph + .add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3,)) + .is_ok() + ); } #[test] @@ -851,12 +861,14 @@ mod tests { false, None, ); - assert!(graph - .add_dep( - crate1, - Dependency::new(CrateName::normalize_dashes("crate-name-with-dashes"), crate2,) - ) - .is_ok()); + assert!( + graph + .add_dep( + crate1, + Dependency::new(CrateName::normalize_dashes("crate-name-with-dashes"), crate2,) + ) + .is_ok() + ); assert_eq!( graph[crate1].dependencies, vec![Dependency::new(CrateName::new("crate_name_with_dashes").unwrap(), crate2,)] diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index eed8c8868395..6c8f089d4810 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -8,7 +8,7 @@ use std::panic; use ra_salsa::Durability; use rustc_hash::FxHashMap; use span::EditionedFileId; -use syntax::{ast, Parse, SourceFile, SyntaxError}; +use syntax::{Parse, SourceFile, SyntaxError, ast}; use triomphe::Arc; use vfs::FileId; @@ -21,7 +21,7 @@ pub use crate::{ }, }; pub use ra_salsa::{self, Cancelled}; -pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, VfsPath}; +pub use vfs::{AnchoredPath, AnchoredPathBuf, VfsPath, file_set::FileSet}; pub use semver::{BuildMetadata, Prerelease, Version, VersionReq}; diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs index 6a6213a871fd..9093e60f99a0 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 6d87d83ad930..6766748097f0 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 710bffcefe90..dc8f743d88e5 100644 --- a/crates/hir-def/src/attr.rs +++ b/crates/hir-def/src/attr.rs @@ -6,27 +6,27 @@ use base_db::CrateId; 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 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. @@ -649,8 +649,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 14b9af84e6ff..6ea21356aa41 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 bec662787728..b35ddbfe7cad 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -4,32 +4,32 @@ pub mod adt; use base_db::CrateId; use hir_expand::{ - name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefKind, + AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefKind, name::Name, }; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use la_arena::{Idx, RawIdx}; use smallvec::SmallVec; -use syntax::{ast, Parse}; +use syntax::{Parse, ast}; use triomphe::Arc; use tt::iter::TtElement; use crate::{ + AssocItemId, AstIdWithPath, ConstId, ConstLoc, ExternCrateId, FunctionId, FunctionLoc, + HasModule, ImplId, Intern, ItemContainerId, ItemLoc, Lookup, Macro2Id, MacroRulesId, ModuleId, + ProcMacroId, StaticId, TraitAliasId, TraitId, TypeAliasId, TypeAliasLoc, db::DefDatabase, expander::{Expander, Mark}, item_tree::{self, AssocItem, FnFlags, ItemTree, ItemTreeId, MacroCall, ModItem, TreeId}, macro_call_as_call_id, nameres::{ + DefMap, MacroSubNs, attr_resolution::ResolvedAttr, diagnostics::{DefDiagnostic, DefDiagnostics}, - proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroKind}, - DefMap, MacroSubNs, + proc_macro::{ProcMacroKind, parse_macro_name_and_helper_attrs}, }, path::ImportAlias, type_ref::{TraitRef, TypeBound, TypeRefId, TypesMap}, visibility::RawVisibility, - AssocItemId, AstIdWithPath, ConstId, ConstLoc, ExternCrateId, FunctionId, FunctionLoc, - HasModule, ImplId, Intern, ItemContainerId, ItemLoc, Lookup, Macro2Id, MacroRulesId, ModuleId, - ProcMacroId, StaticId, TraitAliasId, TraitId, TypeAliasId, TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -543,11 +543,7 @@ impl ExternCrateDeclData { Some(krate) } else { db.crate_graph()[krate].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 c94622016d35..da81801cd014 100644 --- a/crates/hir-def/src/data/adt.rs +++ b/crates/hir-def/src/data/adt.rs @@ -14,6 +14,7 @@ use triomphe::Arc; use tt::iter::TtElement; use crate::{ + EnumId, EnumVariantId, LocalFieldId, LocalModuleId, Lookup, StructId, UnionId, VariantId, builtin_type::{BuiltinInt, BuiltinUint}, db::DefDatabase, hir::Expr, @@ -25,7 +26,6 @@ use crate::{ tt::{Delimiter, DelimiterKind, Leaf, TopSubtree}, 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 598a850898bb..4a95826a9bde 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -1,36 +1,36 @@ //! Defines database & queries for name resolution. -use base_db::{ra_salsa, CrateId, SourceDatabase, Upcast}; +use base_db::{CrateId, SourceDatabase, Upcast, ra_salsa}; 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::{ + AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId, + EnumId, EnumLoc, EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, + ExternCrateLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, InTypeConstId, + InTypeConstLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroId, MacroRulesId, MacroRulesLoc, + MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, + TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, + UseId, UseLoc, VariantId, attr::{Attrs, AttrsWithOwner}, data::{ - adt::{EnumData, EnumVariantData, StructData, VariantData}, ConstData, ExternCrateDeclData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData, TraitAliasData, TraitData, TypeAliasData, + adt::{EnumData, EnumVariantData, StructData, VariantData}, }, - expr_store::{scope::ExprScopes, Body, BodySourceMap}, + expr_store::{Body, BodySourceMap, scope::ExprScopes}, generics::GenericParams, import_map::ImportMap, item_tree::{AttrOwner, ItemTree, ItemTreeSourceMaps}, lang_item::{self, LangItem, LangItemTarget, LangItems}, - nameres::{diagnostics::DefDiagnostics, DefMap}, + nameres::{DefMap, diagnostics::DefDiagnostics}, 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, - InTypeConstLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroId, MacroRulesId, MacroRulesLoc, - MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, - TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, - UseId, UseLoc, VariantId, }; #[ra_salsa::query_group(InternDatabaseStorage)] @@ -304,7 +304,7 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> 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 e9318d146ddf..82f9f83d5703 100644 --- a/crates/hir-def/src/dyn_map.rs +++ b/crates/hir-def/src/dyn_map.rs @@ -5,7 +5,9 @@ //! //! It is used like this: //! -//! ``` +//! ```ignore +//! # use hir_def::dyn_map::DynMap; +//! # use hir_def::dyn_map::Key; //! // keys define submaps of a `DynMap` //! const STRING_TO_U32: Key = Key::new(); //! const U32_TO_VEC: Key> = Key::new(); @@ -25,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>; @@ -110,11 +112,17 @@ pub struct Key { } impl Key { - pub(crate) const fn new() -> Key { + pub const fn new() -> Key { Key { _phantom: PhantomData } } } +impl Default for Key { + fn default() -> Self { + Self::new() + } +} + impl Copy for Key {} impl Clone for Key { diff --git a/crates/hir-def/src/expander.rs b/crates/hir-def/src/expander.rs index a1b3123c9914..d0ee452fba05 100644 --- a/crates/hir-def/src/expander.rs +++ b/crates/hir-def/src/expander.rs @@ -6,17 +6,17 @@ use base_db::CrateId; 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, SyntaxContextId}; -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 5ff6a7ffe566..c5a48f695b99 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, SyntaxContextData}; -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 a55fec4f8b1e..8f8fc9a6b5e1 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 6e505a6b1126..a7ec2d0902ac 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::CrateId; 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, MacroSubNs}, path::{GenericArgs, Path}, type_ref::{Mutability, Rawness, TypeRef}, - AdtId, BlockId, BlockLoc, ConstBlockLoc, DefWithBodyId, MacroId, ModuleDefId, UnresolvedMacro, }; type FxIndexSet = indexmap::IndexSet>; @@ -638,11 +638,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()) }; @@ -2035,7 +2031,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 032c18688ea7..633f976a85dd 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 859a706177aa..2862bb89b6b5 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,13 +325,13 @@ fn compute_expr_scopes( #[cfg(test)] mod tests { use base_db::SourceDatabase; - use hir_expand::{name::AsName, InFile}; + use hir_expand::{InFile, name::AsName}; 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 16bf46d3e3f9..eae93a8990bc 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 c30ad0163b9d..7ca02a6b0de9 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::{CrateId, 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 @@ -652,7 +652,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 e2b36da79b23..c26c7882ed0b 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 la_arena::{Arena, RawIdx}; use stdx::{ @@ -19,6 +19,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}, @@ -29,8 +31,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. @@ -291,11 +291,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 494644d8eff9..cd22ae6638ec 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 28c824fd31d7..8024fbfca790 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::SyntaxContextId; 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 6d4d519cd2b7..12492fc8440e 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 d43776b8a66a..cf487abf0c7b 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::CrateId; -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 { @@ -476,10 +472,10 @@ fn search_maps( #[cfg(test)] mod tests { use base_db::{SourceDatabase, 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 0ca1eb9bcfe3..063901095067 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::CrateId; -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 8d5b3eeb28e1..abddc4dfd0ee 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::CrateId; 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, SyntaxContextId}; 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)] @@ -883,20 +883,20 @@ pub struct UseTree { #[derive(Debug, Clone, Eq, PartialEq)] pub enum UseTreeKind { - /// ``` + /// ```ignore /// use path::to::Item; /// use path::to::Item as Renamed; /// use path::to::Trait as _; /// ``` Single { path: Interned, alias: Option }, - /// ``` + /// ```ignore /// use *; // (invalid, but can occur in nested tree) /// use path::*; /// ``` Glob { path: Option> }, - /// ``` + /// ```ignore /// use prefix::{self, Item, ...}; /// ``` Prefixed { prefix: Option>, list: Box<[UseTree]> }, diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs index 80b699649fba..5ae32fd76b76 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 59f51db9f740..43263b809394 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, CrateId, EnumId, EnumVariantId, - FunctionId, ImplId, ModuleDefId, StaticId, StructId, TraitId, TypeAliasId, UnionId, + AdtId, AssocItemId, AttrDefId, CrateId, 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 @@ -238,11 +234,7 @@ pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: CrateId) -> Opti } } - 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 9c947df35e99..76ef4129599f 100644 --- a/crates/hir-def/src/lib.rs +++ b/crates/hir-def/src/lib.rs @@ -75,28 +75,27 @@ use std::{ }; use base_db::{ - impl_intern_key, + CrateId, impl_intern_key, ra_salsa::{self, InternValueTrivial}, - CrateId, }; 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, SyntaxContextId}; 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, @@ -470,11 +469,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 7cddd48eb174..c0f6e1a6867c 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 408d03ff718e..3db39c9aca54 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -19,31 +19,31 @@ use std::{iter, ops::Range, sync}; use base_db::SourceDatabase; use expect_test::Expect; use hir_expand::{ + InFile, MacroCallKind, MacroFileId, MacroFileIdExt, db::ExpandDatabase, proc_macro::{ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind}, span_map::SpanMapRef, - InFile, MacroCallKind, MacroFileId, MacroFileIdExt, }; use intern::Symbol; use itertools::Itertools; 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 3b6e3c5916e3..b92934b040a5 100644 --- a/crates/hir-def/src/nameres.rs +++ b/crates/hir-def/src/nameres.rs @@ -61,7 +61,7 @@ use std::ops::Deref; use base_db::CrateId; 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; @@ -69,11 +69,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}; +use syntax::{AstNode, SmolStr, SyntaxNode, 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}, @@ -81,8 +83,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/attr_resolution.rs b/crates/hir-def/src/nameres/attr_resolution.rs index d1f6ed023c2f..73365558bb73 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::CrateId; use hir_expand::{ + MacroCallId, MacroCallKind, MacroDefId, attrs::{Attr, AttrId, AttrInput}, inert_attr_macro::find_builtin_attr_idx, - MacroCallId, MacroCallKind, MacroDefId, }; use span::SyntaxContextId; use syntax::ast; use triomphe::Arc; use crate::{ + AstIdWithPath, LocalModuleId, MacroId, UnresolvedMacro, db::DefDatabase, item_scope::BuiltinShadowMode, nameres::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 16f3fd56eb9e..2b899376a3ff 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -9,15 +9,15 @@ use base_db::{CrateId, CrateOrigin, Dependency, 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, SyntaxContextId}; @@ -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, 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, 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 bc1617c55b02..1744d3465b27 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 afee42ecec0b..7a9733bb4d97 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; -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; @@ -134,7 +134,7 @@ impl DirPath { /// So this is the case which doesn't really work I think if we try to be /// 100% platform agnostic: /// - /// ``` + /// ```ignore /// mod a { /// #[path="C://sad/face"] /// mod b { mod c; } diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs index 47c08d3d1dc6..017a2113323e 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, MacroSubNs}, + nameres::{BlockInfo, BuiltinShadowMode, DefMap, MacroSubNs, sub_namespace_match}, path::{ModPath, PathKind}, per_ns::PerNs, visibility::{RawVisibility, Visibility}, - AdtId, LocalModuleId, ModuleDefId, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -336,7 +336,7 @@ impl DefMap { PathKind::Abs => match self.resolve_path_abs(&mut segments, path) { Either::Left(it) => it, Either::Right(reached_fixed_point) => { - return ResolvePathResult::empty(reached_fixed_point) + return ResolvePathResult::empty(reached_fixed_point); } }, }; @@ -381,11 +381,11 @@ impl DefMap { PathKind::Abs => match self.resolve_path_abs(&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 73fc6787bfe8..3435486674fa 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::SourceDatabase; -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 c8b7ec463a0f..d258cfb227b3 100644 --- a/crates/hir-def/src/nameres/tests/incremental.rs +++ b/crates/hir-def/src/nameres/tests/incremental.rs @@ -1,7 +1,7 @@ use base_db::SourceDatabaseFileInputExt as _; use test_fixture::WithFixture; -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 e6c2504d07a5..0e0051304bbb 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 3b7e7653fba5..0bb981d87cf4 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 67a27bf85e89..c0bfb0c87217 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 c2d3f67f17e7..1f7dd6f0c407 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 9dfb6e3cc4b7..8b8588e00471 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -2,35 +2,35 @@ use std::{fmt, iter, mem}; use base_db::CrateId; -use hir_expand::{name::Name, MacroDefId}; +use hir_expand::{MacroDefId, name::Name}; use intern::sym; use itertools::Itertools as _; use rustc_hash::FxHashSet; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; 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, 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)] @@ -313,7 +313,7 @@ impl Resolver { None, ), ResolvePathResultPrefixInfo::default(), - )) + )); } Path::LangItem(l, Some(_)) => { let type_ns = match *l { @@ -532,16 +532,17 @@ impl Resolver { /// Note that in Rust one name can be bound to several items: /// /// ``` + /// # #![allow(non_camel_case_types)] /// macro_rules! t { () => (()) } /// type t = t!(); - /// const t: t = t!() + /// const t: t = t!(); /// ``` /// /// That's why we return a multimap. /// /// The shadowing is accounted for: in /// - /// ``` + /// ```ignore /// let it = 92; /// { /// let it = 92; diff --git a/crates/hir-def/src/src.rs b/crates/hir-def/src/src.rs index c7ebfeecf514..3cd43bfee0b9 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/visibility.rs b/crates/hir-def/src/visibility.rs index c4473e454a1b..bd7092c2d603 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 c9c793d54f26..e2f8b34ada42 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::CrateId; 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, SyntaxContextId}; 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 7b9b7f36e2cd..0bf4943b60ce 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 f250620e775a..0463ce11f679 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; @@ -101,7 +101,7 @@ fn dummy_gate_test_expand( /// somewhat inconsistently resolve derive attributes. /// /// As such, we expand `#[derive(Foo, bar::Bar)]` into -/// ``` +/// ```ignore /// #![Foo] /// #![bar::Bar] /// ``` @@ -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/cfg_process.rs b/crates/hir-expand/src/cfg_process.rs index 626a82ae08ea..1a909145d859 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::CrateId; 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: CrateId) -> 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/change.rs b/crates/hir-expand/src/change.rs index 1fdf251ba521..9f6bfc3104fd 100644 --- a/crates/hir-expand/src/change.rs +++ b/crates/hir-expand/src/change.rs @@ -1,8 +1,8 @@ //! Defines a unit of change that can applied to the database to get the next //! state. Changes are transactional. use base_db::{ - ra_salsa::Durability, CrateGraph, CrateId, CrateWorkspaceData, FileChange, SourceRoot, - SourceRootDatabase, + CrateGraph, CrateId, CrateWorkspaceData, FileChange, SourceRoot, SourceRootDatabase, + ra_salsa::Durability, }; use rustc_hash::FxHashMap; use span::FileId; diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index 8ca8bf1ba4a6..0e3accf0664f 100644 --- a/crates/hir-expand/src/db.rs +++ b/crates/hir-expand/src/db.rs @@ -1,30 +1,31 @@ //! Defines database & queries for macro expansion. -use base_db::{ra_salsa, CrateId, SourceDatabase}; +use base_db::{CrateId, SourceDatabase, ra_salsa}; use either::Either; use mbe::MatchedArmIndex; use rustc_hash::FxHashSet; use span::{AstIdMap, Edition, EditionedFileId, Span, SyntaxContextData, SyntaxContextId}; -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, + CustomProcMacroExpander, EagerCallInfo, EagerExpander, ExpandError, ExpandResult, ExpandTo, + ExpansionSpanMap, HirFileId, HirFileIdRepr, Lookup, MacroCallId, MacroCallKind, MacroCallLoc, + MacroDefId, MacroDefKind, MacroFileId, + 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::ProcMacros, span_map::{RealSpanMap, SpanMap, SpanMapRef}, - tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, - CustomProcMacroExpander, EagerCallInfo, EagerExpander, ExpandError, ExpandResult, ExpandTo, - ExpansionSpanMap, HirFileId, HirFileIdRepr, Lookup, MacroCallId, MacroCallKind, MacroCallLoc, - MacroDefId, MacroDefKind, MacroFileId, + tt, }; /// This is just to ensure the types of smart_macro_arg and macro_arg are the same type MacroArgResult = (Arc, SyntaxFixupUndoInfo, Span); @@ -364,11 +365,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( @@ -597,7 +594,7 @@ fn macro_expand( let (ExpandResult { value: (tt, matched_arm), err }, span) = match loc.def.kind { MacroDefKind::ProcMacro(..) => { - return db.expand_proc_macro(macro_call_id).map(CowArc::Arc).zip_val(None) + return db.expand_proc_macro(macro_call_id).map(CowArc::Arc).zip_val(None); } _ => { let (macro_arg, undo_info, span) = diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs index fef77acb7bbb..64d14b834a29 100644 --- a/crates/hir-expand/src/declarative.rs +++ b/crates/hir-expand/src/declarative.rs @@ -4,15 +4,16 @@ use base_db::CrateId; use intern::sym; use span::{Edition, HirFileIdRepr, MacroCallId, Span, SyntaxContextId}; 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 f476d1b564c4..3327e4a9ed83 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::CrateId; use span::SyntaxContextId; -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, Intern, + MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind, ast::{self, AstNode}, db::ExpandDatabase, mod_path::ModPath, - AstId, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, Intern, - 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 13ddb0d4acce..afb118133b40 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, db::{self, ExpandDatabase}, - map_node_range_up, map_node_range_up_rooted, span_for_offset, MacroFileIdExt, + map_node_range_up, map_node_range_up_rooted, span_for_offset, }; /// `InFile` stores a value of `T` inside a particular file/syntax tree. @@ -274,7 +275,7 @@ impl> InFile { // as we don't have node inputs otherwise and therefore can't find an `N` node in the input let file_id = match self.file_id.repr() { HirFileIdRepr::FileId(file_id) => { - return Some(InRealFile { file_id, value: self.value.borrow().clone() }) + return Some(InRealFile { file_id, value: self.value.borrow().clone() }); } HirFileIdRepr::MacroFile(m) if m.is_attr_macro(db) => m, _ => return None, @@ -357,11 +358,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 } } } } @@ -449,7 +446,7 @@ impl InFile { // as we don't have node inputs otherwise and therefore can't find an `N` node in the input let file_id = match self.file_id.repr() { HirFileIdRepr::FileId(file_id) => { - return Some(InRealFile { file_id, value: self.value }) + return Some(InRealFile { file_id, value: self.value }); } HirFileIdRepr::MacroFile(m) => m, }; diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs index eb430177390f..6de9a1c47bbc 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, SyntaxContextId, 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, + SyntaxContextId, }; 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; @@ -492,7 +493,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/lib.rs b/crates/hir-expand/src/lib.rs index 2c664029f615..47edb86b30db 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -31,22 +31,22 @@ use triomphe::Arc; use core::fmt; use std::hash::Hash; -use base_db::{ra_salsa::InternValueTrivial, CrateId}; +use base_db::{CrateId, ra_salsa::InternValueTrivial}; use either::Either; use span::{ Edition, EditionedFileId, ErasedFileAstId, FileAstId, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData, SyntaxContextId, }; 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, @@ -65,7 +65,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; @@ -213,7 +213,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, }, @@ -396,7 +398,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 f0cf7ebf479f..92d8a7e28ffa 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::CrateId; use intern::sym; use smallvec::SmallVec; use span::{Edition, SyntaxContextId}; -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 0758bd4515ef..a439e2e59392 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, SyntaxContextId}; 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 c744fbce77b7..d6c914cc3f2c 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::CrateId; 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 3dc3dcd760cd..886ee24f474a 100644 --- a/crates/hir-expand/src/proc_macro.rs +++ b/crates/hir-expand/src/proc_macro.rs @@ -8,7 +8,7 @@ use intern::Symbol; use rustc_hash::FxHashMap; use span::Span; -use crate::{db::ExpandDatabase, tt, ExpandError, ExpandErrorKind, ExpandResult}; +use crate::{ExpandError, ExpandErrorKind, ExpandResult, db::ExpandDatabase, tt}; #[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] pub enum ProcMacroKind { @@ -231,7 +231,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 740c27b89cea..88fd3f6d312f 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, SyntaxContextId}; 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/chalk_ext.rs b/crates/hir-ty/src/chalk_ext.rs index 51c178b90d72..49dde303099b 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 7839589994b2..772df27d0e81 100644 --- a/crates/hir-ty/src/consteval.rs +++ b/crates/hir-ty/src/consteval.rs @@ -1,26 +1,26 @@ //! Constant evaluation details -use base_db::{ra_salsa::Cycle, CrateId}; -use chalk_ir::{cast::Cast, BoundVar, DebruijnIndex}; +use base_db::{CrateId, ra_salsa::Cycle}; +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 stdx::never; use triomphe::Arc; use crate::{ - db::HirDatabase, 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, + Const, ConstData, ConstScalar, ConstValue, GenericArg, Interner, MemoryMap, Substitution, + TraitEnvironment, Ty, TyBuilder, db::HirDatabase, generics::Generics, infer::InferenceContext, + lower::ParamLoweringMode, mir::monomorphize_mir_body_bad, 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 2d7d4cacd2c5..1437c29a50df 100644 --- a/crates/hir-ty/src/consteval/tests.rs +++ b/crates/hir-ty/src/consteval/tests.rs @@ -2,16 +2,16 @@ use base_db::SourceDatabase; 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, mir::pad16, test_db::TestDB, Const, ConstScalar, - Interner, MemoryMap, + Const, ConstScalar, Interner, MemoryMap, consteval::try_const_usize, db::HirDatabase, + mir::pad16, test_db::TestDB, }; use super::{ diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs index 76031491d9a0..9fe19641e43f 100644 --- a/crates/hir-ty/src/db.rs +++ b/crates/hir-ty/src/db.rs @@ -4,14 +4,14 @@ use std::sync; use base_db::{ - impl_intern_key, + CrateId, Upcast, impl_intern_key, ra_salsa::{self, InternValueTrivial}, - CrateId, Upcast, }; 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; @@ -19,7 +19,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, @@ -27,8 +28,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, }; #[ra_salsa::query_group(HirDatabaseStorage)] diff --git a/crates/hir-ty/src/diagnostics.rs b/crates/hir-ty/src/diagnostics.rs index 30c02a2936dd..95b233d4454c 100644 --- a/crates/hir-ty/src/diagnostics.rs +++ b/crates/hir-ty/src/diagnostics.rs @@ -5,9 +5,9 @@ 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_expressions, InsideUnsafeBlock, UnsafetyReason}, + unsafe_check::{InsideUnsafeBlock, UnsafetyReason, missing_unsafe, unsafe_expressions}, }; diff --git a/crates/hir-ty/src/diagnostics/decl_check.rs b/crates/hir-ty/src/diagnostics/decl_check.rs index 774991560e9c..d067122e775a 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 348f8a0f4a85..234c7e4b03c3 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 59aaf85164a0..1f5095453332 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -8,9 +8,9 @@ use base_db::CrateId; 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; @@ -18,27 +18,27 @@ use rustc_hash::FxHashSet; use rustc_pattern_analysis::constructor::Constructor; use span::Edition; 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::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 b0f9fc53e29e..1c58485eb97f 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 91eb59fb3140..7c4a9d677eae 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 ac849b0762d7..35bec8509290 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 ae8fbe2ce6d7..9b49fde66d74 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -11,6 +11,8 @@ use base_db::CrateId; 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, @@ -50,12 +55,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 { @@ -95,7 +95,7 @@ pub struct HirFormatter<'a> { enum BoundsFormattingCtx { Entered { /// We can have recursive bounds like the following case: - /// ```rust + /// ```ignore /// where /// T: Foo, /// T::FooAssoc: Baz<::BarAssoc> + Bar @@ -502,7 +502,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!" + ) } } } @@ -1356,7 +1358,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 351926c86c47..4e12b9b3af8c 100644 --- a/crates/hir-ty/src/drop.rs +++ b/crates/hir-ty/src/drop.rs @@ -2,15 +2,15 @@ use base_db::ra_salsa; 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::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 6a01579bccc9..1243832a5dcc 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 18cf6e5ce36e..9ed9817dfa07 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 0cb7002f4460..ae1b13ee33d0 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. @@ -335,7 +335,7 @@ impl Default for InternedStandardTypes { /// sized struct to a dynamically sized one. E.g., &[i32; 4] -> &[i32] is /// represented by: /// -/// ``` +/// ```ignore /// Deref(None) -> [i32; 4], /// Borrow(AutoBorrow::Ref) -> &[i32; 4], /// Unsize -> &[i32], @@ -481,9 +481,10 @@ pub struct InferenceResult { /// or pattern can have multiple binding modes. For example: /// ``` /// fn foo(mut slice: &[u32]) -> usize { - /// slice = match slice { - /// [0, rest @ ..] | rest => rest, - /// }; + /// slice = match slice { + /// [0, rest @ ..] | rest => rest, + /// }; + /// 0 /// } /// ``` /// the first `rest` has implicit `ref` binding mode, but the second `rest` binding mode is `move`. @@ -1189,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 } })); } @@ -1913,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, @@ -2043,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 eb193686e967..b2709ebd6357 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 9283c46d0f61..d59266d1f9cd 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 acd86b1f3ed8..b0fb01a84d18 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 e4f5b5ed378d..563c5699cff6 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 80e3ca1fa282..babfde82009f 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 d74a383f44ef..b157a8bfefd4 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 db93116f1071..6d2811635eea 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 6254bc12392b..088d3b130480 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/inhabitedness.rs b/crates/hir-ty/src/inhabitedness.rs index d6039c548b6f..89fa23fd1763 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 804c3aea3a5c..69c7a21b0617 100644 --- a/crates/hir-ty/src/interner.rs +++ b/crates/hir-ty/src/interner.rs @@ -2,16 +2,16 @@ //! 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 base_db::ra_salsa::InternId; 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 ff9c52fbb6c1..d638d50f8e34 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 e2ab336d2e46..e4123511d041 100644 --- a/crates/hir-ty/src/layout.rs +++ b/crates/hir-ty/src/layout.rs @@ -5,12 +5,12 @@ use std::fmt; use base_db::ra_salsa::Cycle; use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy}; use hir_def::{ + LocalFieldId, StructId, layout::{ BackendRepr, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutData, Primitive, ReprOptions, Scalar, Size, StructKind, TargetDataLayout, WrappingRange, }, - LocalFieldId, StructId, }; use la_arena::{Idx, RawIdx}; use rustc_abi::AddressSpace; @@ -20,12 +20,12 @@ use rustc_index::{IndexSlice, IndexVec}; use triomphe::Arc; use crate::{ + Interner, ProjectionTy, Substitution, TraitEnvironment, Ty, consteval::try_const_usize, db::{HirDatabase, InternedClosure}, infer::normalize, layout::adt::struct_variant_idx, utils::ClosureSubst, - Interner, ProjectionTy, Substitution, TraitEnvironment, Ty, }; pub use self::{ @@ -408,7 +408,7 @@ pub fn layout_of_ty_query( return Err(LayoutError::NotImplemented); } crate::ImplTraitId::AsyncBlockTypeImplTrait(_, _) => { - return Err(LayoutError::NotImplemented) + return Err(LayoutError::NotImplemented); } } } @@ -430,7 +430,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 0ba765bd75ef..892002904ee7 100644 --- a/crates/hir-ty/src/layout/adt.rs +++ b/crates/hir-ty/src/layout/adt.rs @@ -4,9 +4,9 @@ use std::{cmp, ops::Bound}; use base_db::ra_salsa::Cycle; 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, RustcEnumVariantIdx}, - Substitution, TraitEnvironment, + layout::{Layout, LayoutError, RustcEnumVariantIdx, field_ty}, }; use super::LayoutCx; diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs index 4d3896660b47..b4c03e19a3e1 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 707c43777267..f6b5d90aadd6 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -64,20 +64,20 @@ use std::hash::Hash; use base_db::ra_salsa::InternValueTrivial; 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 span::Edition; -use syntax::ast::{make, ConstArg}; +use syntax::ast::{ConstArg, make}; use traits::FnTrait; use triomphe::Arc; @@ -91,16 +91,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, @@ -110,13 +110,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; @@ -651,10 +651,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 @@ -784,8 +782,8 @@ where T: HasInterner + TypeFoldable + Clone, { use chalk_ir::{ - fold::{FallibleTypeFolder, TypeSuperFoldable}, Fallible, + fold::{FallibleTypeFolder, TypeSuperFoldable}, }; struct ErrorReplacer { vars: usize, @@ -846,11 +844,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( @@ -859,11 +853,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( @@ -871,11 +861,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( @@ -883,11 +869,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 af73b5ed9a7b..170abc7d2cf0 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -14,18 +14,21 @@ use std::{ ops::{self, Not as _}, }; -use base_db::{ra_salsa::Cycle, CrateId}; +use base_db::{CrateId, ra_salsa::Cycle}; 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; @@ -52,27 +52,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, 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)] @@ -1298,11 +1297,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 a165932ddcc8..92b50eeb83aa 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 2f38e8fa14c0..400b60527dd1 100644 --- a/crates/hir-ty/src/mapping.rs +++ b/crates/hir-ty/src/mapping.rs @@ -9,8 +9,8 @@ use base_db::ra_salsa::{self, InternKey}; use hir_def::{LifetimeParamId, TraitId, TypeAliasId, TypeOrConstParamId}; 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 db94351dcc99..56ee737c753d 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::CrateId; -use chalk_ir::{cast::Cast, UniverseIndex, WithKind}; +use chalk_ir::{UniverseIndex, WithKind, cast::Cast}; use hir_def::{ - data::{adt::StructFlags, ImplData, TraitFlags}, - nameres::DefMap, AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup, ModuleId, TraitId, + data::{ImplData, TraitFlags, adt::StructFlags}, + nameres::DefMap, }; 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::{ + 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::{unify::InferenceTable, Adjust, Adjustment, OverloadedDeref, PointerCast}, + infer::{Adjust, Adjustment, OverloadedDeref, PointerCast, unify::InferenceTable}, 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, }; /// 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( @@ -705,11 +701,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 41304bbd8a91..4c2e8ee75fee 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::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::CrateId; 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,19 +28,19 @@ 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, mir_body_recover, MirLowerError, + MirLowerError, lower_to_mir, mir_body_for_closure_query, mir_body_query, mir_body_recover, }; pub use monomorphization::{ monomorphize_mir_body_bad, monomorphized_mir_body_for_closure_query, monomorphized_mir_body_query, monomorphized_mir_body_recover, }; use rustc_hash::FxHashMap; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use stdx::{impl_from, never}; use super::consteval::{intern_const_scalar, try_const_usize}; diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs index 9c86d3b59f6d..cf864daa8e45 100644 --- a/crates/hir-ty/src/mir/borrowck.rs +++ b/crates/hir-ty/src/mir/borrowck.rs @@ -12,10 +12,10 @@ use stdx::never; use triomphe::Arc; use crate::{ + ClosureId, Interner, Substitution, Ty, TyExt, TypeFlags, db::{HirDatabase, InternedClosure}, mir::Operand, utils::ClosureSubst, - ClosureId, Interner, Substitution, Ty, TyExt, TypeFlags, }; use super::{ @@ -375,11 +375,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/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs index 7d3376f56be1..9bef7b675bff 100644 --- a/crates/hir-ty/src/mir/eval/shim.rs +++ b/crates/hir-ty/src/mir/eval/shim.rs @@ -10,18 +10,17 @@ use hir_def::{ resolver::HasResolver, }; use hir_expand::name::Name; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; use stdx::never; use crate::{ - error_lifetime, + DropGlue, 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 +1356,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/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs index 2b5486fc5fa0..bbf9fb3ecc30 100644 --- a/crates/hir-ty/src/mir/eval/tests.rs +++ b/crates/hir-ty/src/mir/eval/tests.rs @@ -3,9 +3,9 @@ use span::{Edition, EditionedFileId}; use syntax::{TextRange, TextSize}; use test_fixture::WithFixture; -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/pattern_matching.rs b/crates/hir-ty/src/mir/lower/pattern_matching.rs index 289175feefb1..b805b8c70348 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( @@ -610,7 +610,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 92132fa04736..05f3552c79f8 100644 --- a/crates/hir-ty/src/mir/monomorphization.rs +++ b/crates/hir-ty/src/mir/monomorphization.rs @@ -11,19 +11,19 @@ use std::mem; use base_db::ra_salsa::Cycle; 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, 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 2a26101ac439..240e1dc9997a 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -7,15 +7,15 @@ 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 span::Edition; use crate::{ + ClosureId, db::HirDatabase, display::{ClosureStyle, 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 fe9416c6cfc6..01e4160edb8d 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 f37dd91d8e90..b9d2c858a718 100644 --- a/crates/hir-ty/src/test_db.rs +++ b/crates/hir-ty/src/test_db.rs @@ -3,10 +3,10 @@ use std::{fmt, panic, sync::Mutex}; use base_db::{ - ra_salsa::{self, Durability}, AnchoredPath, CrateId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, + ra_salsa::{self, Durability}, }; -use hir_def::{db::DefDatabase, ModuleId}; +use hir_def::{ModuleId, db::DefDatabase}; use hir_expand::db::ExpandDatabase; use rustc_hash::FxHashMap; use span::{EditionedFileId, FileId}; diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs index f5a4d4ff35c3..1baf0d8b9022 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::SourceDatabaseFileInputExt as _; 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::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 34d299edd1bd..ec2fd8b1692a 100644 --- a/crates/hir-ty/src/tests/closure_captures.rs +++ b/crates/hir-ty/src/tests/closure_captures.rs @@ -1,5 +1,5 @@ use base_db::ra_salsa::InternKey; -use expect_test::{expect, Expect}; +use expect_test::{Expect, expect}; use hir_def::db::DefDatabase; use hir_expand::files::InFileWrapper; use itertools::Itertools; @@ -380,7 +380,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 6cb59491fac8..b718556c8ae0 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 8cb7dbf60f37..73492c324df5 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::CrateId; 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 89d89fe2230a..dc0ba0557e43 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::CrateId; 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( @@ -318,11 +318,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 3a22158ce6f1..3a06a1dc059c 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 4351a34e8228..ba0ff903b994 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 1ed0daa37563..a9893e741d54 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 6f4168ab0867..ec34fd80ad68 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::{ + AliasEq, AliasTy, Interner, ProjectionTyExt, TraitRefExt, TyKind, WhereClause, display::{ - hir_display_with_types_map, write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, HirDisplayWithTypesMap, HirFormatter, SizedByDefault, + hir_display_with_types_map, write_bounds_like_dyn_trait_with_prefix, write_visibility, }, - AliasEq, AliasTy, Interner, ProjectionTyExt, TraitRefExt, TyKind, WhereClause, }; 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 72df07ef8c0c..117955691019 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 a34b4980832c..955017a5cd8e 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,9 @@ 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, + Struct, Trait, TraitAlias, TypeAlias, TypeOrConstParam, Union, Variant, db::HirDatabase, }; pub trait HasSource { diff --git a/crates/hir/src/semantics/child_by_source.rs b/crates/hir/src/semantics/child_by_source.rs index d0fdf5cbdf7a..473bbc9da45d 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 4481b8855fd6..276a23500a7f 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -5,7 +5,7 @@ //! //! This module solves the following problem: //! -//! Given a piece of syntax, find the corresponding semantic definition (def). +//! > Given a piece of syntax, find the corresponding semantic definition (def). //! //! This problem is a part of more-or-less every IDE feature implemented. Every //! IDE functionality (like goto to definition), conceptually starts with a @@ -87,30 +87,30 @@ 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, - MacroFileIdExt, + ExpansionInfo, HirFileId, HirFileIdExt, InMacroFile, MacroCallId, MacroFileIdExt, + attrs::AttrId, name::AsName, }; use rustc_hash::FxHashMap; use smallvec::SmallVec; use span::{EditionedFileId, FileId, MacroFileId}; 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 9019863f7fde..e736eed54f5f 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_expressions, - InsideUnsafeBlock, + InsideUnsafeBlock, record_literal_missing_fields, record_pattern_missing_fields, + unsafe_expressions, }, 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 2ebd88edae2d..56d584f6b57c 100644 --- a/crates/hir/src/symbols.rs +++ b/crates/hir/src/symbols.rs @@ -2,23 +2,23 @@ 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, HirDisplay}, + display::{HirDisplay, hir_display_with_types_map}, }; use intern::Symbol; use rustc_hash::FxHashMap; use span::Edition; -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/expr.rs b/crates/hir/src/term_search/expr.rs index 6ad074e8e5c8..d2070f0e18b4 100644 --- a/crates/hir/src/term_search/expr.rs +++ b/crates/hir/src/term_search/expr.rs @@ -40,7 +40,7 @@ fn mod_item_path_str( /// Type tree shows how can we get from set of types to some type. /// /// Consider the following code as an example -/// ``` +/// ```ignore /// fn foo(x: i32, y: bool) -> Option { None } /// fn bar() { /// let a = 1; diff --git a/crates/hir/src/term_search/tactics.rs b/crates/hir/src/term_search/tactics.rs index 847304d503a8..bcff44fcd016 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 05105c8c92c5..2de0013bb126 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 64e77b2d6982..0f32e9bc2077 100644 --- a/crates/ide-assists/src/assist_context.rs +++ b/crates/ide-assists/src/assist_context.rs @@ -2,16 +2,16 @@ use hir::{FileRange, Semantics}; use ide_db::EditionedFileId; -use ide_db::{label::Label, FileId, RootDatabase}; +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 42f615e71daf..f9124d2d4655 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_label_to_loop.rs b/crates/ide-assists/src/handlers/add_label_to_loop.rs index 001f1e8bb158..fc10501543b4 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 43c0a72fa477..c3e05b8fb083 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 83c049d4613b..3caacd67ebc9 100644 --- a/crates/ide-assists/src/handlers/apply_demorgan.rs +++ b/crates/ide-assists/src/handlers/apply_demorgan.rs @@ -6,12 +6,12 @@ use ide_db::{ syntax_helpers::node_ext::{for_each_tail_expr, walk_expr}, }; use syntax::{ - ast::{self, syntax_factory::SyntaxFactory, AstNode, Expr::BinExpr, HasArgList}, - syntax_editor::{Position, SyntaxEditor}, SyntaxKind, SyntaxNode, T, + ast::{self, AstNode, Expr::BinExpr, HasArgList, syntax_factory::SyntaxFactory}, + syntax_editor::{Position, SyntaxEditor}, }; -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 a92a000c3fbd..f491b9375c33 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 8f053f4df949..5048ff5163ab 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/bool_to_enum.rs b/crates/ide-assists/src/handlers/bool_to_enum.rs index cbd39796241b..812394aa668b 100644 --- a/crates/ide-assists/src/handlers/bool_to_enum.rs +++ b/crates/ide-assists/src/handlers/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/change_visibility.rs b/crates/ide-assists/src/handlers/change_visibility.rs index 07fd5e34181e..8af9121fc8d1 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 8d391c64ce61..73a2ba68f7e4 100644 --- a/crates/ide-assists/src/handlers/convert_bool_then.rs +++ b/crates/ide-assists/src/handlers/convert_bool_then.rs @@ -1,20 +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, make, HasArgList}, - ted, AstNode, SyntaxNode, + AstNode, SyntaxNode, + ast::{self, HasArgList, edit::AstNodeEdit, make}, + ted, }; use crate::{ - utils::{invert_boolean_expression_legacy, unwrap_trivial_block}, AssistContext, AssistId, AssistKind, Assists, + utils::{invert_boolean_expression_legacy, unwrap_trivial_block}, }; // Assist: convert_if_to_bool_then 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 d34cf895cd90..3e0426177ba5 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 fbc0b9f6739f..92b86cee356e 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 c7b1314c861e..7b4d27100f15 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}; @@ -136,7 +136,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem /// Not all comments are valid candidates for conversion into doc comments. For example, the /// comments in the code: -/// ```rust +/// ```ignore /// // Brilliant module right here /// /// // Really good right @@ -148,7 +148,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem /// mod nice_module {} /// ``` /// can be converted to doc comments. However, the comments in this example: -/// ```rust +/// ```ignore /// fn foo_bar(foo: Foo /* not bar yet */) -> Bar { /// foo.into_bar() /// // Nicely done @@ -162,7 +162,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem /// are not allowed to become doc comments. Moreover, some comments _are_ allowed, but aren't common /// style in Rust. For example, the following comments are allowed to be doc comments, but it is not /// common style for them to be: -/// ```rust +/// ```ignore /// fn foo_bar(foo: Foo) -> Bar { /// // this could be an inner comment with //! /// foo.into_bar() 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 dd2e9cbcb5f2..07ad5a695b3c 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 fd3378e8c263..270eecd83b06 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 3c9a91741047..713d215f1209 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 79c34c14da72..9f71031a1e68 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 fd159eb824d6..2db78f412d74 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 8d4ff84084bd..7b8804e53f08 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 b7a77644496f..bd829d1e24bf 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 91af9b05bbb8..0d7993788571 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 f6e516db8883..83e4737350c0 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 beec64d13b68..724de1969cb5 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::{ + AstNode, T, ast::{ - self, + self, HasLoopBody, edit::{AstNodeEdit, IndentLevel}, - make, HasLoopBody, + make, }, - AstNode, T, }; 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 e34e50904875..a8a3a8c927f8 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 39142d606207..95eb88fa8687 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 d26492804670..9d0797d32a82 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 0b95d6177f90..fae5530f9952 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/explicit_enum_discriminant.rs b/crates/ide-assists/src/handlers/explicit_enum_discriminant.rs index fafc3448a87c..9d138100ba59 100644 --- a/crates/ide-assists/src/handlers/explicit_enum_discriminant.rs +++ b/crates/ide-assists/src/handlers/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/extract_expressions_from_format_string.rs b/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs index e4d347ef16bd..c9eb7c52379f 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 967da41c15f7..247b617e4f42 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::{ + Edition, SyntaxElement, + SyntaxKind::{self, COMMENT}, + SyntaxNode, SyntaxToken, T, TextRange, TextSize, TokenAtOffset, WalkEvent, ast::{ - self, edit::IndentLevel, edit_in_place::Indent, AstNode, AstToken, HasGenericParams, - HasName, + self, AstNode, AstToken, HasGenericParams, HasName, edit::IndentLevel, + edit_in_place::Indent, }, - match_ast, ted, Edition, SyntaxElement, - SyntaxKind::{self, COMMENT}, - SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, WalkEvent, T, + match_ast, ted, }; use crate::{ + AssistId, assist_context::{AssistContext, Assists, TreeMutator}, utils::generate_impl, - AssistId, }; // Assist: extract_function @@ -272,7 +273,7 @@ fn make_function_name(semantics_scope: &hir::SemanticsScope<'_>) -> ast::NameRef /// * We want whole node, like `loop {}`, `2 + 2`, `{ let n = 1; }` exprs. /// Then we can use `ast::Expr` /// * We want a few statements for a block. E.g. -/// ```rust,no_run +/// ```ignore /// fn foo() -> i32 { /// let m = 1; /// $0 @@ -386,7 +387,7 @@ struct ContainerInfo { /// Control flow that is exported from extracted function /// /// E.g.: -/// ```rust,no_run +/// ```ignore /// loop { /// $0 /// if 42 == 42 { @@ -1686,11 +1687,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 6e3be0ce6927..9b49ecbf546a 100644 --- a/crates/ide-assists/src/handlers/extract_module.rs +++ b/crates/ide-assists/src/handlers/extract_module.rs @@ -3,23 +3,24 @@ use std::iter; use either::Either; use hir::{HasSource, HirFileIdExt, ModuleSource}; 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::{ + AstNode, + SyntaxKind::{self, WHITESPACE}, + SyntaxNode, TextRange, TextSize, algo::find_node_at_range, ast::{ - self, + self, HasVisibility, edit::{AstNodeEdit, IndentLevel}, - make, HasVisibility, + make, }, - match_ast, ted, AstNode, - SyntaxKind::{self, WHITESPACE}, - SyntaxNode, TextRange, TextSize, + match_ast, ted, }; use crate::{AssistContext, Assists}; @@ -1159,8 +1160,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 d4f2ea3bd941..7fba75f9e56d 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 67b8f5e50503..e6fb4d40d46b 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 7b6f76d00452..2e58e62ab0cc 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/fill_record_pattern_fields.rs b/crates/ide-assists/src/handlers/fill_record_pattern_fields.rs index ee321864805e..56e6cb9d091d 100644 --- a/crates/ide-assists/src/handlers/fill_record_pattern_fields.rs +++ b/crates/ide-assists/src/handlers/fill_record_pattern_fields.rs @@ -1,6 +1,6 @@ use syntax::{ - ast::{self, make}, AstNode, ToSmolStr, + ast::{self, make}, }; use crate::{AssistContext, AssistId, Assists}; diff --git a/crates/ide-assists/src/handlers/fix_visibility.rs b/crates/ide-assists/src/handlers/fix_visibility.rs index 47e4a68293f0..51dbce297317 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 818a868fe344..75133c3a023b 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 95e035c05379..b4f17767fae7 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, SyntaxElement, SyntaxKind, SyntaxToken, T, algo::non_trivia_sibling, ast::{self, syntax_factory::SyntaxFactory}, syntax_editor::{Element, SyntaxMapping}, - AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxToken, 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 298e5bd82c98..03026c765774 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 7f7db07152d3..2f4b6a0421bb 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 a6e3d49e0d1a..c6725a013e3b 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 dc27af5cbed2..1a4349cfea91 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 220259451e86..750f160ec2d2 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 55b860d0ff54..5c39214617e4 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 e558bb6da89b..7bf29978128e 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 53ba144ba9e3..8b4dbeff7cf4 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 862be791d173..df05c0d6b2f3 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 b5d3ed436970..78fdca910c7a 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 ee643ce9a4ac..e96be673a1b6 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 bb08cb904ead..51b6a4be019d 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 9d01ec00f836..bc890ac53b88 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 6091f06b9669..88226820cf27 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 8f5daa4125a3..5ee31e081159 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -3,26 +3,27 @@ use hir::{ StructKind, Type, TypeInfo, }; 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 @@ -178,9 +179,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!( "{}", @@ -1037,7 +1037,7 @@ fn filter_bounds_in_scope( /// Makes duplicate argument names unique by appending incrementing numbers. /// -/// ``` +/// ```ignore /// let mut names: Vec = /// vec!["foo".into(), "foo".into(), "bar".into(), "baz".into(), "bar".into()]; /// deduplicate_arg_names(&mut names); 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 ac58af625252..8e9ed7b2a289 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 4439830947ad..ff4f388e39cb 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 ad422b25c39e..d9ed8111c6f8 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 6aa561ad7f03..8d107e412896 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 70d14d6b95d8..f14a4c107075 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 5f7350bc2812..3470a4d660dc 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 9e09f198feb4..59ae728ca6c6 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::CrateId, 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 c92c22378f87..c6a33e7f9b74 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 b9fc075ae838..34a30c431a0a 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, AstNode, AstToken, HasName}, SyntaxElement, TextRange, + ast::{self, AstNode, AstToken, HasName}, }; 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 66dffde505c1..936b09d5a46c 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; @@ -276,7 +277,7 @@ impl ConstAndTypeMap { /// 1. Map the provided instance's generic args to the type alias's generic /// params: /// -/// ``` +/// ```ignore /// type A<'a, const N: usize, T = u64> = &'a [T; N]; /// ^ alias generic params /// let a: A<100>; 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 e405af5533d5..c8ec3da180b8 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_generic.rs b/crates/ide-assists/src/handlers/introduce_named_generic.rs index 8c276415bb1f..7ddd255c6c67 100644 --- a/crates/ide-assists/src/handlers/introduce_named_generic.rs +++ b/crates/ide-assists/src/handlers/introduce_named_generic.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/introduce_named_lifetime.rs b/crates/ide-assists/src/handlers/introduce_named_lifetime.rs index 62909c586e3d..587e76585f14 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/invert_if.rs b/crates/ide-assists/src/handlers/invert_if.rs index ac710503d8a0..4273a85df5a6 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 417123083690..aae007577c24 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 f83de931eaba..be73377070f3 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 7a0037fa202b..89bd62a084a3 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 5101d8fa0a9e..35571ed8341d 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 743ea9476150..71b1461a6ea6 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 10915f8aafb8..0d6fc49e5fe3 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 a487960d8d4c..abba3de4a1fa 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 bbf18e21948e..5f547593b43a 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 7b38c795dc80..a19c122ddf07 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 0b91eb676df0..813c2dd191db 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 a13799f9b131..9b81aecd7da8 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 0cc771ff3979..04a19d7869c5 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 f222b3eb903c..d9e71ec763d0 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 c3600af5a6c5..d8ade0eb8718 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 2a8465f634cf..a4f066ad364f 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 5a197f23d0e3..21c697f53869 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 1f57f7d3d376..cbc2e4f00473 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 143d5e542428..b31979a91bc1 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 0570b447782e..01c4eedd3e2d 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 5ddb17b20729..4da990d384dc 100644 --- a/crates/ide-assists/src/handlers/remove_unused_param.rs +++ b/crates/ide-assists/src/handlers/remove_unused_param.rs @@ -1,16 +1,16 @@ -use ide_db::{defs::Definition, search::FileReference, EditionedFileId}; +use ide_db::{EditionedFileId, 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 a79a82be4507..410e2bbbdffc 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 c3404173eafe..e254fb9949d4 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 4b20b35c4462..39f350fb68d5 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 31e828eae271..7696a14a4f59 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 e324d6eaaad2..c3b753653c21 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 47972ff619ac..c49f285d8e9d 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 c071d3022d25..34bbd6ba5be7 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 12d025f07594..88b56ebb4b1c 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 26fd887cc99e..f99394e8775e 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 f026b3230dd6..08a4d28e9fea 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 a48b20acbcac..176b4e4af088 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 88b50543dda8..93dfe48ebcab 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 3a6391cd3800..39ebca25a90f 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 54e16d4d80a4..73dfbf023792 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 775ededecbcc..63371ddf9fbc 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 66671c934c4b..49c7c1628164 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 8f937a04122d..9f45b2898a76 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 264a2f0326ec..c1ea7dc4c78c 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 e452b5f77870..80834abecc95 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 6b9f661d4de5..8b6aef02eccd 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::{ + Direction, SyntaxKind, T, algo::neighbor, - ast::{self, edit::IndentLevel, make, AstNode}, + ast::{self, AstNode, edit::IndentLevel, make}, ted::{self, Position}, - Direction, SyntaxKind, T, }; 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 38ca572fa660..7f2dd19ce075 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 abe7fb132f0b..f3ae70160bf3 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 0876246e90b1..beb1b333b945 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, make, AstNode, HasArgList}, TextRange, + ast::{self, AstNode, HasArgList, make}, }; 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 fd37140e9c2b..80d8cebff5bb 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 f647b531b774..f6eb68524f2d 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 d09614c51127..55053ac97dc6 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 0b145dcb06ba..8857c446f6d5 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 149cb4c43849..717c68d04e05 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 11aeb21c77e5..063aa03369ce 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, SourceRootDatabase}, 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 39686f065a9c..3ced9f14657a 100644 --- a/crates/ide-assists/src/utils.rs +++ b/crates/ide-assists/src/utils.rs @@ -2,28 +2,28 @@ pub(crate) use gen_trait_fn_body::gen_trait_fn_body; use hir::{ - db::{ExpandDatabase, HirDatabase}, 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, Edition, 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, Edition, NodeOrToken, SourceFile, - SyntaxKind::*, - SyntaxNode, SyntaxToken, TextRange, TextSize, WalkEvent, T, + ted, }; use crate::assist_context::{AssistContext, SourceChangeBuilder}; @@ -81,11 +81,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 } }) } @@ -497,11 +493,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 7a9bdfe1ecc2..5c2e27b3430f 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 d434872ea595..28830cf2f92b 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 a22e7b272ea0..c8cdad594978 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 cf5427bae38d..fb7df8cc7f44 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 cda0da13b26e..1676a8467c85 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 1f8927401b2f..2fc07e013828 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 04f40e805ad6..c87c46d98127 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 deb12282c025..0641a4f6c3fe 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 12652b448925..cb7ccf737312 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 b38b9ac1f539..dea983b6ea81 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 40af5203e9c3..ab8d8a6169c9 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 365d2dde7e94..32de33e25c3f 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 7c2cc2a6c1d8..570d1a0a2db8 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 7cb710c2d963..71a3e4eb4ed6 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 b795bbd872a0..1441b0e3a01a 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 b5555e661024..b3ba07648930 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 e86eaad4d0f2..6d1e973dc4c5 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 dcd40c3412c7..5ae65b05bc42 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 3ab341e4eded..4ae00ccd81bc 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 831f5665f4aa..e08271f39a32 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 53a62fe49c5a..9bb2bea74b7d 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 cca6a22f290d..04d359196487 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::{SourceRootDatabase, VfsPath}, FxHashSet, RootDatabase, SymbolKind, + base_db::{SourceRootDatabase, 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 8f38e02ed768..d93a352a1ac8 100644 --- a/crates/ide-completion/src/completions/pattern.rs +++ b/crates/ide-completion/src/completions/pattern.rs @@ -1,12 +1,12 @@ //! Completes constants and paths in unqualified patterns. -use hir::{db::DefDatabase, AssocItem, ScopeDef}; +use hir::{AssocItem, ScopeDef, db::DefDatabase}; 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 28e2853096e0..fe4091536808 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 c612170eb54b..7faa1139595f 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 d0c4c24d060f..c18aab007b2c 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 357709e0c1fd..31aae1167622 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 b07148809323..79db705af495 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 b384987c51ce..4d6d0b758a38 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 0ea5157fb46f..d15c35ac8499 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 45aab38e8ea0..844fce5ef801 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 7862b258789c..30974ad20e9c 100644 --- a/crates/ide-completion/src/context.rs +++ b/crates/ide-completion/src/context.rs @@ -11,20 +11,21 @@ use hir::{ SemanticsScope, Symbol, Type, TypeInfo, }; use ide_db::{ - base_db::SourceDatabase, famous_defs::FamousDefs, helpers::is_editable_crate, FilePosition, - FxHashMap, FxHashSet, RootDatabase, + FilePosition, FxHashMap, FxHashSet, RootDatabase, base_db::SourceDatabase, + 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"; @@ -249,8 +250,8 @@ pub(crate) enum Qualified { /// This would be None, if path is not solely made of /// `super` segments, e.g. /// - /// ```rust - /// use super::foo; + /// ```ignore + /// use super::foo; /// ``` /// /// Otherwise it should be Some(count of `super`) @@ -674,11 +675,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 eecd412bc43e..8f58c2181ef4 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)] @@ -97,7 +98,8 @@ fn token_at_offset_ignore_whitespace(file: &SyntaxNode, offset: TextSize) -> Opt /// We do this by recursively expanding all macros and picking the best possible match. We cannot just /// choose the first expansion each time because macros can expand to something that does not include /// our completion marker, e.g.: -/// ``` +/// +/// ```ignore /// macro_rules! helper { ($v:ident) => {} } /// macro_rules! my_macro { /// ($v:ident) => { @@ -106,7 +108,7 @@ fn token_at_offset_ignore_whitespace(file: &SyntaxNode, offset: TextSize) -> Opt /// }; /// } /// -/// my_macro!(complete_me_here) +/// my_macro!(complete_me_here); /// ``` /// If we would expand the first thing we encounter only (which in fact this method used to do), we would /// be unable to complete here, because we would be walking directly into the void. So we instead try diff --git a/crates/ide-completion/src/context/tests.rs b/crates/ide-completion/src/context/tests.rs index fc2bfc01e62a..625a6e0505ea 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 41a82409597b..a0ae8b227e12 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 @@ -149,9 +149,9 @@ pub struct CompletionRelevance { /// This is set when the identifier being completed matches up with the name that is expected, /// like in a function argument. /// - /// ``` + /// ```ignore /// fn f(spam: String) {} - /// fn main { + /// fn main() { /// let spam = 92; /// f($0) // name of local matches the name of param /// } @@ -161,7 +161,7 @@ pub struct CompletionRelevance { pub type_match: Option, /// Set for local variables. /// - /// ``` + /// ```ignore /// fn foo(a: u32) { /// let b = 0; /// $0 // `a` and `b` are local @@ -195,7 +195,7 @@ pub struct CompletionRelevanceTraitInfo { pub enum CompletionRelevanceTypeMatch { /// This is set in cases like these: /// - /// ``` + /// ```ignore /// enum Option { Some(T), None } /// fn f(a: Option) {} /// fn main { @@ -205,9 +205,9 @@ pub enum CompletionRelevanceTypeMatch { CouldUnify, /// This is set in cases where the type matches the expected type, like: /// - /// ``` + /// ```ignore /// fn f(spam: String) {} - /// fn main { + /// fn main() { /// let foo = String::new(); /// f($0) // type of local matches the type of param /// } @@ -221,7 +221,7 @@ pub enum CompletionRelevancePostfixMatch { NonExact, /// This is set in cases like these: /// - /// ``` + /// ```ignore /// (a > b).not$0 /// ``` /// diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs index a1f2eaeb1b6d..ef5ef8135471 100644 --- a/crates/ide-completion/src/lib.rs +++ b/crates/ide-completion/src/lib.rs @@ -11,10 +11,10 @@ mod snippet; mod tests; use ide_db::{ + FilePosition, FxHashSet, RootDatabase, imports::insert_use::{self, ImportScope}, syntax_helpers::tree_diff::diff, text_edit::TextEdit, - FilePosition, FxHashSet, RootDatabase, }; use syntax::ast::make; @@ -143,7 +143,7 @@ impl CompletionFieldsToResolve { /// already present, it should give all possible variants for the identifier at /// the caret. In other words, for /// -/// ```no_run +/// ```ignore /// fn f() { /// let foo = 92; /// let _ = bar$0 diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index dc7eacbfbafd..a7351a58101e 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)] @@ -682,14 +682,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 fd90613964af..6394806d497a 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, Edition, SmolStr, ToSmolStr}; +use syntax::{AstNode, Edition, 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 aab54ca5e014..2845cf8156ed 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, context::{CompletionContext, PathCompletionCtx, PathKind}, item::{Builder, CompletionItem}, 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, }; pub(crate) fn render_variant_lit( @@ -158,11 +157,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 e265e92f9794..6a366f2001d1 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 124abb17b6a1..93e6c5237948 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 742036265211..ec8a98209c7e 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::{ + CompletionItem, CompletionItemKind, 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_union_literal( diff --git a/crates/ide-completion/src/render/variant.rs b/crates/ide-completion/src/render/variant.rs index d8516ea10786..de2c98372e89 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::{db::HirDatabase, sym, HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind}; +use hir::{HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind, db::HirDatabase, sym}; use ide_db::SnippetCap; use itertools::Itertools; use syntax::{Edition, SmolStr}; diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index 9d91f95eb65b..11f39be9c980 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 375575128377..eac11363d7c5 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 2e7c53def7fc..8bba44c12bf6 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 9ab66243b5c8..5ddb3d91f2bd 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 2b05184bdbeb..173eab4e7eed 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::{ + CompletionItemKind, tests::{ - check, check_edit, check_no_kw, check_with_trigger_character, do_completion_with_config, - TEST_CONFIG, + TEST_CONFIG, check, check_edit, check_no_kw, check_with_trigger_character, + do_completion_with_config, }, - CompletionItemKind, }; #[test] diff --git a/crates/ide-db/src/active_parameter.rs b/crates/ide-db/src/active_parameter.rs index 11808fed3be6..06ed4afdf9be 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 46ff4fbf9e90..ff7b277d4c18 100644 --- a/crates/ide-db/src/apply_change.rs +++ b/crates/ide-db/src/apply_change.rs @@ -1,17 +1,17 @@ //! Applies changes to the IDE state transactionally. use base_db::{ + SourceRootId, ra_salsa::{ - debug::{DebugQueryTable, TableEntry}, Database, Durability, Query, QueryTable, + debug::{DebugQueryTable, TableEntry}, }, - SourceRootId, }; -use profile::{memory_usage, Bytes}; +use profile::{Bytes, memory_usage}; use rustc_hash::FxHashSet; 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 6f71c3d9bd7e..1dbf265e1b82 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 b83efcd02f77..96654a2416b6 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 2f4d07446f2c..8efd866b9ef2 100644 --- a/crates/ide-db/src/famous_defs.rs +++ b/crates/ide-db/src/famous_defs.rs @@ -221,11 +221,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 84fa58d743bb..f651258dc770 100644 --- a/crates/ide-db/src/helpers.rs +++ b/crates/ide-db/src/helpers.rs @@ -6,13 +6,14 @@ use base_db::SourceRootDatabase; 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 77fc59b4eccb..0fc287c57e7c 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 8e25ad3472d3..d26e5d62ced5 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::{ + RootDatabase, imports::merge_imports::{ - common_prefix, eq_attrs, eq_visibility, try_merge_imports, use_tree_cmp, MergeBehavior, - NormalizationStyle, + MergeBehavior, NormalizationStyle, common_prefix, eq_attrs, eq_visibility, + try_merge_imports, use_tree_cmp, }, - RootDatabase, }; 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 decb0ea9d8a8..9b5aa7cf4ea1 100644 --- a/crates/ide-db/src/imports/insert_use/tests.rs +++ b/crates/ide-db/src/imports/insert_use/tests.rs @@ -1,6 +1,6 @@ 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 9e89dfe87abe..61962e593476 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 4d9c051354a6..80881829800e 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 3a29232d331f..798fbbc337e7 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -50,13 +50,13 @@ pub use hir::ChangeWithProcMacros; use std::{fmt, mem::ManuallyDrop}; use base_db::{ + AnchoredPath, CrateId, DEFAULT_FILE_TEXT_LRU_CAP, FileLoader, FileLoaderDelegate, + SourceDatabase, Upcast, ra_salsa::{self, Durability}, - AnchoredPath, CrateId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, - DEFAULT_FILE_TEXT_LRU_CAP, }; use hir::{ - db::{DefDatabase, ExpandDatabase, HirDatabase}, FilePositionWrapper, FileRangeWrapper, + db::{DefDatabase, ExpandDatabase, HirDatabase}, }; use triomphe::Arc; @@ -288,11 +288,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 f045e44dd318..bad1f41a1d17 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)] @@ -32,7 +33,7 @@ type DefaultedParam = Either; /// block), you generally want to appropriately qualify the names, and sometimes /// you might want to substitute generic parameters as well: /// -/// ``` +/// ```ignore /// mod x { /// pub struct A; /// pub trait T { fn foo(&self, _: U) -> A; } diff --git a/crates/ide-db/src/prime_caches.rs b/crates/ide-db/src/prime_caches.rs index 22dc3d9e29d6..64202d560a29 100644 --- a/crates/ide-db/src/prime_caches.rs +++ b/crates/ide-db/src/prime_caches.rs @@ -6,16 +6,16 @@ mod topologic_sort; use std::time::Duration; -use hir::{db::DefDatabase, Symbol}; +use hir::{Symbol, db::DefDatabase}; use itertools::Itertools; use crate::{ + FxIndexMap, RootDatabase, base_db::{ - ra_salsa::{Database, ParallelDatabase, Snapshot}, Cancelled, CrateId, SourceDatabase, + ra_salsa::{Database, ParallelDatabase, Snapshot}, }, 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 59914bedde43..777494f7cc6a 100644 --- a/crates/ide-db/src/rename.rs +++ b/crates/ide-db/src/rename.rs @@ -27,20 +27,20 @@ use base_db::AnchoredPathBuf; use either::Either; use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics}; use span::{Edition, EditionedFileId, FileId, SyntaxContextId}; -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 7963e8ae4f78..9dfd8af5b395 100644 --- a/crates/ide-db/src/search.rs +++ b/crates/ide-db/src/search.rs @@ -7,28 +7,28 @@ use std::mem; use std::{cell::LazyCell, cmp::Reverse}; -use base_db::{ra_salsa::Database, SourceDatabase, SourceRootDatabase}; +use base_db::{SourceDatabase, SourceRootDatabase, ra_salsa::Database}; 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; use rustc_hash::{FxHashMap, FxHashSet}; 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)] @@ -1277,7 +1277,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 27ff91dc19d9..784d3a4efc05 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, 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}, }; #[derive(Default, Debug, Clone)] @@ -457,13 +457,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) } @@ -493,7 +494,7 @@ pub enum Snippet { Placeholder(TextRange), /// A group of placeholder snippets, e.g. /// - /// ```no_run + /// ```ignore /// let ${0:new_var} = 4; /// fun(1, 2, 3, ${0:new_var}); /// ``` diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs index bb4c289c9084..6623872ec455 100644 --- a/crates/ide-db/src/symbol_index.rs +++ b/crates/ide-db/src/symbol_index.rs @@ -29,15 +29,15 @@ use std::{ }; use base_db::{ - ra_salsa::{self, ParallelDatabase}, SourceRootDatabase, SourceRootId, Upcast, + ra_salsa::{self, ParallelDatabase}, }; -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 92478ef480d6..7e8c921d9ed3 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 c104aa571894..8f25833fffb8 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 74c0b8e2baac..1c4828cee23f 100644 --- a/crates/ide-db/src/syntax_helpers/node_ext.rs +++ b/crates/ide-db/src/syntax_helpers/node_ext.rs @@ -3,8 +3,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 0a7141c19b6b..354f665b66cc 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; @@ -79,7 +80,9 @@ const USELESS_METHODS: &[&str] = &[ /// the name, e.g. `a`, `a1`, `a2`, ... /// /// # Examples -/// ```rust +/// +/// ``` +/// # use ide_db::syntax_helpers::suggest_name::NameGenerator; /// let mut generator = NameGenerator::new(); /// assert_eq!(generator.suggest_name("a"), "a"); /// assert_eq!(generator.suggest_name("a"), "a1"); diff --git a/crates/ide-db/src/syntax_helpers/tree_diff.rs b/crates/ide-db/src/syntax_helpers/tree_diff.rs index 02e24c47761c..7163c08e1e31 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 0f67496d0989..0593c96f43d5 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 span::Edition; diff --git a/crates/ide-db/src/ty_filter.rs b/crates/ide-db/src/ty_filter.rs index 2fdd8358637d..63ce0ddbb8fc 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 c3f0bf370690..a4a93e36f0e1 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 92b6e748ca5e..92ca7a74184f 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 876c2ccd49d7..f7020a2c50e1 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 7d62daf716c4..3fa8c0133ae8 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 96a368eb0ea3..80ea6f589350 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 d3f302077528..0b9a2ec9db3d 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 246330e6efaa..72619445b5dc 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 f22041ebe233..38eeecb29b71 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::{ + EditionedFileId, FileRange, FxHashMap, RootDatabase, helpers::mod_path_to_ast, - imports::insert_use::{insert_use, ImportScope}, + imports::insert_use::{ImportScope, insert_use}, source_change::SourceChangeBuilder, - EditionedFileId, FileRange, FxHashMap, RootDatabase, }; 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 2f132985895c..9efe251c9ae9 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 0520bb3fe9b9..63fd9b4e3f06 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 938b7182bc94..ac68f4186cc5 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 f3109b9bb73a..e928e57d32ea 100644 --- a/crates/ide-diagnostics/src/handlers/unlinked_file.rs +++ b/crates/ide-diagnostics/src/handlers/unlinked_file.rs @@ -2,20 +2,20 @@ use std::iter; -use hir::{db::DefDatabase, DefMap, InFile, ModuleSource}; +use hir::{DefMap, InFile, ModuleSource, db::DefDatabase}; use ide_db::text_edit::TextEdit; use ide_db::{ + FileId, FileRange, LineIndexDatabase, base_db::{FileLoader, SourceDatabase, SourceRootDatabase}, 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 // @@ -36,7 +36,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 dfb03eee732a..77b70cbaca67 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 2bd8e484f853..7b9dd55e01c6 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 d5caf4de3367..c412536d749e 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 e5c2eca171ae..ac9b34f416b4 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 c53b9ab22b42..1f98acd38af6 100644 --- a/crates/ide-diagnostics/src/lib.rs +++ b/crates/ide-diagnostics/src/lib.rs @@ -693,11 +693,12 @@ struct SeverityAttr { /// /// This is necessary even though we take care to never overwrite a value from deeper nesting /// because of lint groups. For example, in the following code: + /// /// ``` /// #[warn(non_snake_case)] /// mod foo { /// #[allow(nonstandard_style)] - /// mod bar; + /// mod bar {} /// } /// ``` /// We want to not warn on non snake case inside `bar`. If we are traversing this for the first diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs index fc2a7db7174e..366f706a6649 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 ca937a03f82d..8d6b7c637d73 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 a14e69030e32..33807d504e86 100644 --- a/crates/ide-ssr/src/from_comment.rs +++ b/crates/ide-ssr/src/from_comment.rs @@ -1,10 +1,10 @@ //! This module allows building an SSR MatchFinder by parsing the SSR rule //! from a comment. -use ide_db::{base_db::SourceDatabase, EditionedFileId, FilePosition, FileRange, RootDatabase}; +use ide_db::{EditionedFileId, FilePosition, FileRange, RootDatabase, base_db::SourceDatabase}; 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 889258c94c53..5ce10bb3272e 100644 --- a/crates/ide-ssr/src/lib.rs +++ b/crates/ide-ssr/src/lib.rs @@ -81,9 +81,9 @@ pub use crate::{errors::SsrError, from_comment::ssr_from_comment, matching::Matc use crate::{errors::bail, matching::MatchFailureReason}; use hir::{FileRange, Semantics}; use ide_db::text_edit::TextEdit; -use ide_db::{base_db::SourceDatabase, EditionedFileId, FileId, FxHashMap, RootDatabase}; +use ide_db::{EditionedFileId, FileId, FxHashMap, RootDatabase, base_db::SourceDatabase}; 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 4bead14e31d4..3be1b67e0a7f 100644 --- a/crates/ide-ssr/src/matching.rs +++ b/crates/ide-ssr/src/matching.rs @@ -2,17 +2,17 @@ //! 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::FxHashMap; use parser::Edition; 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 ea40d5b815ef..2c0f1658d837 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 11c1615a560e..2ad562f2427a 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 270ee0b3ec96..a687db4bf58d 100644 --- a/crates/ide-ssr/src/resolving.rs +++ b/crates/ide-ssr/src/resolving.rs @@ -4,11 +4,11 @@ use hir::AsAssocItem; use ide_db::FxHashMap; 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 b1cade39266a..f070af0667c2 100644 --- a/crates/ide-ssr/src/search.rs +++ b/crates/ide-ssr/src/search.rs @@ -1,17 +1,16 @@ //! Searching for matches. use crate::{ - matching, + Match, MatchFinder, matching, resolving::{ResolvedPath, ResolvedPattern, ResolvedRule}, - Match, MatchFinder, }; use hir::FileRange; use ide_db::{ + EditionedFileId, FileId, FxHashSet, 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 d783e1952526..4dd68e617bf3 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::{ra_salsa::Durability, SourceDatabase}, EditionedFileId, FxHashSet, + base_db::{SourceDatabase, ra_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 e47891bbdfe7..d44d4bfd2be7 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 08cc10509cb8..427a2eff8201 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 afd6f740c42c..5c0e113d5c6a 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 e35e47e74718..6dca88bb93d2 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, SourceDatabase}, 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 6cc240d65249..c331734c785e 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 d7291c4b9f32..a0bb42891a9e 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,6 +684,8 @@ 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 ad4308e06a14..8d9d5e095cd6 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -2,11 +2,11 @@ use hir::db::ExpandDatabase; use hir::{ExpandResult, InFile, MacroFileIdExt, Semantics}; use ide_db::base_db::CrateId; use ide_db::{ - helpers::pick_best_token, syntax_helpers::prettify_macro_expansion, FileId, RootDatabase, + FileId, RootDatabase, helpers::pick_best_token, syntax_helpers::prettify_macro_expansion, }; use span::{Edition, SpanMap, SyntaxContextId, 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 76414854e91e..a374f9752fcf 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 5ed214443074..944f12a76cff 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, SourceDatabase}, FileId, FxIndexSet, RootDatabase, + base_db::{CrateOrigin, SourceDatabase}, }; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 52fbab6fa12b..347da4e85b4a 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 a0612f48d37e..73b7e771ca95 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 e5a94ff9fe96..194e8c968f75 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 3742edc8db84..a022f1cede87 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 60a904233a9a..5731e25e522a 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, FileLoader, SourceDatabase}, 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 e1d834b5d1c6..1bc28f28b6f5 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 ddc274a83035..bf48a6e23227 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 6463206596af..cad214ea1084 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, defs::{Definition, IdentClass}, helpers::pick_best_token, search::{FileReference, ReferenceCategory, SearchScope}, @@ -9,17 +10,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 { @@ -152,7 +153,10 @@ 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 { @@ -274,11 +278,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 9a3e77f3a932..b36896834496 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -7,25 +7,25 @@ use std::{iter, ops::Not}; use either::Either; use hir::{ - db::DefDatabase, GenericDef, GenericSubstitution, HasCrate, HasSource, LangItem, Semantics, + 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 { @@ -486,7 +486,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 c5a83e58cea1..fab0c7f0956c 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -3,34 +3,34 @@ use std::{env, mem, ops::Not}; use either::Either; use hir::{ - db::ExpandDatabase, Adt, AsAssocItem, AsExternAssocItem, CaptureKind, DropGlue, - DynCompatibilityViolation, HasCrate, HasSource, HirDisplay, Layout, LayoutError, - MethodViolationCode, Name, Semantics, Symbol, Trait, Type, TypeInfo, VariantDef, + Adt, AsAssocItem, AsExternAssocItem, CaptureKind, DropGlue, DynCompatibilityViolation, + HasCrate, HasSource, HirDisplay, Layout, LayoutError, MethodViolationCode, Name, Semantics, + Symbol, Trait, Type, TypeInfo, VariantDef, db::ExpandDatabase, }; use ide_db::{ + RootDatabase, base_db::SourceDatabase, 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( @@ -339,11 +339,7 @@ pub(super) fn try_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option return None, }; @@ -411,7 +407,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)), } @@ -429,7 +425,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 7c720d97cb6d..069136e4f87b 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 63039b1cd34e..e4e03b61bace 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, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef, - ModuleDefId, Semantics, + ClosureStyle, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef, ModuleDefId, + Semantics, sym, }; -use ide_db::{famous_defs::FamousDefs, FileRange, RootDatabase}; -use ide_db::{text_edit::TextEdit, FxHashSet}; +use ide_db::{FileRange, RootDatabase, famous_defs::FamousDefs}; +use ide_db::{FxHashSet, text_edit::TextEdit}; use itertools::Itertools; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use span::{Edition, 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; @@ -834,9 +835,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 d3b95750f7e1..75d370c0b63e 100644 --- a/crates/ide/src/inlay_hints/adjustment.rs +++ b/crates/ide/src/inlay_hints/adjustment.rs @@ -13,7 +13,7 @@ use ide_db::famous_defs::FamousDefs; use ide_db::text_edit::TextEditBuilder; use span::EditionedFileId; -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 => { @@ -286,8 +286,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 c2986a9aa662..7fbf29980e8b 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::Semantics; -use ide_db::{famous_defs::FamousDefs, RootDatabase}; +use ide_db::{RootDatabase, famous_defs::FamousDefs}; use itertools::Itertools; use span::EditionedFileId; @@ -14,8 +14,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( @@ -182,10 +182,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 5bbb4fe4e66e..d29173206889 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 e9b728bcaa75..8ddbfaeffe87 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 8471547727fe..4222a8291e15 100644 --- a/crates/ide/src/inlay_hints/chaining.rs +++ b/crates/ide/src/inlay_hints/chaining.rs @@ -2,8 +2,8 @@ use ide_db::famous_defs::FamousDefs; use span::EditionedFileId; 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 3767d34e2c7a..c619b0099126 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::{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( @@ -158,8 +159,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 9b981c0a3acf..07a86b2c9d3f 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 7858b1d90a38..159307046555 100644 --- a/crates/ide/src/inlay_hints/closure_ret.rs +++ b/crates/ide/src/inlay_hints/closure_ret.rs @@ -6,8 +6,8 @@ use span::EditionedFileId; 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 f1e1955d14ca..827a0438dd02 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 652dff0bc56e..20f54b2cd19d 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 762a4c265518..fc1083fdca65 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::{ + InlayHintsConfig, inlay_hints::{ - tests::{check_with_config, DISABLED_CONFIG}, GenericParameterHints, + tests::{DISABLED_CONFIG, check_with_config}, }, - InlayHintsConfig, }; #[track_caller] diff --git a/crates/ide/src/inlay_hints/implicit_drop.rs b/crates/ide/src/inlay_hints/implicit_drop.rs index 390139d214eb..668232d301c9 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 ae5b519b43d0..f3be09f30a13 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/param_name.rs b/crates/ide/src/inlay_hints/param_name.rs index 8f01b1bd38b5..44ea5351fbdd 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 de9b0e98a4be..d67d84588402 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 ae11072e34b7..87fe94c08d08 100644 --- a/crates/ide/src/interpret.rs +++ b/crates/ide/src/interpret.rs @@ -1,9 +1,9 @@ use hir::{ConstEvalError, DefWithBody, Semantics}; -use ide_db::{base_db::SourceRootDatabase, FilePosition, LineIndexDatabase, RootDatabase}; +use ide_db::{FilePosition, LineIndexDatabase, RootDatabase, base_db::SourceRootDatabase}; use span::Edition; 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 ea18a97070c3..0188c105faa7 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 8ac1a96cc652..19766ae47a62 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -61,19 +61,20 @@ use std::{iter, 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::{ - ra_salsa::{self, ParallelDatabase}, CrateOrigin, CrateWorkspaceData, Env, FileLoader, FileSet, SourceDatabase, SourceRootDatabase, VfsPath, + ra_salsa::{self, ParallelDatabase}, }, - 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::{Cancelled, CrateGraph, CrateId, 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 67346ea9cf90..b2b91d6e3cf3 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 66ea49a98a08..784bd0a5da8b 100644 --- a/crates/ide/src/moniker.rs +++ b/crates/ide/src/moniker.rs @@ -5,16 +5,16 @@ 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 span::Edition; 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 { @@ -195,11 +195,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 } @@ -411,7 +407,7 @@ fn display( #[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 3fb3a788b918..f3bb3df1cd8d 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 d9f80cb53dd6..c7bd53c2d646 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, HirFileIdExt, InFile, LocalSource, ModuleSource, + AssocItem, FieldSource, HasContainer, HasCrate, HasSource, HirDisplay, HirFileId, HirFileIdExt, + 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 @@ -930,7 +931,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 6d82f9b0634b..1388d6e8b1c5 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::{CrateId, FileLoader}, FileId, FilePosition, RootDatabase, + base_db::{CrateId, FileLoader}, }; use itertools::Itertools; use syntax::{ diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 069818d50e76..71c42cc8b579 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 3e8295e3f08e..d7c5e8d847aa 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -6,14 +6,14 @@ use hir::{AsAssocItem, HirFileIdExt, InFile, Semantics}; use ide_db::{ + FileId, FileRange, RootDatabase, 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; @@ -443,7 +443,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 stdx::trim_indent; diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 509ae3204c36..53888b4015cb 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -4,27 +4,28 @@ 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, 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 { @@ -746,7 +747,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/ssr.rs b/crates/ide/src/ssr.rs index 77a011cac198..6d67417271c6 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::ra_salsa::Durability, symbol_index::SymbolsDatabase, FileRange, FxHashSet, - RootDatabase, + FileRange, FxHashSet, RootDatabase, base_db::ra_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 41957bad7e07..987b845f1c2c 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::{SourceRootDatabase, 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}, + Analysis, Fold, HoverConfig, HoverResult, InlayHint, InlayHintsConfig, TryToNav, + hover::{SubstTyLen, hover_for_definition}, inlay_hints::{AdjustmentHintsMode, InlayFieldsToResolve}, - moniker::{def_to_kind, def_to_moniker, MonikerResult, SymbolInformationKind}, + moniker::{MonikerResult, SymbolInformationKind, def_to_kind, def_to_moniker}, parent_module::crates_for, - Analysis, Fold, HoverConfig, HoverResult, InlayHint, InlayHintsConfig, TryToNav, }; /// A static representation of fully analyzed source code. @@ -298,8 +298,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 f8ecaa8fdf25..7e6cf4477894 100644 --- a/crates/ide/src/status.rs +++ b/crates/ide/src/status.rs @@ -1,28 +1,28 @@ use std::{fmt, marker::PhantomData}; use hir::{ - db::{AstIdMapQuery, AttrsQuery, BlockDefMapQuery, ParseMacroExpansionQuery}, Attr, Attrs, ExpandResult, MacroFileId, Module, + db::{AstIdMapQuery, AttrsQuery, BlockDefMapQuery, ParseMacroExpansionQuery}, +}; +use ide_db::{ + RootDatabase, + symbol_index::{LibrarySymbolsQuery, SymbolIndex}, }; use ide_db::{ base_db::{ + CompressedFileTextQuery, CrateData, ParseQuery, SourceDatabase, SourceRootId, ra_salsa::{ - debug::{DebugQueryTable, TableEntry}, Query, QueryTable, + debug::{DebugQueryTable, TableEntry}, }, - CompressedFileTextQuery, CrateData, ParseQuery, SourceDatabase, SourceRootId, }, symbol_index::ModuleSymbolsQuery, }; -use ide_db::{ - symbol_index::{LibrarySymbolsQuery, SymbolIndex}, - RootDatabase, -}; use itertools::Itertools; -use profile::{memory_usage, Bytes}; +use profile::{Bytes, memory_usage}; use span::{EditionedFileId, FileId}; use stdx::format_to; -use syntax::{ast, Parse, SyntaxNode}; +use syntax::{Parse, SyntaxNode, ast}; use triomphe::Arc; // Feature: Status @@ -104,9 +104,9 @@ where Q: QueryCollect, ::Storage: 'q, ::Collector: StatCollect< - as DebugQueryTable>::Key, - as DebugQueryTable>::Value, - >, + as DebugQueryTable>::Key, + as DebugQueryTable>::Value, + >, { struct StatCollectorWrapper(C); impl, K, V> FromIterator> for StatCollectorWrapper { diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 1853e3a34074..8e25ade135f7 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -19,13 +19,14 @@ use hir::{InRealFile, Name, Semantics}; use ide_db::{FxHashMap, Ranker, RootDatabase, SymbolKind}; use span::EditionedFileId; use syntax::{ - ast::{self, IsString}, AstNode, AstToken, NodeOrToken, SyntaxKind::*, - SyntaxNode, TextRange, WalkEvent, T, + SyntaxNode, 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, @@ -33,7 +34,6 @@ use crate::{ macro_::MacroHighlighter, 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 43a6bdad7e9b..166e2d0e3dc2 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, TextRange}; +use syntax::{TextRange, 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 194fde116011..2b8f27b04d49 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -3,20 +3,20 @@ use either::Either; use hir::{AsAssocItem, HasVisibility, MacroFileIdExt, Semantics}; use ide_db::{ - defs::{Definition, IdentClass, NameClass, NameRefClass}, FxHashMap, RootDatabase, SymbolKind, + defs::{Definition, IdentClass, NameClass, NameRefClass}, }; use span::Edition; use stdx::hash_once; use syntax::{ - ast, match_ast, AstNode, AstToken, NodeOrToken, + AstNode, AstToken, NodeOrToken, SyntaxKind::{self, *}, - SyntaxNode, SyntaxToken, T, + SyntaxNode, SyntaxToken, T, ast, match_ast, }; use crate::{ - syntax_highlighting::tags::{HlOperator, HlPunct}, Highlight, HlMod, HlTag, + syntax_highlighting::tags::{HlOperator, HlPunct}, }; pub(super) fn token( @@ -103,11 +103,7 @@ fn punctuation( let is_unsafe = parent .and_then(ast::RefExpr::cast) .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr)); - if let Some(true) = is_unsafe { - h | HlMod::Unsafe - } else { - h - } + if let Some(true) = is_unsafe { h | HlMod::Unsafe } else { h } } (T![::] | T![->] | T![=>] | T![..] | T![..=] | T![=] | T![@] | T![.], _) => { HlOperator::Other.into() @@ -159,7 +155,7 @@ fn punctuation( .and_then(SyntaxNode::parent) .is_some_and(|it| it.kind() == MACRO_RULES) => { - return HlOperator::Other.into() + return HlOperator::Other.into(); } T![<] | T![>] => HlPunct::Angle, T![,] => HlPunct::Comma, @@ -217,7 +213,7 @@ fn keyword( // self, crate, super and `Self` are handled as either a Name or NameRef already, unless they // are inside unmapped token trees T![self] | T![crate] | T![super] | T![Self] if parent_matches::(&token) => { - return None + return None; } T![self] if parent_matches::(&token) => return None, T![ref] => match token.parent().and_then(ast::IdentPat::cast) { @@ -246,7 +242,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, edition) + return highlight_name_ref_by_syntax(name_ref, sema, krate, edition); } // FIXME: This is required for helper attributes used by proc-macros, as those do not map down // to anything when used. @@ -717,11 +713,7 @@ fn highlight_name_ref_by_syntax( } Either::Right(_) => false, }); - if is_union { - h | HlMod::Unsafe - } else { - h.into() - } + if is_union { h | HlMod::Unsafe } else { h.into() } } PATH_SEGMENT => { let name_based_fallback = || { diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 47ad54759a87..889ccc1e8fd7 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs @@ -7,8 +7,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 1be90ad6a1eb..13922eba1919 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 a902fd717f09..c30f79732496 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/macro_.rs b/crates/ide/src/syntax_highlighting/macro_.rs index b441b4cc90eb..8ecc1f319808 100644 --- a/crates/ide/src/syntax_highlighting/macro_.rs +++ b/crates/ide/src/syntax_highlighting/macro_.rs @@ -1,5 +1,5 @@ //! Syntax highlighting for macro_rules!. -use syntax::{SyntaxKind, SyntaxToken, TextRange, T}; +use syntax::{SyntaxKind, SyntaxToken, T, TextRange}; use crate::{HlRange, HlTag}; diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 3775265f234d..c9f999706f10 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 30b1d4c39b30..3664bdad44cf 100644 --- a/crates/ide/src/test_explorer.rs +++ b/crates/ide/src/test_explorer.rs @@ -2,12 +2,12 @@ use hir::{Crate, Module, ModuleDef, Semantics}; use ide_db::{ - base_db::{CrateGraph, CrateId, SourceDatabase}, FileId, RootDatabase, + base_db::{CrateGraph, CrateId, SourceDatabase}, }; 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 8c9dd0514527..4c048b1b71c6 100644 --- a/crates/ide/src/typing.rs +++ b/crates/ide/src/typing.rs @@ -17,12 +17,12 @@ mod on_enter; use std::iter; -use ide_db::{base_db::SourceDatabase, FilePosition, RootDatabase}; +use ide_db::{FilePosition, RootDatabase, base_db::SourceDatabase}; use span::{Edition, EditionedFileId}; 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 c6d1c283f4ec..7832df511ccc 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::RootDatabase; -use ide_db::{base_db::SourceDatabase, FilePosition}; +use ide_db::{FilePosition, base_db::SourceDatabase}; 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 eb6eb7da1e90..bc281c6a2db0 100644 --- a/crates/ide/src/view_crate_graph.rs +++ b/crates/ide/src/view_crate_graph.rs @@ -1,7 +1,7 @@ use dot::{Id, LabelText}; use ide_db::{ - base_db::{CrateGraph, CrateId, Dependency, SourceDatabase, SourceRootDatabase}, FxHashSet, RootDatabase, + base_db::{CrateGraph, CrateId, Dependency, SourceDatabase, SourceRootDatabase}, }; use triomphe::Arc; diff --git a/crates/ide/src/view_hir.rs b/crates/ide/src/view_hir.rs index bfdf9d0f3374..954917d4c09e 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 67c241cbb915..a230b30ed371 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 edb83bc4eac4..415a6487b022 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::{Field, HirDisplay, Layout, Semantics, Type}; use ide_db::{ + RootDatabase, defs::Definition, helpers::{get_definition, pick_best_token}, - RootDatabase, }; use span::Edition; use syntax::{AstNode, SyntaxKind}; diff --git a/crates/ide/src/view_mir.rs b/crates/ide/src/view_mir.rs index aa4ff64a819e..6ca231c7a81a 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 407720864bfd..ecd93e8b2819 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 58327419f631..6548bb18269b 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 b3bf285edfb1..204b1dcb64b8 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; @@ -155,7 +155,7 @@ impl Symbol { SharedValue::new(()), ) .0 - .0, + .0, ), }, } @@ -231,7 +231,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 be0de6c93661..ed220a1ddb87 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 76f1a7f48b6b..4a0f4ef47eef 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, iter, mem, path::Path, sync}; -use crossbeam_channel::{unbounded, Receiver}; +use crossbeam_channel::{Receiver, unbounded}; use hir_expand::proc_macro::{ ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind, ProcMacroLoadResult, ProcMacros, }; use ide_db::{ + ChangeWithProcMacros, FxHashMap, RootDatabase, base_db::{CrateGraph, CrateWorkspaceData, 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)] @@ -625,7 +626,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))]) } @@ -640,7 +641,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)),]) } @@ -655,7 +656,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)),]) } @@ -671,7 +672,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)),]) } @@ -687,7 +688,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 89c300300379..db75dceae1cb 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 5539a88c707d..f910f9f9d753 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 b7f25aa38096..940aaacb02ed 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 7710ea793895..b1f542eac7ce 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 bebd29ef7470..bd76d3ee749b 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -23,8 +23,8 @@ mod tests; use span::{Edition, Span, SyntaxContextId}; 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 16d55492a04b..81bc56c9e025 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, SyntaxContextId}; use tt::iter::{TtElement, TtIter}; @@ -14,7 +14,7 @@ use crate::ParseError; /// /// ``` /// macro_rules! an_macro { -/// ($x:expr + $y:expr) => ($y * $x) +/// ($x:expr , $y:expr) => ($y * $x) /// } /// ``` /// @@ -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 b197b086f377..5be9cb2a2469 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 fe6b904bd889..8ddf50db043a 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 fe1316c9bfde..5b0085fc2a0b 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/input.rs b/crates/parser/src/input.rs index c90b358cfbb4..cabdff214df3 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -36,7 +36,7 @@ impl Input { /// the *previous* token was joint, with mbe, you know whether the *current* /// one is joint. This API allows for styles of usage: /// - /// ``` + /// ```ignore /// // In text: /// tokens.was_joint(prev_joint); /// tokens.push(curr); diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index e461492cc6f9..398ad7cf66ce 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -59,7 +59,7 @@ pub use crate::{ /// /// That is, for something like /// -/// ``` +/// ```ignore /// quick_check! { /// fn prop() {} /// } diff --git a/crates/parser/src/output.rs b/crates/parser/src/output.rs index 386d03a62cc1..0ea15a656c1b 100644 --- a/crates/parser/src/output.rs +++ b/crates/parser/src/output.rs @@ -16,8 +16,9 @@ pub struct Output { /// 32-bit encoding of events. If LSB is zero, then that's an index into the /// error vector. Otherwise, it's one of the thee other variants, with data encoded as /// - /// |16 bit kind|8 bit n_input_tokens|4 bit tag|4 bit leftover| - /// + /// ```text + /// |16 bit kind|8 bit n_input_tokens|4 bit tag|4 bit leftover| + /// `````` event: Vec, error: Vec, } diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index b05868627644..36a363afe93a 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 008424416169..4062274b0767 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 4b831e4acebb..ffe77c5cb0f1 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, SyntaxContextId, 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 dc3328ebcda4..e0dc33e217eb 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}; 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, }; @@ -100,7 +100,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 d998b23d3bbe..dd1f5a2420c9 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 de59e88aac40..0e6b18ecaef1 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 569070766f1c..f54dff1f2d82 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 cbf7a277bfae..245b064387e5 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 f28821b4afc5..4f817b6bc0a5 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 58f5e80dc4ea..a5fa7f6e71a6 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 59293ee3f965..c86212dd09ce 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 409cf3cc7813..d0c7f23a38a0 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 645f7e7c59a3..a3cf76d37bac 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 1b085520d565..c008807fb0a4 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, SyntaxContextId, 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 b0939229f93e..aa0099d0e57e 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 40ab8c53faeb..f59bc2811363 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -580,7 +580,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 37fffba29559..08d51c0d0888 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 0c7344746824..4a7f9a152cd9 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