-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tweak suggest_constraining_type_param
#70009
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr
Show resolved
Hide resolved
hir::Item { kind: hir::ItemKind::Struct(_, generics), .. } | ||
| hir::Item { kind: hir::ItemKind::Enum(_, generics), .. } | ||
| hir::Item { kind: hir::ItemKind::Union(_, generics), .. } | ||
| hir::Item { kind: hir::ItemKind::Trait(_, _, generics, ..), .. } | ||
| hir::Item { kind: hir::ItemKind::Impl { generics, .. }, .. } | ||
| hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. } | ||
| hir::Item { kind: hir::ItemKind::TyAlias(_, generics), .. } | ||
| hir::Item { kind: hir::ItemKind::TraitAlias(generics, _), .. } | ||
| hir::Item { | ||
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }), .. | ||
}, |
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.
nit: you can further simplify this by moving the or-pattern all the way into the kind:
field-pattern (same above).
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.
I tried that first but I got a syntax error so I assumed it wasn't possible.
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.
Huh, that shouldn't happen... Let's merge this without and I'll see what's up with this myself.
r=me with final nit addressed. :) |
@bors r=Centril |
📌 Commit 293cf51 has been approved by |
⌛ Testing commit 293cf51 with merge 1a69ea894186a265cbff1be75029e1e889a0bf5b... |
Tweak `suggest_constraining_type_param` Some of the bound restriction structured suggestions were incorrect while others had subpar output. The only issue left is a suggestion for an already present bound when dealing with `const`s that should be handled independently. Fix rust-lang#69983.
@bors retry |
Failed in #70481 (comment), @bors r- |
It seems like |
Some of the bound restriction structured suggestions were incorrect while others had subpar output.
@bors r=Centril |
📌 Commit 2c71894 has been approved by |
☀️ Test successful - checks-azure |
…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 ?
…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 ?
Some of the bound restriction structured suggestions were incorrect while others had subpar output.
The only issue left is a suggestion for an already present bound when dealing with
const
s that should be handled independently.Fix #69983.