You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compiler can't infer const parameter from infallible array pattern #70529
changed the title [-]Compiler can't infer size const parameter from array infallible pattern[/-][+]Compiler can't infer const parameter from infallible array pattern[/+]on Mar 29, 2020
To solve this, I suspect we'd need to register an obligation CheckArrayPatLen { has_slice: bool, min_len: u64 } which is the information required to check what check_array_pat_len does and then connect this to a const inference variable. Later on, we'll do the checks which were in check_array_pat_len when dealing with the obligation.
What if we just handle the case in which they have to be equal, for now? Because that needs no obligation, you can just unify the constant with the length.
And you'd get a proper mismatch error if the length is not an inference variable.
Yeah, scratch what I said. We can tweak the branch here:
}else{// No idea what the length is, which happens if we have e.g.,// `let [a, b] = arr` where `arr: [T; N]` where `const N: usize`.self.error_scrutinee_unfixed_length(span);}
and as you say, unify the constant with the known length.
Activity
[-]Compiler can't infer size const parameter from array infallible pattern[/-][+]Compiler can't infer const parameter from infallible array pattern[/+]Centril commentedon Mar 29, 2020
Simplified:
Centril commentedon Mar 29, 2020
The relevant code is defined here:
rust/src/librustc_typeck/check/pat.rs
Lines 1360 to 1366 in 8045865
rust/src/librustc_typeck/check/pat.rs
Lines 1396 to 1427 in 8045865
rust/src/librustc_typeck/check/pat.rs
Lines 1460 to 1468 in 8045865
Centril commentedon Mar 29, 2020
To solve this, I suspect we'd need to register an obligation
CheckArrayPatLen { has_slice: bool, min_len: u64 }which is the information required to check whatcheck_array_pat_lendoes and then connect this to a const inference variable. Later on, we'll do the checks which were incheck_array_pat_lenwhen dealing with the obligation.cc @varkor @eddyb
eddyb commentedon Mar 29, 2020
What if we just handle the case in which they have to be equal, for now? Because that needs no obligation, you can just unify the constant with the length.
And you'd get a proper mismatch error if the length is not an inference variable.
Centril commentedon Mar 29, 2020
Yeah, scratch what I said. We can tweak the branch here:
and as you say, unify the constant with the known length.
lcnr commentedon Mar 30, 2020
@rustbot claim
Rollup merge of rust-lang#70562 - lcnr:const-arr_len, r=Centril
Rollup merge of rust-lang#70562 - lcnr:const-arr_len, r=Centril
Rollup merge of rust-lang#70562 - lcnr:const-arr_len, r=Centril