Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cross-crate associated constant evaluation
- Loading branch information
1 parent
936dbbc
commit c91037b
Showing
5 changed files
with
102 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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_consts)] | ||
|
||
trait Foo { | ||
const NUM: usize; | ||
} | ||
|
||
impl Foo for i32 { | ||
const NUM: usize = 1; | ||
} | ||
|
||
const FOO: usize = <i32 as Foo>::NUM; | ||
|
||
fn main() { | ||
assert_eq!(1, FOO); | ||
|
||
match 1 { | ||
<i32 as Foo>::NUM => {}, | ||
_ => assert!(false) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/run-pass/associated-const-cross-crate-const-eval.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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. | ||
|
||
// aux-build:associated-const-cc-lib.rs | ||
|
||
#![feature(associated_consts)] | ||
|
||
extern crate associated_const_cc_lib as foolib; | ||
|
||
pub struct LocalFoo; | ||
|
||
impl foolib::Foo for LocalFoo { | ||
const BAR: usize = 1; | ||
} | ||
|
||
const FOO_1: usize = <foolib::FooNoDefault as foolib::Foo>::BAR; | ||
const FOO_2: usize = <LocalFoo as foolib::Foo>::BAR; | ||
const FOO_3: usize = foolib::InherentBar::BAR; | ||
|
||
fn main() { | ||
assert_eq!(0, FOO_1); | ||
assert_eq!(1, FOO_2); | ||
assert_eq!(3, FOO_3); | ||
|
||
match 0 { | ||
<foolib::FooNoDefault as foolib::Foo>::BAR => {}, | ||
<LocalFoo as foolib::Foo>::BAR => assert!(false), | ||
foolib::InherentBar::BAR => assert!(false), | ||
_ => assert!(false) | ||
} | ||
} |