Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errors

Remove needless returns detected by clippy in the compiler
This commit is contained in:
Jubilee 2024-09-11 15:53:22 -07:00 committed by GitHub
commit a31a8fe0cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 66 additions and 75 deletions

View File

@ -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),
}
}

View File

@ -1240,5 +1240,5 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
candidates.push(meta_lit.symbol);
}
return Some(candidates);
Some(candidates)
}

View File

@ -3669,7 +3669,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
reinits.push(location);
return true;
}
return false;
false
};
while let Some(location) = stack.pop() {

View File

@ -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);

View File

@ -290,7 +290,7 @@ pub(crate) fn check_tied_features(
}
}
}
return None;
None
}
/// Used to generate cfg variables and apply features

View File

@ -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
}
}

View File

@ -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) {

View File

@ -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>> {
@ -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 {

View File

@ -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)
}
}

View File

@ -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(

View File

@ -1038,7 +1038,7 @@ fn report_trait_method_mismatch<'tcx>(
false,
);
return diag.emit();
diag.emit()
}
fn check_region_bounds_on_impl_item<'tcx>(

View File

@ -274,7 +274,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
return false;
}
return true;
true
})
.collect::<Vec<_>>();

View File

@ -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(

View File

@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return true;
}
}
return false;
false
}
fn explain_self_literal(

View File

@ -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)
}
}

View File

@ -2051,7 +2051,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(

View File

@ -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:

View File

@ -133,7 +133,7 @@ fn extract_iterator_next_call<'tcx>(
{
Some(recv)
} else {
return None;
None
}
}

View File

@ -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> {

View File

@ -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.

View File

@ -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.,

View File

@ -2007,7 +2007,7 @@ impl<'tcx> TyCtxt<'tcx> {
));
}
}
return None;
None
}
/// Checks if the bound region is in Impl Item.

View File

@ -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,
}
}

View File

@ -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 {
kind @ StmtKind::Let { pattern, .. } => Err(ParseError {
span: pattern.span,
item_description: format!("{kind:?}"),
expected: "expression".to_string(),
});
}
}),
}
}

View File

@ -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.

View File

@ -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> {

View File

@ -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.

View File

@ -457,7 +457,7 @@ impl<'a> Parser<'a> {
fn parse_item_builtin(&mut self) -> PResult<'a, Option<ItemInfo>> {
// To be expanded
return Ok(None);
Ok(None)
}
/// Parses an item macro, e.g., `item!();`.

View File

@ -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(

View File

@ -394,7 +394,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
}
return false;
false
}
fn visit_node(&mut self, node: Node<'tcx>) {

View File

@ -3076,7 +3076,7 @@ fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
}
}
}
return None;
None
}
fn is_span_suitable_for_use_injection(s: Span) -> bool {

View File

@ -5016,5 +5016,5 @@ fn def_id_matches_path(tcx: TyCtxt<'_>, mut def_id: DefId, expected_path: &[&str
}
def_id = parent;
}
return true;
true
}

View File

@ -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(

View File

@ -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.

View File

@ -353,7 +353,7 @@ fn build_options<O: Default>(
None => early_dcx.early_fatal(format!("unknown {outputname} option: `{key}`")),
}
}
return op;
op
}
#[allow(non_upper_case_globals)]

View File

@ -779,7 +779,7 @@ impl SourceMap {
return Ok(false);
}
}
return Ok(true);
Ok(true)
})
.is_ok_and(|is_accessible| is_accessible)
}

View File

@ -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),
}

View File

@ -66,7 +66,7 @@ where
data.last_offset = offset + Reg::f64().size;
}
data.prefix_index += 1;
return data;
data
}
fn arg_scalar_pair<C>(
@ -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)