-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
return const array from impl function, loses const information #67144
Comments
@varkor I saw in #44580 (comment) that you would be able to help/mentor const_generics issues I would like to give this issue a go, but have no idea where to start. Maybe you could give me some pointers? |
This is a slightly more minimal reproduction: #![feature(const_generics)]
struct A<const N: usize>;
struct X;
impl X {
fn inner<const N: usize>() -> A<N> {
outer::<N>()
}
}
fn outer<const N: usize>() -> A<N> {
A
}
fn main() {
let i: A<3usize> = outer::<3usize>(); // ok
let o: A<3usize> = X::inner::<3usize>(); // error
} @robinvd: This is quite a surprising error to me: I don't have any immediate guesses as to what might be going on. We'll need to do a little investigation here. The error in the example above is:
Clearly, these should unify, so the first step would be to work out why unification doesn't think they're the same value. Hopefully that'll give some clues. The main thing that's different about trait functions is that they have an extra (hidden) generic parameter, which is the |
The reason the values don't unify is because we hit this: rust/src/librustc/ty/relate.rs Line 578 in 760ce94
where we have (something like)
For some reason, it's unable to evaluate one of the constants. |
The issue is that in rust/src/librustc_typeck/collect.rs Lines 1429 to 1432 in 760ce94
we only consider QPath::Resolved . We also need to handle QPath::TypeRelative , which occurs whenever we have a path A::B (like in X::inner ).
|
I've done some refactoring to make the method a little clearer. The bit that needs fixing now is: |
slightly unrelated. I tried some things yesterday, but my edit/compile cycle was 9 minutes with |
It does take a little while to compile rustc, yes. I'm using the suggestion options in the rustc guide and it takes 3 – 4 minutes on my computer after making changes in |
will probably get fixed by #71154 |
const generics triage I went through all const generics issues and closed all issues which are already fixed. Some issues already have a regression test but were not closed. Also doing this as part of this PR. uff r? @eddyb @varkor closes rust-lang#61936 closes rust-lang#62878 closes rust-lang#63695 closes rust-lang#67144 closes rust-lang#68596 closes rust-lang#69816 closes rust-lang#70217 closes rust-lang#70507 closes rust-lang#70586 closes rust-lang#71348 closes rust-lang#71805 closes rust-lang#73120 closes rust-lang#73508 closes rust-lang#73730 closes rust-lang#74255
When returning an const length array from an associated function the length is lost and it becomes a [T; _] array.
I tried this code:
(Playground)
I expected to see this happen:
all lines in test compile
Instead, this happened:
functions from the impl did not return a const array
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: