Skip to content

Commit 1cede2c

Browse files
committed
is_knowable use Result instead of Option
1 parent 86c6ebe commit 1cede2c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,12 @@ fn resolve_negative_obligation<'cx, 'tcx>(
404404
pub fn trait_ref_is_knowable<'tcx>(
405405
tcx: TyCtxt<'tcx>,
406406
trait_ref: ty::TraitRef<'tcx>,
407-
) -> Option<Conflict> {
407+
) -> Result<(), Conflict> {
408408
debug!("trait_ref_is_knowable(trait_ref={:?})", trait_ref);
409409
if orphan_check_trait_ref(tcx, trait_ref, InCrate::Remote).is_ok() {
410410
// A downstream or cousin crate is allowed to implement some
411411
// substitution of this trait-ref.
412-
return Some(Conflict::Downstream);
412+
return Err(Conflict::Downstream);
413413
}
414414

415415
if trait_ref_is_local_or_fundamental(tcx, trait_ref) {
@@ -418,7 +418,7 @@ pub fn trait_ref_is_knowable<'tcx>(
418418
// allowed to implement a substitution of this trait ref, which
419419
// means impls could only come from dependencies of this crate,
420420
// which we already know about.
421-
return None;
421+
return Ok(());
422422
}
423423

424424
// This is a remote non-fundamental trait, so if another crate
@@ -431,10 +431,10 @@ pub fn trait_ref_is_knowable<'tcx>(
431431
// we are an owner.
432432
if orphan_check_trait_ref(tcx, trait_ref, InCrate::Local).is_ok() {
433433
debug!("trait_ref_is_knowable: orphan check passed");
434-
None
434+
Ok(())
435435
} else {
436436
debug!("trait_ref_is_knowable: nonlocal, nonfundamental, unowned");
437-
Some(Conflict::Upstream)
437+
Err(Conflict::Upstream)
438438
}
439439
}
440440

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
7575
&mut self,
7676
stack: &TraitObligationStack<'o, 'tcx>,
7777
) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
78-
if let Some(conflict) = self.is_knowable(stack) {
78+
if let Err(conflict) = self.is_knowable(stack) {
7979
debug!("coherence stage: not knowable");
8080
if self.intercrate_ambiguity_causes.is_some() {
8181
debug!("evaluate_stack: intercrate_ambiguity_causes is some");

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1265,11 +1265,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12651265
Ok(Some(candidate))
12661266
}
12671267

1268-
fn is_knowable<'o>(&mut self, stack: &TraitObligationStack<'o, 'tcx>) -> Option<Conflict> {
1268+
fn is_knowable<'o>(&mut self, stack: &TraitObligationStack<'o, 'tcx>) -> Result<(), Conflict> {
12691269
debug!("is_knowable(intercrate={:?})", self.intercrate);
12701270

12711271
if !self.intercrate || stack.obligation.polarity() == ty::ImplPolarity::Negative {
1272-
return None;
1272+
return Ok(());
12731273
}
12741274

12751275
let obligation = &stack.obligation;

0 commit comments

Comments
 (0)