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

Cannot impl Drop for a generic type with a Higher-Rank Trait Bound #27863

Closed
dwrensha opened this issue Aug 17, 2015 · 4 comments
Closed

Cannot impl Drop for a generic type with a Higher-Rank Trait Bound #27863

dwrensha opened this issue Aug 17, 2015 · 4 comments
Labels
A-destructors Area: destructors (Drop, ..) A-traits Area: Trait system A-typesystem Area: The type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dwrensha
Copy link
Contributor

If I try to compile this program:

pub trait Foo<'a> {}

pub struct Bar<T> where T: for<'a> Foo<'a> {
    _phantom: ::std::marker::PhantomData<T>,
}

impl <T> Drop for Bar<T> where T: for<'a> Foo<'a> {
    fn drop(&mut self) {}
}

fn main() {}

I get this clearly bogus error message:

$ rustc test.rs
test.rs:7:1: 9:2 error: The requirement `for<'a> T : Foo<'a>` is added only by the Drop impl. [E0367]
test.rs:7 impl <T> Drop for Bar<T> where T: for<'a> Foo<'a> {
test.rs:8     fn drop(&mut self) {}
test.rs:9 }
test.rs:7:1: 9:2 help: run `rustc --explain E0367` to see a detailed explanation
test.rs:3:1: 5:2 note: The same requirement must be part of the struct/enum definition
test.rs:3 pub struct Bar<T> where T: for<'a> Foo<'a> {
test.rs:4     _phantom: ::std::marker::PhantomData<T>,
test.rs:5 }

I tried fiddling with it to get it to typecheck, but nothing worked.

$ rustc --version --verbose
rustc 1.4.0-nightly (e822a18ae 2015-08-16)
binary: rustc
commit-hash: e822a18ae7d55cefc332c6598a607cef0554ec77
commit-date: 2015-08-16
host: x86_64-apple-darwin
release: 1.4.0-nightly
@alexcrichton
Copy link
Member

cc @pnkfelix

@steveklabnik steveklabnik added A-typesystem Area: The type system A-traits Area: Trait system labels Aug 17, 2015
@pnkfelix pnkfelix added A-destructors Area: destructors (Drop, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 29, 2016
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@Boiethios
Copy link

Boiethios commented Jul 19, 2018

Same here, I just stumbled on this issue. How is this doing? The issue has been there for 3 years.

@Ralith
Copy link
Contributor

Ralith commented Dec 15, 2019

Affecting me also. Bump?

@cjgillot
Copy link
Contributor

cjgillot commented Mar 5, 2022

Original report now correctly compiles.

@cjgillot cjgillot closed this as completed Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-destructors Area: destructors (Drop, ..) A-traits Area: Trait system A-typesystem Area: The type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants