Skip to content

Commit 9c6904c

Browse files
committed
Auto merge of #33686 - GuillaumeGomez:error-code-tests, r=steveklabnik
Add new error code tests r? @steveklabnik
2 parents 9a14045 + afd4ccc commit 9c6904c

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

src/test/compile-fail/E0027.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Dog {
12+
name: String,
13+
age: u32,
14+
}
15+
16+
fn main() {
17+
let d = Dog { name: "Rusty".to_string(), age: 8 };
18+
19+
match d {
20+
Dog { age: x } => {} //~ ERROR E0027
21+
}
22+
}

src/test/compile-fail/E0029.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let s = "hoho";
13+
14+
match s {
15+
"hello" ... "world" => {} //~ ERROR E0029
16+
_ => {}
17+
}
18+
}

src/test/compile-fail/E0030.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
fn main() {
13+
match 5u32 {
14+
1000 ... 5 => {} //~ ERROR E0030
15+
}
16+
}

src/test/compile-fail/E0033.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait SomeTrait {
12+
fn foo();
13+
}
14+
15+
fn main() {
16+
let trait_obj: &SomeTrait = SomeTrait; //~ ERROR E0425
17+
//~^ ERROR E0038
18+
let &invalid = trait_obj; //~ ERROR E0033
19+
}

src/test/compile-fail/E0034.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Test;
12+
13+
trait Trait1 {
14+
fn foo();
15+
}
16+
17+
trait Trait2 {
18+
fn foo();
19+
}
20+
21+
impl Trait1 for Test { fn foo() {} }
22+
impl Trait2 for Test { fn foo() {} }
23+
24+
fn main() {
25+
Test::foo() //~ ERROR E0034
26+
}

src/test/compile-fail/E0035.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Test;
12+
13+
impl Test {
14+
fn method(&self) {}
15+
}
16+
17+
fn main() {
18+
let x = Test;
19+
x.method::<i32>(); //~ ERROR E0035
20+
}

0 commit comments

Comments
 (0)