fix: extra semicolon, only create callsite once

This commit is contained in:
Jane Lusby
2018-10-24 11:49:39 -04:00
parent c209fc9349
commit f9020bb2dd
3 changed files with 5 additions and 4 deletions

View File

@@ -171,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
if path.ident.name == "as_bytes" { if path.ident.name == "as_bytes" {
if let ExprKind::Lit(ref lit) = args[0].node { if let ExprKind::Lit(ref lit) = args[0].node {
if let LitKind::Str(ref lit_content, _) = lit.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()); let expanded = format!("\"{}\"", lit_content.as_str());
if callsite.starts_with("include_str!") { if callsite.starts_with("include_str!") {
span_lint_and_sugg( span_lint_and_sugg(

View File

@@ -59,6 +59,8 @@ fn both() {
fn str_lit_as_bytes() { fn str_lit_as_bytes() {
let bs = "hello there".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: // no warning, because this cannot be written as a byte string literal:
let ubs = "".as_bytes(); let ubs = "".as_bytes();
@@ -67,6 +69,7 @@ fn str_lit_as_bytes() {
let includestr = include_str!("entry.rs").as_bytes(); let includestr = include_str!("entry.rs").as_bytes();
} }
#[allow(clippy::assign_op_pattern)]
fn main() { fn main() {
add_only(); add_only();
add_assign_only(); add_assign_only();
@@ -74,6 +77,6 @@ fn main() {
// the add is only caught for `String` // the add is only caught for `String`
let mut x = 1; let mut x = 1;
; x = x + 1; x = x + 1;
assert_eq!(2, x); assert_eq!(2, x);
} }

View File

@@ -60,5 +60,3 @@ error: calling `as_bytes()` on a string literal
| |
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings` = note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`
error: aborting due to 11 previous errors