Skip to content

Commit c25aed6

Browse files
committedMar 11, 2018
Used the Formatter::debug_struct() builder instead of string formatting
1 parent 4a57ec7 commit c25aed6

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed
 

‎src/basic_block.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ impl fmt::Debug for BasicBlock {
421421
LLVMIsConstant(self.basic_block as LLVMValueRef) == 1
422422
};
423423

424-
write!(f, "BasicBlock {{\n address: {:?}\n is_const: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", self.basic_block, is_const, llvm_value, llvm_type)
424+
f.debug_struct("BasicBlock")
425+
.field("address", &self.basic_block)
426+
.field("is_const", &is_const)
427+
.field("llvm_value", &llvm_value)
428+
.field("llvm_type", &llvm_type)
429+
.finish()
425430
}
426431
}

‎src/data_layout.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ impl PartialEq for DataLayout {
3636

3737
impl fmt::Debug for DataLayout {
3838
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39-
write!(f, "DataLayout {{\n ")?;
40-
write!(f, "address: {:?}\n ", self.data_layout.get())?;
41-
write!(f, "repr: {:?}\n}}", self.as_str())
39+
f.debug_struct("DataLayout")
40+
.field("address", &self.data_layout.get())
41+
.field("repr", &self.as_str())
42+
.finish()
4243
}
4344
}
4445

‎src/types/fn_type.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ impl fmt::Debug for FunctionType {
8282
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8383
let llvm_type = self.print_to_string();
8484

85-
write!(f, "FunctionType {{\n address: {:?}\n llvm_type: {:?}\n}}", self.as_type_ref(), llvm_type)
85+
f.debug_struct("FunctionType")
86+
.field("address", &self.as_type_ref())
87+
.field("llvm_type", &llvm_type)
88+
.finish()
8689
}
8790
}
8891

‎src/types/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ impl fmt::Debug for Type {
171171
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
172172
let llvm_type = self.print_to_string();
173173

174-
write!(f, "Type {{\n address: {:?}\n llvm_type: {:?}\n}}", self.type_, llvm_type)
174+
f.debug_struct("Type")
175+
.field("address", &self.type_)
176+
.field("llvm_type", &llvm_type)
177+
.finish()
175178
}
176179
}

‎src/values/array_value.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ impl fmt::Debug for ArrayValue {
9393
!LLVMIsAConstantDataArray(self.as_value_ref()).is_null()
9494
};
9595

96-
write!(f, "Value {{\n name: {:?}\n address: {:?}\n is_const: {:?}\n is_const_array: {:?}\n is_const_data_array: {:?}\n is_null: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", name, self.as_value_ref(), is_const, is_const_array, is_const_data_array, is_null, llvm_value, llvm_type.print_to_string())
96+
f.debug_struct("Value")
97+
.field("name", &name)
98+
.field("address", &self.as_value_ref())
99+
.field("is_const", &is_const)
100+
.field("is_const_array", &is_const_array)
101+
.field("is_const_data_array", &is_const_data_array)
102+
.field("is_null", &is_null)
103+
.field("llvm_value", &llvm_value)
104+
.field("llvm_type", &llvm_type)
105+
.finish()
97106
}
98107
}

‎src/values/metadata_value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ impl AsValueRef for MetadataValue {
143143

144144
impl fmt::Debug for MetadataValue {
145145
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
146-
write!(f, "MetadataValue {{\n ")?;
147-
write!(f, "address: {:?}\n", self.as_value_ref())?;
146+
let mut d = f.debug_struct("MetadataValue");
147+
d.field("address", &self.as_value_ref());
148148

149149
if self.is_string() {
150-
write!(f, "value: {:?}\n", self.get_string_value().unwrap())?;
150+
d.field("value", &self.get_string_value().unwrap());
151151
} else {
152-
write!(f, "values: {:?}\n", self.get_node_values())?;
152+
d.field("values", &self.get_node_values());
153153
}
154154

155-
write!(f, "repr: {:?}", self.print_to_string())?;
155+
d.field("repr", &self.print_to_string());
156156

157-
write!(f, "\n}}")
157+
d.finish()
158158
}
159159
}

‎src/values/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ impl fmt::Debug for Value {
168168
let is_null = self.is_null();
169169
let is_undef = self.is_undef();
170170

171-
write!(f, "Value {{\n name: {:?}\n address: {:?}\n is_const: {:?}\n is_null: {:?}\n is_undef: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", name, self.value, is_const, is_null, is_undef, llvm_value, llvm_type)
171+
f.debug_struct("Value")
172+
.field("name", &name)
173+
.field("address", &self.value)
174+
.field("is_const", &is_const)
175+
.field("is_null", &is_null)
176+
.field("is_undef", &is_undef)
177+
.field("llvm_value", &llvm_value)
178+
.field("llvm_type", &llvm_type)
179+
.finish()
172180
}
173181
}

0 commit comments

Comments
 (0)