Lifetime bounds of associated functions

The following example:

struct A<'a, T>(&'a T);

impl<'a, T> A<'a, T>
where T: PartialOrd {
    fn lt(x: &T, a: &T) -> bool { x < a }

    fn f(x: &T) -> bool { Self::lt(x, x) }

does not compile. It looks like using Self::lt induces a dependency on the lifetime of A. If I use an “external” function:

fn lt<T: PartialOrd>(x: &T, a: &T) -> bool { x < a }

and define f as

    fn f(x: &T) -> bool { lt(x, x) }

it works. Why is there a different treatment for associated functions? (I would prefer to use these as they better point to the fact that lt will only be used locally.)

Thanks for your help.

Looks like a bug. The bound T: 'a should be implied. If I specify it explicitly it works:

- impl<'a, T> A<'a, T>
+ impl<'a, T: 'a> A<'a, T>
      T: PartialOrd,


Looks like a bug. The bound T: 'a should be implied.

Ah, that would explain that I have other associated functions taking &T which did not require the T: 'a bound.

I think it is:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.