-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect add bounds suggestion when given type parameter like <T:>
#95898
Comments
@rustbot claim |
You mean that |
Correct, the suggestion reads |
It's my first time contributing and i was taking a look at So i ended up adding a flag to Does that seem reasonable? |
Adding a new flag to Also hmm... I think @WaffleLapkin was also looking at trying to solve this... I opened up this issue before he said that he was trying to fix this issue, though I'm not sure if in general or just a specific case in something he was working on (i.e. another suggestion). Perhaps he could comment to see if he's already solved this, in order to deduplicate work? |
So. I was fixing the same problem in My solution is to use It seems like my fix doesn't fix this issue, because this suggestion is created using different API ( I'll try to clean my fix & create a PR today. |
…s, r=compiler-errors Fix suggestions in case of `T:` bounds This PR fixes a corner case in `suggest_constraining_type_params` that was causing incorrect suggestions. For the following functions: ```rust fn a<T:>(t: T) { [t, t]; } fn b<T>(t: T) where T: { [t, t]; } ``` We previously suggested the following: ```text ... help: consider restricting type parameter `T` | 1 | fn a<T: Copy:>(t: T) { [t, t]; } | ++++++ ... help: consider further restricting this bound | 2 | fn b<T>(t: T) where T: + Copy { [t, t]; } | ++++++ ``` Note that neither `T: Copy:` not `where T: + Copy` is a correct bound. With this commit the suggestions are correct: ```text ... help: consider restricting type parameter `T` | 1 | fn a<T: Copy>(t: T) { [t, t]; } | ++++ ... help: consider further restricting this bound | 2 | fn b<T>(t: T) where T: Copy { [t, t]; } | ++++ ``` r? `@compiler-errors` I've tried fixing rust-lang#95898 here too, but got too confused with how `suggest_traits_to_import` works and what it does 😅
I took a look at your PR, that's way better than my solution. I will use the method you added to |
Given the following code:
The current output is:
Ideally the output should look like:
Note: The
T:
bound is treated incorrectly.The text was updated successfully, but these errors were encountered: