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

Suggest function call on pattern type mismatch #107098

Merged
merged 1 commit into from
Feb 11, 2023

Conversation

compiler-errors
Copy link
Member

Fixes #101208

This could definitely be generalized to support more suggestions in pattern matches. We can't use all of FnCtxt::emit_type_mismatch_suggestions, but it's on my to-do list to play around with more suggestions that would be productive in this position.

@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2023

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 20, 2023
let mut diag = self.err_ctxt().report_mismatched_types(cause, expected, actual, e);
mutate_err(&mut diag);
Some(diag)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add a closure, and not have the caller modify the returned value?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had originally thought to pass in the TypeError that resulted from the demand call, but then I didn't need it anymore, so this is just an artifact of that old design.

compiler/rustc_hir_typeck/src/_match.rs Show resolved Hide resolved
@compiler-errors compiler-errors force-pushed the pat-mismatch-fn-call branch 2 times, most recently from eac8b4f to f900104 Compare January 22, 2023 04:47
@compiler-errors
Copy link
Member Author

It has been two weeks, I'm assuming that @TaKO8Ki is not reviewing at the moment.

r? compiler

@rustbot rustbot assigned lcnr and unassigned TaKO8Ki Feb 1, 2023
@lcnr
Copy link
Contributor

lcnr commented Feb 8, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 8, 2023

📌 Commit f900104 has been approved by lcnr

It is now in the queue for this repository.

@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 Feb 8, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 8, 2023
…ll, r=lcnr

Suggest function call on pattern type mismatch

Fixes rust-lang#101208

This could definitely be generalized to support more suggestions in pattern matches. We can't use all of [`FnCtxt::emit_type_mismatch_suggestions`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#method.emit_type_mismatch_suggestions), but it's on my to-do list to play around with more suggestions that would be productive in this position.
@matthiaskrgr
Copy link
Member

Failed in a rollup (and locally)

---- [ui] tests/ui/suggestions/suggest-call-on-pat-mismatch.rs stdout ----
diff of stderr:

4	LL |     if let E::One(var1, var2) = var {
5	   |            ^^^^^^^^^^^^^^^^^^   --- this expression has type `fn(i32, i32) -> E {E::One}`
6	   |            |
-	   |            expected enum constructor, found enum `E`
+	   |            expected enum constructor, found `E`
8	   |
9	   = note: expected enum constructor `fn(i32, i32) -> E {E::One}`
10	                          found enum `E`

19	LL |     let Some(x) = Some;
20	   |         ^^^^^^^   ---- this expression has type `fn(_) -> Option<_> {Option::<_>::Some}`
21	   |         |
-	   |         expected enum constructor, found enum `Option`
+	   |         expected enum constructor, found `Option<_>`
23	   |
24	   = note: expected enum constructor `fn(_) -> Option<_> {Option::<_>::Some}`
25	                          found enum `Option<_>`


The actual stderr differed from the expected stderr.
Actual stderr saved to /home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/test/ui/suggestions/suggest-call-on-pat-mismatch/suggest-call-on-pat-mismatch.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args suggestions/suggest-call-on-pat-mismatch.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/matthias/vcs/github/rust/tests/ui/suggestions/suggest-call-on-pat-mismatch.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/home/matthias/vcs/github/rust/tests/ui=fake-test-src-base" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/test/ui/suggestions/suggest-call-on-pat-mismatch" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/test/ui/suggestions/suggest-call-on-pat-mismatch/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0308]: mismatched types
  --> fake-test-src-base/suggestions/suggest-call-on-pat-mismatch.rs:7:12
   |
LL |     if let E::One(var1, var2) = var {
   |            ^^^^^^^^^^^^^^^^^^   --- this expression has type `fn(i32, i32) -> E {E::One}`
   |            |
   |            expected enum constructor, found `E`
   |
   = note: expected enum constructor `fn(i32, i32) -> E {E::One}`
                          found enum `E`
help: use parentheses to construct this tuple variant
   |
LL |     if let E::One(var1, var2) = var(/* i32 */, /* i32 */) {
   |                                    ++++++++++++++++++++++

error[E0308]: mismatched types
  --> fake-test-src-base/suggestions/suggest-call-on-pat-mismatch.rs:13:9
   |
LL |     let Some(x) = Some;
   |         ^^^^^^^   ---- this expression has type `fn(_) -> Option<_> {Option::<_>::Some}`
   |         |
   |         expected enum constructor, found `Option<_>`
   |
   = note: expected enum constructor `fn(_) -> Option<_> {Option::<_>::Some}`
                          found enum `Option<_>`
help: use parentheses to construct this tuple variant
   |
LL |     let Some(x) = Some(/* value */);
   |                       +++++++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
------------------------------------------



failures:
    [ui] tests/ui/suggestions/suggest-call-on-pat-mismatch.rs

compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 9, 2023
…ll, r=lcnr

Suggest function call on pattern type mismatch

Fixes rust-lang#101208

This could definitely be generalized to support more suggestions in pattern matches. We can't use all of [`FnCtxt::emit_type_mismatch_suggestions`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#method.emit_type_mismatch_suggestions), but it's on my to-do list to play around with more suggestions that would be productive in this position.
@compiler-errors
Copy link
Member Author

Whoops, matthias commented but didn't r-

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 9, 2023
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Feb 10, 2023

📌 Commit 0eba2f3 has been approved by lcnr

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 10, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 10, 2023
…ll, r=lcnr

Suggest function call on pattern type mismatch

Fixes rust-lang#101208

This could definitely be generalized to support more suggestions in pattern matches. We can't use all of [`FnCtxt::emit_type_mismatch_suggestions`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#method.emit_type_mismatch_suggestions), but it's on my to-do list to play around with more suggestions that would be productive in this position.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2023
Rollup of 9 pull requests

Successful merges:

 - rust-lang#105019 (Add parentheses properly for borrowing suggestion)
 - rust-lang#106001 (Stop at the first `NULL` argument when iterating `argv`)
 - rust-lang#107098 (Suggest function call on pattern type mismatch)
 - rust-lang#107490 (rustdoc: remove inconsistently-present sidebar tooltips)
 - rust-lang#107855 (Add a couple random projection tests for new solver)
 - rust-lang#107857 (Add ui test for implementation on projection)
 - rust-lang#107878 (Clarify `new_size` for realloc means bytes)
 - rust-lang#107888 (revert rust-lang#107074, add regression test)
 - rust-lang#107900 (Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` header)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 400b03a into rust-lang:master Feb 11, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 11, 2023
@compiler-errors compiler-errors deleted the pat-mismatch-fn-call branch August 11, 2023 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide suggestion for error when if let used with enum variant whose values are not initialized
7 participants