diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 47d630a38642e1492ca190949323457ce70d6ee8..238644c4a264a739f5e41e9c1ffa4ed4ef5dd320 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -65,6 +65,7 @@ #![allow(raw_pointer_derive)] #![deny(missing_docs)] +#![feature(associated_type_defaults)] #![feature(intrinsics)] #![feature(lang_items)] #![feature(on_unimplemented)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 53b57cdfaa1ad4f50bd8625fa9cfe4c2a281b0ff..945e457a77b7313dc55259e81387397ac850def0 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -163,8 +163,12 @@ // Allows the definition recursive static items. ("static_recursion", "1.3.0", Active), -// Allows default type parameters to influence type inference. - ("default_type_parameter_fallback", "1.3.0", Active) + + // Allows default type parameters to influence type inference. + ("default_type_parameter_fallback", "1.3.0", Active), + + // Allows associated type defaults + ("associated_type_defaults", "1.2.0", Active), ]; // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -762,6 +766,10 @@ fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) { self.gate_feature("const_fn", ti.span, "const fn is unstable"); } } + ast::TypeTraitItem(_, Some(_)) => { + self.gate_feature("associated_type_defaults", ti.span, + "associated type defaults are unstable"); + } _ => {} } visit::walk_trait_item(self, ti); diff --git a/src/test/auxiliary/xcrate_associated_type_defaults.rs b/src/test/auxiliary/xcrate_associated_type_defaults.rs index a6b70bf974f959dac4afd70795cba580402ed6d6..43852a4e793f363a6477cb8dc7df1caf906c2a65 100644 --- a/src/test/auxiliary/xcrate_associated_type_defaults.rs +++ b/src/test/auxiliary/xcrate_associated_type_defaults.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_type_defaults)] + pub trait Foo { type Input = usize; fn bar(&self, _: Self::Input) {} diff --git a/src/test/compile-fail/associated-types-overridden-default.rs b/src/test/compile-fail/associated-types-overridden-default.rs index eb519e79006d2c8dd9e66a75a193c35ae341cf7a..19f13f5fc2f2ba7bd5da444ed4a8adf4fe469014 100644 --- a/src/test/compile-fail/associated-types-overridden-default.rs +++ b/src/test/compile-fail/associated-types-overridden-default.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(associated_consts)] +#![feature(associated_type_defaults)] pub trait Tr { type Assoc = u8; diff --git a/src/test/compile-fail/feature-gate-assoc-type-defaults.rs b/src/test/compile-fail/feature-gate-assoc-type-defaults.rs new file mode 100644 index 0000000000000000000000000000000000000000..fc4871a712dffc64519885c861f8682253746307 --- /dev/null +++ b/src/test/compile-fail/feature-gate-assoc-type-defaults.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + type Bar = u8; //~ ERROR associated type defaults are unstable +} + +fn main() {} diff --git a/src/test/compile-fail/issue-23073.rs b/src/test/compile-fail/issue-23073.rs index 1286ba873be5ae79e57433e1f06a2a0cff086f72..2d219177a80d400a0f479e22a3a01d8cd5a7ad2d 100644 --- a/src/test/compile-fail/issue-23073.rs +++ b/src/test/compile-fail/issue-23073.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_type_defaults)] + trait Foo { type T; } trait Bar { type Foo: Foo; diff --git a/src/test/compile-fail/issue-23595-1.rs b/src/test/compile-fail/issue-23595-1.rs index 749b261e38719a89e481a41f2831678df23d217c..a3422d859c61fa67bc0dcef7f883a601cad78750 100644 --- a/src/test/compile-fail/issue-23595-1.rs +++ b/src/test/compile-fail/issue-23595-1.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_type_defaults)] + use std::ops::{Index}; trait Hierarchy { diff --git a/src/test/compile-fail/issue-23595-2.rs b/src/test/compile-fail/issue-23595-2.rs index 78a3f42f1a6a7cdaa6715fbc437aba784ba76a30..6a3ce03fce5e096358d4526584653636b89b99a9 100644 --- a/src/test/compile-fail/issue-23595-2.rs +++ b/src/test/compile-fail/issue-23595-2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_type_defaults)] + pub struct C {a:AType} pub trait A { diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs index 04db6c8c8f39c97798136e1af46f2f2136b79143..c98d7083743b8179e7b7cd7f980fee46466ba72e 100644 --- a/src/test/compile-fail/lint-missing-doc.rs +++ b/src/test/compile-fail/lint-missing-doc.rs @@ -12,6 +12,7 @@ // injected intrinsics by the compiler. #![deny(missing_docs)] #![allow(dead_code)] +#![feature(associated_type_defaults)] //! Some garbage docs for the crate here #![doc="More garbage"] diff --git a/src/test/run-pass/default-associated-types.rs b/src/test/run-pass/default-associated-types.rs index b3def429b9b8ce9564205ca06422ab5e63f117d3..3e6c72c993a0aa5e480919674aff6b4b0cdc62db 100644 --- a/src/test/run-pass/default-associated-types.rs +++ b/src/test/run-pass/default-associated-types.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_type_defaults)] + trait Foo { type Out = T; fn foo(&self) -> Self::Out; diff --git a/src/test/run-pass/issue-25339.rs b/src/test/run-pass/issue-25339.rs index af172000fdb1a6336e28849dc3c44ac043e1bab7..381df7c5d5938e4222e0ca30a2c0949209ba5f37 100644 --- a/src/test/run-pass/issue-25339.rs +++ b/src/test/run-pass/issue-25339.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_type_defaults)] + use std::marker::PhantomData; pub trait Routing {