Skip to content

Commit 5f85f73

Browse files
committed
[Clippy] Swap unnecessary_owned_empty_strings to use diagnostic item instead of path
1 parent 5f42ae1 commit 5f85f73

File tree

4 files changed

+3
-3
lines changed

4 files changed

+3
-3
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ symbols! {
18931893
string_deref_patterns,
18941894
string_from_utf8,
18951895
string_insert_str,
1896+
string_new,
18961897
string_push_str,
18971898
stringify,
18981899
struct_field_attributes,

library/alloc/src/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ impl String {
440440
/// ```
441441
#[inline]
442442
#[rustc_const_stable(feature = "const_string_new", since = "1.39.0")]
443+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_new")]
443444
#[stable(feature = "rust1", since = "1.0.0")]
444445
#[must_use]
445446
pub const fn new() -> String {

src/tools/clippy/clippy_lints/src/unnecessary_owned_empty_strings.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::ty::is_type_lang_item;
3-
use clippy_utils::{match_def_path, paths};
43
use rustc_ast::ast::LitKind;
54
use rustc_errors::Applicability;
65
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
@@ -42,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings {
4241
&& let ty::Ref(_, inner_str, _) = cx.typeck_results().expr_ty_adjusted(expr).kind()
4342
&& inner_str.is_str()
4443
{
45-
if match_def_path(cx, fun_def_id, &paths::STRING_NEW) {
44+
if cx.tcx.is_diagnostic_item(sym::string_new, fun_def_id) {
4645
span_lint_and_sugg(
4746
cx,
4847
UNNECESSARY_OWNED_EMPTY_STRINGS,

src/tools/clippy/clippy_utils/src/paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub const SERDE_DESERIALIZE: [&str; 3] = ["serde", "de", "Deserialize"];
5151
pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
5252
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
5353
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
54-
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
5554
pub const SYMBOL: [&str; 3] = ["rustc_span", "symbol", "Symbol"];
5655
pub const SYMBOL_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"];
5756
pub const SYMBOL_INTERN: [&str; 4] = ["rustc_span", "symbol", "Symbol", "intern"];

0 commit comments

Comments
 (0)