Skip to content

Commit b07a2d0

Browse files
committed
codegen_llvm/misc: improve common patterns
1 parent e90e8aa commit b07a2d0

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct MirDebugScope<'ll> {
3737

3838
impl MirDebugScope<'ll> {
3939
pub fn is_valid(&self) -> bool {
40-
!self.scope_metadata.is_none()
40+
self.scope_metadata.is_some()
4141
}
4242
}
4343

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ impl TypeMap<'ll, 'tcx> {
163163
fn get_unique_type_id_of_type<'a>(&mut self, cx: &CodegenCx<'a, 'tcx>,
164164
type_: Ty<'tcx>) -> UniqueTypeId {
165165
// Let's see if we already have something in the cache
166-
match self.type_to_unique_id.get(&type_).cloned() {
167-
Some(unique_type_id) => return unique_type_id,
168-
None => { /* generate one */}
169-
};
166+
if let Some(unique_type_id) = self.type_to_unique_id.get(&type_).cloned() {
167+
return unique_type_id
168+
}
169+
// if not, generate one
170170

171171
// The hasher we are using to generate the UniqueTypeId. We want
172172
// something that provides more than the 64 bits of the DefaultHasher.
@@ -286,11 +286,11 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
286286
// unique id can be found in the type map
287287
macro_rules! return_if_metadata_created_in_meantime {
288288
($cx: expr, $unique_type_id: expr) => (
289-
match debug_context($cx).type_map
290-
.borrow()
291-
.find_metadata_for_unique_id($unique_type_id) {
292-
Some(metadata) => return MetadataCreationResult::new(metadata, true),
293-
None => { /* proceed normally */ }
289+
if let Some(metadata) = debug_context($cx).type_map
290+
.borrow()
291+
.find_metadata_for_unique_id($unique_type_id)
292+
{
293+
return MetadataCreationResult::new(metadata, true)
294294
}
295295
)
296296
}
@@ -548,12 +548,12 @@ pub fn type_metadata(
548548
_ => {
549549
let pointee_metadata = type_metadata(cx, ty, usage_site_span);
550550

551-
match debug_context(cx).type_map
552-
.borrow()
553-
.find_metadata_for_unique_id(unique_type_id) {
554-
Some(metadata) => return Err(metadata),
555-
None => { /* proceed normally */ }
556-
};
551+
if let Some(metadata) = debug_context(cx).type_map
552+
.borrow()
553+
.find_metadata_for_unique_id(unique_type_id)
554+
{
555+
return Err(metadata)
556+
}
557557

558558
Ok(MetadataCreationResult::new(pointer_type_metadata(cx, t, pointee_metadata),
559559
false))
@@ -608,12 +608,12 @@ pub fn type_metadata(
608608
unique_type_id,
609609
t.fn_sig(cx.tcx),
610610
usage_site_span).metadata;
611-
match debug_context(cx).type_map
612-
.borrow()
613-
.find_metadata_for_unique_id(unique_type_id) {
614-
Some(metadata) => return metadata,
615-
None => { /* proceed normally */ }
616-
};
611+
if let Some(metadata) = debug_context(cx).type_map
612+
.borrow()
613+
.find_metadata_for_unique_id(unique_type_id)
614+
{
615+
return metadata
616+
}
617617

618618
// This is actually a function pointer, so wrap it in pointer DI
619619
MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false)
@@ -1476,9 +1476,8 @@ fn prepare_enum_metadata(
14761476
}
14771477
};
14781478

1479-
match (&layout.abi, discriminant_type_metadata) {
1480-
(&layout::Abi::Scalar(_), Some(discr)) => return FinalMetadata(discr),
1481-
_ => {}
1479+
if let (&layout::Abi::Scalar(_), Some(discr)) = (&layout.abi, discriminant_type_metadata) {
1480+
return FinalMetadata(discr)
14821481
}
14831482

14841483
let (enum_type_size, enum_type_align) = layout.size_and_align();

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,14 @@ pub fn create_function_debug_context(
271271
let mut flags = DIFlags::FlagPrototyped;
272272

273273
let local_id = cx.tcx.hir.as_local_node_id(def_id);
274-
match *cx.sess().entry_fn.borrow() {
275-
Some((id, _, _)) => {
276-
if local_id == Some(id) {
277-
flags = flags | DIFlags::FlagMainSubprogram;
278-
}
274+
if let Some((id, _, _)) = *cx.sess().entry_fn.borrow() {
275+
if local_id == Some(id) {
276+
flags |= DIFlags::FlagMainSubprogram;
279277
}
280-
None => {}
281-
};
278+
}
279+
282280
if cx.layout_of(sig.output()).abi.is_uninhabited() {
283-
flags = flags | DIFlags::FlagNoReturn;
281+
flags |= DIFlags::FlagNoReturn;
284282
}
285283

286284
let fn_metadata = unsafe {

src/librustc_codegen_llvm/debuginfo/source_loc.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ pub fn set_source_location(
5656
/// switches source location emitting on and must therefore be called before the
5757
/// first real statement/expression of the function is codegened.
5858
pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext<'ll>) {
59-
match *dbg_context {
60-
FunctionDebugContext::RegularContext(ref data) => {
61-
data.source_locations_enabled.set(true)
62-
},
63-
_ => { /* safe to ignore */ }
59+
if let FunctionDebugContext::RegularContext(ref data) = *dbg_context {
60+
data.source_locations_enabled.set(true)
6461
}
6562
}
6663

0 commit comments

Comments
 (0)