@@ -8,7 +8,7 @@ use rustc_front::hir::*;
8
8
use syntax:: codemap:: Spanned ;
9
9
use utils:: STRING_PATH ;
10
10
use utils:: SpanlessEq ;
11
- use utils:: { match_type, span_lint, walk_ptrs_ty, get_parent_expr} ;
11
+ use utils:: { match_type, span_lint, span_lint_and_then , walk_ptrs_ty, get_parent_expr} ;
12
12
13
13
/// **What it does:** This lint matches code of the form `x = x + y` (without `let`!).
14
14
///
@@ -141,11 +141,18 @@ impl LateLintPass for StringLitAsBytes {
141
141
if let ExprLit ( ref lit) = args[ 0 ] . node {
142
142
if let LitKind :: Str ( ref lit_content, _) = lit. node {
143
143
if lit_content. chars ( ) . all ( |c| c. is_ascii ( ) ) && !in_macro ( cx, args[ 0 ] . span ) {
144
- let msg = format ! ( "calling `as_bytes()` on a string literal. \
145
- Consider using a byte string literal instead: \
146
- `b{}`",
147
- snippet( cx, args[ 0 ] . span, r#""foo""# ) ) ;
148
- span_lint ( cx, STRING_LIT_AS_BYTES , e. span , & msg) ;
144
+ span_lint_and_then ( cx,
145
+ STRING_LIT_AS_BYTES ,
146
+ e. span ,
147
+ "calling `as_bytes()` on a string literal" ,
148
+ |db| {
149
+ let sugg = format ! ( "b{}" ,
150
+ snippet( cx, args[ 0 ] . span, r#""foo""# ) ) ;
151
+ db. span_suggestion ( e. span ,
152
+ "consider using a byte string literal instead" ,
153
+ sugg) ;
154
+ } ) ;
155
+
149
156
}
150
157
}
151
158
}
0 commit comments