Closed
Description
I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=5638c99e5d0c0c6af0b5fd8773cefffb
#![feature(const_generics)]
trait GetType<const N:&'static str>{
type Ty;
fn get(&self)->&Self::Ty;
}
fn get_val<T>(value:&T)->&T::Ty
where
T: GetType<"hello">,
{
value.get()
}
I expected the code to compile successfully(like it did in previous nightly versions)
Instead, the code failed to compile with this error:
error[E0311]: the associated type `<T as GetType<"hello">>::Ty` may not live long enough
--> src/lib.rs:12:5
|
12 | value.get()
| ^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound for `<T as GetType<"hello">>::Ty`
note: the associated type `<T as GetType<"hello">>::Ty` must be valid for the anonymous lifetime #1 defined on the function body at 8:1...
--> src/lib.rs:8:1
|
8 | / fn get_val<T>(value:&T)->&T::Ty
9 | | where
10 | | T: GetType<"hello">,
11 | | {
12 | | value.get()
13 | | }
| |_^
Meta
Tried this on rustc 1.44.0-nightly (2020-04-24 3360cc3)
The way I work around this bug is to write the function like this:
fn get_val<T,R>(value:&T)->&R
where
T: GetType<"hello",Ty=R>,
{
value.get()
}
Metadata
Metadata
Assignees
Labels
Area: const generics (parameters and arguments)Area: Lifetimes / regionsCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(adt_const_params)]`Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.