Skip to content

Commit 2b57ce1

Browse files
Implemented DerefMut for ArmIntrinsicTest
More details: 1. Moved the return type of IntrinsicType::from_c to Rust<Self, String> from Result<Box<Self>, String>
1 parent e89f568 commit 2b57ce1

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

crates/intrinsic-test/src/arm/intrinsic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::common::argument::ArgumentList;
22
use crate::common::indentation::Indentation;
33
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
44
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
5-
use std::ops::Deref;
5+
use std::ops::{Deref, DerefMut};
66

77
#[derive(Debug, Clone, PartialEq)]
88
pub struct ArmIntrinsicType(pub IntrinsicType);
@@ -15,6 +15,12 @@ impl Deref for ArmIntrinsicType {
1515
}
1616
}
1717

18+
impl DerefMut for ArmIntrinsicType {
19+
fn deref_mut(&mut self) -> &mut Self::Target {
20+
&mut self.0
21+
}
22+
}
23+
1824
impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
1925
fn arguments(&self) -> ArgumentList<ArmIntrinsicType> {
2026
self.arguments.clone()

crates/intrinsic-test/src/arm/types.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
121121
}
122122
}
123123

124-
fn from_c(s: &str, target: &str) -> Result<Box<Self>, String> {
124+
fn from_c(s: &str, target: &str) -> Result<Self, String> {
125125
const CONST_STR: &str = "const";
126126
if let Some(s) = s.strip_suffix('*') {
127127
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
@@ -131,9 +131,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
131131
let s = s.trim_end();
132132
let temp_return = ArmIntrinsicType::from_c(s, target);
133133
temp_return.map(|mut op| {
134-
let edited = op.as_mut();
135-
edited.0.ptr = true;
136-
edited.0.ptr_constant = constant;
134+
op.ptr = true;
135+
op.ptr_constant = constant;
137136
op
138137
})
139138
} else {
@@ -163,7 +162,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
163162
),
164163
None => None,
165164
};
166-
Ok(Box::new(ArmIntrinsicType(IntrinsicType {
165+
Ok(ArmIntrinsicType(IntrinsicType {
167166
ptr: false,
168167
ptr_constant: false,
169168
constant,
@@ -172,14 +171,14 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
172171
simd_len,
173172
vec_len,
174173
target: target.to_string(),
175-
})))
174+
}))
176175
} else {
177176
let kind = start.parse::<TypeKind>()?;
178177
let bit_len = match kind {
179178
TypeKind::Int(_) => Some(32),
180179
_ => None,
181180
};
182-
Ok(Box::new(ArmIntrinsicType(IntrinsicType {
181+
Ok(ArmIntrinsicType(IntrinsicType {
183182
ptr: false,
184183
ptr_constant: false,
185184
constant,
@@ -188,7 +187,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
188187
simd_len: None,
189188
vec_len: None,
190189
target: target.to_string(),
191-
})))
190+
}))
192191
}
193192
}
194193
}

crates/intrinsic-test/src/common/intrinsic_helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
322322
fn get_lane_function(&self) -> String;
323323

324324
/// can be implemented in an `impl` block
325-
fn from_c(_s: &str, _target: &str) -> Result<Box<Self>, String>;
325+
fn from_c(_s: &str, _target: &str) -> Result<Self, String>
326+
where
327+
Self: Sized;
326328

327329
/// Gets a string containing the typename for this type in C format.
328330
/// can be directly defined in `impl` blocks

0 commit comments

Comments
 (0)