Skip to content

Trait implementation accepts wrong lifetime in method signature with associated type #22077

Closed
@tomjakubowski

Description

@tomjakubowski

(Sorry for the bad title)

trait Fun {
    type Output;
    fn call<'x>(&'x self) -> Self::Output;
}

struct Holder { x: String }

impl<'a> Fun for Holder {
    type Output = &'a str;
    fn call<'b>(&'b self) -> &'b str {
        &self.x[]
    }
}

This compiles even though the trait's definition should require call's signature in the impl to be fn call<'b>(&'b self) -> &'a str.

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-lifetimesArea: Lifetimes / regions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions