Rollup merge of #80492 - matthiaskrgr:tasty_wraps, r=varkor
remove empty wraps, don't return Results from from infallible functions This makes code easier to understand because it is more obvious when a function actually can't fail (return Err or None) Make functions that only ever return Some(x), return x directly Remove return type from functions that return Option<(), Err> but would only ever return Ok(()). Found with `clippy::unnecessary_wraps`
This commit is contained in:
commit
07083739fb
@ -485,7 +485,7 @@ pub(crate) unsafe fn optimize(
|
||||
diag_handler: &Handler,
|
||||
module: &ModuleCodegen<ModuleLlvm>,
|
||||
config: &ModuleConfig,
|
||||
) -> Result<(), FatalError> {
|
||||
) {
|
||||
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &module.name[..]);
|
||||
|
||||
let llmod = module.module_llvm.llmod();
|
||||
@ -511,7 +511,7 @@ pub(crate) unsafe fn optimize(
|
||||
_ => llvm::OptStage::PreLinkNoLTO,
|
||||
};
|
||||
optimize_with_new_llvm_pass_manager(cgcx, module, config, opt_level, opt_stage);
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
if cgcx.prof.llvm_recording_enabled() {
|
||||
@ -634,7 +634,6 @@ pub(crate) unsafe fn optimize(
|
||||
llvm::LLVMDisposePassManager(fpm);
|
||||
llvm::LLVMDisposePassManager(mpm);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn add_sanitizer_passes(config: &ModuleConfig, passes: &mut Vec<&'static mut llvm::Pass>) {
|
||||
|
@ -2322,13 +2322,13 @@ fn set_members_of_composite_type(
|
||||
DIB(cx),
|
||||
composite_type_metadata,
|
||||
Some(type_array),
|
||||
type_params,
|
||||
Some(type_params),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Computes the type parameters for a type, if any, for the given metadata.
|
||||
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'ll DIArray> {
|
||||
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIArray {
|
||||
if let ty::Adt(def, substs) = *ty.kind() {
|
||||
if substs.types().next().is_some() {
|
||||
let generics = cx.tcx.generics_of(def.did);
|
||||
@ -2358,10 +2358,10 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'
|
||||
})
|
||||
.collect();
|
||||
|
||||
return Some(create_DIArray(DIB(cx), &template_params[..]));
|
||||
return create_DIArray(DIB(cx), &template_params[..]);
|
||||
}
|
||||
}
|
||||
return Some(create_DIArray(DIB(cx), &[]));
|
||||
return create_DIArray(DIB(cx), &[]);
|
||||
|
||||
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
|
||||
let mut names = generics
|
||||
|
@ -160,7 +160,7 @@ unsafe fn optimize(
|
||||
module: &ModuleCodegen<Self::Module>,
|
||||
config: &ModuleConfig,
|
||||
) -> Result<(), FatalError> {
|
||||
back::write::optimize(cgcx, diag_handler, module, config)
|
||||
Ok(back::write::optimize(cgcx, diag_handler, module, config))
|
||||
}
|
||||
unsafe fn optimize_thin(
|
||||
cgcx: &CodegenContext<Self>,
|
||||
|
@ -185,15 +185,15 @@ fn nearest_mod_parent(&mut self, def_id: DefId) -> Module<'a> {
|
||||
|
||||
crate fn get_macro(&mut self, res: Res) -> Option<Lrc<SyntaxExtension>> {
|
||||
match res {
|
||||
Res::Def(DefKind::Macro(..), def_id) => self.get_macro_by_def_id(def_id),
|
||||
Res::Def(DefKind::Macro(..), def_id) => Some(self.get_macro_by_def_id(def_id)),
|
||||
Res::NonMacroAttr(attr_kind) => Some(self.non_macro_attr(attr_kind.is_used())),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
|
||||
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Lrc<SyntaxExtension> {
|
||||
if let Some(ext) = self.macro_map.get(&def_id) {
|
||||
return Some(ext.clone());
|
||||
return ext.clone();
|
||||
}
|
||||
|
||||
let ext = Lrc::new(match self.cstore().load_macro_untracked(def_id, &self.session) {
|
||||
@ -202,7 +202,7 @@ fn nearest_mod_parent(&mut self, def_id: DefId) -> Module<'a> {
|
||||
});
|
||||
|
||||
self.macro_map.insert(def_id, ext.clone());
|
||||
Some(ext)
|
||||
ext
|
||||
}
|
||||
|
||||
crate fn build_reduced_graph(
|
||||
|
@ -1991,14 +1991,13 @@ fn hygienic_lexical_parent_with_compatibility_fallback(
|
||||
{
|
||||
// The macro is a proc macro derive
|
||||
if let Some(def_id) = module.expansion.expn_data().macro_def_id {
|
||||
if let Some(ext) = self.get_macro_by_def_id(def_id) {
|
||||
if !ext.is_builtin
|
||||
&& ext.macro_kind() == MacroKind::Derive
|
||||
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
|
||||
{
|
||||
*poisoned = Some(node_id);
|
||||
return module.parent;
|
||||
}
|
||||
let ext = self.get_macro_by_def_id(def_id);
|
||||
if !ext.is_builtin
|
||||
&& ext.macro_kind() == MacroKind::Derive
|
||||
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
|
||||
{
|
||||
*poisoned = Some(node_id);
|
||||
return module.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ pub(super) fn assemble_candidates<'o>(
|
||||
|
||||
let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
|
||||
|
||||
self.assemble_candidates_for_trait_alias(obligation, &mut candidates)?;
|
||||
self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
|
||||
|
||||
// Other bounds. Consider both in-scope bounds from fn decl
|
||||
// and applicable impls. There is a certain set of precedence rules here.
|
||||
@ -259,11 +259,11 @@ pub(super) fn assemble_candidates<'o>(
|
||||
|
||||
// User-defined copy impls are permitted, but only for
|
||||
// structs and enums.
|
||||
self.assemble_candidates_from_impls(obligation, &mut candidates)?;
|
||||
self.assemble_candidates_from_impls(obligation, &mut candidates);
|
||||
|
||||
// For other types, we'll use the builtin rules.
|
||||
let copy_conditions = self.copy_clone_conditions(obligation);
|
||||
self.assemble_builtin_bound_candidates(copy_conditions, &mut candidates)?;
|
||||
self.assemble_builtin_bound_candidates(copy_conditions, &mut candidates);
|
||||
} else if lang_items.discriminant_kind_trait() == Some(def_id) {
|
||||
// `DiscriminantKind` is automatically implemented for every type.
|
||||
candidates.vec.push(DiscriminantKindCandidate);
|
||||
@ -271,7 +271,7 @@ pub(super) fn assemble_candidates<'o>(
|
||||
// Sized is never implementable by end-users, it is
|
||||
// always automatically computed.
|
||||
let sized_conditions = self.sized_conditions(obligation);
|
||||
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates)?;
|
||||
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates);
|
||||
} else if lang_items.unsize_trait() == Some(def_id) {
|
||||
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
|
||||
} else {
|
||||
@ -280,13 +280,13 @@ pub(super) fn assemble_candidates<'o>(
|
||||
// for `Copy` also has builtin support for `Clone`, and tuples/arrays of `Clone`
|
||||
// types have builtin support for `Clone`.
|
||||
let clone_conditions = self.copy_clone_conditions(obligation);
|
||||
self.assemble_builtin_bound_candidates(clone_conditions, &mut candidates)?;
|
||||
self.assemble_builtin_bound_candidates(clone_conditions, &mut candidates);
|
||||
}
|
||||
|
||||
self.assemble_generator_candidates(obligation, &mut candidates)?;
|
||||
self.assemble_closure_candidates(obligation, &mut candidates)?;
|
||||
self.assemble_fn_pointer_candidates(obligation, &mut candidates)?;
|
||||
self.assemble_candidates_from_impls(obligation, &mut candidates)?;
|
||||
self.assemble_generator_candidates(obligation, &mut candidates);
|
||||
self.assemble_closure_candidates(obligation, &mut candidates);
|
||||
self.assemble_fn_pointer_candidates(obligation, &mut candidates);
|
||||
self.assemble_candidates_from_impls(obligation, &mut candidates);
|
||||
self.assemble_candidates_from_object_ty(obligation, &mut candidates);
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ pub(super) fn assemble_candidates<'o>(
|
||||
// Auto implementations have lower priority, so we only
|
||||
// consider triggering a default if there is no other impl that can apply.
|
||||
if candidates.vec.is_empty() {
|
||||
self.assemble_candidates_from_auto_impls(obligation, &mut candidates)?;
|
||||
self.assemble_candidates_from_auto_impls(obligation, &mut candidates);
|
||||
}
|
||||
debug!("candidate list size: {}", candidates.vec.len());
|
||||
Ok(candidates)
|
||||
@ -367,9 +367,9 @@ fn assemble_generator_candidates(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
if self.tcx().lang_items().gen_trait() != Some(obligation.predicate.def_id()) {
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
// Okay to skip binder because the substs on generator types never
|
||||
@ -388,8 +388,6 @@ fn assemble_generator_candidates(
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks for the artificial impl that the compiler will create for an obligation like `X :
|
||||
@ -402,11 +400,11 @@ fn assemble_closure_candidates(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
let kind = match self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()) {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@ -435,8 +433,6 @@ fn assemble_closure_candidates(
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Implements one of the `Fn()` family for a fn pointer.
|
||||
@ -444,10 +440,10 @@ fn assemble_fn_pointer_candidates(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
// We provide impl of all fn traits for fn pointers.
|
||||
if self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()).is_none() {
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
// Okay to skip binder because what we are inspecting doesn't involve bound regions.
|
||||
@ -485,8 +481,6 @@ fn assemble_fn_pointer_candidates(
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Searches for impls that might apply to `obligation`.
|
||||
@ -494,7 +488,7 @@ fn assemble_candidates_from_impls(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
debug!(?obligation, "assemble_candidates_from_impls");
|
||||
|
||||
// Essentially any user-written impl will match with an error type,
|
||||
@ -504,7 +498,7 @@ fn assemble_candidates_from_impls(
|
||||
// Since compilation is already guaranteed to fail, this is just
|
||||
// to try to show the 'nicest' possible errors to the user.
|
||||
if obligation.references_error() {
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
self.tcx().for_each_relevant_impl(
|
||||
@ -518,15 +512,13 @@ fn assemble_candidates_from_impls(
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assemble_candidates_from_auto_impls(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
// Okay to skip binder here because the tests we do below do not involve bound regions.
|
||||
let self_ty = obligation.self_ty().skip_binder();
|
||||
debug!(?self_ty, "assemble_candidates_from_auto_impls");
|
||||
@ -585,8 +577,6 @@ fn assemble_candidates_from_auto_impls(
|
||||
_ => candidates.vec.push(AutoImplCandidate(def_id)),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Searches for impls that might apply to `obligation`.
|
||||
@ -753,7 +743,7 @@ fn assemble_candidates_for_trait_alias(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
// Okay to skip binder here because the tests we do below do not involve bound regions.
|
||||
let self_ty = obligation.self_ty().skip_binder();
|
||||
debug!(?self_ty, "assemble_candidates_for_trait_alias");
|
||||
@ -763,8 +753,6 @@ fn assemble_candidates_for_trait_alias(
|
||||
if self.tcx().is_trait_alias(def_id) {
|
||||
candidates.vec.push(TraitAliasCandidate(def_id));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Assembles the trait which are built-in to the language itself:
|
||||
@ -773,7 +761,7 @@ fn assemble_builtin_bound_candidates(
|
||||
&mut self,
|
||||
conditions: BuiltinImplConditions<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) -> Result<(), SelectionError<'tcx>> {
|
||||
) {
|
||||
match conditions {
|
||||
BuiltinImplConditions::Where(nested) => {
|
||||
debug!(?nested, "builtin_bound");
|
||||
@ -787,7 +775,5 @@ fn assemble_builtin_bound_candidates(
|
||||
candidates.ambiguous = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -267,15 +267,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
body_id: hir::HirId,
|
||||
) -> Result<(), ErrorReported> {
|
||||
) {
|
||||
debug!("check_drop_obligations typ: {:?}", ty);
|
||||
|
||||
let cause = &ObligationCause::misc(span, body_id);
|
||||
let infer_ok = rcx.infcx.at(cause, rcx.fcx.param_env).dropck_outlives(ty);
|
||||
debug!("dropck_outlives = {:#?}", infer_ok);
|
||||
rcx.fcx.register_infer_ok_obligations(infer_ok);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This is an implementation of the TypeRelation trait with the
|
||||
|
@ -423,9 +423,9 @@ fn probe_op<OP, R>(
|
||||
probe_cx.assemble_inherent_candidates();
|
||||
match scope {
|
||||
ProbeScope::TraitsInScope => {
|
||||
probe_cx.assemble_extension_candidates_for_traits_in_scope(scope_expr_id)?
|
||||
probe_cx.assemble_extension_candidates_for_traits_in_scope(scope_expr_id)
|
||||
}
|
||||
ProbeScope::AllTraits => probe_cx.assemble_extension_candidates_for_all_traits()?,
|
||||
ProbeScope::AllTraits => probe_cx.assemble_extension_candidates_for_all_traits(),
|
||||
};
|
||||
op(probe_cx)
|
||||
})
|
||||
@ -866,35 +866,29 @@ fn elaborate_bounds<F>(
|
||||
}
|
||||
}
|
||||
|
||||
fn assemble_extension_candidates_for_traits_in_scope(
|
||||
&mut self,
|
||||
expr_hir_id: hir::HirId,
|
||||
) -> Result<(), MethodError<'tcx>> {
|
||||
fn assemble_extension_candidates_for_traits_in_scope(&mut self, expr_hir_id: hir::HirId) {
|
||||
let mut duplicates = FxHashSet::default();
|
||||
let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id);
|
||||
if let Some(applicable_traits) = opt_applicable_traits {
|
||||
for trait_candidate in applicable_traits.iter() {
|
||||
let trait_did = trait_candidate.def_id;
|
||||
if duplicates.insert(trait_did) {
|
||||
let result = self.assemble_extension_candidates_for_trait(
|
||||
self.assemble_extension_candidates_for_trait(
|
||||
&trait_candidate.import_ids,
|
||||
trait_did,
|
||||
);
|
||||
result?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assemble_extension_candidates_for_all_traits(&mut self) -> Result<(), MethodError<'tcx>> {
|
||||
fn assemble_extension_candidates_for_all_traits(&mut self) {
|
||||
let mut duplicates = FxHashSet::default();
|
||||
for trait_info in suggest::all_traits(self.tcx) {
|
||||
if duplicates.insert(trait_info.def_id) {
|
||||
self.assemble_extension_candidates_for_trait(&smallvec![], trait_info.def_id)?;
|
||||
self.assemble_extension_candidates_for_trait(&smallvec![], trait_info.def_id);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn matches_return_type(
|
||||
@ -932,7 +926,7 @@ fn assemble_extension_candidates_for_trait(
|
||||
&mut self,
|
||||
import_ids: &SmallVec<[LocalDefId; 1]>,
|
||||
trait_def_id: DefId,
|
||||
) -> Result<(), MethodError<'tcx>> {
|
||||
) {
|
||||
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
|
||||
let trait_substs = self.fresh_item_substs(trait_def_id);
|
||||
let trait_ref = ty::TraitRef::new(trait_def_id, trait_substs);
|
||||
@ -980,7 +974,6 @@ fn assemble_extension_candidates_for_trait(
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn candidate_method_names(&self) -> Vec<Ident> {
|
||||
@ -1027,7 +1020,7 @@ fn pick(mut self) -> PickResult<'tcx> {
|
||||
let span = self.span;
|
||||
let tcx = self.tcx;
|
||||
|
||||
self.assemble_extension_candidates_for_all_traits()?;
|
||||
self.assemble_extension_candidates_for_all_traits();
|
||||
|
||||
let out_of_scope_traits = match self.pick_core() {
|
||||
Some(Ok(p)) => vec![p.item.container.id()],
|
||||
|
@ -325,7 +325,7 @@ fn constrain_bindings_in_pat(&mut self, pat: &hir::Pat<'_>) {
|
||||
pat.each_binding(|_, hir_id, span, _| {
|
||||
let typ = self.resolve_node_type(hir_id);
|
||||
let body_id = self.body_id;
|
||||
let _ = dropck::check_drop_obligations(self, typ, span, body_id);
|
||||
dropck::check_drop_obligations(self, typ, span, body_id);
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -488,7 +488,7 @@ fn check_safety_of_rvalue_destructor_if_necessary(
|
||||
if place_with_id.place.projections.is_empty() {
|
||||
let typ = self.resolve_type(place_with_id.place.ty());
|
||||
let body_id = self.body_id;
|
||||
let _ = dropck::check_drop_obligations(self, typ, span, body_id);
|
||||
dropck::check_drop_obligations(self, typ, span, body_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
crate struct StripItem(pub Item);
|
||||
|
||||
impl StripItem {
|
||||
crate fn strip(self) -> Option<Item> {
|
||||
crate fn strip(self) -> Item {
|
||||
match self.0 {
|
||||
Item { kind: box StrippedItem(..), .. } => Some(self.0),
|
||||
Item { kind: box StrippedItem(..), .. } => self.0,
|
||||
mut i => {
|
||||
i.kind = box StrippedItem(i.kind);
|
||||
Some(i)
|
||||
i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
let old = mem::replace(&mut self.update_retained, false);
|
||||
let ret = StripItem(self.fold_item_recur(i)).strip();
|
||||
self.update_retained = old;
|
||||
return ret;
|
||||
return Some(ret);
|
||||
}
|
||||
_ => return None,
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
|
||||
clean::StructFieldItem(..) => {
|
||||
if !i.visibility.is_public() {
|
||||
return StripItem(i).strip();
|
||||
return Some(StripItem(i).strip());
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
let old = mem::replace(&mut self.update_retained, false);
|
||||
let ret = StripItem(self.fold_item_recur(i)).strip();
|
||||
self.update_retained = old;
|
||||
return ret;
|
||||
return Some(ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user