-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICE: cannot infer substitution
during normalization
#829
Comments
[ see other commentary in #808 ] |
Good point! Can you make a small mock for the real thing with |
This is a minimal example that should trigger the original behavior in #808 trait Trait {
type Assoc;
}
struct S<T> {
fld: T,
}
impl<T1, T2> Trait for S<T1>
where
T1: FnOnce() -> T2,
{
type Assoc = T1;
}
fn test(x: <S<fn()> as Trait>::Assoc) {} |
Even simpler. The following triggers the normalization for function pointers which is orthogonal to the ambiguous substitution part of this issue fn test01<F: FnOnce() -> i32>(f: F) -> F::Output {
f()
}
fn test02(f: fn() -> i32) -> i32 {
test01(f)
} It turns out it's "working" thanks to this (unsound) hack
|
Reopening to make sure we actually fix the issue described in #808 re: |
btw the hack is only unsound once we allow refinements on fnptrs, yes? |
The hack is unsound if:
So yes, it's not unsound for fn ptrs unless we allow refinements on them because 2. doesn't apply here. |
indeed the above don't trigger the ICE... probably should fix at the same time as #803 |
The original issue from #808 still appears to fail: #[flux_rs::trusted]
pub fn get_filter_map(
) -> core::iter::FilterMap<core::slice::Iter<'static, Option<()>>, fn(&Option<()>) -> Option<()>> {
unimplemented!()
}
fn use_filter_map() {
let found = get_filter_map().find(|_| true);
} This errs with:
Do we have a solution for this? |
@nilehmann pub trait MyTrait {}
pub type Handle = &'static dyn MyTrait;
pub fn filter_handles(
slice: &'static [Option<Handle>],
) -> core::iter::FilterMap<
core::slice::Iter<'static, Option<Handle>>,
fn(&Option<Handle>) -> Option<Handle>>
{
slice.iter().filter_map(|&x| x)
} which fails with the error:
It looks like there is just a lifetime parameter that needs to be erased to make them match, but idk. |
I'll take a look. I think the assert is just being overly cautious. |
(Creating a separate issue from #808 FTR)
@ranjitjhala This is a bit tricky. When we normalize
<MyType<...> as MyTrait<...>>::Assoc
we get back an impl of the formWhere
T1,...,Tn
are used as args forTrait
andType
. To proceed with the normalization we need to find a substitution for theT1,...,Tn
based on the refinements we have. For example, if we haveAnd we are trying to normalize
<MyType<Nat> as MyTrait>::Assoc
we get the substitutionT -> Nat
by matchingMyType<Nat>
againstMyType<T>
. This step is important because with this substitution we can infer that<MyType<Nat> as MyTrait>::Assoc
normalizes toNat
.Now, the implementation of
Iterator
forFilterMap
looks like:The
B
is not used inIterator
or inFilterMap<I, F>
so we can't find a substitution for it when doing the matching. TheB
appears to be unconstrained but it's actually constrained by the boundF: FnMut(I::Item) -> Option<B>
. This bounds desugars to the boundsThe second equality bound is constraining
B
Originally posted by @nilehmann in #808 (comment)
The text was updated successfully, but these errors were encountered: