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.
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.
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.
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