aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-18 13:18:25 +0100
committerGitHub <[email protected]>2021-06-18 13:18:25 +0100
commit7eb843b218b5e10b39a5171f5b9689ec6c2d71c3 (patch)
tree64e3deddd104187ff8aa9b5dd9c64819a5378f1d
parent86c3c42d8ed060b66df95f33c20c1f5778c38ee0 (diff)
parent6b1f0057f2dbe48f1c59c8938957daf158e30823 (diff)
Merge #9325
9325: Minor: clippy perf fixes r=matklad a=lnicola Co-authored-by: LaurenČ›iu Nicola <[email protected]>
-rw-r--r--crates/hir_def/src/resolver.rs3
-rw-r--r--crates/hir_expand/src/builtin_macro.rs4
-rw-r--r--crates/hir_ty/src/diagnostics/expr.rs2
-rw-r--r--crates/hir_ty/src/infer/expr.rs10
-rw-r--r--crates/hir_ty/src/infer/pat.rs2
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/ide/src/goto_type_definition.rs2
-rw-r--r--crates/ide_assists/src/handlers/remove_dbg.rs4
-rw-r--r--crates/proc_macro_api/src/version.rs10
-rw-r--r--crates/project_model/src/build_data.rs4
-rw-r--r--crates/test_utils/src/fixture.rs2
11 files changed, 23 insertions, 22 deletions
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index 47e56259f..49c573087 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -640,8 +640,7 @@ pub trait HasResolver: Copy {
640impl HasResolver for ModuleId { 640impl HasResolver for ModuleId {
641 fn resolver(self, db: &dyn DefDatabase) -> Resolver { 641 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
642 let mut def_map = self.def_map(db); 642 let mut def_map = self.def_map(db);
643 let mut modules = Vec::new(); 643 let mut modules = vec![(def_map.clone(), self.local_id)];
644 modules.push((def_map.clone(), self.local_id));
645 while let Some(parent) = def_map.parent() { 644 while let Some(parent) = def_map.parent() {
646 def_map = parent.def_map(db); 645 def_map = parent.def_map(db);
647 modules.push((def_map.clone(), parent.local_id)); 646 modules.push((def_map.clone(), parent.local_id));
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index f24d1d919..4c83a2efe 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -202,7 +202,7 @@ fn assert_expand(
202 202
203 let arg_tts = args.into_iter().flat_map(|arg| { 203 let arg_tts = args.into_iter().flat_map(|arg| {
204 quote! { &(#arg), } 204 quote! { &(#arg), }
205 }.token_trees).collect::<Vec<_>>(); 205 }.token_trees);
206 206
207 let expanded = quote! { 207 let expanded = quote! {
208 { { (##arg_tts); } } 208 { { (##arg_tts); } }
@@ -254,7 +254,7 @@ fn format_args_expand(
254 let _format_string = args.remove(0); 254 let _format_string = args.remove(0);
255 let arg_tts = args.into_iter().flat_map(|arg| { 255 let arg_tts = args.into_iter().flat_map(|arg| {
256 quote! { std::fmt::ArgumentV1::new(&(#arg), std::fmt::Display::fmt), } 256 quote! { std::fmt::ArgumentV1::new(&(#arg), std::fmt::Display::fmt), }
257 }.token_trees).collect::<Vec<_>>(); 257 }.token_trees);
258 let expanded = quote! { 258 let expanded = quote! {
259 std::fmt::Arguments::new_v1(&[], &[##arg_tts]) 259 std::fmt::Arguments::new_v1(&[], &[##arg_tts])
260 }; 260 };
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs
index b809b96a0..dc8f20138 100644
--- a/crates/hir_ty/src/diagnostics/expr.rs
+++ b/crates/hir_ty/src/diagnostics/expr.rs
@@ -56,7 +56,7 @@ impl BodyValidationDiagnostic {
56 pub fn collect(db: &dyn HirDatabase, owner: DefWithBodyId) -> Vec<BodyValidationDiagnostic> { 56 pub fn collect(db: &dyn HirDatabase, owner: DefWithBodyId) -> Vec<BodyValidationDiagnostic> {
57 let _p = profile::span("BodyValidationDiagnostic::collect"); 57 let _p = profile::span("BodyValidationDiagnostic::collect");
58 let infer = db.infer(owner); 58 let infer = db.infer(owner);
59 let mut validator = ExprValidator::new(owner, infer.clone()); 59 let mut validator = ExprValidator::new(owner, infer);
60 validator.validate_body(db); 60 validator.validate_body(db);
61 validator.diagnostics 61 validator.diagnostics
62 } 62 }
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 4e4f6e5a4..c3a5b979f 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -367,7 +367,7 @@ impl<'a> InferenceContext<'a> {
367 Expr::Path(p) => { 367 Expr::Path(p) => {
368 // FIXME this could be more efficient... 368 // FIXME this could be more efficient...
369 let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr); 369 let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
370 self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(self.err_ty()) 370 self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or_else(|| self.err_ty())
371 } 371 }
372 Expr::Continue { .. } => TyKind::Never.intern(&Interner), 372 Expr::Continue { .. } => TyKind::Never.intern(&Interner),
373 Expr::Break { expr, label } => { 373 Expr::Break { expr, label } => {
@@ -511,7 +511,7 @@ impl<'a> InferenceContext<'a> {
511 _ => None, 511 _ => None,
512 } 512 }
513 }) 513 })
514 .unwrap_or(self.err_ty()); 514 .unwrap_or_else(|| self.err_ty());
515 let ty = self.insert_type_vars(ty); 515 let ty = self.insert_type_vars(ty);
516 self.normalize_associated_types_in(ty) 516 self.normalize_associated_types_in(ty)
517 } 517 }
@@ -818,8 +818,10 @@ impl<'a> InferenceContext<'a> {
818 for stmt in statements { 818 for stmt in statements {
819 match stmt { 819 match stmt {
820 Statement::Let { pat, type_ref, initializer } => { 820 Statement::Let { pat, type_ref, initializer } => {
821 let decl_ty = 821 let decl_ty = type_ref
822 type_ref.as_ref().map(|tr| self.make_ty(tr)).unwrap_or(self.err_ty()); 822 .as_ref()
823 .map(|tr| self.make_ty(tr))
824 .unwrap_or_else(|| self.err_ty());
823 825
824 // Always use the declared type when specified 826 // Always use the declared type when specified
825 let mut ty = decl_ty.clone(); 827 let mut ty = decl_ty.clone();
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index 58cb23e9d..c79ed91ea 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -192,7 +192,7 @@ impl<'a> InferenceContext<'a> {
192 Pat::Path(path) => { 192 Pat::Path(path) => {
193 // FIXME use correct resolver for the surrounding expression 193 // FIXME use correct resolver for the surrounding expression
194 let resolver = self.resolver.clone(); 194 let resolver = self.resolver.clone();
195 self.infer_path(&resolver, path, pat.into()).unwrap_or(self.err_ty()) 195 self.infer_path(&resolver, path, pat.into()).unwrap_or_else(|| self.err_ty())
196 } 196 }
197 Pat::Bind { mode, name: _, subpat } => { 197 Pat::Bind { mode, name: _, subpat } => {
198 let mode = if mode == &BindingAnnotation::Unannotated { 198 let mode = if mode == &BindingAnnotation::Unannotated {
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 817a65c20..ea03b6a6c 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -562,7 +562,7 @@ impl<'a> TyLoweringContext<'a> {
562 }, 562 },
563 ); 563 );
564 564
565 ty.unwrap_or(TyKind::Error.intern(&Interner)) 565 ty.unwrap_or_else(|| TyKind::Error.intern(&Interner))
566 } else { 566 } else {
567 TyKind::Error.intern(&Interner) 567 TyKind::Error.intern(&Interner)
568 } 568 }
diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs
index ca3c02bf6..43cffefe5 100644
--- a/crates/ide/src/goto_type_definition.rs
+++ b/crates/ide/src/goto_type_definition.rs
@@ -25,7 +25,7 @@ pub(crate) fn goto_type_definition(
25 let token: SyntaxToken = pick_best(file.syntax().token_at_offset(position.offset))?; 25 let token: SyntaxToken = pick_best(file.syntax().token_at_offset(position.offset))?;
26 let token: SyntaxToken = sema.descend_into_macros(token); 26 let token: SyntaxToken = sema.descend_into_macros(token);
27 27
28 let (ty, node) = sema.token_ancestors_with_macros(token.clone()).find_map(|node| { 28 let (ty, node) = sema.token_ancestors_with_macros(token).find_map(|node| {
29 let ty = match_ast! { 29 let ty = match_ast! {
30 match node { 30 match node {
31 ast::Expr(it) => sema.type_of_expr(&it)?, 31 ast::Expr(it) => sema.type_of_expr(&it)?,
diff --git a/crates/ide_assists/src/handlers/remove_dbg.rs b/crates/ide_assists/src/handlers/remove_dbg.rs
index b20fe992d..5866d8974 100644
--- a/crates/ide_assists/src/handlers/remove_dbg.rs
+++ b/crates/ide_assists/src/handlers/remove_dbg.rs
@@ -35,14 +35,14 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
35 .prev_sibling_or_token() 35 .prev_sibling_or_token()
36 .and_then(whitespace_start) 36 .and_then(whitespace_start)
37 .map(|start| TextRange::new(start, macro_call.syntax().text_range().end())) 37 .map(|start| TextRange::new(start, macro_call.syntax().text_range().end()))
38 .unwrap_or(macro_call.syntax().text_range()) 38 .unwrap_or_else(|| macro_call.syntax().text_range())
39 }, 39 },
40 ast::ExprStmt(it) => { 40 ast::ExprStmt(it) => {
41 let start = it 41 let start = it
42 .syntax() 42 .syntax()
43 .prev_sibling_or_token() 43 .prev_sibling_or_token()
44 .and_then(whitespace_start) 44 .and_then(whitespace_start)
45 .unwrap_or(it.syntax().text_range().start()); 45 .unwrap_or_else(|| it.syntax().text_range().start());
46 let end = it.syntax().text_range().end(); 46 let end = it.syntax().text_range().end();
47 47
48 TextRange::new(start, end) 48 TextRange::new(start, end)
diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs
index 28a4ac086..434decc7e 100644
--- a/crates/proc_macro_api/src/version.rs
+++ b/crates/proc_macro_api/src/version.rs
@@ -28,23 +28,23 @@ pub fn read_dylib_info(dylib_path: &Path) -> io::Result<RustCInfo> {
28 28
29 let ver_str = read_version(dylib_path)?; 29 let ver_str = read_version(dylib_path)?;
30 let mut items = ver_str.split_whitespace(); 30 let mut items = ver_str.split_whitespace();
31 let tag = items.next().ok_or(err!("version format error"))?; 31 let tag = items.next().ok_or_else(|| err!("version format error"))?;
32 if tag != "rustc" { 32 if tag != "rustc" {
33 return Err(err!("version format error (No rustc tag)")); 33 return Err(err!("version format error (No rustc tag)"));
34 } 34 }
35 35
36 let version_part = items.next().ok_or(err!("no version string"))?; 36 let version_part = items.next().ok_or_else(|| err!("no version string"))?;
37 let mut version_parts = version_part.split('-'); 37 let mut version_parts = version_part.split('-');
38 let version = version_parts.next().ok_or(err!("no version"))?; 38 let version = version_parts.next().ok_or_else(|| err!("no version"))?;
39 let channel = version_parts.next().unwrap_or_default().to_string(); 39 let channel = version_parts.next().unwrap_or_default().to_string();
40 40
41 let commit = items.next().ok_or(err!("no commit info"))?; 41 let commit = items.next().ok_or_else(|| err!("no commit info"))?;
42 // remove ( 42 // remove (
43 if commit.len() == 0 { 43 if commit.len() == 0 {
44 return Err(err!("commit format error")); 44 return Err(err!("commit format error"));
45 } 45 }
46 let commit = commit[1..].to_string(); 46 let commit = commit[1..].to_string();
47 let date = items.next().ok_or(err!("no date info"))?; 47 let date = items.next().ok_or_else(|| err!("no date info"))?;
48 // remove ) 48 // remove )
49 if date.len() == 0 { 49 if date.len() == 0 {
50 return Err(err!("date format error")); 50 return Err(err!("date format error"));
diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs
index 53cb4bae7..45bbb08dc 100644
--- a/crates/project_model/src/build_data.rs
+++ b/crates/project_model/src/build_data.rs
@@ -187,7 +187,7 @@ impl WorkspaceBuildData {
187 let mut deserializer = serde_json::Deserializer::from_str(line); 187 let mut deserializer = serde_json::Deserializer::from_str(line);
188 deserializer.disable_recursion_limit(); 188 deserializer.disable_recursion_limit();
189 let message = Message::deserialize(&mut deserializer) 189 let message = Message::deserialize(&mut deserializer)
190 .unwrap_or(Message::TextLine(line.to_string())); 190 .unwrap_or_else(|_| Message::TextLine(line.to_string()));
191 191
192 match message { 192 match message {
193 Message::BuildScriptExecuted(BuildScript { 193 Message::BuildScriptExecuted(BuildScript {
@@ -229,7 +229,7 @@ impl WorkspaceBuildData {
229 Message::CompilerArtifact(message) => { 229 Message::CompilerArtifact(message) => {
230 progress(format!("metadata {}", message.target.name)); 230 progress(format!("metadata {}", message.target.name));
231 231
232 if message.target.kind.contains(&"proc-macro".to_string()) { 232 if message.target.kind.iter().any(|k| k == "proc-macro") {
233 let package_id = message.package_id; 233 let package_id = message.package_id;
234 // Skip rmeta file 234 // Skip rmeta file
235 if let Some(filename) = 235 if let Some(filename) =
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 8d8f3b560..44656267f 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -131,7 +131,7 @@ impl Fixture {
131 res.push(meta) 131 res.push(meta)
132 } else { 132 } else {
133 if line.starts_with("// ") 133 if line.starts_with("// ")
134 && line.contains(":") 134 && line.contains(':')
135 && !line.contains("::") 135 && !line.contains("::")
136 && line.chars().all(|it| !it.is_uppercase()) 136 && line.chars().all(|it| !it.is_uppercase())
137 { 137 {