Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bbde7a

Browse files
committed
Make From a lang item
1 parent 2a06022 commit 2bbde7a

File tree

7 files changed

+11
-8
lines changed

7 files changed

+11
-8
lines changed

‎compiler/rustc_hir/src/lang_items.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ language_item_table! {
433433
// Experimental lang items for implementing contract pre- and post-condition checking.
434434
ContractBuildCheckEnsures, sym::contract_build_check_ensures, contract_build_check_ensures_fn, Target::Fn, GenericRequirement::None;
435435
ContractCheckRequires, sym::contract_check_requires, contract_check_requires_fn, Target::Fn, GenericRequirement::None;
436+
437+
// Used to fallback `{float}` to `f32` when `f32: From<{float}>`
438+
From, sym::From, from_trait, Target::Trait, GenericRequirement::Exact(1);
436439
}
437440

438441
/// The requirement imposed on the generics of a lang item

‎compiler/rustc_hir_typeck/src/cast.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_middle::ty::error::TypeError;
4343
use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, VariantDef, elaborate};
4444
use rustc_middle::{bug, span_bug};
4545
use rustc_session::lint;
46-
use rustc_span::{DUMMY_SP, Span, sym};
46+
use rustc_span::{DUMMY_SP, Span};
4747
use rustc_trait_selection::infer::InferCtxtExt;
4848
use tracing::{debug, instrument};
4949

@@ -487,7 +487,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
487487
let mut label = true;
488488
// Check `impl From<self.expr_ty> for self.cast_ty {}` for accurate suggestion:
489489
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span)
490-
&& let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::From)
490+
&& let Some(from_trait) = fcx.tcx.lang_items().from_trait()
491491
{
492492
let ty = fcx.resolve_vars_if_possible(self.cast_ty);
493493
// Erase regions to avoid panic in `prove_value` when calling

‎compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
22032203
/// within `?` desugaring.
22042204
pub fn is_try_conversion(&self, span: Span, trait_def_id: DefId) -> bool {
22052205
span.is_desugaring(DesugaringKind::QuestionMark)
2206-
&& self.tcx.is_diagnostic_item(sym::From, trait_def_id)
2206+
&& self.tcx.is_lang_item(trait_def_id,LangItem::From)
22072207
}
22082208

22092209
/// Structurally compares two types, modulo any inference variables.

‎compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
10631063
&& self
10641064
.infcx
10651065
.type_implements_trait(
1066-
self.tcx.get_diagnostic_item(sym::From).unwrap(),
1066+
self.tcx.lang_items().from_trait().unwrap(),
10671067
[self_ty, expr_ty],
10681068
obligation.param_env,
10691069
)
@@ -1122,7 +1122,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11221122
if self
11231123
.infcx
11241124
.type_implements_trait(
1125-
self.tcx.get_diagnostic_item(sym::From).unwrap(),
1125+
self.tcx.lang_items().from_trait().unwrap(),
11261126
[self_ty, err_ty],
11271127
obligation.param_env,
11281128
)

‎library/core/src/convert/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ pub trait Into<T>: Sized {
572572
/// [`String`]: ../../std/string/struct.String.html
573573
/// [`from`]: From::from
574574
/// [book]: ../../book/ch09-00-error-handling.html
575-
#[rustc_diagnostic_item = "From"]
575+
#[cfg_attr(not(bootstrap), lang = "From")]
576576
#[stable(feature = "rust1", since = "1.0.0")]
577577
#[rustc_on_unimplemented(on(
578578
all(_Self = "&str", T = "alloc::string::String"),

‎src/tools/clippy/clippy_lints/src/fallible_impl_from.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
5656
&& let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
5757
&& cx
5858
.tcx
59-
.is_diagnostic_item(sym::From,impl_trait_ref.skip_binder().def_id)
59+
.is_lang_item(impl_trait_ref.skip_binder().def_id, hir::LangItem::From)
6060
{
6161
lint_impl_body(cx, item.span, impl_.items);
6262
}

‎src/tools/clippy/clippy_lints/src/unconditional_recursion.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn check_from(cx: &LateContext<'_>, method_span: Span, method_def_id: LocalDefId
406406
&& let (Some(s1), Some(s2)) = (s1.as_type(), s2.as_type())
407407
&& let Some(trait_def_id) = cx.tcx.trait_of_item(fn_def_id)
408408
&& cx.tcx.is_diagnostic_item(sym::Into, trait_def_id)
409-
&& get_impl_trait_def_id(cx, method_def_id) == cx.tcx.get_diagnostic_item(sym::From)
409+
&& get_impl_trait_def_id(cx, method_def_id) == cx.tcx.lang_items().from_trait()
410410
&& s1 == sig.inputs()[0]
411411
&& s2 == sig.output()
412412
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /