Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct MirDebugScope<'ll> {

impl MirDebugScope<'ll> {
pub fn is_valid(&self) -> bool {
!self.scope_metadata.is_none()
self.scope_metadata.is_some()
}
}

Expand Down
93 changes: 46 additions & 47 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ impl TypeMap<'ll, 'tcx> {
fn get_unique_type_id_of_type<'a>(&mut self, cx: &CodegenCx<'a, 'tcx>,
type_: Ty<'tcx>) -> UniqueTypeId {
// Let's see if we already have something in the cache
match self.type_to_unique_id.get(&type_).cloned() {
Some(unique_type_id) => return unique_type_id,
None => { /* generate one */}
};
if let Some(unique_type_id) = self.type_to_unique_id.get(&type_).cloned() {
return unique_type_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return as part of a statement should end with a semicolon. (Here and in the other changes.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of that; thanks, I'll update the PR shortly.

}
// if not, generate one

// The hasher we are using to generate the UniqueTypeId. We want
// something that provides more than the 64 bits of the DefaultHasher.
Expand Down Expand Up @@ -286,11 +286,11 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
// unique id can be found in the type map
macro_rules! return_if_metadata_created_in_meantime {
($cx: expr, $unique_type_id: expr) => (
match debug_context($cx).type_map
.borrow()
.find_metadata_for_unique_id($unique_type_id) {
Some(metadata) => return MetadataCreationResult::new(metadata, true),
None => { /* proceed normally */ }
if let Some(metadata) = debug_context($cx).type_map
.borrow()
.find_metadata_for_unique_id($unique_type_id)
{
return MetadataCreationResult::new(metadata, true)
}
)
}
Expand Down Expand Up @@ -352,15 +352,15 @@ fn vec_slice_metadata(

let member_descriptions = vec![
MemberDescription {
name: "data_ptr".to_string(),
name: "data_ptr".to_owned(),
type_metadata: data_ptr_metadata,
offset: Size::ZERO,
size: pointer_size,
align: pointer_align,
flags: DIFlags::FlagZero,
},
MemberDescription {
name: "length".to_string(),
name: "length".to_owned(),
type_metadata: type_metadata(cx, cx.tcx.types.usize, span),
offset: pointer_size,
size: usize_size,
Expand Down Expand Up @@ -463,7 +463,7 @@ fn trait_pointer_metadata(
let vtable_field = layout.field(cx, 1);
let member_descriptions = vec![
MemberDescription {
name: "pointer".to_string(),
name: "pointer".to_owned(),
type_metadata: type_metadata(cx,
cx.tcx.mk_mut_ptr(cx.tcx.types.u8),
syntax_pos::DUMMY_SP),
Expand All @@ -473,7 +473,7 @@ fn trait_pointer_metadata(
flags: DIFlags::FlagArtificial,
},
MemberDescription {
name: "vtable".to_string(),
name: "vtable".to_owned(),
type_metadata: type_metadata(cx, vtable_field.ty, syntax_pos::DUMMY_SP),
offset: layout.fields.offset(1),
size: vtable_field.size,
Expand Down Expand Up @@ -548,12 +548,12 @@ pub fn type_metadata(
_ => {
let pointee_metadata = type_metadata(cx, ty, usage_site_span);

match debug_context(cx).type_map
.borrow()
.find_metadata_for_unique_id(unique_type_id) {
Some(metadata) => return Err(metadata),
None => { /* proceed normally */ }
};
if let Some(metadata) = debug_context(cx).type_map
.borrow()
.find_metadata_for_unique_id(unique_type_id)
{
return Err(metadata)
}

Ok(MetadataCreationResult::new(pointer_type_metadata(cx, t, pointee_metadata),
false))
Expand Down Expand Up @@ -582,12 +582,12 @@ pub fn type_metadata(
}
ty::Dynamic(..) => {
MetadataCreationResult::new(
trait_pointer_metadata(cx, t, None, unique_type_id),
false)
trait_pointer_metadata(cx, t, None, unique_type_id),
false)
}
ty::Foreign(..) => {
MetadataCreationResult::new(
foreign_type_metadata(cx, t, unique_type_id),
foreign_type_metadata(cx, t, unique_type_id),
false)
}
ty::RawPtr(ty::TypeAndMut{ty, ..}) |
Expand All @@ -608,12 +608,12 @@ pub fn type_metadata(
unique_type_id,
t.fn_sig(cx.tcx),
usage_site_span).metadata;
match debug_context(cx).type_map
.borrow()
.find_metadata_for_unique_id(unique_type_id) {
Some(metadata) => return metadata,
None => { /* proceed normally */ }
};
if let Some(metadata) = debug_context(cx).type_map
.borrow()
.find_metadata_for_unique_id(unique_type_id)
{
return metadata
}

// This is actually a function pointer, so wrap it in pointer DI
MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false)
Expand Down Expand Up @@ -646,16 +646,16 @@ pub fn type_metadata(
}
AdtKind::Union => {
prepare_union_metadata(cx,
t,
unique_type_id,
usage_site_span).finalize(cx)
t,
unique_type_id,
usage_site_span).finalize(cx)
}
AdtKind::Enum => {
prepare_enum_metadata(cx,
t,
def.did,
unique_type_id,
usage_site_span).finalize(cx)
t,
def.did,
unique_type_id,
usage_site_span).finalize(cx)
}
},
ty::Tuple(ref elements) => {
Expand Down Expand Up @@ -943,7 +943,7 @@ enum MemberDescriptionFactory<'ll, 'tcx> {

impl MemberDescriptionFactory<'ll, 'tcx> {
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
-> Vec<MemberDescription<'ll>> {
-> Vec<MemberDescription<'ll>> {
match *self {
StructMDF(ref this) => {
this.create_member_descriptions(cx)
Expand Down Expand Up @@ -977,7 +977,7 @@ struct StructMemberDescriptionFactory<'tcx> {

impl<'tcx> StructMemberDescriptionFactory<'tcx> {
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
-> Vec<MemberDescription<'ll>> {
-> Vec<MemberDescription<'ll>> {
let layout = cx.layout_of(self.ty);
self.variant.fields.iter().enumerate().map(|(i, f)| {
let name = if self.variant.ctor_kind == CtorKind::Fn {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ struct TupleMemberDescriptionFactory<'tcx> {

impl<'tcx> TupleMemberDescriptionFactory<'tcx> {
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
-> Vec<MemberDescription<'ll>> {
-> Vec<MemberDescription<'ll>> {
let layout = cx.layout_of(self.ty);
self.component_types.iter().enumerate().map(|(i, &component_type)| {
let (size, align) = cx.size_and_align_of(component_type);
Expand Down Expand Up @@ -1101,7 +1101,7 @@ struct UnionMemberDescriptionFactory<'tcx> {

impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
-> Vec<MemberDescription<'ll>> {
-> Vec<MemberDescription<'ll>> {
self.variant.fields.iter().enumerate().map(|(i, f)| {
let field = self.layout.field(cx, i);
let (size, align) = field.size_and_align();
Expand Down Expand Up @@ -1170,7 +1170,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {

impl EnumMemberDescriptionFactory<'ll, 'tcx> {
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
-> Vec<MemberDescription<'ll>> {
-> Vec<MemberDescription<'ll>> {
let adt = &self.enum_type.ty_adt_def().unwrap();
match self.layout.variants {
layout::Variants::Single { .. } if adt.variants.is_empty() => vec![],
Expand Down Expand Up @@ -1362,7 +1362,7 @@ fn describe_enum_variant(
// We have the layout of an enum variant, we need the layout of the outer enum
let enum_layout = cx.layout_of(layout.ty);
(Some(enum_layout.fields.offset(0)),
Some(("RUST$ENUM$DISR".to_string(), enum_layout.field(cx, 0).ty)))
Some(("RUST$ENUM$DISR".to_owned(), enum_layout.field(cx, 0).ty)))
}
_ => (None, None),
};
Expand Down Expand Up @@ -1476,9 +1476,8 @@ fn prepare_enum_metadata(
}
};

match (&layout.abi, discriminant_type_metadata) {
(&layout::Abi::Scalar(_), Some(discr)) => return FinalMetadata(discr),
_ => {}
if let (&layout::Abi::Scalar(_), Some(discr)) = (&layout.abi, discriminant_type_metadata) {
return FinalMetadata(discr)
}

let (enum_type_size, enum_type_align) = layout.size_and_align();
Expand Down Expand Up @@ -1551,7 +1550,7 @@ fn composite_type_metadata(
composite_type_metadata,
member_descriptions);

return composite_type_metadata;
composite_type_metadata
}

fn set_members_of_composite_type(cx: &CodegenCx<'ll, '_>,
Expand Down Expand Up @@ -1639,7 +1638,7 @@ fn create_struct_stub(
unique_type_id.as_ptr())
};

return metadata_stub;
metadata_stub
}

fn create_union_stub(
Expand Down Expand Up @@ -1675,7 +1674,7 @@ fn create_union_stub(
unique_type_id.as_ptr())
};

return metadata_stub;
metadata_stub
}

/// Creates debug information for the given global variable.
Expand Down
18 changes: 8 additions & 10 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,14 @@ pub fn create_function_debug_context(
let mut flags = DIFlags::FlagPrototyped;

let local_id = cx.tcx.hir.as_local_node_id(def_id);
match *cx.sess().entry_fn.borrow() {
Some((id, _, _)) => {
if local_id == Some(id) {
flags = flags | DIFlags::FlagMainSubprogram;
}
if let Some((id, _, _)) = *cx.sess().entry_fn.borrow() {
if local_id == Some(id) {
flags |= DIFlags::FlagMainSubprogram;
}
None => {}
};
}

if cx.layout_of(sig.output()).abi.is_uninhabited() {
flags = flags | DIFlags::FlagNoReturn;
flags |= DIFlags::FlagNoReturn;
}

let fn_metadata = unsafe {
Expand Down Expand Up @@ -371,7 +369,7 @@ pub fn create_function_debug_context(
}
}

return create_DIArray(DIB(cx), &signature[..]);
create_DIArray(DIB(cx), &signature[..])
}

fn get_template_parameters(
Expand Down Expand Up @@ -428,7 +426,7 @@ pub fn create_function_debug_context(
vec![]
};

return create_DIArray(DIB(cx), &template_params[..]);
create_DIArray(DIB(cx), &template_params[..])
}

fn get_parameter_names(cx: &CodegenCx,
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_codegen_llvm/debuginfo/source_loc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ pub fn set_source_location(
/// switches source location emitting on and must therefore be called before the
/// first real statement/expression of the function is codegened.
pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext<'ll>) {
match *dbg_context {
FunctionDebugContext::RegularContext(ref data) => {
data.source_locations_enabled.set(true)
},
_ => { /* safe to ignore */ }
if let FunctionDebugContext::RegularContext(ref data) = *dbg_context {
data.source_locations_enabled.set(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
ty::GeneratorWitness(..) |
ty::Param(_) => {
bug!("debuginfo: Trying to create type name for \
unexpected type: {:?}", t);
unexpected type: {:?}", t);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ArchiveRO {
return unsafe {
let s = path2cstr(dst);
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
super::last_error().unwrap_or("failed to open archive".to_string())
super::last_error().unwrap_or("failed to open archive".to_owned())
})?;
Ok(ArchiveRO { raw: ar })
};
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
}

fn visit_place(&mut self,
place: &mir::Place<'tcx>,
context: PlaceContext<'tcx>,
location: Location) {
place: &mir::Place<'tcx>,
context: PlaceContext<'tcx>,
location: Location) {
debug!("visit_place(place={:?}, context={:?})", place, context);
let cx = self.fx.cx;

Expand Down
Loading