Skip to content

Spurious error "The requirement ... is added only by the Drop impl" #34426

@canndrew

Description

@canndrew
Contributor

It seems like it's not possible to implement Drop for types that have higher ranked trait bounds on their type arguments.

trait WithLifetime<'a> {
}

struct Foo<A: for<'a> WithLifetime<'a>> {
    a: A,
}

impl<A: for<'a> WithLifetime<'a>> Drop for Foo<A> {
    fn drop(&mut self) {}
}

This gives the error "The requirement for<'a> A: WithLifetime<'a> is added only by the Drop impl" which is obviously untrue. Removing that bound from the Drop impl gives the error "the trait bound for<'a> A: WithLifetime<'a> is not satisfied" as it should.

Activity

durka

durka commented on Jun 27, 2016

@durka
Contributor

As an aside, the error message rephrased the bound to for<'a> A: WithLifetime<'a> which is illegal syntax.

Osspial

Osspial commented on Mar 17, 2019

@Osspial

I'd be willing to try and tackle this issue! Is there anyone that would be able to do any mentoring? The attempts I've made to figure out the proper way of fixing this have resulted in me getting lost in the compiler's code, and I'm running out of stamina going at it alone.

added 2 commits that reference this issue on Dec 21, 2019
abb4234
1113eb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @durka@pnkfelix@Mark-Simulacrum@canndrew@Osspial

      Issue actions

        Spurious error "The requirement ... is added only by the Drop impl" · Issue #34426 · rust-lang/rust