You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, the following code (using version 1.0.1) fails to compile.
use std::borrow::Cow;#[derive(arbitrary::Arbitrary)]pubstructWithACow{cow:Cow<'static,str>,}fnmain(){println!("Hello, world!");}
With the error message
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> src/main.rs:3:10
|
3 | #[derive(arbitrary::Arbitrary)]
| ^^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'arbitrary` as defined on the impl at 3:10...
--> src/main.rs:3:10
|
3 | #[derive(arbitrary::Arbitrary)]
| ^^^^^^^^^^^^^^^^^^^^
note: ...so that the expression is assignable
--> src/main.rs:3:10
|
3 | #[derive(arbitrary::Arbitrary)]
| ^^^^^^^^^^^^^^^^^^^^
= note: expected `&mut Unstructured<'_>`
found `&mut Unstructured<'arbitrary>`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the expression is assignable
--> src/main.rs:3:10
|
3 | #[derive(arbitrary::Arbitrary)]
| ^^^^^^^^^^^^^^^^^^^^
= note: expected `Cow<'static, _>`
found `Cow<'_, _>`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
But something like this does compile:
use std::borrow::Cow;use arbitrary::Arbitrary;pubstructWithACow{cow:Cow<'static,str>,}impl<'a>Arbitrary<'a>forWithACow{fnarbitrary(u:&mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self>{Ok(WithACow{cow:Arbitrary::arbitrary(u).map(Cow::Owned)?,})}}fnmain(){println!("Hello, world!");}
The text was updated successfully, but these errors were encountered:
works, because you're always constructing an owned data.
To generate the Borrowed variant, Arbitrary would need data with 'static lifetime, but there is no place where it can get from. So the error makes sense, it's the case where one would need to construct Cow manually.
Once this #129 gets merged, you'll be able to implement custom arbitrary for single fields, which may help to workaround this problem.
For example, the following code (using version
1.0.1
) fails to compile.With the error message
But something like this does compile:
The text was updated successfully, but these errors were encountered: