mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Add tests
Closes #22781. Closes #23891. Closes #24956. Closes #25145. Closes #25693. Closes #26095. Closes #26459. Closes #27320. Closes #27895.
This commit is contained in:
parent
04e497c005
commit
671602c8c9
22
src/test/compile-fail/issue-25145.rs
Normal file
22
src/test/compile-fail/issue-25145.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// 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)]
|
||||
|
||||
struct S;
|
||||
|
||||
impl S {
|
||||
const N: usize = 3;
|
||||
}
|
||||
|
||||
static STUFF: [u8; S::N] = [0; S::N];
|
||||
//~^ ERROR array length constant evaluation error: unresolved path in constant expression
|
||||
|
||||
fn main() {}
|
16
src/test/compile-fail/issue-26459.rs
Normal file
16
src/test/compile-fail/issue-26459.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.
|
||||
|
||||
fn main() {
|
||||
match 'a' {
|
||||
char{ch} => true
|
||||
//~^ ERROR `char` does not name a struct or a struct variant
|
||||
};
|
||||
}
|
21
src/test/compile-fail/issue-27895.rs
Normal file
21
src/test/compile-fail/issue-27895.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.
|
||||
|
||||
fn main() {
|
||||
let i = 5;
|
||||
let index = 6;
|
||||
|
||||
match i {
|
||||
0...index => println!("winner"),
|
||||
//~^ ERROR paths in constants may only refer to constants or functions
|
||||
//~| ERROR non-constant path in constant expression
|
||||
_ => println!("hello"),
|
||||
}
|
||||
}
|
23
src/test/run-pass/issue-22781.rs
Normal file
23
src/test/run-pass/issue-22781.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::collections::HashMap;
|
||||
use std::collections::hash_map::Entry::Vacant;
|
||||
|
||||
pub fn foo() {
|
||||
type F = Box<Fn(&()) + 'static>;
|
||||
let mut map: HashMap<(), F> = HashMap::new();
|
||||
let x: &mut F = match map.entry(()) {
|
||||
Vacant(_) => unimplemented!(),
|
||||
_ => unimplemented!()
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
20
src/test/run-pass/issue-23891.rs
Normal file
20
src/test/run-pass/issue-23891.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
macro_rules! id {
|
||||
($s: pat) => ($s);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match (Some(123), Some(456)) {
|
||||
(id!(Some(a)), _) | (_, id!(Some(a))) => println!("{}", a),
|
||||
_ => (),
|
||||
}
|
||||
}
|
20
src/test/run-pass/issue-24956.rs
Normal file
20
src/test/run-pass/issue-24956.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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(bool);
|
||||
const NEW_FALSE: bool = false;
|
||||
const STATIC_FOO: Foo = Foo(NEW_FALSE);
|
||||
|
||||
pub fn main() {
|
||||
match (Foo(false)) {
|
||||
STATIC_FOO => 3,
|
||||
_ => 11
|
||||
};
|
||||
}
|
30
src/test/run-pass/issue-25693.rs
Normal file
30
src/test/run-pass/issue-25693.rs
Normal file
@ -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.
|
||||
|
||||
pub trait Paramters { type SelfRef; }
|
||||
|
||||
struct RP<'a> { _marker: std::marker::PhantomData<&'a ()> }
|
||||
struct BP;
|
||||
|
||||
impl<'a> Paramters for RP<'a> { type SelfRef = &'a X<RP<'a>>; }
|
||||
impl Paramters for BP { type SelfRef = Box<X<BP>>; }
|
||||
|
||||
pub struct Y;
|
||||
pub enum X<P: Paramters> {
|
||||
Nothing,
|
||||
SameAgain(P::SelfRef, Y)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let bnil: Box<X<BP>> = Box::new(X::Nothing);
|
||||
let bx: Box<X<BP>> = Box::new(X::SameAgain(bnil, Y));
|
||||
let rnil: X<RP> = X::Nothing;
|
||||
let rx: X<RP> = X::SameAgain(&rnil, Y);
|
||||
}
|
30
src/test/run-pass/issue-26095.rs
Normal file
30
src/test/run-pass/issue-26095.rs
Normal file
@ -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 HasNumber<T> {
|
||||
const Number: usize;
|
||||
}
|
||||
|
||||
enum One {}
|
||||
enum Two {}
|
||||
|
||||
enum Foo {}
|
||||
|
||||
impl<T> HasNumber<T> for One {
|
||||
const Number: usize = 1;
|
||||
}
|
||||
|
||||
impl<T> HasNumber<T> for Two {
|
||||
const Number: usize = 2;
|
||||
}
|
||||
|
||||
fn main() {}
|
21
src/test/run-pass/issue-27320.rs
Normal file
21
src/test/run-pass/issue-27320.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.
|
||||
|
||||
macro_rules! piece(
|
||||
($piece:pat) => ($piece);
|
||||
);
|
||||
|
||||
enum Piece {A, B}
|
||||
|
||||
fn main() {
|
||||
match Piece::A {
|
||||
piece!(pt@ Piece::A) | piece!(pt@ Piece::B) => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user