Skip to content

Commit fd616f0

Browse files
committed
Rollup merge of rust-lang#54933 - ljedrz:cleanup_codegen_llvm/misc, r=varkor
Cleanup the rest of codegen_llvm - improve common patterns - convert string literals with `to_owned` - remove explicit `return`s - whitespace & formatting improvements
2 parents e4ac447 + 24b74b2 commit fd616f0

File tree

8 files changed

+83
-88
lines changed

8 files changed

+83
-88
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: 46 additions & 47 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
}
@@ -352,15 +352,15 @@ fn vec_slice_metadata(
352352

353353
let member_descriptions = vec![
354354
MemberDescription {
355-
name: "data_ptr".to_string(),
355+
name: "data_ptr".to_owned(),
356356
type_metadata: data_ptr_metadata,
357357
offset: Size::ZERO,
358358
size: pointer_size,
359359
align: pointer_align,
360360
flags: DIFlags::FlagZero,
361361
},
362362
MemberDescription {
363-
name: "length".to_string(),
363+
name: "length".to_owned(),
364364
type_metadata: type_metadata(cx, cx.tcx.types.usize, span),
365365
offset: pointer_size,
366366
size: usize_size,
@@ -458,7 +458,7 @@ fn trait_pointer_metadata(
458458
let vtable_field = layout.field(cx, 1);
459459
let member_descriptions = vec![
460460
MemberDescription {
461-
name: "pointer".to_string(),
461+
name: "pointer".to_owned(),
462462
type_metadata: type_metadata(cx,
463463
cx.tcx.mk_mut_ptr(cx.tcx.types.u8),
464464
syntax_pos::DUMMY_SP),
@@ -468,7 +468,7 @@ fn trait_pointer_metadata(
468468
flags: DIFlags::FlagArtificial,
469469
},
470470
MemberDescription {
471-
name: "vtable".to_string(),
471+
name: "vtable".to_owned(),
472472
type_metadata: type_metadata(cx, vtable_field.ty, syntax_pos::DUMMY_SP),
473473
offset: layout.fields.offset(1),
474474
size: vtable_field.size,
@@ -543,12 +543,12 @@ pub fn type_metadata(
543543
_ => {
544544
let pointee_metadata = type_metadata(cx, ty, usage_site_span);
545545

546-
match debug_context(cx).type_map
547-
.borrow()
548-
.find_metadata_for_unique_id(unique_type_id) {
549-
Some(metadata) => return Err(metadata),
550-
None => { /* proceed normally */ }
551-
};
546+
if let Some(metadata) = debug_context(cx).type_map
547+
.borrow()
548+
.find_metadata_for_unique_id(unique_type_id)
549+
{
550+
return Err(metadata);
551+
}
552552

553553
Ok(MetadataCreationResult::new(pointer_type_metadata(cx, t, pointee_metadata),
554554
false))
@@ -577,12 +577,12 @@ pub fn type_metadata(
577577
}
578578
ty::Dynamic(..) => {
579579
MetadataCreationResult::new(
580-
trait_pointer_metadata(cx, t, None, unique_type_id),
581-
false)
580+
trait_pointer_metadata(cx, t, None, unique_type_id),
581+
false)
582582
}
583583
ty::Foreign(..) => {
584584
MetadataCreationResult::new(
585-
foreign_type_metadata(cx, t, unique_type_id),
585+
foreign_type_metadata(cx, t, unique_type_id),
586586
false)
587587
}
588588
ty::RawPtr(ty::TypeAndMut{ty, ..}) |
@@ -603,12 +603,12 @@ pub fn type_metadata(
603603
unique_type_id,
604604
t.fn_sig(cx.tcx),
605605
usage_site_span).metadata;
606-
match debug_context(cx).type_map
607-
.borrow()
608-
.find_metadata_for_unique_id(unique_type_id) {
609-
Some(metadata) => return metadata,
610-
None => { /* proceed normally */ }
611-
};
606+
if let Some(metadata) = debug_context(cx).type_map
607+
.borrow()
608+
.find_metadata_for_unique_id(unique_type_id)
609+
{
610+
return metadata;
611+
}
612612

613613
// This is actually a function pointer, so wrap it in pointer DI
614614
MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false)
@@ -641,16 +641,16 @@ pub fn type_metadata(
641641
}
642642
AdtKind::Union => {
643643
prepare_union_metadata(cx,
644-
t,
645-
unique_type_id,
646-
usage_site_span).finalize(cx)
644+
t,
645+
unique_type_id,
646+
usage_site_span).finalize(cx)
647647
}
648648
AdtKind::Enum => {
649649
prepare_enum_metadata(cx,
650-
t,
651-
def.did,
652-
unique_type_id,
653-
usage_site_span).finalize(cx)
650+
t,
651+
def.did,
652+
unique_type_id,
653+
usage_site_span).finalize(cx)
654654
}
655655
},
656656
ty::Tuple(ref elements) => {
@@ -938,7 +938,7 @@ enum MemberDescriptionFactory<'ll, 'tcx> {
938938

939939
impl MemberDescriptionFactory<'ll, 'tcx> {
940940
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
941-
-> Vec<MemberDescription<'ll>> {
941+
-> Vec<MemberDescription<'ll>> {
942942
match *self {
943943
StructMDF(ref this) => {
944944
this.create_member_descriptions(cx)
@@ -972,7 +972,7 @@ struct StructMemberDescriptionFactory<'tcx> {
972972

973973
impl<'tcx> StructMemberDescriptionFactory<'tcx> {
974974
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
975-
-> Vec<MemberDescription<'ll>> {
975+
-> Vec<MemberDescription<'ll>> {
976976
let layout = cx.layout_of(self.ty);
977977
self.variant.fields.iter().enumerate().map(|(i, f)| {
978978
let name = if self.variant.ctor_kind == CtorKind::Fn {
@@ -1042,7 +1042,7 @@ struct TupleMemberDescriptionFactory<'tcx> {
10421042

10431043
impl<'tcx> TupleMemberDescriptionFactory<'tcx> {
10441044
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
1045-
-> Vec<MemberDescription<'ll>> {
1045+
-> Vec<MemberDescription<'ll>> {
10461046
let layout = cx.layout_of(self.ty);
10471047
self.component_types.iter().enumerate().map(|(i, &component_type)| {
10481048
let (size, align) = cx.size_and_align_of(component_type);
@@ -1096,7 +1096,7 @@ struct UnionMemberDescriptionFactory<'tcx> {
10961096

10971097
impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
10981098
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
1099-
-> Vec<MemberDescription<'ll>> {
1099+
-> Vec<MemberDescription<'ll>> {
11001100
self.variant.fields.iter().enumerate().map(|(i, f)| {
11011101
let field = self.layout.field(cx, i);
11021102
let (size, align) = field.size_and_align();
@@ -1165,7 +1165,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {
11651165

11661166
impl EnumMemberDescriptionFactory<'ll, 'tcx> {
11671167
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
1168-
-> Vec<MemberDescription<'ll>> {
1168+
-> Vec<MemberDescription<'ll>> {
11691169
let adt = &self.enum_type.ty_adt_def().unwrap();
11701170
match self.layout.variants {
11711171
layout::Variants::Single { .. } if adt.variants.is_empty() => vec![],
@@ -1357,7 +1357,7 @@ fn describe_enum_variant(
13571357
// We have the layout of an enum variant, we need the layout of the outer enum
13581358
let enum_layout = cx.layout_of(layout.ty);
13591359
(Some(enum_layout.fields.offset(0)),
1360-
Some(("RUST$ENUM$DISR".to_string(), enum_layout.field(cx, 0).ty)))
1360+
Some(("RUST$ENUM$DISR".to_owned(), enum_layout.field(cx, 0).ty)))
13611361
}
13621362
_ => (None, None),
13631363
};
@@ -1471,9 +1471,8 @@ fn prepare_enum_metadata(
14711471
}
14721472
};
14731473

1474-
match (&layout.abi, discriminant_type_metadata) {
1475-
(&layout::Abi::Scalar(_), Some(discr)) => return FinalMetadata(discr),
1476-
_ => {}
1474+
if let (&layout::Abi::Scalar(_), Some(discr)) = (&layout.abi, discriminant_type_metadata) {
1475+
return FinalMetadata(discr);
14771476
}
14781477

14791478
let (enum_type_size, enum_type_align) = layout.size_and_align();
@@ -1546,7 +1545,7 @@ fn composite_type_metadata(
15461545
composite_type_metadata,
15471546
member_descriptions);
15481547

1549-
return composite_type_metadata;
1548+
composite_type_metadata
15501549
}
15511550

15521551
fn set_members_of_composite_type(cx: &CodegenCx<'ll, '_>,
@@ -1634,7 +1633,7 @@ fn create_struct_stub(
16341633
unique_type_id.as_ptr())
16351634
};
16361635

1637-
return metadata_stub;
1636+
metadata_stub
16381637
}
16391638

16401639
fn create_union_stub(
@@ -1670,7 +1669,7 @@ fn create_union_stub(
16701669
unique_type_id.as_ptr())
16711670
};
16721671

1673-
return metadata_stub;
1672+
metadata_stub
16741673
}
16751674

16761675
/// Creates debug information for the given global variable.

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 8 additions & 10 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 {
@@ -371,7 +369,7 @@ pub fn create_function_debug_context(
371369
}
372370
}
373371

374-
return create_DIArray(DIB(cx), &signature[..]);
372+
create_DIArray(DIB(cx), &signature[..])
375373
}
376374

377375
fn get_template_parameters(
@@ -428,7 +426,7 @@ pub fn create_function_debug_context(
428426
vec![]
429427
};
430428

431-
return create_DIArray(DIB(cx), &template_params[..]);
429+
create_DIArray(DIB(cx), &template_params[..])
432430
}
433431

434432
fn get_parameter_names(cx: &CodegenCx,

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

src/librustc_codegen_llvm/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
177177
ty::GeneratorWitness(..) |
178178
ty::Param(_) => {
179179
bug!("debuginfo: Trying to create type name for \
180-
unexpected type: {:?}", t);
180+
unexpected type: {:?}", t);
181181
}
182182
}
183183

src/librustc_codegen_llvm/llvm/archive_ro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ArchiveRO {
4040
return unsafe {
4141
let s = path2cstr(dst);
4242
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
43-
super::last_error().unwrap_or("failed to open archive".to_string())
43+
super::last_error().unwrap_or("failed to open archive".to_owned())
4444
})?;
4545
Ok(ArchiveRO { raw: ar })
4646
};

0 commit comments

Comments
 (0)