use if_chain::if_chain;
use crate::utils::SpanlessEq;
-use crate::utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty};
+use crate::utils::{get_parent_expr, is_allowed, is_type_diagnostic_item, span_lint, span_lint_and_sugg, walk_ptrs_ty};
declare_clippy_lint! {
/// **What it does:** Checks for string appends of the form `x = x + y` (without
/// ```rust
/// let mut x = "Hello".to_owned();
/// x = x + ", World";
+ ///
+ /// // More readable
+ /// x += ", World";
+ /// x.push_str(", World");
/// ```
pub STRING_ADD_ASSIGN,
pedantic,
///
/// **Example:**
/// ```rust
+ /// // Bad
/// let bs = "a byte string".as_bytes();
+ ///
+ /// // Good
+ /// let bs = b"a byte string";
/// ```
pub STRING_LIT_AS_BYTES,
style,
}
fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
- match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), &paths::STRING)
+ is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), sym!(string_type))
}
fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool {