Skip to content

Commit 9c27fc7

Browse files
authored
Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot
Remove `from` lang item It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item.
2 parents edd27cf + 312020e commit 9c27fc7

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

compiler/rustc_hir/src/lang_items.rs

-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ language_item_table! {
302302
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
303303
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
304304

305-
FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
306-
307305
OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
308306
OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;
309307

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ symbols! {
740740
frem_fast,
741741
from,
742742
from_desugaring,
743+
from_fn,
743744
from_iter,
744745
from_method,
745746
from_output,

library/core/src/convert/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ pub trait Into<T>: Sized {
542542
#[const_trait]
543543
pub trait From<T>: Sized {
544544
/// Converts to this type from the input type.
545-
#[lang = "from"]
545+
#[rustc_diagnostic_item = "from_fn"]
546546
#[must_use]
547547
#[stable(feature = "rust1", since = "1.0.0")]
548548
fn from(value: T) -> Self;

src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
4949
(arg, arg.span)
5050
},
5151
ExprKind::Call(path, [arg])
52-
if path_def_id(cx, path).map_or(false, |id| {
53-
if match_def_path(cx, id, &paths::FROM_STR_METHOD) {
52+
if path_def_id(cx, path).map_or(false, |did| {
53+
if match_def_path(cx, did, &paths::FROM_STR_METHOD) {
5454
true
55-
} else if cx.tcx.lang_items().from_fn() == Some(id) {
55+
} else if cx.tcx.is_diagnostic_item(sym::from_fn, did) {
5656
!is_copy(cx, typeck.expr_ty(expr))
5757
} else {
5858
false

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::ty;
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
10+
use rustc_span::symbol::sym;
1011

1112
declare_clippy_lint! {
1213
/// ### What it does
@@ -54,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings {
5455
);
5556
} else {
5657
if_chain! {
57-
if Some(fun_def_id) == cx.tcx.lang_items().from_fn();
58+
if cx.tcx.is_diagnostic_item(sym::from_fn, fun_def_id);
5859
if let [.., last_arg] = args;
5960
if let ExprKind::Lit(spanned) = &last_arg.kind;
6061
if let LitKind::Str(symbol, _) = spanned.node;

src/tools/clippy/clippy_lints/src/useless_conversion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
161161
}
162162

163163
if_chain! {
164-
if Some(def_id) == cx.tcx.lang_items().from_fn();
164+
if cx.tcx.is_diagnostic_item(sym::from_fn, def_id);
165165
if same_type_and_consts(a, b);
166166

167167
then {

0 commit comments

Comments
 (0)