about summary refs log tree commit diff
path: root/compiler/rustc_session/src
diff options
context:
space:
mode:
authorAyrton <a.munoz3327@gmail.com>2020-10-21 17:19:21 -0400
committerAyrton <a.munoz3327@gmail.com>2020-10-27 11:04:04 -0400
commit935fc3642a61e1545e1b98bf4716acbb7bf12e91 (patch)
tree2b7c3e0fd656b9c28fdcac2baf5ce829624d3997 /compiler/rustc_session/src
parentd6fa7e15d6679a1c01a6b4c32400f571d04c6a6c (diff)
downloadrust-935fc3642a61e1545e1b98bf4716acbb7bf12e91.tar.gz
rust-935fc3642a61e1545e1b98bf4716acbb7bf12e91.zip
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.
Diffstat (limited to 'compiler/rustc_session/src')
-rw-r--r--compiler/rustc_session/src/lint/builtin.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_session/src/lint/builtin.rs b/compiler/rustc_session/src/lint/builtin.rs
index 41abdacb54c..806f79af277 100644
--- a/compiler/rustc_session/src/lint/builtin.rs
+++ b/compiler/rustc_session/src/lint/builtin.rs
@@ -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",