Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
canndrew opened this issue Jun 23, 2016 · 2 comments · Fixed by #67059
Closed

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

canndrew opened this issue Jun 23, 2016 · 2 comments · Fixed by #67059
Labels
A-destructors Area: Destructors (`Drop`, …) C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@canndrew
Copy link
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.

@pnkfelix pnkfelix added the A-destructors Area: Destructors (`Drop`, …) label Jun 23, 2016
@durka
Copy link
Contributor

durka commented Jun 27, 2016

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

@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 25, 2017
@Osspial
Copy link

Osspial commented Mar 17, 2019

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.

TommasoBianchi added a commit to TommasoBianchi/rust that referenced this issue Dec 5, 2019
Centril added a commit to Centril/rust that referenced this issue Dec 21, 2019
…felix

Fix too restrictive checks on Drop impls

Fixes rust-lang#34426. Fixes rust-lang#58311.

This PR completes and extends rust-lang#59497 (which has been inactive for a while now).
The problem generating both issues was that when checking that the `Predicate`s of the `Drop` impl are exactly the same as the ones of the struct definition, the check was essentially performed by a simple `==` operator, which was not handling correctly HRTBs and involved `Fn` types.

The implemented solution relies on the `relate` machinery to more correctly equate `Predicate`s, and on `anonymize_late_bound_regions` to handle HRTB in a more general way. As the `Relate` trait currently is implemented only for `TraitPredicate` and `ProjectionPredicate` (and as they were the ones generating problems), `relate` is used only for them while for other `Predicate`s the equality check is kept. I'm currently considering whether it would make sense to implement the `Relate` trait also for all other `Predicate`s to render the proposed solution more general.
@bors bors closed this as completed in 1113eb5 Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-destructors Area: Destructors (`Drop`, …) C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
5 participants