Skip to content

Commit df3035a

Browse files
committed
Fix tests making use of uninhabited arguments
1 parent 2e04872 commit df3035a

10 files changed

+59
-28
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// run-pass
22
#![allow(dead_code)]
33
#![allow(unused_variables)]
4-
// pretty-expanded FIXME #23616
4+
#![allow(unreachable_code)]
55

6-
enum Foo { }
6+
enum Foo {}
77

88
impl Drop for Foo {
99
fn drop(&mut self) { }
1010
}
1111

12-
fn foo(x: Foo) { }
12+
fn foo() {
13+
let _x: Foo = unimplemented!();
14+
}
1315

1416
fn main() { }
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// run-pass
22
#![allow(dead_code)]
3+
#![allow(unused_variables)]
34
// pretty-expanded FIXME #23616
4-
#![allow(non_camel_case_types)]
55

6-
enum what { }
6+
enum Void {}
77

8-
fn what_to_string(x: what) -> String
9-
{
10-
match x {
11-
}
8+
fn void() -> Void {
9+
unimplemented!()
1210
}
1311

14-
pub fn main()
15-
{
12+
fn void_to_string() -> String {
13+
match void() {}
1614
}
15+
16+
pub fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: functions with parameters of uninhabited types are uncallable
2+
--> $DIR/issue-46855.rs:15:1
3+
|
4+
LL | fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 }
5+
| ^^^^^^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| this parameter has an uninhabited type
8+
|
9+
= note: #[warn(unreachable_code)] on by default
10+
11+
warning: functions with parameters of uninhabited types are uncallable
12+
--> $DIR/issue-46855.rs:17:1
13+
|
14+
LL | fn bar([(_, x)]: [(Never, u32); 1]) -> u32 { x }
15+
| ^^^^^^^--------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
| |
17+
| this parameter has an uninhabited type
18+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// run-pass
22
enum Void {}
3+
4+
#[allow(unreachable_code)]
35
fn foo(_: Result<(Void, u32), (Void, String)>) {}
6+
47
fn main() {
58
let _: fn(_) = foo;
69
}

src/test/run-pass/never-type-rvalues.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(dead_code)]
33
#![allow(path_statements)]
44
#![allow(unreachable_patterns)]
5+
#![allow(unreachable_code)]
56

67
fn never_direct(x: !) {
78
x;

src/test/ui/match/match-no-arms-unreachable-after.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
enum Void { }
55

6-
fn foo(v: Void) {
7-
match v { }
8-
let x = 2; //~ ERROR unreachable
6+
fn bar() -> Void {
7+
unreachable!()
98
}
109

11-
fn main() {
10+
fn foo() {
11+
match bar() { }
12+
let x = 2; //~ ERROR unreachable
1213
}
14+
15+
fn main() {}

src/test/ui/match/match-no-arms-unreachable-after.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unreachable statement
2-
--> $DIR/match-no-arms-unreachable-after.rs:8:5
2+
--> $DIR/match-no-arms-unreachable-after.rs:12:5
33
|
44
LL | let x = 2; //~ ERROR unreachable
55
| ^^^^^^^^^^

src/test/ui/reachable/expr_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#![allow(dead_code)]
55
#![deny(unreachable_code)]
66

7-
fn foo(x: !, y: usize) { }
7+
fn foo(x: (), y: usize) {}
88

9-
fn bar(x: !) { }
9+
fn bar(x: ()) {}
1010

1111
fn a() {
1212
// the `22` is unreachable:

src/test/ui/unreachable/unwarned-match-on-never.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
#![feature(never_type)]
2+
13
#![deny(unreachable_code)]
24
#![allow(dead_code)]
35

4-
#![feature(never_type)]
6+
fn never() -> ! {
7+
unimplemented!()
8+
}
59

6-
fn foo(x: !) -> bool {
10+
fn foo() -> bool {
711
// Explicit matches on the never type are unwarned.
8-
match x {}
12+
match never() {}
913
// But matches in unreachable code are warned.
10-
match x {} //~ ERROR unreachable expression
14+
match never() {} //~ ERROR unreachable expression
1115
}
1216

1317
fn bar() {

src/test/ui/unreachable/unwarned-match-on-never.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: unreachable expression
2-
--> $DIR/unwarned-match-on-never.rs:10:5
2+
--> $DIR/unwarned-match-on-never.rs:14:5
33
|
4-
LL | match x {} //~ ERROR unreachable expression
5-
| ^^^^^^^^^^
4+
LL | match never() {} //~ ERROR unreachable expression
5+
| ^^^^^^^^^^^^^^^^
66
|
77
note: lint level defined here
8-
--> $DIR/unwarned-match-on-never.rs:1:9
8+
--> $DIR/unwarned-match-on-never.rs:3:9
99
|
1010
LL | #![deny(unreachable_code)]
1111
| ^^^^^^^^^^^^^^^^
1212

1313
error: unreachable arm
14-
--> $DIR/unwarned-match-on-never.rs:15:15
14+
--> $DIR/unwarned-match-on-never.rs:19:15
1515
|
1616
LL | () => () //~ ERROR unreachable arm
1717
| ^^
1818

1919
error: unreachable expression
20-
--> $DIR/unwarned-match-on-never.rs:21:5
20+
--> $DIR/unwarned-match-on-never.rs:25:5
2121
|
2222
LL | / match () { //~ ERROR unreachable expression
2323
LL | | () => (),

0 commit comments

Comments
 (0)