about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2020-02-04 17:02:46 +0100
committerflip1995 <hello@philkrones.com>2020-02-06 19:15:01 +0100
commit250c1842b1e27c1eb6d174e8a954ea37a2f707bb (patch)
treecd82cf09cc2c739dc5015a586dd1979d3a260a93
parent7363728d18659c695453cc6f6923c70a2554b1d4 (diff)
downloadrust-250c1842b1e27c1eb6d174e8a954ea37a2f707bb.tar.gz
rust-250c1842b1e27c1eb6d174e8a954ea37a2f707bb.zip
Document the indent_relative_to arg of snippet_block
-rw-r--r--clippy_lints/src/utils/mod.rs34
1 files changed, 29 insertions, 5 deletions
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index b9a62382aa3..ed6d9f81cc9 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -534,16 +534,40 @@ pub fn snippet_opt<T: LintContext>(cx: &T, span: Span) -> Option<String> {
     cx.sess().source_map().span_to_snippet(span).ok()
 }
 
-/// Converts a span (from a block) to a code snippet if available, otherwise use
-/// default.
-/// This trims the code of indentation, except for the first line. Use it for
-/// blocks or block-like
+/// Converts a span (from a block) to a code snippet if available, otherwise use default.
+///
+/// This trims the code of indentation, except for the first line. Use it for blocks or block-like
 /// things which need to be printed as such.
 ///
+/// The `indent_relative_to` arg can be used, to provide a span, where the indentation of the
+/// resulting snippet of the given span.
+///
 /// # Example
+///
 /// ```rust,ignore
-/// snippet_block(cx, expr.span, "..", None)
+/// snippet_block(cx, block.span, "..", None)
+/// // where, `block` is the block of the if expr
+///     if x {
+///         y;
+///     }
+/// // will return the snippet
+/// {
+///     y;
+/// }
+/// ```
+///
+/// ```rust,ignore
+/// snippet_block(cx, block.span, "..", Some(if_expr.span))
+/// // where, `block` is the block of the if expr
+///     if x {
+///         y;
+///     }
+/// // will return the snippet
+/// {
+///         y;
+///     } // aligned with `if`
 /// ```
+/// Note that the first line of the snippet always has 0 indentation.
 pub fn snippet_block<'a, T: LintContext>(
     cx: &T,
     span: Span,