Skip to content

Commit a31a8fe

Browse files
Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errors
Remove needless returns detected by clippy in the compiler
2 parents c4488c4 + 0b20ffc commit a31a8fe

File tree

38 files changed

+66
-75
lines changed

38 files changed

+66
-75
lines changed

Diff for: compiler/rustc_ast/src/ast_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl HasTokens for StmtKind {
153153
StmtKind::Let(local) => local.tokens.as_ref(),
154154
StmtKind::Item(item) => item.tokens(),
155155
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(),
156-
StmtKind::Empty => return None,
156+
StmtKind::Empty => None,
157157
StmtKind::MacCall(mac) => mac.tokens.as_ref(),
158158
}
159159
}
@@ -162,7 +162,7 @@ impl HasTokens for StmtKind {
162162
StmtKind::Let(local) => Some(&mut local.tokens),
163163
StmtKind::Item(item) => item.tokens_mut(),
164164
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(),
165-
StmtKind::Empty => return None,
165+
StmtKind::Empty => None,
166166
StmtKind::MacCall(mac) => Some(&mut mac.tokens),
167167
}
168168
}

Diff for: compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,5 +1240,5 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
12401240
candidates.push(meta_lit.symbol);
12411241
}
12421242

1243-
return Some(candidates);
1243+
Some(candidates)
12441244
}

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3669,7 +3669,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
36693669
reinits.push(location);
36703670
return true;
36713671
}
3672-
return false;
3672+
false
36733673
};
36743674

36753675
while let Some(location) = stack.pop() {

Diff for: compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
214214
let delegate = FnMutDelegate {
215215
regions: &mut |br: ty::BoundRegion| {
216216
if let Some(ex_reg_var) = reg_map.get(&br) {
217-
return *ex_reg_var;
217+
*ex_reg_var
218218
} else {
219219
let ex_reg_var = self.next_existential_region_var(true, br.kind.get_name());
220220
debug!(?ex_reg_var);

Diff for: compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub(crate) fn check_tied_features(
290290
}
291291
}
292292
}
293-
return None;
293+
None
294294
}
295295

296296
/// Used to generate cfg variables and apply features

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ fn link_rlib<'a>(
438438
ab.add_file(&lib)
439439
}
440440

441-
return Ok(ab);
441+
Ok(ab)
442442
}
443443

444444
/// Extract all symbols defined in raw-dylib libraries, collated by library name.
@@ -1319,15 +1319,15 @@ fn link_sanitizer_runtime(
13191319
fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf {
13201320
let path = sess.target_tlib_path.dir.join(filename);
13211321
if path.exists() {
1322-
return sess.target_tlib_path.dir.clone();
1322+
sess.target_tlib_path.dir.clone()
13231323
} else {
13241324
let default_sysroot =
13251325
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
13261326
let default_tlib = filesearch::make_target_lib_path(
13271327
&default_sysroot,
13281328
sess.opts.target_triple.triple(),
13291329
);
1330-
return default_tlib;
1330+
default_tlib
13311331
}
13321332
}
13331333

Diff for: compiler/rustc_codegen_ssa/src/back/linker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,6 @@ impl<'a> Linker for L4Bender<'a> {
14841484
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
14851485
// ToDo, not implemented, copy from GCC
14861486
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
1487-
return;
14881487
}
14891488

14901489
fn subsystem(&mut self, subsystem: &str) {

Diff for: compiler/rustc_codegen_ssa/src/back/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a
171171
"Metadata at offset {offset} with size {len} is beyond .info section"
172172
));
173173
}
174-
return Ok(&info_data[offset..(offset + len)]);
174+
Ok(&info_data[offset..(offset + len)])
175175
} else {
176-
return Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"));
177-
};
176+
Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"))
177+
}
178178
}
179179

180180
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {
@@ -413,7 +413,7 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach
413413

414414
/// Is Apple's CPU subtype `arm64e`s
415415
fn macho_is_arm64e(target: &Target) -> bool {
416-
return target.llvm_target.starts_with("arm64e");
416+
target.llvm_target.starts_with("arm64e")
417417
}
418418

419419
pub enum MetadataPosition {

Diff for: compiler/rustc_const_eval/src/interpret/call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
235235
if self.layout_compat(caller_abi.layout, callee_abi.layout)? {
236236
// Ensure that our checks imply actual ABI compatibility for this concrete call.
237237
assert!(caller_abi.eq_abi(callee_abi));
238-
return Ok(true);
238+
Ok(true)
239239
} else {
240240
trace!(
241241
"check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}",
242242
caller_abi, callee_abi
243243
);
244-
return Ok(false);
244+
Ok(false)
245245
}
246246
}
247247

Diff for: compiler/rustc_expand/src/mbe/transcribe.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -773,34 +773,34 @@ fn extract_symbol_from_pnr<'a>(
773773
match pnr {
774774
ParseNtResult::Ident(nt_ident, is_raw) => {
775775
if let IdentIsRaw::Yes = is_raw {
776-
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
776+
Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR))
777+
} else {
778+
Ok(nt_ident.name)
777779
}
778-
return Ok(nt_ident.name);
779780
}
780781
ParseNtResult::Tt(TokenTree::Token(
781782
Token { kind: TokenKind::Ident(symbol, is_raw), .. },
782783
_,
783784
)) => {
784785
if let IdentIsRaw::Yes = is_raw {
785-
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
786+
Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR))
787+
} else {
788+
Ok(*symbol)
786789
}
787-
return Ok(*symbol);
788790
}
789791
ParseNtResult::Tt(TokenTree::Token(
790792
Token {
791793
kind: TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }),
792794
..
793795
},
794796
_,
795-
)) => {
796-
return Ok(*symbol);
797-
}
797+
)) => Ok(*symbol),
798798
ParseNtResult::Nt(nt)
799799
if let Nonterminal::NtLiteral(expr) = &**nt
800800
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) =
801801
&expr.kind =>
802802
{
803-
return Ok(*symbol);
803+
Ok(*symbol)
804804
}
805805
_ => Err(dcx
806806
.struct_err(

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ fn report_trait_method_mismatch<'tcx>(
10381038
false,
10391039
);
10401040

1041-
return diag.emit();
1041+
diag.emit()
10421042
}
10431043

10441044
fn check_region_bounds_on_impl_item<'tcx>(

Diff for: compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
274274
return false;
275275
}
276276

277-
return true;
277+
true
278278
})
279279
.collect::<Vec<_>>();
280280

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
605605
Abi::Rust,
606606
));
607607

608-
return Some(ExpectedSig { cause_span, sig });
608+
Some(ExpectedSig { cause_span, sig })
609609
}
610610

611611
fn sig_of_closure(

Diff for: compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10421042
return true;
10431043
}
10441044
}
1045-
return false;
1045+
false
10461046
}
10471047

10481048
fn explain_self_literal(

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'tcx> ArgMatrix<'tcx> {
307307
permutation.into_iter().map(|x| x.unwrap()).collect();
308308
return Some(Issue::Permutation(final_permutation));
309309
}
310-
return None;
310+
None
311311
}
312312

313313
// Obviously, detecting exact user intention is impossible, so the goal here is to
@@ -410,6 +410,6 @@ impl<'tcx> ArgMatrix<'tcx> {
410410
// sort errors with same type by the order they appear in the source
411411
// so that suggestion will be handled properly, see #112507
412412
errors.sort();
413-
return (errors, matched_inputs);
413+
(errors, matched_inputs)
414414
}
415415
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20512051

20522052
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
20532053
err.span_suggestion_verbose(span.shrink_to_hi(), msg, sugg, Applicability::HasPlaceholders);
2054-
return true;
2054+
true
20552055
}
20562056

20572057
pub(crate) fn suggest_coercing_result_via_try_operator(

Diff for: compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ impl<'tcx> InferCtxt<'tcx> {
14811481
// This hoists the borrow/release out of the loop body.
14821482
let inner = self.inner.try_borrow();
14831483

1484-
return move |infer_var: TyOrConstInferVar| match (infer_var, &inner) {
1484+
move |infer_var: TyOrConstInferVar| match (infer_var, &inner) {
14851485
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
14861486
use self::type_variable::TypeVariableValue;
14871487

@@ -1491,7 +1491,7 @@ impl<'tcx> InferCtxt<'tcx> {
14911491
)
14921492
}
14931493
_ => false,
1494-
};
1494+
}
14951495
}
14961496

14971497
/// `ty_or_const_infer_var_changed` is equivalent to one of these two:

Diff for: compiler/rustc_lint/src/for_loops_over_fallibles.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn extract_iterator_next_call<'tcx>(
133133
{
134134
Some(recv)
135135
} else {
136-
return None;
136+
None
137137
}
138138
}
139139

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
7171
debug_assert_ne!(parent_id, self.current_id);
7272

7373
self.current_id = parent_id;
74-
return Some(parent_id);
74+
Some(parent_id)
7575
}
7676
}
7777

@@ -103,7 +103,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
103103
self.current_id = HirId::make_owner(parent_id.def_id);
104104

105105
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
106-
return Some((self.current_id.owner, node));
106+
Some((self.current_id.owner, node))
107107
}
108108
}
109109

@@ -1233,14 +1233,14 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12331233
body_owners,
12341234
..
12351235
} = collector;
1236-
return ModuleItems {
1236+
ModuleItems {
12371237
submodules: submodules.into_boxed_slice(),
12381238
free_items: items.into_boxed_slice(),
12391239
trait_items: trait_items.into_boxed_slice(),
12401240
impl_items: impl_items.into_boxed_slice(),
12411241
foreign_items: foreign_items.into_boxed_slice(),
12421242
body_owners: body_owners.into_boxed_slice(),
1243-
};
1243+
}
12441244
}
12451245

12461246
pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
@@ -1262,14 +1262,14 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
12621262
..
12631263
} = collector;
12641264

1265-
return ModuleItems {
1265+
ModuleItems {
12661266
submodules: submodules.into_boxed_slice(),
12671267
free_items: items.into_boxed_slice(),
12681268
trait_items: trait_items.into_boxed_slice(),
12691269
impl_items: impl_items.into_boxed_slice(),
12701270
foreign_items: foreign_items.into_boxed_slice(),
12711271
body_owners: body_owners.into_boxed_slice(),
1272-
};
1272+
}
12731273
}
12741274

12751275
struct ItemCollector<'tcx> {

Diff for: compiler/rustc_middle/src/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
641641
pub fn write_uninit(&mut self, cx: &impl HasDataLayout, range: AllocRange) -> AllocResult {
642642
self.mark_init(range, false);
643643
self.provenance.clear(range, cx)?;
644-
return Ok(());
644+
Ok(())
645645
}
646646

647647
/// Remove all provenance in the given memory range.

Diff for: compiler/rustc_middle/src/mir/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1166,10 +1166,9 @@ impl<'tcx> LocalDecl<'tcx> {
11661166
/// Returns `true` if this is a DerefTemp
11671167
pub fn is_deref_temp(&self) -> bool {
11681168
match self.local_info() {
1169-
LocalInfo::DerefTemp => return true,
1170-
_ => (),
1169+
LocalInfo::DerefTemp => true,
1170+
_ => false,
11711171
}
1172-
return false;
11731172
}
11741173

11751174
/// Returns `true` is the local is from a compiler desugaring, e.g.,

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ impl<'tcx> TyCtxt<'tcx> {
20072007
));
20082008
}
20092009
}
2010-
return None;
2010+
None
20112011
}
20122012

20132013
/// Checks if the bound region is in Impl Item.

Diff for: compiler/rustc_middle/src/ty/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl BoundRegionKind {
431431

432432
pub fn get_id(&self) -> Option<DefId> {
433433
match *self {
434-
BoundRegionKind::BrNamed(id, _) => return Some(id),
434+
BoundRegionKind::BrNamed(id, _) => Some(id),
435435
_ => None,
436436
}
437437
}

Diff for: compiler/rustc_mir_build/src/build/custom/parse.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
8282
fn statement_as_expr(&self, stmt_id: StmtId) -> PResult<ExprId> {
8383
match &self.thir[stmt_id].kind {
8484
StmtKind::Expr { expr, .. } => Ok(*expr),
85-
kind @ StmtKind::Let { pattern, .. } => {
86-
return Err(ParseError {
87-
span: pattern.span,
88-
item_description: format!("{kind:?}"),
89-
expected: "expression".to_string(),
90-
});
91-
}
85+
kind @ StmtKind::Let { pattern, .. } => Err(ParseError {
86+
span: pattern.span,
87+
item_description: format!("{kind:?}"),
88+
expected: "expression".to_string(),
89+
}),
9290
}
9391
}
9492

Diff for: compiler/rustc_monomorphize/src/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) ->
11931193
return Some(new.def_id);
11941194
}
11951195
}
1196-
return None;
1196+
None
11971197
}
11981198

11991199
/// Scans the MIR in order to find function calls, closures, and drop-glue.

Diff for: compiler/rustc_parse/src/lexer/tokentrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'psess, 'src> TokenTreesReader<'psess, 'src> {
299299
}
300300
return diff_errs;
301301
}
302-
return errs;
302+
errs
303303
}
304304

305305
fn close_delim_err(&mut self, delim: Delimiter) -> PErr<'psess> {

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ impl<'a> Parser<'a> {
25532553
err.delay_as_bug();
25542554
}
25552555
}
2556-
return Ok(false); // Don't continue.
2556+
Ok(false) // Don't continue.
25572557
}
25582558

25592559
/// Attempt to parse a generic const argument that has not been enclosed in braces.

0 commit comments

Comments
 (0)