Skip to content

Commit 8fe8bad

Browse files
authored
Rollup merge of rust-lang#70254 - matthiaskrgr:cl4ppy, r=Centril
couple more clippy fixes (let_and_return, if_same_then_else) * summarize if-else-code with identical blocks (clippy::if_same_then_else) * don't create variable bindings just to return the bound value immediately (clippy::let_and_return)
2 parents e5d3476 + 74d68ea commit 8fe8bad

File tree

16 files changed

+34
-67
lines changed

16 files changed

+34
-67
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
@@ -1044,9 +1044,7 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
10441044
collector.finalize_and_compute_crate_hash(crate_disambiguator, &*tcx.cstore, cmdline_args)
10451045
};
10461046

1047-
let map = tcx.arena.alloc(IndexedHir { crate_hash, map });
1048-
1049-
map
1047+
tcx.arena.alloc(IndexedHir { crate_hash, map })
10501048
}
10511049

10521050
/// 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
@@ -398,7 +398,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
398398
where
399399
F: FnOnce(&mut Self) -> InterpResult<'tcx, T>,
400400
{
401-
let r = match f(self) {
401+
match f(self) {
402402
Ok(val) => Some(val),
403403
Err(error) => {
404404
// Some errors shouldn't come up because creating them causes
@@ -412,8 +412,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
412412
);
413413
None
414414
}
415-
};
416-
r
415+
}
417416
}
418417

419418
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
@@ -187,14 +187,12 @@ impl<'a> StringReader<'a> {
187187
rustc_lexer::TokenKind::LineComment => {
188188
let string = self.str_from(start);
189189
// comments with only more "/"s are not doc comments
190-
let tok = if comments::is_line_doc_comment(string) {
190+
if comments::is_line_doc_comment(string) {
191191
self.forbid_bare_cr(start, string, "bare CR not allowed in doc-comment");
192192
token::DocComment(Symbol::intern(string))
193193
} else {
194194
token::Comment
195-
};
196-
197-
tok
195+
}
198196
}
199197
rustc_lexer::TokenKind::BlockComment { terminated } => {
200198
let string = self.str_from(start);
@@ -212,14 +210,12 @@ impl<'a> StringReader<'a> {
212210
self.fatal_span_(start, last_bpos, msg).raise();
213211
}
214212

215-
let tok = if is_doc_comment {
213+
if is_doc_comment {
216214
self.forbid_bare_cr(start, string, "bare CR not allowed in block doc-comment");
217215
token::DocComment(Symbol::intern(string))
218216
} else {
219217
token::Comment
220-
};
221-
222-
tok
218+
}
223219
}
224220
rustc_lexer::TokenKind::Whitespace => token::Whitespace,
225221
rustc_lexer::TokenKind::Ident | rustc_lexer::TokenKind::RawIdent => {

src/librustc_parse/parser/stmt.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,7 @@ impl<'a> Parser<'a> {
217217

218218
/// Parses the RHS of a local variable declaration (e.g., '= 14;').
219219
fn parse_initializer(&mut self, skip_eq: bool) -> PResult<'a, Option<P<Expr>>> {
220-
if self.eat(&token::Eq) {
221-
Ok(Some(self.parse_expr()?))
222-
} else if skip_eq {
223-
Ok(Some(self.parse_expr()?))
224-
} else {
225-
Ok(None)
226-
}
220+
if self.eat(&token::Eq) || skip_eq { Ok(Some(self.parse_expr()?)) } else { Ok(None) }
227221
}
228222

229223
/// Parses a block. No inner attributes are allowed.

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)