Skip to content

Commit 3db3153

Browse files
Add ui test for function_casts_as_integer lint
1 parent a92fad8 commit 3db3153

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
3+
#![deny(function_casts_as_integer)]
4+
#![allow(unused_variables)] // For the rustfix-ed code.
5+
6+
fn foo() {}
7+
8+
fn main() {
9+
let x = foo as fn() as usize; //~ ERROR: function_casts_as_integer
10+
let x = String::len as for<'a> fn(&'a String) -> usize as usize; //~ ERROR: function_casts_as_integer
11+
// Ok.
12+
let x = foo as fn() as usize;
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
3+
#![deny(function_casts_as_integer)]
4+
#![allow(unused_variables)] // For the rustfix-ed code.
5+
6+
fn foo() {}
7+
8+
fn main() {
9+
let x = foo as usize; //~ ERROR: function_casts_as_integer
10+
let x = String::len as usize; //~ ERROR: function_casts_as_integer
11+
// Ok.
12+
let x = foo as fn() as usize;
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: casting a function into an integer implicitly
2+
--> $DIR/function_casts_as_integer.rs:9:17
3+
|
4+
LL | let x = foo as usize;
5+
| ^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/function_casts_as_integer.rs:3:9
9+
|
10+
LL | #![deny(function_casts_as_integer)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: add `fn() as usize`
13+
|
14+
LL | let x = foo as fn() as usize;
15+
| +++++++
16+
17+
error: casting a function into an integer implicitly
18+
--> $DIR/function_casts_as_integer.rs:10:25
19+
|
20+
LL | let x = String::len as usize;
21+
| ^^^^^^^^
22+
|
23+
help: add `for<'a> fn(&'a String) -> usize as usize`
24+
|
25+
LL | let x = String::len as for<'a> fn(&'a String) -> usize as usize;
26+
| ++++++++++++++++++++++++++++++++++
27+
28+
error: aborting due to 2 previous errors
29+

0 commit comments

Comments
 (0)