about summary refs log tree commit diff
path: root/clippy_utils/src/source.rs
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2021-11-04 12:09:48 +0100
committerxFrednet <xFrednet@gmail.com>2021-11-04 12:42:29 +0100
commitd134dddf706e16eb876a3b42c0a7f546626e5954 (patch)
tree1bd39b673f54f1ff06cb2bce2a719a440081515a /clippy_utils/src/source.rs
parent1011e083cd4b87c71ee042e07345dc547bcfc055 (diff)
downloadrust-d134dddf706e16eb876a3b42c0a7f546626e5954.tar.gz
rust-d134dddf706e16eb876a3b42c0a7f546626e5954.zip
Improve `clippy_utils` function docs
Diffstat (limited to 'clippy_utils/src/source.rs')
-rw-r--r--clippy_utils/src/source.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs
index 789079510c5..7f68cc388eb 100644
--- a/clippy_utils/src/source.rs
+++ b/clippy_utils/src/source.rs
@@ -155,14 +155,22 @@ fn reindent_multiline_inner(s: &str, ignore_first: bool, indent: Option<usize>,
         .join("\n")
 }
 
-/// Converts a span to a code snippet if available, otherwise use default.
+/// Converts a span to a code snippet if available, otherwise returns the default.
 ///
 /// This is useful if you want to provide suggestions for your lint or more generally, if you want
-/// to convert a given `Span` to a `str`.
+/// to convert a given `Span` to a `str`. To create suggestions consider using
+/// [`snippet_with_applicability`] to ensure that the applicability stays correct.
 ///
 /// # Example
 /// ```rust,ignore
-/// snippet(cx, expr.span, "..")
+/// // Given two spans one for `value` and one for the `init` expression.
+/// let value = Vec::new();
+/// //  ^^^^^   ^^^^^^^^^^
+/// //  span1   span2
+///
+/// // The snipped call would return the corresponding code snippet
+/// snippet(cx, span1, "..") // -> "value"
+/// snippet(cx, span2, "..") // -> "Vec::new()"
 /// ```
 pub fn snippet<'a, T: LintContext>(cx: &T, span: Span, default: &'a str) -> Cow<'a, str> {
     snippet_opt(cx, span).map_or_else(|| Cow::Borrowed(default), From::from)