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
const generic inference variables not properly tracked by traits/fulfill. #70180
#![feature(const_generics)]fnworks(){let array/*: [_; _]*/ = default_array();let _:[_;4] = array;Foo::foo(&array);}fndoesnt_work(){let array/*: [_; _]*/ = default_array();// ^ cannot infer type for type parameter `T` declared on the function `default_array`Foo::foo(&array);let _:[_;4] = array;}traitFoo{fnfoo(&self){}}implFoofor[i32;4]{}implFoofor[i64;8]{}// Only needed because `[_; _]` is not valid type syntax.fndefault_array<T,constN:usize>() -> [T;N]where[T;N]:Default,{Default::default()}
My understanding is that the error is caused by the [$T; $C]: Foo obligation being stalled_on on just $T (which means it's not retried when $C is unified with 4), whereas it should be stalled on both $T and $C so that it's retried when either changes.
Right now stalled_on is limited to type inference variables, so its representation will need to change, and Ty::walk will need to expose constants too.
I believe #70107 ran into this as well, but for WF obligations, not trait ones.
I'm self-assigning this because I'm working on the fix (as part of a larger effort).
Note to self: the PR fixing this should also test this example (playground):
#![feature(const_generics)]fnworks(){let array/*: [u8; _]*/ = default_byte_array();let _:[_;4] = array;Foo::foo(&array);}fndoesnt_work(){let array/*: [u8; _]*/ = default_byte_array();Foo::foo(&array);// ^ cannot infer type for type parameter `T` declared on the trait `Foo`let _:[_;4] = array;}traitFoo<T>{fnfoo(&self){}}implFoo<i32>for[u8;4]{}implFoo<i64>for[u8;8]{}// Only needed because `[u8; _]` is not valid type syntax.fndefault_byte_array<constN:usize>() -> [u8;N]where[u8;N]:Default,{Default::default()}
The reason for this is that this second example has the type and const inference variables in different generic args of Foo, meaning fixing it also requires changing this to has_infer_types_or_consts:
I've definitely noticed problems with inference involving consts before, but wasn't able to pin down where the issue was stemming from. It would be great if this could be addressed once and for all.
Activity
eddyb commentedon Mar 20, 2020
Note to self: the PR fixing this should also test this example (playground):
The reason for this is that this second example has the type and const inference variables in different generic args of
Foo, meaning fixing it also requires changing this tohas_infer_types_or_consts:rust/src/librustc_trait_selection/traits/fulfill.rs
Line 545 in f4c675c
varkor commentedon Mar 20, 2020
I've definitely noticed problems with inference involving consts before, but wasn't able to pin down where the issue was stemming from. It would be great if this could be addressed once and for all.
Rollup merge of rust-lang#70213 - eddyb:stalled-on-ty-or-const, r=nik…
Rollup merge of rust-lang#70213 - eddyb:stalled-on-ty-or-const, r=nik…
Rollup merge of rust-lang#70213 - eddyb:stalled-on-ty-or-const, r=nik…
Rollup merge of rust-lang#72061 - lcnr:const-inference-test, r=eddyb
Rollup merge of rust-lang#72061 - lcnr:const-inference-test, r=eddyb