rust-fuzz / rust-fuzz/arbitrary
Arbitrary derive fails with lifetimes in some cases
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 880
- Forks
- 93
- PR merge metrics
- No merged PRs in 30d
Description
Hello! Bear with me as I am new to Arbitrary.
I have this type from juniper:
pub struct Arguments<'a, S> {
pub items: Vec<(Spanning<&'a str>, Spanning<InputValue<S>>)>,
}
Spanning and InputValue successfully derive(arbitrary::Arbitrary)). When I try to derive on Arguments, I get the following error:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> juniper/src/ast.rs:59:42
|
59 | #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
| ^^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
--> juniper/src/ast.rs:60:22
|
60 | pub struct Arguments<'a, S> {
| ^^
note: ...so that the types are compatible
--> juniper/src/ast.rs:59:42
|
59 | #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
| ^^^^^^^^^^^^^^^^^^^^
= note: expected `<&'a str as Arbitrary<'_>>`
found `<&str as Arbitrary<'_>>`
note: but, the lifetime must be valid for the lifetime `'arbitrary` as defined here...
--> juniper/src/ast.rs:59:42
|
59 | #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
| ^^^^^^^^^^^^^^^^^^^^
note: ...so that the types are compatible
Manually implenting it works:
impl<'a, S> arbitrary::Arbitrary<'a> for Arguments<'a, S>
where
S: arbitrary::Arbitrary<'a>,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let items: Vec<(Spanning<&'a str>, Spanning<InputValue<S>>)> = u.arbitrary()?;
Ok(Self { items })
}
}
Even though I am unblocked, I figured I'd file as one would expect the derive to work in this case.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the derive failure using the Arguments definition from juniper/src/ast.rs and inspect the Arbitrary derive implementation for lifetime handling. Add coverage for Arguments<'a, S> and confirm the generated implementation compiles like the manual implementation shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100