Skip to content

Conversation

@HuaGu-Dragon
Copy link

@HuaGu-Dragon HuaGu-Dragon commented Dec 24, 2025

Close: #21312

Release Note:

  • Fix: Complete methods on all numeric types for unsuffixed numeric literals

This PR fixes method completion for unsuffixed numeric literals (like 23. and 2.0.) to show methods from all applicable numeric types, not just the default inferred type.

Problem

Previously:

  • 23. only showed methods from i32 (not i64, u64, etc.)
  • 2.0. only showed methods from f64 (not f32, f16, etc.)

This made #21312 occured.

Solution

Now checks methods on ALL applicable types:

  • Integer literals (23.): Checks all integer types (i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize)
  • Float literals (2.0.): Checks all float types (f16, f32, f64, f128)
  • Proper deduplication: Uses FxHashSet<Function> to ensure each method appears only once

Changes

  1. crates/hir/src/lib.rs : Added constructor methods for all numeric builtin types
  2. crates/ide-completion/src/completions/dot.rs : Enhanced completion logic with deduplication
  3. crates/ide-completion/src/tests/expression.rs : Added comprehensive tests

Example

Before:

trait MyTrait { fn my_method(&self) {} }
impl MyTrait for i64 {}

fn main() {
    23.my_method();  // ❌ No completion
}

After:

trait MyTrait { fn my_method(&self) {} }
impl MyTrait for i64 {}

fn main() {
    23.my_method();  // ✅ my_method() now available!
}

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.

Copilot AI review requested due to automatic review settings December 24, 2025 13:53
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2025
Copy link

Copilot AI left a 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 FxHashSet to 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.

@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Dec 24, 2025

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2025
@HuaGu-Dragon
Copy link
Author

Please note that we require disclosure when using AI tools to author a PR.

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.

@HuaGu-Dragon
Copy link
Author

@ChayimFriedman2 Thanks for the reminder and sorry for missing the disclosure earlier.

What I changed

  • Added an explicit AI-tools disclosure to the PR description
  • Fixed the issue AI mentioned and ran the tests locally.

I have reopened the PR — please let me know if anything else is needed.

@HuaGu-Dragon HuaGu-Dragon reopened this Dec 24, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2025
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a 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.

@HuaGu-Dragon
Copy link
Author

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 abs() entries), I'm using:

  • Inherent methods: Only from f64
  • Trait methods: All float types with FxHashSet

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 26, 2025
HuaGu-Dragon and others added 9 commits December 26, 2025 18:50
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
@rustbot rustbot removed has-merge-commits S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot complete f32 methods on unsuffixed float

3 participants