Use suggestion for redundant_closure

This commit is contained in:
Seo Sanghyeon
2015-12-08 15:03:01 +09:00
parent 98c4dc185c
commit 35b5c3efdd
3 changed files with 21 additions and 7 deletions

View File

@@ -195,6 +195,11 @@ pub fn snippet<'a, T: LintContext>(cx: &T, span: Span, default: &'a str) -> Cow<
cx.sess().codemap().span_to_snippet(span).map(From::from).unwrap_or(Cow::Borrowed(default))
}
/// Converts a span to a code snippet. Returns None if not available.
pub fn snippet_opt<T: LintContext>(cx: &T, span: Span) -> Option<String> {
cx.sess().codemap().span_to_snippet(span).ok()
}
/// convert a span (from a block) to a code snippet if available, otherwise use default, e.g.
/// `snippet(cx, expr.span, "..")`
/// This trims the code of indentation, except for the first line