Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f9020bb

Browse files
committed
fix: extra semicolon, only create callsite once
1 parent c209fc9 commit f9020bb

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

clippy_lints/src/strings.rs

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

tests/ui/strings.rs

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

62+
let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
63+
6264
// no warning, because this cannot be written as a byte string literal:
6365
let ubs = "☃".as_bytes();
6466

@@ -67,13 +69,14 @@ fn str_lit_as_bytes() {
6769
let includestr = include_str!("entry.rs").as_bytes();
6870
}
6971

72+
#[allow(clippy::assign_op_pattern)]
7073
fn main() {
7174
add_only();
7275
add_assign_only();
7376
both();
7477

7578
// the add is only caught for `String`
7679
let mut x = 1;
77-
; x = x + 1;
80+
x = x + 1;
7881
assert_eq!(2, x);
7982
}

tests/ui/strings.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,3 @@ error: calling `as_bytes()` on a string literal
6060
|
6161
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`
6262

63-
error: aborting due to 11 previous errors
64-

0 commit comments

Comments
 (0)