mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Merge pull request #18256 from MoskalykA/use-is_none_or
Start using `Option::is_none_or`
This commit is contained in:
commit
ae86e6a229
4 changed files with 4 additions and 21 deletions
|
@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
rust-version = "1.81"
|
rust-version = "1.82"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
authors = ["rust-analyzer team"]
|
authors = ["rust-analyzer team"]
|
||||||
|
|
|
@ -11,7 +11,7 @@ use hir_def::{
|
||||||
ConstBlockLoc, EnumVariantId, GeneralConstId, StaticId,
|
ConstBlockLoc, EnumVariantId, GeneralConstId, StaticId,
|
||||||
};
|
};
|
||||||
use hir_expand::Lookup;
|
use hir_expand::Lookup;
|
||||||
use stdx::{never, IsNoneOr};
|
use stdx::never;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -287,7 +287,7 @@ pub(crate) fn const_eval_discriminant_variant(
|
||||||
}
|
}
|
||||||
|
|
||||||
let repr = db.enum_data(loc.parent).repr;
|
let repr = db.enum_data(loc.parent).repr;
|
||||||
let is_signed = IsNoneOr::is_none_or(repr.and_then(|repr| repr.int), |int| int.is_signed());
|
let is_signed = repr.and_then(|repr| repr.int).is_none_or(|int| int.is_signed());
|
||||||
|
|
||||||
let mir_body = db.monomorphized_mir_body(
|
let mir_body = db.monomorphized_mir_body(
|
||||||
def,
|
def,
|
||||||
|
|
|
@ -7,7 +7,6 @@ use ide_db::{
|
||||||
base_db::{SourceRootDatabase, VfsPath},
|
base_db::{SourceRootDatabase, VfsPath},
|
||||||
FxHashSet, RootDatabase, SymbolKind,
|
FxHashSet, RootDatabase, SymbolKind,
|
||||||
};
|
};
|
||||||
use stdx::IsNoneOr;
|
|
||||||
use syntax::{ast, AstNode, SyntaxKind, ToSmolStr};
|
use syntax::{ast, AstNode, SyntaxKind, ToSmolStr};
|
||||||
|
|
||||||
use crate::{context::CompletionContext, CompletionItem, Completions};
|
use crate::{context::CompletionContext, CompletionItem, Completions};
|
||||||
|
@ -66,7 +65,7 @@ pub(crate) fn complete_mod(
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&submodule_candidate_file| submodule_candidate_file != module_definition_file)
|
.filter(|&submodule_candidate_file| submodule_candidate_file != module_definition_file)
|
||||||
.filter(|&submodule_candidate_file| {
|
.filter(|&submodule_candidate_file| {
|
||||||
IsNoneOr::is_none_or(module_declaration_file, |it| it != submodule_candidate_file)
|
module_declaration_file.is_none_or(|it| it != submodule_candidate_file)
|
||||||
})
|
})
|
||||||
.filter_map(|submodule_file| {
|
.filter_map(|submodule_file| {
|
||||||
let submodule_path = source_root.path_for_file(&submodule_file)?;
|
let submodule_path = source_root.path_for_file(&submodule_file)?;
|
||||||
|
|
|
@ -304,22 +304,6 @@ pub fn slice_tails<T>(this: &[T]) -> impl Iterator<Item = &[T]> {
|
||||||
(0..this.len()).map(|i| &this[i..])
|
(0..this.len()).map(|i| &this[i..])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IsNoneOr {
|
|
||||||
type Type;
|
|
||||||
#[allow(clippy::wrong_self_convention)]
|
|
||||||
fn is_none_or(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
|
|
||||||
}
|
|
||||||
#[allow(unstable_name_collisions)]
|
|
||||||
impl<T> IsNoneOr for Option<T> {
|
|
||||||
type Type = T;
|
|
||||||
fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
|
|
||||||
match self {
|
|
||||||
Some(v) => f(v),
|
|
||||||
None => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue