Skip to content

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

Merged
bors merged 2 commits into
rust-lang:masterfrom
SkiFire13:fix-87261
Jul 24, 2021
Merged

Fix span when suggesting to add an associated type bound#87348
bors merged 2 commits into
rust-lang:masterfrom
SkiFire13:fix-87261

Conversation

@SkiFire13

@SkiFire13SkiFire13 commented Jul 21, 2021

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

r? @michaelwoerister

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

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2021
@oli-obk

Copy link
Copy Markdown
Contributor

Please add tests for the two issues you described

Comment threadcompiler/rustc_middle/src/ty/error.rs Outdated
@oli-obkoli-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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor
  • 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.

Comment threadsrc/test/ui/associated-types/issue-87261.stderr Outdated
@SkiFire13

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

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

@SkiFire13SkiFire13 changed the title Fix span when suggesting to add an associated type bound to an opaque typeFix span when suggesting to add an associated type boundJul 22, 2021
Comment threadcompiler/rustc_middle/src/ty/error.rs Outdated
@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

Thanks!

@bors

bors commented Jul 23, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit d1bc941 has been approved by oli-obk

@borsbors 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
Fixesrust-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>`
@JohnTitorJohnTitor mentioned this pull request Jul 24, 2021
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:masterJul 24, 2021
@rustbotrustbot 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`S-waiting-on-borsStatus: 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

@SkiFire13@rust-highfive@oli-obk@bors@michaelwoerister@rustbot