Fix E0191 suggestion for empty dyn trait args#155637
Open
qaijuang wants to merge 2 commits intorust-lang:mainfrom
Open
Fix E0191 suggestion for empty dyn trait args#155637qaijuang wants to merge 2 commits intorust-lang:mainfrom
qaijuang wants to merge 2 commits intorust-lang:mainfrom
Conversation
Collaborator
|
HIR ty lowering was modified cc @fmease |
Collaborator
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Kivooeo
reviewed
Apr 22, 2026
Comment on lines
1118
to
1126
| let code = if let Some(snippet) = snippet.strip_suffix('>') { | ||
| // Don't insert a leading comma for empty generic args like `dyn Trait<>`. | ||
| let separator = if snippet.trim_end().ends_with('<') { "" } else { ", " }; | ||
| // The user wrote `Trait<'a>` or similar and we don't have a term we can suggest, | ||
| // but at least we can clue them to the correct syntax `Trait<'a, Item = /* ... */>` | ||
| // while accounting for the `<'a>` in the suggestion. | ||
| format!("{}, {}>", snippet, bindings.join(", ")) | ||
| format!("{snippet}{separator}{}>", bindings.join(", ")) | ||
| } else if in_expr_or_pat { | ||
| // The user wrote `Trait`, so we don't have a term we can suggest, but at least we |
Member
There was a problem hiding this comment.
Suggested change
| let code = if let Some(snippet) = snippet.strip_suffix('>') { | |
| // Don't insert a leading comma for empty generic args like `dyn Trait<>`. | |
| let separator = if snippet.trim_end().ends_with('<') { "" } else { ", " }; | |
| // The user wrote `Trait<'a>` or similar and we don't have a term we can suggest, | |
| // but at least we can clue them to the correct syntax `Trait<'a, Item = /* ... */>` | |
| // while accounting for the `<'a>` in the suggestion. | |
| format!("{}, {}>", snippet, bindings.join(", ")) | |
| format!("{snippet}{separator}{}>", bindings.join(", ")) | |
| } else if in_expr_or_pat { | |
| // The user wrote `Trait`, so we don't have a term we can suggest, but at least we | |
| let code = if let Some(snippet) = snippet.strip_suffix("<>") { | |
| // Empty generics | |
| format!("{snippet}<{}>", bindings.join(", ")) | |
| } else if let Some(snippet) = snippet.strip_suffix('>') { | |
| // Non-empty generics | |
| format!("{snippet}, {}>", bindings.join(", ")) | |
| } else if in_expr_or_pat { | |
| // ... | |
| }; |
Here is prototype that I haven't tested, but, something like this should be easier to read and follow
fmease
reviewed
Apr 22, 2026
Member
There was a problem hiding this comment.
Could you please look for an existing test file that exercises this diagnostic and add the test case there? Of course, you should keep the reference to the GH issue in a comment above it.
This is super niche and doesn't warrant its own file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #155578.