Increase scope nesting to borrow
authorDale Wijnand <dale.wijnand@gmail.com>
Mon, 16 Apr 2018 22:17:57 +0000 (00:17 +0200)
committerDale Wijnand <dale.wijnand@gmail.com>
Fri, 20 Apr 2018 18:45:59 +0000 (19:45 +0100)
src/cargo/util/toml/targets.rs

index 896278c49c22a06f7270436baa04647643f58751..168245ec16865c5b67ee805a9733efb6cf83cb2b 100644 (file)
@@ -317,31 +317,37 @@ fn clean_benches(
     warnings: &mut Vec<String>,
     errors: &mut Vec<String>,
 ) -> CargoResult<Vec<Target>> {
-    let mut legacy_bench_path = |bench: &TomlTarget| {
-        let legacy_path = package_root.join("src").join("bench.rs");
-        if !(bench.name() == "bench" && legacy_path.exists()) {
-            return None;
-        }
-        warnings.push(format!(
-            "path `{}` was erroneously implicitly accepted for benchmark `{}`,\n\
-             please set bench.path in Cargo.toml",
-            legacy_path.display(),
-            bench.name()
-        ));
-        Some(legacy_path)
-    };
+    let mut legacy_warnings = vec![];
+
+    let targets = {
+        let mut legacy_bench_path = |bench: &TomlTarget| {
+            let legacy_path = package_root.join("src").join("bench.rs");
+            if !(bench.name() == "bench" && legacy_path.exists()) {
+                return None;
+            }
+            legacy_warnings.push(format!(
+                "path `{}` was erroneously implicitly accepted for benchmark `{}`,\n\
+                 please set bench.path in Cargo.toml",
+                legacy_path.display(),
+                bench.name()
+            ));
+            Some(legacy_path)
+        };
 
-    let inferred = infer_from_directory(&package_root.join("benches"));
+        let inferred = infer_from_directory(&package_root.join("benches"));
+
+        clean_targets_with_legacy_path(
+            "benchmark",
+            "bench",
+            toml_benches,
+            &inferred,
+            package_root,
+            errors,
+            &mut legacy_bench_path,
+        )?
+    };
 
-    let targets = clean_targets_with_legacy_path(
-        "benchmark",
-        "bench",
-        toml_benches,
-        &inferred,
-        package_root,
-        errors,
-        &mut legacy_bench_path,
-    )?;
+    warnings.append(&mut legacy_warnings);
 
     let mut result = Vec::new();
     for (path, toml) in targets {