Skip to content

Autoharness: do not synthesize Arbitrary for structs with reference fields - #4694

Open
tautschnig wants to merge 1 commit into
model-checking:mainfrom
tautschnig:fix-ref-field-derive
Open

Autoharness: do not synthesize Arbitrary for structs with reference fields#4694
tautschnig wants to merge 1 commit into
model-checking:mainfrom
tautschnig:fix-ref-field-derive

Conversation

@tautschnig

Copy link
Copy Markdown
Member

Description

can_derive_arbitrary recursed into reference field types, so a struct with a &'static reference field (reference fields with lifetime parameters were already rejected via the ADT's generic arguments) was deemed derivable. The compiler-synthesized any() then created the referent's storage inside its own body and returned a dangling reference, so the generated harness failed spuriously with "dereference failure: dead object" — a false alarm the user can do nothing about.

Reject reference fields in the derivability check; such functions are now skipped with the usual "Missing Arbitrary implementation" reason. Top-level reference arguments are unaffected: for those the generated harness itself owns the referent's storage, which outlives the call.

Found while implementing #4691 (the storage-lifetime asymmetry between argument position and field position is exactly what that PR documents for slices).

Testing

New script-based test cargo_autoharness_ref_field: asserts the struct-with-reference-field function is skipped (previously: spurious dead-object failure) while a plain &u32 argument remains supported. Formatting and the compiler unit tests pass.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

…ields

can_derive_arbitrary recursed into reference field types (reachable for
'static references; reference fields with a lifetime parameter were already
rejected via the ADT's generic arguments), so a struct like

    struct HasStaticRef { r: &'static u32 }

was deemed derivable. The synthesized any() then created the referent's
storage inside its own body and returned a dangling reference, producing
spurious 'dereference failure: dead object' verification failures in the
generated harness.

Reject reference fields in the derivability check. Note the asymmetry with
top-level argument references, which remain supported: for those, the
generated harness itself owns the referent's storage, which therefore
outlives the call.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig
tautschnig requested a review from a team as a code owner July 29, 2026 09:43
Copilot AI review requested due to automatic review settings July 29, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Jul 29, 2026
@feliperodri feliperodri added the Z-Autoharness Issue related to autoharness subcommand label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-Autoharness Issue related to autoharness subcommand Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants