Skip to content

Conversation

@chenyukang
Copy link
Member

@chenyukang chenyukang commented Oct 16, 2025

Fixes #147749

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 16, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

}

fn suggest_bounds_for_range_to_method(
&self,
Copy link
Member

@fmease fmease Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only suggest 0 if the element type is integral.

Right now, you suggest (0..'f').rev() for (..'f').rev(). This affects all types that implement the Step trait and aren't integral.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should it be 0 if the element is signed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's not good to suggest (0..-10), so I changed the code to only suggest 0 for integral and without negative sign, otherwise suggest a place hold _, not sure this is the best way, but I didn't come out with a better one.

it's complex to handle all scenario, for instance the code maybe (...val), while val is a negative value or some other types..

anyway, this is a MaybeIncorrect suggestion.

@petrochenkov
Copy link
Contributor

r? @fmease

@rustbot rustbot assigned fmease and unassigned petrochenkov Oct 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 16, 2025

fmease is currently at their maximum review capacity.
They may take a while to respond.

Comment on lines 48 to 50
|
LL | for _x in (_..'a').rev() {}
| +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still kinda sceptic about this underscore as suggetstion honestly

I wonder if it will be possible to get a type to make suggestion like here?

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=30592d851c5474c123063a64fc97b939

This one is kinda nice and very noticeable for users

Copy link
Member Author

@chenyukang chenyukang Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean like this?

for _x in (/* start */..'a').rev() {}
              +++++

seems better, but the */ followed by .. maybe looks confusing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked in discord some opinions, so... hopefully we will get little more points of view on this

Yeah, I mean this, hm, looks a bit confusing I agree, maybe space can help, what do you think?

for _x in ( /* start */ ..'a').rev() {}
              +++++

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK without the space, since I just realized it looks perfect in a terminal:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlight is doing great job here, but still, do you think it reasonable to suggest 0 for integers, for example above 0..4 is i32 afaik, so it should be i32::MIN

I'd suggest to do comment placeholder for all types, just for consistency and should make implementation easier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess starting from 0 is the most common scenario if the ending bound is an integer.
I am neutral on both choices here. Any thoughts on this? @fmease

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use 0 for integers cause I think that's probably what the user intended. At least that was the case for me. Non integer cases seem less likely to occur in the first place. I guess char::MIN makes sense for chars.

Copy link
Member

@Kivooeo Kivooeo Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes, I do agree that 0 is most common scenario so let's keep it as it

char::MIN is \0, so I'm not sure if it's what users really have meant, most likely it's just a or A (depends on case)

@chenyukang chenyukang force-pushed the yukang-147749 branch 2 times, most recently from f1795fa to 1a2f058 Compare October 17, 2025 15:19
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 22, 2025
…method-error, r=nnethercote

Code refactoring on hir report_no_match_method_error

While working on rust-lang#147753, I found `report_no_match_method_error` now is too long for maintain, 1200 lines of code now:
https://github.com/rust-lang/rust/blob/57ef8d642d21965304bde849bab4f389b4353e27/compiler/rustc_hir_typeck/src/method/suggest.rs#L589-L1736

this PR try to refactor it.

I tried my best to group most related code into same places, but the logic here is still very complex, there are some variables across different functions, maybe we need more work to make it better understand.

Maybe we could add a tidy check to avoid long spaghetti code.

r? `@nnethercote`
@rustbot
Copy link
Collaborator

rustbot commented Oct 22, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 23, 2025
…ror, r=nnethercote

Code refactoring on hir report_no_match_method_error

While working on rust-lang/rust#147753, I found `report_no_match_method_error` now is too long for maintain, 1200 lines of code now:
https://github.com/rust-lang/rust/blob/57ef8d642d21965304bde849bab4f389b4353e27/compiler/rustc_hir_typeck/src/method/suggest.rs#L589-L1736

this PR try to refactor it.

I tried my best to group most related code into same places, but the logic here is still very complex, there are some variables across different functions, maybe we need more work to make it better understand.

Maybe we could add a tidy check to avoid long spaghetti code.

r? `@nnethercote`
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add code suggestion for RangeTo is not an iterator

7 participants