nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: xd009642/tarpaulin
Pull request #1531 (2024-05-01 18:15:53)

Implement smarter generic detection
<!--- When contributing to tarpaulin all contributions should branch off the -->
<!--- develop branch as master is only used for releases. --> 

<!--- Check CONTRIBUTING.md for more information-->

<!--- Please describe the changes in the PR and them motivation below -->



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0b3c454..046b6d2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ file.
 - Fixed build for x86
 - Add summary coverage, covered and coverable to json report #1415
 - Pass RUSTFLAGS to the binary under test for any project bins compiled during test
+- Force coverage of generic functions/methods using `impl Trait` args
 
 ## [0.28.0] 2024-04-13
 ### Changed
diff --git a/src/source_analysis/items.rs b/src/source_analysis/items.rs
index f9f715c..4d8fe3a 100644
--- a/src/source_analysis/items.rs
+++ b/src/source_analysis/items.rs
@@ -98,7 +98,7 @@ impl SourceAnalysis {
         let mut ignored_attr = false;
         let mut is_inline = false;
         let mut ignore_span = false;
-        let is_generic = !func.sig.generics.params.is_empty();
+        let is_generic = is_sig_generic(&func.sig);
         for attr in &func.attrs {
             if let Ok(x) = attr.parse_meta() {
                 let id = x.path();
@@ -223,3 +223,18 @@ impl SourceAnalysis {
         }
     }
 }
+
+fn has_generic_arg<'a>(args: impl Iterator<Item = &'a FnArg>) -> bool {
+    for arg in args {
+        if let FnArg::Typed(pat) = arg {
+            if matches!(*pat.ty, Type::ImplTrait(_)) {
+                return true;
+            }
+        }
+    }
+    false
+}
+
+fn is_sig_generic(sig: &Signature) -> bool {
+    !sig.generics.params.is_empty() || has_generic_arg(sig.inputs.iter())
+}


Test patch:
diff --git a/src/source_analysis/tests.rs b/src/source_analysis/tests.rs
index 9b93015..dd240bd 100644
--- a/src/source_analysis/tests.rs
+++ b/src/source_analysis/tests.rs
@@ -787,6 +787,25 @@ fn cover_default_trait_methods() {
     assert!(lines.cover.contains(&3));
 }
 
+#[test]
+fn cover_impl_trait_generic_fns() {
+    let config = Config::default();
+    let ctx = Context {
+        config: &config,
+        file_contents: "fn bloop(t: impl std::io::Read) -> usize {
+                t.bytes().count()
+            }",
+        file: Path::new(""),
+        ignore_mods: RefCell::new(HashSet::new()),
+    };
+    let parser = parse_file(ctx.file_contents).unwrap();
+    let mut analysis = SourceAnalysis::new();
+    analysis.process_items(&parser.items, &ctx);
+    let lines = analysis.get_line_analysis(ctx.file.to_path_buf());
+    assert!(lines.cover.contains(&1));
+    assert!(lines.cover.contains(&2));
+}
+
 #[test]
 fn filter_method_args() {
     let config = Config::default();