-
Notifications
You must be signed in to change notification settings - Fork 1.7k
const eval / trait deduction issues in nalgebra #11803
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 managed to make an nalgebra-free repro: pub struct Const<const R: usize>;
impl Const<3> {
pub fn foo(self) -> Const<2> { panic!() }
}
impl Const<4> {
pub fn foo(self) -> Const<3> { panic!() }
}
struct Foo;
impl std::ops::Mul<Foo> for Const<3> {
type Output = Foo;
fn mul(self, _: Foo) -> Self::Output { Foo }
}
const FOUR: usize = 4;
fn test(c: Const<{ FOUR }>) -> Foo {
let pt = c.foo();
let foo = pt * Foo;
foo
} The fact that |
Well, my conclusion from this would actually be that it's a different root cause 😅 We'll see. |
There is literaly no const eval in const generics yet, so |
Considering that rust-analyzer already has |
Yes, in general it'd be good to avoid showing these kinds of "follow-up" errors. And we should detect ambiguous method resolutions instead of just choosing the first one. |
@digama0 Btw, Is the original issue solved with the latest commit in nalgebra? |
Yes, the code example at the top works with that commit, as well as the real world example it was distilled from. So if you like you can close this issue, although of course the root cause is not fixed yet (but the linked issues could also be used to track that). |
Yes, let's close this then. |
The
nalgebra
crate has some nasty types that give rust-analyzer a hell of a time. I will try to make an example which does not depend on it, but for now here is a simple example depending onnalgebra 0.30.1
:rustc can compile this just fine, but r-a gets confused and infers the types wrong, leading to an unresolved type at the end that causes a type error. Here are the types as resolved by rustc:
and here are the types as resolved by rust-analyzer:
From what I can tell by commenting lines out:
mat
is inferred to&Matrix<f32, Const<_>, Const<_>, ArrayStorage<f32, 4, 4>>
. It is possible to resolve those numbers to4
at this point, but perhaps it is not evaluating them because there is no need to at the moment.zero
line on its own is of course unresolved, it requires the line after it.pt
line, the issue is that there are two impls oftransform_point()
, which look like this:mat
has type&Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 4, 4>>
(which is kind of nonsense but not ill formed).mat
line then constructs a fully 3x3 matrix, presumably because of the type and const arguments onappend_translation
.Foo
.rust-analyzer version: c2ea378 2022-03-23 nightly
rustc version: rustc 1.59.0 (9d1b2106e 2022-02-23)
The text was updated successfully, but these errors were encountered: