Skip to content

Commit 2c8f042

Browse files
committed
Add tests for privately/publicly uninhabited types in function signatures
1 parent 7d86754 commit 2c8f042

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/test/ui/uninhabited/uninhabited-function-parameter-warning.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@
22

33
enum Void {}
44

5+
mod hide {
6+
pub struct PrivatelyUninhabited(::Void);
7+
8+
pub struct PubliclyUninhabited(pub ::Void);
9+
}
10+
11+
// Check that functions with (publicly) uninhabited parameters trigger a lint.
12+
513
fn foo(a: (), b: Void) { //~ ERROR functions with parameters of uninhabited types are uncallable
614
a
715
}
816

17+
fn bar(a: (), b: hide::PrivatelyUninhabited) { // ok
18+
a
19+
}
20+
21+
fn baz(a: (), b: hide::PubliclyUninhabited) {
22+
//~^ ERROR functions with parameters of uninhabited types are uncallable
23+
a
24+
}
25+
26+
// Check that trait methods with uninhabited parameters do not trigger a lint
27+
// (at least for now).
28+
929
trait Foo {
1030
fn foo(a: Self);
1131

src/test/ui/uninhabited/uninhabited-function-parameter-warning.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: functions with parameters of uninhabited types are uncallable
2-
--> $DIR/uninhabited-function-parameter-warning.rs:5:1
2+
--> $DIR/uninhabited-function-parameter-warning.rs:13:1
33
|
44
LL | fn foo(a: (), b: Void) { //~ ERROR functions with parameters of uninhabited types are uncallable
55
| ^ - this parameter has an uninhabited type
@@ -15,5 +15,17 @@ note: lint level defined here
1515
LL | #![deny(unreachable_code)]
1616
| ^^^^^^^^^^^^^^^^
1717

18-
error: aborting due to previous error
18+
error: functions with parameters of uninhabited types are uncallable
19+
--> $DIR/uninhabited-function-parameter-warning.rs:21:1
20+
|
21+
LL | fn baz(a: (), b: hide::PubliclyUninhabited) {
22+
| ^ - this parameter has an uninhabited type
23+
| _|
24+
| |
25+
LL | | //~^ ERROR functions with parameters of uninhabited types are uncallable
26+
LL | | a
27+
LL | | }
28+
| |_^
29+
30+
error: aborting due to 2 previous errors
1931

0 commit comments

Comments
 (0)