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

Reduce diagram mess in 'match arms have incompatible types' error #78255

Merged
merged 2 commits into from
Oct 23, 2020

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Oct 22, 2020

I noticed this wild diagram in https://twitter.com/a_hoverbear/status/1318960787105353728 which I think does not benefit from the big outer vertical span.

This PR shrinks the outer span to cover just the match keyword and scrutinee expression if at least one of the highlighted match arms involved in the error is multiline.

Before:

error[E0308]: `match` arms have incompatible types
   --> src/topology/builder.rs:141:35
    |
120 |             let transform = match transform {
    |    _________________________-
121 |   |             Transform::Function(t) => {
    |  _|_______________________________________-
122 | | |                 filter_event_type(input_rx, input_type).compat().flat_map(|v| {
123 | | |                     futures::stream::iter(match v {
124 | | |                         Err(e) => {
...   | |
139 | | |                 .compat();
140 | | |             }
    | |_|_____________- this is found to be of type `()`
141 |   |             Transform::Task(t) => t
    |  _|___________________________________^
142 | | |                 .transform(filter_event_type(input_rx, input_type))
143 | | |                 .forward(output)
144 | | |                 .map(|_| debug!("Finished"))
145 | | |                 .compat(),
    | |_|_________________________^ expected `()`, found struct `futures::compat::Compat01As03`
146 |   |         };
    |   |_________- `match` arms have incompatible types
    |
    = note: expected type `()`
             found struct `futures::compat::Compat01As03<futures::Map<futures::stream::Forward<std::boxed::Box<dyn futures::Stream<Error = (), Item = event::Event> + std::marker::Send>, topology::fanout::Fanout>, [closure@src/topology/builder.rs:144:22: 144:44]>>`

After:

error[E0308]: `match` arms have incompatible types
   --> src/topology/builder.rs:141:35
    |
120 |             let transform = match transform {
    |                             --------------- `match` arms have incompatible types
121 |                 Transform::Function(t) => {
    |  _________________________________________-
122 | |                   filter_event_type(input_rx, input_type).compat().flat_map(|v| {
123 | |                       futures::stream::iter(match v {
124 | |                           Err(e) => {
...   |
139 | |                   .compat();
140 | |               }
    | |_______________- this is found to be of type `()`
141 |                 Transform::Task(t) => t
    |  _____________________________________^
142 | |                   .transform(filter_event_type(input_rx, input_type))
143 | |                   .forward(output)
144 | |                   .map(|_| debug!("Finished"))
145 | |                   .compat(),
    | |___________________________^ expected `()`, found struct `futures::compat::Compat01As03`
    |
    = note: expected type `()`
             found struct `futures::compat::Compat01As03<futures::Map<futures::stream::Forward<std::boxed::Box<dyn futures::Stream<Error = (), Item = event::Event> + std::marker::Send>, topology::fanout::Fanout>, [closure@src/topology/builder.rs:144:22: 144:44]>>`

FYI @Hoverbear

@rust-highfive
Copy link
Collaborator

r? @lcnr

(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 Oct 22, 2020
Copy link
Contributor

@Hoverbear Hoverbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvment @dtolnay !

@camelid camelid added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 23, 2020
@lcnr
Copy link
Contributor

lcnr commented Oct 23, 2020

lgtm 👍

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 23, 2020

📌 Commit b005950 has been approved by lcnr

@bors
Copy link
Contributor

bors commented Oct 23, 2020

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@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 Oct 23, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 23, 2020
Rollup of 17 pull requests

Successful merges:

 - rust-lang#77268 (Link to "Contributing to Rust" rather than "Getting Started".)
 - rust-lang#77339 (Implement TryFrom between NonZero types.)
 - rust-lang#77488 (Mark `repr128` as `incomplete_features`)
 - rust-lang#77890 (Fixing escaping to ensure generation of welformed json.)
 - rust-lang#77918 (Cleanup network tests)
 - rust-lang#77920 (Avoid extraneous space between visibility kw and ident for statics)
 - rust-lang#77969 (Doc formating consistency between slice sort and sort_unstable, and big O notation consistency)
 - rust-lang#78098 (Clean up and improve some docs)
 - rust-lang#78116 (Make inline const work in range patterns)
 - rust-lang#78153 (Sync LLVM submodule if it has been initialized)
 - rust-lang#78163 (Clean up lib docs)
 - rust-lang#78169 (Update cargo)
 - rust-lang#78231 (Make closures inherit the parent function's target features)
 - rust-lang#78235 (Explain where the closure return type was inferred)
 - rust-lang#78255 (Reduce diagram mess in 'match arms have incompatible types' error)
 - rust-lang#78263 (Add regression test of issue-77668)
 - rust-lang#78265 (Add some inference-related regression tests about incorrect diagnostics)

Failed merges:

r? `@ghost`
@bors bors merged commit 7ba519e into rust-lang:master Oct 23, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 23, 2020
@dtolnay dtolnay deleted the match branch October 23, 2020 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

None yet

7 participants