ΠΡΠ»ΠΈ Ρ ΠΏΠΎΠΏΡΡΠ°ΡΡΡ ΡΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡΠΎΠ²Π°ΡΡ ΡΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ:
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
cc @pnkfelix
Π’ΠΎ ΠΆΠ΅ ΡΠ°ΠΌΠΎΠ΅, Ρ ΡΠΎΠ»ΡΠΊΠΎ ΡΡΠΎ Π½Π°ΡΠΊΠ½ΡΠ»ΡΡ Π½Π° ΡΡΡ ΠΏΡΠΎΠ±Π»Π΅ΠΌΡ. ΠΠ°ΠΊ Π΄Π΅Π»Π°? ΠΠΎΠΏΡΠΎΡ ΡΡΠΎΠΈΡ 3 Π³ΠΎΠ΄Π°.
ΠΠ»ΠΈΡΠ΅Ρ ΠΈ Π½Π° ΠΌΠ΅Π½Ρ. Π£Π΄Π°Ρ?
Π‘Π°ΠΌΡΠΉ ΠΏΠΎΠ»Π΅Π·Π½ΡΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ
Π’ΠΎ ΠΆΠ΅ ΡΠ°ΠΌΠΎΠ΅, Ρ ΡΠΎΠ»ΡΠΊΠΎ ΡΡΠΎ Π½Π°ΡΠΊΠ½ΡΠ»ΡΡ Π½Π° ΡΡΡ ΠΏΡΠΎΠ±Π»Π΅ΠΌΡ. ΠΠ°ΠΊ Π΄Π΅Π»Π°? ΠΠΎΠΏΡΠΎΡ ΡΡΠΎΠΈΡ 3 Π³ΠΎΠ΄Π°.