Skip to content

Commit 3e1b33d

Browse files
Add new error code tests
1 parent a9907a1 commit 3e1b33d

16 files changed

+324
-0
lines changed

src/test/compile-fail/E0502.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 bar(x: &mut i32) {}
12+
fn foo(a: &mut i32) {
13+
let ref y = a;
14+
bar(a); //~ ERROR E0502
15+
}
16+
17+
fn main() {
18+
}

src/test/compile-fail/E0503.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 mut value = 3;
13+
let _borrow = &mut value;
14+
let _sum = value + 1; //~ ERROR E0503
15+
}

src/test/compile-fail/E0504.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 FancyNum {
12+
num: u8,
13+
}
14+
15+
fn main() {
16+
let fancy_num = FancyNum { num: 5 };
17+
let fancy_ref = &fancy_num;
18+
19+
let x = move || {
20+
println!("child function: {}", fancy_num.num); //~ ERROR E0504
21+
};
22+
23+
x();
24+
println!("main function: {}", fancy_ref.num);
25+
}

src/test/compile-fail/E0505.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 Value {}
12+
13+
fn eat(val: Value) {}
14+
15+
fn main() {
16+
let x = Value{};
17+
{
18+
let _ref_to_val: &Value = &x;
19+
eat(x); //~ ERROR E0505
20+
}
21+
}

src/test/compile-fail/E0506.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 FancyNum {
12+
num: u8,
13+
}
14+
15+
fn main() {
16+
let mut fancy_num = FancyNum { num: 5 };
17+
let fancy_ref = &fancy_num;
18+
fancy_num = FancyNum { num: 6 }; //~ ERROR E0506
19+
20+
println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
21+
}

src/test/compile-fail/E0507.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
use std::cell::RefCell;
12+
13+
struct TheDarkKnight;
14+
15+
impl TheDarkKnight {
16+
fn nothing_is_true(self) {}
17+
}
18+
19+
fn main() {
20+
let x = RefCell::new(TheDarkKnight);
21+
22+
x.borrow().nothing_is_true(); //~ ERROR E0507
23+
}

src/test/compile-fail/E0508.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+
struct NonCopy;
12+
13+
fn main() {
14+
let array = [NonCopy; 1];
15+
let _value = array[0]; //~ ERROR E0508
16+
}

src/test/compile-fail/E0509.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 FancyNum {
12+
num: usize
13+
}
14+
15+
struct DropStruct {
16+
fancy: FancyNum
17+
}
18+
19+
impl Drop for DropStruct {
20+
fn drop(&mut self) {
21+
}
22+
}
23+
24+
fn main() {
25+
let drop_struct = DropStruct{fancy: FancyNum{num: 5}};
26+
let fancy_field = drop_struct.fancy; //~ ERROR E0509
27+
println!("Fancy: {}", fancy_field.num);
28+
}

src/test/compile-fail/E0511.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+
#![feature(platform_intrinsics)]
12+
13+
extern "platform-intrinsic" {
14+
fn simd_add<T>(a: T, b: T) -> T;
15+
}
16+
17+
fn main() {
18+
unsafe { simd_add(0, 1); } //~ ERROR E0511
19+
}

src/test/compile-fail/E0512.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 takes_u8(_: u8) {}
12+
13+
fn main() {
14+
unsafe { takes_u8(::std::mem::transmute(0u16)); } //~ ERROR E0512
15+
}

src/test/compile-fail/E0516.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 x: typeof(92) = 92; //~ ERROR E0516
13+
}

src/test/compile-fail/E0517.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#[repr(C)] //~ ERROR E0517
12+
type Foo = u8;
13+
14+
#[repr(packed)] //~ ERROR E0517
15+
enum Foo2 {Bar, Baz}
16+
17+
#[repr(u8)] //~ ERROR E0517
18+
struct Foo3 {bar: bool, baz: bool}
19+
20+
#[repr(C)] //~ ERROR E0517
21+
impl Foo3 {
22+
}
23+
24+
fn main() {
25+
}

src/test/compile-fail/E0518.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+
#[inline(always)] //~ ERROR E0518
12+
struct Foo;
13+
14+
#[inline(never)] //~ ERROR E0518
15+
impl Foo {
16+
}
17+
18+
fn main() {
19+
}

src/test/compile-fail/E0520.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
#![feature(specialization)]
12+
13+
trait SpaceLlama {
14+
fn fly(&self);
15+
}
16+
17+
impl<T> SpaceLlama for T {
18+
default fn fly(&self) {}
19+
}
20+
21+
impl<T: Clone> SpaceLlama for T {
22+
fn fly(&self) {}
23+
}
24+
25+
impl SpaceLlama for i32 {
26+
default fn fly(&self) {} //~ ERROR E0520
27+
}
28+
29+
fn main() {
30+
}

src/test/compile-fail/E0522.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+
#![feature(lang_items)]
12+
13+
#[lang = "cookie"]
14+
fn cookie() -> ! { //~ E0522
15+
loop {}
16+
}

src/test/compile-fail/E0527.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+
#![feature(slice_patterns)]
12+
13+
fn main() {
14+
let r = &[1, 2, 3, 4];
15+
match r {
16+
&[a, b] => { //~ ERROR E0527
17+
println!("a={}, b={}", a, b);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)