Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert some Into impls into From impls #134949

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ impl AngleBracketedArg {
}
}

impl Into<P<GenericArgs>> for AngleBracketedArgs {
fn into(self) -> P<GenericArgs> {
P(GenericArgs::AngleBracketed(self))
impl From<AngleBracketedArgs> for P<GenericArgs> {
fn from(val: AngleBracketedArgs) -> Self {
P(GenericArgs::AngleBracketed(val))
}
}

impl Into<P<GenericArgs>> for ParenthesizedArgs {
fn into(self) -> P<GenericArgs> {
P(GenericArgs::Parenthesized(self))
impl From<ParenthesizedArgs> for P<GenericArgs> {
fn from(val: ParenthesizedArgs) -> Self {
P(GenericArgs::Parenthesized(val))
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ impl<T> From<Vec<T>> for P<[T]> {
}
}

impl<T> Into<Vec<T>> for P<[T]> {
fn into(self) -> Vec<T> {
self.into_vec()
impl<T> From<P<[T]>> for Vec<T> {
fn from(val: P<[T]>) -> Self {
val.into_vec()
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ impl From<Cow<'static, str>> 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<SubdiagMessage> for DiagMessage {
fn into(self) -> SubdiagMessage {
match self {
impl From<DiagMessage> 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),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ impl IntoDiagArg for DiagArgValue {
}
}

impl Into<FluentValue<'static>> for DiagArgValue {
fn into(self) -> FluentValue<'static> {
match self {
impl From<DiagArgValue> 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),
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4072,33 +4072,33 @@ impl<'hir> OwnerNode<'hir> {
}
}

impl<'hir> Into<OwnerNode<'hir>> 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<OwnerNode<'hir>> 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<OwnerNode<'hir>> 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<OwnerNode<'hir>> 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<Node<'hir>> for OwnerNode<'hir> {
fn into(self) -> Node<'hir> {
match self {
impl<'hir> From<OwnerNode<'hir>> 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),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ pub(crate) struct RawDefId {
index: u32,
}

impl Into<RawDefId> for DefId {
fn into(self) -> RawDefId {
RawDefId { krate: self.krate.as_u32(), index: self.index.as_u32() }
impl From<DefId> for RawDefId {
fn from(val: DefId) -> Self {
RawDefId { krate: val.krate.as_u32(), index: val.index.as_u32() }
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ impl ReportedErrorInfo {
}
}

impl Into<ErrorGuaranteed> for ReportedErrorInfo {
impl From<ReportedErrorInfo> for ErrorGuaranteed {
#[inline]
fn into(self) -> ErrorGuaranteed {
self.error
fn from(val: ReportedErrorInfo) -> Self {
val.error
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ pub enum AdtKind {
Enum,
}

impl Into<DataTypeKind> for AdtKind {
fn into(self) -> DataTypeKind {
match self {
impl From<AdtKind> for DataTypeKind {
fn from(val: AdtKind) -> Self {
match val {
AdtKind::Struct => DataTypeKind::Struct,
AdtKind::Union => DataTypeKind::Union,
AdtKind::Enum => DataTypeKind::Enum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ pub enum TypeAnnotationNeeded {
E0284,
}

impl Into<ErrCode> for TypeAnnotationNeeded {
fn into(self) -> ErrCode {
match self {
Self::E0282 => E0282,
Self::E0283 => E0283,
Self::E0284 => E0284,
impl From<TypeAnnotationNeeded> for ErrCode {
fn from(val: TypeAnnotationNeeded) -> Self {
match val {
TypeAnnotationNeeded::E0282 => E0282,
TypeAnnotationNeeded::E0283 => E0283,
TypeAnnotationNeeded::E0284 => E0284,
}
}
}
Expand Down
Loading