Rollup merge of #33585 - GuillaumeGomez:error_code_test, r=steveklabnik
Add compile-fail tests for error codes r? @steveklabnik cc @jonathandturner
This commit is contained in:
commit
e82596b9d8
18
src/test/compile-fail/E0001.rs
Normal file
18
src/test/compile-fail/E0001.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 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 foo = Some(1);
|
||||
match foo {
|
||||
Some(bar) => {/* ... */}
|
||||
None => {/* ... */}
|
||||
_ => {/* ... */} //~ ERROR E0001
|
||||
}
|
||||
}
|
15
src/test/compile-fail/E0002.rs
Normal file
15
src/test/compile-fail/E0002.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2016 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 x = Some(1);
|
||||
|
||||
match x { } //~ ERROR E0002
|
||||
}
|
22
src/test/compile-fail/E0004.rs
Normal file
22
src/test/compile-fail/E0004.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
enum Terminator {
|
||||
HastaLaVistaBaby,
|
||||
TalkToMyHand,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Terminator::HastaLaVistaBaby;
|
||||
|
||||
match x { //~ ERROR E0004
|
||||
Terminator::TalkToMyHand => {}
|
||||
}
|
||||
}
|
14
src/test/compile-fail/E0005.rs
Normal file
14
src/test/compile-fail/E0005.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2016 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 x = Some(1);
|
||||
let Some(y) = x; //~ ERROR E0005
|
||||
}
|
18
src/test/compile-fail/E0007.rs
Normal file
18
src/test/compile-fail/E0007.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 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 x = Some("s".to_string());
|
||||
match x {
|
||||
op_string @ Some(s) => {}, //~ ERROR E0007
|
||||
//~| ERROR E0303
|
||||
None => {},
|
||||
}
|
||||
}
|
16
src/test/compile-fail/E0008.rs
Normal file
16
src/test/compile-fail/E0008.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2016 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 Some("hi".to_string()) {
|
||||
Some(s) if s.len() == 0 => {}, //~ ERROR E0008
|
||||
_ => {},
|
||||
}
|
||||
}
|
18
src/test/compile-fail/E0009.rs
Normal file
18
src/test/compile-fail/E0009.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 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() {
|
||||
struct X { x: (), }
|
||||
let x = Some((X { x: () }, X { x: () }));
|
||||
match x {
|
||||
Some((y, ref z)) => {}, //~ ERROR E0009
|
||||
None => panic!()
|
||||
}
|
||||
}
|
15
src/test/compile-fail/E0010.rs
Normal file
15
src/test/compile-fail/E0010.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2016 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(box_syntax)]
|
||||
|
||||
const CON : Box<i32> = box 0; //~ ERROR E0010
|
||||
|
||||
fn main() {}
|
22
src/test/compile-fail/E0017.rs
Normal file
22
src/test/compile-fail/E0017.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
static X: i32 = 1;
|
||||
const C: i32 = 2;
|
||||
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
|
||||
//~| ERROR E0017
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
|
||||
//~| ERROR E0017
|
||||
//~| ERROR E0388
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
|
||||
//~| ERROR E0017
|
||||
|
||||
fn main() {}
|
22
src/test/compile-fail/E0023.rs
Normal file
22
src/test/compile-fail/E0023.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
enum Fruit {
|
||||
Apple(String, String),
|
||||
Pear(u32),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Fruit::Apple(String::new(), String::new());
|
||||
match x {
|
||||
Fruit::Apple(a) => {}, //~ ERROR E0023
|
||||
Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
|
||||
}
|
||||
}
|
22
src/test/compile-fail/E0024.rs
Normal file
22
src/test/compile-fail/E0024.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
enum Number {
|
||||
Zero,
|
||||
One(u32)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Number::Zero;
|
||||
match x {
|
||||
Number::Zero(inside) => {}, //~ ERROR E0024
|
||||
Number::One(inside) => {},
|
||||
}
|
||||
}
|
19
src/test/compile-fail/E0025.rs
Normal file
19
src/test/compile-fail/E0025.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2016 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 {
|
||||
a: u8,
|
||||
b: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Foo { a:1, b:2 };
|
||||
let Foo { a: x, a: y, b: 0 } = x; //~ ERROR E0025
|
||||
}
|
21
src/test/compile-fail/E0026.rs
Normal file
21
src/test/compile-fail/E0026.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2016 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 Thing {
|
||||
x: u32,
|
||||
y: u32
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let thing = Thing { x: 0, y: 0 };
|
||||
match thing {
|
||||
Thing { x, y, z } => {} //~ ERROR E0026
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user