mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
remove unnecessary lazy evaluations
This commit is contained in:
parent
7530d76f00
commit
cc80c5bd07
31 changed files with 50 additions and 51 deletions
|
@ -273,7 +273,7 @@ impl DocCommentToken {
|
|||
let (in_expansion_range, link, ns) =
|
||||
extract_definitions_from_docs(&docs).into_iter().find_map(|(range, link, ns)| {
|
||||
let mapped = doc_mapping.map(range)?;
|
||||
(mapped.value.contains(abs_in_expansion_offset)).then(|| (mapped.value, link, ns))
|
||||
(mapped.value.contains(abs_in_expansion_offset)).then_some((mapped.value, link, ns))
|
||||
})?;
|
||||
// get the relative range to the doc/attribute in the expansion
|
||||
let in_expansion_relative_range = in_expansion_range - descended_prefix_len - token_start;
|
||||
|
|
|
@ -205,7 +205,7 @@ fn extend_single_word_in_comment_or_string(
|
|||
}
|
||||
|
||||
let start_idx = before.rfind(non_word_char)? as u32;
|
||||
let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32;
|
||||
let end_idx = after.find(non_word_char).unwrap_or(after.len()) as u32;
|
||||
|
||||
let from: TextSize = (start_idx + 1).into();
|
||||
let to: TextSize = (cursor_position + end_idx).into();
|
||||
|
|
|
@ -110,7 +110,7 @@ fn impls_for_trait_item(
|
|||
.filter_map(|imp| {
|
||||
let item = imp.items(sema.db).iter().find_map(|itm| {
|
||||
let itm_name = itm.name(sema.db)?;
|
||||
(itm_name == fun_name).then(|| *itm)
|
||||
(itm_name == fun_name).then_some(*itm)
|
||||
})?;
|
||||
item.try_to_nav(sema.db)
|
||||
})
|
||||
|
|
|
@ -110,7 +110,7 @@ fn highlight_references(
|
|||
.and_then(|decl| decl.focus_range)
|
||||
.map(|range| {
|
||||
let category =
|
||||
references::decl_mutability(&def, node, range).then(|| ReferenceCategory::Write);
|
||||
references::decl_mutability(&def, node, range).then_some(ReferenceCategory::Write);
|
||||
HighlightedRange { range, category }
|
||||
});
|
||||
if let Some(hl_range) = hl_range {
|
||||
|
@ -365,7 +365,7 @@ mod tests {
|
|||
|
||||
let mut expected = annotations
|
||||
.into_iter()
|
||||
.map(|(r, access)| (r.range, (!access.is_empty()).then(|| access)))
|
||||
.map(|(r, access)| (r.range, (!access.is_empty()).then_some(access)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut actual = hls
|
||||
|
|
|
@ -167,7 +167,7 @@ fn is_named_constructor(
|
|||
ast::PathSegmentKind::Type { type_ref: Some(ty), trait_ref: None } => ty.to_string(),
|
||||
_ => return None,
|
||||
};
|
||||
(ctor_name == ty_name).then(|| ())
|
||||
(ctor_name == ty_name).then_some(())
|
||||
}
|
||||
|
||||
fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &hir::Type) -> bool {
|
||||
|
|
|
@ -111,7 +111,7 @@ fn punctuation(
|
|||
let is_raw_ptr = (|| {
|
||||
let prefix_expr = parent.and_then(ast::PrefixExpr::cast)?;
|
||||
let expr = prefix_expr.expr()?;
|
||||
sema.type_of_expr(&expr)?.original.is_raw_ptr().then(|| ())
|
||||
sema.type_of_expr(&expr)?.original.is_raw_ptr().then_some(())
|
||||
})();
|
||||
if let Some(()) = is_raw_ptr {
|
||||
HlTag::Operator(HlOperator::Other) | HlMod::Unsafe
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue