Skip to content
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

Fix span when suggesting to add an associated type bound #87348

Merged
merged 2 commits into from
Jul 24, 2021

Conversation

SkiFire13
Copy link
Contributor

@SkiFire13 SkiFire13 commented Jul 21, 2021

Fixes #87261

Note that this fix is not perfect, it will still give incorrect won't give suggestions in some situations:

  • If the associated type is defined on a supertrait of those contained in the opaque type, it will fallback to the previous behaviour, e.g. if AssocTy is defined on the trait Foo, Bar has Foo as supertrait and the opaque type is a impl Bar + Baz.
  • If the the associated type is defined on a generic trait and the opaque type includes two versions of that generic trait, e.g. the opaque type is impl Foo<A> + Foo<B>

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2021
@oli-obk oli-obk assigned oli-obk and unassigned michaelwoerister Jul 22, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Jul 22, 2021

Please add tests for the two issues you described

@oli-obk oli-obk added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Jul 22, 2021
@SkiFire13
Copy link
Contributor Author

Please add tests for the two issues you described

Should I add tests for them even if they currently produce the wrong output? Or should I make them not suggest anything and test that?

@oli-obk
Copy link
Contributor

oli-obk commented Jul 22, 2021

Or should I make them not suggest anything and test that?

Either is fine. We often test wrong output and add comments to the test stating that this is wrong and should be fixed.

@SkiFire13
Copy link
Contributor Author

  • If the code can't find the right trait to which add the bound it no longer emits a suggestion, instead it just emits the help message on the whole opaque type span
  • I've added some logic to handle cases like impl SubTrait or impl SubTrait + 'lt which weren't covered before but I think are common enough it would be unfortunate to lose the correct suggestion on them.

@SkiFire13
Copy link
Contributor Author

Digging around I think I've found a similar issue with generic bounds playground. The existing logic for them is a bit smarter than the one for opaque types, however it still fails when there are multiple generics. I'm tempted to include a fix for that issue in this PR and merge the logic.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 22, 2021

I'm tempted to include a fix for that issue in this PR and merge the logic.

Whatever you prefer. We can also merge this right now and you can build a new PR on top of it

@SkiFire13 SkiFire13 changed the title Fix span when suggesting to add an associated type bound to an opaque type Fix span when suggesting to add an associated type bound Jul 22, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Jul 23, 2021

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jul 23, 2021

📌 Commit d1bc941 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 24, 2021
Fix span when suggesting to add an associated type bound

Fixes rust-lang#87261

Note that this fix is not perfect, it ~~will still give incorrect~~ won't give suggestions in some situations:
- If the associated type is defined on a supertrait of those contained in the opaque type, it will fallback to the previous behaviour, e.g. if `AssocTy` is defined on the trait `Foo`, `Bar` has `Foo` as supertrait and the opaque type is a `impl Bar + Baz`.
- If the the associated type is defined on a generic trait and the opaque type includes two versions of that generic trait, e.g. the opaque type is `impl Foo<A> + Foo<B>`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 24, 2021
…arth

Rollup of 9 pull requests

Successful merges:

 - rust-lang#87348 (Fix span when suggesting to add an associated type bound)
 - rust-lang#87359 (Remove detection of rustup and cargo in 'missing extern crate' diagnostics)
 - rust-lang#87370 (Add support for powerpc-unknown-freebsd)
 - rust-lang#87389 (Rename `known_attrs` to `expanded_inert_attrs` and move to rustc_expand)
 - rust-lang#87395 (Clear up std::env::set_var panic section.)
 - rust-lang#87403 (Implement `AssignToDroppingUnionField` in THIR unsafeck)
 - rust-lang#87410 (Mark `format_args_nl` as `#[doc(hidden)]`)
 - rust-lang#87419 (IEEE 754 is not an RFC)
 - rust-lang#87422 (DOC: remove unnecessary feature crate attribute from example code)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e4d8f0e into rust-lang:master Jul 24, 2021
@rustbot rustbot added this to the 1.56.0 milestone Jul 24, 2021
@SkiFire13 SkiFire13 deleted the fix-87261 branch July 24, 2021 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect suggestion when trying to implement Trait<Associated = ()> with impl Trait + 'static
6 participants