Skip to content

Commit 7908ad7

Browse files
Copilotsourcefrog
andcommitted
Include struct type in field deletion mutant names
- Updated visit_expr_struct to capture and store struct type name - Modified mutant display to show "delete field X from struct Y expression" - Format now includes both struct type and function name (if any) - Example: "delete field name from struct Cat expression in make_cat" Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
1 parent 2525689 commit 7908ad7

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/mutant.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,23 @@ impl Mutant {
180180
);
181181
}
182182
Genre::StructField => {
183-
v.push(s("delete field "));
184-
v.push(
185-
s(self
186-
.short_replaced
187-
.as_ref()
188-
.expect("short_replaced should be set on StructField"))
189-
.yellow(),
190-
);
191-
v.push(s(" from struct expression"));
183+
let field_and_type = self
184+
.short_replaced
185+
.as_ref()
186+
.expect("short_replaced should be set on StructField");
187+
// Parse "field_name::StructType" format
188+
if let Some((field_name, struct_type)) = field_and_type.split_once("::") {
189+
v.push(s("delete field "));
190+
v.push(s(field_name).yellow());
191+
v.push(s(" from struct "));
192+
v.push(s(struct_type).yellow());
193+
v.push(s(" expression"));
194+
} else {
195+
// Fallback for older format (shouldn't happen)
196+
v.push(s("delete field "));
197+
v.push(s(field_and_type).yellow());
198+
v.push(s(" from struct expression"));
199+
}
192200
}
193201
_ => {
194202
if self.replacement.is_empty() {

src/visit.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,13 +697,17 @@ impl<'ast> Visit<'ast> for DiscoveryVisitor<'_> {
697697

698698
// Check if this struct has a base (default) expression like `..Default::default()`
699699
if let Some(_rest) = &i.rest {
700+
// Get the struct type name
701+
let struct_type = i.path.to_pretty_string();
702+
700703
// Generate a mutant for each field by deleting it
701704
// We need to include the trailing comma in the span
702705
for pair in i.fields.pairs() {
703706
let field = pair.value();
704707
if let syn::Member::Named(field_name) = &field.member {
705708
let field_name_str = field_name.to_string();
706-
let short_replaced = Some(field_name_str);
709+
// Store both field name and struct type, separated by "::"
710+
let short_replaced = Some(format!("{}::{}", field_name_str, struct_type));
707711
// Span includes the field and its trailing comma (if present)
708712
let span = if let Some(comma) = pair.punct() {
709713
// Include the comma in the span
@@ -1470,8 +1474,8 @@ mod test {
14701474
assert_eq!(
14711475
mutants,
14721476
&[
1473-
"delete field name from struct expression",
1474-
"delete field coat from struct expression"
1477+
"delete field name from struct Cat expression",
1478+
"delete field coat from struct Cat expression"
14751479
]
14761480
);
14771481
}
@@ -1505,8 +1509,8 @@ mod test {
15051509
assert_eq!(
15061510
mutants,
15071511
&[
1508-
"delete field timeout from struct expression",
1509-
"delete field retries from struct expression"
1512+
"delete field timeout from struct Config expression",
1513+
"delete field retries from struct Config expression"
15101514
]
15111515
);
15121516
}
@@ -1522,7 +1526,7 @@ mod test {
15221526
"#,
15231527
);
15241528
// Should work with a single field too
1525-
assert_eq!(mutants, &["delete field x from struct expression"]);
1529+
assert_eq!(mutants, &["delete field x from struct Point expression"]);
15261530
}
15271531

15281532
#[test]
@@ -1541,8 +1545,8 @@ mod test {
15411545
assert_eq!(
15421546
mutants,
15431547
&[
1544-
"delete field enabled from struct expression",
1545-
"delete field count from struct expression",
1548+
"delete field enabled from struct Settings expression",
1549+
"delete field count from struct Settings expression",
15461550
"replace + with -",
15471551
"replace + with *"
15481552
]

0 commit comments

Comments
 (0)