compiler: fold by value
This commit is contained in:
parent
3ec6720bf1
commit
2bf93bd852
140 changed files with 679 additions and 699 deletions
|
@ -38,7 +38,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query
|
||||
pub fn canonicalize_query<V>(
|
||||
&self,
|
||||
value: &V,
|
||||
value: V,
|
||||
query_state: &mut OriginalQueryValues<'tcx>,
|
||||
) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
|
@ -80,7 +80,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
/// out the [chapter in the rustc dev guide][c].
|
||||
///
|
||||
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query-result
|
||||
pub fn canonicalize_response<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
||||
pub fn canonicalize_response<V>(&self, value: V) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
V: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn canonicalize_user_type_annotation<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
||||
pub fn canonicalize_user_type_annotation<V>(&self, value: V) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
V: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -123,7 +123,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
// and just use `canonicalize_query`.
|
||||
pub fn canonicalize_hr_query_hack<V>(
|
||||
&self,
|
||||
value: &V,
|
||||
value: V,
|
||||
query_state: &mut OriginalQueryValues<'tcx>,
|
||||
) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
|
@ -293,7 +293,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
|||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
|
||||
fn fold_binder<T>(&mut self, t: ty::Binder<T>) -> ty::Binder<T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -479,7 +479,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||
/// The main `canonicalize` method, shared impl of
|
||||
/// `canonicalize_query` and `canonicalize_response`.
|
||||
fn canonicalize<V>(
|
||||
value: &V,
|
||||
value: V,
|
||||
infcx: Option<&InferCtxt<'_, 'tcx>>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
canonicalize_region_mode: &dyn CanonicalizeRegionMode,
|
||||
|
|
|
@ -59,7 +59,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
|
||||
{
|
||||
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
|
||||
let canonical_result = self.canonicalize_response(&query_response);
|
||||
let canonical_result = self.canonicalize_response(query_response);
|
||||
|
||||
debug!("make_canonicalized_query_response: canonical_result = {:#?}", canonical_result);
|
||||
|
||||
|
@ -83,7 +83,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
where
|
||||
T: Debug + TypeFoldable<'tcx>,
|
||||
{
|
||||
self.canonicalize_response(&QueryResponse {
|
||||
self.canonicalize_response(QueryResponse {
|
||||
var_values: inference_vars,
|
||||
region_constraints: QueryRegionConstraints::default(),
|
||||
certainty: Certainty::Proven, // Ambiguities are OK!
|
||||
|
@ -176,7 +176,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
));
|
||||
|
||||
let user_result: R =
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| q_r.value.clone());
|
||||
|
||||
Ok(InferOk { value: user_result, obligations })
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
for (index, original_value) in original_values.var_values.iter().enumerate() {
|
||||
// ...with the value `v_r` of that variable from the query.
|
||||
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
|
||||
&v.var_values[BoundVar::new(index)]
|
||||
v.var_values[BoundVar::new(index)]
|
||||
});
|
||||
match (original_value.unpack(), result_value.unpack()) {
|
||||
(
|
||||
|
@ -296,7 +296,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
|
||||
// ...also include the other query region constraints from the query.
|
||||
output_query_region_constraints.outlives.extend(
|
||||
query_response.value.region_constraints.outlives.iter().filter_map(|r_c| {
|
||||
query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| {
|
||||
let r_c = substitute_value(self.tcx, &result_subst, r_c);
|
||||
|
||||
// Screen out `'a: 'a` cases -- we skip the binder here but
|
||||
|
@ -314,11 +314,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
.region_constraints
|
||||
.member_constraints
|
||||
.iter()
|
||||
.map(|p_c| substitute_value(self.tcx, &result_subst, p_c)),
|
||||
.map(|p_c| substitute_value(self.tcx, &result_subst, p_c.clone())),
|
||||
);
|
||||
|
||||
let user_result: R =
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| q_r.value.clone());
|
||||
|
||||
Ok(InferOk { value: user_result, obligations })
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
// `query_response.var_values` after applying the substitution
|
||||
// `result_subst`.
|
||||
let substituted_query_response = |index: BoundVar| -> GenericArg<'tcx> {
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |v| v.var_values[index])
|
||||
};
|
||||
|
||||
// Unify the original value for each variable with the value
|
||||
|
@ -524,7 +524,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
unsubstituted_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
|
||||
result_subst: &'a CanonicalVarValues<'tcx>,
|
||||
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
|
||||
unsubstituted_region_constraints.iter().map(move |constraint| {
|
||||
unsubstituted_region_constraints.iter().map(move |&constraint| {
|
||||
let ty::OutlivesPredicate(k1, r2) =
|
||||
substitute_value(self.tcx, result_subst, constraint).skip_binder();
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ pub(super) trait CanonicalExt<'tcx, V> {
|
|||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
projection_fn: impl FnOnce(&V) -> &T,
|
||||
projection_fn: impl FnOnce(&V) -> T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>;
|
||||
|
@ -39,14 +39,14 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
|||
where
|
||||
V: TypeFoldable<'tcx>,
|
||||
{
|
||||
self.substitute_projected(tcx, var_values, |value| value)
|
||||
self.substitute_projected(tcx, var_values, |value| value.clone())
|
||||
}
|
||||
|
||||
fn substitute_projected<T>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
projection_fn: impl FnOnce(&V) -> &T,
|
||||
projection_fn: impl FnOnce(&V) -> T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
|
@ -60,16 +60,16 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
|||
/// Substitute the values from `var_values` into `value`. `var_values`
|
||||
/// must be values for the set of canonical variables that appear in
|
||||
/// `value`.
|
||||
pub(super) fn substitute_value<'a, 'tcx, T>(
|
||||
pub(super) fn substitute_value<'tcx, T>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
value: &'a T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
if var_values.var_values.is_empty() {
|
||||
value.clone()
|
||||
value
|
||||
} else {
|
||||
let fld_r =
|
||||
|br: ty::BoundRegion| match var_values.var_values[br.assert_bound_var()].unpack() {
|
||||
|
|
|
@ -389,7 +389,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
member_region,
|
||||
span,
|
||||
} => {
|
||||
let hidden_ty = self.resolve_vars_if_possible(&hidden_ty);
|
||||
let hidden_ty = self.resolve_vars_if_possible(hidden_ty);
|
||||
unexpected_hidden_region_diagnostic(
|
||||
self.tcx,
|
||||
span,
|
||||
|
@ -590,7 +590,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
) {
|
||||
match cause.code {
|
||||
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
|
||||
let ty = self.resolve_vars_if_possible(&root_ty);
|
||||
let ty = self.resolve_vars_if_possible(root_ty);
|
||||
if ty.is_suggestable() {
|
||||
// don't show type `_`
|
||||
err.span_label(span, format!("this expression has type `{}`", ty));
|
||||
|
@ -661,7 +661,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
_ => {
|
||||
// `last_ty` can be `!`, `expected` will have better info when present.
|
||||
let t = self.resolve_vars_if_possible(&match exp_found {
|
||||
let t = self.resolve_vars_if_possible(match exp_found {
|
||||
Some(ty::error::ExpectedFound { expected, .. }) => expected,
|
||||
_ => last_ty,
|
||||
});
|
||||
|
@ -1547,7 +1547,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
|
||||
_ => (false, Mismatch::Fixed("type")),
|
||||
};
|
||||
let vals = match self.values_str(&values) {
|
||||
let vals = match self.values_str(values) {
|
||||
Some((expected, found)) => Some((expected, found)),
|
||||
None => {
|
||||
// Derived error. Cancel the emitter.
|
||||
|
@ -1893,32 +1893,32 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
|
||||
fn values_str(
|
||||
&self,
|
||||
values: &ValuePairs<'tcx>,
|
||||
values: ValuePairs<'tcx>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||
match *values {
|
||||
infer::Types(ref exp_found) => self.expected_found_str_ty(exp_found),
|
||||
infer::Regions(ref exp_found) => self.expected_found_str(exp_found),
|
||||
infer::Consts(ref exp_found) => self.expected_found_str(exp_found),
|
||||
infer::TraitRefs(ref exp_found) => {
|
||||
match values {
|
||||
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
|
||||
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
||||
infer::Consts(exp_found) => self.expected_found_str(exp_found),
|
||||
infer::TraitRefs(exp_found) => {
|
||||
let pretty_exp_found = ty::error::ExpectedFound {
|
||||
expected: exp_found.expected.print_only_trait_path(),
|
||||
found: exp_found.found.print_only_trait_path(),
|
||||
};
|
||||
self.expected_found_str(&pretty_exp_found)
|
||||
self.expected_found_str(pretty_exp_found)
|
||||
}
|
||||
infer::PolyTraitRefs(ref exp_found) => {
|
||||
infer::PolyTraitRefs(exp_found) => {
|
||||
let pretty_exp_found = ty::error::ExpectedFound {
|
||||
expected: exp_found.expected.print_only_trait_path(),
|
||||
found: exp_found.found.print_only_trait_path(),
|
||||
};
|
||||
self.expected_found_str(&pretty_exp_found)
|
||||
self.expected_found_str(pretty_exp_found)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn expected_found_str_ty(
|
||||
&self,
|
||||
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
||||
exp_found: ty::error::ExpectedFound<Ty<'tcx>>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
|
@ -1931,7 +1931,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// Returns a string of the form "expected `{}`, found `{}`".
|
||||
fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
exp_found: &ty::error::ExpectedFound<T>,
|
||||
exp_found: ty::error::ExpectedFound<T>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
|
@ -2180,7 +2180,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
"...",
|
||||
);
|
||||
if let Some(infer::RelateParamBound(_, t)) = origin {
|
||||
let t = self.resolve_vars_if_possible(&t);
|
||||
let t = self.resolve_vars_if_possible(t);
|
||||
match t.kind() {
|
||||
// We've got:
|
||||
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
|
||||
|
@ -2237,7 +2237,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
debug!("report_sub_sup_conflict: sub_trace.values={:?}", sub_trace.values);
|
||||
|
||||
if let (Some((sup_expected, sup_found)), Some((sub_expected, sub_found))) =
|
||||
(self.values_str(&sup_trace.values), self.values_str(&sub_trace.values))
|
||||
(self.values_str(sup_trace.values), self.values_str(sub_trace.values))
|
||||
{
|
||||
if sub_expected == sup_expected && sub_found == sup_found {
|
||||
note_and_explain_region(
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
|
|||
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
|
||||
match ty_opt {
|
||||
Some(ty) => {
|
||||
let ty = self.infcx.resolve_vars_if_possible(&ty);
|
||||
let ty = self.infcx.resolve_vars_if_possible(ty);
|
||||
if ty.walk().any(|inner| {
|
||||
inner == self.target
|
||||
|| match (inner.unpack(), self.target.unpack()) {
|
||||
|
@ -343,7 +343,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
arg: GenericArg<'tcx>,
|
||||
error_code: TypeAnnotationNeeded,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let arg = self.resolve_vars_if_possible(&arg);
|
||||
let arg = self.resolve_vars_if_possible(arg);
|
||||
let arg_data = self.extract_inference_diagnostics_data(arg, None);
|
||||
let kind_str = match arg.unpack() {
|
||||
GenericArgKind::Type(_) => "type",
|
||||
|
@ -686,7 +686,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
span: Span,
|
||||
ty: Ty<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
let data = self.extract_inference_diagnostics_data(ty.into(), None);
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
|
|
|
@ -234,14 +234,13 @@ impl NiceRegionError<'me, 'tcx> {
|
|||
false
|
||||
};
|
||||
|
||||
let expected_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef {
|
||||
let expected_trait_ref = self.infcx.resolve_vars_if_possible(ty::TraitRef {
|
||||
def_id: trait_def_id,
|
||||
substs: expected_substs,
|
||||
});
|
||||
let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef {
|
||||
def_id: trait_def_id,
|
||||
substs: actual_substs,
|
||||
});
|
||||
let actual_trait_ref = self
|
||||
.infcx
|
||||
.resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: actual_substs });
|
||||
|
||||
// Search the expected and actual trait references to see (a)
|
||||
// whether the sub/sup placeholders appear in them (sometimes
|
||||
|
|
|
@ -414,7 +414,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
tcx,
|
||||
ctxt.param_env,
|
||||
ctxt.assoc_item.def_id,
|
||||
self.infcx.resolve_vars_if_possible(&ctxt.substs),
|
||||
self.infcx.resolve_vars_if_possible(ctxt.substs),
|
||||
) {
|
||||
Ok(Some(instance)) => instance,
|
||||
_ => return false,
|
||||
|
|
|
@ -86,7 +86,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
}
|
||||
|
||||
if let Some((expected, found)) =
|
||||
self.infcx.expected_found_str_ty(&ExpectedFound { expected, found })
|
||||
self.infcx.expected_found_str_ty(ExpectedFound { expected, found })
|
||||
{
|
||||
// Highlighted the differences when showing the "expected/found" note.
|
||||
err.note_expected_found(&"", expected, &"", found);
|
||||
|
|
|
@ -55,12 +55,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let owner_id = hir.body_owner(body_id);
|
||||
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
|
||||
let poly_fn_sig = self.tcx().fn_sig(id);
|
||||
let fn_sig = self.tcx().liberate_late_bound_regions(id, &poly_fn_sig);
|
||||
let fn_sig = self.tcx().liberate_late_bound_regions(id, poly_fn_sig);
|
||||
body.params.iter().enumerate().find_map(|(index, param)| {
|
||||
// May return None; sometimes the tables are not yet populated.
|
||||
let ty = fn_sig.inputs()[index];
|
||||
let mut found_anon_region = false;
|
||||
let new_param_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
|
||||
let new_param_ty = self.tcx().fold_regions(ty, &mut false, |r, _| {
|
||||
if *r == *anon_region {
|
||||
found_anon_region = true;
|
||||
replace_region
|
||||
|
|
|
@ -24,7 +24,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
};
|
||||
match *origin {
|
||||
infer::Subtype(ref trace) => {
|
||||
if let Some((expected, found)) = self.values_str(&trace.values) {
|
||||
if let Some((expected, found)) = self.values_str(trace.values) {
|
||||
label_or_note(
|
||||
trace.cause.span,
|
||||
&format!("...so that the {}", trace.cause.as_requirement_str()),
|
||||
|
|
|
@ -105,7 +105,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
let (mut fudger, value) = self.probe(|_| {
|
||||
match f() {
|
||||
Ok(value) => {
|
||||
let value = self.resolve_vars_if_possible(&value);
|
||||
let value = self.resolve_vars_if_possible(value);
|
||||
|
||||
// At this point, `value` could in principle refer
|
||||
// to inference variables that have been created during
|
||||
|
|
|
@ -33,14 +33,14 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
|
|||
self.infcx.commit_if_ok(|_| {
|
||||
// First, we instantiate each bound region in the supertype with a
|
||||
// fresh placeholder region.
|
||||
let b_prime = self.infcx.replace_bound_vars_with_placeholders(&b);
|
||||
let b_prime = self.infcx.replace_bound_vars_with_placeholders(b);
|
||||
|
||||
// Next, we instantiate each bound region in the subtype
|
||||
// with a fresh region variable. These region variables --
|
||||
// but no other pre-existing region variables -- can name
|
||||
// the placeholders.
|
||||
let (a_prime, _) =
|
||||
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, &a);
|
||||
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, a);
|
||||
|
||||
debug!("a_prime={:?}", a_prime);
|
||||
debug!("b_prime={:?}", b_prime);
|
||||
|
@ -66,7 +66,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// the [rustc dev guide].
|
||||
///
|
||||
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
|
||||
pub fn replace_bound_vars_with_placeholders<T>(&self, binder: &ty::Binder<T>) -> T
|
||||
pub fn replace_bound_vars_with_placeholders<T>(&self, binder: ty::Binder<T>) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -113,10 +113,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
debug!(
|
||||
"replace_bound_vars_with_placeholders(\
|
||||
next_universe={:?}, \
|
||||
binder={:?}, \
|
||||
result={:?}, \
|
||||
map={:?})",
|
||||
next_universe, binder, result, map,
|
||||
next_universe, result, map,
|
||||
);
|
||||
|
||||
result
|
||||
|
|
|
@ -1001,7 +1001,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
|||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(&value, &mut false, |r, _db| match r {
|
||||
tcx.fold_regions(value, &mut false, |r, _db| match r {
|
||||
ty::ReVar(rid) => self.resolve_var(*rid),
|
||||
_ => r,
|
||||
})
|
||||
|
|
|
@ -345,7 +345,7 @@ pub struct InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// See the `error_reporting` module for more details.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, TypeFoldable)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
|
||||
pub enum ValuePairs<'tcx> {
|
||||
Types(ExpectedFound<Ty<'tcx>>),
|
||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||
|
@ -955,7 +955,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
|
||||
Some(self.commit_if_ok(|_snapshot| {
|
||||
let ty::SubtypePredicate { a_is_expected, a, b } =
|
||||
self.replace_bound_vars_with_placeholders(&predicate);
|
||||
self.replace_bound_vars_with_placeholders(predicate);
|
||||
|
||||
let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?;
|
||||
|
||||
|
@ -970,7 +970,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
) -> UnitResult<'tcx> {
|
||||
self.commit_if_ok(|_snapshot| {
|
||||
let ty::OutlivesPredicate(r_a, r_b) =
|
||||
self.replace_bound_vars_with_placeholders(&predicate);
|
||||
self.replace_bound_vars_with_placeholders(predicate);
|
||||
let origin = SubregionOrigin::from_obligation_cause(cause, || {
|
||||
RelateRegionParamBound(cause.span)
|
||||
});
|
||||
|
@ -1266,7 +1266,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
|
||||
self.resolve_vars_if_possible(&t).to_string()
|
||||
self.resolve_vars_if_possible(t).to_string()
|
||||
}
|
||||
|
||||
pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {
|
||||
|
@ -1274,7 +1274,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
format!("({})", tstrs.join(", "))
|
||||
}
|
||||
|
||||
pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String {
|
||||
pub fn trait_ref_to_string(&self, t: ty::TraitRef<'tcx>) -> String {
|
||||
self.resolve_vars_if_possible(t).print_only_trait_path().to_string()
|
||||
}
|
||||
|
||||
|
@ -1314,7 +1314,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// is left as is. This is an idempotent operation that does
|
||||
/// not affect inference state in any way and so you can do it
|
||||
/// at will.
|
||||
pub fn resolve_vars_if_possible<T>(&self, value: &T) -> T
|
||||
pub fn resolve_vars_if_possible<T>(&self, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -1349,7 +1349,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> {
|
||||
pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: T) -> FixupResult<'tcx, T> {
|
||||
/*!
|
||||
* Attempts to resolve all type/region/const variables in
|
||||
* `value`. Region inference must have been run already (e.g.,
|
||||
|
@ -1383,7 +1383,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
where
|
||||
M: FnOnce(String) -> DiagnosticBuilder<'tcx>,
|
||||
{
|
||||
let actual_ty = self.resolve_vars_if_possible(&actual_ty);
|
||||
let actual_ty = self.resolve_vars_if_possible(actual_ty);
|
||||
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
|
||||
|
||||
// Don't report an error if actual type is `Error`.
|
||||
|
@ -1420,7 +1420,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
&self,
|
||||
span: Span,
|
||||
lbrct: LateBoundRegionConversionTime,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
|
@ -1508,7 +1508,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
span: Option<Span>,
|
||||
) -> EvalToConstValueResult<'tcx> {
|
||||
let mut original_values = OriginalQueryValues::default();
|
||||
let canonical = self.canonicalize_query(&(param_env, substs), &mut original_values);
|
||||
let canonical = self.canonicalize_query((param_env, substs), &mut original_values);
|
||||
|
||||
let (param_env, substs) = canonical.value;
|
||||
// The return value is the evaluated value which doesn't contain any reference to inference
|
||||
|
|
|
@ -167,7 +167,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
sup_type, sub_region, origin
|
||||
);
|
||||
|
||||
let sup_type = self.resolve_vars_if_possible(&sup_type);
|
||||
let sup_type = self.resolve_vars_if_possible(sup_type);
|
||||
|
||||
if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) {
|
||||
let outlives = &mut TypeOutlives::new(
|
||||
|
@ -205,7 +205,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||
implicit_region_bound,
|
||||
param_env,
|
||||
);
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
outlives.type_must_outlive(origin, ty, region);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,10 +124,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
|||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
) -> Vec<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
|
||||
let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.tcx);
|
||||
let erased_projection_ty = self.tcx.erase_regions(&projection_ty);
|
||||
let erased_projection_ty = self.tcx.erase_regions(projection_ty);
|
||||
self.declared_generic_bounds_from_env_with_compare_fn(|ty| {
|
||||
if let ty::Projection(..) = ty.kind() {
|
||||
let erased_ty = self.tcx.erase_regions(&ty);
|
||||
let erased_ty = self.tcx.erase_regions(ty);
|
||||
erased_ty == erased_projection_ty
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
|
|||
/// Full type resolution replaces all type and region variables with
|
||||
/// their concrete results. If any variable cannot be replaced (never unified, etc)
|
||||
/// then an `Err` result is returned.
|
||||
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, value: &T) -> FixupResult<'tcx, T>
|
||||
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, value: T) -> FixupResult<'tcx, T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
|
|||
// TypeFoldable implementations.
|
||||
|
||||
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
traits::Obligation {
|
||||
cause: self.cause.clone(),
|
||||
recursion_depth: self.recursion_depth,
|
||||
|
|
|
@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
pred: ty::Predicate<'tcx>,
|
||||
) -> ty::Predicate<'tcx> {
|
||||
match pred.kind() {
|
||||
match *pred.kind() {
|
||||
ty::PredicateKind::ForAll(binder) => {
|
||||
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
|
||||
tcx.reuse_or_mk_predicate(pred, new)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue