Skip to content

Commit 6e6d5b1

Browse files
committed
Feature gate associated type defaults
There are multiple issues with them as designed and implemented. cc #27364 Conflicts: src/libsyntax/feature_gate.rs src/test/auxiliary/xcrate_associated_type_defaults.rs
1 parent e6b2f0c commit 6e6d5b1

File tree

6 files changed

+45
-0
lines changed

6 files changed

+45
-0
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

+7
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
155155

156156
// Allows the definition of `const fn` functions.
157157
("const_fn", "1.2.0", Active),
158+
159+
// Allows associated type defaults
160+
("associated_type_defaults", "1.2.0", Active),
158161
];
159162
// (changing above list without updating src/doc/reference.md makes @cmr sad)
160163

@@ -686,6 +689,10 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
686689
self.gate_feature("const_fn", ti.span, "const fn is unstable");
687690
}
688691
}
692+
ast::TypeTraitItem(_, Some(_)) => {
693+
self.gate_feature("associated_type_defaults", ti.span,
694+
"associated type defaults are unstable");
695+
}
689696
_ => {}
690697
}
691698
visit::walk_trait_item(self, ti);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
#![feature(associated_type_defaults)]
12+
13+
pub trait Foo {
14+
type Input = usize;
15+
fn bar(&self, _: Self::Input) {}
16+
}
17+
18+
impl Foo for () {}
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)