[Clippy] Swap unnecessary_owned_empty_strings
to use diagnostic item instead of path
This commit is contained in:
parent
5f42ae13c1
commit
5f85f73f63
@ -1893,6 +1893,7 @@
|
||||
string_deref_patterns,
|
||||
string_from_utf8,
|
||||
string_insert_str,
|
||||
string_new,
|
||||
string_push_str,
|
||||
stringify,
|
||||
struct_field_attributes,
|
||||
|
@ -440,6 +440,7 @@ impl String {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[rustc_const_stable(feature = "const_string_new", since = "1.39.0")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "string_new")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
pub const fn new() -> String {
|
||||
|
@ -1,6 +1,5 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::ty::is_type_lang_item;
|
||||
use clippy_utils::{match_def_path, paths};
|
||||
use rustc_ast::ast::LitKind;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
|
||||
@ -42,7 +41,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
&& let ty::Ref(_, inner_str, _) = cx.typeck_results().expr_ty_adjusted(expr).kind()
|
||||
&& inner_str.is_str()
|
||||
{
|
||||
if match_def_path(cx, fun_def_id, &paths::STRING_NEW) {
|
||||
if cx.tcx.is_diagnostic_item(sym::string_new, fun_def_id) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
UNNECESSARY_OWNED_EMPTY_STRINGS,
|
||||
|
@ -51,7 +51,6 @@
|
||||
pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
|
||||
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
|
||||
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
|
||||
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
|
||||
pub const SYMBOL: [&str; 3] = ["rustc_span", "symbol", "Symbol"];
|
||||
pub const SYMBOL_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"];
|
||||
pub const SYMBOL_INTERN: [&str; 4] = ["rustc_span", "symbol", "Symbol", "intern"];
|
||||
|
Loading…
Reference in New Issue
Block a user