Skip to content

Commit

Permalink
Rollup merge of #70187 - matthiaskrgr:cl2ppy, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
more clippy fixes

    * remove redundant returns (clippy::needless_return)
    * remove redundant import (clippy::single_component_path_imports)
    * remove redundant format!() call (clippy::useless_format)
    * don't use ok() before calling expect() (clippy::ok_expect)
  • Loading branch information
Centril authored Mar 21, 2020
2 parents 621f2b7 + ad00e91 commit 3e6b1ac
Show file tree
Hide file tree
Showing 87 changed files with 142 additions and 172 deletions.
2 changes: 1 addition & 1 deletion src/libcore/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ pub fn black_box<T>(dummy: T) -> T {
// more than we want, but it's so far good enough.
unsafe {
asm!("" : : "r"(&dummy));
return dummy;
dummy
}
}
2 changes: 1 addition & 1 deletion src/librustc/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl LintLevelSets {
level = cmp::min(*driver_level, level);
}

return (level, src);
(level, src)
}

pub fn get_lint_id_level(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl<'tcx> ScopeTree {
}

debug!("temporary_scope({:?}) = None", expr_id);
return None;
None
}

/// Returns the lifetime of the variable `id`.
Expand Down Expand Up @@ -498,7 +498,7 @@ impl<'tcx> ScopeTree {

debug!("is_subscope_of({:?}, {:?})=true", subscope, superscope);

return true;
true
}

/// Returns the ID of the innermost containing body.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,11 +1447,11 @@ impl<'tcx> TyCtxt<'tcx> {
_ => return None,
};

return Some(FreeRegionInfo {
Some(FreeRegionInfo {
def_id: suitable_region_binding_scope,
boundregion: bound_region,
is_impl_item,
});
})
}

pub fn return_type_impl_trait(&self, scope_def_id: DefId) -> Option<(Ty<'tcx>, Span)> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
(Some(sz_a_val), Some(sz_b_val)) => Err(TypeError::FixedArraySize(
expected_found(relation, &sz_a_val, &sz_b_val),
)),
_ => return Err(err),
_ => Err(err),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ impl<'tcx> PolyExistentialProjection<'tcx> {
}

pub fn item_def_id(&self) -> DefId {
return self.skip_binder().item_def_id;
self.skip_binder().item_def_id
}
}

Expand Down Expand Up @@ -2000,8 +2000,8 @@ impl<'tcx> TyS<'tcx> {
#[inline]
pub fn is_unsafe_ptr(&self) -> bool {
match self.kind {
RawPtr(_) => return true,
_ => return false,
RawPtr(_) => true,
_ => false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
self.root_ty = None;
}

return t1;
t1
}

fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn decodable_substructure(
let blkarg = cx.ident_of("_d", trait_span);
let blkdecoder = cx.expr_ident(trait_span, blkarg);

return match *substr.fields {
match *substr.fields {
StaticStruct(_, ref summary) => {
let nfields = match *summary {
Unnamed(ref fields, _) => fields.len(),
Expand Down Expand Up @@ -178,7 +178,7 @@ fn decodable_substructure(
)
}
_ => cx.bug("expected StaticEnum or StaticStruct in derive(Decodable)"),
};
}
}

/// Creates a decoder for a single enum variant/struct:
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn default_substructure(
let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]);
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());

return match *substr.fields {
match *substr.fields {
StaticStruct(_, ref summary) => match *summary {
Unnamed(ref fields, is_tuple) => {
if !is_tuple {
Expand Down Expand Up @@ -83,5 +83,5 @@ fn default_substructure(
DummyResult::raw_expr(trait_span, true)
}
_ => cx.span_bug(trait_span, "method in `derive(Default)`"),
};
}
}
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn encodable_substructure(
],
));

return match *substr.fields {
match *substr.fields {
Struct(_, ref fields) => {
let emit_struct_field = cx.ident_of("emit_struct_field", trait_span);
let mut stmts = Vec::new();
Expand Down Expand Up @@ -283,5 +283,5 @@ fn encodable_substructure(
}

_ => cx.bug("expected Struct or EnumMatching in derive(Encodable)"),
};
}
}
1 change: 0 additions & 1 deletion src/librustc_builtin_macros/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ impl<'a> TraitDef<'a> {
// set earlier; see
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
// librustc_expand/base.rs:Annotatable::derive_allowed()
return;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ pub mod printf {
//
// Note: `move` used to capture copies of the cursors as they are *now*.
let fallback = move || {
return Some((
Some((
Substitution::Format(Format {
span: start.slice_between(next).unwrap(),
parameter: None,
Expand All @@ -371,7 +371,7 @@ pub mod printf {
position: InnerSpan::new(start.at, next.at),
}),
next.slice_after(),
));
))
};

// Next parsing state.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
}

// ok, don't skip this
return false;
false
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/back/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn encode(identifier: &str, bytecode: &[u8]) -> Vec<u8> {
encoded.push(0);
}

return encoded;
encoded
}

pub struct DecodedBytecode<'a> {
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'a> DecodedBytecode<'a> {
pub fn bytecode(&self) -> Vec<u8> {
let mut data = Vec::new();
DeflateDecoder::new(self.encoded_bytecode).read_to_end(&mut data).unwrap();
return data;
data
}

pub fn identifier(&self) -> &'a str {
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,11 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> {

impl CodegenCx<'ll, 'tcx> {
pub fn const_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
unsafe {
return llvm::LLVMConstArray(ty, elts.as_ptr(), elts.len() as c_uint);
}
unsafe { llvm::LLVMConstArray(ty, elts.as_ptr(), elts.len() as c_uint) }
}

pub fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value {
unsafe {
return llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint);
}
unsafe { llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint) }
}

pub fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
Expand Down Expand Up @@ -330,7 +326,7 @@ pub fn val_ty(v: &Value) -> &Type {
pub fn bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
unsafe {
let ptr = bytes.as_ptr() as *const c_char;
return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl CodegenCx<'b, 'tcx> {
ifn!("llvm.dbg.declare", fn(self.type_metadata(), self.type_metadata()) -> void);
ifn!("llvm.dbg.value", fn(self.type_metadata(), t_i64, self.type_metadata()) -> void);
}
return None;
None
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl TypeMap<'ll, 'tcx> {
let key = self.unique_id_interner.intern(&unique_type_id);
self.type_to_unique_id.insert(type_, UniqueTypeId(key));

return UniqueTypeId(key);
UniqueTypeId(key)
}

/// Gets the `UniqueTypeId` for an enum variant. Enum variants are not really
Expand Down Expand Up @@ -314,7 +314,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
member_holding_stub,
member_descriptions,
);
return MetadataCreationResult::new(metadata_stub, true);
MetadataCreationResult::new(metadata_stub, true)
}
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ fn fixed_vec_metadata(
)
};

return MetadataCreationResult::new(metadata, false);
MetadataCreationResult::new(metadata, false)
}

fn vec_slice_metadata(
Expand Down Expand Up @@ -445,7 +445,7 @@ fn subroutine_type_metadata(

return_if_metadata_created_in_meantime!(cx, unique_type_id);

return MetadataCreationResult::new(
MetadataCreationResult::new(
unsafe {
llvm::LLVMRustDIBuilderCreateSubroutineType(
DIB(cx),
Expand All @@ -454,7 +454,7 @@ fn subroutine_type_metadata(
)
},
false,
);
)
}

// FIXME(1563): This is all a bit of a hack because 'trait pointer' is an ill-
Expand Down Expand Up @@ -781,7 +781,7 @@ fn file_metadata_raw(
let key = (file_name, directory);

match debug_context(cx).created_files.borrow_mut().entry(key) {
Entry::Occupied(o) => return o.get(),
Entry::Occupied(o) => o.get(),
Entry::Vacant(v) => {
let (file_name, directory) = v.key();
debug!("file_metadata: file_name: {:?}, directory: {:?}", file_name, directory);
Expand Down Expand Up @@ -831,7 +831,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
)
};

return ty_metadata;
ty_metadata
}

fn foreign_type_metadata(
Expand Down Expand Up @@ -1273,11 +1273,11 @@ fn prepare_union_metadata(
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
// On MSVC we have to use the fallback mode, because LLVM doesn't
// lower variant parts to PDB.
return cx.sess().target.target.options.is_like_msvc
cx.sess().target.target.options.is_like_msvc
// LLVM version 7 did not release with an important bug fix;
// but the required patch is in the LLVM 8. Rust LLVM reports
// 8 as well.
|| llvm_util::get_major_version() < 8;
|| llvm_util::get_major_version() < 8
}

// FIXME(eddyb) maybe precompute this? Right now it's computed once
Expand Down Expand Up @@ -2075,7 +2075,7 @@ fn prepare_enum_metadata(
}
};

return create_and_register_recursive_type_forward_declaration(
create_and_register_recursive_type_forward_declaration(
cx,
enum_type,
unique_type_id,
Expand All @@ -2088,7 +2088,7 @@ fn prepare_enum_metadata(
containing_scope,
span,
}),
);
)
}

/// Creates debug information for a composite type, that is, anything that
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
vec![]
};

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

fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_codegen_llvm/debuginfo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {

#[allow(non_snake_case)]
pub fn create_DIArray(builder: &DIBuilder<'ll>, arr: &[Option<&'ll DIDescriptor>]) -> &'ll DIArray {
return unsafe {
llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
};
unsafe { llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) }
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ impl ArchiveRO {
/// If this archive is used with a mutable method, then an error will be
/// raised.
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
return unsafe {
unsafe {
let s = path_to_c_string(dst);
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
super::last_error().unwrap_or_else(|| "failed to open archive".to_owned())
})?;
Ok(ArchiveRO { raw: ar })
};
}
}

pub fn iter(&self) -> Iter<'_> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Command {
for k in &self.env_remove {
ret.env_remove(k);
}
return ret;
ret
}

// extensions
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ impl CrateInfo {
info.missing_lang_items.insert(cnum, missing);
}

return info;
info
}
}

Expand Down Expand Up @@ -887,7 +887,7 @@ pub fn provide_both(providers: &mut Providers<'_>) {
}
}
}
return tcx.sess.opts.optimize;
tcx.sess.opts.optimize
};

providers.dllimport_foreign_items = |tcx, krate| {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_data_structures/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ impl<'dom, Node: Idx> Iterator for Iter<'dom, Node> {
} else {
self.node = Some(dom);
}
return Some(node);
Some(node)
} else {
return None;
None
}
}
}
Loading

0 comments on commit 3e6b1ac

Please sign in to comment.