fix clippy::redundant_closure

This commit is contained in:
Matthias Krüger 2022-03-12 13:35:31 +01:00
parent 1f70886b15
commit 451fcd3c79
11 changed files with 17 additions and 25 deletions

View File

@ -421,12 +421,12 @@ pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> {
} }
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
let src = node.map(|it| AstPtr::new(it)); let src = node.map(AstPtr::new);
self.expr_map.get(&src).cloned() self.expr_map.get(&src).cloned()
} }
pub fn node_macro_file(&self, node: InFile<&ast::MacroCall>) -> Option<HirFileId> { pub fn node_macro_file(&self, node: InFile<&ast::MacroCall>) -> Option<HirFileId> {
let src = node.map(|it| AstPtr::new(it)); let src = node.map(AstPtr::new);
self.expansions.get(&src).cloned() self.expansions.get(&src).cloned()
} }
@ -449,7 +449,7 @@ pub fn label_syntax(&self, label: LabelId) -> LabelSource {
} }
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> { pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
let src = node.map(|it| AstPtr::new(it)); let src = node.map(AstPtr::new);
self.label_map.get(&src).cloned() self.label_map.get(&src).cloned()
} }
@ -457,7 +457,7 @@ pub fn field_syntax(&self, expr: ExprId) -> InFile<AstPtr<ast::RecordExprField>>
self.field_map_back[&expr].clone() self.field_map_back[&expr].clone()
} }
pub fn node_field(&self, node: InFile<&ast::RecordExprField>) -> Option<ExprId> { pub fn node_field(&self, node: InFile<&ast::RecordExprField>) -> Option<ExprId> {
let src = node.map(|it| AstPtr::new(it)); let src = node.map(AstPtr::new);
self.field_map.get(&src).cloned() self.field_map.get(&src).cloned()
} }

View File

@ -941,17 +941,15 @@ fn from(ast_lit_kind: ast::LiteralKind) -> Self {
LiteralKind::IntNumber(lit) => { LiteralKind::IntNumber(lit) => {
if let builtin @ Some(_) = lit.suffix().and_then(BuiltinFloat::from_suffix) { if let builtin @ Some(_) = lit.suffix().and_then(BuiltinFloat::from_suffix) {
Literal::Float(Default::default(), builtin) Literal::Float(Default::default(), builtin)
} else if let builtin @ Some(_) = } else if let builtin @ Some(_) = lit.suffix().and_then(BuiltinInt::from_suffix) {
lit.suffix().and_then(|it| BuiltinInt::from_suffix(it))
{
Literal::Int(lit.value().unwrap_or(0) as i128, builtin) Literal::Int(lit.value().unwrap_or(0) as i128, builtin)
} else { } else {
let builtin = lit.suffix().and_then(|it| BuiltinUint::from_suffix(it)); let builtin = lit.suffix().and_then(BuiltinUint::from_suffix);
Literal::Uint(lit.value().unwrap_or(0), builtin) Literal::Uint(lit.value().unwrap_or(0), builtin)
} }
} }
LiteralKind::FloatNumber(lit) => { LiteralKind::FloatNumber(lit) => {
let ty = lit.suffix().and_then(|it| BuiltinFloat::from_suffix(it)); let ty = lit.suffix().and_then(BuiltinFloat::from_suffix);
Literal::Float(Default::default(), ty) Literal::Float(Default::default(), ty)
} }
LiteralKind::ByteString(bs) => { LiteralKind::ByteString(bs) => {

View File

@ -66,7 +66,7 @@ pub(crate) fn fn_data_query(db: &dyn DefDatabase, func: FunctionId) -> Arc<Funct
.by_key("rustc_legacy_const_generics") .by_key("rustc_legacy_const_generics")
.tt_values() .tt_values()
.next() .next()
.map(|arg| parse_rustc_legacy_const_generics(arg)) .map(parse_rustc_legacy_const_generics)
.unwrap_or_default(); .unwrap_or_default();
Arc::new(FunctionData { Arc::new(FunctionData {

View File

@ -88,9 +88,8 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, ExpandError> {
debug!("parsed item has no name"); debug!("parsed item has no name");
ExpandError::Other("missing name".into()) ExpandError::Other("missing name".into())
})?; })?;
let name_token_id = token_map let name_token_id =
.token_by_range(name.syntax().text_range()) token_map.token_by_range(name.syntax().text_range()).unwrap_or_else(TokenId::unspecified);
.unwrap_or_else(|| TokenId::unspecified());
let name_token = tt::Ident { id: name_token_id, text: name.text().into() }; let name_token = tt::Ident { id: name_token_id, text: name.text().into() };
let type_or_const_params = let type_or_const_params =
params.map_or(0, |type_param_list| type_param_list.type_or_const_params().count()); params.map_or(0, |type_param_list| type_param_list.type_or_const_params().count());

View File

@ -446,7 +446,7 @@ fn concat_bytes_expand(
match token.kind() { match token.kind() {
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()), syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
syntax::SyntaxKind::BYTE_STRING => { syntax::SyntaxKind::BYTE_STRING => {
let components = unquote_byte_string(lit).unwrap_or_else(|| Vec::new()); let components = unquote_byte_string(lit).unwrap_or_else(Vec::new);
components.into_iter().for_each(|x| bytes.push(x.to_string())); components.into_iter().for_each(|x| bytes.push(x.to_string()));
} }
_ => { _ => {

View File

@ -128,6 +128,6 @@ pub(crate) fn set_current_program<OP, R>(p: &dyn HirDatabase, op: OP) -> R
// type. // type.
let static_p: &DebugContext<'static> = let static_p: &DebugContext<'static> =
unsafe { std::mem::transmute::<&DebugContext, &DebugContext<'static>>(&ctx) }; unsafe { std::mem::transmute::<&DebugContext, &DebugContext<'static>>(&ctx) };
PROGRAM.set(static_p, || op()) PROGRAM.set(static_p, op)
} }
} }

View File

@ -283,7 +283,7 @@ fn nearby_delimiter(
let final_node = delimiter_node let final_node = delimiter_node
.next_sibling_or_token() .next_sibling_or_token()
.and_then(|it| it.into_token()) .and_then(|it| it.into_token())
.filter(|node| is_single_line_ws(node)) .filter(is_single_line_ws)
.unwrap_or(delimiter_node); .unwrap_or(delimiter_node);
return Some(TextRange::new(node.text_range().start(), final_node.text_range().end())); return Some(TextRange::new(node.text_range().start(), final_node.text_range().end()));

View File

@ -417,7 +417,7 @@ fn change_visibility(&self, record_fields: Vec<SyntaxNode>) -> Option<Vec<ast::I
replacements.append(&mut impl_item_replacements); replacements.append(&mut impl_item_replacements);
record_field_parents.into_iter().for_each(|x| { record_field_parents.into_iter().for_each(|x| {
x.1.descendants().filter_map(|x| ast::RecordField::cast(x)).for_each(|desc| { x.1.descendants().filter_map(ast::RecordField::cast).for_each(|desc| {
let is_record_field_present = record_fields let is_record_field_present = record_fields
.clone() .clone()
.into_iter() .into_iter()

View File

@ -85,7 +85,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
} }
mods.push(do_nl(after, tok)); mods.push(do_nl(after, tok));
} }
LIFETIME_IDENT if is_next(|it| is_text(it), true) => { LIFETIME_IDENT if is_next(is_text, true) => {
mods.push(do_ws(after, tok)); mods.push(do_ws(after, tok));
} }
AS_KW | DYN_KW | IMPL_KW => { AS_KW | DYN_KW | IMPL_KW => {

View File

@ -117,12 +117,7 @@ fn is_outline_mod(item: &ast::Item) -> bool {
} }
// If there are existing `mod m;` items, append after them (after the first group of them, rather). // If there are existing `mod m;` items, append after them (after the first group of them, rather).
match ast match ast.items().skip_while(|item| !is_outline_mod(item)).take_while(is_outline_mod).last() {
.items()
.skip_while(|item| !is_outline_mod(item))
.take_while(|item| is_outline_mod(item))
.last()
{
Some(last) => { Some(last) => {
cov_mark::hit!(unlinked_file_append_to_existing_mods); cov_mark::hit!(unlinked_file_append_to_existing_mods);
let offset = last.syntax().text_range().end(); let offset = last.syntax().text_range().end();

View File

@ -49,7 +49,7 @@ pub fn field_from_idents<'a>(
) -> Option<ast::Expr> { ) -> Option<ast::Expr> {
let mut iter = parts.into_iter(); let mut iter = parts.into_iter();
let base = expr_path(ext::ident_path(iter.next()?)); let base = expr_path(ext::ident_path(iter.next()?));
let expr = iter.fold(base, |base, s| expr_field(base, s)); let expr = iter.fold(base, expr_field);
Some(expr) Some(expr)
} }