From aea2a6f8361c95d60cc8e2757ca473f6915902a9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 31 Dec 2024 01:56:28 +0000 Subject: [PATCH] Convert some Into impls into From impls --- compiler/rustc_ast/src/ast.rs | 12 ++++---- compiler/rustc_ast/src/ptr.rs | 6 ++-- compiler/rustc_error_messages/src/lib.rs | 6 ++-- compiler/rustc_errors/src/diagnostic.rs | 6 ++-- compiler/rustc_hir/src/hir.rs | 30 +++++++++---------- compiler/rustc_metadata/src/rmeta/mod.rs | 6 ++-- .../rustc_middle/src/mir/interpret/error.rs | 6 ++-- compiler/rustc_middle/src/ty/adt.rs | 6 ++-- .../error_reporting/infer/need_type_info.rs | 12 ++++---- 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 31e6750a6788c..3a81b93d157ce 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -241,15 +241,15 @@ impl AngleBracketedArg { } } -impl Into> for AngleBracketedArgs { - fn into(self) -> P { - P(GenericArgs::AngleBracketed(self)) +impl From for P { + fn from(val: AngleBracketedArgs) -> Self { + P(GenericArgs::AngleBracketed(val)) } } -impl Into> for ParenthesizedArgs { - fn into(self) -> P { - P(GenericArgs::Parenthesized(self)) +impl From for P { + fn from(val: ParenthesizedArgs) -> Self { + P(GenericArgs::Parenthesized(val)) } } diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index 97c714df8fd2f..dd923305cdfd9 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -158,9 +158,9 @@ impl From> for P<[T]> { } } -impl Into> for P<[T]> { - fn into(self) -> Vec { - self.into_vec() +impl From> for Vec { + fn from(val: P<[T]>) -> Self { + val.into_vec() } } diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 74b6d63365a58..a51c4140e1760 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -357,9 +357,9 @@ impl From> for DiagMessage { /// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be /// able to convert between these, as much as they'll be converted back into `DiagMessage` /// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive. -impl Into for DiagMessage { - fn into(self) -> SubdiagMessage { - match self { +impl From for SubdiagMessage { + fn from(val: DiagMessage) -> Self { + match val { DiagMessage::Str(s) => SubdiagMessage::Str(s), DiagMessage::Translated(s) => SubdiagMessage::Translated(s), DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::FluentIdentifier(id), diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 05b9cbfbc0664..afce877547f3e 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -156,9 +156,9 @@ impl IntoDiagArg for DiagArgValue { } } -impl Into> for DiagArgValue { - fn into(self) -> FluentValue<'static> { - match self { +impl From for FluentValue<'static> { + fn from(val: DiagArgValue) -> Self { + match val { DiagArgValue::Str(s) => From::from(s), DiagArgValue::Number(n) => From::from(n), DiagArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l), diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 8cea269f29823..5ea3bcef9ba3b 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -4072,33 +4072,33 @@ impl<'hir> OwnerNode<'hir> { } } -impl<'hir> Into> for &'hir Item<'hir> { - fn into(self) -> OwnerNode<'hir> { - OwnerNode::Item(self) +impl<'hir> From<&'hir Item<'hir>> for OwnerNode<'hir> { + fn from(val: &'hir Item<'hir>) -> Self { + OwnerNode::Item(val) } } -impl<'hir> Into> for &'hir ForeignItem<'hir> { - fn into(self) -> OwnerNode<'hir> { - OwnerNode::ForeignItem(self) +impl<'hir> From<&'hir ForeignItem<'hir>> for OwnerNode<'hir> { + fn from(val: &'hir ForeignItem<'hir>) -> Self { + OwnerNode::ForeignItem(val) } } -impl<'hir> Into> for &'hir ImplItem<'hir> { - fn into(self) -> OwnerNode<'hir> { - OwnerNode::ImplItem(self) +impl<'hir> From<&'hir ImplItem<'hir>> for OwnerNode<'hir> { + fn from(val: &'hir ImplItem<'hir>) -> Self { + OwnerNode::ImplItem(val) } } -impl<'hir> Into> for &'hir TraitItem<'hir> { - fn into(self) -> OwnerNode<'hir> { - OwnerNode::TraitItem(self) +impl<'hir> From<&'hir TraitItem<'hir>> for OwnerNode<'hir> { + fn from(val: &'hir TraitItem<'hir>) -> Self { + OwnerNode::TraitItem(val) } } -impl<'hir> Into> for OwnerNode<'hir> { - fn into(self) -> Node<'hir> { - match self { +impl<'hir> From> for Node<'hir> { + fn from(val: OwnerNode<'hir>) -> Self { + match val { OwnerNode::Item(n) => Node::Item(n), OwnerNode::ForeignItem(n) => Node::ForeignItem(n), OwnerNode::ImplItem(n) => Node::ImplItem(n), diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 64a1c70dd2ff8..4fe8f73efd601 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -303,9 +303,9 @@ pub(crate) struct RawDefId { index: u32, } -impl Into for DefId { - fn into(self) -> RawDefId { - RawDefId { krate: self.krate.as_u32(), index: self.index.as_u32() } +impl From for RawDefId { + fn from(val: DefId) -> Self { + RawDefId { krate: val.krate.as_u32(), index: val.index.as_u32() } } } diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 37328470aa7e8..8c085fa310ab5 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -88,10 +88,10 @@ impl ReportedErrorInfo { } } -impl Into for ReportedErrorInfo { +impl From for ErrorGuaranteed { #[inline] - fn into(self) -> ErrorGuaranteed { - self.error + fn from(val: ReportedErrorInfo) -> Self { + val.error } } diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 8f4137cc01123..e28fcc555dcd1 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -249,9 +249,9 @@ pub enum AdtKind { Enum, } -impl Into for AdtKind { - fn into(self) -> DataTypeKind { - match self { +impl From for DataTypeKind { + fn from(val: AdtKind) -> Self { + match val { AdtKind::Struct => DataTypeKind::Struct, AdtKind::Union => DataTypeKind::Union, AdtKind::Enum => DataTypeKind::Enum, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index 2dcf3760d2f74..68a5338123049 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -45,12 +45,12 @@ pub enum TypeAnnotationNeeded { E0284, } -impl Into for TypeAnnotationNeeded { - fn into(self) -> ErrCode { - match self { - Self::E0282 => E0282, - Self::E0283 => E0283, - Self::E0284 => E0284, +impl From for ErrCode { + fn from(val: TypeAnnotationNeeded) -> Self { + match val { + TypeAnnotationNeeded::E0282 => E0282, + TypeAnnotationNeeded::E0283 => E0283, + TypeAnnotationNeeded::E0284 => E0284, } } }