Skip to content

Inherent static methods can be called with a non-well-formed Self-type #28848

@arielb1

Description

@arielb1

UPDATE: This has been fixed, but a test is still needed. See the comment below for instructions.


STR

struct Foo<'a, 'b: 'a>(&'a &'b ());

impl<'a, 'b> Foo<'a, 'b> {
    fn xmute(a: &'b ()) -> &'a () {
        unreachable!()
    }
}

pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
    Foo::<'a, 'b>::xmute(u)
}

fn main() {}

Here a static method on Foo is called with unrelated lifetimes 'a and 'b, potentially violating the 'b: 'a bound. As Foo::xmute is not allowed to assume Foo is well-formed, this does not cause a soundness issue, but is still a potential back-compat hazard.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions