aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model/docs.rs2
-rw-r--r--crates/ra_hir/src/expr.rs8
-rw-r--r--crates/ra_hir/src/expr/scope.rs2
-rw-r--r--crates/ra_hir/src/lang_item.rs4
-rw-r--r--crates/ra_hir/src/mock.rs2
-rw-r--r--crates/ra_hir/src/nameres/collector.rs14
-rw-r--r--crates/ra_hir/src/resolve.rs4
-rw-r--r--crates/ra_hir/src/ty/infer.rs14
-rw-r--r--crates/ra_hir/src/ty/infer/unify.rs4
9 files changed, 24 insertions, 30 deletions
diff --git a/crates/ra_hir/src/code_model/docs.rs b/crates/ra_hir/src/code_model/docs.rs
index f696307a7..007ef315d 100644
--- a/crates/ra_hir/src/code_model/docs.rs
+++ b/crates/ra_hir/src/code_model/docs.rs
@@ -74,7 +74,7 @@ pub(crate) fn documentation_query(
74 DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast), 74 DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast),
75 DocDef::StructField(it) => match it.source(db).ast { 75 DocDef::StructField(it) => match it.source(db).ast {
76 FieldSource::Named(named) => docs_from_ast(&*named), 76 FieldSource::Named(named) => docs_from_ast(&*named),
77 FieldSource::Pos(..) => return None, 77 FieldSource::Pos(..) => None,
78 }, 78 },
79 DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), 79 DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
80 DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast), 80 DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index d5b4ba6b6..3e763fef0 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -150,7 +150,7 @@ impl BodySourceMap {
150 } 150 }
151 151
152 pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::NamedField> { 152 pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::NamedField> {
153 self.field_map[&(expr, field)].clone() 153 self.field_map[&(expr, field)]
154 } 154 }
155} 155}
156 156
@@ -471,15 +471,15 @@ impl Pat {
471 match self { 471 match self {
472 Pat::Range { .. } | Pat::Lit(..) | Pat::Path(..) | Pat::Wild | Pat::Missing => {} 472 Pat::Range { .. } | Pat::Lit(..) | Pat::Path(..) | Pat::Wild | Pat::Missing => {}
473 Pat::Bind { subpat, .. } => { 473 Pat::Bind { subpat, .. } => {
474 subpat.iter().map(|pat| *pat).for_each(f); 474 subpat.iter().copied().for_each(f);
475 } 475 }
476 Pat::Tuple(args) | Pat::TupleStruct { args, .. } => { 476 Pat::Tuple(args) | Pat::TupleStruct { args, .. } => {
477 args.iter().map(|pat| *pat).for_each(f); 477 args.iter().copied().for_each(f);
478 } 478 }
479 Pat::Ref { pat, .. } => f(*pat), 479 Pat::Ref { pat, .. } => f(*pat),
480 Pat::Slice { prefix, rest, suffix } => { 480 Pat::Slice { prefix, rest, suffix } => {
481 let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter()); 481 let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter());
482 total_iter.map(|pat| *pat).for_each(f); 482 total_iter.copied().for_each(f);
483 } 483 }
484 Pat::Struct { args, .. } => { 484 Pat::Struct { args, .. } => {
485 args.iter().map(|f| f.pat).for_each(f); 485 args.iter().map(|f| f.pat).for_each(f);
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index f27cc6e8d..28fd52684 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -72,7 +72,7 @@ impl ExprScopes {
72 } 72 }
73 73
74 pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { 74 pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
75 self.scope_by_expr.get(&expr).map(|&scope| scope) 75 self.scope_by_expr.get(&expr).copied()
76 } 76 }
77 77
78 pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> { 78 pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> {
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs
index f9fe47b0f..0443d4d9a 100644
--- a/crates/ra_hir/src/lang_item.rs
+++ b/crates/ra_hir/src/lang_item.rs
@@ -122,7 +122,7 @@ impl LangItems {
122 module: Module, 122 module: Module,
123 ) { 123 ) {
124 if let Some(module_lang_items) = db.module_lang_items(module) { 124 if let Some(module_lang_items) = db.module_lang_items(module) {
125 self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), v.clone()))) 125 self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), *v)))
126 } 126 }
127 127
128 // Look for lang items in the children 128 // Look for lang items in the children
@@ -142,7 +142,7 @@ impl LangItems {
142 { 142 {
143 let node = item.source(db).ast; 143 let node = item.source(db).ast;
144 if let Some(lang_item_name) = lang_item_name(&*node) { 144 if let Some(lang_item_name) = lang_item_name(&*node) {
145 self.items.entry(lang_item_name).or_insert(constructor(item)); 145 self.items.entry(lang_item_name).or_insert_with(|| constructor(item));
146 } 146 }
147 } 147 }
148} 148}
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index b26ea58c9..ba33273b8 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -76,7 +76,7 @@ impl MockDatabase {
76 76
77 pub fn diagnostics(&self) -> String { 77 pub fn diagnostics(&self) -> String {
78 let mut buf = String::from("\n"); 78 let mut buf = String::from("\n");
79 let mut files: Vec<FileId> = self.files.values().map(|&it| it).collect(); 79 let mut files: Vec<FileId> = self.files.values().copied().collect();
80 files.sort(); 80 files.sort();
81 for file in files { 81 for file in files {
82 let module = crate::source_binder::module_from_file_id(self, file).unwrap(); 82 let module = crate::source_binder::module_from_file_id(self, file).unwrap();
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 2b07ebf4a..d66be34db 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -227,10 +227,8 @@ where
227 .items 227 .items
228 .iter() 228 .iter()
229 .map(|(name, res)| (name.clone(), Either::A(res.clone()))); 229 .map(|(name, res)| (name.clone(), Either::A(res.clone())));
230 let macros = scope 230 let macros =
231 .macros 231 scope.macros.iter().map(|(name, res)| (name.clone(), Either::B(*res)));
232 .iter()
233 .map(|(name, res)| (name.clone(), Either::B(res.clone())));
234 232
235 let all = items.chain(macros).collect::<Vec<_>>(); 233 let all = items.chain(macros).collect::<Vec<_>>();
236 self.update(module_id, Some(import_id), &all); 234 self.update(module_id, Some(import_id), &all);
@@ -243,10 +241,8 @@ where
243 .items 241 .items
244 .iter() 242 .iter()
245 .map(|(name, res)| (name.clone(), Either::A(res.clone()))); 243 .map(|(name, res)| (name.clone(), Either::A(res.clone())));
246 let macros = scope 244 let macros =
247 .macros 245 scope.macros.iter().map(|(name, res)| (name.clone(), Either::B(*res)));
248 .iter()
249 .map(|(name, res)| (name.clone(), Either::B(res.clone())));
250 246
251 let all = items.chain(macros).collect::<Vec<_>>(); 247 let all = items.chain(macros).collect::<Vec<_>>();
252 248
@@ -651,7 +647,7 @@ fn resolve_submodule(
651 candidates.push(file_dir_mod.clone()); 647 candidates.push(file_dir_mod.clone());
652 }; 648 };
653 let sr = db.source_root(source_root_id); 649 let sr = db.source_root(source_root_id);
654 let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).map(|&it| it); 650 let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).copied();
655 // FIXME: handle ambiguity 651 // FIXME: handle ambiguity
656 match points_to.next() { 652 match points_to.next() {
657 Some(file_id) => Ok(file_id), 653 Some(file_id) => Ok(file_id),
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index fc981e9b3..c8be27e54 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -272,7 +272,7 @@ impl Scope {
272 }, 272 },
273 Scope::ImplBlockScope(i) => { 273 Scope::ImplBlockScope(i) => {
274 if name.as_known_name() == Some(KnownName::SelfType) { 274 if name.as_known_name() == Some(KnownName::SelfType) {
275 PerNs::types(Resolution::SelfType(i.clone())) 275 PerNs::types(Resolution::SelfType(*i))
276 } else { 276 } else {
277 PerNs::none() 277 PerNs::none()
278 } 278 }
@@ -317,7 +317,7 @@ impl Scope {
317 } 317 }
318 } 318 }
319 Scope::ImplBlockScope(i) => { 319 Scope::ImplBlockScope(i) => {
320 f(Name::self_type(), PerNs::types(Resolution::SelfType(i.clone()))); 320 f(Name::self_type(), PerNs::types(Resolution::SelfType(*i)));
321 } 321 }
322 Scope::ExprScope(e) => { 322 Scope::ExprScope(e) => {
323 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { 323 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index a2dc92370..9228dd314 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -116,16 +116,16 @@ pub struct InferenceResult {
116 116
117impl InferenceResult { 117impl InferenceResult {
118 pub fn method_resolution(&self, expr: ExprId) -> Option<Function> { 118 pub fn method_resolution(&self, expr: ExprId) -> Option<Function> {
119 self.method_resolutions.get(&expr).map(|it| *it) 119 self.method_resolutions.get(&expr).copied()
120 } 120 }
121 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> { 121 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> {
122 self.field_resolutions.get(&expr).map(|it| *it) 122 self.field_resolutions.get(&expr).copied()
123 } 123 }
124 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> { 124 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> {
125 self.assoc_resolutions.get(&id.into()).map(|it| *it) 125 self.assoc_resolutions.get(&id.into()).copied()
126 } 126 }
127 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<ImplItem> { 127 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<ImplItem> {
128 self.assoc_resolutions.get(&id.into()).map(|it| *it) 128 self.assoc_resolutions.get(&id.into()).copied()
129 } 129 }
130 pub(crate) fn add_diagnostics( 130 pub(crate) fn add_diagnostics(
131 &self, 131 &self,
@@ -239,8 +239,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
239 &self.resolver, 239 &self.resolver,
240 type_ref, 240 type_ref,
241 ); 241 );
242 let ty = self.insert_type_vars(ty); 242 self.insert_type_vars(ty)
243 ty
244 } 243 }
245 244
246 fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool { 245 fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool {
@@ -973,8 +972,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
973 972
974 for (arg_pat, arg_type) in args.iter().zip(arg_types.iter()) { 973 for (arg_pat, arg_type) in args.iter().zip(arg_types.iter()) {
975 let expected = if let Some(type_ref) = arg_type { 974 let expected = if let Some(type_ref) = arg_type {
976 let ty = self.make_ty(type_ref); 975 self.make_ty(type_ref)
977 ty
978 } else { 976 } else {
979 Ty::Unknown 977 Ty::Unknown
980 }; 978 };
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs
index 04633bdb2..49bf5b946 100644
--- a/crates/ra_hir/src/ty/infer/unify.rs
+++ b/crates/ra_hir/src/ty/infer/unify.rs
@@ -102,7 +102,7 @@ impl<T> Canonicalized<T> {
102 ty.fold(&mut |ty| match ty { 102 ty.fold(&mut |ty| match ty {
103 Ty::Bound(idx) => { 103 Ty::Bound(idx) => {
104 if (idx as usize) < self.free_vars.len() { 104 if (idx as usize) < self.free_vars.len() {
105 Ty::Infer(self.free_vars[idx as usize].clone()) 105 Ty::Infer(self.free_vars[idx as usize])
106 } else { 106 } else {
107 Ty::Bound(idx) 107 Ty::Bound(idx)
108 } 108 }
@@ -120,7 +120,7 @@ impl<T> Canonicalized<T> {
120 let new_vars = 120 let new_vars =
121 (0..solution.num_vars).map(|_| ctx.new_type_var()).collect::<Vec<_>>().into(); 121 (0..solution.num_vars).map(|_| ctx.new_type_var()).collect::<Vec<_>>().into();
122 for (i, ty) in solution.value.into_iter().enumerate() { 122 for (i, ty) in solution.value.into_iter().enumerate() {
123 let var = self.free_vars[i].clone(); 123 let var = self.free_vars[i];
124 ctx.unify(&Ty::Infer(var), &ty.subst_bound_vars(&new_vars)); 124 ctx.unify(&Ty::Infer(var), &ty.subst_bound_vars(&new_vars));
125 } 125 }
126 } 126 }