cherry-pick over the tests I wrote for the reachability code
For the most part, the current code performs similarly, although it differs in some particulars. I'll be nice to have these tests for judging future changes, as well.
This commit is contained in:
parent
a60e27e25b
commit
609bfe82fd
7
src/test/ui/reachable/README.md
Normal file
7
src/test/ui/reachable/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
A variety of tests around reachability. These tests in general check
|
||||
two things:
|
||||
|
||||
- that we get unreachable code warnings in reasonable locations;
|
||||
- that we permit coercions **into** `!` from expressions which
|
||||
diverge, where an expression "diverges" if it must execute some
|
||||
subexpression of type `!`, or it has type `!` itself.
|
28
src/test/ui/reachable/expr_add.rs
Normal file
28
src/test/ui/reachable/expr_add.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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(never_type)]
|
||||
#![allow(unused_variables)]
|
||||
#![deny(unreachable_code)]
|
||||
|
||||
use std::ops;
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl ops::Add<!> for Foo {
|
||||
type Output = !;
|
||||
fn add(self, rhs: !) -> ! {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Foo + return;
|
||||
}
|
14
src/test/ui/reachable/expr_add.stderr
Normal file
14
src/test/ui/reachable/expr_add.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_add.rs:27:13
|
||||
|
|
||||
27 | let x = Foo + return;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_add.rs:13:9
|
||||
|
|
||||
13 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
20
src/test/ui/reachable/expr_again.rs
Normal file
20
src/test/ui/reachable/expr_again.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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)]
|
||||
#![allow(unused_variables)]
|
||||
#![deny(unreachable_code)]
|
||||
|
||||
fn main() {
|
||||
let x = loop {
|
||||
continue;
|
||||
println!("hi");
|
||||
};
|
||||
}
|
15
src/test/ui/reachable/expr_again.stderr
Normal file
15
src/test/ui/reachable/expr_again.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_again.rs:18:9
|
||||
|
|
||||
18 | println!("hi");
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_again.rs:13:9
|
||||
|
|
||||
13 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: aborting due to previous error
|
||||
|
21
src/test/ui/reachable/expr_andand.rs
Normal file
21
src/test/ui/reachable/expr_andand.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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
|
||||
fn foo() {
|
||||
// No error here.
|
||||
let x = false && (return);
|
||||
println!("I am not dead.");
|
||||
}
|
||||
|
||||
fn main() { }
|
0
src/test/ui/reachable/expr_andand.stderr
Normal file
0
src/test/ui/reachable/expr_andand.stderr
Normal file
28
src/test/ui/reachable/expr_array.rs
Normal file
28
src/test/ui/reachable/expr_array.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn a() {
|
||||
// the `22` is unreachable:
|
||||
let x: [usize; 2] = [return, 22];
|
||||
}
|
||||
|
||||
fn b() {
|
||||
// the `array is unreachable:
|
||||
let x: [usize; 2] = [22, return];
|
||||
}
|
||||
|
||||
fn main() { }
|
20
src/test/ui/reachable/expr_array.stderr
Normal file
20
src/test/ui/reachable/expr_array.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_array.rs:20:34
|
||||
|
|
||||
20 | let x: [usize; 2] = [return, 22];
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_array.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_array.rs:25:25
|
||||
|
|
||||
25 | let x: [usize; 2] = [22, return];
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
39
src/test/ui/reachable/expr_assign.rs
Normal file
39
src/test/ui/reachable/expr_assign.rs
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn foo() {
|
||||
// No error here.
|
||||
let x;
|
||||
x = return;
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
use std::ptr;
|
||||
let p: *mut ! = ptr::null_mut::<!>();
|
||||
unsafe {
|
||||
// Here we consider the `return` unreachable because
|
||||
// "evaluating" the `*p` has type `!`. This is somewhat
|
||||
// dubious, I suppose.
|
||||
*p = return;
|
||||
}
|
||||
}
|
||||
|
||||
fn baz() {
|
||||
let mut i = 0;
|
||||
*{return; &mut i} = 22;
|
||||
}
|
||||
|
||||
fn main() { }
|
26
src/test/ui/reachable/expr_assign.stderr
Normal file
26
src/test/ui/reachable/expr_assign.stderr
Normal file
@ -0,0 +1,26 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_assign.rs:20:5
|
||||
|
|
||||
20 | x = return;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_assign.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_assign.rs:30:14
|
||||
|
|
||||
30 | *p = return;
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_assign.rs:36:15
|
||||
|
|
||||
36 | *{return; &mut i} = 22;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
41
src/test/ui/reachable/expr_block.rs
Normal file
41
src/test/ui/reachable/expr_block.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn a() {
|
||||
// Here the tail expression is considered unreachable:
|
||||
let x = {
|
||||
return;
|
||||
22
|
||||
};
|
||||
}
|
||||
|
||||
fn b() {
|
||||
// Here the `x` assignment is considered unreachable, not the block:
|
||||
let x = {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
fn c() {
|
||||
// Here the `println!` is unreachable:
|
||||
let x = {
|
||||
return;
|
||||
println!("foo");
|
||||
22
|
||||
};
|
||||
}
|
||||
|
||||
fn main() { }
|
22
src/test/ui/reachable/expr_block.stderr
Normal file
22
src/test/ui/reachable/expr_block.stderr
Normal file
@ -0,0 +1,22 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_block.rs:21:9
|
||||
|
|
||||
21 | 22
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_block.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_block.rs:36:9
|
||||
|
|
||||
36 | println!("foo");
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
18
src/test/ui/reachable/expr_box.rs
Normal file
18
src/test/ui/reachable/expr_box.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.
|
||||
|
||||
#![feature(box_syntax)]
|
||||
#![allow(unused_variables)]
|
||||
#![deny(unreachable_code)]
|
||||
|
||||
fn main() {
|
||||
let x = box return;
|
||||
println!("hi");
|
||||
}
|
14
src/test/ui/reachable/expr_box.stderr
Normal file
14
src/test/ui/reachable/expr_box.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_box.rs:16:13
|
||||
|
|
||||
16 | let x = box return;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_box.rs:13:9
|
||||
|
|
||||
13 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
31
src/test/ui/reachable/expr_call.rs
Normal file
31
src/test/ui/reachable/expr_call.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn foo(x: !, y: usize) { }
|
||||
|
||||
fn bar(x: !) { }
|
||||
|
||||
fn a() {
|
||||
// the `22` is unreachable:
|
||||
foo(return, 22);
|
||||
}
|
||||
|
||||
fn b() {
|
||||
// the call is unreachable:
|
||||
bar(return);
|
||||
}
|
||||
|
||||
fn main() { }
|
20
src/test/ui/reachable/expr_call.stderr
Normal file
20
src/test/ui/reachable/expr_call.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_call.rs:23:17
|
||||
|
|
||||
23 | foo(return, 22);
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_call.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_call.rs:28:5
|
||||
|
|
||||
28 | bar(return);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
23
src/test/ui/reachable/expr_cast.rs
Normal file
23
src/test/ui/reachable/expr_cast.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn a() {
|
||||
// the cast is unreachable:
|
||||
let x = {return} as !;
|
||||
}
|
||||
|
||||
fn main() { }
|
14
src/test/ui/reachable/expr_cast.stderr
Normal file
14
src/test/ui/reachable/expr_cast.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_cast.rs:20:13
|
||||
|
|
||||
20 | let x = {return} as !;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_cast.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
41
src/test/ui/reachable/expr_if.rs
Normal file
41
src/test/ui/reachable/expr_if.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn foo() {
|
||||
if {return} {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
if {true} {
|
||||
return;
|
||||
}
|
||||
println!("I am not dead.");
|
||||
}
|
||||
|
||||
fn baz() {
|
||||
if {true} {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// As the next action to be taken after the if arms, we should
|
||||
// report the `println!` as unreachable:
|
||||
println!("But I am.");
|
||||
}
|
||||
|
||||
fn main() { }
|
15
src/test/ui/reachable/expr_if.stderr
Normal file
15
src/test/ui/reachable/expr_if.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_if.rs:38:5
|
||||
|
|
||||
38 | println!("But I am.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_if.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: aborting due to previous error
|
||||
|
44
src/test/ui/reachable/expr_loop.rs
Normal file
44
src/test/ui/reachable/expr_loop.rs
Normal file
@ -0,0 +1,44 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn a() {
|
||||
loop { return; }
|
||||
println!("I am dead.");
|
||||
}
|
||||
|
||||
fn b() {
|
||||
loop {
|
||||
break;
|
||||
}
|
||||
println!("I am not dead.");
|
||||
}
|
||||
|
||||
fn c() {
|
||||
loop { return; }
|
||||
println!("I am dead.");
|
||||
}
|
||||
|
||||
fn d() {
|
||||
'outer: loop { loop { break 'outer; } }
|
||||
println!("I am not dead.");
|
||||
}
|
||||
|
||||
fn e() {
|
||||
loop { 'middle: loop { loop { break 'middle; } } }
|
||||
println!("I am dead.");
|
||||
}
|
||||
|
||||
fn main() { }
|
31
src/test/ui/reachable/expr_loop.stderr
Normal file
31
src/test/ui/reachable/expr_loop.stderr
Normal file
@ -0,0 +1,31 @@
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_loop.rs:19:5
|
||||
|
|
||||
19 | println!("I am dead.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_loop.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_loop.rs:31:5
|
||||
|
|
||||
31 | println!("I am dead.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_loop.rs:41:5
|
||||
|
|
||||
41 | println!("I am dead.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
54
src/test/ui/reachable/expr_match.rs
Normal file
54
src/test/ui/reachable/expr_match.rs
Normal file
@ -0,0 +1,54 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn a() {
|
||||
// The match is considered unreachable here, because the `return`
|
||||
// diverges:
|
||||
match {return} { }
|
||||
}
|
||||
|
||||
fn b() {
|
||||
match () { () => return }
|
||||
println!("I am dead");
|
||||
}
|
||||
|
||||
fn c() {
|
||||
match () { () if false => return, () => () }
|
||||
println!("I am not dead");
|
||||
}
|
||||
|
||||
fn d() {
|
||||
match () { () if false => return, () => return }
|
||||
println!("I am dead");
|
||||
}
|
||||
|
||||
fn e() {
|
||||
// Here the compiler fails to figure out that the `println` is dead.
|
||||
match () { () if return => (), () => return }
|
||||
println!("I am dead");
|
||||
}
|
||||
|
||||
fn f() {
|
||||
match Some(()) { None => (), Some(()) => return }
|
||||
println!("I am not dead");
|
||||
}
|
||||
|
||||
fn g() {
|
||||
match Some(()) { None => return, Some(()) => () }
|
||||
println!("I am not dead");
|
||||
}
|
||||
|
||||
fn main() { }
|
30
src/test/ui/reachable/expr_match.stderr
Normal file
30
src/test/ui/reachable/expr_match.stderr
Normal file
@ -0,0 +1,30 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_match.rs:20:5
|
||||
|
|
||||
20 | match {return} { }
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_match.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_match.rs:25:5
|
||||
|
|
||||
25 | println!("I am dead");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_match.rs:35:5
|
||||
|
|
||||
35 | println!("I am dead");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
34
src/test/ui/reachable/expr_method.rs
Normal file
34
src/test/ui/reachable/expr_method.rs
Normal file
@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
fn foo(&self, x: !, y: usize) { }
|
||||
fn bar(&self, x: !) { }
|
||||
}
|
||||
|
||||
fn a() {
|
||||
// the `22` is unreachable:
|
||||
Foo.foo(return, 22);
|
||||
}
|
||||
|
||||
fn b() {
|
||||
// the call is unreachable:
|
||||
Foo.bar(return);
|
||||
}
|
||||
|
||||
fn main() { }
|
20
src/test/ui/reachable/expr_method.stderr
Normal file
20
src/test/ui/reachable/expr_method.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_method.rs:26:21
|
||||
|
|
||||
26 | Foo.foo(return, 22);
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_method.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_method.rs:31:5
|
||||
|
|
||||
31 | Foo.bar(return);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
20
src/test/ui/reachable/expr_oror.rs
Normal file
20
src/test/ui/reachable/expr_oror.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
|
||||
fn foo() {
|
||||
let x = false || (return);
|
||||
println!("I am not dead.");
|
||||
}
|
||||
|
||||
fn main() { }
|
0
src/test/ui/reachable/expr_oror.stderr
Normal file
0
src/test/ui/reachable/expr_oror.stderr
Normal file
23
src/test/ui/reachable/expr_repeat.rs
Normal file
23
src/test/ui/reachable/expr_repeat.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn a() {
|
||||
// the repeat is unreachable:
|
||||
let x: [usize; 2] = [return; 2];
|
||||
}
|
||||
|
||||
fn main() { }
|
14
src/test/ui/reachable/expr_repeat.stderr
Normal file
14
src/test/ui/reachable/expr_repeat.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_repeat.rs:20:25
|
||||
|
|
||||
20 | let x: [usize; 2] = [return; 2];
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_repeat.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
24
src/test/ui/reachable/expr_return.rs
Normal file
24
src/test/ui/reachable/expr_return.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn a() {
|
||||
// Here we issue that the "2nd-innermost" return is unreachable,
|
||||
// but we stop there.
|
||||
let x = {return {return {return;}}};
|
||||
}
|
||||
|
||||
fn main() { }
|
14
src/test/ui/reachable/expr_return.stderr
Normal file
14
src/test/ui/reachable/expr_return.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_return.rs:21:22
|
||||
|
|
||||
21 | let x = {return {return {return;}}};
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_return.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
43
src/test/ui/reachable/expr_struct.rs
Normal file
43
src/test/ui/reachable/expr_struct.rs
Normal file
@ -0,0 +1,43 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
struct Foo {
|
||||
a: usize,
|
||||
b: usize,
|
||||
}
|
||||
|
||||
fn a() {
|
||||
// struct expr is unreachable:
|
||||
let x = Foo { a: 22, b: 33, ..return };
|
||||
}
|
||||
|
||||
fn b() {
|
||||
// the `33` is unreachable:
|
||||
let x = Foo { a: return, b: 33, ..return };
|
||||
}
|
||||
|
||||
fn c() {
|
||||
// the `..return` is unreachable:
|
||||
let x = Foo { a: 22, b: return, ..return };
|
||||
}
|
||||
|
||||
fn d() {
|
||||
// the struct expr is unreachable:
|
||||
let x = Foo { a: 22, b: return };
|
||||
}
|
||||
|
||||
fn main() { }
|
32
src/test/ui/reachable/expr_struct.stderr
Normal file
32
src/test/ui/reachable/expr_struct.stderr
Normal file
@ -0,0 +1,32 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:25:13
|
||||
|
|
||||
25 | let x = Foo { a: 22, b: 33, ..return };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_struct.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:30:33
|
||||
|
|
||||
30 | let x = Foo { a: return, b: 33, ..return };
|
||||
| ^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:35:39
|
||||
|
|
||||
35 | let x = Foo { a: 22, b: return, ..return };
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:40:13
|
||||
|
|
||||
40 | let x = Foo { a: 22, b: return };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
28
src/test/ui/reachable/expr_tup.rs
Normal file
28
src/test/ui/reachable/expr_tup.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn a() {
|
||||
// the `2` is unreachable:
|
||||
let x: (usize, usize) = (return, 2);
|
||||
}
|
||||
|
||||
fn b() {
|
||||
// the tuple is unreachable:
|
||||
let x: (usize, usize) = (2, return);
|
||||
}
|
||||
|
||||
fn main() { }
|
20
src/test/ui/reachable/expr_tup.stderr
Normal file
20
src/test/ui/reachable/expr_tup.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_tup.rs:20:38
|
||||
|
|
||||
20 | let x: (usize, usize) = (return, 2);
|
||||
| ^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_tup.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_tup.rs:25:29
|
||||
|
|
||||
25 | let x: (usize, usize) = (2, return);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
23
src/test/ui/reachable/expr_type.rs
Normal file
23
src/test/ui/reachable/expr_type.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
#![feature(type_ascription)]
|
||||
|
||||
fn a() {
|
||||
// the cast is unreachable:
|
||||
let x = {return}: !;
|
||||
}
|
||||
|
||||
fn main() { }
|
14
src/test/ui/reachable/expr_type.stderr
Normal file
14
src/test/ui/reachable/expr_type.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_type.rs:20:13
|
||||
|
|
||||
20 | let x = {return}: !;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_type.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
21
src/test/ui/reachable/expr_unary.rs
Normal file
21
src/test/ui/reachable/expr_unary.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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn foo() {
|
||||
let x: ! = ! { return; 22 };
|
||||
}
|
||||
|
||||
fn main() { }
|
8
src/test/ui/reachable/expr_unary.stderr
Normal file
8
src/test/ui/reachable/expr_unary.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: cannot apply unary operator `!` to type `!`
|
||||
--> $DIR/expr_unary.rs:18:16
|
||||
|
|
||||
18 | let x: ! = ! { return; 22 };
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
38
src/test/ui/reachable/expr_while.rs
Normal file
38
src/test/ui/reachable/expr_while.rs
Normal file
@ -0,0 +1,38 @@
|
||||
// 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.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
#![allow(dead_code)]
|
||||
#![deny(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn foo() {
|
||||
while {return} {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
while {true} {
|
||||
return;
|
||||
}
|
||||
println!("I am not dead.");
|
||||
}
|
||||
|
||||
fn baz() {
|
||||
// Here, we cite the `while` loop as dead.
|
||||
while {return} {
|
||||
println!("I am dead.");
|
||||
}
|
||||
println!("I am, too.");
|
||||
}
|
||||
|
||||
fn main() { }
|
31
src/test/ui/reachable/expr_while.stderr
Normal file
31
src/test/ui/reachable/expr_while.stderr
Normal file
@ -0,0 +1,31 @@
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_while.rs:19:9
|
||||
|
|
||||
19 | println!("Hello, world!");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_while.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_while.rs:33:9
|
||||
|
|
||||
33 | println!("I am dead.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_while.rs:35:5
|
||||
|
|
||||
35 | println!("I am, too.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user