Skip to content

Commit 74d68ea

Browse files
committed
don't create variable bindings just to return the bound value immediately (clippy::let_and_return)
1 parent 3599fd3 commit 74d68ea

File tree

15 files changed

+33
-60
lines changed

15 files changed

+33
-60
lines changed

src/liballoc/slice.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ mod hack {
145145
unsafe {
146146
let len = b.len();
147147
let b = Box::into_raw(b);
148-
let xs = Vec::from_raw_parts(b as *mut T, len, len);
149-
xs
148+
Vec::from_raw_parts(b as *mut T, len, len)
150149
}
151150
}
152151

src/librustc/hir/map/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,7 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
10381038
collector.finalize_and_compute_crate_hash(crate_disambiguator, &*tcx.cstore, cmdline_args)
10391039
};
10401040

1041-
let map = tcx.arena.alloc(IndexedHir { crate_hash, map });
1042-
1043-
map
1041+
tcx.arena.alloc(IndexedHir { crate_hash, map })
10441042
}
10451043

10461044
/// Identical to the `PpAnn` implementation for `hir::Crate`,

src/librustc_codegen_ssa/back/rpath.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ fn get_rpaths(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {
8181
rpaths.extend_from_slice(&fallback_rpaths);
8282

8383
// Remove duplicates
84-
let rpaths = minimize_rpaths(&rpaths);
85-
86-
rpaths
84+
minimize_rpaths(&rpaths)
8785
}
8886

8987
fn get_rpaths_relative_to_output(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {

src/librustc_codegen_ssa/back/write.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
288288
B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules).unwrap_or_else(|e| e.raise())
289289
};
290290

291-
let result = lto_modules
291+
lto_modules
292292
.into_iter()
293293
.map(|module| {
294294
let cost = module.cost();
@@ -303,9 +303,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
303303
0,
304304
)
305305
}))
306-
.collect();
307-
308-
result
306+
.collect()
309307
}
310308

311309
pub struct CompiledModules {

src/librustc_infer/infer/canonical/canonicalizer.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
555555
// avoid allocations in those cases. We also don't use `indices` to
556556
// determine if a kind has been seen before until the limit of 8 has
557557
// been exceeded, to also avoid allocations for `indices`.
558-
let var = if !var_values.spilled() {
558+
if !var_values.spilled() {
559559
// `var_values` is stack-allocated. `indices` isn't used yet. Do a
560560
// direct linear search of `var_values`.
561561
if let Some(idx) = var_values.iter().position(|&k| k == kind) {
@@ -589,9 +589,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
589589
assert_eq!(variables.len(), var_values.len());
590590
BoundVar::new(variables.len() - 1)
591591
})
592-
};
593-
594-
var
592+
}
595593
}
596594

597595
/// Shorthand helper that creates a canonical region variable for

src/librustc_metadata/dynamic_lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ mod dl {
9494
let result = f();
9595

9696
let last_error = libc::dlerror() as *const _;
97-
let ret = if ptr::null() == last_error {
97+
if ptr::null() == last_error {
9898
Ok(result)
9999
} else {
100100
let s = CStr::from_ptr(last_error).to_bytes();
101101
Err(str::from_utf8(s).unwrap().to_owned())
102-
};
103-
104-
ret
102+
}
105103
}
106104
}
107105

src/librustc_mir/dataflow/move_paths/builder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,13 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
184184
..
185185
} = self.builder;
186186
*rev_lookup.projections.entry((base, elem.lift())).or_insert_with(move || {
187-
let path = MoveDataBuilder::new_move_path(
187+
MoveDataBuilder::new_move_path(
188188
move_paths,
189189
path_map,
190190
init_path_map,
191191
Some(base),
192192
mk_place(*tcx),
193-
);
194-
path
193+
)
195194
})
196195
}
197196

src/librustc_mir/transform/const_prop.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
400400
where
401401
F: FnOnce(&mut Self) -> InterpResult<'tcx, T>,
402402
{
403-
let r = match f(self) {
403+
match f(self) {
404404
Ok(val) => Some(val),
405405
Err(error) => {
406406
// Some errors shouldn't come up because creating them causes
@@ -414,8 +414,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
414414
);
415415
None
416416
}
417-
};
418-
r
417+
}
419418
}
420419

421420
fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {

src/librustc_parse/lexer/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,12 @@ impl<'a> StringReader<'a> {
179179
rustc_lexer::TokenKind::LineComment => {
180180
let string = self.str_from(start);
181181
// comments with only more "/"s are not doc comments
182-
let tok = if comments::is_line_doc_comment(string) {
182+
if comments::is_line_doc_comment(string) {
183183
self.forbid_bare_cr(start, string, "bare CR not allowed in doc-comment");
184184
token::DocComment(Symbol::intern(string))
185185
} else {
186186
token::Comment
187-
};
188-
189-
tok
187+
}
190188
}
191189
rustc_lexer::TokenKind::BlockComment { terminated } => {
192190
let string = self.str_from(start);
@@ -204,14 +202,12 @@ impl<'a> StringReader<'a> {
204202
self.fatal_span_(start, last_bpos, msg).raise();
205203
}
206204

207-
let tok = if is_doc_comment {
205+
if is_doc_comment {
208206
self.forbid_bare_cr(start, string, "bare CR not allowed in block doc-comment");
209207
token::DocComment(Symbol::intern(string))
210208
} else {
211209
token::Comment
212-
};
213-
214-
tok
210+
}
215211
}
216212
rustc_lexer::TokenKind::Whitespace => token::Whitespace,
217213
rustc_lexer::TokenKind::Ident | rustc_lexer::TokenKind::RawIdent => {

src/librustc_resolve/diagnostics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ crate struct ImportSuggestion {
5959
/// `source_map` functions and this function to something more robust.
6060
fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span {
6161
let impl_span = sm.span_until_char(impl_span, '<');
62-
let impl_span = sm.span_until_whitespace(impl_span);
63-
impl_span
62+
sm.span_until_whitespace(impl_span)
6463
}
6564

6665
impl<'a> Resolver<'a> {

src/librustc_resolve/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1871,16 +1871,15 @@ impl<'a> Resolver<'a> {
18711871
// No adjustments
18721872
}
18731873
}
1874-
let result = self.resolve_ident_in_module_unadjusted_ext(
1874+
self.resolve_ident_in_module_unadjusted_ext(
18751875
module,
18761876
ident,
18771877
ns,
18781878
adjusted_parent_scope,
18791879
false,
18801880
record_used,
18811881
path_span,
1882-
);
1883-
result
1882+
)
18841883
}
18851884

18861885
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {

src/librustc_typeck/check/expr.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1069,16 +1069,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10691069
}
10701070
});
10711071

1072-
let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| {
1073-
let t = match flds {
1074-
Some(ref fs) if i < fs.len() => {
1075-
let ety = fs[i].expect_ty();
1076-
self.check_expr_coercable_to_type(&e, ety);
1077-
ety
1078-
}
1079-
_ => self.check_expr_with_expectation(&e, NoExpectation),
1080-
};
1081-
t
1072+
let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| match flds {
1073+
Some(ref fs) if i < fs.len() => {
1074+
let ety = fs[i].expect_ty();
1075+
self.check_expr_coercable_to_type(&e, ety);
1076+
ety
1077+
}
1078+
_ => self.check_expr_with_expectation(&e, NoExpectation),
10821079
});
10831080
let tuple = self.tcx.mk_tup(elt_ts_iter);
10841081
if tuple.references_error() {

src/librustc_typeck/check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3654,14 +3654,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36543654

36553655
// Otherwise, fall back to the immutable version.
36563656
let (imm_tr, imm_op) = self.resolve_place_op(op, false);
3657-
let method = match (method, imm_tr) {
3657+
match (method, imm_tr) {
36583658
(None, Some(trait_did)) => {
36593659
self.lookup_method_in_trait(span, imm_op, trait_did, base_ty, Some(arg_tys))
36603660
}
36613661
(method, _) => method,
3662-
};
3663-
3664-
method
3662+
}
36653663
}
36663664

36673665
fn check_method_argument_types(

src/librustdoc/clean/utils.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
507507
}
508508

509509
pub fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<String> {
510-
let value = cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
510+
cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
511511
let ty = cx.tcx.type_of(def_id);
512512
match (val, &ty.kind) {
513513
(_, &ty::Ref(..)) => None,
@@ -518,9 +518,7 @@ pub fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<Strin
518518
}
519519
_ => None,
520520
}
521-
});
522-
523-
value
521+
})
524522
}
525523

526524
fn format_integer_with_underscore_sep(num: &str) -> String {

src/librustdoc/html/render/cache.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -666,13 +666,12 @@ fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
666666
}
667667

668668
fn get_index_type(clean_type: &clean::Type) -> RenderType {
669-
let t = RenderType {
669+
RenderType {
670670
ty: clean_type.def_id(),
671671
idx: None,
672672
name: get_index_type_name(clean_type, true).map(|s| s.to_ascii_lowercase()),
673673
generics: get_generics(clean_type),
674-
};
675-
t
674+
}
676675
}
677676

678677
fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<String> {

0 commit comments

Comments
 (0)