Rust: 不能针对具有较高Rank Trait约束的泛型类型隐含Drop

创建于 2015-08-17  ·  3评论  ·  资料来源: rust-lang/rust

如果我尝试编译该程序:

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() {}

我收到这明显是虚假的错误消息:

$ 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 }

我尝试摆弄它以进行类型检查,但没有任何效果。

$ 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
A-destructors A-traits A-typesystem C-bug T-compiler

最有用的评论

同样在这里,我只是偶然发现了这个问题。 怎么样了问题已经存在了三年。

所有3条评论

cc @pnkfelix

同样在这里,我只是偶然发现了这个问题。 怎么样了问题已经存在了三年。

也影响我。 磕碰?

此页面是否有帮助?
0 / 5 - 0 等级