Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameter type T may not live long enough - when the counted struct is generic #13

Open
peter-lyons-kehl opened this issue May 27, 2022 · 1 comment

Comments

@peter-lyons-kehl
Copy link

peter-lyons-kehl commented May 27, 2022

Somewhere between v. 2 and 3.0.1 countme changed so the following

#[derive(PartialEq)]
pub struct SegmentedBuf<T> {
    _c: countme::Count<Self>,
    pub(crate) bufs: SmallVec<[T; 4]>,
    pos: usize,
    offset: usize,
    read_pos: usize,
    read_offset: usize,
    segment_size: usize,
}

fails with

error[E0310]: the parameter type `T` may not live long enough
   --> src/segmented_buffer.rs:104:9
    |
103 | pub struct SegmentedBuf<T> {
    |                         - help: consider adding an explicit lifetime bound...: `T: 'static`
104 |     _c: countme::Count<Self>,
    |         ^^^^^^^^^^^^^^^^^^^^ ...so that the type `SegmentedBuf<T>` will meet its required lifetime bounds...
    |
note: ...that is required by this bound
   --> /home/pkehl/.cargo/registry/src/github.com-1ecc6299db9ec823/countme-3.0.1/src/lib.rs:71:21
    |
71  | pub struct Count<T: 'static> {

FYI the error comes from https://github.com/logdna/logdna-rust/blob/main/src/segmented_buffer.rs#L103= (after updating the version in Cargo.toml). I'm not familiar with logdna-rust yet, but I'll try to narrow this issue down.
(The same error happens with Rust 1.61.0 and 1.63.0-nightly.)

@peter-lyons-kehl
Copy link
Author

Ahah, as per "it means it doesn't/can't contain any non-static references. Meaning it can only have owned types and/or 'static references." (from https://www.reddit.com/r/rust/comments/o9w6rl/comment/h3dszio/?utm_source=reddit&utm_medium=web2x&context=3).

May I suggest a note about that in README.md, please. Especially so because this use of 'static is infrequent, and cargoc's message is not helpful either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant