Skip to content

Commit

Permalink
Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
matthiaskrgr committed Feb 26, 2023
2 parents edd27cf + 312020e commit 9c27fc7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ language_item_table! {
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ symbols! {
frem_fast,
from,
from_desugaring,
from_fn,
from_iter,
from_method,
from_output,
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub trait Into<T>: Sized {
#[const_trait]
pub trait From<T>: Sized {
/// Converts to this type from the input type.
#[lang = "from"]
#[rustc_diagnostic_item = "from_fn"]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn from(value: T) -> Self;
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
(arg, arg.span)
},
ExprKind::Call(path, [arg])
if path_def_id(cx, path).map_or(false, |id| {
if match_def_path(cx, id, &paths::FROM_STR_METHOD) {
if path_def_id(cx, path).map_or(false, |did| {
if match_def_path(cx, did, &paths::FROM_STR_METHOD) {
true
} else if cx.tcx.lang_items().from_fn() == Some(id) {
} else if cx.tcx.is_diagnostic_item(sym::from_fn, did) {
!is_copy(cx, typeck.expr_ty(expr))
} else {
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::sym;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -54,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings {
);
} else {
if_chain! {
if Some(fun_def_id) == cx.tcx.lang_items().from_fn();
if cx.tcx.is_diagnostic_item(sym::from_fn, fun_def_id);
if let [.., last_arg] = args;
if let ExprKind::Lit(spanned) = &last_arg.kind;
if let LitKind::Str(symbol, _) = spanned.node;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
}

if_chain! {
if Some(def_id) == cx.tcx.lang_items().from_fn();
if cx.tcx.is_diagnostic_item(sym::from_fn, def_id);
if same_type_and_consts(a, b);

then {
Expand Down

0 comments on commit 9c27fc7

Please sign in to comment.