From f9020bb2dded44e97fd997ab71ab4edf6d88033b Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Wed, 24 Oct 2018 11:49:39 -0400 Subject: [PATCH] fix: extra semicolon, only create callsite once --- clippy_lints/src/strings.rs | 2 +- tests/ui/strings.rs | 5 ++++- tests/ui/strings.stderr | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 9b6478fb9cd6..fe3d461ab43a 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -171,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes { if path.ident.name == "as_bytes" { if let ExprKind::Lit(ref lit) = args[0].node { if let LitKind::Str(ref lit_content, _) = lit.node { - let callsite = snippet(cx, args[0].span.source_callsite(), ""); + let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#); let expanded = format!("\"{}\"", lit_content.as_str()); if callsite.starts_with("include_str!") { span_lint_and_sugg( diff --git a/tests/ui/strings.rs b/tests/ui/strings.rs index 6693776a9617..d2062b356dc0 100644 --- a/tests/ui/strings.rs +++ b/tests/ui/strings.rs @@ -59,6 +59,8 @@ fn both() { fn str_lit_as_bytes() { let bs = "hello there".as_bytes(); + let bs = r###"raw string with three ### in it and some " ""###.as_bytes(); + // no warning, because this cannot be written as a byte string literal: let ubs = "☃".as_bytes(); @@ -67,6 +69,7 @@ fn str_lit_as_bytes() { let includestr = include_str!("entry.rs").as_bytes(); } +#[allow(clippy::assign_op_pattern)] fn main() { add_only(); add_assign_only(); @@ -74,6 +77,6 @@ fn main() { // the add is only caught for `String` let mut x = 1; -; x = x + 1; + x = x + 1; assert_eq!(2, x); } diff --git a/tests/ui/strings.stderr b/tests/ui/strings.stderr index 8a93733732ea..2496270ba0d5 100644 --- a/tests/ui/strings.stderr +++ b/tests/ui/strings.stderr @@ -60,5 +60,3 @@ error: calling `as_bytes()` on a string literal | = note: `-D clippy::string-lit-as-bytes` implied by `-D warnings` -error: aborting due to 11 previous errors -