-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
ICE with const generics with explicit lifetime argument #60814
Comments
@rustbot modify labels: I-ICE C-Bug T-compiler A-const-generics |
Edit: it seems like the implementation of |
The current ICE is:
|
Shouldn't the code actually fail to compile? For example, this code is very similar and fails to compile: fn greet<'a>(name: &'a str) {
const HELLO: &'a str = "Hello";
println!("{} {}", HELLO, name);
}
The |
The nomenclature is a bit confusing, but |
Ok, thanks for the answer! I will dig into this today. See what I find. I'm curious however why there is this difference. Can I read up on that somewhere? What is a valid use case for non-static lifetimes in const generics? |
The difference is just due to the word "const" being reused for different things. Const variables are essentially just inlined, whereas const parameters are values that are are guaranteed to be constant, and known at compile time. In theory, I don't see why consts couldn't have non-static lifetimes in general. I don't know of a realistic example for non-static lifetimes in const generics either, but there's no technical reason they shouldn't work, so we should fix it :) |
This has been put in place to patch over an ICE caused when we encounter a non-static lifetime in a const generic during borrow checking. This restriction may be relaxed in the future, but we need more discussion before then, and in the meantime we should still deal with this ICE. Fixes issue rust-lang#60814
…akis disallow non-static lifetimes in const generics Disallow non-static lifetimes in const generics in order to to patch over an ICE caused when we encounter a non-static lifetime in a const generic during borrow checking. This restriction may be relaxed in the future, but we need more discussion before then, and in the meantime we should still deal with this ICE. Fixes issue rust-lang#60814
Fixed by #74051. |
This is a very slight modification of an example in #60813, but filing as a separate bug, since the error message is very different.
The following code
results in the following ICE:
Playground link
cc @Serentty
The text was updated successfully, but these errors were encountered: