Skip to content

Commit e5ead5f

Browse files
committed
remove unused return types such as empty Results or Options that would always be Some(..)
remove unused return type of dropck::check_drop_obligations() don't wrap return type in Option in get_macro_by_def_id() since we would always return Some(..) remove redundant return type of back::write::optimize() don't Option-wrap return type of compute_type_parameters() since we always return Some(..) don't return empty Result in assemble_generator_candidates() don't return empty Result in assemble_closure_candidates() don't return empty result in assemble_fn_pointer_candidates() don't return empty result in assemble_candidates_from_impls() don't return empty result in assemble_candidates_from_auto_impls() don't return emtpy result in assemble_candidates_for_trait_alias() don't return empty result in assemble_builtin_bound_candidates() don't return empty results in assemble_extension_candidates_for_traits_in_scope() and assemble_extension_candidates_for_trait() remove redundant wrapping of return type of StripItem::strip() since it always returns Some(..) remove unused return type of assemble_extension_candidates_for_all_traits()
1 parent b9c403b commit e5ead5f

File tree

12 files changed

+56
-81
lines changed

12 files changed

+56
-81
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub(crate) unsafe fn optimize(
485485
diag_handler: &Handler,
486486
module: &ModuleCodegen<ModuleLlvm>,
487487
config: &ModuleConfig,
488-
) -> Result<(), FatalError> {
488+
) {
489489
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &module.name[..]);
490490

491491
let llmod = module.module_llvm.llmod();
@@ -511,7 +511,7 @@ pub(crate) unsafe fn optimize(
511511
_ => llvm::OptStage::PreLinkNoLTO,
512512
};
513513
optimize_with_new_llvm_pass_manager(cgcx, module, config, opt_level, opt_stage);
514-
return Ok(());
514+
return;
515515
}
516516

517517
if cgcx.prof.llvm_recording_enabled() {
@@ -634,7 +634,6 @@ pub(crate) unsafe fn optimize(
634634
llvm::LLVMDisposePassManager(fpm);
635635
llvm::LLVMDisposePassManager(mpm);
636636
}
637-
Ok(())
638637
}
639638

640639
unsafe fn add_sanitizer_passes(config: &ModuleConfig, passes: &mut Vec<&'static mut llvm::Pass>) {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2322,13 +2322,13 @@ fn set_members_of_composite_type(
23222322
DIB(cx),
23232323
composite_type_metadata,
23242324
Some(type_array),
2325-
type_params,
2325+
Some(type_params),
23262326
);
23272327
}
23282328
}
23292329

23302330
/// Computes the type parameters for a type, if any, for the given metadata.
2331-
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'ll DIArray> {
2331+
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIArray {
23322332
if let ty::Adt(def, substs) = *ty.kind() {
23332333
if substs.types().next().is_some() {
23342334
let generics = cx.tcx.generics_of(def.did);
@@ -2358,10 +2358,10 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'
23582358
})
23592359
.collect();
23602360

2361-
return Some(create_DIArray(DIB(cx), &template_params[..]));
2361+
return create_DIArray(DIB(cx), &template_params[..]);
23622362
}
23632363
}
2364-
return Some(create_DIArray(DIB(cx), &[]));
2364+
return create_DIArray(DIB(cx), &[]);
23652365

23662366
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
23672367
let mut names = generics

compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
160160
module: &ModuleCodegen<Self::Module>,
161161
config: &ModuleConfig,
162162
) -> Result<(), FatalError> {
163-
back::write::optimize(cgcx, diag_handler, module, config)
163+
Ok(back::write::optimize(cgcx, diag_handler, module, config))
164164
}
165165
unsafe fn optimize_thin(
166166
cgcx: &CodegenContext<Self>,

compiler/rustc_resolve/src/build_reduced_graph.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ impl<'a> Resolver<'a> {
185185

186186
crate fn get_macro(&mut self, res: Res) -> Option<Lrc<SyntaxExtension>> {
187187
match res {
188-
Res::Def(DefKind::Macro(..), def_id) => self.get_macro_by_def_id(def_id),
188+
Res::Def(DefKind::Macro(..), def_id) => Some(self.get_macro_by_def_id(def_id)),
189189
Res::NonMacroAttr(attr_kind) => Some(self.non_macro_attr(attr_kind.is_used())),
190190
_ => None,
191191
}
192192
}
193193

194-
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
194+
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Lrc<SyntaxExtension> {
195195
if let Some(ext) = self.macro_map.get(&def_id) {
196-
return Some(ext.clone());
196+
return ext.clone();
197197
}
198198

199199
let ext = Lrc::new(match self.cstore().load_macro_untracked(def_id, &self.session) {
@@ -202,7 +202,7 @@ impl<'a> Resolver<'a> {
202202
});
203203

204204
self.macro_map.insert(def_id, ext.clone());
205-
Some(ext)
205+
ext
206206
}
207207

208208
crate fn build_reduced_graph(

compiler/rustc_resolve/src/lib.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1991,14 +1991,13 @@ impl<'a> Resolver<'a> {
19911991
{
19921992
// The macro is a proc macro derive
19931993
if let Some(def_id) = module.expansion.expn_data().macro_def_id {
1994-
if let Some(ext) = self.get_macro_by_def_id(def_id) {
1995-
if !ext.is_builtin
1996-
&& ext.macro_kind() == MacroKind::Derive
1997-
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
1998-
{
1999-
*poisoned = Some(node_id);
2000-
return module.parent;
2001-
}
1994+
let ext = self.get_macro_by_def_id(def_id);
1995+
if !ext.is_builtin
1996+
&& ext.macro_kind() == MacroKind::Derive
1997+
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
1998+
{
1999+
*poisoned = Some(node_id);
2000+
return module.parent;
20022001
}
20032002
}
20042003
}

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+21-35
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
247247

248248
let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
249249

250-
self.assemble_candidates_for_trait_alias(obligation, &mut candidates)?;
250+
self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
251251

252252
// Other bounds. Consider both in-scope bounds from fn decl
253253
// and applicable impls. There is a certain set of precedence rules here.
@@ -259,19 +259,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
259259

260260
// User-defined copy impls are permitted, but only for
261261
// structs and enums.
262-
self.assemble_candidates_from_impls(obligation, &mut candidates)?;
262+
self.assemble_candidates_from_impls(obligation, &mut candidates);
263263

264264
// For other types, we'll use the builtin rules.
265265
let copy_conditions = self.copy_clone_conditions(obligation);
266-
self.assemble_builtin_bound_candidates(copy_conditions, &mut candidates)?;
266+
self.assemble_builtin_bound_candidates(copy_conditions, &mut candidates);
267267
} else if lang_items.discriminant_kind_trait() == Some(def_id) {
268268
// `DiscriminantKind` is automatically implemented for every type.
269269
candidates.vec.push(DiscriminantKindCandidate);
270270
} else if lang_items.sized_trait() == Some(def_id) {
271271
// Sized is never implementable by end-users, it is
272272
// always automatically computed.
273273
let sized_conditions = self.sized_conditions(obligation);
274-
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates)?;
274+
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates);
275275
} else if lang_items.unsize_trait() == Some(def_id) {
276276
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
277277
} else {
@@ -280,13 +280,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
280280
// for `Copy` also has builtin support for `Clone`, and tuples/arrays of `Clone`
281281
// types have builtin support for `Clone`.
282282
let clone_conditions = self.copy_clone_conditions(obligation);
283-
self.assemble_builtin_bound_candidates(clone_conditions, &mut candidates)?;
283+
self.assemble_builtin_bound_candidates(clone_conditions, &mut candidates);
284284
}
285285

286-
self.assemble_generator_candidates(obligation, &mut candidates)?;
287-
self.assemble_closure_candidates(obligation, &mut candidates)?;
288-
self.assemble_fn_pointer_candidates(obligation, &mut candidates)?;
289-
self.assemble_candidates_from_impls(obligation, &mut candidates)?;
286+
self.assemble_generator_candidates(obligation, &mut candidates);
287+
self.assemble_closure_candidates(obligation, &mut candidates);
288+
self.assemble_fn_pointer_candidates(obligation, &mut candidates);
289+
self.assemble_candidates_from_impls(obligation, &mut candidates);
290290
self.assemble_candidates_from_object_ty(obligation, &mut candidates);
291291
}
292292

@@ -295,7 +295,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
295295
// Auto implementations have lower priority, so we only
296296
// consider triggering a default if there is no other impl that can apply.
297297
if candidates.vec.is_empty() {
298-
self.assemble_candidates_from_auto_impls(obligation, &mut candidates)?;
298+
self.assemble_candidates_from_auto_impls(obligation, &mut candidates);
299299
}
300300
debug!("candidate list size: {}", candidates.vec.len());
301301
Ok(candidates)
@@ -367,9 +367,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
367367
&mut self,
368368
obligation: &TraitObligation<'tcx>,
369369
candidates: &mut SelectionCandidateSet<'tcx>,
370-
) -> Result<(), SelectionError<'tcx>> {
370+
) {
371371
if self.tcx().lang_items().gen_trait() != Some(obligation.predicate.def_id()) {
372-
return Ok(());
372+
return;
373373
}
374374

375375
// Okay to skip binder because the substs on generator types never
@@ -388,8 +388,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
388388
}
389389
_ => {}
390390
}
391-
392-
Ok(())
393391
}
394392

395393
/// Checks for the artificial impl that the compiler will create for an obligation like `X :
@@ -402,11 +400,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
402400
&mut self,
403401
obligation: &TraitObligation<'tcx>,
404402
candidates: &mut SelectionCandidateSet<'tcx>,
405-
) -> Result<(), SelectionError<'tcx>> {
403+
) {
406404
let kind = match self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()) {
407405
Some(k) => k,
408406
None => {
409-
return Ok(());
407+
return;
410408
}
411409
};
412410

@@ -435,19 +433,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
435433
}
436434
_ => {}
437435
}
438-
439-
Ok(())
440436
}
441437

442438
/// Implements one of the `Fn()` family for a fn pointer.
443439
fn assemble_fn_pointer_candidates(
444440
&mut self,
445441
obligation: &TraitObligation<'tcx>,
446442
candidates: &mut SelectionCandidateSet<'tcx>,
447-
) -> Result<(), SelectionError<'tcx>> {
443+
) {
448444
// We provide impl of all fn traits for fn pointers.
449445
if self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()).is_none() {
450-
return Ok(());
446+
return;
451447
}
452448

453449
// Okay to skip binder because what we are inspecting doesn't involve bound regions.
@@ -485,16 +481,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
485481
}
486482
_ => {}
487483
}
488-
489-
Ok(())
490484
}
491485

492486
/// Searches for impls that might apply to `obligation`.
493487
fn assemble_candidates_from_impls(
494488
&mut self,
495489
obligation: &TraitObligation<'tcx>,
496490
candidates: &mut SelectionCandidateSet<'tcx>,
497-
) -> Result<(), SelectionError<'tcx>> {
491+
) {
498492
debug!(?obligation, "assemble_candidates_from_impls");
499493

500494
// Essentially any user-written impl will match with an error type,
@@ -504,7 +498,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
504498
// Since compilation is already guaranteed to fail, this is just
505499
// to try to show the 'nicest' possible errors to the user.
506500
if obligation.references_error() {
507-
return Ok(());
501+
return;
508502
}
509503

510504
self.tcx().for_each_relevant_impl(
@@ -518,15 +512,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
518512
});
519513
},
520514
);
521-
522-
Ok(())
523515
}
524516

525517
fn assemble_candidates_from_auto_impls(
526518
&mut self,
527519
obligation: &TraitObligation<'tcx>,
528520
candidates: &mut SelectionCandidateSet<'tcx>,
529-
) -> Result<(), SelectionError<'tcx>> {
521+
) {
530522
// Okay to skip binder here because the tests we do below do not involve bound regions.
531523
let self_ty = obligation.self_ty().skip_binder();
532524
debug!(?self_ty, "assemble_candidates_from_auto_impls");
@@ -585,8 +577,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
585577
_ => candidates.vec.push(AutoImplCandidate(def_id)),
586578
}
587579
}
588-
589-
Ok(())
590580
}
591581

592582
/// Searches for impls that might apply to `obligation`.
@@ -753,7 +743,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
753743
&mut self,
754744
obligation: &TraitObligation<'tcx>,
755745
candidates: &mut SelectionCandidateSet<'tcx>,
756-
) -> Result<(), SelectionError<'tcx>> {
746+
) {
757747
// Okay to skip binder here because the tests we do below do not involve bound regions.
758748
let self_ty = obligation.self_ty().skip_binder();
759749
debug!(?self_ty, "assemble_candidates_for_trait_alias");
@@ -763,8 +753,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
763753
if self.tcx().is_trait_alias(def_id) {
764754
candidates.vec.push(TraitAliasCandidate(def_id));
765755
}
766-
767-
Ok(())
768756
}
769757

770758
/// Assembles the trait which are built-in to the language itself:
@@ -773,7 +761,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
773761
&mut self,
774762
conditions: BuiltinImplConditions<'tcx>,
775763
candidates: &mut SelectionCandidateSet<'tcx>,
776-
) -> Result<(), SelectionError<'tcx>> {
764+
) {
777765
match conditions {
778766
BuiltinImplConditions::Where(nested) => {
779767
debug!(?nested, "builtin_bound");
@@ -787,7 +775,5 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
787775
candidates.ambiguous = true;
788776
}
789777
}
790-
791-
Ok(())
792778
}
793779
}

compiler/rustc_typeck/src/check/dropck.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,13 @@ crate fn check_drop_obligations<'a, 'tcx>(
267267
ty: Ty<'tcx>,
268268
span: Span,
269269
body_id: hir::HirId,
270-
) -> Result<(), ErrorReported> {
270+
) {
271271
debug!("check_drop_obligations typ: {:?}", ty);
272272

273273
let cause = &ObligationCause::misc(span, body_id);
274274
let infer_ok = rcx.infcx.at(cause, rcx.fcx.param_env).dropck_outlives(ty);
275275
debug!("dropck_outlives = {:#?}", infer_ok);
276276
rcx.fcx.register_infer_ok_obligations(infer_ok);
277-
278-
Ok(())
279277
}
280278

281279
// This is an implementation of the TypeRelation trait with the

0 commit comments

Comments
 (0)