-use rustc::lint::in_external_macro;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Spanned;
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 {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
use crate::utils::{snippet, snippet_with_applicability};
- use syntax::ast::LitKind;
+ use rustc_ast::ast::LitKind;
if_chain! {
if let ExprKind::MethodCall(path, _, args) = &e.kind;