-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
allow concrete self types in consts #76195
Conversation
This comment has been minimized.
This comment has been minimized.
/// The `bool` indicates if this constant may reference generic parameters | ||
/// and is used to only allow generic parameters to be used in trivial constant expressions. | ||
ConstantItemRibKind(bool), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be a new enum
, but it is great you added docs to it.
compiler/rustc_resolve/src/lib.rs
Outdated
if self.session.features_untracked().min_const_generics { | ||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`. | ||
if !trivial { | ||
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant | ||
// we can't easily tell if it's generic at this stage, so we instead remember | ||
// this and then enforce the self type to be concrete later on. | ||
if let Res::SelfTy(trait_def, Some((impl_def, _))) = res { | ||
res = Res::SelfTy(trait_def, Some((impl_def, true))); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of this @petrochenkov?
It seems sketchy as hell, but likely "correct", and being gated behing min_const_generics
I am inclined at allowing as is.
8271d7c
to
c71f90e
Compare
✔️ review |
I'm going to approve: if @petrochenkov has any comments later, we can address them in a follow up. @bors r+ |
📌 Commit f32593b5d5693d11c582240cf14ada7bb06201aa has been approved by |
⌛ Testing commit f32593b5d5693d11c582240cf14ada7bb06201aa with merge b40adb3fedaabc8291fcc5a429b101336bf2ed5f... |
💔 Test failed - checks-actions |
blessed new tests @bors r=varkor |
📌 Commit 90dd798 has been approved by |
☀️ Test successful - checks-actions, checks-azure |
This is quite a bad hack to fix #75486. There might be a better way to check if the self type depends on generic parameters, but I wasn't able to come up with one.
r? @varkor cc @petrochenkov