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

When a local binding shadows a fn, point at fn def in call failure #117924

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Nov 15, 2023

When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name.

error[E0618]: expected function, found `&str`
  --> $DIR/issue-22468.rs:3:13
   |
LL |     let foo = "bar";
   |         --- `foo` has type `&str`
LL |     let x = foo("baz");
   |             ^^^-------
   |             |
   |             call expression requires function
...
LL | fn foo(file: &str) -> bool {
   | -------------------------- this function of the same name is available here, but it shadowed by the local binding of the same name

Fix #53841

@rustbot
Copy link
Collaborator

rustbot commented Nov 15, 2023

r? @petrochenkov

(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 Nov 15, 2023
@estebank estebank force-pushed the issue-53841 branch 2 times, most recently from 8bcf2fb to 9a7e6c9 Compare November 15, 2023 01:31
compiler/rustc_hir_typeck/src/callee.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/callee.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/callee.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

r=me with cleanup.
@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 17, 2023
When a local binding shadows a function that is then called, this local
binding will cause an E0618 error. We now point not only at the binding
definition, but also at the locally defined function of the same name.

```
error[E0618]: expected function, found `&str`
  --> $DIR/issue-22468.rs:3:13
   |
LL |     let foo = "bar";
   |         --- `foo` has type `&str`
LL |     let x = foo("baz");
   |             ^^^-------
   |             |
   |             call expression requires function
...
LL | fn foo(file: &str) -> bool {
   | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name
```

Fix rust-lang#53841
@estebank
Copy link
Contributor Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Nov 18, 2023

📌 Commit 7141399 has been approved by petrochenkov

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 Nov 18, 2023
@bors
Copy link
Contributor

bors commented Nov 18, 2023

⌛ Testing commit 7141399 with merge e1e60b6...

@bors
Copy link
Contributor

bors commented Nov 18, 2023

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing e1e60b6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 18, 2023
@bors bors merged commit e1e60b6 into rust-lang:master Nov 18, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 18, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e1e60b6): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-2.9% [-4.0%, -2.3%] 3
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 675.683s -> 678.285s (0.39%)
Artifact size: 313.83 MiB -> 313.84 MiB (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

confusing diagnostic when variable name equals function name
6 participants