- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Add a suggestion to replace parentheses with angle brackets on associated trait constraint #97656
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
Add a suggestion to replace parentheses with angle brackets on associated trait constraint #97656
Conversation
| Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. Please see the contribution instructions for more information. | 
| && snippet.ends_with(')') | ||
| && let Some(split) = snippet.find("(") { | ||
|  | ||
| let trait_name = &snippet[0..split]; | 
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.
This is not the trait name.  According to the parser, split is always 0.
|  | ||
| // Suggest removing empty parentheses: "Trait()" -> "Trait" | ||
| if data.inputs.is_empty() { | ||
| err.span_suggestion( | 
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.
Could you add a test for this case?
| gen_args.span(), | ||
| "parenthesized generic arguments cannot be used in associated type constraints", | ||
| ); | ||
| if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) | 
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.
Please avoid re-parsing the source code, you have all the required information in the spans.
The span of the ( is data.span.shrink_to_lo().to(data.inputs.first().unwrap().span().shrink_to_lo()).
Similarly computation for the span for ).
You can use a multipart suggestion to suggest replacing ( by < and ) by >, without touching to the args' code.
| Other nit: please avoid merge commits in your PR. In case of merge conflict, you can rebase your branch: https://rustc-dev-guide.rust-lang.org/git.html | 
5cbd004    to
    9598b4b      
    Compare
  
    | Thanks @EdwinRy! Could you squash the commits? I'll get them merged. | 
c80cd7c    to
    cd03fe1      
    Compare
  
    | @bors r+ rollup | 
| 📌 Commit cd03fe1 has been approved by  | 
…askrgr Rollup of 5 pull requests Successful merges: - rust-lang#97446 (Make hir().get_generics and generics_of consistent.) - rust-lang#97656 (Add a suggestion to replace parentheses with angle brackets on associated trait constraint) - rust-lang#97692 (Add `#T-types/nominated` zulip notification) - rust-lang#97696 (Do not ICE when failing to normalize during inlining.) - rust-lang#97702 (Remove useless LocalDefId in ImplTraitContext::Universal.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This implements a requested suggestion FIXME in
compiler/rustc_ast_lowering/src/lib.rsThe suggestion asks for the parentheses to either be replaced with angle brackets or removed completely depending on whether there are arguments provided within.
r? @oli-obk