diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index ef2a33c37dd..6da1a3da5fd 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 6fa6e46d880..945e457a77b 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -165,7 +165,10 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[ ("static_recursion", "1.3.0", Active), // Allows default type parameters to influence type inference. - ("default_type_parameter_fallback", "1.3.0", Active) + ("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) @@ -763,6 +766,10 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { 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 a6b70bf974f..43852a4e793 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/feature-gate-assoc-type-defaults.rs b/src/test/compile-fail/feature-gate-assoc-type-defaults.rs new file mode 100644 index 00000000000..fc4871a712d --- /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/run-pass/default-associated-types.rs b/src/test/run-pass/default-associated-types.rs index b3def429b9b..3e6c72c993a 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 af172000fdb..381df7c5d59 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 {