-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
the "add missing members" assists: implemented substitution of default values of const params #15179
the "add missing members" assists: implemented substitution of default values of const params #15179
Conversation
58fdf05
to
df7e701
Compare
☔ The latest upstream changes (presumably #15224) made this pull request unmergeable. Please resolve the merge conflicts. |
2665241
to
695c2d2
Compare
@@ -290,7 +290,7 @@ TypeParam = | |||
|
|||
ConstParam = | |||
Attr* 'const' Name ':' Type | |||
('=' default_val:Expr)? | |||
('=' default_val:ConstArg)? |
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.
by the way, while the parser is aware of the restrictions for ConstArg
, rust.ungram is not. not sure if it's worth fixing
47b3db1
to
5ce26e3
Compare
crates/hir-ty/src/lib.rs
Outdated
@@ -719,3 +721,16 @@ where | |||
value.visit_with(&mut collector, DebruijnIndex::INNERMOST); | |||
collector.placeholders.into_iter().collect() | |||
} | |||
|
|||
pub fn known_const_to_string(konst: &Const, db: &dyn HirDatabase) -> Option<String> { |
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.
I'm not sure where it would be better to place this function, nor how to name it. but it seems that it should be separated from the old display
function, as it treats unknown consts in a special way and "unfolds" complex expressions.
@HKalbasi Can you review the const lowering part? I'll review the rest. |
Sorry I missed the first mention. The const parts looks good to me. |
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.
I'm deeply sorry it took so long to review. The change generally looks awesome; I'm leaving some small suggestions.
One thing we could do (but does not block this PR; just dumping my thoughts before I forget. I'm not even sure if it's possible right now) is consteval const default expressions and substitute them rather than copy-pasting the default values from the definition. For example, given the following definitions mod m {
const fn foo() { 42 } // notice this is private to the module
pub trait Trait<const N: usize = { foo() }> { }
} we cannot substitute the default value for |
…t values of const params
…const param default values
8929e40
to
68e8379
Compare
@lowr well, I'm not sure if it's a good idea to consteval expressions with private, hm, components. it sounds to me like a cheaty way to make private function (or smth else) public. as a developer, I'd rather change visibility of the expression components - or become scared that the private values are used in an unexpected place |
I think keeping these unevaluated is better, since unevaluated consts are usually unevaluated for a reason. For example, we shouldn't replace |
Sorry for this taking so long. |
☀️ Test successful - checks-actions |
…neric-const, r=HKalbasi fix: start hovering default values of generic constants It's just a kind of a postscriptum for [my last PR](#15179) adding default values of const generics to `hir::ConstParamData`. Here I patch other pieces of code which used to ignore const default values and which I managed to find (you're welcome to show me more)
…neric-const, r=HKalbasi fix: start hovering default values of generic constants It's just a kind of a postscriptum for [my last PR](#15179) adding default values of const generics to `hir::ConstParamData`. Here I patch other pieces of code which used to ignore const default values and which I managed to find (you're welcome to show me more)
To achieve this, I've made
hir::ConstParamData
store the default values