Skip to content

Commit

Permalink
Feature gate associated type defaults
Browse files Browse the repository at this point in the history
There are multiple issues with them as designed and implemented.

cc rust-lang#27364

Conflicts:
	src/libsyntax/feature_gate.rs
	src/test/auxiliary/xcrate_associated_type_defaults.rs
  • Loading branch information
brson committed Jul 29, 2015
1 parent e6b2f0c commit 6e6d5b1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#![allow(raw_pointer_derive)]
#![deny(missing_docs)]

#![feature(associated_type_defaults)]
#![feature(intrinsics)]
#![feature(lang_items)]
#![feature(on_unimplemented)]
Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[

// Allows the definition of `const fn` functions.
("const_fn", "1.2.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)

Expand Down Expand Up @@ -686,6 +689,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);
Expand Down
18 changes: 18 additions & 0 deletions src/test/auxiliary/xcrate_associated_type_defaults.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// 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) {}
}

impl Foo for () {}
15 changes: 15 additions & 0 deletions src/test/compile-fail/feature-gate-assoc-type-defaults.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
2 changes: 2 additions & 0 deletions src/test/run-pass/default-associated-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
type Out = T;
fn foo(&self) -> Self::Out;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-25339.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I> {
Expand Down

0 comments on commit 6e6d5b1

Please sign in to comment.