Skip to content

Commit 64a17a0

Browse files
committed
Rm diagnostic item, use lang item
1 parent c74f155 commit 64a17a0

32 files changed

+103
-100
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
464464
ref_cnt += 1;
465465
}
466466
if let ty::Adt(adt, _) = peeled.kind()
467-
&& self.tcx.is_diagnostic_item(sym::String, adt.did())
467+
&& Some(adt.did()) == self.tcx.lang_items().string()
468468
{
469469
err.span_suggestion_verbose(
470470
expr.span.shrink_to_hi(),

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
817817
ty.is_str()
818818
|| matches!(
819819
ty.kind(),
820-
ty::Adt(adt, _) if self.tcx.is_diagnostic_item(sym::String, adt.did())
820+
ty::Adt(adt, _) if Some(adt.did()) == self.tcx.lang_items().string()
821821
)
822822
}
823-
ty::Adt(adt, _) => self.tcx.is_diagnostic_item(sym::String, adt.did()),
823+
ty::Adt(adt, _) => Some(adt.did()) == self.tcx.lang_items().string(),
824824
_ => false,
825825
};
826826
if is_string_or_ref_str && item_name.name == sym::iter {

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
556556
let rm_borrow_msg = "remove the borrow to obtain an owned `String`";
557557
let to_owned_msg = "create an owned `String` from a string reference";
558558

559+
let string_type = self.tcx.lang_items().string();
559560
let is_std_string = |ty: Ty<'tcx>| {
560-
ty.ty_adt_def()
561-
.map_or(false, |ty_def| self.tcx.is_diagnostic_item(sym::String, ty_def.did()))
561+
ty.ty_adt_def().map_or(false, |ty_def| Some(ty_def.did()) == string_type)
562562
};
563563

564564
match (lhs_ty.kind(), rhs_ty.kind()) {

compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
148148
ty::Ref(_, r, _) if *r.kind() == ty::Str,
149149
) || matches!(
150150
ty.ty_adt_def(),
151-
Some(ty_def) if cx.tcx.is_diagnostic_item(sym::String, ty_def.did()),
151+
Some(ty_def) if Some(ty_def.did()) == cx.tcx.lang_items().string(),
152152
);
153153

154154
let infcx = cx.tcx.infer_ctxt().build();

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
17051705
ty::Bool => Some(0),
17061706
ty::Char => Some(1),
17071707
ty::Str => Some(2),
1708-
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::String, def.did()) => Some(2),
1708+
ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().string() => Some(2),
17091709
ty::Int(..)
17101710
| ty::Uint(..)
17111711
| ty::Float(..)

library/alloc/src/string.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,8 @@ use crate::vec::Vec;
362362
/// [`Deref`]: core::ops::Deref "ops::Deref"
363363
/// [`as_str()`]: String::as_str
364364
#[derive(PartialOrd, Eq, Ord)]
365-
#[cfg_attr(not(test), rustc_diagnostic_item = "String")]
366365
#[stable(feature = "rust1", since = "1.0.0")]
367-
#[cfg_attr(not(bootstrap), lang = "String")]
366+
#[cfg_attr(all(not(bootstrap), not(test)), lang = "String")]
368367
pub struct String {
369368
vec: Vec<u8>,
370369
}

src/tools/clippy/clippy_lints/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
7373
if format_args.format_string.parts == [kw::Empty];
7474
if arg.format.is_default();
7575
if match cx.typeck_results().expr_ty(value).peel_refs().kind() {
76-
ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did()),
76+
ty::Adt(adt, _) => Some(adt.did()) == cx.tcx.lang_items().string(),
7777
ty::Str => true,
7878
_ => false,
7979
};

src/tools/clippy/clippy_lints/src/format_push_string.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::ty::is_type_diagnostic_item;
2+
use clippy_utils::ty::is_type_lang_item;
33
use clippy_utils::{match_def_path, paths, peel_hir_expr_refs};
4-
use rustc_hir::{BinOpKind, Expr, ExprKind};
4+
use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77
use rustc_span::sym;
@@ -41,7 +41,7 @@ declare_clippy_lint! {
4141
declare_lint_pass!(FormatPushString => [FORMAT_PUSH_STRING]);
4242

4343
fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
44-
is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym::String)
44+
is_type_lang_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), LangItem::String)
4545
}
4646
fn is_format(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
4747
if let Some(macro_def_id) = e.span.ctxt().outer_expn_data().macro_def_id {

src/tools/clippy/clippy_lints/src/from_str_radix_10.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::is_integer_literal;
33
use clippy_utils::sugg::Sugg;
4-
use clippy_utils::ty::is_type_diagnostic_item;
4+
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{def, Expr, ExprKind, PrimTy, QPath, TyKind};
7+
use rustc_hir::{def, Expr, ExprKind, LangItem, PrimTy, QPath, TyKind};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::ty::Ty;
1010
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -98,5 +98,5 @@ impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 {
9898

9999
/// Checks if a Ty is `String` or `&str`
100100
fn is_ty_stringish(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
101-
is_type_diagnostic_item(cx, ty, sym::String) || is_type_diagnostic_item(cx, ty, sym::str)
101+
is_type_lang_item(cx, ty, LangItem::String) || is_type_diagnostic_item(cx, ty, sym::str)
102102
}

src/tools/clippy/clippy_lints/src/inherent_to_string.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
2+
use clippy_utils::ty::{implements_trait, is_type_lang_item};
33
use clippy_utils::{return_ty, trait_ref_of_method};
44
use if_chain::if_chain;
5-
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind};
5+
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::sym;
@@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
105105
if impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. }));
106106

107107
// Check if return type is String
108-
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String);
108+
if is_type_lang_item(cx, return_ty(cx, impl_item.hir_id()), LangItem::String);
109109

110110
// Filters instances of to_string which are required by a trait
111111
if trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none();

0 commit comments

Comments
 (0)