use simpler .map(|x| y) instead of .and_then(|x| Some(y)) for Options. (clippy::bind_instead_of_map)
This commit is contained in:
parent
64b91393b8
commit
ff5f90d8ae
@ -73,8 +73,8 @@ fn find_parent_and_path(
|
||||
) -> Option<(Either<ast::UseTree, ast::UseTreeList>, ast::Path)> {
|
||||
return star.ancestors().find_map(|n| {
|
||||
find_use_tree_list(n.clone())
|
||||
.and_then(|(u, p)| Some((Either::Right(u), p)))
|
||||
.or_else(|| find_use_tree(n).and_then(|(u, p)| Some((Either::Left(u), p))))
|
||||
.map(|(u, p)| (Either::Right(u), p))
|
||||
.or_else(|| find_use_tree(n).map(|(u, p)| (Either::Left(u), p)))
|
||||
});
|
||||
|
||||
fn find_use_tree_list(n: SyntaxNode) -> Option<(ast::UseTreeList, ast::Path)> {
|
||||
|
@ -161,15 +161,9 @@ impl Definition {
|
||||
|
||||
if let Definition::Local(var) = self {
|
||||
let range = match var.parent(db) {
|
||||
DefWithBody::Function(f) => {
|
||||
f.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
}
|
||||
DefWithBody::Const(c) => {
|
||||
c.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
}
|
||||
DefWithBody::Static(s) => {
|
||||
s.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
}
|
||||
DefWithBody::Function(f) => f.source(db).map(|src| src.value.syntax().text_range()),
|
||||
DefWithBody::Const(c) => c.source(db).map(|src| src.value.syntax().text_range()),
|
||||
DefWithBody::Static(s) => s.source(db).map(|src| src.value.syntax().text_range()),
|
||||
};
|
||||
let mut res = FxHashMap::default();
|
||||
res.insert(file_id, range);
|
||||
@ -179,33 +173,29 @@ impl Definition {
|
||||
if let Definition::GenericParam(hir::GenericParam::LifetimeParam(param)) = self {
|
||||
let range = match param.parent(db) {
|
||||
hir::GenericDef::Function(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
hir::GenericDef::Adt(it) => match it {
|
||||
hir::Adt::Struct(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
}
|
||||
hir::Adt::Union(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
}
|
||||
hir::Adt::Enum(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
hir::Adt::Union(it) => it.source(db).map(|src| src.value.syntax().text_range()),
|
||||
hir::Adt::Enum(it) => it.source(db).map(|src| src.value.syntax().text_range()),
|
||||
},
|
||||
hir::GenericDef::Trait(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
hir::GenericDef::TypeAlias(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
hir::GenericDef::Impl(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
hir::GenericDef::Variant(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
hir::GenericDef::Const(it) => {
|
||||
it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
|
||||
it.source(db).map(|src| src.value.syntax().text_range())
|
||||
}
|
||||
};
|
||||
let mut res = FxHashMap::default();
|
||||
|
Loading…
x
Reference in New Issue
Block a user