-
Notifications
You must be signed in to change notification settings - Fork 46
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
Exp
and Shleft
with constant left side fail.
#75
Comments
This should work fine ... I'll look into it. Any chance you could post a longer snippet so I can see exactly what you're doing? |
I have verified that this println!("{}", <Exp<U2, U10> as Unsigned>::to_u32()); works fine, so I'll definitely need to see how you're using it to be able to help. |
I am trying to do something like this:
but the same problem happens with functions:
Error it gives: http://pastebin.com/UpsHSWSV |
Ah, this is the case of a poor compiler message. What is happening is that you can do what you want, but the compiler doesn't know that, and it's freaking out instead of informing you. While struct Struct<N: Unsigned> where U2: Pow<N>, Exp<U2, N>: ArrayLength<f64> {
data: GenericArray<f64, Exp<U2, N>>
} or fn function<N: Unsigned>() -> u64 where U1: Shl<N>, Shleft<U1, N>: Unsigned {
<Shleft<U1, N> as Unsigned>::to_u64()
} If you were to change exponentiation to, say, multiplication, then you get a much more sane error message:
|
Ahh... That was it. I was trying all sorts of bounds, but didn't realise you could give bounds like that to concrete types. After getting that fixed I tried to create constructor for my type like this:
and encountered the same problem... Is there any plans for creating some kind of tutorial for resolving these kinds of problems? I would think that encountering these without any help would hugely discoure people from using And is there issue in rust-lang/rust to make those errors better? |
I haven't had any, but that's a great idea. I'm just not sure when I'd be able to get around to it.
None that I'm aware of. I've been wanting to submit an issue (although I haven't searched yet so one may exist), but I'd want to spend some time and get a minimal example first. You are, of course, welcome to submit one---if you do, I'd love a link to it here. As for you constructor issue, I'm not really sure what's going on, but it's almost certainly related to the error messages. I've tried to play with it a bit, but didn't get it to work. I may try more later. Typenum pushes Rust's type system to its limits, and sometimes it gets grumpy about it. Often, I've managed to solve similar issues with trivial-seeming refactoring. Basically a lot of "maybe if I do it this way it'll work", and, at some point, it finally does. You may be interested in #61, as @mkeeter seems to be doing something similar, and might have solved the constructor issue. |
Actually just trying to create the struct fails: |
Welp... I tried to reduce the code and got to this point:
which fails with:
Which makes literally no sense to me.... Edit(1): Edit(2): I reduced the original reduction from:
just before submitting it Edit(3): For function that creates |
I experimented with this a little more.
works for faking constructor, but for methods this doesn't work. And it's still bit strange as if you try to call it like If I move the bounds to the impl, it breaks. |
Some longstanding bugs have been fixed as of Rust 1.17.0 (the current beta), and at least some of your issues have been fixed. Your function Anyway, I'd invite you to revisit this using beta or nightly, and let me know if you're still having issues. |
I got this working: struct Test<N: Unsigned>(GenericArray<f64, <U2 as Pow<N>>::Output>)
where U2: Pow<N>,
<U2 as Pow<N>>::Output: ArrayLength<f64>;
fn from_slice<N: Unsigned>(data: &[f64]) -> Test<N>
where U2: Pow<N>,
<U2 as Pow<N>>::Output: ArrayLength<f64>,
{
Test::<N>(GenericArray::<f64, <U2 as Pow<N>>::Output>::from_slice(data))
}
fn doit() {
let test = from_slice::<U5>(&[
0.,
0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0.,
0.,
]);
} but if I try to make that impl<N: Unsigned> Test<N>
where U2: Pow<N>,
<U2 as Pow<N>>::Output: ArrayLength<f64>,
{
fn from_slice(data: &[f64]) -> Test<N> {
Test::<N>(GenericArray::<f64, <U2 as Pow<N>>::Output>::from_slice(data))
}
}
fn doit() {
let test = Test::<U5>::from_slice(&[
0.,
0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0.,
0.,
]);
} Atleast some progress :D |
I was curious and wanted to see if compiler improvements had fixed this. For the record, it's still broken. Using
I still get this error. Full example, modified to work with new generic-array, for easier future testing:
|
Still broken on |
I am trying to calculate 2.pow(n) for generic array size and failing misserably.
If I do
Exp<U2, N>
orShleft<U1, N>
, compilation fails from overflowing while trying figure out Sized bound.I have tried all kinds of bounds for N, but without success. Is this just not possible or am I missing some crucial thing?
The text was updated successfully, but these errors were encountered: