1
Fork 0

Feature-gate associated constants.

This commit is contained in:
Sean Patrick Santos 2015-03-26 13:06:26 -06:00
parent 29eb550ee6
commit b1db4ec3d0
23 changed files with 95 additions and 1 deletions

View file

@ -2340,7 +2340,10 @@ The currently implemented features of the reference compiler are:
semantics are likely to change, so this macro usage must be opted
into.
* `associated_types` - Allows type aliases in traits. Experimental.
* `associated_consts` - Allows constants to be defined in `impl` and `trait`
blocks, so that they can be associated with a type or
trait in a similar manner to methods and associated
types.
* `box_patterns` - Allows `box` patterns, the exact semantics of which
is subject to change.

View file

@ -155,6 +155,10 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
// Allows use of unary negate on unsigned integers, e.g. -e for e: u8
("negate_unsigned", "1.0.0", Active),
// Allows the definition of associated constants in `trait` or `impl`
// blocks.
("associated_consts", "1.0.0", Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
@ -659,6 +663,30 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
}
visit::walk_fn(self, fn_kind, fn_decl, block, span);
}
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
match ti.node {
ast::ConstTraitItem(..) => {
self.gate_feature("associated_consts",
ti.span,
"associated constants are experimental")
}
_ => {}
}
visit::walk_trait_item(self, ti);
}
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
match ii.node {
ast::ConstImplItem(..) => {
self.gate_feature("associated_consts",
ii.span,
"associated constants are experimental")
}
_ => {}
}
visit::walk_impl_item(self, ii);
}
}
fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
#![crate_type="lib"]
use std::marker::MarkerTrait;

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
#![deny(dead_code)]
struct MyFoo;

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
trait Foo: MarkerTrait {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
mod bar1 {

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
#![deny(non_upper_case_globals)]
#![allow(dead_code)]

View file

@ -0,0 +1,25 @@
// 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.
use std::marker::MarkerTrait;
trait MyTrait: MarkerTrait {
const C: bool;
//~^ associated constants are experimental
//~| add #![feature(associated_consts)] to the crate attributes to enable
}
struct Foo;
impl Foo {
const C: bool = true;
//~^ associated constants are experimental
//~| add #![feature(associated_consts)] to the crate attributes to enable
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
trait Foo {
fn bar(&self);
const MY_CONST: u32;

View file

@ -10,6 +10,8 @@
// aux-build:associated-const-cc-lib.rs
#![feature(associated_consts)]
extern crate associated_const_cc_lib as foolib;
pub struct LocalFooUseDefault;

View file

@ -10,6 +10,8 @@
// aux-build:associated-const-cc-lib.rs
#![feature(associated_consts)]
extern crate associated_const_cc_lib as foolib;
pub struct LocalFoo;

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
struct Foo;
impl Foo {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
struct Foo;
impl Foo {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
#![deny(dead_code)]
const GLOBAL_BAR: u32 = 1;

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
struct Foo;

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
trait Foo: MarkerTrait {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
mod bar1 {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
struct MyType;

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
trait MyInt: MarkerTrait {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
trait Foo: MarkerTrait {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
trait Foo: MarkerTrait {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
// The main purpose of this test is to ensure that different impls of the same

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
use std::marker::MarkerTrait;
trait Foo: MarkerTrait {