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

Point at expressions where inference refines an unexpected type #106400

Merged
merged 12 commits into from
Jan 6, 2023

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jan 3, 2023

Fix #106355. Fix #14007. (!)

error[E0308]: mismatched types
  --> src/test/ui/type/type-check/point-at-inference.rs:12:9
   |
9  |         foo.push(i);
   |                  - this is of type `&{integer}`, which makes `foo` to be inferred as `Vec<&{integer}>`
...
12 |     bar(foo);
   |     --- ^^^ expected `i32`, found `&{integer}`
   |     |
   |     arguments to this function are incorrect
   |
   = note: expected struct `Vec<i32>`
              found struct `Vec<&{integer}>`
note: function defined here
  --> src/test/ui/type/type-check/point-at-inference.rs:2:4
   |
2  | fn bar(_: Vec<i32>) {}
   |    ^^^ -----------
help: consider dereferencing the borrow
   |
9  |         foo.push(*i);
   |                  +

@rustbot
Copy link
Collaborator

rustbot commented Jan 3, 2023

r? @compiler-errors

(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 3, 2023
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
src/test/ui/span/coerce-suggestions.stderr Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
src/test/ui/closures/closure-return-type-mismatch.stderr Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
@estebank
Copy link
Contributor Author

estebank commented Jan 4, 2023

@compiler-errors I think I addressed all of your previous comments

@estebank estebank force-pushed the type-errs branch 3 times, most recently from 095a33e to b3488b2 Compare January 5, 2023 00:38
@compiler-errors
Copy link
Member

Hm, I'm not sure if I fully grasp some of this method argument stuff, since it seems like this PR got rewritten since I last reviewed it. Need to spend some time reasoning with some of this logic.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

one nit: "make" here is a synonym of "cause" but I'm not sure if it works with the same construction?

r=me -- I may take a stab at this method code a bit later, but I don't want to block you and I'm still trying to think of a way to avoid theCollectAllMismatches usage here.

compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
@estebank
Copy link
Contributor Author

estebank commented Jan 5, 2023

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jan 5, 2023

📌 Commit 25cf71e has been approved by compiler-errors

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 Jan 5, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jan 5, 2023
Point at expressions where inference refines an unexpected type

Fix rust-lang#106355. Fix rust-lang#14007. (!)

```
error[E0308]: mismatched types
  --> src/test/ui/type/type-check/point-at-inference.rs:12:9
   |
9  |         foo.push(i);
   |                  - this is of type `&{integer}`, which makes `foo` to be inferred as `Vec<&{integer}>`
...
12 |     bar(foo);
   |     --- ^^^ expected `i32`, found `&{integer}`
   |     |
   |     arguments to this function are incorrect
   |
   = note: expected struct `Vec<i32>`
              found struct `Vec<&{integer}>`
note: function defined here
  --> src/test/ui/type/type-check/point-at-inference.rs:2:4
   |
2  | fn bar(_: Vec<i32>) {}
   |    ^^^ -----------
help: consider dereferencing the borrow
   |
9  |         foo.push(*i);
   |                  +
```
@bors
Copy link
Contributor

bors commented Jan 5, 2023

⌛ Testing commit 25cf71e with merge cfbc12774406f0ed9a269e2c28275de9e0a45330...

@bors
Copy link
Contributor

bors commented Jan 5, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 5, 2023
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor Author

estebank commented Jan 5, 2023

I'm very confused by this merge conflict, pulling and rebasing still builds 👀

- Only point at a the single expression where the found type was first
  inferred.
- Find method call argument that might have caused the found type to be
  inferred.
- Provide structured suggestion.
- Apply some review comments.
- Tweak wording.
```rust
fn main() {
    let v = Vec::new();
    v.push(0);
    v.push(0);
    v.push("");
}
```

now produces

```
error[E0308]: mismatched types
  --> $DIR/point-at-inference-3.rs:6:12
   |
LL |     v.push(0);
   |            - this is of type `{integer}`, which makes `v` to be inferred as `Vec<{integer}>`
...
LL |     v.push("");
   |       ---- ^^ expected integer, found `&str`
   |       |
   |       arguments to this function are incorrect
   |
note: associated function defined here
  --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
```
@estebank
Copy link
Contributor Author

estebank commented Jan 5, 2023

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jan 5, 2023

📌 Commit f98f2fc has been approved by compiler-errors

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 Jan 5, 2023
@bors
Copy link
Contributor

bors commented Jan 5, 2023

⌛ Testing commit f98f2fc with merge 6660916f5ebc99a31603558493a43b72f7189242...

@bors
Copy link
Contributor

bors commented Jan 5, 2023

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 5, 2023
@estebank
Copy link
Contributor Author

estebank commented Jan 5, 2023

@bors retry

@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 Jan 5, 2023
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 6, 2023
Rollup of 5 pull requests

Successful merges:

 - rust-lang#106400 (Point at expressions where inference refines an unexpected type)
 - rust-lang#106491 (Fix error-index redirect to work with the back button.)
 - rust-lang#106494 (Add regression test for rust-lang#58355)
 - rust-lang#106499 (fix [type error] for error E0029 and E0277)
 - rust-lang#106502 (rustdoc: remove legacy user-select CSS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6ae0f08 into rust-lang:master Jan 6, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 6, 2023
@estebank estebank deleted the type-errs branch November 9, 2023 05: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
5 participants