Repository navigation
No associated item found when the associated item was used as const generic parameter in return type #99705
Copy link
Copy link
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`
Description
Activity
I did some digging and this might be related to
rust/compiler/rustc_typeck/src/collect.rs
Lines 2468 to 2480 in e33cc71
// In `generics_of` we set the generics' parent to be our parent's parent which means that // we lose out on the predicates of our actual parent if we dont return those predicates here. // (See comment in `generics_of` for more information on why the parent shenanigans is necessary) // // struct Foo<T, const N: usize = { <T as Trait>::ASSOC }>(T) where T: Trait; // ^^^ ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling // ^^^ explicit_predicates_of on // parent item we dont have set as the // parent of generics returned by `generics_of` // // In the above code we want the anon const to have predicates in its param env for `T: Trait` let item_def_id = tcx.hir().get_parent_item(hir_id); // In the above code example we would be calling `explicit_predicates_of(Foo)` here rust/compiler/rustc_typeck/src/collect.rs
Lines 2158 to 2169 in e33cc71
// We don't inherit predicates from the parent here: // If we have, say `fn f<'a, T: 'a>() -> impl Sized {}` // then the return type is `f::<'static, T>::{{opaque}}`. // // If we inherited the predicates of `f` then we would // require that `T: 'static` to show that the return // type is well-formed. // // The only way to have something with this opaque type // is from the return type of the containing function, // which will ensure that the function's predicates // hold. @BoxyUwU Mind taking a look?
- addedF-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)
on Jul 27, 2022 A fix exists here at #99801 but we're waiting on @spastorino 's pending RPIT refactor work to fix this. In the mean time, developers who need this feature can use the branch in #99801.
https://rust-lang.github.io/rustup/concepts/toolchains.html#custom-toolchains
- added a commit that references this issue
on Nov 2, 2022
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`
I tried this code:
This code should compile normally.
Instead, this happened:
In the
testfunction, T was already bounded by theFootrait which does have an associated item namedABC. However, Rust complains that no associated item namedABCwas found forT.Meta
rustc --version --verbose: