fn query_result_substitution_guess<R>(
        &self,
        cause: &ObligationCause<'tcx>,
        original_values: &SmallCanonicalVarValues<'tcx>,
        query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
    ) -> CanonicalVarValues<'tcx>
    where
        R: Debug + TypeFoldable<'tcx>,
    {
        debug!(
            "query_result_substitution_guess(original_values={:#?}, query_result={:#?})",
            original_values, query_result,
        );

        // Every canonical query result includes values for each of
        // the inputs to the query. Therefore, we begin by unifying
        // these values with the original inputs that were
        // canonicalized.
        let result_values = &query_result.value.var_values;
        assert_eq!(original_values.len(), result_values.len());

        // Quickly try to find initial values for the canonical
        // variables in the result in terms of the query. We do this
        // by iterating down the values that the query gave to each of
        // the canonical inputs. If we find that one of those values
        // is directly equal to one of the canonical variables in the
        // result, then we can type the corresponding value from the
        // input. See the example above.
        let mut opt_values: IndexVec<CanonicalVar, Option<Kind<'tcx>>> =
            IndexVec::from_elem_n(None, query_result.variables.len());

        // In terms of our example above, we are iterating over pairs like:
        // [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
        for (original_value, result_value) in original_values.iter().zip(result_values) {
            match result_value.unpack() {
                UnpackedKind::Type(result_value) => {
                    // e.g., here `result_value` might be `?0` in the example above...
                    if let ty::TyInfer(ty::InferTy::CanonicalTy(index)) = result_value.sty {
                        // in which case we would set `canonical_vars[0]` to `Some(?U)`.
                        opt_values[index] = Some(*original_value);
                    }
                }
                UnpackedKind::Lifetime(result_value) => {
                    // e.g., here `result_value` might be `'?1` in the example above...
                    if let &ty::RegionKind::ReCanonical(index) = result_value {
                        // in which case we would set `canonical_vars[0]` to `Some('static)`.
                        opt_values[index] = Some(*original_value);
                    }
                }
            }
        }

        // Create a result substitution: if we found a value for a
        // given variable in the loop above, use that. Otherwise, use
        // a fresh inference variable.
        let result_subst = CanonicalVarValues {
            var_values: query_result
                .variables
                .iter()
                .enumerate()
                .map(|(index, info)| match opt_values[CanonicalVar::new(index)] {
                    Some(k) => k,
                    None => self.fresh_inference_var_for_canonical_var(cause.span, *info),
                })
                .collect(),
        };

        result_subst
    }
/// Given the original values and the (canonicalized) result from
/// computing a query, returns a **guess** at a substitution that
/// can be applied to the query result to convert the result back
/// into the original namespace. This is called a **guess**
/// because it uses a quick heuristic to find the values for each
/// canonical variable; if that quick heuristic fails, then we
/// will instantiate fresh inference variables for each canonical
/// variable instead. Therefore, the result of this method must be
/// properly unified
Given the original values and the (canonicalized) result from
computing a query, returns a **guess** at a substitution that
can be applied to the query result to convert the result back
into the original namespace. This is called a **guess
because it uses a quick heuristic to find the values for each
canonical variable; if that quick heuristic fails, then we
will instantiate fresh inference variables for each canonical
variable instead. Therefore, the result of this method must be
properly unified
Given the original values and the ( canonicalized ) result from computing a query returns a ** guess ** at a substitution that can be applied to the query result to convert the result back into the original namespace . This is called a ** guess because it uses a quick heuristic to find the values for each canonical variable ; if that quick heuristic fails then we will instantiate fresh inference variables for each canonical variable instead . Therefore the result of this method must be properly unified
fn query_result_substitution_guess<R>(
        &self,
        cause: &ObligationCause<'tcx>,
        original_values: &SmallCanonicalVarValues<'tcx>,
        query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
    ) -> CanonicalVarValues<'tcx>
    where
        R: Debug + TypeFoldable<'tcx>,
    {
        debug!(
            "query_result_substitution_guess(original_values={:#?}, query_result={:#?})",
            original_values, query_result,
        );
        // Every canonical query result includes values for each of
        // the inputs to the query. Therefore, we begin by unifying
        // these values with the original inputs that were
        // canonicalized.
        let result_values = &query_result.value.var_values;
        assert_eq!(original_values.len(), result_values.len());
        // Quickly try to find initial values for the canonical
        // variables in the result in terms of the query. We do this
        // by iterating down the values that the query gave to each of
        // the canonical inputs. If we find that one of those values
        // is directly equal to one of the canonical variables in the
        // result, then we can type the corresponding value from the
        // input. See the example above.
        let mut opt_values: IndexVec<CanonicalVar, Option<Kind<'tcx>>> =
            IndexVec::from_elem_n(None, query_result.variables.len());
        // In terms of our example above, we are iterating over pairs like:
        // [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
        for (original_value, result_value) in original_values.iter().zip(result_values) {
            match result_value.unpack() {
                UnpackedKind::Type(result_value) => {
                    // e.g., here `result_value` might be `?0` in the example above...
                    if let ty::TyInfer(ty::InferTy::CanonicalTy(index)) = result_value.sty {
                        // in which case we would set `canonical_vars[0]` to `Some(?U)`.
                        opt_values[index] = Some(*original_value);
                    }
                }
                UnpackedKind::Lifetime(result_value) => {
                    // e.g., here `result_value` might be `'?1` in the example above...
                    if let &ty::RegionKind::ReCanonical(index) = result_value {
                        // in which case we would set `canonical_vars[0]` to `Some('static)`.
                        opt_values[index] = Some(*original_value);
                    }
                }
            }
        }
        // Create a result substitution: if we found a value for a
        // given variable in the loop above, use that. Otherwise, use
        // a fresh inference variable.
        let result_subst = CanonicalVarValues {
            var_values: query_result
                .variables
                .iter()
                .enumerate()
                .map(|(index, info)| match opt_values[CanonicalVar::new(index)] {
                    Some(k) => k,
                    None => self.fresh_inference_var_for_canonical_var(cause.span, *info),
                })
                .collect(),
        };
        result_subst
    }
fn query_result_substitution_guess < R > ( & self , cause : & ObligationCause < ' tcx > , original_values : & SmallCanonicalVarValues < ' tcx > , query_result : & Canonical < ' tcx , QueryResult < ' tcx , R > > , ) -> CanonicalVarValues < ' tcx > where R : Debug + TypeFoldable < ' tcx > , { debug ! ( " " original_values query_result ) ; // Every canonical query result includes values for each of // the inputs to the query. Therefore, we begin by unifying // these values with the original inputs that were // canonicalized. let result_values = & query_result . value . var_values ; assert_eq ! ( original_values len ( ) result_values len ( ) ) ; // Quickly try to find initial values for the canonical // variables in the result in terms of the query. We do this // by iterating down the values that the query gave to each of // the canonical inputs. If we find that one of those values // is directly equal to one of the canonical variables in the // result, then we can type the corresponding value from the // input. See the example above. let mut opt_values : IndexVec < CanonicalVar , Option < Kind < ' tcx > > > = IndexVec :: from_elem_n ( None , query_result . variables . len ( ) ) ; // In terms of our example above, we are iterating over pairs like: // [(?A, Vec<?0>), ('static, '?1), (?B, ?0)] for ( original_value , result_value ) in original_values . iter ( ) . zip ( result_values ) { match result_value . unpack ( ) { UnpackedKind :: Type ( result_value ) => { // e.g., here `result_value` might be `?0` in the example above... if let ty :: TyInfer ( ty :: InferTy :: CanonicalTy ( index ) ) = result_value . sty { // in which case we would set `canonical_vars[0]` to `Some(?U)`. opt_values [ index ] = Some ( * original_value ) ; } } UnpackedKind :: Lifetime ( result_value ) => { // e.g., here `result_value` might be `'?1` in the example above... if let & ty :: RegionKind :: ReCanonical ( index ) = result_value { // in which case we would set `canonical_vars[0]` to `Some('static)`. opt_values [ index ] = Some ( * original_value ) ; } } } } // Create a result substitution: if we found a value for a // given variable in the loop above, use that. Otherwise, use // a fresh inference variable. let result_subst = CanonicalVarValues { var_values : query_result . variables . iter ( ) . enumerate ( ) . map ( | ( index , info ) | match opt_values [ CanonicalVar :: new ( index ) ] { Some ( k ) => k , None => self . fresh_inference_var_for_canonical_var ( cause . span , * info ) , } ) . collect ( ) , } ; result_subst }
Given the original values and the (canonicalized) result from
computing a query, returns a **guess** at a substitution that
can be applied to the query result to convert the result back
into the original namespace.
Given the original values and the ( canonicalized ) result from computing a query returns a ** guess ** at a substitution that can be applied to the query result to convert the result back into the original namespace .
&self
cause
&ObligationCause<'tcx>
original_values
&SmallCanonicalVarValues<'tcx>
query_result
&Canonical<'tcx, QueryResult<'tcx, R>>