Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed lint to suggest casting to the proper function type and added…
… a test
- Loading branch information
Showing
3 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// check-pass | ||
fn foo() -> usize { 42 } | ||
fn bar(x: usize) -> usize { x } | ||
fn baz(x: usize, y: usize) -> usize { x + y } | ||
|
||
fn main() { | ||
println!("{:p}", &foo); | ||
//~^ WARN cast `foo` with `as *const fn() -> _` to use it as a pointer | ||
println!("{:p}", &bar); | ||
//~^ WARN cast `bar` with `as *const fn(_) -> _` to use it as a pointer | ||
println!("{:p}", &baz); | ||
//~^ WARN cast `baz` with `as *const fn(_, _) -> _` to use it as a pointer | ||
|
||
//should not produce any warnings | ||
println!("{:p}", foo as *const fn() -> usize); | ||
println!("{:p}", bar as *const fn(usize) -> usize); | ||
println!("{:p}", baz as *const fn(usize, usize) -> usize); | ||
|
||
//should not produce any warnings | ||
let fn_thing = foo; | ||
println!("{:p}", &fn_thing); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
warning: cast `foo` with `as *const fn() -> _` to use it as a pointer | ||
--> $DIR/function-references.rs:7:23 | ||
| | ||
LL | println!("{:p}", &foo); | ||
| ^^^ | ||
| | ||
= note: `#[warn(function_references)]` on by default | ||
|
||
warning: cast `bar` with `as *const fn(_) -> _` to use it as a pointer | ||
--> $DIR/function-references.rs:9:23 | ||
| | ||
LL | println!("{:p}", &bar); | ||
| ^^^ | ||
|
||
warning: cast `baz` with `as *const fn(_, _) -> _` to use it as a pointer | ||
--> $DIR/function-references.rs:11:23 | ||
| | ||
LL | println!("{:p}", &baz); | ||
| ^^^ | ||
|
||
warning: 3 warnings emitted | ||
|