-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix: Complete methods on all unsuffixed numeric literals #21329
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR fixes method completion for unsuffixed numeric literals to show methods from all applicable numeric types rather than just the default inferred type.
- Adds constructor methods for all numeric builtin types (i8-i128, u8-u128, f16-f128) in HIR
- Enhances dot completion logic to check methods across all integer types for integer literals (e.g.,
23.) and all float types for float literals (e.g.,2.0.) - Implements deduplication using
FxHashSetto prevent duplicate method suggestions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/hir/src/lib.rs | Adds constructor methods for all numeric builtin types (i8, i16, i64, i128, isize, u8, u16, u32, u64, u128, usize, f16, f32, f64, f128) |
| crates/ide-completion/src/completions/dot.rs | Implements multi-type method completion for unsuffixed numeric literals with deduplication logic |
| crates/ide-completion/src/tests/expression.rs | Adds test cases for integer and float literal method completion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Thanks for the reminder — sorry, I missed the disclosure requirement. I’ll add the required AI‑tools disclosure, fix the issue it just mentioned , and reopen the PR shortly. |
|
@ChayimFriedman2 Thanks for the reminder and sorry for missing the disclosure earlier. What I changed
I have reopened the PR — please let me know if anything else is needed. |
ChayimFriedman2
left a comment
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.
Definitely don't enumerate methods for all types. That'll lead to a lot of effectively duplicated methods. Choose one type - probably f64. Look at how this is implemented for unsuffixed integers.
Got it, Thanks for the feedback! I'm enumerating all numeric types to discover traits implemented only on non-default types (e.g., a trait only on f32, not f64) - these would actually compile due to type inference but would be missed if we only check f64. To avoid duplicate inherent methods (multiple
|
This comment has been minimized.
This comment has been minimized.
Fixed method completion for unsuffixed numeric literals to show methods from all applicable types, not just the default inferred type.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use FieldKind in DotAccessKind, replace the boolean receiver_is_ambiguous_float_literal with a FieldKind enum
016bdf4 to
d5f9ced
Compare
Close: #21312
Release Note:
This PR fixes method completion for unsuffixed numeric literals (like
23.and2.0.) to show methods from all applicable numeric types, not just the default inferred type.Problem
Previously:
23.only showed methods fromi32(noti64,u64, etc.)2.0.only showed methods fromf64(notf32,f16, etc.)This made #21312 occured.
Solution
Now checks methods on ALL applicable types:
23.): Checks all integer types (i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize)2.0.): Checks all float types (f16, f32, f64, f128)FxHashSet<Function>to ensure each method appears only onceChanges
crates/hir/src/lib.rs: Added constructor methods for all numeric builtin typescrates/ide-completion/src/completions/dot.rs: Enhanced completion logic with deduplicationcrates/ide-completion/src/tests/expression.rs: Added comprehensive testsExample
Before:
After:
Usage of AI tools
I implemented the logic and wrote the code.
I used AI only to brainstorm ideas , propose variable/struct names, and draft inline comments.
I manually reviewed and edited every AI suggestion before committing. No code was blindly accepted from the tool.