Feature-gate associated constants.
This commit is contained in:
parent
29eb550ee6
commit
b1db4ec3d0
23 changed files with 95 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)]
|
||||
|
||||
|
|
25
src/test/compile-fail/gated-associated_consts.rs
Normal file
25
src/test/compile-fail/gated-associated_consts.rs
Normal 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
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue