Skip to content

Commit b20db78

Browse files
authored
Rollup merge of #70187 - matthiaskrgr:cl2ppy, r=Mark-Simulacrum
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)
2 parents c4494c8 + ad00e91 commit b20db78

File tree

87 files changed

+143
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+143
-174
lines changed

src/libcore/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ pub fn black_box<T>(dummy: T) -> T {
114114
// more than we want, but it's so far good enough.
115115
unsafe {
116116
asm!("" : : "r"(&dummy));
117-
return dummy;
117+
dummy
118118
}
119119
}

src/librustc/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl LintLevelSets {
8585
level = cmp::min(*driver_level, level);
8686
}
8787

88-
return (level, src);
88+
(level, src)
8989
}
9090

9191
pub fn get_lint_id_level(

src/librustc/middle/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'tcx> ScopeTree {
467467
}
468468

469469
debug!("temporary_scope({:?}) = None", expr_id);
470-
return None;
470+
None
471471
}
472472

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

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

501-
return true;
501+
true
502502
}
503503

504504
/// Returns the ID of the innermost containing body.

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1447,11 +1447,11 @@ impl<'tcx> TyCtxt<'tcx> {
14471447
_ => return None,
14481448
};
14491449

1450-
return Some(FreeRegionInfo {
1450+
Some(FreeRegionInfo {
14511451
def_id: suitable_region_binding_scope,
14521452
boundregion: bound_region,
14531453
is_impl_item,
1454-
});
1454+
})
14551455
}
14561456

14571457
pub fn return_type_impl_trait(&self, scope_def_id: DefId) -> Option<(Ty<'tcx>, Span)> {

src/librustc/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
440440
(Some(sz_a_val), Some(sz_b_val)) => Err(TypeError::FixedArraySize(
441441
expected_found(relation, &sz_a_val, &sz_b_val),
442442
)),
443-
_ => return Err(err),
443+
_ => Err(err),
444444
}
445445
}
446446
}

src/librustc/ty/sty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ impl<'tcx> PolyExistentialProjection<'tcx> {
16121612
}
16131613

16141614
pub fn item_def_id(&self) -> DefId {
1615-
return self.skip_binder().item_def_id;
1615+
self.skip_binder().item_def_id
16161616
}
16171617
}
16181618

@@ -2000,8 +2000,8 @@ impl<'tcx> TyS<'tcx> {
20002000
#[inline]
20012001
pub fn is_unsafe_ptr(&self) -> bool {
20022002
match self.kind {
2003-
RawPtr(_) => return true,
2004-
_ => return false,
2003+
RawPtr(_) => true,
2004+
_ => false,
20052005
}
20062006
}
20072007

src/librustc/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
524524
self.root_ty = None;
525525
}
526526

527-
return t1;
527+
t1
528528
}
529529

530530
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {

src/librustc_builtin_macros/deriving/decodable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn decodable_substructure(
8787
let blkarg = cx.ident_of("_d", trait_span);
8888
let blkdecoder = cx.expr_ident(trait_span, blkarg);
8989

90-
return match *substr.fields {
90+
match *substr.fields {
9191
StaticStruct(_, ref summary) => {
9292
let nfields = match *summary {
9393
Unnamed(ref fields, _) => fields.len(),
@@ -178,7 +178,7 @@ fn decodable_substructure(
178178
)
179179
}
180180
_ => cx.bug("expected StaticEnum or StaticStruct in derive(Decodable)"),
181-
};
181+
}
182182
}
183183

184184
/// Creates a decoder for a single enum variant/struct:

src/librustc_builtin_macros/deriving/default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn default_substructure(
5353
let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]);
5454
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
5555

56-
return match *substr.fields {
56+
match *substr.fields {
5757
StaticStruct(_, ref summary) => match *summary {
5858
Unnamed(ref fields, is_tuple) => {
5959
if !is_tuple {
@@ -83,5 +83,5 @@ fn default_substructure(
8383
DummyResult::raw_expr(trait_span, true)
8484
}
8585
_ => cx.span_bug(trait_span, "method in `derive(Default)`"),
86-
};
86+
}
8787
}

src/librustc_builtin_macros/deriving/encodable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn encodable_substructure(
173173
],
174174
));
175175

176-
return match *substr.fields {
176+
match *substr.fields {
177177
Struct(_, ref fields) => {
178178
let emit_struct_field = cx.ident_of("emit_struct_field", trait_span);
179179
let mut stmts = Vec::new();
@@ -283,5 +283,5 @@ fn encodable_substructure(
283283
}
284284

285285
_ => cx.bug("expected Struct or EnumMatching in derive(Encodable)"),
286-
};
286+
}
287287
}

src/librustc_builtin_macros/deriving/generic/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ impl<'a> TraitDef<'a> {
489489
// set earlier; see
490490
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
491491
// librustc_expand/base.rs:Annotatable::derive_allowed()
492-
return;
493492
}
494493
}
495494
}

src/librustc_builtin_macros/format_foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ pub mod printf {
359359
//
360360
// Note: `move` used to capture copies of the cursors as they are *now*.
361361
let fallback = move || {
362-
return Some((
362+
Some((
363363
Substitution::Format(Format {
364364
span: start.slice_between(next).unwrap(),
365365
parameter: None,
@@ -371,7 +371,7 @@ pub mod printf {
371371
position: InnerSpan::new(start.at, next.at),
372372
}),
373373
next.slice_after(),
374-
));
374+
))
375375
};
376376

377377
// Next parsing state.

src/librustc_codegen_llvm/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
146146
}
147147

148148
// ok, don't skip this
149-
return false;
149+
false
150150
})
151151
}
152152

src/librustc_codegen_llvm/back/bytecode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn encode(identifier: &str, bytecode: &[u8]) -> Vec<u8> {
8383
encoded.push(0);
8484
}
8585

86-
return encoded;
86+
encoded
8787
}
8888

8989
pub struct DecodedBytecode<'a> {
@@ -132,7 +132,7 @@ impl<'a> DecodedBytecode<'a> {
132132
pub fn bytecode(&self) -> Vec<u8> {
133133
let mut data = Vec::new();
134134
DeflateDecoder::new(self.encoded_bytecode).read_to_end(&mut data).unwrap();
135-
return data;
135+
data
136136
}
137137

138138
pub fn identifier(&self) -> &'a str {

src/librustc_codegen_llvm/common.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> {
9696

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

104102
pub fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value {
105-
unsafe {
106-
return llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint);
107-
}
103+
unsafe { llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint) }
108104
}
109105

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

src/librustc_codegen_llvm/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl CodegenCx<'b, 'tcx> {
800800
ifn!("llvm.dbg.declare", fn(self.type_metadata(), self.type_metadata()) -> void);
801801
ifn!("llvm.dbg.value", fn(self.type_metadata(), t_i64, self.type_metadata()) -> void);
802802
}
803-
return None;
803+
None
804804
}
805805
}
806806

src/librustc_codegen_llvm/debuginfo/metadata.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl TypeMap<'ll, 'tcx> {
203203
let key = self.unique_id_interner.intern(&unique_type_id);
204204
self.type_to_unique_id.insert(type_, UniqueTypeId(key));
205205

206-
return UniqueTypeId(key);
206+
UniqueTypeId(key)
207207
}
208208

209209
/// Gets the `UniqueTypeId` for an enum variant. Enum variants are not really
@@ -314,7 +314,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
314314
member_holding_stub,
315315
member_descriptions,
316316
);
317-
return MetadataCreationResult::new(metadata_stub, true);
317+
MetadataCreationResult::new(metadata_stub, true)
318318
}
319319
}
320320
}
@@ -364,7 +364,7 @@ fn fixed_vec_metadata(
364364
)
365365
};
366366

367-
return MetadataCreationResult::new(metadata, false);
367+
MetadataCreationResult::new(metadata, false)
368368
}
369369

370370
fn vec_slice_metadata(
@@ -445,7 +445,7 @@ fn subroutine_type_metadata(
445445

446446
return_if_metadata_created_in_meantime!(cx, unique_type_id);
447447

448-
return MetadataCreationResult::new(
448+
MetadataCreationResult::new(
449449
unsafe {
450450
llvm::LLVMRustDIBuilderCreateSubroutineType(
451451
DIB(cx),
@@ -454,7 +454,7 @@ fn subroutine_type_metadata(
454454
)
455455
},
456456
false,
457-
);
457+
)
458458
}
459459

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

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

834-
return ty_metadata;
834+
ty_metadata
835835
}
836836

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

12831283
// FIXME(eddyb) maybe precompute this? Right now it's computed once
@@ -2075,7 +2075,7 @@ fn prepare_enum_metadata(
20752075
}
20762076
};
20772077

2078-
return create_and_register_recursive_type_forward_declaration(
2078+
create_and_register_recursive_type_forward_declaration(
20792079
cx,
20802080
enum_type,
20812081
unique_type_id,
@@ -2088,7 +2088,7 @@ fn prepare_enum_metadata(
20882088
containing_scope,
20892089
span,
20902090
}),
2091-
);
2091+
)
20922092
}
20932093

20942094
/// Creates debug information for a composite type, that is, anything that

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
444444
vec![]
445445
};
446446

447-
return create_DIArray(DIB(cx), &template_params[..]);
447+
create_DIArray(DIB(cx), &template_params[..])
448448
}
449449

450450
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {

src/librustc_codegen_llvm/debuginfo/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
2424

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

3230
#[inline]

src/librustc_codegen_llvm/llvm/archive_ro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ impl ArchiveRO {
2727
/// If this archive is used with a mutable method, then an error will be
2828
/// raised.
2929
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
30-
return unsafe {
30+
unsafe {
3131
let s = path_to_c_string(dst);
3232
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
3333
super::last_error().unwrap_or_else(|| "failed to open archive".to_owned())
3434
})?;
3535
Ok(ArchiveRO { raw: ar })
36-
};
36+
}
3737
}
3838

3939
pub fn iter(&self) -> Iter<'_> {

src/librustc_codegen_ssa/back/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Command {
119119
for k in &self.env_remove {
120120
ret.env_remove(k);
121121
}
122-
return ret;
122+
ret
123123
}
124124

125125
// extensions

src/librustc_codegen_ssa/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl CrateInfo {
852852
info.missing_lang_items.insert(cnum, missing);
853853
}
854854

855-
return info;
855+
info
856856
}
857857
}
858858

@@ -887,7 +887,7 @@ pub fn provide_both(providers: &mut Providers<'_>) {
887887
}
888888
}
889889
}
890-
return tcx.sess.opts.optimize;
890+
tcx.sess.opts.optimize
891891
};
892892

893893
providers.dllimport_foreign_items = |tcx, krate| {

src/librustc_data_structures/graph/dominators/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ impl<'dom, Node: Idx> Iterator for Iter<'dom, Node> {
125125
} else {
126126
self.node = Some(dom);
127127
}
128-
return Some(node);
128+
Some(node)
129129
} else {
130-
return None;
130+
None
131131
}
132132
}
133133
}

0 commit comments

Comments
 (0)