Functional changes for associated constants. Cross-crate usage of associated constants is not yet working.
This commit is contained in:
parent
b5499775d6
commit
7129e8815e
43 changed files with 1387 additions and 294 deletions
27
src/test/compile-fail/associated-const-private-impl.rs
Normal file
27
src/test/compile-fail/associated-const-private-impl.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// 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;
|
||||
|
||||
mod bar1 {
|
||||
pub use self::bar2::Foo;
|
||||
mod bar2 {
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
const ID: i32 = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, bar1::Foo::ID);
|
||||
//~^ERROR associated const `ID` is private
|
||||
}
|
||||
21
src/test/compile-fail/impl-type-where-trait-has-method.rs
Normal file
21
src/test/compile-fail/impl-type-where-trait-has-method.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// 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 {
|
||||
fn bar(&self);
|
||||
}
|
||||
|
||||
impl Foo for u32 {
|
||||
//~^ ERROR not all trait items implemented, missing: `bar`
|
||||
type bar = u64;
|
||||
//~^ ERROR item `bar` is an associated type, which doesn't match its trait `Foo`
|
||||
}
|
||||
|
||||
fn main () {}
|
||||
|
|
@ -16,6 +16,6 @@ impl Foo {
|
|||
fn foo() {}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
} //~ ERROR expected one of `extern`, `fn`, `pub`, `type`, or `unsafe`, found `}`
|
||||
} //~ ERROR expected one of `const`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `}`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ struct Foo;
|
|||
|
||||
impl Foo {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
} //~ ERROR expected one of `extern`, `fn`, `pub`, `type`, or `unsafe`, found `}`
|
||||
} //~ ERROR expected one of `const`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `}`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@
|
|||
// compile-flags: -Z parse-only
|
||||
|
||||
trait MyTrait<T>: Iterator {
|
||||
Item = T; //~ ERROR expected one of `extern`, `fn`, `type`, or `unsafe`, found `Item`
|
||||
Item = T; //~ ERROR expected one of `const`, `extern`, `fn`, `type`, or `unsafe`, found `Item`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@ struct S;
|
|||
|
||||
impl S {
|
||||
static fn f() {}
|
||||
//~^ ERROR expected one of `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `static`
|
||||
}
|
||||
//~^^ ERROR expected one of `const`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `static`
|
||||
|
|
|
|||
16
src/test/parse-fail/trait-pub-assoc-const.rs
Normal file
16
src/test/parse-fail/trait-pub-assoc-const.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// 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 {
|
||||
pub const Foo: u32;
|
||||
//~^ ERROR expected one of `const`, `extern`, `fn`, `type`, or `unsafe`, found `pub`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -9,7 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait Foo {
|
||||
pub type Foo; //~ ERROR expected one of `extern`, `fn`, `type`, or `unsafe`, found `pub`
|
||||
pub type Foo;
|
||||
//~^ ERROR expected one of `const`, `extern`, `fn`, `type`, or `unsafe`, found `pub`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait Foo {
|
||||
pub fn foo(); //~ ERROR expected one of `extern`, `fn`, `type`, or `unsafe`, found `pub`
|
||||
pub fn foo();
|
||||
//~^ ERROR expected one of `const`, `extern`, `fn`, `type`, or `unsafe`, found `pub`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
19
src/test/run-pass/associated-const-inherent-impl.rs
Normal file
19
src/test/run-pass/associated-const-inherent-impl.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// 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.
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
const ID: i32 = 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, Foo::ID);
|
||||
}
|
||||
23
src/test/run-pass/associated-const-overwrite-default.rs
Normal file
23
src/test/run-pass/associated-const-overwrite-default.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// 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 Foo: MarkerTrait {
|
||||
const ID: i32 = 2;
|
||||
}
|
||||
|
||||
impl Foo for i32 {
|
||||
const ID: i32 = 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, <i32 as Foo>::ID);
|
||||
}
|
||||
26
src/test/run-pass/associated-const-public-impl.rs
Normal file
26
src/test/run-pass/associated-const-public-impl.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// 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;
|
||||
|
||||
mod bar1 {
|
||||
pub use self::bar2::Foo;
|
||||
mod bar2 {
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
pub const ID: i32 = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, bar1::Foo::ID);
|
||||
}
|
||||
23
src/test/run-pass/associated-const-self-type.rs
Normal file
23
src/test/run-pass/associated-const-self-type.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// 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 MyInt: MarkerTrait {
|
||||
const ONE: Self;
|
||||
}
|
||||
|
||||
impl MyInt for i32 {
|
||||
const ONE: i32 = 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, <i32>::ONE);
|
||||
}
|
||||
23
src/test/run-pass/associated-const-ufcs-infer-trait.rs
Normal file
23
src/test/run-pass/associated-const-ufcs-infer-trait.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// 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 Foo: MarkerTrait {
|
||||
const ID: i32;
|
||||
}
|
||||
|
||||
impl Foo for i32 {
|
||||
const ID: i32 = 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, <i32>::ID);
|
||||
}
|
||||
21
src/test/run-pass/associated-const-use-default.rs
Normal file
21
src/test/run-pass/associated-const-use-default.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// 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 Foo: MarkerTrait {
|
||||
const ID: i32 = 1;
|
||||
}
|
||||
|
||||
impl Foo for i32 {}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, <i32 as Foo>::ID);
|
||||
}
|
||||
23
src/test/run-pass/associated-const.rs
Normal file
23
src/test/run-pass/associated-const.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// 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 Foo: MarkerTrait {
|
||||
const ID: i32;
|
||||
}
|
||||
|
||||
impl Foo for i32 {
|
||||
const ID: i32 = 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, <i32 as Foo>::ID);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue