From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/ra_hir/src/adt.rs | 23 +-- crates/ra_hir/src/code_model_api.rs | 71 ++------ crates/ra_hir/src/code_model_impl/function.rs | 12 +- crates/ra_hir/src/code_model_impl/krate.rs | 9 +- crates/ra_hir/src/code_model_impl/module.rs | 10 +- crates/ra_hir/src/expr.rs | 150 +++------------- crates/ra_hir/src/expr/scope.rs | 52 ++---- crates/ra_hir/src/generics.rs | 10 +- crates/ra_hir/src/ids.rs | 34 +--- crates/ra_hir/src/impl_block.rs | 23 +-- crates/ra_hir/src/macros.rs | 22 +-- crates/ra_hir/src/mock.rs | 5 +- crates/ra_hir/src/module_tree.rs | 22 +-- crates/ra_hir/src/nameres.rs | 95 +++------- crates/ra_hir/src/nameres/lower.rs | 31 ++-- crates/ra_hir/src/nameres/tests.rs | 34 +--- crates/ra_hir/src/path.rs | 44 ++--- crates/ra_hir/src/query_definitions.rs | 4 +- crates/ra_hir/src/resolve.rs | 35 +--- crates/ra_hir/src/source_binder.rs | 31 +--- crates/ra_hir/src/ty.rs | 249 +++++++------------------- crates/ra_hir/src/ty/method_resolution.rs | 30 ++-- crates/ra_hir/src/ty/tests.rs | 9 +- crates/ra_hir/src/type_ref.rs | 13 +- 24 files changed, 238 insertions(+), 780 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index c549e2126..6d917bb1b 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -62,10 +62,7 @@ impl StructData { } fn variants(enum_def: &ast::EnumDef) -> impl Iterator { - enum_def - .variant_list() - .into_iter() - .flat_map(|it| it.variants()) + enum_def.variant_list().into_iter().flat_map(|it| it.variants()) } impl EnumVariant { @@ -83,9 +80,7 @@ impl EnumVariant { (file_id, var) } pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc { - db.enum_data(self.parent).variants[self.id] - .variant_data - .clone() + db.enum_data(self.parent).variants[self.id].variant_data.clone() } } @@ -222,14 +217,12 @@ impl StructField { }; let field_sources = match struct_flavor { - ast::StructFlavor::Tuple(fl) => fl - .fields() - .map(|it| FieldSource::Pos(it.to_owned())) - .collect(), - ast::StructFlavor::Named(fl) => fl - .fields() - .map(|it| FieldSource::Named(it.to_owned())) - .collect(), + ast::StructFlavor::Tuple(fl) => { + fl.fields().map(|it| FieldSource::Pos(it.to_owned())).collect() + } + ast::StructFlavor::Named(fl) => { + fl.fields().map(|it| FieldSource::Named(it.to_owned())).collect() + } ast::StructFlavor::Unit => Vec::new(), }; let field = field_sources diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index a58bf8f87..cafc5279d 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -71,17 +71,7 @@ pub enum ModuleDef { Trait(Trait), Type(Type), } -impl_froms!( - ModuleDef: Module, - Function, - Struct, - Enum, - EnumVariant, - Const, - Static, - Trait, - Type -); +impl_froms!(ModuleDef: Module, Function, Struct, Enum, EnumVariant, Const, Static, Trait, Type); pub enum ModuleSource { SourceFile(TreeArc), @@ -90,13 +80,8 @@ pub enum ModuleSource { #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum Problem { - UnresolvedModule { - candidate: RelativePathBuf, - }, - NotDirOwner { - move_to: RelativePathBuf, - candidate: RelativePathBuf, - }, + UnresolvedModule { candidate: RelativePathBuf }, + NotDirOwner { move_to: RelativePathBuf, candidate: RelativePathBuf }, } impl Module { @@ -187,8 +172,7 @@ impl Module { impl Docs for Module { fn docs(&self, db: &impl HirDatabase) -> Option { - self.declaration_source(db) - .and_then(|it| docs_from_ast(&*it.1)) + self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) } } @@ -206,9 +190,7 @@ pub enum FieldSource { impl StructField { pub fn name(&self, db: &impl HirDatabase) -> Name { - self.parent.variant_data(db).fields().unwrap()[self.id] - .name - .clone() + self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() } pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { @@ -257,10 +239,7 @@ impl Struct { .fields() .into_iter() .flat_map(|it| it.iter()) - .map(|(id, _)| StructField { - parent: (*self).into(), - id, - }) + .map(|(id, _)| StructField { parent: (*self).into(), id }) .collect() } @@ -271,10 +250,7 @@ impl Struct { .into_iter() .flat_map(|it| it.iter()) .find(|(_id, data)| data.name == *name) - .map(|(id, _)| StructField { - parent: (*self).into(), - id, - }) + .map(|(id, _)| StructField { parent: (*self).into(), id }) } pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc { @@ -292,11 +268,7 @@ impl Struct { let r = self.module(db).resolver(db); // ...and add generic params, if present let p = self.generic_params(db); - let r = if !p.params.is_empty() { - r.push_generic_params_scope(p) - } else { - r - }; + let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; r } } @@ -356,11 +328,7 @@ impl Enum { let r = self.module(db).resolver(db); // ...and add generic params, if present let p = self.generic_params(db); - let r = if !p.params.is_empty() { - r.push_generic_params_scope(p) - } else { - r - }; + let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; r } } @@ -400,10 +368,7 @@ impl EnumVariant { .fields() .into_iter() .flat_map(|it| it.iter()) - .map(|(id, _)| StructField { - parent: (*self).into(), - id, - }) + .map(|(id, _)| StructField { parent: (*self).into(), id }) .collect() } @@ -413,10 +378,7 @@ impl EnumVariant { .into_iter() .flat_map(|it| it.iter()) .find(|(_id, data)| data.name == *name) - .map(|(id, _)| StructField { - parent: (*self).into(), - id, - }) + .map(|(id, _)| StructField { parent: (*self).into(), id }) } } @@ -488,10 +450,7 @@ impl Function { pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { let scopes = db.expr_scopes(*self); let syntax_mapping = db.body_syntax_mapping(*self); - ScopesWithSyntaxMapping { - scopes, - syntax_mapping, - } + ScopesWithSyntaxMapping { scopes, syntax_mapping } } pub fn signature(&self, db: &impl HirDatabase) -> Arc { @@ -516,11 +475,7 @@ impl Function { .unwrap_or_else(|| self.module(db).resolver(db)); // ...and add generic params, if present let p = self.generic_params(db); - let r = if !p.params.is_empty() { - r.push_generic_params_scope(p) - } else { - r - }; + let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; r } } diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index 8326c02c7..b9438fdb7 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs @@ -25,10 +25,7 @@ impl FnSignature { func: Function, ) -> Arc { let (_, node) = func.source(db); - let name = node - .name() - .map(|n| n.as_name()) - .unwrap_or_else(Name::missing); + let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); let mut params = Vec::new(); let mut has_self_param = false; if let Some(param_list) = node.param_list() { @@ -61,12 +58,7 @@ impl FnSignature { TypeRef::unit() }; - let sig = FnSignature { - name, - params, - ret_type, - has_self_param, - }; + let sig = FnSignature { name, params, ret_type, has_self_param }; Arc::new(sig) } } diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs index 1517434b8..161ae6e18 100644 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ b/crates/ra_hir/src/code_model_impl/krate.rs @@ -11,9 +11,7 @@ impl Crate { crate_graph .dependencies(self.crate_id) .map(|dep| { - let krate = Crate { - crate_id: dep.crate_id(), - }; + let krate = Crate { crate_id: dep.crate_id() }; let name = dep.as_name(); CrateDependency { krate, name } }) @@ -23,10 +21,7 @@ impl Crate { let module_tree = db.module_tree(*self); let module_id = module_tree.modules().next()?; - let module = Module { - krate: *self, - module_id, - }; + let module = Module { krate: *self, module_id }; Some(module) } } diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index f487b8532..1425fa693 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -12,10 +12,7 @@ use crate::{ impl Module { fn with_module_id(&self, module_id: ModuleId) -> Module { - Module { - module_id, - krate: self.krate, - } + Module { module_id, krate: self.krate } } pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option { @@ -42,10 +39,7 @@ impl Module { ) -> Option<(FileId, TreeArc)> { let module_tree = db.module_tree(self.krate); let link = self.module_id.parent_link(&module_tree)?; - let file_id = link - .owner(&module_tree) - .file_id(&module_tree) - .as_original_file(); + let file_id = link.owner(&module_tree).file_id(&module_tree).as_original_file(); let src = link.source(&module_tree, db); Some((file_id, src)) } diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 6826e966b..4e61d87ff 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -121,9 +121,7 @@ impl BodySyntaxMapping { } pub fn node_expr(&self, node: &ast::Expr) -> Option { - self.expr_syntax_mapping - .get(&SyntaxNodePtr::new(node.syntax())) - .cloned() + self.expr_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned() } pub fn pat_syntax(&self, pat: PatId) -> Option { @@ -135,9 +133,7 @@ impl BodySyntaxMapping { } pub fn node_pat(&self, node: &ast::Pat) -> Option { - self.pat_syntax_mapping - .get(&SyntaxNodePtr::new(node.syntax())) - .cloned() + self.pat_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned() } pub fn body(&self) -> &Arc { @@ -262,11 +258,7 @@ pub struct StructLitField { #[derive(Debug, Clone, Eq, PartialEq)] pub enum Statement { - Let { - pat: PatId, - type_ref: Option, - initializer: Option, - }, + Let { pat: PatId, type_ref: Option, initializer: Option }, Expr(ExprId), } @@ -275,11 +267,7 @@ impl Expr { match self { Expr::Missing => {} Expr::Path(_) => {} - Expr::If { - condition, - then_branch, - else_branch, - } => { + Expr::If { condition, then_branch, else_branch } => { f(*condition); f(*then_branch); if let Some(else_branch) = else_branch { @@ -457,11 +445,7 @@ impl Pat { args.iter().map(|pat| *pat).for_each(f); } Pat::Ref { pat, .. } => f(*pat), - Pat::Slice { - prefix, - rest, - suffix, - } => { + Pat::Slice { prefix, rest, suffix } => { let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter()); total_iter.map(|pat| *pat).for_each(f); } @@ -520,10 +504,7 @@ impl ExprCollector { } fn empty_block(&mut self) -> ExprId { - let block = Expr::Block { - statements: Vec::new(), - tail: None, - }; + let block = Expr::Block { statements: Vec::new(), tail: None }; self.exprs.alloc(block) } @@ -549,24 +530,10 @@ impl ExprCollector { .unwrap_or_else(|| self.empty_block()); let placeholder_pat = self.pats.alloc(Pat::Missing); let arms = vec![ - MatchArm { - pats: vec![pat], - expr: then_branch, - guard: None, - }, - MatchArm { - pats: vec![placeholder_pat], - expr: else_branch, - guard: None, - }, + MatchArm { pats: vec![pat], expr: then_branch, guard: None }, + MatchArm { pats: vec![placeholder_pat], expr: else_branch, guard: None }, ]; - self.alloc_expr( - Expr::Match { - expr: match_expr, - arms, - }, - syntax_ptr, - ) + self.alloc_expr(Expr::Match { expr: match_expr, arms }, syntax_ptr) } else { let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr())); let then_branch = self.collect_block_opt(e.then_branch()); @@ -577,14 +544,7 @@ impl ExprCollector { self.collect_expr(expr) } }); - self.alloc_expr( - Expr::If { - condition, - then_branch, - else_branch, - }, - syntax_ptr, - ) + self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) } } ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()), @@ -610,14 +570,7 @@ impl ExprCollector { let iterable = self.collect_expr_opt(e.iterable()); let pat = self.collect_pat_opt(e.pat()); let body = self.collect_block_opt(e.loop_body()); - self.alloc_expr( - Expr::For { - iterable, - pat, - body, - }, - syntax_ptr, - ) + self.alloc_expr(Expr::For { iterable, pat, body }, syntax_ptr) } ast::ExprKind::CallExpr(e) => { let callee = self.collect_expr_opt(e.expr()); @@ -635,18 +588,8 @@ impl ExprCollector { } else { Vec::new() }; - let method_name = e - .name_ref() - .map(|nr| nr.as_name()) - .unwrap_or_else(Name::missing); - self.alloc_expr( - Expr::MethodCall { - receiver, - method_name, - args, - }, - syntax_ptr, - ) + let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); + self.alloc_expr(Expr::MethodCall { receiver, method_name, args }, syntax_ptr) } ast::ExprKind::MatchExpr(e) => { let expr = self.collect_expr_opt(e.expr()); @@ -668,11 +611,8 @@ impl ExprCollector { self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) } ast::ExprKind::PathExpr(e) => { - let path = e - .path() - .and_then(Path::from_ast) - .map(Expr::Path) - .unwrap_or(Expr::Missing); + let path = + e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing); self.alloc_expr(path, syntax_ptr) } ast::ExprKind::ContinueExpr(_e) => { @@ -721,21 +661,11 @@ impl ExprCollector { Vec::new() }; let spread = e.spread().map(|s| self.collect_expr(s)); - self.alloc_expr( - Expr::StructLit { - path, - fields, - spread, - }, - syntax_ptr, - ) + self.alloc_expr(Expr::StructLit { path, fields, spread }, syntax_ptr) } ast::ExprKind::FieldExpr(e) => { let expr = self.collect_expr_opt(e.expr()); - let name = e - .name_ref() - .map(|nr| nr.as_name()) - .unwrap_or_else(Name::missing); + let name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) } ast::ExprKind::TryExpr(e) => { @@ -772,14 +702,7 @@ impl ExprCollector { } } let body = self.collect_expr_opt(e.body()); - self.alloc_expr( - Expr::Lambda { - args, - arg_types, - body, - }, - syntax_ptr, - ) + self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr) } ast::ExprKind::BinExpr(e) => { let lhs = self.collect_expr_opt(e.lhs()); @@ -804,9 +727,8 @@ impl ExprCollector { let lit = match child.flavor() { LiteralFlavor::IntNumber { suffix } => { - let known_name = suffix - .map(Name::new) - .and_then(|name| UncertainIntTy::from_name(&name)); + let known_name = + suffix.map(Name::new).and_then(|name| UncertainIntTy::from_name(&name)); Literal::Int( Default::default(), @@ -857,11 +779,7 @@ impl ExprCollector { let pat = self.collect_pat_opt(stmt.pat()); let type_ref = stmt.type_ref().map(TypeRef::from_ast); let initializer = stmt.initializer().map(|e| self.collect_expr(e)); - Statement::Let { - pat, - type_ref, - initializer, - } + Statement::Let { pat, type_ref, initializer } } ast::StmtKind::ExprStmt(stmt) => { Statement::Expr(self.collect_expr_opt(stmt.expr())) @@ -869,10 +787,7 @@ impl ExprCollector { }) .collect(); let tail = block.expr().map(|e| self.collect_expr(e)); - self.alloc_expr( - Expr::Block { statements, tail }, - SyntaxNodePtr::new(block.syntax()), - ) + self.alloc_expr(Expr::Block { statements, tail }, SyntaxNodePtr::new(block.syntax())) } fn collect_block_opt(&mut self, block: Option<&ast::Block>) -> ExprId { @@ -886,17 +801,10 @@ impl ExprCollector { fn collect_pat(&mut self, pat: &ast::Pat) -> PatId { let pattern = match pat.kind() { ast::PatKind::BindPat(bp) => { - let name = bp - .name() - .map(|nr| nr.as_name()) - .unwrap_or_else(Name::missing); + let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref()); let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); - Pat::Bind { - name, - mode: annotation, - subpat, - } + Pat::Bind { name, mode: annotation, subpat } } ast::PatKind::TupleStructPat(p) => { let path = p.path().and_then(Path::from_ast); @@ -919,9 +827,8 @@ impl ExprCollector { ast::PatKind::PlaceholderPat(_) => Pat::Wild, ast::PatKind::StructPat(p) => { let path = p.path().and_then(Path::from_ast); - let field_pat_list = p - .field_pat_list() - .expect("every struct should have a field list"); + let field_pat_list = + p.field_pat_list().expect("every struct should have a field list"); let mut fields: Vec<_> = field_pat_list .bind_pats() .map(|bind_pat| { @@ -961,10 +868,7 @@ impl ExprCollector { if let Some(param_list) = node.param_list() { if let Some(self_param) = param_list.self_param() { let self_param = SyntaxNodePtr::new( - self_param - .self_kw() - .expect("self param without self keyword") - .syntax(), + self_param.self_kw().expect("self param without self keyword").syntax(), ); let param_pat = self.alloc_pat( Pat::Bind { diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 368994bf7..44d5c2429 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -74,17 +74,11 @@ impl ExprScopes { } fn root_scope(&mut self) -> ScopeId { - self.scopes.alloc(ScopeData { - parent: None, - entries: vec![], - }) + self.scopes.alloc(ScopeData { parent: None, entries: vec![] }) } fn new_scope(&mut self, parent: ScopeId) -> ScopeId { - self.scopes.alloc(ScopeData { - parent: Some(parent), - entries: vec![], - }) + self.scopes.alloc(ScopeData { parent: Some(parent), entries: vec![] }) } fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) { @@ -92,10 +86,7 @@ impl ExprScopes { Pat::Bind { name, .. } => { // bind can have a subpattern, but it's actually not allowed // to bind to things in there - let entry = ScopeEntry { - name: name.clone(), - pat, - }; + let entry = ScopeEntry { name: name.clone(), pat }; self.scopes[scope].entries.push(entry) } p => p.walk_child_pats(|pat| self.add_bindings(body, scope, pat)), @@ -104,9 +95,7 @@ impl ExprScopes { fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) { let body = Arc::clone(&self.body); - params - .iter() - .for_each(|pat| self.add_bindings(&body, scope, *pat)); + params.iter().for_each(|pat| self.add_bindings(&body, scope, *pat)); } fn set_scope(&mut self, node: ExprId, scope: ScopeId) { @@ -142,9 +131,7 @@ impl ScopeEntryWithSyntax { impl ScopesWithSyntaxMapping { fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator + 'a { - generate(self.scope_for(node), move |&scope| { - self.scopes.scopes[scope].parent - }) + generate(self.scope_for(node), move |&scope| self.scopes.scopes[scope].parent) } pub fn scope_for_offset(&self, offset: TextUnit) -> Option { @@ -154,10 +141,7 @@ impl ScopesWithSyntaxMapping { .filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope))) // find containing scope .min_by_key(|(ptr, _scope)| { - ( - !(ptr.range().start() <= offset && offset <= ptr.range().end()), - ptr.range().len(), - ) + (!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len()) }) .map(|(ptr, scope)| self.adjust(ptr, *scope, offset)) } @@ -251,9 +235,7 @@ fn compute_block_scopes( ) { for stmt in statements { match stmt { - Statement::Let { - pat, initializer, .. - } => { + Statement::Let { pat, initializer, .. } => { if let Some(expr) = initializer { scopes.set_scope(*expr, scope); compute_expr_scopes(*expr, body, scopes, scope); @@ -278,21 +260,13 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope Expr::Block { statements, tail } => { compute_block_scopes(&statements, *tail, body, scopes, scope); } - Expr::For { - iterable, - pat, - body: body_expr, - } => { + Expr::For { iterable, pat, body: body_expr } => { compute_expr_scopes(*iterable, body, scopes, scope); let scope = scopes.new_scope(scope); scopes.add_bindings(body, scope, *pat); compute_expr_scopes(*body_expr, body, scopes, scope); } - Expr::Lambda { - args, - body: body_expr, - .. - } => { + Expr::Lambda { args, body: body_expr, .. } => { let scope = scopes.new_scope(scope); scopes.add_params_bindings(scope, &args); compute_expr_scopes(*body_expr, body, scopes, scope); @@ -341,9 +315,7 @@ mod tests { let file = SourceFile::parse(&code); let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); - let irrelevant_function = Function { - id: crate::ids::FunctionId::from_raw(0.into()), - }; + let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def); let scopes = ExprScopes::new(Arc::clone(body_hir.body())); let scopes = ScopesWithSyntaxMapping { @@ -444,9 +416,7 @@ mod tests { let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); - let irrelevant_function = Function { - id: crate::ids::FunctionId::from_raw(0.into()), - }; + let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def); let scopes = ExprScopes::new(Arc::clone(body_hir.body())); let scopes = ScopesWithSyntaxMapping { diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index a82205f0b..c72360f44 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -58,14 +58,8 @@ impl GenericParams { fn fill_params(&mut self, params: &ast::TypeParamList) { for (idx, type_param) in params.type_params().enumerate() { - let name = type_param - .name() - .map(AsName::as_name) - .unwrap_or_else(Name::missing); - let param = GenericParam { - idx: idx as u32, - name, - }; + let name = type_param.name().map(AsName::as_name).unwrap_or_else(Name::missing); + let param = GenericParam { idx: idx as u32, name }; self.params.push(param); } } diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 95678bf70..ea13c1196 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -169,11 +169,7 @@ impl Hash for ItemLoc { impl Clone for ItemLoc { fn clone(&self) -> ItemLoc { - ItemLoc { - module: self.module, - raw: self.raw, - _ty: PhantomData, - } + ItemLoc { module: self.module, raw: self.raw, _ty: PhantomData } } } @@ -186,11 +182,7 @@ pub(crate) struct LocationCtx { impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { - LocationCtx { - db, - module, - file_id, - } + LocationCtx { db, module, file_id } } pub(crate) fn to_def(self, ast: &N) -> DEF where @@ -205,15 +197,9 @@ pub(crate) trait AstItemDef: ArenaId + Clone { fn interner(interner: &HirInterner) -> &LocationIntener, Self>; fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { let items = ctx.db.file_items(ctx.file_id); - let raw = SourceItemId { - file_id: ctx.file_id, - item_id: items.id_of(ctx.file_id, ast.syntax()), - }; - let loc = ItemLoc { - module: ctx.module, - raw, - _ty: PhantomData, - }; + let raw = + SourceItemId { file_id: ctx.file_id, item_id: items.id_of(ctx.file_id, ast.syntax()) }; + let loc = ItemLoc { module: ctx.module, raw, _ty: PhantomData }; Self::interner(ctx.db.as_ref()).loc2id(&loc) } @@ -221,9 +207,8 @@ pub(crate) trait AstItemDef: ArenaId + Clone { let int = Self::interner(db.as_ref()); let loc = int.id2loc(self); let syntax = db.file_item(loc.raw); - let ast = N::cast(&syntax) - .unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)) - .to_owned(); + let ast = + N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned(); (loc.raw.file_id, ast) } fn module(self, db: &impl HirDatabase) -> Module { @@ -317,10 +302,7 @@ pub struct SourceFileItems { impl SourceFileItems { pub(crate) fn new(file_id: HirFileId, source_file: &SourceFile) -> SourceFileItems { - let mut res = SourceFileItems { - file_id, - arena: Arena::default(), - }; + let mut res = SourceFileItems { file_id, arena: Arena::default() }; res.init(source_file); res } diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 094dbedb3..b2fbee8d7 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -50,17 +50,11 @@ impl ImplBlock { item: ImplItem, ) -> Option { let impl_id = *module_impl_blocks.impls_by_def.get(&item)?; - Some(ImplBlock { - module_impl_blocks, - impl_id, - }) + Some(ImplBlock { module_impl_blocks, impl_id }) } pub(crate) fn from_id(module_impl_blocks: Arc, impl_id: ImplId) -> ImplBlock { - ImplBlock { - module_impl_blocks, - impl_id, - } + ImplBlock { module_impl_blocks, impl_id } } pub fn id(&self) -> ImplId { @@ -144,11 +138,7 @@ impl ImplData { } else { Vec::new() }; - ImplData { - target_trait, - target_type, - items, - } + ImplData { target_trait, target_type, items } } pub fn target_trait(&self) -> Option<&TypeRef> { @@ -212,10 +202,9 @@ impl ModuleImplBlocks { let file_id: HirFileId = file_id.into(); let node = match &module_source { ModuleSource::SourceFile(node) => node.syntax(), - ModuleSource::Module(node) => node - .item_list() - .expect("inline module should have item list") - .syntax(), + ModuleSource::Module(node) => { + node.item_list().expect("inline module should have item list").syntax() + } }; for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index cb8a9312e..95925159f 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs @@ -48,9 +48,7 @@ impl MacroDef { let input = { let arg = macro_call.token_tree()?.syntax(); - MacroInput { - text: arg.text().to_string(), - } + MacroInput { text: arg.text().to_string() } }; Some((def, input)) } @@ -68,20 +66,14 @@ impl MacroDef { let ptr = SyntaxNodePtr::new(array_expr.syntax()); let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text)); let ranges_map = vec![(src_range, array_expr.syntax().range())]; - let res = MacroExpansion { - text, - ranges_map, - ptr, - }; + let res = MacroExpansion { text, ranges_map, ptr }; Some(res) } fn expand_query_group(self, input: MacroInput) -> Option { let anchor = "trait "; let pos = input.text.find(anchor)? + anchor.len(); - let trait_name = input.text[pos..] - .chars() - .take_while(|c| c.is_alphabetic()) - .collect::(); + let trait_name = + input.text[pos..].chars().take_while(|c| c.is_alphabetic()).collect::(); if trait_name.is_empty() { return None; } @@ -92,11 +84,7 @@ impl MacroDef { let name = trait_def.name()?; let ptr = SyntaxNodePtr::new(trait_def.syntax()); let ranges_map = vec![(src_range, name.syntax().range())]; - let res = MacroExpansion { - text, - ranges_map, - ptr, - }; + let res = MacroExpansion { text, ranges_map, ptr }; Some(res) } } diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 87095fb21..950f89948 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -64,10 +64,7 @@ impl MockDatabase { let mut source_root = SourceRoot::default(); for entry in parse_fixture(fixture) { if entry.text.contains(CURSOR_MARKER) { - assert!( - position.is_none(), - "only one marker (<|>) per fixture is allowed" - ); + assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); position = Some(self.add_file_with_position( source_root_id, &mut source_root, diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index a1aa3d8ce..1f19ee191 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs @@ -153,10 +153,8 @@ impl ModuleTree { file_id: HirFileId, decl_id: Option, ) -> Option { - let (res, _) = self - .mods - .iter() - .find(|(_, m)| (m.file_id, m.decl_id) == (file_id, decl_id))?; + let (res, _) = + self.mods.iter().find(|(_, m)| (m.file_id, m.decl_id) == (file_id, decl_id))?; Some(res) } @@ -178,18 +176,10 @@ impl ModuleTree { decl_id: Option, ) -> ModuleId { let is_root = parent.is_none(); - let id = self.alloc_mod(ModuleData { - file_id, - decl_id, - parent, - children: Vec::new(), - }); + let id = self.alloc_mod(ModuleData { file_id, decl_id, parent, children: Vec::new() }); for sub in db.submodules(file_id, decl_id).iter() { let link = self.alloc_link(LinkData { - source: SourceItemId { - file_id, - item_id: sub.decl_id, - }, + source: SourceItemId { file_id, item_id: sub.decl_id }, name: sub.name.clone(), owner: id, points_to: Vec::new(), @@ -244,9 +234,7 @@ impl ModuleId { Some(tree.links[link].owner) } pub(crate) fn crate_root(self, tree: &ModuleTree) -> ModuleId { - generate(Some(self), move |it| it.parent(tree)) - .last() - .unwrap() + generate(Some(self), move |it| it.parent(tree)).last().unwrap() } pub(crate) fn child(self, tree: &ModuleTree, name: &Name) -> Option { let link = tree.mods[self] diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 681aa9a67..b7382d9c3 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -83,40 +83,25 @@ pub struct PerNs { impl Default for PerNs { fn default() -> Self { - PerNs { - types: None, - values: None, - } + PerNs { types: None, values: None } } } impl PerNs { pub fn none() -> PerNs { - PerNs { - types: None, - values: None, - } + PerNs { types: None, values: None } } pub fn values(t: T) -> PerNs { - PerNs { - types: None, - values: Some(t), - } + PerNs { types: None, values: Some(t) } } pub fn types(t: T) -> PerNs { - PerNs { - types: Some(t), - values: None, - } + PerNs { types: Some(t), values: None } } pub fn both(types: T, values: T) -> PerNs { - PerNs { - types: Some(types), - values: Some(values), - } + PerNs { types: Some(types), values: Some(values) } } pub fn is_none(&self) -> bool { @@ -147,31 +132,19 @@ impl PerNs { } pub fn as_ref(&self) -> PerNs<&T> { - PerNs { - types: self.types.as_ref(), - values: self.values.as_ref(), - } + PerNs { types: self.types.as_ref(), values: self.values.as_ref() } } pub fn combine(self, other: PerNs) -> PerNs { - PerNs { - types: self.types.or(other.types), - values: self.values.or(other.values), - } + PerNs { types: self.types.or(other.types), values: self.values.or(other.values) } } pub fn and_then(self, f: impl Fn(T) -> Option) -> PerNs { - PerNs { - types: self.types.and_then(&f), - values: self.values.and_then(&f), - } + PerNs { types: self.types.and_then(&f), values: self.values.and_then(&f) } } pub fn map(self, f: impl Fn(T) -> U) -> PerNs { - PerNs { - types: self.types.map(&f), - values: self.values.map(&f), - } + PerNs { types: self.types.map(&f), values: self.values.map(&f) } } } @@ -233,9 +206,7 @@ where for dep in self.krate.dependencies(self.db) { log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); if let Some(module) = dep.krate.root_module(self.db) { - self.result - .extern_prelude - .insert(dep.name.clone(), module.into()); + self.result.extern_prelude.insert(dep.name.clone(), module.into()); } } } @@ -245,17 +216,11 @@ where for (import_id, import_data) in input.imports.iter() { if let Some(last_segment) = import_data.path.segments.iter().last() { if !import_data.is_glob { - let name = import_data - .alias - .clone() - .unwrap_or_else(|| last_segment.name.clone()); - module_items.items.insert( - name, - Resolution { - def: PerNs::none(), - import: Some(import_id), - }, - ); + let name = + import_data.alias.clone().unwrap_or_else(|| last_segment.name.clone()); + module_items + .items + .insert(name, Resolution { def: PerNs::none(), import: Some(import_id) }); } } } @@ -267,10 +232,7 @@ where // Populate modules for (name, module_id) in module_id.children(&self.module_tree) { - let module = Module { - module_id, - krate: self.krate, - }; + let module = Module { module_id, krate: self.krate }; self.add_module_item(&mut module_items, name, PerNs::types(module.into())); } @@ -305,20 +267,13 @@ where if import.is_glob { return ReachedFixedPoint::Yes; }; - let original_module = Module { - krate: self.krate, - module_id, - }; + let original_module = Module { krate: self.krate, module_id }; let (def, reached_fixedpoint) = - self.result - .resolve_path_fp(self.db, original_module, &import.path); + self.result.resolve_path_fp(self.db, original_module, &import.path); if reached_fixedpoint == ReachedFixedPoint::Yes { let last_segment = import.path.segments.last().unwrap(); - let name = import - .alias - .clone() - .unwrap_or_else(|| last_segment.name.clone()); + let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone()); log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 @@ -330,10 +285,7 @@ where } } self.update(module_id, |items| { - let res = Resolution { - def, - import: Some(import_id), - }; + let res = Resolution { def, import: Some(import_id) }; items.items.insert(name, res); }); } @@ -358,12 +310,7 @@ impl ItemMap { let module_tree = db.module_tree(krate); let input = module_tree .modules() - .map(|module_id| { - ( - module_id, - db.lower_module_module(Module { krate, module_id }), - ) - }) + .map(|module_id| (module_id, db.lower_module_module(Module { krate, module_id }))) .collect::>(); let resolver = Resolver::new(db, &input, krate); diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 7e6e48ae0..7e9a3de2b 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs @@ -82,13 +82,9 @@ impl LoweredModule { let mut source_map = ImportSourceMap::default(); let mut res = LoweredModule::default(); match source { - ModuleSource::SourceFile(it) => res.fill( - &mut source_map, - db, - module, - file_id, - &mut it.items_with_macros(), - ), + ModuleSource::SourceFile(it) => { + res.fill(&mut source_map, db, module, file_id, &mut it.items_with_macros()) + } ModuleSource::Module(it) => { if let Some(item_list) = it.item_list() { res.fill( @@ -121,10 +117,8 @@ impl LoweredModule { } ast::ItemOrMacro::Macro(macro_call) => { let item_id = file_items.id_of_unchecked(macro_call.syntax()); - let loc = MacroCallLoc { - module, - source_item_id: SourceItemId { file_id, item_id }, - }; + let loc = + MacroCallLoc { module, source_item_id: SourceItemId { file_id, item_id } }; let id = loc.id(db); let file_id = HirFileId::from(id); //FIXME: expand recursively @@ -163,22 +157,19 @@ impl LoweredModule { ast::ModuleItemKind::FnDef(it) => { if let Some(name) = it.name() { let func = Function { id: ctx.to_def(it) }; - self.declarations - .insert(name.as_name(), PerNs::values(func.into())); + self.declarations.insert(name.as_name(), PerNs::values(func.into())); } } ast::ModuleItemKind::TraitDef(it) => { if let Some(name) = it.name() { let t = Trait { id: ctx.to_def(it) }; - self.declarations - .insert(name.as_name(), PerNs::types(t.into())); + self.declarations.insert(name.as_name(), PerNs::types(t.into())); } } ast::ModuleItemKind::TypeDef(it) => { if let Some(name) = it.name() { let t = Type { id: ctx.to_def(it) }; - self.declarations - .insert(name.as_name(), PerNs::types(t.into())); + self.declarations.insert(name.as_name(), PerNs::types(t.into())); } } ast::ModuleItemKind::ImplBlock(_) => { @@ -207,15 +198,13 @@ impl LoweredModule { ast::ModuleItemKind::ConstDef(it) => { if let Some(name) = it.name() { let c = Const { id: ctx.to_def(it) }; - self.declarations - .insert(name.as_name(), PerNs::values(c.into())); + self.declarations.insert(name.as_name(), PerNs::values(c.into())); } } ast::ModuleItemKind::StaticDef(it) => { if let Some(name) = it.name() { let s = Static { id: ctx.to_def(it) }; - self.declarations - .insert(name.as_name(), PerNs::values(s.into())); + self.declarations.insert(name.as_name(), PerNs::values(s.into())); } } ast::ModuleItemKind::Module(_) => { diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 0654dbaa1..3dfad6bf2 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -42,19 +42,11 @@ fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { .collect::>(); lines.sort(); let actual = lines.join("\n"); - let expected = expected - .trim() - .lines() - .map(|it| it.trim()) - .collect::>() - .join("\n"); + let expected = expected.trim().lines().map(|it| it.trim()).collect::>().join("\n"); assert_eq_text!(&expected, &actual); fn dump_resolution(resolution: &Resolution) -> &'static str { - match ( - resolution.def.types.is_some(), - resolution.def.values.is_some(), - ) { + match (resolution.def.types.is_some(), resolution.def.values.is_some()) { (true, true) => "t v", (true, false) => "t", (false, true) => "v", @@ -314,9 +306,7 @@ fn item_map_across_crates() { let mut crate_graph = CrateGraph::default(); let main_crate = crate_graph.add_crate_root(main_id); let lib_crate = crate_graph.add_crate_root(lib_id); - crate_graph - .add_dep(main_crate, "test_crate".into(), lib_crate) - .unwrap(); + crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); db.set_crate_graph(Arc::new(crate_graph)); @@ -357,9 +347,7 @@ fn extern_crate_rename() { let mut crate_graph = CrateGraph::default(); let main_crate = crate_graph.add_crate_root(main_id); let lib_crate = crate_graph.add_crate_root(lib_id); - crate_graph - .add_dep(main_crate, "alloc".into(), lib_crate) - .unwrap(); + crate_graph.add_dep(main_crate, "alloc".into(), lib_crate).unwrap(); db.set_crate_graph(Arc::new(crate_graph)); @@ -406,9 +394,7 @@ fn import_across_source_roots() { let mut crate_graph = CrateGraph::default(); let main_crate = crate_graph.add_crate_root(main_id); let lib_crate = crate_graph.add_crate_root(lib_id); - crate_graph - .add_dep(main_crate, "test_crate".into(), lib_crate) - .unwrap(); + crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); db.set_crate_graph(Arc::new(crate_graph)); @@ -447,9 +433,7 @@ fn reexport_across_crates() { let mut crate_graph = CrateGraph::default(); let main_crate = crate_graph.add_crate_root(main_id); let lib_crate = crate_graph.add_crate_root(lib_id); - crate_graph - .add_dep(main_crate, "test_crate".into(), lib_crate) - .unwrap(); + crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); db.set_crate_graph(Arc::new(crate_graph)); @@ -482,11 +466,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { let events = db.log_executed(|| { db.item_map(krate); }); - assert!( - !format!("{:?}", events).contains("item_map"), - "{:#?}", - events - ) + assert!(!format!("{:?}", events).contains("item_map"), "{:#?}", events) } } diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index cb0a04500..6a24c8aa7 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs @@ -66,14 +66,9 @@ impl Path { match segment.kind()? { ast::PathSegmentKind::Name(name) => { - let args = segment - .type_arg_list() - .and_then(GenericArgs::from_ast) - .map(Arc::new); - let segment = PathSegment { - name: name.as_name(), - args_and_bindings: args, - }; + let args = + segment.type_arg_list().and_then(GenericArgs::from_ast).map(Arc::new); + let segment = PathSegment { name: name.as_name(), args_and_bindings: args }; segments.push(segment); } ast::PathSegmentKind::CrateKw => { @@ -153,10 +148,7 @@ impl From for Path { fn from(name: Name) -> Path { Path { kind: PathKind::Plain, - segments: vec![PathSegment { - name, - args_and_bindings: None, - }], + segments: vec![PathSegment { name, args_and_bindings: None }], } } } @@ -209,18 +201,13 @@ fn expand_use_tree<'a>( } fn convert_path(prefix: Option, path: &ast::Path) -> Option { - let prefix = if let Some(qual) = path.qualifier() { - Some(convert_path(prefix, qual)?) - } else { - prefix - }; + let prefix = + if let Some(qual) = path.qualifier() { Some(convert_path(prefix, qual)?) } else { prefix }; let segment = path.segment()?; let res = match segment.kind()? { ast::PathSegmentKind::Name(name) => { - let mut res = prefix.unwrap_or_else(|| Path { - kind: PathKind::Plain, - segments: Vec::with_capacity(1), - }); + let mut res = prefix + .unwrap_or_else(|| Path { kind: PathKind::Plain, segments: Vec::with_capacity(1) }); res.segments.push(PathSegment { name: name.as_name(), args_and_bindings: None, // no type args in use @@ -231,28 +218,19 @@ fn convert_path(prefix: Option, path: &ast::Path) -> Option { if prefix.is_some() { return None; } - Path { - kind: PathKind::Crate, - segments: Vec::new(), - } + Path { kind: PathKind::Crate, segments: Vec::new() } } ast::PathSegmentKind::SelfKw => { if prefix.is_some() { return None; } - Path { - kind: PathKind::Self_, - segments: Vec::new(), - } + Path { kind: PathKind::Self_, segments: Vec::new() } } ast::PathSegmentKind::SuperKw => { if prefix.is_some() { return None; } - Path { - kind: PathKind::Super, - segments: Vec::new(), - } + Path { kind: PathKind::Super, segments: Vec::new() } } }; Some(res) diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index b4d8da1e6..03113e7cc 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -23,7 +23,5 @@ pub(super) fn file_item( source_item_id: SourceItemId, ) -> TreeArc { let source_file = db.hir_parse(source_item_id.file_id); - db.file_items(source_item_id.file_id)[source_item_id.item_id] - .to_node(&source_file) - .to_owned() + db.file_items(source_item_id.file_id)[source_item_id.item_id].to_node(&source_file).to_owned() } diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 0f60d4742..3d7ec5683 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -138,10 +138,7 @@ impl Resolver { expr_scopes: Arc, scope_id: ScopeId, ) -> Resolver { - self.push_scope(Scope::ExprScope(ExprScope { - expr_scopes, - scope_id, - })) + self.push_scope(Scope::ExprScope(ExprScope { expr_scopes, scope_id })) } } @@ -170,11 +167,8 @@ impl Scope { } } Scope::ExprScope(e) => { - let entry = e - .expr_scopes - .entries(e.scope_id) - .iter() - .find(|entry| entry.name() == name); + let entry = + e.expr_scopes.entries(e.scope_id).iter().find(|entry| entry.name() == name); match entry { Some(e) => PerNs::values(Resolution::LocalBinding(e.pat())), None => PerNs::none(), @@ -193,35 +187,24 @@ impl Scope { // def: m.module.into(), // }), // ); - m.item_map[m.module.module_id] - .entries() - .for_each(|(name, res)| { - f(name.clone(), res.def.map(Resolution::Def)); - }); + m.item_map[m.module.module_id].entries().for_each(|(name, res)| { + f(name.clone(), res.def.map(Resolution::Def)); + }); m.item_map.extern_prelude.iter().for_each(|(name, def)| { f(name.clone(), PerNs::types(Resolution::Def(*def))); }); } Scope::GenericParams(gp) => { for param in &gp.params { - f( - param.name.clone(), - PerNs::types(Resolution::GenericParam(param.idx)), - ) + f(param.name.clone(), PerNs::types(Resolution::GenericParam(param.idx))) } } Scope::ImplBlockScope(i) => { - f( - Name::self_type(), - PerNs::types(Resolution::SelfType(i.clone())), - ); + f(Name::self_type(), PerNs::types(Resolution::SelfType(i.clone()))); } Scope::ExprScope(e) => { e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { - f( - e.name().clone(), - PerNs::values(Resolution::LocalBinding(e.pat())), - ); + f(e.name().clone(), PerNs::values(Resolution::LocalBinding(e.pat()))); }); } } diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 59f782277..625a2ce45 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -65,11 +65,7 @@ pub fn module_from_child_node( file_id: FileId, child: &SyntaxNode, ) -> Option { - if let Some(m) = child - .ancestors() - .filter_map(ast::Module::cast) - .find(|it| !it.has_semi()) - { + if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { module_from_inline(db, file_id.into(), m) } else { module_from_file_id(db, file_id.into()) @@ -82,14 +78,13 @@ fn module_from_source( decl_id: Option, ) -> Option { let source_root_id = db.file_source_root(file_id.as_original_file()); - db.source_root_crates(source_root_id) - .iter() - .map(|&crate_id| Crate { crate_id }) - .find_map(|krate| { + db.source_root_crates(source_root_id).iter().map(|&crate_id| Crate { crate_id }).find_map( + |krate| { let module_tree = db.module_tree(krate); let module_id = module_tree.find_module_by_source(file_id, decl_id)?; Some(Module { krate, module_id }) - }) + }, + ) } pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option { @@ -116,9 +111,7 @@ pub fn function_from_module( let (file_id, _) = module.definition_source(db); let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); - Function { - id: ctx.to_def(fn_def), - } + Function { id: ctx.to_def(fn_def) } } pub fn function_from_child_node( @@ -138,18 +131,14 @@ pub fn struct_from_module( let (file_id, _) = module.definition_source(db); let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); - Struct { - id: ctx.to_def(struct_def), - } + Struct { id: ctx.to_def(struct_def) } } pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { let (file_id, _) = module.definition_source(db); let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); - Enum { - id: ctx.to_def(enum_def), - } + Enum { id: ctx.to_def(enum_def) } } pub fn trait_from_module( @@ -160,9 +149,7 @@ pub fn trait_from_module( let (file_id, _) = module.definition_source(db); let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); - Trait { - id: ctx.to_def(trait_def), - } + Trait { id: ctx.to_def(trait_def) } } pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> { diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 86a7f8b83..453520bbe 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -305,10 +305,8 @@ impl Ty { match type_ref { TypeRef::Never => Ty::Never, TypeRef::Tuple(inner) => { - let inner_tys = inner - .iter() - .map(|tr| Ty::from_hir(db, resolver, tr)) - .collect::>(); + let inner_tys = + inner.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::>(); Ty::Tuple(inner_tys.into()) } TypeRef::Path(path) => Ty::from_hir_path(db, resolver, path), @@ -330,17 +328,11 @@ impl Ty { } TypeRef::Placeholder => Ty::Unknown, TypeRef::Fn(params) => { - let mut inner_tys = params - .iter() - .map(|tr| Ty::from_hir(db, resolver, tr)) - .collect::>(); - let return_ty = inner_tys - .pop() - .expect("TypeRef::Fn should always have at least return type"); - let sig = FnSig { - input: inner_tys, - output: return_ty, - }; + let mut inner_tys = + params.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::>(); + let return_ty = + inner_tys.pop().expect("TypeRef::Fn should always have at least return type"); + let sig = FnSig { input: inner_tys, output: return_ty }; Ty::FnPtr(Arc::new(sig)) } TypeRef::Error => Ty::Unknown, @@ -407,10 +399,7 @@ impl Ty { resolved: TypableDef, ) -> Substs { let mut substs = Vec::new(); - let last = path - .segments - .last() - .expect("path should have at least one segment"); + let last = path.segments.last().expect("path should have at least one segment"); let (def_generics, segment) = match resolved { TypableDef::Function(func) => (func.generic_params(db), last), TypableDef::Struct(s) => (s.generic_params(db), last), @@ -447,11 +436,8 @@ impl Ty { } // add placeholders for args that were not provided // TODO: handle defaults - let supplied_params = segment - .args_and_bindings - .as_ref() - .map(|ga| ga.args.len()) - .unwrap_or(0); + let supplied_params = + segment.args_and_bindings.as_ref().map(|ga| ga.args.len()).unwrap_or(0); for _ in supplied_params..def_generics.params.len() { substs.push(Ty::Unknown); } @@ -531,17 +517,8 @@ impl Ty { /// `Option` afterwards.) pub fn apply_substs(self, substs: Substs) -> Ty { match self { - Ty::Adt { def_id, name, .. } => Ty::Adt { - def_id, - name, - substs, - }, - Ty::FnDef { def, name, sig, .. } => Ty::FnDef { - def, - name, - sig, - substs, - }, + Ty::Adt { def_id, name, .. } => Ty::Adt { def_id, name, substs }, + Ty::FnDef { def, name, sig, .. } => Ty::FnDef { def, name, sig, substs }, _ => self, } } @@ -591,42 +568,25 @@ impl fmt::Display for Ty { if ts.len() == 1 { write!(f, "({},)", ts[0]) } else { - join(ts.iter()) - .surround_with("(", ")") - .separator(", ") - .to_fmt(f) + join(ts.iter()).surround_with("(", ")").separator(", ").to_fmt(f) } } Ty::FnPtr(sig) => { - join(sig.input.iter()) - .surround_with("fn(", ")") - .separator(", ") - .to_fmt(f)?; + join(sig.input.iter()).surround_with("fn(", ")").separator(", ").to_fmt(f)?; write!(f, " -> {}", sig.output) } - Ty::FnDef { - name, substs, sig, .. - } => { + Ty::FnDef { name, substs, sig, .. } => { write!(f, "fn {}", name)?; if substs.0.len() > 0 { - join(substs.0.iter()) - .surround_with("<", ">") - .separator(", ") - .to_fmt(f)?; + join(substs.0.iter()).surround_with("<", ">").separator(", ").to_fmt(f)?; } - join(sig.input.iter()) - .surround_with("(", ")") - .separator(", ") - .to_fmt(f)?; + join(sig.input.iter()).surround_with("(", ")").separator(", ").to_fmt(f)?; write!(f, " -> {}", sig.output) } Ty::Adt { name, substs, .. } => { write!(f, "{}", name)?; if substs.0.len() > 0 { - join(substs.0.iter()) - .surround_with("<", ">") - .separator(", ") - .to_fmt(f)?; + join(substs.0.iter()).surround_with("<", ">").separator(", ").to_fmt(f)?; } Ok(()) } @@ -646,31 +606,16 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { let resolver = def.resolver(db); let generics = def.generic_params(db); let name = def.name(db); - let input = signature - .params() - .iter() - .map(|tr| Ty::from_hir(db, &resolver, tr)) - .collect::>(); + let input = + signature.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::>(); let output = Ty::from_hir(db, &resolver, signature.ret_type()); let sig = Arc::new(FnSig { input, output }); let substs = make_substs(&generics); - Ty::FnDef { - def, - sig, - name, - substs, - } + Ty::FnDef { def, sig, name, substs } } fn make_substs(generics: &GenericParams) -> Substs { - Substs( - generics - .params - .iter() - .map(|_p| Ty::Unknown) - .collect::>() - .into(), - ) + Substs(generics.params.iter().map(|_p| Ty::Unknown).collect::>().into()) } fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty { @@ -935,11 +880,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs) -> bool { - substs1 - .0 - .iter() - .zip(substs2.0.iter()) - .all(|(t1, t2)| self.unify(t1, t2)) + substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify(t1, t2)) } fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { @@ -961,25 +902,16 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { }, (Ty::Bool, _) | (Ty::Str, _) | (Ty::Never, _) | (Ty::Char, _) => ty1 == ty2, ( - Ty::Adt { - def_id: def_id1, - substs: substs1, - .. - }, - Ty::Adt { - def_id: def_id2, - substs: substs2, - .. - }, + Ty::Adt { def_id: def_id1, substs: substs1, .. }, + Ty::Adt { def_id: def_id2, substs: substs2, .. }, ) if def_id1 == def_id2 => self.unify_substs(substs1, substs2), (Ty::Slice(t1), Ty::Slice(t2)) => self.unify(t1, t2), (Ty::RawPtr(t1, m1), Ty::RawPtr(t2, m2)) if m1 == m2 => self.unify(t1, t2), (Ty::Ref(t1, m1), Ty::Ref(t2, m2)) if m1 == m2 => self.unify(t1, t2), (Ty::FnPtr(sig1), Ty::FnPtr(sig2)) if sig1 == sig2 => true, - (Ty::Tuple(ts1), Ty::Tuple(ts2)) if ts1.len() == ts2.len() => ts1 - .iter() - .zip(ts2.iter()) - .all(|(t1, t2)| self.unify(t1, t2)), + (Ty::Tuple(ts1), Ty::Tuple(ts2)) if ts1.len() == ts2.len() => { + ts1.iter().zip(ts2.iter()).all(|(t1, t2)| self.unify(t1, t2)) + } (Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2))) | (Ty::Infer(InferTy::IntVar(tv1)), Ty::Infer(InferTy::IntVar(tv2))) | (Ty::Infer(InferTy::FloatVar(tv1)), Ty::Infer(InferTy::FloatVar(tv2))) => { @@ -994,8 +926,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | (Ty::Infer(InferTy::FloatVar(tv)), other) | (other, Ty::Infer(InferTy::FloatVar(tv))) => { // the type var is unknown since we tried to resolve it - self.var_unification_table - .union_value(*tv, TypeVarValue::Known(other.clone())); + self.var_unification_table.union_value(*tv, TypeVarValue::Known(other.clone())); true } _ => false, @@ -1003,21 +934,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn new_type_var(&mut self) -> Ty { - Ty::Infer(InferTy::TypeVar( - self.var_unification_table.new_key(TypeVarValue::Unknown), - )) + Ty::Infer(InferTy::TypeVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) } fn new_integer_var(&mut self) -> Ty { - Ty::Infer(InferTy::IntVar( - self.var_unification_table.new_key(TypeVarValue::Unknown), - )) + Ty::Infer(InferTy::IntVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) } fn new_float_var(&mut self) -> Ty { - Ty::Infer(InferTy::FloatVar( - self.var_unification_table.new_key(TypeVarValue::Unknown), - )) + Ty::Infer(InferTy::FloatVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) } /// Replaces Ty::Unknown by a new type var, so we can maybe still infer it. @@ -1207,9 +1132,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { for subpat in subpats { let matching_field = def.and_then(|it| it.field(self.db, &subpat.name)); - let expected_ty = matching_field - .map_or(Ty::Unknown, |field| field.ty(self.db)) - .subst(&substs); + let expected_ty = + matching_field.map_or(Ty::Unknown, |field| field.ty(self.db)).subst(&substs); self.infer_pat(subpat.pat, &expected_ty); } @@ -1249,25 +1173,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let subty = self.infer_pat(*pat, expectation); Ty::Ref(subty.into(), *mutability) } - Pat::TupleStruct { - path: ref p, - args: ref subpats, - } => self.infer_tuple_struct_pat(p.as_ref(), subpats, expected), - Pat::Struct { - path: ref p, - args: ref fields, - } => self.infer_struct_pat(p.as_ref(), fields, expected), + Pat::TupleStruct { path: ref p, args: ref subpats } => { + self.infer_tuple_struct_pat(p.as_ref(), subpats, expected) + } + Pat::Struct { path: ref p, args: ref fields } => { + self.infer_struct_pat(p.as_ref(), fields, expected) + } Pat::Path(path) => { // TODO use correct resolver for the surrounding expression let resolver = self.resolver.clone(); - self.infer_path_expr(&resolver, &path) - .unwrap_or(Ty::Unknown) - } - Pat::Bind { - mode, - name: _name, - subpat, - } => { + self.infer_path_expr(&resolver, &path).unwrap_or(Ty::Unknown) + } + Pat::Bind { mode, name: _name, subpat } => { let subty = if let Some(subpat) = subpat { self.infer_pat(*subpat, expected) } else { @@ -1294,11 +1211,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let body = Arc::clone(&self.body); // avoid borrow checker problem let ty = match &body[tgt_expr] { Expr::Missing => Ty::Unknown, - Expr::If { - condition, - then_branch, - else_branch, - } => { + Expr::If { condition, then_branch, else_branch } => { // if let is desugared to match, so this is always simple if self.infer_expr(*condition, &Expectation::has_type(Ty::Bool)); let then_ty = self.infer_expr(*then_branch, expected); @@ -1325,21 +1238,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.infer_expr(*body, &Expectation::has_type(Ty::unit())); Ty::unit() } - Expr::For { - iterable, - body, - pat, - } => { + Expr::For { iterable, body, pat } => { let _iterable_ty = self.infer_expr(*iterable, &Expectation::none()); self.infer_pat(*pat, &Ty::Unknown); self.infer_expr(*body, &Expectation::has_type(Ty::unit())); Ty::unit() } - Expr::Lambda { - body, - args, - arg_types, - } => { + Expr::Lambda { body, args, arg_types } => { assert_eq!(args.len(), arg_types.len()); for (arg_pat, arg_type) in args.iter().zip(arg_types.iter()) { @@ -1362,11 +1267,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Ty::FnPtr(sig) => (sig.input.clone(), sig.output.clone()), Ty::FnDef { substs, sig, .. } => { let ret_ty = sig.output.clone().subst(&substs); - let param_tys = sig - .input - .iter() - .map(|ty| ty.clone().subst(&substs)) - .collect(); + let param_tys = + sig.input.iter().map(|ty| ty.clone().subst(&substs)).collect(); (param_tys, ret_ty) } _ => { @@ -1381,11 +1283,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } ret_ty } - Expr::MethodCall { - receiver, - args, - method_name, - } => { + Expr::MethodCall { receiver, args, method_name } => { let receiver_ty = self.infer_expr(*receiver, &Expectation::none()); let resolved = receiver_ty.clone().lookup_method(self.db, method_name); let method_ty = match resolved { @@ -1399,11 +1297,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty { Ty::FnPtr(sig) => { if !sig.input.is_empty() { - ( - sig.input[0].clone(), - sig.input[1..].to_vec(), - sig.output.clone(), - ) + (sig.input[0].clone(), sig.input[1..].to_vec(), sig.output.clone()) } else { (Ty::Unknown, Vec::new(), sig.output.clone()) } @@ -1469,11 +1363,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } Ty::Never } - Expr::StructLit { - path, - fields, - spread, - } => { + Expr::StructLit { path, fields, spread } => { let (ty, def_id) = self.resolve_variant(path.as_ref()); let substs = ty.substs().unwrap_or_else(Substs::empty); for field in fields { @@ -1497,14 +1387,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let i = name.to_string().parse::().ok(); i.and_then(|i| fields.get(i).cloned()) } - Ty::Adt { - def_id: AdtDef::Struct(s), - ref substs, - .. - } => s.field(self.db, name).map(|field| { - self.write_field_resolution(tgt_expr, field); - field.ty(self.db).subst(substs) - }), + Ty::Adt { def_id: AdtDef::Struct(s), ref substs, .. } => { + s.field(self.db, name).map(|field| { + self.write_field_resolution(tgt_expr, field); + field.ty(self.db).subst(substs) + }) + } _ => None, }) .unwrap_or(Ty::Unknown); @@ -1635,15 +1523,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ) -> Ty { for stmt in statements { match stmt { - Statement::Let { - pat, - type_ref, - initializer, - } => { - let decl_ty = type_ref - .as_ref() - .map(|tr| self.make_ty(tr)) - .unwrap_or(Ty::Unknown); + Statement::Let { pat, type_ref, initializer } => { + let decl_ty = + type_ref.as_ref().map(|tr| self.make_ty(tr)).unwrap_or(Ty::Unknown); let decl_ty = self.insert_type_vars(decl_ty); let ty = if let Some(expr) = initializer { let expr_ty = self.infer_expr(*expr, &Expectation::has_type(decl_ty)); @@ -1659,11 +1541,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } } } - let ty = if let Some(expr) = tail { - self.infer_expr(expr, expected) - } else { - Ty::unit() - }; + let ty = if let Some(expr) = tail { self.infer_expr(expr, expected) } else { Ty::unit() }; ty } @@ -1678,10 +1556,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn infer_body(&mut self) { - self.infer_expr( - self.body.body_expr(), - &Expectation::has_type(self.return_ty.clone()), - ); + self.infer_expr(self.body.body_expr(), &Expectation::has_type(self.return_ty.clone())); } } diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index a7d4517ee..da7587f01 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -46,18 +46,13 @@ impl CrateImplBlocks { ty: &Ty, ) -> impl Iterator + 'a { let fingerprint = TyFingerprint::for_impl(ty); - fingerprint - .and_then(|f| self.impls.get(&f)) - .into_iter() - .flat_map(|i| i.iter()) - .map(move |(module_id, impl_id)| { - let module = Module { - krate: self.krate, - module_id: *module_id, - }; + fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flat_map(|i| i.iter()).map( + move |(module_id, impl_id)| { + let module = Module { krate: self.krate, module_id: *module_id }; let module_impl_blocks = db.impls_in_module(module); (module, ImplBlock::from_id(module_impl_blocks, *impl_id)) - }) + }, + ) } pub fn lookup_impl_blocks_for_trait<'a>( @@ -66,18 +61,13 @@ impl CrateImplBlocks { tr: &Trait, ) -> impl Iterator + 'a { let id = tr.id; - self.impls_by_trait - .get(&id) - .into_iter() - .flat_map(|i| i.iter()) - .map(move |(module_id, impl_id)| { - let module = Module { - krate: self.krate, - module_id: *module_id, - }; + self.impls_by_trait.get(&id).into_iter().flat_map(|i| i.iter()).map( + move |(module_id, impl_id)| { + let module = Module { krate: self.krate, module_id: *module_id }; let module_impl_blocks = db.impls_in_module(module); (module, ImplBlock::from_id(module_impl_blocks, *impl_id)) - }) + }, + ) } fn collect_recursive(&mut self, db: &impl HirDatabase, module: &Module) { diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 30da8fc23..2621d1b55 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -634,11 +634,7 @@ fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); let source_file = db.parse(file_id); let mut acc = String::new(); - for fn_def in source_file - .syntax() - .descendants() - .filter_map(ast::FnDef::cast) - { + for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); let inference_result = func.infer(&db); let body_syntax_mapping = func.body_syntax_mapping(&db); @@ -725,8 +721,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { " .to_string(); - db.query_mut(ra_db::FileTextQuery) - .set(pos.file_id, Arc::new(new_text)); + db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); { let events = db.log_executed(|| { diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs index c9db4e0a5..ee8b7376a 100644 --- a/crates/ra_hir/src/type_ref.rs +++ b/crates/ra_hir/src/type_ref.rs @@ -62,11 +62,9 @@ impl TypeRef { ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), TupleType(inner) => TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()), NeverType(..) => TypeRef::Never, - PathType(inner) => inner - .path() - .and_then(Path::from_ast) - .map(TypeRef::Path) - .unwrap_or(TypeRef::Error), + PathType(inner) => { + inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error) + } PointerType(inner) => { let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); let mutability = Mutability::from_mutable(inner.is_mut()); @@ -83,10 +81,7 @@ impl TypeRef { FnPointerType(inner) => { let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref())); let mut params = if let Some(pl) = inner.param_list() { - pl.params() - .map(|p| p.type_ref()) - .map(TypeRef::from_ast_opt) - .collect() + pl.params().map(|p| p.type_ref()).map(TypeRef::from_ast_opt).collect() } else { Vec::new() }; -- cgit v1.2.3