Skip to content

Commit 70be5ce

Browse files
authored
Rollup merge of rust-lang#81277 - flip1995:from_diag_items, r=matthewjasper
Make more traits of the From/Into family diagnostic items Following traits are now diagnostic items: - `From` (unchanged) - `Into` - `TryFrom` - `TryInto` This also adds symbols for those items: - `into_trait` - `try_from_trait` - `try_into_trait` Related: rust-lang/rust-clippy#6620 (comment)
2 parents 84ad95b + e25959b commit 70be5ce

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

compiler/rustc_span/src/symbol.rs

+3
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ symbols! {
622622
intel,
623623
into_iter,
624624
into_result,
625+
into_trait,
625626
intra_doc_pointers,
626627
intrinsics,
627628
irrefutable_let_patterns,
@@ -1159,6 +1160,8 @@ symbols! {
11591160
truncf32,
11601161
truncf64,
11611162
try_blocks,
1163+
try_from_trait,
1164+
try_into_trait,
11621165
try_trait,
11631166
tt,
11641167
tuple,

library/core/src/convert/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub trait AsMut<T: ?Sized> {
267267
///
268268
/// [`String`]: ../../std/string/struct.String.html
269269
/// [`Vec`]: ../../std/vec/struct.Vec.html
270+
#[rustc_diagnostic_item = "into_trait"]
270271
#[stable(feature = "rust1", since = "1.0.0")]
271272
pub trait Into<T>: Sized {
272273
/// Performs the conversion.
@@ -382,6 +383,7 @@ pub trait From<T>: Sized {
382383
///
383384
/// This suffers the same restrictions and reasoning as implementing
384385
/// [`Into`], see there for details.
386+
#[rustc_diagnostic_item = "try_into_trait"]
385387
#[stable(feature = "try_from", since = "1.34.0")]
386388
pub trait TryInto<T>: Sized {
387389
/// The type returned in the event of a conversion error.
@@ -462,6 +464,7 @@ pub trait TryInto<T>: Sized {
462464
///
463465
/// [`try_from`]: TryFrom::try_from
464466
/// [`!`]: ../../std/primitive.never.html
467+
#[rustc_diagnostic_item = "try_from_trait"]
465468
#[stable(feature = "try_from", since = "1.34.0")]
466469
pub trait TryFrom<T>: Sized {
467470
/// The type returned in the event of a conversion error.

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::utils::paths::FROM_TRAIT;
2-
use crate::utils::{
3-
is_expn_of, is_type_diagnostic_item, match_def_path, match_panic_def_id, method_chain_args, span_lint_and_then,
4-
};
1+
use crate::utils::{is_expn_of, is_type_diagnostic_item, match_panic_def_id, method_chain_args, span_lint_and_then};
52
use if_chain::if_chain;
63
use rustc_hir as hir;
74
use rustc_lint::{LateContext, LateLintPass};
@@ -59,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
5956
if_chain! {
6057
if let hir::ItemKind::Impl(impl_) = &item.kind;
6158
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
62-
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
59+
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
6360
then {
6461
lint_impl_body(cx, item.span, impl_.items);
6562
}

src/tools/clippy/clippy_lints/src/utils/paths.rs

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub const FN_MUT: [&str; 3] = ["core", "ops", "FnMut"];
4848
pub const FN_ONCE: [&str; 3] = ["core", "ops", "FnOnce"];
4949
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
5050
pub const FROM_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "FromIterator"];
51-
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
5251
pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
5352
pub const HASH: [&str; 3] = ["core", "hash", "Hash"];
5453
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];

0 commit comments

Comments
 (0)