From c61a0092bc236c4be4cb691fcd50ff50e91ab0d6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 26 Dec 2014 03:30:51 -0500 Subject: Fix orphan checking (cc #19470). (This is not a complete fix of #19470 because of the backwards compatibility feature gate.) This is a [breaking-change]. The new rules require that, for an impl of a trait defined in some other crate, two conditions must hold: 1. Some type must be local. 2. Every type parameter must appear "under" some local type. Here are some examples that are legal: ```rust struct MyStruct { ... } // Here `T` appears "under' `MyStruct`. impl Clone for MyStruct { } // Here `T` appears "under' `MyStruct` as well. Note that it also appears // elsewhere. impl Iterator for MyStruct { } ``` Here is an illegal example: ```rust // Here `U` does not appear "under" `MyStruct` or any other local type. // We call `U` "uncovered". impl Iterator for MyStruct { } ``` There are a couple of ways to rewrite this last example so that it is legal: 1. In some cases, the uncovered type parameter (here, `U`) should be converted into an associated type. This is however a non-local change that requires access to the original trait. Also, associated types are not fully baked. 2. Add `U` as a type parameter of `MyStruct`: ```rust struct MyStruct { ... } impl Iterator for MyStruct { } ``` 3. Create a newtype wrapper for `U` ```rust impl Iterator> for MyStruct { } ``` Because associated types are not fully baked, which in the case of the `Hash` trait makes adhering to this rule impossible, you can temporarily disable this rule in your crate by using `#![feature(old_orphan_check)]`. Note that the `old_orphan_check` feature will be removed before 1.0 is released. --- src/liballoc/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/liballoc/lib.rs') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 61b5d43d1cb..d17a54ce6e5 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -64,7 +64,8 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![no_std] -#![feature(lang_items, phase, unsafe_destructor, default_type_params)] +#![allow(unknown_features)] +#![feature(lang_items, phase, unsafe_destructor, default_type_params, old_orphan_check)] #[phase(plugin, link)] extern crate core; -- cgit 1.4.1-3-g733a5