1//! This module contains the code to instantiate a "query result", and
2//! in particular to extract out the resulting region obligations and
3//! encode them therein.
4//!
5//! For an overview of what canonicalization is and how it fits into
6//! rustc, check out the [chapter in the rustc dev guide][c].
7//!
8//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
910use std::fmt::Debug;
11use std::iter;
1213use rustc_index::{Idx, IndexVec};
14use rustc_middle::arena::ArenaAllocatable;
15use rustc_middle::bug;
16use rustc_middle::infer::canonical::CanonicalVarKind;
17use rustc_middle::ty::{self, BoundVar, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable};
18use tracing::{debug, instrument};
1920use crate::infer::canonical::instantiate::{CanonicalExt, instantiate_value};
21use crate::infer::canonical::{
22Canonical, CanonicalQueryResponse, CanonicalVarValues, Certainty, OriginalQueryValues,
23QueryRegionConstraints, QueryResponse,
24};
25use crate::infer::region_constraints::RegionConstraintData;
26use crate::infer::{
27DefineOpaqueTypes, InferCtxt, InferOk, InferResult, SubregionOrigin, TypeOutlivesConstraint,
28};
29use crate::traits::query::NoSolution;
30use crate::traits::{ObligationCause, PredicateObligations, ScrubbedTraitError, TraitEngine};
3132impl<'tcx> InferCtxt<'tcx> {
33/// This method is meant to be invoked as the final step of a canonical query
34 /// implementation. It is given:
35 ///
36 /// - the instantiated variables `inference_vars` created from the query key
37 /// - the result `answer` of the query
38 /// - a fulfillment context `fulfill_cx` that may contain various obligations which
39 /// have yet to be proven.
40 ///
41 /// Given this, the function will process the obligations pending
42 /// in `fulfill_cx`:
43 ///
44 /// - If all the obligations can be proven successfully, it will
45 /// package up any resulting region obligations (extracted from
46 /// `infcx`) along with the fully resolved value `answer` into a
47 /// query result (which is then itself canonicalized).
48 /// - If some obligations can be neither proven nor disproven, then
49 /// the same thing happens, but the resulting query is marked as ambiguous.
50 /// - Finally, if any of the obligations result in a hard error,
51 /// then `Err(NoSolution)` is returned.
52#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("make_canonicalized_query_response",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(52u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<CanonicalQueryResponse<'tcx, T>, NoSolution> =
loop {};
return __tracing_attr_fake_return;
}
{
let query_response =
self.make_query_response(inference_vars, answer, fulfill_cx)?;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:64",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(64u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("query_response = {0:#?}",
query_response) as &dyn Value))])
});
} else { ; }
};
let canonical_result = self.canonicalize_response(query_response);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:66",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(66u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("canonical_result = {0:#?}",
canonical_result) as &dyn Value))])
});
} else { ; }
};
Ok(self.tcx.arena.alloc(canonical_result))
}
}
}#[instrument(skip(self, inference_vars, answer, fulfill_cx), level = "trace")]53pub fn make_canonicalized_query_response<T>(
54&self,
55 inference_vars: CanonicalVarValues<'tcx>,
56 answer: T,
57 fulfill_cx: &mut dyn TraitEngine<'tcx, ScrubbedTraitError<'tcx>>,
58 ) -> Result<CanonicalQueryResponse<'tcx, T>, NoSolution>
59where
60T: Debug + TypeFoldable<TyCtxt<'tcx>>,
61Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
62 {
63let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
64debug!("query_response = {:#?}", query_response);
65let canonical_result = self.canonicalize_response(query_response);
66debug!("canonical_result = {:#?}", canonical_result);
6768Ok(self.tcx.arena.alloc(canonical_result))
69 }
7071/// A version of `make_canonicalized_query_response` that does
72 /// not pack in obligations, for contexts that want to drop
73 /// pending obligations instead of treating them as an ambiguity (e.g.
74 /// typeck "probing" contexts).
75 ///
76 /// If you DO want to keep track of pending obligations (which
77 /// include all region obligations, so this includes all cases
78 /// that care about regions) with this function, you have to
79 /// do it yourself, by e.g., having them be a part of the answer.
80pub fn make_query_response_ignoring_pending_obligations<T>(
81&self,
82 inference_vars: CanonicalVarValues<'tcx>,
83 answer: T,
84 ) -> Canonical<'tcx, QueryResponse<'tcx, T>>
85where
86T: Debug + TypeFoldable<TyCtxt<'tcx>>,
87 {
88// While we ignore region constraints and pending obligations,
89 // we do return constrained opaque types to avoid unconstrained
90 // inference variables in the response. This is important as we want
91 // to check that opaques in deref steps stay unconstrained.
92 //
93 // This doesn't handle the more general case for non-opaques as
94 // ambiguous `Projection` obligations have same the issue.
95let opaque_types = if self.next_trait_solver() {
96self.inner
97 .borrow_mut()
98 .opaque_type_storage
99 .iter_opaque_types()
100 .map(|(k, v)| (k, v.ty))
101 .collect()
102 } else {
103::alloc::vec::Vec::new()vec![]104 };
105106self.canonicalize_response(QueryResponse {
107 var_values: inference_vars,
108 region_constraints: QueryRegionConstraints::default(),
109 certainty: Certainty::Proven, // Ambiguities are OK!
110opaque_types,
111 value: answer,
112 })
113 }
114115/// Helper for `make_canonicalized_query_response` that does
116 /// everything up until the final canonicalization.
117#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("make_query_response",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(117u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["inference_vars",
"answer"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&inference_vars)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&answer)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<QueryResponse<'tcx, T>, NoSolution> = loop {};
return __tracing_attr_fake_return;
}
{
let errors =
fulfill_cx.evaluate_obligations_error_on_ambiguity(self);
if errors.iter().any(|e| e.is_true_error()) {
return Err(NoSolution);
}
let region_obligations =
self.take_registered_region_obligations();
let region_assumptions =
self.take_registered_region_assumptions();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:137",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(137u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["region_obligations"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(®ion_obligations)
as &dyn Value))])
});
} else { ; }
};
let region_constraints =
self.with_region_constraints(|region_constraints|
{
make_query_region_constraints(region_obligations,
region_constraints, region_assumptions)
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:145",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(145u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["region_constraints"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(®ion_constraints)
as &dyn Value))])
});
} else { ; }
};
let certainty =
if errors.is_empty() {
Certainty::Proven
} else { Certainty::Ambiguous };
let opaque_types =
self.inner.borrow_mut().opaque_type_storage.take_opaque_types().map(|(k,
v)| (k, v.ty)).collect();
Ok(QueryResponse {
var_values: inference_vars,
region_constraints,
certainty,
value: answer,
opaque_types,
})
}
}
}#[instrument(skip(self, fulfill_cx), level = "debug")]118fn make_query_response<T>(
119&self,
120 inference_vars: CanonicalVarValues<'tcx>,
121 answer: T,
122 fulfill_cx: &mut dyn TraitEngine<'tcx, ScrubbedTraitError<'tcx>>,
123 ) -> Result<QueryResponse<'tcx, T>, NoSolution>
124where
125T: Debug + TypeFoldable<TyCtxt<'tcx>>,
126 {
127// Select everything, returning errors.
128let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(self);
129130// True error!
131if errors.iter().any(|e| e.is_true_error()) {
132return Err(NoSolution);
133 }
134135let region_obligations = self.take_registered_region_obligations();
136let region_assumptions = self.take_registered_region_assumptions();
137debug!(?region_obligations);
138let region_constraints = self.with_region_constraints(|region_constraints| {
139 make_query_region_constraints(
140 region_obligations,
141 region_constraints,
142 region_assumptions,
143 )
144 });
145debug!(?region_constraints);
146147let certainty = if errors.is_empty() { Certainty::Proven } else { Certainty::Ambiguous };
148149let opaque_types = self
150.inner
151 .borrow_mut()
152 .opaque_type_storage
153 .take_opaque_types()
154 .map(|(k, v)| (k, v.ty))
155 .collect();
156157Ok(QueryResponse {
158 var_values: inference_vars,
159 region_constraints,
160 certainty,
161 value: answer,
162 opaque_types,
163 })
164 }
165166/// Given the (canonicalized) result to a canonical query,
167 /// instantiates the result so it can be used, plugging in the
168 /// values from the canonical query. (Note that the result may
169 /// have been ambiguous; you should check the certainty level of
170 /// the query before applying this function.)
171 ///
172 /// To get a good understanding of what is happening here, check
173 /// out the [chapter in the rustc dev guide][c].
174 ///
175 /// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#processing-the-canonicalized-query-result
176pub fn instantiate_query_response_and_region_obligations<R>(
177&self,
178 cause: &ObligationCause<'tcx>,
179 param_env: ty::ParamEnv<'tcx>,
180 original_values: &OriginalQueryValues<'tcx>,
181 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
182 ) -> InferResult<'tcx, R>
183where
184R: Debug + TypeFoldable<TyCtxt<'tcx>>,
185 {
186let InferOk { value: result_args, obligations } =
187self.query_response_instantiation(cause, param_env, original_values, query_response)?;
188189for (predicate, _category) in &query_response.value.region_constraints.outlives {
190let predicate = instantiate_value(self.tcx, &result_args, *predicate);
191self.register_outlives_constraint(predicate, cause);
192 }
193194for assumption in &query_response.value.region_constraints.assumptions {
195let assumption = instantiate_value(self.tcx, &result_args, *assumption);
196self.register_region_assumption(assumption);
197 }
198199let user_result: R =
200query_response.instantiate_projected(self.tcx, &result_args, |q_r| q_r.value.clone());
201202Ok(InferOk { value: user_result, obligations })
203 }
204205/// An alternative to
206 /// `instantiate_query_response_and_region_obligations` that is more
207 /// efficient for NLL. NLL is a bit more advanced in the
208 /// "transition to chalk" than the rest of the compiler. During
209 /// the NLL type check, all of the "processing" of types and
210 /// things happens in queries -- the NLL checker itself is only
211 /// interested in the region obligations (`'a: 'b` or `T: 'b`)
212 /// that come out of these queries, which it wants to convert into
213 /// MIR-based constraints and solve. Therefore, it is most
214 /// convenient for the NLL Type Checker to **directly consume**
215 /// the `QueryOutlivesConstraint` values that arise from doing a
216 /// query. This is contrast to other parts of the compiler, which
217 /// would prefer for those `QueryOutlivesConstraint` to be converted
218 /// into the older infcx-style constraints (e.g., calls to
219 /// `sub_regions` or `register_region_obligation`).
220 ///
221 /// Therefore, `instantiate_nll_query_response_and_region_obligations` performs the same
222 /// basic operations as `instantiate_query_response_and_region_obligations` but
223 /// it returns its result differently:
224 ///
225 /// - It creates an instantiation `S` that maps from the original
226 /// query variables to the values computed in the query
227 /// result. If any errors arise, they are propagated back as an
228 /// `Err` result.
229 /// - In the case of a successful instantiation, we will append
230 /// `QueryOutlivesConstraint` values onto the
231 /// `output_query_region_constraints` vector for the solver to
232 /// use (if an error arises, some values may also be pushed, but
233 /// they should be ignored).
234 /// - It **can happen** (though it rarely does currently) that
235 /// equating types and things will give rise to subobligations
236 /// that must be processed. In this case, those subobligations
237 /// are propagated back in the return value.
238 /// - Finally, the query result (of type `R`) is propagated back,
239 /// after applying the instantiation `S`.
240pub fn instantiate_nll_query_response_and_region_obligations<R>(
241&self,
242 cause: &ObligationCause<'tcx>,
243 param_env: ty::ParamEnv<'tcx>,
244 original_values: &OriginalQueryValues<'tcx>,
245 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
246 output_query_region_constraints: &mut QueryRegionConstraints<'tcx>,
247 ) -> InferResult<'tcx, R>
248where
249R: Debug + TypeFoldable<TyCtxt<'tcx>>,
250 {
251let InferOk { value: result_args, mut obligations } = self252 .query_response_instantiation_guess(
253cause,
254param_env,
255original_values,
256query_response,
257 )?;
258259// Compute `QueryOutlivesConstraint` values that unify each of
260 // the original values `v_o` that was canonicalized into a
261 // variable...
262263let constraint_category = cause.to_constraint_category();
264265for (index, original_value) in original_values.var_values.iter().enumerate() {
266// ...with the value `v_r` of that variable from the query.
267let result_value = query_response.instantiate_projected(self.tcx, &result_args, |v| {
268 v.var_values[BoundVar::new(index)]
269 });
270match (original_value.kind(), result_value.kind()) {
271 (GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
272if re1.is_erased() && re2.is_erased() =>
273 {
274// No action needed.
275}
276277 (GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
278// To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
279if v_o != v_r {
280 output_query_region_constraints
281 .outlives
282 .push((ty::OutlivesPredicate(v_o.into(), v_r), constraint_category));
283 output_query_region_constraints
284 .outlives
285 .push((ty::OutlivesPredicate(v_r.into(), v_o), constraint_category));
286 }
287 }
288289 (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
290 obligations.extend(
291self.at(&cause, param_env)
292 .eq(DefineOpaqueTypes::Yes, v1, v2)?
293.into_obligations(),
294 );
295 }
296297 (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
298 obligations.extend(
299self.at(&cause, param_env)
300 .eq(DefineOpaqueTypes::Yes, v1, v2)?
301.into_obligations(),
302 );
303 }
304305_ => {
306::rustc_middle::util::bug::bug_fmt(format_args!("kind mismatch, cannot unify {0:?} and {1:?}",
original_value, result_value));bug!("kind mismatch, cannot unify {:?} and {:?}", original_value, result_value);
307 }
308 }
309 }
310311// ...also include the other query region constraints from the query.
312output_query_region_constraints.outlives.extend(
313query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| {
314let r_c = instantiate_value(self.tcx, &result_args, r_c);
315316// Screen out `'a: 'a` cases.
317let ty::OutlivesPredicate(k1, r2) = r_c.0;
318if k1 != r2.into() { Some(r_c) } else { None }
319 }),
320 );
321322// FIXME(higher_ranked_auto): Optimize this to instantiate all assumptions
323 // at once, rather than calling `instantiate_value` repeatedly which may
324 // create more universes.
325output_query_region_constraints.assumptions.extend(
326query_response327 .value
328 .region_constraints
329 .assumptions
330 .iter()
331 .map(|&r_c| instantiate_value(self.tcx, &result_args, r_c)),
332 );
333334let user_result: R =
335query_response.instantiate_projected(self.tcx, &result_args, |q_r| q_r.value.clone());
336337Ok(InferOk { value: user_result, obligations })
338 }
339340/// Given the original values and the (canonicalized) result from
341 /// computing a query, returns an instantiation that can be applied
342 /// to the query result to convert the result back into the
343 /// original namespace.
344 ///
345 /// The instantiation also comes accompanied with subobligations
346 /// that arose from unification; these might occur if (for
347 /// example) we are doing lazy normalization and the value
348 /// assigned to a type variable is unified with an unnormalized
349 /// projection.
350fn query_response_instantiation<R>(
351&self,
352 cause: &ObligationCause<'tcx>,
353 param_env: ty::ParamEnv<'tcx>,
354 original_values: &OriginalQueryValues<'tcx>,
355 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
356 ) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
357where
358R: Debug + TypeFoldable<TyCtxt<'tcx>>,
359 {
360{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:360",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(360u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("query_response_instantiation(original_values={0:#?}, query_response={1:#?})",
original_values, query_response) as &dyn Value))])
});
} else { ; }
};debug!(
361"query_response_instantiation(original_values={:#?}, query_response={:#?})",
362 original_values, query_response,
363 );
364365let mut value = self.query_response_instantiation_guess(
366cause,
367param_env,
368original_values,
369query_response,
370 )?;
371372value.obligations.extend(
373self.unify_query_response_instantiation_guess(
374cause,
375param_env,
376original_values,
377&value.value,
378query_response,
379 )?
380.into_obligations(),
381 );
382383Ok(value)
384 }
385386/// Given the original values and the (canonicalized) result from
387 /// computing a query, returns a **guess** at an instantiation that
388 /// can be applied to the query result to convert the result back
389 /// into the original namespace. This is called a **guess**
390 /// because it uses a quick heuristic to find the values for each
391 /// canonical variable; if that quick heuristic fails, then we
392 /// will instantiate fresh inference variables for each canonical
393 /// variable instead. Therefore, the result of this method must be
394 /// properly unified
395#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("query_response_instantiation_guess",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(395u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["cause",
"original_values", "query_response"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cause)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&original_values)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_response)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
InferResult<'tcx, CanonicalVarValues<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let mut universe_map = original_values.universe_map.clone();
let num_universes_in_query = original_values.universe_map.len();
let num_universes_in_response =
query_response.max_universe.as_usize() + 1;
for _ in num_universes_in_query..num_universes_in_response {
universe_map.push(self.create_next_universe());
}
if !!universe_map.is_empty() {
::core::panicking::panic("assertion failed: !universe_map.is_empty()")
};
match (&universe_map[ty::UniverseIndex::ROOT.as_usize()],
&ty::UniverseIndex::ROOT) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
let result_values = &query_response.value.var_values;
match (&original_values.var_values.len(), &result_values.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
let mut opt_values: IndexVec<BoundVar, Option<GenericArg<'tcx>>> =
IndexVec::from_elem_n(None, query_response.variables.len());
for (original_value, result_value) in
iter::zip(&original_values.var_values, result_values) {
match result_value.kind() {
GenericArgKind::Type(result_value) => {
if let ty::Bound(index_kind, b) = *result_value.kind() &&
!#[allow(non_exhaustive_omitted_patterns)] match query_response.variables[b.var.as_usize()]
{
CanonicalVarKind::Ty { .. } => true,
_ => false,
} {
if !#[allow(non_exhaustive_omitted_patterns)] match index_kind
{
ty::BoundVarIndexKind::Canonical => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(index_kind, ty::BoundVarIndexKind::Canonical)")
};
opt_values[b.var] = Some(*original_value);
}
}
GenericArgKind::Lifetime(result_value) => {
if let ty::ReBound(index_kind, b) = result_value.kind() {
if !#[allow(non_exhaustive_omitted_patterns)] match index_kind
{
ty::BoundVarIndexKind::Canonical => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(index_kind, ty::BoundVarIndexKind::Canonical)")
};
opt_values[b.var] = Some(*original_value);
}
}
GenericArgKind::Const(result_value) => {
if let ty::ConstKind::Bound(index_kind, b) =
result_value.kind() {
if !#[allow(non_exhaustive_omitted_patterns)] match index_kind
{
ty::BoundVarIndexKind::Canonical => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(index_kind, ty::BoundVarIndexKind::Canonical)")
};
opt_values[b.var] = Some(*original_value);
}
}
}
}
let tcx = self.tcx;
let variables = query_response.variables;
let var_values =
CanonicalVarValues::instantiate(tcx, variables,
|var_values, kind|
{
if kind.universe() != ty::UniverseIndex::ROOT {
self.instantiate_canonical_var(cause.span, kind,
&var_values, |u| { universe_map[u.as_usize()] })
} else if kind.is_existential() {
match opt_values[BoundVar::new(var_values.len())] {
Some(k) => k,
None =>
self.instantiate_canonical_var(cause.span, kind,
&var_values, |u| { universe_map[u.as_usize()] }),
}
} else {
opt_values[BoundVar::new(var_values.len())].expect("expected placeholder to be unified with itself during response")
}
});
let mut obligations = PredicateObligations::new();
for &(a, b) in &query_response.value.opaque_types {
let a = instantiate_value(self.tcx, &var_values, a);
let b = instantiate_value(self.tcx, &var_values, b);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:504",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(504u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["message", "a", "b"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("constrain opaque type")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&a) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&b) as
&dyn Value))])
});
} else { ; }
};
obligations.extend(self.at(cause,
param_env).eq(DefineOpaqueTypes::Yes,
Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.args),
b)?.obligations);
}
Ok(InferOk { value: var_values, obligations })
}
}
}#[instrument(level = "debug", skip(self, param_env))]396fn query_response_instantiation_guess<R>(
397&self,
398 cause: &ObligationCause<'tcx>,
399 param_env: ty::ParamEnv<'tcx>,
400 original_values: &OriginalQueryValues<'tcx>,
401 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
402 ) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
403where
404R: Debug + TypeFoldable<TyCtxt<'tcx>>,
405 {
406// For each new universe created in the query result that did
407 // not appear in the original query, create a local
408 // superuniverse.
409let mut universe_map = original_values.universe_map.clone();
410let num_universes_in_query = original_values.universe_map.len();
411let num_universes_in_response = query_response.max_universe.as_usize() + 1;
412for _ in num_universes_in_query..num_universes_in_response {
413 universe_map.push(self.create_next_universe());
414 }
415assert!(!universe_map.is_empty()); // always have the root universe
416assert_eq!(universe_map[ty::UniverseIndex::ROOT.as_usize()], ty::UniverseIndex::ROOT);
417418// Every canonical query result includes values for each of
419 // the inputs to the query. Therefore, we begin by unifying
420 // these values with the original inputs that were
421 // canonicalized.
422let result_values = &query_response.value.var_values;
423assert_eq!(original_values.var_values.len(), result_values.len());
424425// Quickly try to find initial values for the canonical
426 // variables in the result in terms of the query. We do this
427 // by iterating down the values that the query gave to each of
428 // the canonical inputs. If we find that one of those values
429 // is directly equal to one of the canonical variables in the
430 // result, then we can type the corresponding value from the
431 // input. See the example above.
432let mut opt_values: IndexVec<BoundVar, Option<GenericArg<'tcx>>> =
433 IndexVec::from_elem_n(None, query_response.variables.len());
434435for (original_value, result_value) in iter::zip(&original_values.var_values, result_values)
436 {
437match result_value.kind() {
438 GenericArgKind::Type(result_value) => {
439// We disable the instantiation guess for inference variables
440 // and only use it for placeholders. We need to handle the
441 // `sub_root` of type inference variables which would make this
442 // more involved. They are also a lot rarer than region variables.
443if let ty::Bound(index_kind, b) = *result_value.kind()
444 && !matches!(
445 query_response.variables[b.var.as_usize()],
446 CanonicalVarKind::Ty { .. }
447 )
448 {
449// We only allow a `Canonical` index in generic parameters.
450assert!(matches!(index_kind, ty::BoundVarIndexKind::Canonical));
451 opt_values[b.var] = Some(*original_value);
452 }
453 }
454 GenericArgKind::Lifetime(result_value) => {
455if let ty::ReBound(index_kind, b) = result_value.kind() {
456// We only allow a `Canonical` index in generic parameters.
457assert!(matches!(index_kind, ty::BoundVarIndexKind::Canonical));
458 opt_values[b.var] = Some(*original_value);
459 }
460 }
461 GenericArgKind::Const(result_value) => {
462if let ty::ConstKind::Bound(index_kind, b) = result_value.kind() {
463// We only allow a `Canonical` index in generic parameters.
464assert!(matches!(index_kind, ty::BoundVarIndexKind::Canonical));
465 opt_values[b.var] = Some(*original_value);
466 }
467 }
468 }
469 }
470471// Create result arguments: if we found a value for a
472 // given variable in the loop above, use that. Otherwise, use
473 // a fresh inference variable.
474let tcx = self.tcx;
475let variables = query_response.variables;
476let var_values = CanonicalVarValues::instantiate(tcx, variables, |var_values, kind| {
477if kind.universe() != ty::UniverseIndex::ROOT {
478// A variable from inside a binder of the query. While ideally these shouldn't
479 // exist at all, we have to deal with them for now.
480self.instantiate_canonical_var(cause.span, kind, &var_values, |u| {
481 universe_map[u.as_usize()]
482 })
483 } else if kind.is_existential() {
484match opt_values[BoundVar::new(var_values.len())] {
485Some(k) => k,
486None => self.instantiate_canonical_var(cause.span, kind, &var_values, |u| {
487 universe_map[u.as_usize()]
488 }),
489 }
490 } else {
491// For placeholders which were already part of the input, we simply map this
492 // universal bound variable back the placeholder of the input.
493opt_values[BoundVar::new(var_values.len())]
494 .expect("expected placeholder to be unified with itself during response")
495 }
496 });
497498let mut obligations = PredicateObligations::new();
499500// Carry all newly resolved opaque types to the caller's scope
501for &(a, b) in &query_response.value.opaque_types {
502let a = instantiate_value(self.tcx, &var_values, a);
503let b = instantiate_value(self.tcx, &var_values, b);
504debug!(?a, ?b, "constrain opaque type");
505// We use equate here instead of, for example, just registering the
506 // opaque type's hidden value directly, because the hidden type may have been an inference
507 // variable that got constrained to the opaque type itself. In that case we want to equate
508 // the generic args of the opaque with the generic params of its hidden type version.
509obligations.extend(
510self.at(cause, param_env)
511 .eq(
512 DefineOpaqueTypes::Yes,
513 Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.args),
514 b,
515 )?
516.obligations,
517 );
518 }
519520Ok(InferOk { value: var_values, obligations })
521 }
522523/// Given a "guess" at the values for the canonical variables in
524 /// the input, try to unify with the *actual* values found in the
525 /// query result. Often, but not always, this is a no-op, because
526 /// we already found the mapping in the "guessing" step.
527 ///
528 /// See also: [`Self::query_response_instantiation_guess`]
529fn unify_query_response_instantiation_guess<R>(
530&self,
531 cause: &ObligationCause<'tcx>,
532 param_env: ty::ParamEnv<'tcx>,
533 original_values: &OriginalQueryValues<'tcx>,
534 result_args: &CanonicalVarValues<'tcx>,
535 query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
536 ) -> InferResult<'tcx, ()>
537where
538R: Debug + TypeFoldable<TyCtxt<'tcx>>,
539 {
540// A closure that yields the result value for the given
541 // canonical variable; this is taken from
542 // `query_response.var_values` after applying the instantiation
543 // by `result_args`.
544let instantiated_query_response = |index: BoundVar| -> GenericArg<'tcx> {
545query_response.instantiate_projected(self.tcx, result_args, |v| v.var_values[index])
546 };
547548// Unify the original value for each variable with the value
549 // taken from `query_response` (after applying `result_args`).
550self.unify_canonical_vars(cause, param_env, original_values, instantiated_query_response)
551 }
552553/// Given two sets of values for the same set of canonical variables, unify them.
554 /// The second set is produced lazily by supplying indices from the first set.
555fn unify_canonical_vars(
556&self,
557 cause: &ObligationCause<'tcx>,
558 param_env: ty::ParamEnv<'tcx>,
559 variables1: &OriginalQueryValues<'tcx>,
560 variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
561 ) -> InferResult<'tcx, ()> {
562let mut obligations = PredicateObligations::new();
563for (index, value1) in variables1.var_values.iter().enumerate() {
564let value2 = variables2(BoundVar::new(index));
565566match (value1.kind(), value2.kind()) {
567 (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
568 obligations.extend(
569self.at(cause, param_env)
570 .eq(DefineOpaqueTypes::Yes, v1, v2)?
571.into_obligations(),
572 );
573 }
574 (GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
575if re1.is_erased() && re2.is_erased() =>
576 {
577// no action needed
578}
579 (GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
580self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
581 SubregionOrigin::RelateRegionParamBound(cause.span, None),
582 v1,
583 v2,
584 );
585 }
586 (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
587let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
588 obligations.extend(ok.into_obligations());
589 }
590_ => {
591::rustc_middle::util::bug::bug_fmt(format_args!("kind mismatch, cannot unify {0:?} and {1:?}",
value1, value2));bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
592 }
593 }
594 }
595Ok(InferOk { value: (), obligations })
596 }
597}
598599/// Given the region obligations and constraints scraped from the infcx,
600/// creates query region constraints.
601pub fn make_query_region_constraints<'tcx>(
602 outlives_obligations: Vec<TypeOutlivesConstraint<'tcx>>,
603 region_constraints: &RegionConstraintData<'tcx>,
604 assumptions: Vec<ty::ArgOutlivesPredicate<'tcx>>,
605) -> QueryRegionConstraints<'tcx> {
606let RegionConstraintData { constraints, verifys } = region_constraints;
607608if !verifys.is_empty() {
::core::panicking::panic("assertion failed: verifys.is_empty()")
};assert!(verifys.is_empty());
609610{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/canonical/query_response.rs:610",
"rustc_infer::infer::canonical::query_response",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/canonical/query_response.rs"),
::tracing_core::__macro_support::Option::Some(610u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::canonical::query_response"),
::tracing_core::field::FieldSet::new(&["constraints"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&constraints)
as &dyn Value))])
});
} else { ; }
};debug!(?constraints);
611612let outlives: Vec<_> = constraints613 .iter()
614 .map(|(c, origin)| {
615// Swap regions because we are going from sub (<=) to outlives (>=).
616let constraint = ty::OutlivesPredicate(c.sup.into(), c.sub);
617 (constraint, origin.to_constraint_category())
618 })
619 .chain(outlives_obligations.into_iter().map(|obl| {
620 (
621 ty::OutlivesPredicate(obl.sup_type.into(), obl.sub_region),
622obl.origin.to_constraint_category(),
623 )
624 }))
625 .collect();
626627QueryRegionConstraints { outlives, assumptions }
628}