Skip to content

Commit 5daf5b3

Browse files
committed
fix: extra semicolon, only create callsite once
1 parent 4e4f091 commit 5daf5b3

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

clippy_lints/src/strings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
161161
if path.ident.name == "as_bytes" {
162162
if let ExprKind::Lit(ref lit) = args[0].node {
163163
if let LitKind::Str(ref lit_content, _) = lit.node {
164-
let callsite = snippet(cx, args[0].span.source_callsite(), "");
164+
let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#);
165165
let expanded = format!("\"{}\"", lit_content.as_str());
166166
if callsite.starts_with("include_str!") {
167167
span_lint_and_sugg(

tests/ui/strings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ fn both() {
4949
fn str_lit_as_bytes() {
5050
let bs = "hello there".as_bytes();
5151

52+
let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
53+
5254
// no warning, because this cannot be written as a byte string literal:
5355
let ubs = "☃".as_bytes();
5456

@@ -57,13 +59,14 @@ fn str_lit_as_bytes() {
5759
let includestr = include_str!("entry.rs").as_bytes();
5860
}
5961

62+
#[allow(clippy::assign_op_pattern)]
6063
fn main() {
6164
add_only();
6265
add_assign_only();
6366
both();
6467

6568
// the add is only caught for `String`
6669
let mut x = 1;
67-
; x = x + 1;
70+
x = x + 1;
6871
assert_eq!(2, x);
6972
}

tests/ui/strings.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,10 @@ error: calling `as_bytes()` on a string literal
6161
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`
6262

6363
error: calling `as_bytes()` on `include_str!(..)`
64-
--> $DIR/strings.rs:57:22
64+
--> $DIR/strings.rs:59:22
6565
|
66-
57 | let includestr = include_str!("entry.rs").as_bytes();
66+
59 | let includestr = include_str!("entry.rs").as_bytes();
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("entry.rs")`
6868

69-
error: manual implementation of an assign operation
70-
--> $DIR/strings.rs:67:6
71-
|
72-
67 | ; x = x + 1;
73-
| ^^^^^^^^^ help: replace it with: `x += 1`
74-
75-
error: aborting due to 11 previous errors
69+
error: aborting due to 10 previous errors
7670

0 commit comments

Comments
 (0)