mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 04:14:28 +00:00
Rollup merge of #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: https://github.com/rust-lang/rust-clippy/pull/6620#discussion_r562482587
This commit is contained in:
commit
70be5cef69
@ -622,6 +622,7 @@ symbols! {
|
|||||||
intel,
|
intel,
|
||||||
into_iter,
|
into_iter,
|
||||||
into_result,
|
into_result,
|
||||||
|
into_trait,
|
||||||
intra_doc_pointers,
|
intra_doc_pointers,
|
||||||
intrinsics,
|
intrinsics,
|
||||||
irrefutable_let_patterns,
|
irrefutable_let_patterns,
|
||||||
@ -1159,6 +1160,8 @@ symbols! {
|
|||||||
truncf32,
|
truncf32,
|
||||||
truncf64,
|
truncf64,
|
||||||
try_blocks,
|
try_blocks,
|
||||||
|
try_from_trait,
|
||||||
|
try_into_trait,
|
||||||
try_trait,
|
try_trait,
|
||||||
tt,
|
tt,
|
||||||
tuple,
|
tuple,
|
||||||
|
@ -267,6 +267,7 @@ pub trait AsMut<T: ?Sized> {
|
|||||||
///
|
///
|
||||||
/// [`String`]: ../../std/string/struct.String.html
|
/// [`String`]: ../../std/string/struct.String.html
|
||||||
/// [`Vec`]: ../../std/vec/struct.Vec.html
|
/// [`Vec`]: ../../std/vec/struct.Vec.html
|
||||||
|
#[rustc_diagnostic_item = "into_trait"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Into<T>: Sized {
|
pub trait Into<T>: Sized {
|
||||||
/// Performs the conversion.
|
/// Performs the conversion.
|
||||||
@ -382,6 +383,7 @@ pub trait From<T>: Sized {
|
|||||||
///
|
///
|
||||||
/// This suffers the same restrictions and reasoning as implementing
|
/// This suffers the same restrictions and reasoning as implementing
|
||||||
/// [`Into`], see there for details.
|
/// [`Into`], see there for details.
|
||||||
|
#[rustc_diagnostic_item = "try_into_trait"]
|
||||||
#[stable(feature = "try_from", since = "1.34.0")]
|
#[stable(feature = "try_from", since = "1.34.0")]
|
||||||
pub trait TryInto<T>: Sized {
|
pub trait TryInto<T>: Sized {
|
||||||
/// The type returned in the event of a conversion error.
|
/// The type returned in the event of a conversion error.
|
||||||
@ -462,6 +464,7 @@ pub trait TryInto<T>: Sized {
|
|||||||
///
|
///
|
||||||
/// [`try_from`]: TryFrom::try_from
|
/// [`try_from`]: TryFrom::try_from
|
||||||
/// [`!`]: ../../std/primitive.never.html
|
/// [`!`]: ../../std/primitive.never.html
|
||||||
|
#[rustc_diagnostic_item = "try_from_trait"]
|
||||||
#[stable(feature = "try_from", since = "1.34.0")]
|
#[stable(feature = "try_from", since = "1.34.0")]
|
||||||
pub trait TryFrom<T>: Sized {
|
pub trait TryFrom<T>: Sized {
|
||||||
/// The type returned in the event of a conversion error.
|
/// The type returned in the event of a conversion error.
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
use crate::utils::paths::FROM_TRAIT;
|
use crate::utils::{is_expn_of, is_type_diagnostic_item, match_panic_def_id, method_chain_args, span_lint_and_then};
|
||||||
use crate::utils::{
|
|
||||||
is_expn_of, is_type_diagnostic_item, match_def_path, match_panic_def_id, method_chain_args, span_lint_and_then,
|
|
||||||
};
|
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
@ -59,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
|||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
||||||
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
|
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
|
||||||
then {
|
then {
|
||||||
lint_impl_body(cx, item.span, impl_.items);
|
lint_impl_body(cx, item.span, impl_.items);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ pub const FN_MUT: [&str; 3] = ["core", "ops", "FnMut"];
|
|||||||
pub const FN_ONCE: [&str; 3] = ["core", "ops", "FnOnce"];
|
pub const FN_ONCE: [&str; 3] = ["core", "ops", "FnOnce"];
|
||||||
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
|
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
|
||||||
pub const FROM_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "FromIterator"];
|
pub const FROM_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "FromIterator"];
|
||||||
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
|
|
||||||
pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
|
pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
|
||||||
pub const HASH: [&str; 3] = ["core", "hash", "Hash"];
|
pub const HASH: [&str; 3] = ["core", "hash", "Hash"];
|
||||||
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
|
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
|
||||||
|
Loading…
Reference in New Issue
Block a user