Skip to content

Commit

Permalink
Add two regression tests for const eval
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Jul 1, 2018
1 parent faef6a3 commit 46512e0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/compile-fail/const-err4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2018 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.

#[derive(Copy, Clone)]
union Foo {
a: isize,
b: (),
}

enum Bar {
Boo = [unsafe { Foo { b: () }.a }; 4][3],
//~^ ERROR constant evaluation of enum discriminant resulted in non-integer
}

fn main() {
assert_ne!(Bar::Boo as isize, 0);
}
19 changes: 19 additions & 0 deletions src/test/run-pass/const-repeated-values.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018 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.

const FOO: isize = 42;

enum Bar {
Boo = *[&FOO; 4][3],
}

fn main() {
assert_eq!(Bar::Boo as isize, 42);
}

0 comments on commit 46512e0

Please sign in to comment.