1
Fork 0

Added documentation for function_item_references lint

Added documentation for `function_item_references` lint to the rustc book and
fixed comments in the lint checker itself.
This commit is contained in:
Ayrton 2020-10-21 17:19:21 -04:00
parent d6fa7e15d6
commit 935fc3642a
5 changed files with 105 additions and 73 deletions

View file

@ -2648,6 +2648,30 @@ declare_lint! {
}
declare_lint! {
/// The `function_item_references` lint detects function references that are
/// formatted with [`fmt::Pointer`] or transmuted.
///
/// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
///
/// ### Example
///
/// ```rust
/// fn foo() { }
///
/// fn main() {
/// println!("{:p}", &foo);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Taking a reference to a function may be mistaken as a way to obtain a
/// pointer to that function. This can give unexpected results when
/// formatting the reference as a pointer or transmuting it. This lint is
/// issued when function references are formatted as pointers, passed as
/// arguments bound by [`fmt::Pointer`] or transmuted.
pub FUNCTION_ITEM_REFERENCES,
Warn,
"suggest casting functions to pointers when attempting to take references",