-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Function parameter type resolution incorrect when multiple generics used #134387
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
Comments
I was able to shrink down the example to something closer to an mcve use std::ops::Index;
struct Reproducer {
pattern: &'static [u8],
bad_char_shift_map: Vec<u8>,
}
impl Reproducer {
pub fn find_first_in<'a, T, F>(&'a self, text: &'a T, e: F)
where
T: Index<usize, Output = u8> + ?Sized,
&'a T: IntoIterator<Item = &'a u8>,
<&'a T as IntoIterator>::IntoIter: Sized + DoubleEndedIterator + ExactSizeIterator,
F: Fn(u8, u8) -> Option<(u8, u8)>,
{
// This works
//find_spec::<T, [u8], F>(text, self.pattern, &self.bad_char_shift_map, 1, e)
find_spec(text, self.pattern, &self.bad_char_shift_map, 1, e)
}
}
pub fn find_spec<'a, TT: 'a, TP: 'a, F>(
_text: &'a TT,
_pattern: &'a TP,
_bad_char_shift_map: &Vec<u8>,
_limit: usize,
_e: F,
) where
TT: Index<usize, Output = u8> + ?Sized,
&'a TT: IntoIterator<Item = &'a u8>,
<&'a TT as IntoIterator>::IntoIter: Sized + DoubleEndedIterator + ExactSizeIterator,
TP: Index<usize, Output = u8> + ?Sized,
&'a TP: IntoIterator<Item = &'a u8>,
<&'a TP as IntoIterator>::IntoIter: Sized + DoubleEndedIterator + ExactSizeIterator,
F: Fn(u8, u8) -> Option<(u8, u8)>,
{
unimplemented!()
}
fn main() {} |
I think this is the smallest I can make it pub fn r0<'a, T>(p0: &'a T, p1: &'a [u8])
where
&'a T: IntoIterator<Item = &'a u8>,
{
// This works
//r1::<T, [u8]>(p0, p1)
r1(p0, p1)
}
pub fn r1<'a, TT: 'a, TP: 'a>(
_tt: &'a TT,
_tp: &'a TP,
) where
&'a TT: IntoIterator<Item = &'a u8>,
&'a TP: IntoIterator<Item = &'a u8>,
{
unimplemented!()
} The error is currently:
|
@jieyouxu is there anything else needed? |
Simpler. pub struct Wrap<T>(T);
pub trait MyTrait {}
impl MyTrait for Wrap<u8> {}
pub fn parent<T>(_a: T, b: u8)
where
Wrap<T>: MyTrait,
{
child(b)
// child::<u8>(b) // this compiles.
}
pub fn child<U>(b: U)
where
Wrap<U>: MyTrait,
{
unimplemented!()
} The cause is that the type parameter of I believe this is a duplicate of #134854. |
More fundamentally, the problem is that This is an old issue #24066. |
I tried this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9788298bae9b348de0833cd9b125c70e
I expected to see this happen:
Compiler correctly identifies the types used in the function
Instead, this happened:
This error is fixed if I explicitly set the function types
Meta
rustc --version --verbose
:This behavior also exists in Beta and Nightly.
The text was updated successfully, but these errors were encountered: