fix syntax error in suggesting generic constraint in trait parameter#76695
Merged
bors merged 2 commits intorust-lang:masterfrom Sep 16, 2020
Merged
fix syntax error in suggesting generic constraint in trait parameter#76695bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
Contributor
|
r? @oli-obk (rust_highfive has picked a reviewer for you, use r? to override) |
suggest `where T: Foo` for the first bound on a trait, then suggest `, T: Foo` when the suggested bound would add to an existing set of `where` clauses. `where T: Foo` may be the first bound if `T` has a default, because we'd rather suggest ``` trait A<T=()> where T: Copy ``` than ``` trait A<T: Copy=()> ``` for legibility reasons.
dcd571c to
0eac38b
Compare
estebank
approved these changes
Sep 14, 2020
Contributor
estebank
left a comment
There was a problem hiding this comment.
Minor wording changes to comments, otherwise r=me!
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Contributor
Author
|
Good catches! tweaks applied. |
Contributor
Collaborator
|
📌 Commit e1607c8 has been approved by |
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this pull request
Sep 16, 2020
…ion, r=estebank fix syntax error in suggesting generic constraint in trait parameter suggest `where T: Foo` for the first bound on a trait, then suggest `, T: Foo` when the suggested bound would add to an existing set of `where` clauses. `where T: Foo` may be the first bound if `T` has a default, because we'd rather suggest ``` trait A<T=()> where T: Copy ``` than ``` trait A<T: Copy=()> ``` for legibility reasons. the test case i added here is derived from [this reproduction](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0bf3ace9f2a183d0bdbd748c6b8e3971): ``` struct B<T: Copy> { t: T } trait A<T = ()> { fn returns_constrained_type(&self, t: T) -> B<T> { B { t } } } ``` where the suggested fix, ``` trait A<T = ()>, T: Copy { ... } ``` is in fact invalid syntax! i also found an error in the existing suggestion for `trait Base<T = String>: Super<T>` where rustc would suggest `trait Base<T = String>: Super<T>, T: Copy`, but `T: Copy` is the first of the trait's `where` clauses and should be `where T: Copy` as well. the test for that suggestion expects invalid syntax, and has been revised to a compiler-pleasing `trait Base<T = String>: Super<T> where T: Copy`. judging by rust-lang#70009 i'll.. cc @estebank ?
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 16, 2020
Rollup of 10 pull requests Successful merges: - rust-lang#76669 (Prefer asm! over llvm_asm! in core) - rust-lang#76675 (Small improvements to asm documentation) - rust-lang#76681 (remove orphaned files) - rust-lang#76694 (Introduce a PartitioningCx struct) - rust-lang#76695 (fix syntax error in suggesting generic constraint in trait parameter) - rust-lang#76699 (improve const infer error) - rust-lang#76707 (Simplify iter flatten struct doc) - rust-lang#76710 (:arrow_up: rust-analyzer) - rust-lang#76714 (Small docs improvements) - rust-lang#76717 (Fix generating rustc docs with non-default lib directory.) Failed merges: r? `@ghost`
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.
suggest
where T: Foofor the first bound on a trait, then suggest, T: Foowhen the suggested bound would add to an existing set ofwhereclauses.where T: Foomay be the first bound ifThas adefault, because we'd rather suggest
than
for legibility reasons.
the test case i added here is derived from this reproduction:
where the suggested fix,
is in fact invalid syntax!
i also found an error in the existing suggestion for
trait Base<T = String>: Super<T>where rustc would suggesttrait Base<T = String>: Super<T>, T: Copy, butT: Copyis the first of the trait'swhereclauses and should bewhere T: Copyas well. the test for that suggestion expects invalid syntax, and has been revised to a compiler-pleasingtrait Base<T = String>: Super<T> where T: Copy.judging by #70009 i'll.. cc @estebank ?