Skip to content

Commit

Permalink
Rollup merge of rust-lang#130114 - eduardosm:needless-returns, r=comp…
Browse files Browse the repository at this point in the history
…iler-errors

Remove needless returns detected by clippy in the compiler
  • Loading branch information
workingjubilee authored Sep 11, 2024
2 parents 2994fde + 0b20ffc commit 9e42180
Show file tree
Hide file tree
Showing 38 changed files with 66 additions and 75 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand All @@ -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),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,5 +1240,5 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
candidates.push(meta_lit.symbol);
}

return Some(candidates);
Some(candidates)
}
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3669,7 +3669,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
reinits.push(location);
return true;
}
return false;
false
};

while let Some(location) = stack.pop() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub(crate) fn check_tied_features(
}
}
}
return None;
None
}

/// Used to generate cfg variables and apply features
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,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.
Expand Down Expand Up @@ -1342,15 +1342,15 @@ 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");
let default_tlib = filesearch::make_target_lib_path(
&default_sysroot,
sess.opts.target_triple.triple(),
);
return default_tlib;
default_tlib
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<write::Object<'static>> {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,34 +773,34 @@ 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 {
kind: TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }),
..
},
_,
)) => {
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(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ fn report_trait_method_mismatch<'tcx>(
false,
);

return diag.emit();
diag.emit()
}

fn check_region_bounds_on_impl_item<'tcx>(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
return false;
}

return true;
true
})
.collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return true;
}
}
return false;
false
}

fn explain_self_literal(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -1491,7 +1491,7 @@ impl<'tcx> InferCtxt<'tcx> {
)
}
_ => false,
};
}
}

/// `ty_or_const_infer_var_changed` is equivalent to one of these two:
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/for_loops_over_fallibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn extract_iterator_next_call<'tcx>(
{
Some(recv)
} else {
return None;
None
}
}

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
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(())
}

/// Remove all provenance in the given memory range.
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,10 +1166,9 @@ impl<'tcx> LocalDecl<'tcx> {
/// Returns `true` if this is a DerefTemp
pub fn is_deref_temp(&self) -> bool {
match self.local_info() {
LocalInfo::DerefTemp => return true,
_ => (),
LocalInfo::DerefTemp => true,
_ => false,
}
return false;
}

/// Returns `true` is the local is from a compiler desugaring, e.g.,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ impl<'tcx> TyCtxt<'tcx> {
));
}
}
return None;
None
}

/// Checks if the bound region is in Impl Item.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl BoundRegionKind {

pub fn get_id(&self) -> Option<DefId> {
match *self {
BoundRegionKind::BrNamed(id, _) => return Some(id),
BoundRegionKind::BrNamed(id, _) => Some(id),
_ => None,
}
}
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_mir_build/src/build/custom/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
fn statement_as_expr(&self, stmt_id: StmtId) -> PResult<ExprId> {
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(),
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 9e42180

Please sign in to comment.