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/libserialize/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libserialize/json.rs') diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 3f0d59c319a..684856ae33b 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -81,7 +81,7 @@ //! use serialize::json; //! //! // Automatically generate `Decodable` and `Encodable` trait implementations -//! #[deriving(Decodable, Encodable)] +//! #[deriving(RustcDecodable, RustcEncodable)] //! pub struct TestStruct { //! data_int: u8, //! data_str: String, -- cgit 1.4.1-3-g733a5 From 5c34781a7d3f5b6761fa564a4a9ebeb19bb50cc1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 1 Jan 2015 16:45:22 -0500 Subject: Disable the JSON doctests because they don't pass the new coherence rules and cannot be updated until the libraries are synced, nor can they opt in to the old semantics. --- src/libserialize/json.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/libserialize/json.rs') diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 684856ae33b..a734630a215 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -76,7 +76,8 @@ //! Create a struct called `TestStruct` and serialize and deserialize it to and from JSON using the //! serialization API, using the derived serialization code. //! -//! ```rust +//! ```notrust +//! // FIXME(#19470): this cannot be ```rust``` because it fails orphan checking at the moment //! extern crate serialize; //! use serialize::json; //! @@ -110,7 +111,8 @@ //! //! ### Simple example of `ToJson` usage //! -//! ```rust +//! ```notrust +//! // FIXME(#19470): this cannot be ```rust``` because it fails orphan checking at the moment //! extern crate serialize; //! use serialize::json::{mod, ToJson, Json}; //! @@ -149,7 +151,8 @@ //! //! ### Verbose example of `ToJson` usage //! -//! ```rust +//! ```notrust +//! // FIXME(#19470): this cannot be ```rust``` because it fails orphan checking at the moment //! extern crate serialize; //! use std::collections::BTreeMap; //! use serialize::json::{mod, Json, ToJson}; -- cgit 1.4.1-3-g733a5