1
Fork 0

attempt to make a minimal example work

This commit is contained in:
Deadbeef 2022-12-21 16:32:16 +00:00
parent 23718a3cc2
commit 6e63f7be54
13 changed files with 62 additions and 21 deletions

View file

@ -254,18 +254,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// touch bound regions, they just capture the in-scope
// type/region parameters
match *obligation.self_ty().skip_binder().kind() {
ty::Closure(_, closure_substs) => {
ty::Closure(def_id, closure_substs) => {
let is_const = self.tcx().is_const_fn_raw(def_id);
debug!(?kind, ?obligation, "assemble_unboxed_candidates");
match self.infcx.closure_kind(closure_substs) {
Some(closure_kind) => {
debug!(?closure_kind, "assemble_unboxed_candidates");
if closure_kind.extends(kind) {
candidates.vec.push(ClosureCandidate);
candidates.vec.push(ClosureCandidate {
is_const,
});
}
}
None => {
debug!("assemble_unboxed_candidates: closure_kind not yet known");
candidates.vec.push(ClosureCandidate);
candidates.vec.push(ClosureCandidate {
is_const,
});
}
}
}

View file

@ -84,7 +84,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplSource::Object(data)
}
ClosureCandidate => {
ClosureCandidate { .. } => {
let vtable_closure = self.confirm_closure_candidate(obligation)?;
ImplSource::Closure(vtable_closure)
}

View file

@ -1365,15 +1365,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// const param
ParamCandidate(trait_pred) if trait_pred.is_const_if_const() => {}
// const projection
ProjectionCandidate(_, ty::BoundConstness::ConstIfConst) => {}
ProjectionCandidate(_, ty::BoundConstness::ConstIfConst)
// auto trait impl
AutoImplCandidate => {}
| AutoImplCandidate
// generator / future, this will raise error in other places
// or ignore error with const_async_blocks feature
GeneratorCandidate => {}
FutureCandidate => {}
| GeneratorCandidate
| FutureCandidate
// FnDef where the function is const
FnPointerCandidate { is_const: true } => {}
| FnPointerCandidate { is_const: true }
| ConstDestructCandidate(_)
| ClosureCandidate { is_const: true } => {}
FnPointerCandidate { is_const: false } => {
if let ty::FnDef(def_id, _) = obligation.self_ty().skip_binder().kind() && tcx.trait_of_item(*def_id).is_some() {
// Trait methods are not seen as const unless the trait is implemented as const.
@ -1382,7 +1385,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
continue
}
}
ConstDestructCandidate(_) => {}
_ => {
// reject all other types of candidates
continue;
@ -1844,7 +1847,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(
ParamCandidate(ref cand),
ImplCandidate(..)
| ClosureCandidate
| ClosureCandidate { .. }
| GeneratorCandidate
| FutureCandidate
| FnPointerCandidate { .. }
@ -1863,7 +1866,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
(
ImplCandidate(_)
| ClosureCandidate
| ClosureCandidate { .. }
| GeneratorCandidate
| FutureCandidate
| FnPointerCandidate { .. }
@ -1894,7 +1897,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(
ObjectCandidate(_) | ProjectionCandidate(..),
ImplCandidate(..)
| ClosureCandidate
| ClosureCandidate { .. }
| GeneratorCandidate
| FutureCandidate
| FnPointerCandidate { .. }
@ -1907,7 +1910,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(
ImplCandidate(..)
| ClosureCandidate
| ClosureCandidate { .. }
| GeneratorCandidate
| FutureCandidate
| FnPointerCandidate { .. }
@ -1989,7 +1992,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Everything else is ambiguous
(
ImplCandidate(_)
| ClosureCandidate
| ClosureCandidate { .. }
| GeneratorCandidate
| FutureCandidate
| FnPointerCandidate { .. }
@ -1999,7 +2002,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| BuiltinCandidate { has_nested: true }
| TraitAliasCandidate,
ImplCandidate(_)
| ClosureCandidate
| ClosureCandidate { .. }
| GeneratorCandidate
| FutureCandidate
| FnPointerCandidate { .. }