diff --git a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs index 0484837a48d7d..56352ae963f20 100644 --- a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs +++ b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs @@ -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() } } diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 6eff086a2ba05..f5e5287cd42c5 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -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; + } + // 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. @@ -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); } ) } @@ -352,7 +352,7 @@ 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, @@ -360,7 +360,7 @@ fn vec_slice_metadata( 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, @@ -458,7 +458,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), @@ -468,7 +468,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, @@ -543,12 +543,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)) @@ -577,12 +577,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, ..}) | @@ -603,12 +603,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) @@ -641,16 +641,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) => { @@ -938,7 +938,7 @@ enum MemberDescriptionFactory<'ll, 'tcx> { impl MemberDescriptionFactory<'ll, 'tcx> { fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) - -> Vec> { + -> Vec> { match *self { StructMDF(ref this) => { this.create_member_descriptions(cx) @@ -972,7 +972,7 @@ struct StructMemberDescriptionFactory<'tcx> { impl<'tcx> StructMemberDescriptionFactory<'tcx> { fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) - -> Vec> { + -> Vec> { let layout = cx.layout_of(self.ty); self.variant.fields.iter().enumerate().map(|(i, f)| { let name = if self.variant.ctor_kind == CtorKind::Fn { @@ -1042,7 +1042,7 @@ struct TupleMemberDescriptionFactory<'tcx> { impl<'tcx> TupleMemberDescriptionFactory<'tcx> { fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) - -> Vec> { + -> Vec> { 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); @@ -1096,7 +1096,7 @@ struct UnionMemberDescriptionFactory<'tcx> { impl<'tcx> UnionMemberDescriptionFactory<'tcx> { fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) - -> Vec> { + -> Vec> { self.variant.fields.iter().enumerate().map(|(i, f)| { let field = self.layout.field(cx, i); let (size, align) = field.size_and_align(); @@ -1165,7 +1165,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> { impl EnumMemberDescriptionFactory<'ll, 'tcx> { fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) - -> Vec> { + -> Vec> { let adt = &self.enum_type.ty_adt_def().unwrap(); match self.layout.variants { layout::Variants::Single { .. } if adt.variants.is_empty() => vec![], @@ -1357,7 +1357,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), }; @@ -1471,9 +1471,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(); @@ -1546,7 +1545,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, '_>, @@ -1634,7 +1633,7 @@ fn create_struct_stub( unique_type_id.as_ptr()) }; - return metadata_stub; + metadata_stub } fn create_union_stub( @@ -1670,7 +1669,7 @@ fn create_union_stub( unique_type_id.as_ptr()) }; - return metadata_stub; + metadata_stub } /// Creates debug information for the given global variable. diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 7b0c413e85761..acb79d6f568cc 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -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 { @@ -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( @@ -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, diff --git a/src/librustc_codegen_llvm/debuginfo/source_loc.rs b/src/librustc_codegen_llvm/debuginfo/source_loc.rs index c59b5e2b8f5f5..60ebcb888166f 100644 --- a/src/librustc_codegen_llvm/debuginfo/source_loc.rs +++ b/src/librustc_codegen_llvm/debuginfo/source_loc.rs @@ -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); } } diff --git a/src/librustc_codegen_llvm/debuginfo/type_names.rs b/src/librustc_codegen_llvm/debuginfo/type_names.rs index 06b9318a5e830..f5abb527e430f 100644 --- a/src/librustc_codegen_llvm/debuginfo/type_names.rs +++ b/src/librustc_codegen_llvm/debuginfo/type_names.rs @@ -177,7 +177,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); } } diff --git a/src/librustc_codegen_llvm/llvm/archive_ro.rs b/src/librustc_codegen_llvm/llvm/archive_ro.rs index 4cbf0d92d7b99..e0a9f31e508ba 100644 --- a/src/librustc_codegen_llvm/llvm/archive_ro.rs +++ b/src/librustc_codegen_llvm/llvm/archive_ro.rs @@ -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 }) }; diff --git a/src/librustc_codegen_llvm/mir/block.rs b/src/librustc_codegen_llvm/mir/block.rs index 5be176f75c96a..68e30227185c0 100644 --- a/src/librustc_codegen_llvm/mir/block.rs +++ b/src/librustc_codegen_llvm/mir/block.rs @@ -125,10 +125,10 @@ impl FunctionCx<'a, 'll, 'tcx> { this.unreachable_block() }; let invokeret = bx.invoke(fn_ptr, - &llargs, - ret_bx, - llblock(this, cleanup), - cleanup_bundle); + &llargs, + ret_bx, + llblock(this, cleanup), + cleanup_bundle); fn_ty.apply_attrs_callsite(&bx, invokeret); if let Some((ret_dest, target)) = destination { @@ -213,7 +213,8 @@ impl FunctionCx<'a, 'll, 'tcx> { } else { let (otherwise, targets) = targets.split_last().unwrap(); let switch = bx.switch(discr.immediate(), - llblock(self, *otherwise), values.len()); + llblock(self, *otherwise), + values.len()); let switch_llty = bx.cx.layout_of(switch_ty).immediate_llvm_type(bx.cx); for (&value, target) in values.iter().zip(targets) { let llval = C_uint_big(switch_llty, value); @@ -387,8 +388,8 @@ impl FunctionCx<'a, 'll, 'tcx> { let msg_str = Symbol::intern(str).as_str(); let msg_str = C_str_slice(bx.cx, msg_str); let msg_file_line_col = C_struct(bx.cx, - &[msg_str, filename, line, col], - false); + &[msg_str, filename, line, col], + false); let msg_file_line_col = consts::addr_of(bx.cx, msg_file_line_col, align, @@ -509,8 +510,8 @@ impl FunctionCx<'a, 'll, 'tcx> { let msg_str = Symbol::intern(&str).as_str(); let msg_str = C_str_slice(bx.cx, msg_str); let msg_file_line_col = C_struct(bx.cx, - &[msg_str, filename, line, col], - false); + &[msg_str, filename, line, col], + false); let msg_file_line_col = consts::addr_of(bx.cx, msg_file_line_col, align, @@ -619,7 +620,7 @@ impl FunctionCx<'a, 'll, 'tcx> { let callee_ty = instance.as_ref().unwrap().ty(bx.cx.tcx); codegen_intrinsic_call(&bx, callee_ty, &fn_ty, &args, dest, - terminator.source_info.span); + terminator.source_info.span); if let ReturnDest::IndirectOperand(dst, _) = ret_dest { self.store_return(&bx, ret_dest, &fn_ty.ret, dst.llval); @@ -756,7 +757,7 @@ impl FunctionCx<'a, 'll, 'tcx> { // Have to load the argument, maybe while casting it. if let PassMode::Cast(ty) = arg.mode { llval = bx.load(bx.pointercast(llval, ty.llvm_type(bx.cx).ptr_to()), - align.min(arg.layout.align)); + align.min(arg.layout.align)); } else { // We can't use `PlaceRef::load` here because the argument // may have a type we don't treat as immediate, but the ABI @@ -778,10 +779,10 @@ impl FunctionCx<'a, 'll, 'tcx> { } fn codegen_arguments_untupled(&mut self, - bx: &Builder<'a, 'll, 'tcx>, - operand: &mir::Operand<'tcx>, - llargs: &mut Vec<&'ll Value>, - args: &[ArgType<'tcx, Ty<'tcx>>]) { + bx: &Builder<'a, 'll, 'tcx>, + operand: &mir::Operand<'tcx>, + llargs: &mut Vec<&'ll Value>, + args: &[ArgType<'tcx, Ty<'tcx>>]) { let tuple = self.codegen_operand(bx, operand); // Handle both by-ref and immediate tuples. @@ -933,8 +934,8 @@ impl FunctionCx<'a, 'll, 'tcx> { } fn codegen_transmute(&mut self, bx: &Builder<'a, 'll, 'tcx>, - src: &mir::Operand<'tcx>, - dst: &mir::Place<'tcx>) { + src: &mir::Operand<'tcx>, + dst: &mir::Place<'tcx>) { if let mir::Place::Local(index) = *dst { match self.locals[index] { LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place), @@ -961,8 +962,8 @@ impl FunctionCx<'a, 'll, 'tcx> { } fn codegen_transmute_into(&mut self, bx: &Builder<'a, 'll, 'tcx>, - src: &mir::Operand<'tcx>, - dst: PlaceRef<'ll, 'tcx>) { + src: &mir::Operand<'tcx>, + dst: PlaceRef<'ll, 'tcx>) { let src = self.codegen_operand(bx, src); let llty = src.layout.llvm_type(bx.cx); let cast_ptr = bx.pointercast(dst.llval, llty.ptr_to()); diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index c61a326e7c839..a6e2ccf92e4e3 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -162,16 +162,16 @@ impl FunctionCx<'a, 'll, 'tcx> { // corresponding to span's containing source scope. If so, we need to create a DIScope // "extension" into that file. fn scope_metadata_for_loc(&self, scope_id: mir::SourceScope, pos: BytePos) - -> Option<&'ll DIScope> { + -> Option<&'ll DIScope> { let scope_metadata = self.scopes[scope_id].scope_metadata; if pos < self.scopes[scope_id].file_start_pos || pos >= self.scopes[scope_id].file_end_pos { let cm = self.cx.sess().source_map(); let defining_crate = self.debug_context.get_ref(DUMMY_SP).defining_crate; Some(debuginfo::extend_scope_to_file(self.cx, - scope_metadata.unwrap(), - &cm.lookup_char_pos(pos).file, - defining_crate)) + scope_metadata.unwrap(), + &cm.lookup_char_pos(pos).file, + defining_crate)) } else { scope_metadata }