From 339bdc491aeba8716fda35c5cd8f9ca8553902b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Sun, 8 Sep 2024 20:42:37 +0200 Subject: [PATCH] Remove needless returns detected by clippy --- compiler/rustc_ast/src/ast_traits.rs | 4 ++-- compiler/rustc_attr/src/builtin.rs | 2 +- .../src/diagnostics/conflict_errors.rs | 5 +++-- compiler/rustc_borrowck/src/lib.rs | 2 +- .../rustc_borrowck/src/type_check/relate_tys.rs | 2 +- compiler/rustc_codegen_llvm/src/llvm_util.rs | 2 +- compiler/rustc_codegen_ssa/src/back/link.rs | 6 +++--- compiler/rustc_codegen_ssa/src/back/linker.rs | 1 - compiler/rustc_codegen_ssa/src/back/metadata.rs | 8 ++++---- .../rustc_const_eval/src/check_consts/check.rs | 6 +----- compiler/rustc_const_eval/src/interpret/call.rs | 4 ++-- .../src/interpret/eval_context.rs | 2 +- .../rustc_const_eval/src/interpret/memory.rs | 2 +- compiler/rustc_expand/src/mbe/transcribe.rs | 16 ++++++++-------- compiler/rustc_hir_analysis/src/check/check.rs | 1 - .../src/check/compare_impl_item.rs | 2 +- .../rustc_hir_analysis/src/coherence/builtin.rs | 2 +- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- .../src/errors/wrong_number_of_generic_args.rs | 2 +- compiler/rustc_hir_typeck/src/closure.rs | 2 +- compiler/rustc_hir_typeck/src/demand.rs | 4 ++-- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs | 4 ++-- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 1 - .../rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 2 +- compiler/rustc_hir_typeck/src/method/suggest.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 4 ++-- .../src/infer/lexical_region_resolve/mod.rs | 4 ++-- compiler/rustc_infer/src/infer/mod.rs | 4 ++-- compiler/rustc_lint/src/drop_forget_useless.rs | 2 +- .../rustc_lint/src/for_loops_over_fallibles.rs | 2 +- compiler/rustc_lint/src/noop_method_call.rs | 4 ++-- compiler/rustc_metadata/src/locator.rs | 10 ++++------ compiler/rustc_middle/src/hir/map/mod.rs | 12 ++++++------ compiler/rustc_middle/src/mir/consts.rs | 4 ++-- .../rustc_middle/src/mir/interpret/allocation.rs | 8 ++++---- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/print/mod.rs | 5 +++-- compiler/rustc_middle/src/ty/region.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 4 +--- .../rustc_mir_build/src/build/custom/parse.rs | 12 +++++------- compiler/rustc_mir_transform/src/sroa.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 4 ++-- compiler/rustc_monomorphize/src/polymorphize.rs | 4 ++-- .../src/solve/trait_goals.rs | 2 +- compiler/rustc_parse/src/lexer/tokentrees.rs | 2 +- compiler/rustc_parse/src/parser/diagnostics.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 7 ++----- compiler/rustc_passes/src/dead.rs | 13 ++++++------- compiler/rustc_resolve/src/diagnostics.rs | 4 +--- .../rustc_resolve/src/effective_visibilities.rs | 4 ++-- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_resolve/src/late/diagnostics.rs | 2 +- compiler/rustc_session/src/filesearch.rs | 2 +- compiler/rustc_session/src/options.rs | 2 +- compiler/rustc_span/src/source_map.rs | 2 +- compiler/rustc_target/src/abi/call/mod.rs | 6 ++---- compiler/rustc_target/src/abi/call/sparc64.rs | 6 +++--- .../src/error_reporting/infer/suggest.rs | 4 +--- .../error_reporting/traits/on_unimplemented.rs | 2 +- .../src/error_reporting/traits/suggestions.rs | 2 +- .../rustc_ty_utils/src/layout_sanity_check.rs | 1 - library/alloc/src/collections/vec_deque/iter.rs | 4 ++-- .../alloc/src/collections/vec_deque/iter_mut.rs | 4 ++-- library/alloc/src/vec/in_place_collect.rs | 2 +- library/alloc/src/vec/into_iter.rs | 4 ++-- library/core/src/ptr/metadata.rs | 4 ++-- library/core/src/str/pattern.rs | 4 ++-- library/std/src/sys/pal/unix/linux/pidfd.rs | 11 ++++++----- library/std/src/sys/pal/wasi/fs.rs | 4 ++-- library/std/src/sys/pal/wasi/helpers.rs | 2 +- 73 files changed, 132 insertions(+), 153 deletions(-) diff --git a/compiler/rustc_ast/src/ast_traits.rs b/compiler/rustc_ast/src/ast_traits.rs index 6b95fb7dd36b8..60f8c6e10481b 100644 --- a/compiler/rustc_ast/src/ast_traits.rs +++ b/compiler/rustc_ast/src/ast_traits.rs @@ -153,7 +153,7 @@ impl HasTokens for StmtKind { StmtKind::Let(local) => local.tokens.as_ref(), StmtKind::Item(item) => item.tokens(), StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(), - StmtKind::Empty => return None, + StmtKind::Empty => None, StmtKind::MacCall(mac) => mac.tokens.as_ref(), } } @@ -162,7 +162,7 @@ impl HasTokens for StmtKind { StmtKind::Let(local) => Some(&mut local.tokens), StmtKind::Item(item) => item.tokens_mut(), StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(), - StmtKind::Empty => return None, + StmtKind::Empty => None, StmtKind::MacCall(mac) => Some(&mut mac.tokens), } } diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index e46dabc7a6e22..309049b98f0e2 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -1240,5 +1240,5 @@ pub fn parse_confusables(attr: &Attribute) -> Option> { candidates.push(meta_lit.symbol); } - return Some(candidates); + Some(candidates) } diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index c817b6fac7134..83e44315c9564 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -3667,9 +3667,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } if any_match { reinits.push(location); - return true; + true + } else { + false } - return false; }; while let Some(location) = stack.pop() { diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index d40dcfa58054a..3e3d5d2f6f9c3 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -1909,7 +1909,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> { (place_span.0, place_span.0, place_span.1), uninit_mpi, ); - return; // don't bother finding other problems. + // don't bother finding other problems. } } } diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index bb4a58930e1bb..421f4e2efe0e8 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -214,7 +214,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> { let delegate = FnMutDelegate { regions: &mut |br: ty::BoundRegion| { if let Some(ex_reg_var) = reg_map.get(&br) { - return *ex_reg_var; + *ex_reg_var } else { let ex_reg_var = self.next_existential_region_var(true, br.kind.get_name()); debug!(?ex_reg_var); diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index d55220ba5c3a4..6e4ddbb6f3b6a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -290,7 +290,7 @@ pub(crate) fn check_tied_features( } } } - return None; + None } /// Used to generate cfg variables and apply features diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index e8143b9a5f38f..dbb65707bd23b 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -438,7 +438,7 @@ fn link_rlib<'a>( ab.add_file(&lib) } - return Ok(ab); + Ok(ab) } /// Extract all symbols defined in raw-dylib libraries, collated by library name. @@ -1319,7 +1319,7 @@ fn link_sanitizer_runtime( fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf { let path = sess.target_tlib_path.dir.join(filename); if path.exists() { - return sess.target_tlib_path.dir.clone(); + sess.target_tlib_path.dir.clone() } else { let default_sysroot = filesearch::get_or_default_sysroot().expect("Failed finding sysroot"); @@ -1327,7 +1327,7 @@ fn link_sanitizer_runtime( &default_sysroot, sess.opts.target_triple.triple(), ); - return default_tlib; + default_tlib } } diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index cb266247e0dde..ea71b92de3ae7 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -1484,7 +1484,6 @@ impl<'a> Linker for L4Bender<'a> { fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) { // ToDo, not implemented, copy from GCC self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented); - return; } fn subsystem(&mut self, subsystem: &str) { diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 0fd9d7fffe8f9..6215616e51000 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -171,10 +171,10 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a "Metadata at offset {offset} with size {len} is beyond .info section" )); } - return Ok(&info_data[offset..(offset + len)]); + Ok(&info_data[offset..(offset + len)]) } else { - return Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}")); - }; + Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}")) + } } pub(crate) fn create_object_file(sess: &Session) -> Option> { @@ -413,7 +413,7 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach /// Is Apple's CPU subtype `arm64e`s fn macho_is_arm64e(target: &Target) -> bool { - return target.llvm_target.starts_with("arm64e"); + target.llvm_target.starts_with("arm64e") } pub enum MetadataPosition { diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 8be327a8b5647..b39780f23b2f3 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -1006,11 +1006,7 @@ fn place_as_reborrow<'tcx>( // reborrow, even if the check above were to disappear. let inner_ty = place_base.ty(body, tcx).ty; - if let ty::Ref(..) = inner_ty.kind() { - return Some(place_base); - } else { - return None; - } + if let ty::Ref(..) = inner_ty.kind() { Some(place_base) } else { None } } } _ => None, diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 568a9a3a637be..419d412b0630b 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -235,13 +235,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { if self.layout_compat(caller_abi.layout, callee_abi.layout)? { // Ensure that our checks imply actual ABI compatibility for this concrete call. assert!(caller_abi.eq_abi(callee_abi)); - return Ok(true); + Ok(true) } else { trace!( "check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}", caller_abi, callee_abi ); - return Ok(false); + Ok(false) } } diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index dd744c51f23be..8cfb3e70d4e0b 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -336,7 +336,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { return true; } } - return false; + false } /// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 45a5eb9bd52fc..1f2243d8d21da 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -859,7 +859,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { } Some(GlobalAlloc::VTable(..)) => { // No data to be accessed here. But vtables are pointer-aligned. - return (Size::ZERO, self.tcx.data_layout.pointer_align.abi, AllocKind::VTable); + (Size::ZERO, self.tcx.data_layout.pointer_align.abi, AllocKind::VTable) } // The rest must be dead. None => { diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 39489a8df1bed..2bd78d347368a 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -773,18 +773,20 @@ fn extract_symbol_from_pnr<'a>( match pnr { ParseNtResult::Ident(nt_ident, is_raw) => { if let IdentIsRaw::Yes = is_raw { - return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR)); + Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR)) + } else { + Ok(nt_ident.name) } - return Ok(nt_ident.name); } ParseNtResult::Tt(TokenTree::Token( Token { kind: TokenKind::Ident(symbol, is_raw), .. }, _, )) => { if let IdentIsRaw::Yes = is_raw { - return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR)); + Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR)) + } else { + Ok(*symbol) } - return Ok(*symbol); } ParseNtResult::Tt(TokenTree::Token( Token { @@ -792,15 +794,13 @@ fn extract_symbol_from_pnr<'a>( .. }, _, - )) => { - return Ok(*symbol); - } + )) => Ok(*symbol), ParseNtResult::Nt(nt) if let Nonterminal::NtLiteral(expr) = &**nt && let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) = &expr.kind => { - return Ok(*symbol); + Ok(*symbol) } _ => Err(dcx .struct_err( diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index e47c707ee18d9..7360f0e6a4b3d 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1116,7 +1116,6 @@ fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) { primitive scalar (integer/float/pointer) type" ) .emit(); - return; } } } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 2afed04c5bcd5..388e02b36e02c 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -1038,7 +1038,7 @@ fn report_trait_method_mismatch<'tcx>( false, ); - return diag.emit(); + diag.emit() } fn check_region_bounds_on_impl_item<'tcx>( diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 30fc06829ed8e..480116a624921 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -274,7 +274,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<() return false; } - return true; + true }) .collect::>(); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 5cb90e97eefe0..cce160b4bc3fa 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -122,7 +122,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { (ty, None) }; tcx.dcx().emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg }); - return ty; + ty } _ => Ty::new_error_with_message( diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index da89f5769d1fc..1dc1fb4a9b60e 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -807,7 +807,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { num_assoc_fn_excess_args, num_trait_generics_except_self, ), - _ => return, + _ => {} } } } diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 5117eef9ed8f5..f71427e42d4a5 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -605,7 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Abi::Rust, )); - return Some(ExpectedSig { cause_span, sig }); + Some(ExpectedSig { cause_span, sig }) } fn sig_of_closure( diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 0da299f017942..4c6eb5a58530c 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return true; } } - return false; + false } fn explain_self_literal( @@ -1182,7 +1182,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; maybe_emit_help(def_id, method.ident, args, CallableKind::Method) } - _ => return, + _ => {} } } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 19f7950287f93..3e3ad770397a3 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -899,7 +899,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match kind { hir::ClosureKind::CoroutineClosure(_) => { // FIXME(async_closures): Implement this. - return None; + None } hir::ClosureKind::Closure => Some((def_id, fn_decl, true)), hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared( diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs index cb77d3f85d935..358bc389bd138 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs @@ -307,7 +307,7 @@ impl<'tcx> ArgMatrix<'tcx> { permutation.into_iter().map(|x| x.unwrap()).collect(); return Some(Issue::Permutation(final_permutation)); } - return None; + None } // Obviously, detecting exact user intention is impossible, so the goal here is to @@ -410,6 +410,6 @@ impl<'tcx> ArgMatrix<'tcx> { // sort errors with same type by the order they appear in the source // so that suggestion will be handled properly, see #112507 errors.sort(); - return (errors, matched_inputs); + (errors, matched_inputs) } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index bdf84f332166d..174a810492518 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -697,7 +697,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { assoc.name, ), ); - return; } }; // A "softer" version of the `demand_compatible`, which checks types without persisting them, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 4454703645e79..c9ffdeea998e7 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -2028,7 +2028,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let span = expr.span.find_oldest_ancestor_in_same_ctxt(); err.span_suggestion_verbose(span.shrink_to_hi(), msg, sugg, Applicability::HasPlaceholders); - return true; + true } pub(crate) fn suggest_coercing_result_via_try_operator( diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 14ad5830111b4..471299553e073 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -513,7 +513,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.sugg_let = Some(binding); return true; } - return false; + false } } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 1930e357fc9cc..c94fdbd30f104 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -380,7 +380,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { ty::Infer(ty::IntVar(vid)) => { let nt = self.infcx.unwrap().opportunistic_resolve_int_var(vid); if nt != t { - return self.fold_ty(nt); + self.fold_ty(nt) } else { self.canonicalize_ty_var( CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Int) }, @@ -391,7 +391,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { ty::Infer(ty::FloatVar(vid)) => { let nt = self.infcx.unwrap().opportunistic_resolve_float_var(vid); if nt != t { - return self.fold_ty(nt); + self.fold_ty(nt) } else { self.canonicalize_ty_var( CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Float) }, diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index aab64883bc50f..55020c836ce0b 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -371,7 +371,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { fn sub_region_values(&self, a: VarValue<'tcx>, b: VarValue<'tcx>) -> bool { match (a, b) { // Error region is `'static` - (VarValue::ErrorValue, _) | (_, VarValue::ErrorValue) => return true, + (VarValue::ErrorValue, _) | (_, VarValue::ErrorValue) => true, (VarValue::Empty(a_ui), VarValue::Empty(b_ui)) => { // Empty regions are ordered according to the universe // they are associated with. @@ -439,7 +439,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // If this empty region is from a universe that can // name the placeholder, then the placeholder is // larger; otherwise, the only ancestor is `'static`. - return a_ui.can_name(placeholder.universe); + a_ui.can_name(placeholder.universe) } } } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 234dc5133f8db..5ebc67a7f2cc3 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1481,7 +1481,7 @@ impl<'tcx> InferCtxt<'tcx> { // This hoists the borrow/release out of the loop body. let inner = self.inner.try_borrow(); - return move |infer_var: TyOrConstInferVar| match (infer_var, &inner) { + move |infer_var: TyOrConstInferVar| match (infer_var, &inner) { (TyOrConstInferVar::Ty(ty_var), Ok(inner)) => { use self::type_variable::TypeVariableValue; @@ -1491,7 +1491,7 @@ impl<'tcx> InferCtxt<'tcx> { ) } _ => false, - }; + } } /// `ty_or_const_infer_var_changed` is equivalent to one of these two: diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs index a9de258e005c9..f2551878005c8 100644 --- a/compiler/rustc_lint/src/drop_forget_useless.rs +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -219,7 +219,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { }, ); } - _ => return, + _ => {} }; } } diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs index 2793d48dc512b..1b25f21ef84dd 100644 --- a/compiler/rustc_lint/src/for_loops_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loops_over_fallibles.rs @@ -133,7 +133,7 @@ fn extract_iterator_next_call<'tcx>( { Some(recv) } else { - return None; + None } } diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index d08a959f6547b..de75e5bcac388 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { match name { // If `type_of(x) == T` and `x.borrow()` is used to get `&T`, // then that should be allowed - sym::noop_method_borrow => return, + sym::noop_method_borrow => {} sym::noop_method_clone => cx.emit_span_lint( SUSPICIOUS_DOUBLE_REF_OP, span, @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { span, SuspiciousDoubleRefDerefDiag { ty: expr_ty }, ), - _ => return, + _ => {} } } } diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 90228db378a95..f2a0371216663 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -862,12 +862,10 @@ fn get_metadata_section<'p>( "invalid metadata version found: {}", filename.display() ))), - Err(Some(found_version)) => { - return Err(MetadataError::VersionMismatch { - expected_version: rustc_version(cfg_version), - found_version, - }); - } + Err(Some(found_version)) => Err(MetadataError::VersionMismatch { + expected_version: rustc_version(cfg_version), + found_version, + }), } } diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 3d346b9cc5d0a..8b0a855612c19 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -71,7 +71,7 @@ impl<'hir> Iterator for ParentHirIterator<'hir> { debug_assert_ne!(parent_id, self.current_id); self.current_id = parent_id; - return Some(parent_id); + Some(parent_id) } } @@ -103,7 +103,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> { self.current_id = HirId::make_owner(parent_id.def_id); let node = self.map.tcx.hir_owner_node(self.current_id.owner); - return Some((self.current_id.owner, node)); + Some((self.current_id.owner, node)) } } @@ -1233,14 +1233,14 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod body_owners, .. } = collector; - return ModuleItems { + ModuleItems { submodules: submodules.into_boxed_slice(), free_items: items.into_boxed_slice(), trait_items: trait_items.into_boxed_slice(), impl_items: impl_items.into_boxed_slice(), foreign_items: foreign_items.into_boxed_slice(), body_owners: body_owners.into_boxed_slice(), - }; + } } pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems { @@ -1262,14 +1262,14 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems { .. } = collector; - return ModuleItems { + ModuleItems { submodules: submodules.into_boxed_slice(), free_items: items.into_boxed_slice(), trait_items: trait_items.into_boxed_slice(), impl_items: impl_items.into_boxed_slice(), foreign_items: foreign_items.into_boxed_slice(), body_owners: body_owners.into_boxed_slice(), - }; + } } struct ItemCollector<'tcx> { diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index c6105d1f383b1..e61254c7e0e33 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -177,8 +177,8 @@ impl<'tcx> ConstValue<'tcx> { /// Can return `true` even if there is no provenance. pub fn may_have_provenance(&self, tcx: TyCtxt<'tcx>, size: Size) -> bool { match *self { - ConstValue::ZeroSized | ConstValue::Scalar(Scalar::Int(_)) => return false, - ConstValue::Scalar(Scalar::Ptr(..)) => return true, + ConstValue::ZeroSized | ConstValue::Scalar(Scalar::Int(_)) => false, + ConstValue::Scalar(Scalar::Ptr(..)) => true, // It's hard to find out the part of the allocation we point to; // just conservatively check everything. ConstValue::Slice { data, meta: _ } => !data.inner().provenance().ptrs().is_empty(), diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 5fb8af576ae93..2a3d34151f2c2 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -576,7 +576,7 @@ impl Allocation } // Now use this provenance. let ptr = Pointer::new(prov, Size::from_bytes(bits)); - return Ok(Scalar::from_maybe_pointer(ptr, cx)); + Ok(Scalar::from_maybe_pointer(ptr, cx)) } else { // Without OFFSET_IS_ADDR, the only remaining case we can handle is total absence of // provenance. @@ -584,7 +584,7 @@ impl Allocation return Ok(Scalar::from_uint(bits, range.size)); } // Else we have mixed provenance, that doesn't work. - return Err(AllocError::ReadPartialPointer(range.start)); + Err(AllocError::ReadPartialPointer(range.start)) } } else { // We are *not* reading a pointer. @@ -594,7 +594,7 @@ impl Allocation return Ok(Scalar::from_uint(bits, range.size)); } // There is some provenance and we don't have OFFSET_IS_ADDR. This doesn't work. - return Err(AllocError::ReadPointerAsInt(None)); + Err(AllocError::ReadPointerAsInt(None)) } } @@ -641,7 +641,7 @@ impl Allocation pub fn write_uninit(&mut self, cx: &impl HasDataLayout, range: AllocRange) -> AllocResult { self.mark_init(range, false); self.provenance.clear(range, cx)?; - return Ok(()); + Ok(()) } /// Applies a previously prepared provenance copy. diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 081a23b6ff317..c3995afcc52a9 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1169,7 +1169,7 @@ impl<'tcx> LocalDecl<'tcx> { LocalInfo::DerefTemp => return true, _ => (), } - return false; + false } /// Returns `true` is the local is from a compiler desugaring, e.g., diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 2a3008897c676..2571cbbf29965 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2003,7 +2003,7 @@ impl<'tcx> TyCtxt<'tcx> { )); } } - return None; + None } /// Checks if the bound region is in Impl Item. diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index cc7467467603a..e122f0413ec6f 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -273,9 +273,10 @@ fn characteristic_def_id_of_type_cached<'a>( ty::Tuple(tys) => tys.iter().find_map(|ty| { if visited.insert(ty) { - return characteristic_def_id_of_type_cached(ty, visited); + characteristic_def_id_of_type_cached(ty, visited) + } else { + None } - return None; }), ty::FnDef(def_id, _) diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index a2a961057771a..44956d5b0a6bd 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -431,7 +431,7 @@ impl BoundRegionKind { pub fn get_id(&self) -> Option { match *self { - BoundRegionKind::BrNamed(id, _) => return Some(id), + BoundRegionKind::BrNamed(id, _) => Some(id), _ => None, } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index d70ff8258d04c..ce3834e6d3bbc 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1790,9 +1790,7 @@ where } Ok(intern(folder.cx(), &new_list)) } - Some((_, Err(err))) => { - return Err(err); - } + Some((_, Err(err))) => Err(err), None => Ok(list), } } diff --git a/compiler/rustc_mir_build/src/build/custom/parse.rs b/compiler/rustc_mir_build/src/build/custom/parse.rs index 646aefa08829e..1f186c8f99afe 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse.rs @@ -82,13 +82,11 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { fn statement_as_expr(&self, stmt_id: StmtId) -> PResult { match &self.thir[stmt_id].kind { StmtKind::Expr { expr, .. } => Ok(*expr), - kind @ StmtKind::Let { pattern, .. } => { - return Err(ParseError { - span: pattern.span, - item_description: format!("{kind:?}"), - expected: "expression".to_string(), - }); - } + kind @ StmtKind::Let { pattern, .. } => Err(ParseError { + span: pattern.span, + item_description: format!("{kind:?}"), + expected: "expression".to_string(), + }), } } diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index 3c5ccc0c99a8a..327e2e1a232e1 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -149,7 +149,7 @@ fn escaping_locals<'tcx>( // Storage statements are expanded in run_pass. StatementKind::StorageLive(..) | StatementKind::StorageDead(..) - | StatementKind::Deinit(..) => return, + | StatementKind::Deinit(..) => {} _ => self.super_statement(statement, location), } } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 093697a290c00..2224900a91a39 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -648,7 +648,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> { ), Err(err @ ErrorHandled::Reported(..)) => { err.emit_note(self.tcx); - return None; + None } } } @@ -1193,7 +1193,7 @@ fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> return Some(new.def_id); } } - return None; + None } /// Scans the MIR in order to find function calls, closures, and drop-glue. diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index c65ad9fa67e53..f39a231a9ef9a 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -106,11 +106,11 @@ fn should_polymorphize<'tcx>( match tcx.hir().body_const_context(def_id.expect_local()) { Some(ConstContext::ConstFn) | None if !tcx.is_mir_available(def_id) => { debug!("no mir available"); - return false; + false } Some(_) if !tcx.is_ctfe_mir_available(def_id) => { debug!("no ctfe mir available"); - return false; + false } _ => true, } diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 683d8dab3b2a8..2d1a559c4959e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -1172,7 +1172,7 @@ where trace!(?def_id, ?goal, "disqualified auto-trait implementation"); // No need to actually consider the candidate here, // since we do that in `consider_impl_candidate`. - return Some(Err(NoSolution)); + Some(Err(NoSolution)) } else { None } diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs index e7a7105803fcd..c83d8bf4021ee 100644 --- a/compiler/rustc_parse/src/lexer/tokentrees.rs +++ b/compiler/rustc_parse/src/lexer/tokentrees.rs @@ -299,7 +299,7 @@ impl<'psess, 'src> TokenTreesReader<'psess, 'src> { } return diff_errs; } - return errs; + errs } fn close_delim_err(&mut self, delim: Delimiter) -> PErr<'psess> { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f6f66821df7fb..bee73c58cb794 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2553,7 +2553,7 @@ impl<'a> Parser<'a> { err.delay_as_bug(); } } - return Ok(false); // Don't continue. + Ok(false) // Don't continue. } /// Attempt to parse a generic const argument that has not been enclosed in braces. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index c6a5e1908f704..83d10dea6a8fb 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -457,7 +457,7 @@ impl<'a> Parser<'a> { fn parse_item_builtin(&mut self) -> PResult<'a, Option> { // To be expanded - return Ok(None); + Ok(None) } /// Parses an item macro, e.g., `item!();`. diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index e41f89a3c9da9..f1664789cb5a3 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1905,10 +1905,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { || (int_reprs == 1 && is_c && item.is_some_and(|item| { - if let ItemLike::Item(item) = item { - return is_c_like_enum(item); - } - return false; + if let ItemLike::Item(item) = item { is_c_like_enum(item) } else { false } })) { self.tcx.emit_node_span_lint( @@ -2350,7 +2347,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_coroutine(&self, attr: &Attribute, target: Target) { match target { - Target::Closure => return, + Target::Closure => {} _ => { self.dcx().emit_err(errors::CoroutineOnNonClosure { span: attr.span }); } diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 7f1e906ffd737..0a2716df67148 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -193,17 +193,16 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { return true; } } - return false; + false } (hir::ExprKind::Field(lhs_l, ident_l), hir::ExprKind::Field(lhs_r, ident_r)) => { if ident_l == ident_r { - return check_for_self_assign_helper(typeck_results, lhs_l, lhs_r); + check_for_self_assign_helper(typeck_results, lhs_l, lhs_r) + } else { + false } - return false; - } - _ => { - return false; } + _ => false, } } @@ -394,7 +393,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { } } - return false; + false } fn visit_node(&mut self, node: Node<'tcx>) { diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index bcbdf627b5662..36742dbef1697 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -3040,7 +3040,6 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder { self.first_legal_span = Some(inject); } self.first_use_span = search_for_any_use_in_items(&c.items); - return; } else { visit::walk_crate(self, c); } @@ -3054,7 +3053,6 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder { self.first_legal_span = Some(inject); } self.first_use_span = search_for_any_use_in_items(items); - return; } } else { visit::walk_item(self, item); @@ -3076,7 +3074,7 @@ fn search_for_any_use_in_items(items: &[P]) -> Option { } } } - return None; + None } fn is_span_suitable_for_use_injection(s: Span) -> bool { diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index 5ee495da2d93d..bb976d7035d77 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -231,7 +231,7 @@ impl<'r, 'ast, 'tcx> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r, 't // If it's a mod, also make the visitor walk all of its items match item.kind { // Resolved in rustc_privacy when types are available - ast::ItemKind::Impl(..) => return, + ast::ItemKind::Impl(..) => {} // Should be unreachable at this stage ast::ItemKind::MacCall(..) | ast::ItemKind::DelegationMac(..) => panic!( @@ -276,7 +276,7 @@ impl<'r, 'ast, 'tcx> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r, 't | ast::ItemKind::MacroDef(..) | ast::ItemKind::ForeignMod(..) | ast::ItemKind::Fn(..) - | ast::ItemKind::Delegation(..) => return, + | ast::ItemKind::Delegation(..) => {} } } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 917cb81aa511f..40a6ac70bfdd8 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -5016,5 +5016,5 @@ fn def_id_matches_path(tcx: TyCtxt<'_>, mut def_id: DefId, expected_path: &[&str } def_id = parent; } - return true; + true } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 8f516c2db0900..098509cd1d508 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -779,7 +779,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { candidates = self.smart_resolve_partial_mod_path_errors(path, following_seg); } - return (false, candidates); + (false, candidates) } fn suggest_trait_and_bounds( diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index d78f4a78de732..e72d4face3c87 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -182,7 +182,7 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> { } } - return sysroot_candidates; + sysroot_candidates } /// Returns the provided sysroot or calls [`get_or_default_sysroot`] if it's none. diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index a57dc80b3168d..982a3d5cf110d 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -353,7 +353,7 @@ fn build_options( None => early_dcx.early_fatal(format!("unknown {outputname} option: `{key}`")), } } - return op; + op } #[allow(non_upper_case_globals)] diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index f914e8dc1baaa..98447147d3e13 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -779,7 +779,7 @@ impl SourceMap { return Ok(false); } } - return Ok(true); + Ok(true) }) .is_ok_and(|is_accessible| is_accessible) } diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 082c169b210f8..c2826b55dc5b1 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -188,7 +188,7 @@ impl ArgAttributes { if self.arg_ext != other.arg_ext { return false; } - return true; + true } } @@ -632,7 +632,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { PassMode::Indirect { .. } => { self.mode = PassMode::Direct(ArgAttributes::new()); } - PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) => return, // already direct + PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) => {} // already direct _ => panic!("Tried to make {:?} direct", self.mode), } } @@ -646,7 +646,6 @@ impl<'a, Ty> ArgAbi<'a, Ty> { } PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false } => { // already indirect - return; } _ => panic!("Tried to make {:?} indirect", self.mode), } @@ -661,7 +660,6 @@ impl<'a, Ty> ArgAbi<'a, Ty> { } PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false } => { // already indirect - return; } _ => panic!("Tried to make {:?} indirect (expected `PassMode::Ignore`)", self.mode), } diff --git a/compiler/rustc_target/src/abi/call/sparc64.rs b/compiler/rustc_target/src/abi/call/sparc64.rs index 2954d9642df95..835353f76fc9a 100644 --- a/compiler/rustc_target/src/abi/call/sparc64.rs +++ b/compiler/rustc_target/src/abi/call/sparc64.rs @@ -66,7 +66,7 @@ where data.last_offset = offset + Reg::f64().size; } data.prefix_index += 1; - return data; + data } fn arg_scalar_pair( @@ -92,7 +92,7 @@ where offset += Size::from_bytes(4 - (offset.bytes() % 4)); } data = arg_scalar(cx, scalar2, offset, data); - return data; + data } fn parse_structure<'a, Ty, C>( @@ -128,7 +128,7 @@ where } } - return data; + data } fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, in_registers_max: Size) diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs index 50cbdcc615185..b0d557f5e6c81 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs @@ -470,9 +470,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { diag.subdiagnostic(FnConsiderCasting { casting }); } - _ => { - return; - } + _ => {} }; } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs index 41b0ee56a4cb5..ff87cdddae750 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs @@ -530,7 +530,7 @@ impl<'tcx> OnUnimplementedDirective { pub fn of_item(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> Result, ErrorGuaranteed> { if let Some(attr) = tcx.get_attr(item_def_id, sym::rustc_on_unimplemented) { - return Self::parse_attribute(attr, false, tcx, item_def_id); + Self::parse_attribute(attr, false, tcx, item_def_id) } else { tcx.get_attrs_by_path(item_def_id, &[sym::diagnostic, sym::on_unimplemented]) .filter_map(|attr| Self::parse_attribute(attr, true, tcx, item_def_id).transpose()) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 45e157b108006..bdc983ac7744d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -1401,7 +1401,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { return true; } } - return false; + false }; if let ObligationCauseCode::ImplDerived(cause) = &*code { diff --git a/compiler/rustc_ty_utils/src/layout_sanity_check.rs b/compiler/rustc_ty_utils/src/layout_sanity_check.rs index 2223aca28d1f6..468d44b1c3d68 100644 --- a/compiler/rustc_ty_utils/src/layout_sanity_check.rs +++ b/compiler/rustc_ty_utils/src/layout_sanity_check.rs @@ -109,7 +109,6 @@ pub(super) fn sanity_check_layout<'tcx>( } FieldsShape::Union(..) => { // FIXME: I guess we could also check something here? Like, look at all fields? - return; } FieldsShape::Arbitrary { .. } => { // Should be an enum, the only field is the discriminant. diff --git a/library/alloc/src/collections/vec_deque/iter.rs b/library/alloc/src/collections/vec_deque/iter.rs index bf4dd66f47638..6922ea9b79bfd 100644 --- a/library/alloc/src/collections/vec_deque/iter.rs +++ b/library/alloc/src/collections/vec_deque/iter.rs @@ -73,7 +73,7 @@ impl<'a, T> Iterator for Iter<'a, T> { fn advance_by(&mut self, n: usize) -> Result<(), NonZero> { let remaining = self.i1.advance_by(n); match remaining { - Ok(()) => return Ok(()), + Ok(()) => Ok(()), Err(n) => { mem::swap(&mut self.i1, &mut self.i2); self.i1.advance_by(n.get()) @@ -144,7 +144,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero> { match self.i2.advance_back_by(n) { - Ok(()) => return Ok(()), + Ok(()) => Ok(()), Err(n) => { mem::swap(&mut self.i1, &mut self.i2); self.i2.advance_back_by(n.get()) diff --git a/library/alloc/src/collections/vec_deque/iter_mut.rs b/library/alloc/src/collections/vec_deque/iter_mut.rs index 7a349a1b4edd0..84b7410958013 100644 --- a/library/alloc/src/collections/vec_deque/iter_mut.rs +++ b/library/alloc/src/collections/vec_deque/iter_mut.rs @@ -64,7 +64,7 @@ impl<'a, T> Iterator for IterMut<'a, T> { fn advance_by(&mut self, n: usize) -> Result<(), NonZero> { match self.i1.advance_by(n) { - Ok(()) => return Ok(()), + Ok(()) => Ok(()), Err(remaining) => { mem::swap(&mut self.i1, &mut self.i2); self.i1.advance_by(remaining.get()) @@ -135,7 +135,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero> { match self.i2.advance_back_by(n) { - Ok(()) => return Ok(()), + Ok(()) => Ok(()), Err(remaining) => { mem::swap(&mut self.i1, &mut self.i2); self.i2.advance_back_by(remaining.get()) diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index d119e6ca397c5..ec0ab8ee7289c 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -208,7 +208,7 @@ const fn needs_realloc(src_cap: usize, dst_cap: usize) -> bool { // type layouts don't guarantee a fit, so do a runtime check to see if // the allocations happen to match - return src_cap > 0 && src_cap * mem::size_of::() != dst_cap * mem::size_of::(); + src_cap > 0 && src_cap * mem::size_of::() != dst_cap * mem::size_of::() } /// This provides a shorthand for the source type since local type aliases aren't a thing. diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index fad8abad49353..92c5e360da453 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -288,11 +288,11 @@ impl Iterator for IntoIter { // Safety: `len` is larger than the array size. Copy a fixed amount here to fully initialize // the array. - return unsafe { + unsafe { ptr::copy_nonoverlapping(self.ptr.as_ptr(), raw_ary.as_mut_ptr() as *mut T, N); self.ptr = self.ptr.add(N); Ok(raw_ary.transpose().assume_init()) - }; + } } fn fold(mut self, mut accum: B, mut f: F) -> B diff --git a/library/core/src/ptr/metadata.rs b/library/core/src/ptr/metadata.rs index ccc9f8754f00c..76a0e2ba77483 100644 --- a/library/core/src/ptr/metadata.rs +++ b/library/core/src/ptr/metadata.rs @@ -187,14 +187,14 @@ impl DynMetadata { // Consider a reference like `&(i32, dyn Send)`: the vtable will only store the size of the // `Send` part! // SAFETY: DynMetadata always contains a valid vtable pointer - return unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) }; + unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) } } /// Returns the alignment of the type associated with this vtable. #[inline] pub fn align_of(self) -> usize { // SAFETY: DynMetadata always contains a valid vtable pointer - return unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) }; + unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) } } /// Returns the size and alignment together as a `Layout` diff --git a/library/core/src/str/pattern.rs b/library/core/src/str/pattern.rs index 2f1096db8f00c..9f1294d760647 100644 --- a/library/core/src/str/pattern.rs +++ b/library/core/src/str/pattern.rs @@ -1814,7 +1814,7 @@ fn simd_contains(needle: &str, haystack: &str) -> Option { } mask &= !(1 << trailing); } - return false; + false }; let test_chunk = |idx| -> u16 { @@ -1830,7 +1830,7 @@ fn simd_contains(needle: &str, haystack: &str) -> Option { let both = eq_first.bitand(eq_last); let mask = both.to_bitmask() as u16; - return mask; + mask }; let mut i = 0; diff --git a/library/std/src/sys/pal/unix/linux/pidfd.rs b/library/std/src/sys/pal/unix/linux/pidfd.rs index 7474f80e94f9d..78744430f3b51 100644 --- a/library/std/src/sys/pal/unix/linux/pidfd.rs +++ b/library/std/src/sys/pal/unix/linux/pidfd.rs @@ -13,7 +13,7 @@ pub(crate) struct PidFd(FileDesc); impl PidFd { pub fn kill(&self) -> io::Result<()> { - return cvt(unsafe { + cvt(unsafe { libc::syscall( libc::SYS_pidfd_send_signal, self.0.as_raw_fd(), @@ -22,7 +22,7 @@ impl PidFd { 0, ) }) - .map(drop); + .map(drop) } pub fn wait(&self) -> io::Result { @@ -30,7 +30,7 @@ impl PidFd { cvt(unsafe { libc::waitid(libc::P_PIDFD, self.0.as_raw_fd() as u32, &mut siginfo, libc::WEXITED) })?; - return Ok(ExitStatus::from_waitid_siginfo(siginfo)); + Ok(ExitStatus::from_waitid_siginfo(siginfo)) } pub fn try_wait(&self) -> io::Result> { @@ -45,9 +45,10 @@ impl PidFd { ) })?; if unsafe { siginfo.si_pid() } == 0 { - return Ok(None); + Ok(None) + } else { + Ok(Some(ExitStatus::from_waitid_siginfo(siginfo))) } - return Ok(Some(ExitStatus::from_waitid_siginfo(siginfo))); } } diff --git a/library/std/src/sys/pal/wasi/fs.rs b/library/std/src/sys/pal/wasi/fs.rs index 88b1e543ec7c2..e1c61cae9f810 100644 --- a/library/std/src/sys/pal/wasi/fs.rs +++ b/library/std/src/sys/pal/wasi/fs.rs @@ -265,7 +265,7 @@ impl OpenOptions { pub fn new() -> OpenOptions { let mut base = OpenOptions::default(); base.dirflags = wasi::LOOKUPFLAGS_SYMLINK_FOLLOW; - return base; + base } pub fn read(&mut self, read: bool) { @@ -382,7 +382,7 @@ impl OpenOptions { base |= wasi::RIGHTS_PATH_UNLINK_FILE; base |= wasi::RIGHTS_POLL_FD_READWRITE; - return base; + base } fn rights_inheriting(&self) -> wasi::Rights { diff --git a/library/std/src/sys/pal/wasi/helpers.rs b/library/std/src/sys/pal/wasi/helpers.rs index d047bf2fce857..37ef17858cb96 100644 --- a/library/std/src/sys/pal/wasi/helpers.rs +++ b/library/std/src/sys/pal/wasi/helpers.rs @@ -115,7 +115,7 @@ pub fn hashmap_random_keys() -> (u64, u64) { let len = mem::size_of_val(&ret); wasi::random_get(base, len).expect("random_get failure"); } - return ret; + ret } #[inline]