Skip to content

Commit 9dd5214

Browse files
committed
Take small copy types by value per clippy's prescription
1 parent 335121d commit 9dd5214

28 files changed

+422
-414
lines changed

src/attributes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Attribute {
4141
///
4242
/// assert!(enum_attribute.is_enum());
4343
/// ```
44-
pub fn is_enum(&self) -> bool {
44+
pub fn is_enum(self) -> bool {
4545
unsafe {
4646
LLVMIsEnumAttribute(self.attribute) == 1
4747
}
@@ -61,7 +61,7 @@ impl Attribute {
6161
///
6262
/// assert!(string_attribute.is_string());
6363
/// ```
64-
pub fn is_string(&self) -> bool {
64+
pub fn is_string(self) -> bool {
6565
unsafe {
6666
LLVMIsStringAttribute(self.attribute) == 1
6767
}
@@ -99,7 +99,7 @@ impl Attribute {
9999
///
100100
/// assert_eq!(enum_attribute.get_enum_kind_id(), 0);
101101
/// ```
102-
pub fn get_enum_kind_id(&self) -> u32 {
102+
pub fn get_enum_kind_id(self) -> u32 {
103103
assert!(self.is_enum()); // FIXME: SubTypes
104104

105105
unsafe {
@@ -134,7 +134,7 @@ impl Attribute {
134134
///
135135
/// assert_eq!(enum_attribute.get_enum_value(), 10);
136136
/// ```
137-
pub fn get_enum_value(&self) -> u64 {
137+
pub fn get_enum_value(self) -> u64 {
138138
assert!(self.is_enum()); // FIXME: SubTypes
139139

140140
unsafe {
@@ -207,11 +207,11 @@ pub enum AttributeLoc {
207207
}
208208

209209
impl AttributeLoc {
210-
pub(crate) fn get_index(&self) -> u32 {
210+
pub(crate) fn get_index(self) -> u32 {
211211
match self {
212212
AttributeLoc::Return => 0,
213213
AttributeLoc::Param(index) => {
214-
assert!(*index <= u32::max_value() - 2, "Param index must be <= u32::max_value() - 2");
214+
assert!(index <= u32::max_value() - 2, "Param index must be <= u32::max_value() - 2");
215215

216216
index + 1
217217
},

src/basic_block.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'ctx> BasicBlock<'ctx> {
6161
///
6262
/// assert!(basic_block.get_parent().is_none());
6363
/// ```
64-
pub fn get_parent(&self) -> Option<FunctionValue<'ctx>> {
64+
pub fn get_parent(self) -> Option<FunctionValue<'ctx>> {
6565
let value = unsafe {
6666
LLVMGetBasicBlockParent(self.basic_block)
6767
};
@@ -95,7 +95,7 @@ impl<'ctx> BasicBlock<'ctx> {
9595
/// assert!(basic_block2.get_previous_basic_block().is_none());
9696
/// assert_eq!(basic_block3.get_previous_basic_block().unwrap(), basic_block2);
9797
/// ```
98-
pub fn get_previous_basic_block(&self) -> Option<BasicBlock<'ctx>> {
98+
pub fn get_previous_basic_block(self) -> Option<BasicBlock<'ctx>> {
9999
self.get_parent()?;
100100

101101
let bb = unsafe {
@@ -132,7 +132,7 @@ impl<'ctx> BasicBlock<'ctx> {
132132
/// assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block3);
133133
/// assert!(basic_block3.get_next_basic_block().is_none());
134134
/// ```
135-
pub fn get_next_basic_block(&self) -> Option<BasicBlock<'ctx>> {
135+
pub fn get_next_basic_block(self) -> Option<BasicBlock<'ctx>> {
136136
self.get_parent()?;
137137

138138
let bb = unsafe {
@@ -166,7 +166,7 @@ impl<'ctx> BasicBlock<'ctx> {
166166
/// assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block1);
167167
/// ```
168168
// REVIEW: What happens if blocks are from different scopes?
169-
pub fn move_before(&self, basic_block: BasicBlock<'ctx>) -> Result<(), ()> {
169+
pub fn move_before(self, basic_block: BasicBlock<'ctx>) -> Result<(), ()> {
170170
// This method is UB if the parent no longer exists, so we must check for parent (or encode into type system)
171171
if self.get_parent().is_none() || basic_block.get_parent().is_none() {
172172
return Err(());
@@ -203,7 +203,7 @@ impl<'ctx> BasicBlock<'ctx> {
203203
/// assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block1);
204204
/// ```
205205
// REVIEW: What happens if blocks are from different scopes?
206-
pub fn move_after(&self, basic_block: BasicBlock<'ctx>) -> Result<(), ()> {
206+
pub fn move_after(self, basic_block: BasicBlock<'ctx>) -> Result<(), ()> {
207207
// This method is UB if the parent no longer exists, so we must check for parent (or encode into type system)
208208
if self.get_parent().is_none() || basic_block.get_parent().is_none() {
209209
return Err(());
@@ -238,7 +238,7 @@ impl<'ctx> BasicBlock<'ctx> {
238238
///
239239
/// assert_eq!(basic_block.get_first_instruction().unwrap().get_opcode(), InstructionOpcode::Return);
240240
/// ```
241-
pub fn get_first_instruction(&self) -> Option<InstructionValue<'ctx>> {
241+
pub fn get_first_instruction(self) -> Option<InstructionValue<'ctx>> {
242242
let value = unsafe {
243243
LLVMGetFirstInstruction(self.basic_block)
244244
};
@@ -272,7 +272,7 @@ impl<'ctx> BasicBlock<'ctx> {
272272
///
273273
/// assert_eq!(basic_block.get_last_instruction().unwrap().get_opcode(), InstructionOpcode::Return);
274274
/// ```
275-
pub fn get_last_instruction(&self) -> Option<InstructionValue<'ctx>> {
275+
pub fn get_last_instruction(self) -> Option<InstructionValue<'ctx>> {
276276
let value = unsafe {
277277
LLVMGetLastInstruction(self.basic_block)
278278
};
@@ -310,7 +310,7 @@ impl<'ctx> BasicBlock<'ctx> {
310310
// if getting a value over an instruction is preferable
311311
// TODOC: Every BB must have a terminating instruction or else it is invalid
312312
// REVIEW: Unclear how this differs from get_last_instruction
313-
pub fn get_terminator(&self) -> Option<InstructionValue<'ctx>> {
313+
pub fn get_terminator(self) -> Option<InstructionValue<'ctx>> {
314314
let value = unsafe {
315315
LLVMGetBasicBlockTerminator(self.basic_block)
316316
};
@@ -348,7 +348,7 @@ impl<'ctx> BasicBlock<'ctx> {
348348
// by taking ownership of self (though BasicBlock's are not uniquely obtained...)
349349
// might have to make some methods do something like -> Result<..., BasicBlock<Orphan>> for BasicBlock<HasParent>
350350
// and would move_before/after make it no longer orphaned? etc..
351-
pub fn remove_from_function(&self) -> Result<(), ()> {
351+
pub fn remove_from_function(self) -> Result<(), ()> {
352352
// This method is UB if the parent no longer exists, so we must check for parent (or encode into type system)
353353
if self.get_parent().is_none() {
354354
return Err(());
@@ -410,7 +410,7 @@ impl<'ctx> BasicBlock<'ctx> {
410410
///
411411
/// assert_eq!(context, *basic_block.get_context());
412412
/// ```
413-
pub fn get_context(&self) -> ContextRef<'ctx> {
413+
pub fn get_context(self) -> ContextRef<'ctx> {
414414
let context = unsafe {
415415
LLVMGetTypeContext(LLVMTypeOf(LLVMBasicBlockAsValue(self.basic_block)))
416416
};
@@ -470,7 +470,7 @@ impl<'ctx> BasicBlock<'ctx> {
470470
///
471471
/// assert_eq!(branch_inst.get_operand(0).unwrap().right().unwrap(), bb2);
472472
/// ```
473-
pub fn replace_all_uses_with(&self, other: &BasicBlock<'ctx>) {
473+
pub fn replace_all_uses_with(self, other: &BasicBlock<'ctx>) {
474474
let value = unsafe { LLVMBasicBlockAsValue(self.basic_block) };
475475
let other = unsafe { LLVMBasicBlockAsValue(other.basic_block) };
476476

@@ -506,7 +506,7 @@ impl<'ctx> BasicBlock<'ctx> {
506506
/// assert!(bb2.get_first_use().is_none());
507507
/// assert!(bb1.get_first_use().is_some());
508508
/// ```
509-
pub fn get_first_use(&self) -> Option<BasicValueUse> {
509+
pub fn get_first_use(self) -> Option<BasicValueUse<'ctx>> {
510510
let use_ = unsafe {
511511
LLVMGetFirstUse(LLVMBasicBlockAsValue(self.basic_block))
512512
};

src/comdat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Comdat {
3333
}
3434

3535
/// Gets what kind of `Comdat` this is.
36-
pub fn get_selection_kind(&self) -> ComdatSelectionKind {
36+
pub fn get_selection_kind(self) -> ComdatSelectionKind {
3737
let kind_ptr = unsafe {
3838
LLVMGetComdatSelectionKind(self.0)
3939
};
@@ -42,7 +42,7 @@ impl Comdat {
4242
}
4343

4444
/// Sets what kind of `Comdat` this should be.
45-
pub fn set_selection_kind(&self, kind: ComdatSelectionKind) {
45+
pub fn set_selection_kind(self, kind: ComdatSelectionKind) {
4646
unsafe {
4747
LLVMSetComdatSelectionKind(self.0, kind.as_llvm_enum())
4848
}

src/execution_engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl<'ctx> ExecutionEngine<'ctx> {
368368

369369
// TODOC: Marked as unsafe because input function could very well do something unsafe. It's up to the caller
370370
// to ensure that doesn't happen by defining their function correctly.
371-
pub unsafe fn run_function(&self, function: FunctionValue<'ctx>, args: &[&GenericValue]) -> GenericValue {
371+
pub unsafe fn run_function(&self, function: FunctionValue<'ctx>, args: &[&GenericValue<'ctx>]) -> GenericValue<'ctx> {
372372
let mut args: Vec<LLVMGenericValueRef> = args.iter()
373373
.map(|val| val.generic_value)
374374
.collect();

src/types/array_type.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'ctx> ArrayType<'ctx> {
3636
/// let i8_array_type = i8_type.array_type(3);
3737
/// let i8_array_type_size = i8_array_type.size_of();
3838
/// ```
39-
pub fn size_of(&self) -> Option<IntValue<'ctx>> {
39+
pub fn size_of(self) -> Option<IntValue<'ctx>> {
4040
self.array_type.size_of()
4141
}
4242

@@ -52,7 +52,7 @@ impl<'ctx> ArrayType<'ctx> {
5252
/// let i8_array_type = i8_type.array_type(3);
5353
/// let i8_array_type_alignment = i8_array_type.get_alignment();
5454
/// ```
55-
pub fn get_alignment(&self) -> IntValue<'ctx> {
55+
pub fn get_alignment(self) -> IntValue<'ctx> {
5656
self.array_type.get_alignment()
5757
}
5858

@@ -71,7 +71,7 @@ impl<'ctx> ArrayType<'ctx> {
7171
///
7272
/// assert_eq!(i8_array_ptr_type.get_element_type().into_array_type(), i8_array_type);
7373
/// ```
74-
pub fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx> {
74+
pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx> {
7575
self.array_type.ptr_type(address_space)
7676
}
7777

@@ -88,7 +88,7 @@ impl<'ctx> ArrayType<'ctx> {
8888
///
8989
/// assert_eq!(*i8_array_type.get_context(), context);
9090
/// ```
91-
pub fn get_context(&self) -> ContextRef<'ctx> {
91+
pub fn get_context(self) -> ContextRef<'ctx> {
9292
self.array_type.get_context()
9393
}
9494

@@ -104,7 +104,7 @@ impl<'ctx> ArrayType<'ctx> {
104104
/// let i8_array_type = i8_type.array_type(3);
105105
/// let fn_type = i8_array_type.fn_type(&[], false);
106106
/// ```
107-
pub fn fn_type(&self, param_types: &[BasicTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> {
107+
pub fn fn_type(self, param_types: &[BasicTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> {
108108
self.array_type.fn_type(param_types, is_var_args)
109109
}
110110

@@ -123,7 +123,7 @@ impl<'ctx> ArrayType<'ctx> {
123123
/// assert_eq!(i8_array_array_type.len(), 3);
124124
/// assert_eq!(i8_array_array_type.get_element_type().into_array_type(), i8_array_type);
125125
/// ```
126-
pub fn array_type(&self, size: u32) -> ArrayType<'ctx> {
126+
pub fn array_type(self, size: u32) -> ArrayType<'ctx> {
127127
self.array_type.array_type(size)
128128
}
129129

@@ -141,7 +141,7 @@ impl<'ctx> ArrayType<'ctx> {
141141
///
142142
/// assert!(f32_array_array.is_const());
143143
/// ```
144-
pub fn const_array(&self, values: &[ArrayValue<'ctx>]) -> ArrayValue<'ctx> {
144+
pub fn const_array(self, values: &[ArrayValue<'ctx>]) -> ArrayValue<'ctx> {
145145
let mut values: Vec<LLVMValueRef> = values.iter()
146146
.map(|val| val.as_value_ref())
147147
.collect();
@@ -164,7 +164,7 @@ impl<'ctx> ArrayType<'ctx> {
164164
/// let i8_array_type = i8_type.array_type(3);
165165
/// let i8_array_zero = i8_array_type.const_zero();
166166
/// ```
167-
pub fn const_zero(&self) -> ArrayValue<'ctx> {
167+
pub fn const_zero(self) -> ArrayValue<'ctx> {
168168
ArrayValue::new(self.array_type.const_zero())
169169
}
170170

@@ -181,21 +181,21 @@ impl<'ctx> ArrayType<'ctx> {
181181
///
182182
/// assert_eq!(i8_array_type.len(), 3);
183183
/// ```
184-
pub fn len(&self) -> u32 {
184+
pub fn len(self) -> u32 {
185185
unsafe {
186186
LLVMGetArrayLength(self.as_type_ref())
187187
}
188188
}
189189

190190
/// Prints the definition of a `ArrayType` to a `LLVMString`.
191-
pub fn print_to_string(&self) -> LLVMString {
191+
pub fn print_to_string(self) -> LLVMString {
192192
self.array_type.print_to_string()
193193
}
194194

195195
// See Type::print_to_stderr note on 5.0+ status
196196
/// Prints the definition of an `ArrayType` to stderr. Not available in newer LLVM versions.
197197
#[llvm_versions(3.7..=4.0)]
198-
pub fn print_to_stderr(&self) {
198+
pub fn print_to_stderr(self) {
199199
self.array_type.print_to_stderr()
200200
}
201201

@@ -212,7 +212,7 @@ impl<'ctx> ArrayType<'ctx> {
212212
///
213213
/// assert!(i8_array_undef.is_undef());
214214
/// ```
215-
pub fn get_undef(&self) -> ArrayValue<'ctx> {
215+
pub fn get_undef(self) -> ArrayValue<'ctx> {
216216
ArrayValue::new(self.array_type.get_undef())
217217
}
218218

@@ -230,7 +230,7 @@ impl<'ctx> ArrayType<'ctx> {
230230
///
231231
/// assert_eq!(i8_array_type.get_element_type().into_int_type(), i8_type);
232232
/// ```
233-
pub fn get_element_type(&self) -> BasicTypeEnum<'ctx> {
233+
pub fn get_element_type(self) -> BasicTypeEnum<'ctx> {
234234
self.array_type.get_element_type().to_basic_type_enum()
235235
}
236236

0 commit comments

Comments
 (0)