Skip to content

Commit 8fe8bad

Browse files
authored
Rollup merge of #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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 1 addition & 7 deletions
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.

0 commit comments

Comments
 (0)