1//! Core logic responsible for determining what it means for various type system
2//! primitives to be "well formed". Actually checking whether these primitives are
3//! well formed is performed elsewhere (e.g. during type checking or item well formedness
4//! checking).
56use std::iter;
78use rustc_hiras hir;
9use rustc_hir::def::DefKind;
10use rustc_hir::lang_items::LangItem;
11use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
12use rustc_middle::bug;
13use rustc_middle::ty::{
14self, GenericArgsRef, Term, TermKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
15TypeVisitableExt, TypeVisitor,
16};
17use rustc_session::errors::feature_err;
18use rustc_span::def_id::{DefId, LocalDefId};
19use rustc_span::{Span, sym};
20use tracing::{debug, instrument, trace};
2122use crate::infer::InferCtxt;
23use crate::traits;
2425/// Returns the set of obligations needed to make `arg` well-formed.
26/// If `arg` contains unresolved inference variables, this may include
27/// further WF obligations. However, if `arg` IS an unresolved
28/// inference variable, returns `None`, because we are not able to
29/// make any progress at all. This is to prevent cycles where we
30/// say "?0 is WF if ?0 is WF".
31pub fn obligations<'tcx>(
32 infcx: &InferCtxt<'tcx>,
33 param_env: ty::ParamEnv<'tcx>,
34 body_id: LocalDefId,
35 recursion_depth: usize,
36 term: Term<'tcx>,
37 span: Span,
38) -> Option<PredicateObligations<'tcx>> {
39// Handle the "cycle" case (see comment above) by bailing out if necessary.
40let term = match term.kind() {
41TermKind::Ty(ty) => {
42match ty.kind() {
43 ty::Infer(ty::TyVar(_)) => {
44let resolved_ty = infcx.shallow_resolve(ty);
45if resolved_ty == ty {
46// No progress, bail out to prevent cycles.
47return None;
48 } else {
49resolved_ty50 }
51 }
52_ => ty,
53 }
54 .into()
55 }
56TermKind::Const(ct) => {
57match ct.kind() {
58 ty::ConstKind::Infer(_) => {
59let resolved = infcx.shallow_resolve_const(ct);
60if resolved == ct {
61// No progress, bail out to prevent cycles.
62return None;
63 } else {
64resolved65 }
66 }
67_ => ct,
68 }
69 .into()
70 }
71 };
7273let mut wf = WfPredicates {
74infcx,
75param_env,
76body_id,
77span,
78 out: PredicateObligations::new(),
79recursion_depth,
80 item: None,
81 };
82wf.add_wf_preds_for_term(term);
83{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:83",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(83u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::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!("wf::obligations({0:?}, body_id={1:?}) = {2:?}",
term, body_id, wf.out) as &dyn Value))])
});
} else { ; }
};debug!("wf::obligations({:?}, body_id={:?}) = {:?}", term, body_id, wf.out);
8485let result = wf.normalize(infcx);
86{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:86",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(86u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::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!("wf::obligations({0:?}, body_id={1:?}) ~~> {2:?}",
term, body_id, result) as &dyn Value))])
});
} else { ; }
};debug!("wf::obligations({:?}, body_id={:?}) ~~> {:?}", term, body_id, result);
87Some(result)
88}
8990/// Compute the predicates that are required for a type to be well-formed.
91///
92/// This is only intended to be used in the new solver, since it does not
93/// take into account recursion depth or proper error-reporting spans.
94pub fn unnormalized_obligations<'tcx>(
95 infcx: &InferCtxt<'tcx>,
96 param_env: ty::ParamEnv<'tcx>,
97 term: Term<'tcx>,
98 span: Span,
99 body_id: LocalDefId,
100) -> Option<PredicateObligations<'tcx>> {
101if true {
match (&term, &infcx.resolve_vars_if_possible(term)) {
(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);
}
}
};
};debug_assert_eq!(term, infcx.resolve_vars_if_possible(term));
102103// However, if `arg` IS an unresolved inference variable, returns `None`,
104 // because we are not able to make any progress at all. This is to prevent
105 // cycles where we say "?0 is WF if ?0 is WF".
106if term.is_infer() {
107return None;
108 }
109110let mut wf = WfPredicates {
111infcx,
112param_env,
113body_id,
114span,
115 out: PredicateObligations::new(),
116 recursion_depth: 0,
117 item: None,
118 };
119wf.add_wf_preds_for_term(term);
120Some(wf.out)
121}
122123/// Returns the obligations that make this trait reference
124/// well-formed. For example, if there is a trait `Set` defined like
125/// `trait Set<K: Eq>`, then the trait bound `Foo: Set<Bar>` is WF
126/// if `Bar: Eq`.
127pub fn trait_obligations<'tcx>(
128 infcx: &InferCtxt<'tcx>,
129 param_env: ty::ParamEnv<'tcx>,
130 body_id: LocalDefId,
131 trait_pred: ty::TraitPredicate<'tcx>,
132 span: Span,
133 item: &'tcx hir::Item<'tcx>,
134) -> PredicateObligations<'tcx> {
135let mut wf = WfPredicates {
136infcx,
137param_env,
138body_id,
139span,
140 out: PredicateObligations::new(),
141 recursion_depth: 0,
142 item: Some(item),
143 };
144wf.add_wf_preds_for_trait_pred(trait_pred, Elaborate::All);
145{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:145",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(145u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["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(&wf.out) as
&dyn Value))])
});
} else { ; }
};debug!(obligations = ?wf.out);
146wf.normalize(infcx)
147}
148149/// Returns the requirements for `clause` to be well-formed.
150///
151/// For example, if there is a trait `Set` defined like
152/// `trait Set<K: Eq>`, then the trait bound `Foo: Set<Bar>` is WF
153/// if `Bar: Eq`.
154x;#[instrument(skip(infcx), ret)]155pub fn clause_obligations<'tcx>(
156 infcx: &InferCtxt<'tcx>,
157 param_env: ty::ParamEnv<'tcx>,
158 body_id: LocalDefId,
159 clause: ty::Clause<'tcx>,
160 span: Span,
161) -> PredicateObligations<'tcx> {
162let mut wf = WfPredicates {
163 infcx,
164 param_env,
165 body_id,
166 span,
167 out: PredicateObligations::new(),
168 recursion_depth: 0,
169 item: None,
170 };
171172// It's ok to skip the binder here because wf code is prepared for it
173match clause.kind().skip_binder() {
174 ty::ClauseKind::Trait(t) => {
175 wf.add_wf_preds_for_trait_pred(t, Elaborate::None);
176 }
177 ty::ClauseKind::HostEffect(..) => {
178// Technically the well-formedness of this predicate is implied by
179 // the corresponding trait predicate it should've been generated beside.
180}
181 ty::ClauseKind::RegionOutlives(..) => {}
182 ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
183 wf.add_wf_preds_for_term(ty.into());
184 }
185 ty::ClauseKind::Projection(t) => {
186 wf.add_wf_preds_for_alias_term(t.projection_term);
187 wf.add_wf_preds_for_term(t.term);
188 }
189 ty::ClauseKind::ConstArgHasType(ct, ty) => {
190 wf.add_wf_preds_for_term(ct.into());
191 wf.add_wf_preds_for_term(ty.into());
192 }
193 ty::ClauseKind::WellFormed(term) => {
194 wf.add_wf_preds_for_term(term);
195 }
196197 ty::ClauseKind::ConstEvaluatable(ct) => {
198 wf.add_wf_preds_for_term(ct.into());
199 }
200 ty::ClauseKind::UnstableFeature(_) => {}
201 }
202203 wf.normalize(infcx)
204}
205206struct WfPredicates<'a, 'tcx> {
207 infcx: &'a InferCtxt<'tcx>,
208 param_env: ty::ParamEnv<'tcx>,
209 body_id: LocalDefId,
210 span: Span,
211 out: PredicateObligations<'tcx>,
212 recursion_depth: usize,
213 item: Option<&'tcx hir::Item<'tcx>>,
214}
215216/// Controls whether we "elaborate" supertraits and so forth on the WF
217/// predicates. This is a kind of hack to address #43784. The
218/// underlying problem in that issue was a trait structure like:
219///
220/// ```ignore (illustrative)
221/// trait Foo: Copy { }
222/// trait Bar: Foo { }
223/// impl<T: Bar> Foo for T { }
224/// impl<T> Bar for T { }
225/// ```
226///
227/// Here, in the `Foo` impl, we will check that `T: Copy` holds -- but
228/// we decide that this is true because `T: Bar` is in the
229/// where-clauses (and we can elaborate that to include `T:
230/// Copy`). This wouldn't be a problem, except that when we check the
231/// `Bar` impl, we decide that `T: Foo` must hold because of the `Foo`
232/// impl. And so nowhere did we check that `T: Copy` holds!
233///
234/// To resolve this, we elaborate the WF requirements that must be
235/// proven when checking impls. This means that (e.g.) the `impl Bar
236/// for T` will be forced to prove not only that `T: Foo` but also `T:
237/// Copy` (which it won't be able to do, because there is no `Copy`
238/// impl for `T`).
239#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Elaborate {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Elaborate::All => "All",
Elaborate::None => "None",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for Elaborate {
#[inline]
fn eq(&self, other: &Elaborate) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Elaborate {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for Elaborate { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Elaborate {
#[inline]
fn clone(&self) -> Elaborate { *self }
}Clone)]
240enum Elaborate {
241 All,
242None,
243}
244245/// Points the cause span of a super predicate at the relevant associated type.
246///
247/// Given a trait impl item:
248///
249/// ```ignore (incomplete)
250/// impl TargetTrait for TargetType {
251/// type Assoc = SomeType;
252/// }
253/// ```
254///
255/// And a super predicate of `TargetTrait` that has any of the following forms:
256///
257/// 1. `<OtherType as OtherTrait>::Assoc == <TargetType as TargetTrait>::Assoc`
258/// 2. `<<TargetType as TargetTrait>::Assoc as OtherTrait>::Assoc == OtherType`
259/// 3. `<TargetType as TargetTrait>::Assoc: OtherTrait`
260///
261/// Replace the span of the cause with the span of the associated item:
262///
263/// ```ignore (incomplete)
264/// impl TargetTrait for TargetType {
265/// type Assoc = SomeType;
266/// // ^^^^^^^^ this span
267/// }
268/// ```
269///
270/// Note that bounds that can be expressed as associated item bounds are **not**
271/// super predicates. This means that form 2 and 3 from above are only relevant if
272/// the [`GenericArgsRef`] of the projection type are not its identity arguments.
273fn extend_cause_with_original_assoc_item_obligation<'tcx>(
274 tcx: TyCtxt<'tcx>,
275 item: Option<&hir::Item<'tcx>>,
276 cause: &mut traits::ObligationCause<'tcx>,
277 pred: ty::Predicate<'tcx>,
278) {
279{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:279",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(279u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["message", "item",
"cause", "pred"],
::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!("extended_cause_with_original_assoc_item_obligation")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&item) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&cause) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&pred) as
&dyn Value))])
});
} else { ; }
};debug!(?item, ?cause, ?pred, "extended_cause_with_original_assoc_item_obligation");
280let (items, impl_def_id) = match item {
281Some(hir::Item { kind: hir::ItemKind::Impl(impl_), owner_id, .. }) => {
282 (impl_.items, *owner_id)
283 }
284_ => return,
285 };
286287let ty_to_impl_span = |ty: Ty<'_>| {
288if let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) = ty.kind()
289 && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(def_id)
290 && let Some(impl_item) =
291items.iter().find(|item| item.owner_id.to_def_id() == impl_item_id)
292 {
293Some(tcx.hir_impl_item(*impl_item).expect_type().span)
294 } else {
295None296 }
297 };
298299// It is fine to skip the binder as we don't care about regions here.
300match pred.kind().skip_binder() {
301 ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj)) => {
302// Form 1: The obligation comes not from the current `impl` nor the `trait` being
303 // implemented, but rather from a "second order" obligation, where an associated
304 // type has a projection coming from another associated type.
305 // See `tests/ui/traits/assoc-type-in-superbad.rs` for an example.
306if let Some(term_ty) = proj.term.as_type()
307 && let Some(impl_item_span) = ty_to_impl_span(term_ty)
308 {
309cause.span = impl_item_span;
310 }
311312// Form 2: A projection obligation for an associated item failed to be met.
313 // We overwrite the span from above to ensure that a bound like
314 // `Self::Assoc1: Trait<OtherAssoc = Self::Assoc2>` gets the same
315 // span for both obligations that it is lowered to.
316if let Some(impl_item_span) = ty_to_impl_span(proj.self_ty()) {
317cause.span = impl_item_span;
318 }
319 }
320321 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
322// Form 3: A trait obligation for an associated item failed to be met.
323{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:323",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(323u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::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!("extended_cause_with_original_assoc_item_obligation trait proj {0:?}",
pred) as &dyn Value))])
});
} else { ; }
};debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
324if let Some(impl_item_span) = ty_to_impl_span(pred.self_ty()) {
325cause.span = impl_item_span;
326 }
327 }
328_ => {}
329 }
330}
331332impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
333fn tcx(&self) -> TyCtxt<'tcx> {
334self.infcx.tcx
335 }
336337fn cause(&self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
338 traits::ObligationCause::new(self.span, self.body_id, code)
339 }
340341fn normalize(self, infcx: &InferCtxt<'tcx>) -> PredicateObligations<'tcx> {
342// Do not normalize `wf` obligations with the new solver.
343 //
344 // The current deep normalization routine with the new solver does not
345 // handle ambiguity and the new solver correctly deals with unnnormalized goals.
346 // If the user relies on normalized types, e.g. for `fn implied_outlives_bounds`,
347 // it is their responsibility to normalize while avoiding ambiguity.
348if infcx.next_trait_solver() {
349return self.out;
350 }
351352let cause = self.cause(ObligationCauseCode::WellFormed(None));
353let param_env = self.param_env;
354let mut obligations = PredicateObligations::with_capacity(self.out.len());
355for mut obligation in self.out {
356if !!obligation.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !obligation.has_escaping_bound_vars()")
};assert!(!obligation.has_escaping_bound_vars());
357let mut selcx = traits::SelectionContext::new(infcx);
358// Don't normalize the whole obligation, the param env is either
359 // already normalized, or we're currently normalizing the
360 // param_env. Either way we should only normalize the predicate.
361let normalized_predicate = traits::normalize::normalize_with_depth_to(
362&mut selcx,
363 param_env,
364 cause.clone(),
365self.recursion_depth,
366 obligation.predicate,
367&mut obligations,
368 );
369 obligation.predicate = normalized_predicate;
370 obligations.push(obligation);
371 }
372obligations373 }
374375/// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
376fn add_wf_preds_for_trait_pred(
377&mut self,
378 trait_pred: ty::TraitPredicate<'tcx>,
379 elaborate: Elaborate,
380 ) {
381let tcx = self.tcx();
382let trait_ref = trait_pred.trait_ref;
383384// Negative trait predicates don't require supertraits to hold, just
385 // that their args are WF.
386if trait_pred.polarity == ty::PredicatePolarity::Negative {
387self.add_wf_preds_for_negative_trait_pred(trait_ref);
388return;
389 }
390391// if the trait predicate is not const, the wf obligations should not be const as well.
392let obligations = self.nominal_obligations(trait_ref.def_id, trait_ref.args);
393394{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:394",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(394u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::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!("compute_trait_pred obligations {0:?}",
obligations) as &dyn Value))])
});
} else { ; }
};debug!("compute_trait_pred obligations {:?}", obligations);
395let param_env = self.param_env;
396let depth = self.recursion_depth;
397398let item = self.item;
399400let extend = |traits::PredicateObligation { predicate, mut cause, .. }| {
401if let Some(parent_trait_pred) = predicate.as_trait_clause() {
402cause = cause.derived_cause(
403parent_trait_pred,
404 traits::ObligationCauseCode::WellFormedDerived,
405 );
406 }
407extend_cause_with_original_assoc_item_obligation(tcx, item, &mut cause, predicate);
408 traits::Obligation::with_depth(tcx, cause, depth, param_env, predicate)
409 };
410411if let Elaborate::All = elaborate {
412let implied_obligations = traits::util::elaborate(tcx, obligations);
413let implied_obligations = implied_obligations.map(extend);
414self.out.extend(implied_obligations);
415 } else {
416self.out.extend(obligations);
417 }
418419self.out.extend(
420trait_ref421 .args
422 .iter()
423 .enumerate()
424 .filter_map(|(i, arg)| arg.as_term().map(|t| (i, t)))
425 .filter(|(_, term)| !term.has_escaping_bound_vars())
426 .map(|(i, term)| {
427let mut cause = traits::ObligationCause::misc(self.span, self.body_id);
428// The first arg is the self ty - use the correct span for it.
429if i == 0 {
430if let Some(hir::ItemKind::Impl(hir::Impl { self_ty, .. })) =
431item.map(|i| &i.kind)
432 {
433cause.span = self_ty.span;
434 }
435 }
436 traits::Obligation::with_depth(
437tcx,
438cause,
439depth,
440param_env,
441 ty::ClauseKind::WellFormed(term),
442 )
443 }),
444 );
445 }
446447// Compute the obligations that are required for `trait_ref` to be WF,
448 // given that it is a *negative* trait predicate.
449fn add_wf_preds_for_negative_trait_pred(&mut self, trait_ref: ty::TraitRef<'tcx>) {
450for arg in trait_ref.args {
451if let Some(term) = arg.as_term() {
452self.add_wf_preds_for_term(term);
453 }
454 }
455 }
456457/// Pushes the obligations required for an alias (except inherent) to be WF
458 /// into `self.out`.
459fn add_wf_preds_for_alias_term(&mut self, data: ty::AliasTerm<'tcx>) {
460// A projection is well-formed if
461 //
462 // (a) its predicates hold (*)
463 // (b) its args are wf
464 //
465 // (*) The predicates of an associated type include the predicates of
466 // the trait that it's contained in. For example, given
467 //
468 // trait A<T>: Clone {
469 // type X where T: Copy;
470 // }
471 //
472 // The predicates of `<() as A<i32>>::X` are:
473 // [
474 // `(): Sized`
475 // `(): Clone`
476 // `(): A<i32>`
477 // `i32: Sized`
478 // `i32: Clone`
479 // `i32: Copy`
480 // ]
481let obligations = self.nominal_obligations(data.def_id(), data.args);
482self.out.extend(obligations);
483484self.add_wf_preds_for_projection_args(data.args);
485 }
486487/// Pushes the obligations required for an inherent alias to be WF
488 /// into `self.out`.
489// FIXME(inherent_associated_types): Merge this function with `fn compute_alias`.
490fn add_wf_preds_for_inherent_projection(&mut self, data: ty::AliasTerm<'tcx>) {
491// An inherent projection is well-formed if
492 //
493 // (a) its predicates hold (*)
494 // (b) its args are wf
495 //
496 // (*) The predicates of an inherent associated type include the
497 // predicates of the impl that it's contained in.
498499if !data.self_ty().has_escaping_bound_vars() {
500// FIXME(inherent_associated_types): Should this happen inside of a snapshot?
501 // FIXME(inherent_associated_types): This is incompatible with the new solver and lazy norm!
502let args = traits::project::compute_inherent_assoc_term_args(
503&mut traits::SelectionContext::new(self.infcx),
504self.param_env,
505data,
506self.cause(ObligationCauseCode::WellFormed(None)),
507self.recursion_depth,
508&mut self.out,
509 );
510let obligations = self.nominal_obligations(data.def_id(), args);
511self.out.extend(obligations);
512 }
513514data.args.visit_with(self);
515 }
516517fn add_wf_preds_for_projection_args(&mut self, args: GenericArgsRef<'tcx>) {
518let tcx = self.tcx();
519let cause = self.cause(ObligationCauseCode::WellFormed(None));
520let param_env = self.param_env;
521let depth = self.recursion_depth;
522523self.out.extend(
524args.iter()
525 .filter_map(|arg| arg.as_term())
526 .filter(|term| !term.has_escaping_bound_vars())
527 .map(|term| {
528 traits::Obligation::with_depth(
529tcx,
530cause.clone(),
531depth,
532param_env,
533 ty::ClauseKind::WellFormed(term),
534 )
535 }),
536 );
537 }
538539fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {
540if !subty.has_escaping_bound_vars() {
541let cause = self.cause(cause);
542let trait_ref = ty::TraitRef::new(
543self.tcx(),
544self.tcx().require_lang_item(LangItem::Sized, cause.span),
545 [subty],
546 );
547self.out.push(traits::Obligation::with_depth(
548self.tcx(),
549cause,
550self.recursion_depth,
551self.param_env,
552 ty::Binder::dummy(trait_ref),
553 ));
554 }
555 }
556557/// Pushes all the predicates needed to validate that `term` is WF into `out`.
558#[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("add_wf_preds_for_term",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(558u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["term"],
::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(&term)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
term.visit_with(self);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:561",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(561u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["self.out"],
::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(&self.out)
as &dyn Value))])
});
} else { ; }
};
}
}
}#[instrument(level = "debug", skip(self))]559fn add_wf_preds_for_term(&mut self, term: Term<'tcx>) {
560 term.visit_with(self);
561debug!(?self.out);
562 }
563564#[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("nominal_obligations",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(564u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["def_id", "args"],
::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(&def_id)
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(&args)
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: PredicateObligations<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
if self.tcx().is_lang_item(def_id, LangItem::Sized) {
return Default::default();
}
if self.tcx().is_lang_item(def_id, LangItem::ConstParamTy) &&
self.tcx().features().const_param_ty_unchecked() {
return Default::default();
}
let predicates = self.tcx().predicates_of(def_id);
let mut origins =
::alloc::vec::from_elem(def_id, predicates.predicates.len());
let mut head = predicates;
while let Some(parent) = head.parent {
head = self.tcx().predicates_of(parent);
origins.extend(iter::repeat(parent).take(head.predicates.len()));
}
let predicates = predicates.instantiate(self.tcx(), args);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:592",
"rustc_trait_selection::traits::wf",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(592u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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!("{0:#?}",
predicates) as &dyn Value))])
});
} else { ; }
};
if true {
match (&predicates.predicates.len(), &origins.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);
}
}
};
};
iter::zip(predicates,
origins.into_iter().rev()).map(|((pred, span),
origin_def_id)|
{
let code =
ObligationCauseCode::WhereClause(origin_def_id, span);
let cause = self.cause(code);
traits::Obligation::with_depth(self.tcx(), cause,
self.recursion_depth, self.param_env, pred.skip_norm_wip())
}).filter(|pred| !pred.has_escaping_bound_vars()).collect()
}
}
}#[instrument(level = "debug", skip(self))]565fn nominal_obligations(
566&mut self,
567 def_id: DefId,
568 args: GenericArgsRef<'tcx>,
569 ) -> PredicateObligations<'tcx> {
570// PERF: `Sized`'s predicates include `MetaSized`, but both are compiler implemented marker
571 // traits, so `MetaSized` will always be WF if `Sized` is WF and vice-versa. Determining
572 // the nominal obligations of `Sized` would in-effect just elaborate `MetaSized` and make
573 // the compiler do a bunch of work needlessly.
574if self.tcx().is_lang_item(def_id, LangItem::Sized) {
575return Default::default();
576 }
577if self.tcx().is_lang_item(def_id, LangItem::ConstParamTy)
578 && self.tcx().features().const_param_ty_unchecked()
579 {
580return Default::default();
581 }
582583let predicates = self.tcx().predicates_of(def_id);
584let mut origins = vec![def_id; predicates.predicates.len()];
585let mut head = predicates;
586while let Some(parent) = head.parent {
587 head = self.tcx().predicates_of(parent);
588 origins.extend(iter::repeat(parent).take(head.predicates.len()));
589 }
590591let predicates = predicates.instantiate(self.tcx(), args);
592trace!("{:#?}", predicates);
593debug_assert_eq!(predicates.predicates.len(), origins.len());
594595 iter::zip(predicates, origins.into_iter().rev())
596 .map(|((pred, span), origin_def_id)| {
597let code = ObligationCauseCode::WhereClause(origin_def_id, span);
598let cause = self.cause(code);
599 traits::Obligation::with_depth(
600self.tcx(),
601 cause,
602self.recursion_depth,
603self.param_env,
604 pred.skip_norm_wip(),
605 )
606 })
607 .filter(|pred| !pred.has_escaping_bound_vars())
608 .collect()
609 }
610611fn add_wf_preds_for_dyn_ty(
612&mut self,
613 ty: Ty<'tcx>,
614 data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
615 region: ty::Region<'tcx>,
616 ) {
617// Imagine a type like this:
618 //
619 // trait Foo { }
620 // trait Bar<'c> : 'c { }
621 //
622 // &'b (Foo+'c+Bar<'d>)
623 // ^
624 //
625 // In this case, the following relationships must hold:
626 //
627 // 'b <= 'c
628 // 'd <= 'c
629 //
630 // The first conditions is due to the normal region pointer
631 // rules, which say that a reference cannot outlive its
632 // referent.
633 //
634 // The final condition may be a bit surprising. In particular,
635 // you may expect that it would have been `'c <= 'd`, since
636 // usually lifetimes of outer things are conservative
637 // approximations for inner things. However, it works somewhat
638 // differently with trait objects: here the idea is that if the
639 // user specifies a region bound (`'c`, in this case) it is the
640 // "master bound" that *implies* that bounds from other traits are
641 // all met. (Remember that *all bounds* in a type like
642 // `Foo+Bar+Zed` must be met, not just one, hence if we write
643 // `Foo<'x>+Bar<'y>`, we know that the type outlives *both* 'x and
644 // 'y.)
645 //
646 // Note: in fact we only permit builtin traits, not `Bar<'d>`, I
647 // am looking forward to the future here.
648if !data.has_escaping_bound_vars() && !region.has_escaping_bound_vars() {
649let implicit_bounds = object_region_bounds(self.tcx(), data);
650651let explicit_bound = region;
652653self.out.reserve(implicit_bounds.len());
654for implicit_bound in implicit_bounds {
655let cause = self.cause(ObligationCauseCode::ObjectTypeBound(ty, explicit_bound));
656let outlives =
657 ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
658self.out.push(traits::Obligation::with_depth(
659self.tcx(),
660 cause,
661self.recursion_depth,
662self.param_env,
663 outlives,
664 ));
665 }
666667// We don't add any wf predicates corresponding to the trait ref's generic arguments
668 // which allows code like this to compile:
669 // ```rust
670 // trait Trait<T: Sized> {}
671 // fn foo(_: &dyn Trait<[u32]>) {}
672 // ```
673}
674 }
675676fn add_wf_preds_for_pat_ty(&mut self, base_ty: Ty<'tcx>, pat: ty::Pattern<'tcx>) {
677let tcx = self.tcx();
678match *pat {
679 ty::PatternKind::Range { start, end } => {
680let mut check = |c| {
681let cause = self.cause(ObligationCauseCode::Misc);
682self.out.push(traits::Obligation::with_depth(
683tcx,
684cause.clone(),
685self.recursion_depth,
686self.param_env,
687 ty::Binder::dummy(ty::PredicateKind::Clause(
688 ty::ClauseKind::ConstArgHasType(c, base_ty),
689 )),
690 ));
691if !tcx.features().generic_pattern_types() {
692if c.has_param() {
693if self.span.is_dummy() {
694self.tcx()
695 .dcx()
696 .delayed_bug("feature error should be reported elsewhere, too");
697 } else {
698feature_err(
699&self.tcx().sess,
700 sym::generic_pattern_types,
701self.span,
702"wraparound pattern type ranges cause monomorphization time errors",
703 )
704 .emit();
705 }
706 }
707 }
708 };
709check(start);
710check(end);
711 }
712 ty::PatternKind::NotNull => {}
713 ty::PatternKind::Or(patterns) => {
714for pat in patterns {
715self.add_wf_preds_for_pat_ty(base_ty, pat)
716 }
717 }
718 }
719 }
720}
721722impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
723fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
724{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:724",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(724u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::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!("wf bounds for t={0:?} t.kind={1:#?}",
t, t.kind()) as &dyn Value))])
});
} else { ; }
};debug!("wf bounds for t={:?} t.kind={:#?}", t, t.kind());
725726let tcx = self.tcx();
727728match *t.kind() {
729 ty::Bool730 | ty::Char731 | ty::Int(..)
732 | ty::Uint(..)
733 | ty::Float(..)
734 | ty::Error(_)
735 | ty::Str736 | ty::CoroutineWitness(..)
737 | ty::Never738 | ty::Param(_)
739 | ty::Bound(..)
740 | ty::Placeholder(..)
741 | ty::Foreign(..) => {
742// WfScalar, WfParameter, etc
743}
744745// Can only infer to `ty::Int(_) | ty::Uint(_)`.
746ty::Infer(ty::IntVar(_)) => {}
747748// Can only infer to `ty::Float(_)`.
749ty::Infer(ty::FloatVar(_)) => {}
750751 ty::Slice(subty) => {
752self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
753 }
754755 ty::Array(subty, len) => {
756self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
757// Note that the len being WF is implicitly checked while visiting.
758 // Here we just check that it's of type usize.
759let cause = self.cause(ObligationCauseCode::ArrayLen(t));
760self.out.push(traits::Obligation::with_depth(
761tcx,
762cause,
763self.recursion_depth,
764self.param_env,
765 ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(
766len,
767tcx.types.usize,
768 ))),
769 ));
770 }
771772 ty::Pat(base_ty, pat) => {
773self.require_sized(base_ty, ObligationCauseCode::Misc);
774self.add_wf_preds_for_pat_ty(base_ty, pat);
775 }
776777 ty::Tuple(tys) => {
778if let Some((last, rest)) = tys.split_last() {
779for &elem in rest {
780self.require_sized(elem, ObligationCauseCode::TupleElem);
781if elem.is_scalable_vector() && !self.span.is_dummy() {
782self.tcx()
783 .dcx()
784 .struct_span_err(
785self.span,
786"scalable vectors cannot be tuple fields",
787 )
788 .emit();
789 }
790 }
791792if last.is_scalable_vector() && !self.span.is_dummy() {
793self.tcx()
794 .dcx()
795 .struct_span_err(self.span, "scalable vectors cannot be tuple fields")
796 .emit();
797 }
798 }
799 }
800801 ty::RawPtr(_, _) => {
802// Simple cases that are WF if their type args are WF.
803}
804805 ty::Alias(ty::AliasTy {
806 kind: ty::Projection { def_id } | ty::Opaque { def_id } | ty::Free { def_id },
807 args,
808 ..
809 }) => {
810let obligations = self.nominal_obligations(def_id, args);
811self.out.extend(obligations);
812 }
813 ty::Alias(data @ ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
814self.add_wf_preds_for_inherent_projection(data.into());
815return; // Subtree handled by compute_inherent_projection.
816}
817818 ty::Adt(def, args) => {
819// WfNominalType
820let obligations = self.nominal_obligations(def.did(), args);
821self.out.extend(obligations);
822 }
823824 ty::FnDef(did, args) => {
825// HACK: Check the return type of function definitions for
826 // well-formedness to mostly fix #84533. This is still not
827 // perfect and there may be ways to abuse the fact that we
828 // ignore requirements with escaping bound vars. That's a
829 // more general issue however.
830let fn_sig = tcx.fn_sig(did).instantiate(tcx, args).skip_norm_wip();
831fn_sig.output().skip_binder().visit_with(self);
832833let obligations = self.nominal_obligations(did, args);
834self.out.extend(obligations);
835 }
836837 ty::Ref(r, rty, _) => {
838// WfReference
839if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
840let cause = self.cause(ObligationCauseCode::ReferenceOutlivesReferent(t));
841self.out.push(traits::Obligation::with_depth(
842tcx,
843cause,
844self.recursion_depth,
845self.param_env,
846 ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(
847 ty::OutlivesPredicate(rty, r),
848 ))),
849 ));
850 }
851 }
852853 ty::Coroutine(did, args, ..) => {
854// Walk ALL the types in the coroutine: this will
855 // include the upvar types as well as the yield
856 // type. Note that this is mildly distinct from
857 // the closure case, where we have to be careful
858 // about the signature of the closure. We don't
859 // have the problem of implied bounds here since
860 // coroutines don't take arguments.
861let obligations = self.nominal_obligations(did, args);
862self.out.extend(obligations);
863 }
864865 ty::Closure(did, args) => {
866// Note that we cannot skip the generic types
867 // types. Normally, within the fn
868 // body where they are created, the generics will
869 // always be WF, and outside of that fn body we
870 // are not directly inspecting closure types
871 // anyway, except via auto trait matching (which
872 // only inspects the upvar types).
873 // But when a closure is part of a type-alias-impl-trait
874 // then the function that created the defining site may
875 // have had more bounds available than the type alias
876 // specifies. This may cause us to have a closure in the
877 // hidden type that is not actually well formed and
878 // can cause compiler crashes when the user abuses unsafe
879 // code to procure such a closure.
880 // See tests/ui/type-alias-impl-trait/wf_check_closures.rs
881let obligations = self.nominal_obligations(did, args);
882self.out.extend(obligations);
883// Only check the upvar types for WF, not the rest
884 // of the types within. This is needed because we
885 // capture the signature and it may not be WF
886 // without the implied bounds. Consider a closure
887 // like `|x: &'a T|` -- it may be that `T: 'a` is
888 // not known to hold in the creator's context (and
889 // indeed the closure may not be invoked by its
890 // creator, but rather turned to someone who *can*
891 // verify that).
892 //
893 // The special treatment of closures here really
894 // ought not to be necessary either; the problem
895 // is related to #25860 -- there is no way for us
896 // to express a fn type complete with the implied
897 // bounds that it is assuming. I think in reality
898 // the WF rules around fn are a bit messed up, and
899 // that is the rot problem: `fn(&'a T)` should
900 // probably always be WF, because it should be
901 // shorthand for something like `where(T: 'a) {
902 // fn(&'a T) }`, as discussed in #25860.
903let upvars = args.as_closure().tupled_upvars_ty();
904return upvars.visit_with(self);
905 }
906907 ty::CoroutineClosure(did, args) => {
908// See the above comments. The same apply to coroutine-closures.
909let obligations = self.nominal_obligations(did, args);
910self.out.extend(obligations);
911let upvars = args.as_coroutine_closure().tupled_upvars_ty();
912return upvars.visit_with(self);
913 }
914915 ty::FnPtr(..) => {
916// Let the visitor iterate into the argument/return
917 // types appearing in the fn signature.
918}
919 ty::UnsafeBinder(ty) => {
920// FIXME(unsafe_binders): For now, we have no way to express
921 // that a type must be `ManuallyDrop` OR `Copy` (or a pointer).
922if !ty.has_escaping_bound_vars() {
923self.out.push(traits::Obligation::new(
924self.tcx(),
925self.cause(ObligationCauseCode::Misc),
926self.param_env,
927ty.map_bound(|ty| {
928 ty::TraitRef::new(
929self.tcx(),
930self.tcx().require_lang_item(
931 LangItem::BikeshedGuaranteedNoDrop,
932self.span,
933 ),
934 [ty],
935 )
936 }),
937 ));
938 }
939940// We recurse into the binder below.
941}
942943 ty::Dynamic(data, r) => {
944// WfObject
945 //
946 // Here, we defer WF checking due to higher-ranked
947 // regions. This is perhaps not ideal.
948self.add_wf_preds_for_dyn_ty(t, data, r);
949950// FIXME(#27579) RFC also considers adding trait
951 // obligations that don't refer to Self and
952 // checking those
953if let Some(principal) = data.principal() {
954let principal_def_id = principal.skip_binder().def_id;
955self.out.push(traits::Obligation::with_depth(
956tcx,
957self.cause(ObligationCauseCode::WellFormed(None)),
958self.recursion_depth,
959self.param_env,
960 ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal_def_id)),
961 ));
962963// For the most part we don't add wf predicates corresponding to
964 // the trait ref's generic arguments which allows code like this
965 // to compile:
966 // ```rust
967 // trait Trait<T: Sized> {}
968 // fn foo(_: &dyn Trait<[u32]>) {}
969 // ```
970 //
971 // However, we sometimes incidentally check that const arguments
972 // have the correct type as a side effect of the anon const
973 // desugaring. To make this "consistent" for users we explicitly
974 // check `ConstArgHasType` clauses so that const args that don't
975 // go through an anon const still have their types checked.
976 //
977 // See also: https://rustc-dev-guide.rust-lang.org/const-generics.html
978let args = principal.skip_binder().with_self_ty(self.tcx(), t).args;
979let obligations =
980self.nominal_obligations(principal_def_id, args).into_iter().filter(|o| {
981let kind = o.predicate.kind().skip_binder();
982match kind {
983 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(
984 ct,
985_,
986 )) if #[allow(non_exhaustive_omitted_patterns)] match ct.kind() {
ty::ConstKind::Param(..) => true,
_ => false,
}matches!(ct.kind(), ty::ConstKind::Param(..)) => {
987// ConstArgHasType clauses are not higher kinded. Assert as
988 // such so we can fix this up if that ever changes.
989if !o.predicate.kind().bound_vars().is_empty() {
::core::panicking::panic("assertion failed: o.predicate.kind().bound_vars().is_empty()")
};assert!(o.predicate.kind().bound_vars().is_empty());
990// In stable rust, variables from the trait object binder
991 // cannot be referenced by a ConstArgHasType clause. However,
992 // under `generic_const_parameter_types`, it can. Ignore those
993 // predicates for now, to not have HKT-ConstArgHasTypes.
994!kind.has_escaping_bound_vars()
995 }
996_ => false,
997 }
998 });
999self.out.extend(obligations);
1000 }
10011002if !t.has_escaping_bound_vars() {
1003for projection in data.projection_bounds() {
1004let pred_binder = projection
1005 .with_self_ty(tcx, t)
1006 .map_bound(|p| {
1007 p.term.as_const().map(|ct| {
1008let assoc_const_ty = tcx
1009 .type_of(p.projection_term.def_id())
1010 .instantiate(tcx, p.projection_term.args)
1011 .skip_norm_wip();
1012 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(
1013 ct,
1014 assoc_const_ty,
1015 ))
1016 })
1017 })
1018 .transpose();
1019if let Some(pred_binder) = pred_binder {
1020self.out.push(traits::Obligation::with_depth(
1021 tcx,
1022self.cause(ObligationCauseCode::WellFormed(None)),
1023self.recursion_depth,
1024self.param_env,
1025 pred_binder,
1026 ));
1027 }
1028 }
1029 }
1030 }
10311032// Inference variables are the complicated case, since we don't
1033 // know what type they are. We do two things:
1034 //
1035 // 1. Check if they have been resolved, and if so proceed with
1036 // THAT type.
1037 // 2. If not, we've at least simplified things (e.g., we went
1038 // from `Vec?0>: WF` to `?0: WF`), so we can
1039 // register a pending obligation and keep
1040 // moving. (Goal is that an "inductive hypothesis"
1041 // is satisfied to ensure termination.)
1042 // See also the comment on `fn obligations`, describing cycle
1043 // prevention, which happens before this can be reached.
1044ty::Infer(_) => {
1045let cause = self.cause(ObligationCauseCode::WellFormed(None));
1046self.out.push(traits::Obligation::with_depth(
1047tcx,
1048cause,
1049self.recursion_depth,
1050self.param_env,
1051 ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
1052t.into(),
1053 ))),
1054 ));
1055 }
1056 }
10571058t.super_visit_with(self)
1059 }
10601061fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
1062let tcx = self.tcx();
10631064match c.kind() {
1065 ty::ConstKind::Unevaluated(uv) => {
1066if !c.has_escaping_bound_vars() {
1067// Skip type consts as mGCA doesn't support evaluatable clauses
1068if !tcx.is_type_const(uv.def) {
1069let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
1070 ty::ClauseKind::ConstEvaluatable(c),
1071 ));
1072let cause = self.cause(ObligationCauseCode::WellFormed(None));
1073self.out.push(traits::Obligation::with_depth(
1074tcx,
1075cause,
1076self.recursion_depth,
1077self.param_env,
1078predicate,
1079 ));
1080 }
10811082if #[allow(non_exhaustive_omitted_patterns)] match tcx.def_kind(uv.def) {
DefKind::AssocConst { .. } => true,
_ => false,
}matches!(tcx.def_kind(uv.def), DefKind::AssocConst { .. })1083 && tcx.def_kind(tcx.parent(uv.def)) == (DefKind::Impl { of_trait: false })
1084 {
1085self.add_wf_preds_for_inherent_projection(
1086 ty::AliasTerm::from_unevaluated_const(tcx, uv),
1087 );
1088return; // Subtree is handled by above function
1089} else {
1090let obligations = self.nominal_obligations(uv.def, uv.args);
1091self.out.extend(obligations);
1092 }
1093 }
1094 }
1095 ty::ConstKind::Infer(_) => {
1096let cause = self.cause(ObligationCauseCode::WellFormed(None));
10971098self.out.push(traits::Obligation::with_depth(
1099tcx,
1100cause,
1101self.recursion_depth,
1102self.param_env,
1103 ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
1104c.into(),
1105 ))),
1106 ));
1107 }
1108 ty::ConstKind::Expr(_) => {
1109// FIXME(generic_const_exprs): this doesn't verify that given `Expr(N + 1)` the
1110 // trait bound `typeof(N): Add<typeof(1)>` holds. This is currently unnecessary
1111 // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Unevaluated`
1112 // which means that the `DefId` would have been typeck'd elsewhere. However in
1113 // the future we may allow directly lowering to `ConstKind::Expr` in which case
1114 // we would not be proving bounds we should.
11151116let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
1117 ty::ClauseKind::ConstEvaluatable(c),
1118 ));
1119let cause = self.cause(ObligationCauseCode::WellFormed(None));
1120self.out.push(traits::Obligation::with_depth(
1121tcx,
1122cause,
1123self.recursion_depth,
1124self.param_env,
1125predicate,
1126 ));
1127 }
11281129 ty::ConstKind::Error(_)
1130 | ty::ConstKind::Param(_)
1131 | ty::ConstKind::Bound(..)
1132 | ty::ConstKind::Placeholder(..) => {
1133// These variants are trivially WF, so nothing to do here.
1134}
1135 ty::ConstKind::Value(val) => {
1136// FIXME(mgca): no need to feature-gate once valtree lifetimes are not erased
1137if tcx.features().min_generic_const_args() {
1138match val.ty.kind() {
1139 ty::Adt(adt_def, args) => {
1140let adt_val = val.destructure_adt_const();
1141let variant_def = adt_def.variant(adt_val.variant);
1142let cause = self.cause(ObligationCauseCode::WellFormed(None));
1143self.out.extend(variant_def.fields.iter().zip(adt_val.fields).map(
1144 |(field_def, &field_val)| {
1145let field_ty = tcx1146 .type_of(field_def.did)
1147 .instantiate(tcx, args)
1148 .skip_norm_wip();
1149let predicate = ty::PredicateKind::Clause(
1150 ty::ClauseKind::ConstArgHasType(field_val, field_ty),
1151 );
1152 traits::Obligation::with_depth(
1153tcx,
1154cause.clone(),
1155self.recursion_depth,
1156self.param_env,
1157predicate,
1158 )
1159 },
1160 ));
1161 }
1162 ty::Tuple(field_tys) => {
1163let field_vals = val.to_branch();
1164let cause = self.cause(ObligationCauseCode::WellFormed(None));
1165self.out.extend(field_tys.iter().zip(field_vals).map(
1166 |(field_ty, &field_val)| {
1167let predicate = ty::PredicateKind::Clause(
1168 ty::ClauseKind::ConstArgHasType(field_val, field_ty),
1169 );
1170 traits::Obligation::with_depth(
1171tcx,
1172cause.clone(),
1173self.recursion_depth,
1174self.param_env,
1175predicate,
1176 )
1177 },
1178 ));
1179 }
1180 ty::Array(elem_ty, _len) => {
1181let elem_vals = val.to_branch();
1182let cause = self.cause(ObligationCauseCode::WellFormed(None));
11831184self.out.extend(elem_vals.iter().map(|&elem_val| {
1185let predicate = ty::PredicateKind::Clause(
1186 ty::ClauseKind::ConstArgHasType(elem_val, *elem_ty),
1187 );
1188 traits::Obligation::with_depth(
1189tcx,
1190cause.clone(),
1191self.recursion_depth,
1192self.param_env,
1193predicate,
1194 )
1195 }));
1196 }
1197_ => {}
1198 }
1199 }
12001201// FIXME: Enforce that values are structurally-matchable.
1202}
1203 }
12041205c.super_visit_with(self)
1206 }
12071208fn visit_predicate(&mut self, _p: ty::Predicate<'tcx>) -> Self::Result {
1209::rustc_middle::util::bug::bug_fmt(format_args!("predicate should not be checked for well-formedness"));bug!("predicate should not be checked for well-formedness");
1210 }
1211}
12121213/// Given an object type like `SomeTrait + Send`, computes the lifetime
1214/// bounds that must hold on the elided self type. These are derived
1215/// from the declarations of `SomeTrait`, `Send`, and friends -- if
1216/// they declare `trait SomeTrait : 'static`, for example, then
1217/// `'static` would appear in the list.
1218///
1219/// N.B., in some cases, particularly around higher-ranked bounds,
1220/// this function returns a kind of conservative approximation.
1221/// That is, all regions returned by this function are definitely
1222/// required, but there may be other region bounds that are not
1223/// returned, as well as requirements like `for<'a> T: 'a`.
1224///
1225/// Requires that trait definitions have been processed so that we can
1226/// elaborate predicates and walk supertraits.
1227pub fn object_region_bounds<'tcx>(
1228 tcx: TyCtxt<'tcx>,
1229 existential_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
1230) -> Vec<ty::Region<'tcx>> {
1231let erased_self_ty = tcx.types.trait_object_dummy_self;
12321233let predicates =
1234existential_predicates.iter().map(|predicate| predicate.with_self_ty(tcx, erased_self_ty));
12351236 traits::elaborate(tcx, predicates)
1237 .filter_map(|pred| {
1238{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/wf.rs:1238",
"rustc_trait_selection::traits::wf",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/wf.rs"),
::tracing_core::__macro_support::Option::Some(1238u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::wf"),
::tracing_core::field::FieldSet::new(&["pred"],
::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(&pred) as
&dyn Value))])
});
} else { ; }
};debug!(?pred);
1239match pred.kind().skip_binder() {
1240 ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
1241// Search for a bound of the form `erased_self_ty
1242 // : 'a`, but be wary of something like `for<'a>
1243 // erased_self_ty : 'a` (we interpret a
1244 // higher-ranked bound like that as 'static,
1245 // though at present the code in `fulfill.rs`
1246 // considers such bounds to be unsatisfiable, so
1247 // it's kind of a moot point since you could never
1248 // construct such an object, but this seems
1249 // correct even if that code changes).
1250if t == &erased_self_ty && !r.has_escaping_bound_vars() {
1251Some(*r)
1252 } else {
1253None1254 }
1255 }
1256 ty::ClauseKind::Trait(_)
1257 | ty::ClauseKind::HostEffect(..)
1258 | ty::ClauseKind::RegionOutlives(_)
1259 | ty::ClauseKind::Projection(_)
1260 | ty::ClauseKind::ConstArgHasType(_, _)
1261 | ty::ClauseKind::WellFormed(_)
1262 | ty::ClauseKind::UnstableFeature(_)
1263 | ty::ClauseKind::ConstEvaluatable(_) => None,
1264 }
1265 })
1266 .collect()
1267}