mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
fix: extra semicolon, only create callsite once
This commit is contained in:
parent
c209fc9349
commit
f9020bb2dd
3 changed files with 5 additions and 4 deletions
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue