about summary refs log tree commit diff
path: root/clippy_utils/src/source.rs
diff options
context:
space:
mode:
authorflip1995 <philipp.krones@embecosm.com>2021-04-22 11:24:26 +0200
committerflip1995 <philipp.krones@embecosm.com>2021-04-22 11:24:26 +0200
commit44c8057f4d48157193eaa9a7b5ced772cc6ae81a (patch)
tree10f507cafeacb62a974d92e99c22e2066fed463b /clippy_utils/src/source.rs
parent419bf6bbd827f07406447419d84a154ce9294aa8 (diff)
parent1f7aef336ea947e14cfabcb22538863e04a87e57 (diff)
downloadrust-44c8057f4d48157193eaa9a7b5ced772cc6ae81a.tar.gz
rust-44c8057f4d48157193eaa9a7b5ced772cc6ae81a.zip
Merge remote-tracking branch 'upstream/master' into rustup
Diffstat (limited to 'clippy_utils/src/source.rs')
-rw-r--r--clippy_utils/src/source.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs
index 2d794d48dc5..53180d1f9f5 100644
--- a/clippy_utils/src/source.rs
+++ b/clippy_utils/src/source.rs
@@ -66,6 +66,15 @@ pub fn indent_of<T: LintContext>(cx: &T, span: Span) -> Option<usize> {
     snippet_opt(cx, line_span(cx, span)).and_then(|snip| snip.find(|c: char| !c.is_whitespace()))
 }
 
+/// Gets a snippet of the indentation of the line of a span
+pub fn snippet_indent<T: LintContext>(cx: &T, span: Span) -> Option<String> {
+    snippet_opt(cx, line_span(cx, span)).map(|mut s| {
+        let len = s.len() - s.trim_start().len();
+        s.truncate(len);
+        s
+    })
+}
+
 // If the snippet is empty, it's an attribute that was inserted during macro
 // expansion and we want to ignore those, because they could come from external
 // sources that the user has no control over.