Skip to content

Commit a09bce1

Browse files
committed
Feature gate associated type defaults
There are multiple issues with them as designed and implemented. cc #27364
1 parent 1c8194c commit a09bce1

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#![allow(raw_pointer_derive)]
6666
#![deny(missing_docs)]
6767

68+
#![feature(associated_type_defaults)]
6869
#![feature(intrinsics)]
6970
#![feature(lang_items)]
7071
#![feature(on_unimplemented)]

src/libsyntax/feature_gate.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
165165
("static_recursion", "1.3.0", Active),
166166

167167
// Allows default type parameters to influence type inference.
168-
("default_type_parameter_fallback", "1.3.0", Active)
168+
("default_type_parameter_fallback", "1.3.0", Active),
169+
170+
// Allows associated type defaults
171+
("associated_type_defaults", "1.2.0", Active),
169172
];
170173
// (changing above list without updating src/doc/reference.md makes @cmr sad)
171174

@@ -763,6 +766,10 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
763766
self.gate_feature("const_fn", ti.span, "const fn is unstable");
764767
}
765768
}
769+
ast::TypeTraitItem(_, Some(_)) => {
770+
self.gate_feature("associated_type_defaults", ti.span,
771+
"associated type defaults are unstable");
772+
}
766773
_ => {}
767774
}
768775
visit::walk_trait_item(self, ti);

src/test/auxiliary/xcrate_associated_type_defaults.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_type_defaults)]
12+
1113
pub trait Foo {
1214
type Input = usize;
1315
fn bar(&self, _: Self::Input) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo {
12+
type Bar = u8; //~ ERROR associated type defaults are unstable
13+
}
14+
15+
fn main() {}

src/test/run-pass/default-associated-types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_type_defaults)]
12+
1113
trait Foo<T> {
1214
type Out = T;
1315
fn foo(&self) -> Self::Out;

src/test/run-pass/issue-25339.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_type_defaults)]
12+
1113
use std::marker::PhantomData;
1214

1315
pub trait Routing<I> {

0 commit comments

Comments
 (0)