pub fn solve(mut self, subst: Substitution) -> Result<Solution> {
        let outcome = self.fulfill()?;

        if self.cannot_prove {
            return Ok(Solution::Ambig(Guidance::Unknown));
        }

        if outcome.is_complete() {
            // No obligations remain, so we have definitively solved our goals,
            // and the current inference state is the unique way to solve them.

            let constraints = self.constraints.into_iter().collect();
            let constrained = self.infer.canonicalize(&ConstrainedSubst { subst, constraints });
            return Ok(Solution::Unique(constrained.quantified))
        }

        // Otherwise, we have (positive or negative) obligations remaining, but
        // haven't proved that it's *impossible* to satisfy out obligations. we
        // need to determine how to package up what we learned about type
        // inference as an ambiguous solution.

        if subst.is_trivial_within(&mut self.infer) {
            // In this case, we didn't learn *anything* definitively. So now, we
            // go one last time through the positive obligations, this time
            // applying even *tentative* inference suggestions, so that we can
            // yield these upwards as our own suggestions. There are no
            // particular guarantees about *which* obligaiton we derive
            // suggestions from.

            while let Some(obligation) = self.obligations.pop() {
                if let Obligation::Prove(goal) = obligation {
                    let PositiveSolution { free_vars, solution } = self.prove(&goal).unwrap();
                    if let Some(constrained_subst) = solution.constrained_subst() {
                        self.apply_solution(free_vars, constrained_subst);
                        let subst = self.infer.canonicalize(&subst);
                        return Ok(Solution::Ambig(Guidance::Suggested(subst.quantified)));
                    }
                }
            }

            Ok(Solution::Ambig(Guidance::Unknown))
        } else {
            // While we failed to prove the goal, we still learned that
            // something had to hold. Here's an example where this happens:
            //
            // ```rust
            // trait Display {}
            // trait Debug {}
            // struct Foo<T> {}
            // struct Bar {}
            // struct Baz {}
            //
            // impl Display for Bar {}
            // impl Display for Baz {}
            //
            // impl<T> Debug for Foo<T> where T: Display {}
            // ```
            //
            // If we pose the goal `exists<T> { T: Debug }`, we can't say
            // for sure what `T` must be (it could be either `Foo<Bar>` or
            // `Foo<Baz>`, but we *can* say for sure that it must be of the
            // form `Foo<?0>`.
            let subst = self.infer.canonicalize(&subst);
            Ok(Solution::Ambig(Guidance::Definite(subst.quantified)))
        }
    }
/// Try to fulfill all pending obligations and build the resulting
/// solution. The returned solution will transform `subst` substitution with
/// the outcome of type inference by updating the replacements it provides.
Try to fulfill all pending obligations and build the resulting
solution. The returned solution will transform `subst` substitution with
the outcome of type inference by updating the replacements it provides.
Try to fulfill all pending obligations and build the resulting solution . The returned solution will transform ` subst ` substitution with the outcome of type inference by updating the replacements it provides .
pub fn solve(mut self, subst: Substitution) -> Result<Solution> {
        let outcome = self.fulfill()?;
        if self.cannot_prove {
            return Ok(Solution::Ambig(Guidance::Unknown));
        }
        if outcome.is_complete() {
            // No obligations remain, so we have definitively solved our goals,
            // and the current inference state is the unique way to solve them.
            let constraints = self.constraints.into_iter().collect();
            let constrained = self.infer.canonicalize(&ConstrainedSubst { subst, constraints });
            return Ok(Solution::Unique(constrained.quantified))
        }
        // Otherwise, we have (positive or negative) obligations remaining, but
        // haven't proved that it's *impossible* to satisfy out obligations. we
        // need to determine how to package up what we learned about type
        // inference as an ambiguous solution.
        if subst.is_trivial_within(&mut self.infer) {
            // In this case, we didn't learn *anything* definitively. So now, we
            // go one last time through the positive obligations, this time
            // applying even *tentative* inference suggestions, so that we can
            // yield these upwards as our own suggestions. There are no
            // particular guarantees about *which* obligaiton we derive
            // suggestions from.
            while let Some(obligation) = self.obligations.pop() {
                if let Obligation::Prove(goal) = obligation {
                    let PositiveSolution { free_vars, solution } = self.prove(&goal).unwrap();
                    if let Some(constrained_subst) = solution.constrained_subst() {
                        self.apply_solution(free_vars, constrained_subst);
                        let subst = self.infer.canonicalize(&subst);
                        return Ok(Solution::Ambig(Guidance::Suggested(subst.quantified)));
                    }
                }
            }
            Ok(Solution::Ambig(Guidance::Unknown))
        } else {
            // While we failed to prove the goal, we still learned that
            // something had to hold. Here's an example where this happens:
            //
            // ```rust
            // trait Display {}
            // trait Debug {}
            // struct Foo<T> {}
            // struct Bar {}
            // struct Baz {}
            //
            // impl Display for Bar {}
            // impl Display for Baz {}
            //
            // impl<T> Debug for Foo<T> where T: Display {}
            // ```
            //
            // If we pose the goal `exists<T> { T: Debug }`, we can't say
            // for sure what `T` must be (it could be either `Foo<Bar>` or
            // `Foo<Baz>`, but we *can* say for sure that it must be of the
            // form `Foo<?0>`.
            let subst = self.infer.canonicalize(&subst);
            Ok(Solution::Ambig(Guidance::Definite(subst.quantified)))
        }
    }
pub fn solve ( mut self , subst : Substitution ) -> Result < Solution > { let outcome = self . fulfill ( ) ? ; if self . cannot_prove { return Ok ( Solution :: Ambig ( Guidance :: Unknown ) ) ; } if outcome . is_complete ( ) { // No obligations remain, so we have definitively solved our goals, // and the current inference state is the unique way to solve them. let constraints = self . constraints . into_iter ( ) . collect ( ) ; let constrained = self . infer . canonicalize ( & ConstrainedSubst { subst , constraints } ) ; return Ok ( Solution :: Unique ( constrained . quantified ) ) } // Otherwise, we have (positive or negative) obligations remaining, but // haven't proved that it's *impossible* to satisfy out obligations. we // need to determine how to package up what we learned about type // inference as an ambiguous solution. if subst . is_trivial_within ( & mut self . infer ) { // In this case, we didn't learn *anything* definitively. So now, we // go one last time through the positive obligations, this time // applying even *tentative* inference suggestions, so that we can // yield these upwards as our own suggestions. There are no // particular guarantees about *which* obligaiton we derive // suggestions from. while let Some ( obligation ) = self . obligations . pop ( ) { if let Obligation :: Prove ( goal ) = obligation { let PositiveSolution { free_vars , solution } = self . prove ( & goal ) . unwrap ( ) ; if let Some ( constrained_subst ) = solution . constrained_subst ( ) { self . apply_solution ( free_vars , constrained_subst ) ; let subst = self . infer . canonicalize ( & subst ) ; return Ok ( Solution :: Ambig ( Guidance :: Suggested ( subst . quantified ) ) ) ; } } } Ok ( Solution :: Ambig ( Guidance :: Unknown ) ) } else { // While we failed to prove the goal, we still learned that // something had to hold. Here's an example where this happens: // // ```rust // trait Display {} // trait Debug {} // struct Foo<T> {} // struct Bar {} // struct Baz {} // // impl Display for Bar {} // impl Display for Baz {} // // impl<T> Debug for Foo<T> where T: Display {} // ``` // // If we pose the goal `exists<T> { T: Debug }`, we can't say // for sure what `T` must be (it could be either `Foo<Bar>` or // `Foo<Baz>`, but we *can* say for sure that it must be of the // form `Foo<?0>`. let subst = self . infer . canonicalize ( & subst ) ; Ok ( Solution :: Ambig ( Guidance :: Definite ( subst . quantified ) ) ) } }
Try to fulfill all pending obligations and build the resulting
solution.
Try to fulfill all pending obligations and build the resulting solution .
mut self
subst
Substitution