cargo fmt

This commit is contained in:
BenjaminBrienen 2025-03-10 12:42:27 +01:00
parent 87f837cec7
commit 7535bb4661
571 changed files with 2210 additions and 2458 deletions

View file

@ -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;

View file

@ -6,7 +6,7 @@ use rustc_hash::FxHashSet;
use salsa::{Database as _, Durability};
use triomphe::Arc;
use crate::{symbol_index::SymbolsDatabase, ChangeWithProcMacros, RootDatabase};
use crate::{ChangeWithProcMacros, RootDatabase, symbol_index::SymbolsDatabase};
impl RootDatabase {
pub fn request_cancellation(&mut self) {

View file

@ -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`?

View file

@ -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<String> {
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 {

View file

@ -220,11 +220,7 @@ impl FamousDefs<'_, '_> {
for segment in path {
module = module.children(db).find_map(|child| {
let name = child.name(db)?;
if name.as_str() == segment {
Some(child)
} else {
None
}
if name.as_str() == segment { Some(child) } else { None }
})?;
}
let def =

View file

@ -6,13 +6,14 @@ use base_db::SourceDatabase;
use hir::{Crate, ItemInNs, ModuleDef, Name, Semantics};
use span::{Edition, FileId};
use syntax::{
ast::{self, make},
AstToken, SyntaxKind, SyntaxToken, ToSmolStr, TokenAtOffset,
ast::{self, make},
};
use crate::{
RootDatabase,
defs::{Definition, IdentClass},
generated, RootDatabase,
generated,
};
pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option<Name> {

View file

@ -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,

View file

@ -6,20 +6,20 @@ use std::cmp::Ordering;
use hir::Semantics;
use syntax::{
algo,
Direction, NodeOrToken, SyntaxKind, SyntaxNode, algo,
ast::{
self, edit_in_place::Removable, make, AstNode, HasAttrs, HasModuleItem, HasVisibility,
PathSegmentKind,
self, AstNode, HasAttrs, HasModuleItem, HasVisibility, PathSegmentKind,
edit_in_place::Removable, make,
},
ted, Direction, NodeOrToken, SyntaxKind, SyntaxNode,
ted,
};
use crate::{
imports::merge_imports::{
common_prefix, eq_attrs, eq_visibility, try_merge_imports, use_tree_cmp, MergeBehavior,
NormalizationStyle,
},
RootDatabase,
imports::merge_imports::{
MergeBehavior, NormalizationStyle, common_prefix, eq_attrs, eq_visibility,
try_merge_imports, use_tree_cmp,
},
};
pub use hir::PrefixKind;

View file

@ -1,7 +1,7 @@
use salsa::AsDynDatabase;
use stdx::trim_indent;
use test_fixture::WithFixture;
use test_utils::{assert_eq_text, CURSOR_MARKER};
use test_utils::{CURSOR_MARKER, assert_eq_text};
use super::*;

View file

@ -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());

View file

@ -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.

View file

@ -51,12 +51,12 @@ use salsa::Durability;
use std::{fmt, mem::ManuallyDrop};
use base_db::{
query_group, CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, RootQueryDb,
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast,
CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, RootQueryDb,
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast, query_group,
};
use hir::{
db::{DefDatabase, ExpandDatabase, HirDatabase},
FilePositionWrapper, FileRangeWrapper,
db::{DefDatabase, ExpandDatabase, HirDatabase},
};
use triomphe::Arc;
@ -360,11 +360,7 @@ pub struct SnippetCap {
impl SnippetCap {
pub const fn new(allow_snippets: bool) -> Option<SnippetCap> {
if allow_snippets {
Some(SnippetCap { _private: () })
} else {
None
}
if allow_snippets { Some(SnippetCap { _private: () }) } else { None }
}
}

View file

@ -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)]

View file

@ -6,14 +6,14 @@ mod topologic_sort;
use std::time::Duration;
use hir::{db::DefDatabase, Symbol};
use hir::{Symbol, db::DefDatabase};
use itertools::Itertools;
use salsa::{Cancelled, Database};
use crate::{
FxIndexMap, RootDatabase,
base_db::{Crate, RootQueryDb},
symbol_index::SymbolsDatabase,
FxIndexMap, RootDatabase,
};
/// We're indexing many crates.

View file

@ -30,20 +30,20 @@ use base_db::AnchoredPathBuf;
use either::Either;
use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics};
use span::{Edition, EditionedFileId, FileId, SyntaxContext};
use stdx::{never, TupleExt};
use stdx::{TupleExt, never};
use syntax::{
AstNode, SyntaxKind, T, TextRange,
ast::{self, HasName},
utils::is_raw_identifier,
AstNode, SyntaxKind, TextRange, T,
};
use crate::{
RootDatabase,
defs::Definition,
search::{FileReference, FileReferenceNode},
source_change::{FileSystemEdit, SourceChange},
syntax_helpers::node_ext::expr_as_name_ref,
traits::convert_to_def_in_trait,
RootDatabase,
};
pub type Result<T, E = RenameError> = std::result::Result<T, E>;

View file

@ -10,9 +10,9 @@ use std::{cell::LazyCell, cmp::Reverse};
use base_db::{RootQueryDb, SourceDatabase};
use either::Either;
use hir::{
sym, Adt, AsAssocItem, DefWithBody, FileRange, FileRangeWrapper, HasAttrs, HasContainer,
HasSource, HirFileIdExt, InFile, InFileWrapper, InRealFile, InlineAsmOperand, ItemContainer,
ModuleSource, PathResolution, Semantics, Visibility,
Adt, AsAssocItem, DefWithBody, FileRange, FileRangeWrapper, HasAttrs, HasContainer, HasSource,
HirFileIdExt, InFile, InFileWrapper, InRealFile, InlineAsmOperand, ItemContainer, ModuleSource,
PathResolution, Semantics, Visibility, sym,
};
use memchr::memmem::Finder;
use parser::SyntaxKind;
@ -20,16 +20,16 @@ use rustc_hash::{FxHashMap, FxHashSet};
use salsa::Database;
use span::EditionedFileId;
use syntax::{
AstNode, AstToken, SmolStr, SyntaxElement, SyntaxNode, TextRange, TextSize, ToSmolStr,
ast::{self, HasName, Rename},
match_ast, AstNode, AstToken, SmolStr, SyntaxElement, SyntaxNode, TextRange, TextSize,
ToSmolStr,
match_ast,
};
use triomphe::Arc;
use crate::{
RootDatabase,
defs::{Definition, NameClass, NameRefClass},
traits::{as_trait_assoc_def, convert_to_def_in_trait},
RootDatabase,
};
#[derive(Debug, Default, Clone)]
@ -1292,7 +1292,7 @@ impl<'a> FindUsages<'a> {
if convert_to_def_in_trait(self.sema.db, def)
!= convert_to_def_in_trait(self.sema.db, self.def) =>
{
return false
return false;
}
(Some(_), Definition::TypeAlias(_)) => {}
// We looking at an assoc item of a trait definition, so reference all the

View file

@ -6,7 +6,7 @@
use std::{collections::hash_map::Entry, fmt, iter, mem};
use crate::text_edit::{TextEdit, TextEditBuilder};
use crate::{assists::Command, syntax_helpers::tree_diff::diff, SnippetCap};
use crate::{SnippetCap, assists::Command, syntax_helpers::tree_diff::diff};
use base_db::AnchoredPathBuf;
use itertools::Itertools;
use nohash_hasher::IntMap;
@ -14,8 +14,8 @@ use rustc_hash::FxHashMap;
use span::FileId;
use stdx::never;
use syntax::{
syntax_editor::{SyntaxAnnotation, SyntaxEditor},
AstNode, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
syntax_editor::{SyntaxAnnotation, SyntaxEditor},
};
/// An annotation ID associated with an indel, to describe changes.
@ -479,13 +479,14 @@ impl SourceChangeBuilder {
self.commit();
// Only one file can have snippet edits
stdx::never!(self
.source_change
.source_file_edits
.iter()
.filter(|(_, (_, snippet_edit))| snippet_edit.is_some())
.at_most_one()
.is_err());
stdx::never!(
self.source_change
.source_file_edits
.iter()
.filter(|(_, (_, snippet_edit))| snippet_edit.is_some())
.at_most_one()
.is_err()
);
mem::take(&mut self.source_change)
}

View file

@ -28,12 +28,12 @@ use std::{
};
use base_db::{RootQueryDb, SourceDatabase, SourceRootId, Upcast};
use fst::{raw::IndexedValue, Automaton, Streamer};
use fst::{Automaton, Streamer, raw::IndexedValue};
use hir::{
Crate, Module,
db::HirDatabase,
import_map::{AssocSearchMode, SearchMode},
symbols::{FileSymbol, SymbolCollector},
Crate, Module,
};
use rayon::prelude::*;
use rustc_hash::FxHashSet;

View file

@ -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?

View file

@ -183,7 +183,7 @@ pub fn parse_format_exprs(input: &str) -> Result<(String, Vec<Arg>), ()> {
#[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![]));

View file

@ -5,8 +5,8 @@ use itertools::Itertools;
use parser::T;
use span::Edition;
use syntax::{
ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind},
AstNode, AstToken, Preorder, RustLanguage, WalkEvent,
ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind},
};
pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {

View file

@ -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;

View file

@ -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};

View file

@ -1,9 +1,9 @@
//! Functionality for obtaining data related to traits from the DB.
use crate::{defs::Definition, RootDatabase};
use hir::{db::HirDatabase, AsAssocItem, Semantics};
use crate::{RootDatabase, defs::Definition};
use hir::{AsAssocItem, Semantics, db::HirDatabase};
use rustc_hash::FxHashSet;
use syntax::{ast, AstNode};
use syntax::{AstNode, ast};
/// Given the `impl` block, attempts to find the trait this `impl` corresponds to.
pub fn resolve_target_trait(
@ -113,7 +113,7 @@ fn assoc_item_of_trait(
#[cfg(test)]
mod tests {
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use hir::FilePosition;
use hir::Semantics;
use salsa::AsDynDatabase;

View file

@ -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;

View file

@ -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)