Skip to content

type parameter bounds can't use already defined lifetimes #5715

Closed
@doy

Description

@doy
trait Base<'self,A> {
    fn foo(&self, blk: &fn(v: &'self A));
}

struct Bar<A> {
    a: A,
}

impl<'self,A> Base<'self,A> for Bar<A> {
    fn foo(&self, blk: &fn(v: &'self A)) {
        blk(&self.a);
    }
}

fn bar<'r,A,IA:Base<'r,A>>(b: &'r Bar<A>, blk: &fn(&'r A)) {
    b.foo(blk);
}
test3.rs:15:22: 15:23 error: Illegal lifetime 'r: only 'static is allowed here
test3.rs:15 fn bar<'r,A,IA:Base<'r,A>>(b: &'r Bar<A>, blk: &fn(&'r A)) {
                                  ^
error: aborting due to previous error

Seems like this should work, since without the lifetimes involved, fn bar<A,IA:Base<A>>(...) works fine - the earlier type declaration of A makes it possible to use A as a parameter in the type bound.

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