Skip to content

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

Open
@peter-lyons-kehl

Description

@peter-lyons-kehl

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions