Skip to content

Suggest Default::default() when binding isn't initialized #102184

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

Merged
merged 1 commit into from
Sep 26, 2022

Conversation

chenyukang
Copy link
Member

Fixes #102087

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 23, 2022
@rust-highfive
Copy link
Contributor

r? @nagisa

(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 Sep 23, 2022
@chenyukang
Copy link
Member Author

My first try on the type-checking part, there are several parts I'm not sure.

@chenyukang chenyukang force-pushed the fix-102087-add-binding-sugg branch from 8356aa8 to 2bfab8e Compare September 24, 2022 12:01

let mut visitor = LetVisitor { decl_span, ty_span: None };
visitor.visit_body(&body);
if let Some(ty_span) = visitor.ty_span {
Copy link
Member

@nagisa nagisa Sep 24, 2022

Choose a reason for hiding this comment

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

Hm, seems quite unfortunate that we only handle the bindings that have a specified type. As such code like this isn’t really covered:

fn apple(_: u32) { }

fn banana() {
    let chaenomeles;
    apple(chaenomeles);
}

Not saying though that this needs to be implemented here and now, but perhaps a FIXME comment or an issue for this would be warranted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed the code to support this scenario now, the type infer know it's a u32, so here we give this suggestion:

error[E0381]: used binding `chaenomeles` isn't initialized
 --> bug.rs:5:11
  |
4 |     let chaenomeles;
  |         ----------- binding declared here but left uninitialized
5 |     apple(chaenomeles);
  |           ^^^^^^^^^^^ `chaenomeles` used here but it isn't initialized
  |
help: consider assigning a value
  |
4 |     let chaenomeles = 0;
  |                     +++

@chenyukang chenyukang force-pushed the fix-102087-add-binding-sugg branch 2 times, most recently from 85582e6 to 21b9222 Compare September 24, 2022 15:06
@nagisa
Copy link
Member

nagisa commented Sep 24, 2022

This is quite awesome!

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 24, 2022

📌 Commit 21b9222 has been approved by nagisa

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 Sep 24, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 24, 2022
…sugg, r=nagisa

Suggest Default::default() when binding isn't initialized

Fixes rust-lang#102087
@matthiaskrgr
Copy link
Member

@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 Sep 25, 2022
@chenyukang
Copy link
Member Author

chenyukang commented Sep 25, 2022

@bors r- failed in a rollup (test needs update) https://github.com/rust-lang-ci/rust/actions/runs/3120399661/jobs/5060949966#step:25:24352 #102247

updated it!
How can we avoid this happend for those testcase which depended on some specific arch?
I just manually removed the only-aarch64 and generated the stderr.

@nagisa
Copy link
Member

nagisa commented Sep 25, 2022

How can we avoid this happend for those testcase which depended on some specific arch? I just manually removed the only-aarch64 and generated the stderr.

Unfortunately that’s the downside of only running the tests on the specified architecture. The more appropriate thing to do is to write the test in a way that is able to cross-compile if necessary to test target-specific details, but this isn’t always feasible (e.g. when test depends on libstd.)

The most straightfoward thing to do today is to just let bors deal with it, to be honest.

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Sep 25, 2022

📌 Commit 8b2a008fd2edfd01c8f9ede3d5131dbea5d0d725 has been approved by nagisa

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 Sep 25, 2022
@nagisa
Copy link
Member

nagisa commented Sep 25, 2022

@bors r-

Could you squash the commits a little please? Commits like “cleanup” or “update test” don’t really carry themselves.

@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 Sep 25, 2022
@chenyukang chenyukang force-pushed the fix-102087-add-binding-sugg branch from 8b2a008 to 672e3f4 Compare September 25, 2022 23:57
@chenyukang
Copy link
Member Author

@bors r-

Could you squash the commits a little please? Commits like “cleanup” or “update test” don’t really carry themselves.

squashed!

@nagisa
Copy link
Member

nagisa commented Sep 26, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 26, 2022

📌 Commit 672e3f4 has been approved by nagisa

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 Sep 26, 2022
@bors
Copy link
Collaborator

bors commented Sep 26, 2022

⌛ Testing commit 672e3f4 with merge 84946fe...

@bors
Copy link
Collaborator

bors commented Sep 26, 2022

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 84946fe to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 26, 2022
@bors bors merged commit 84946fe into rust-lang:master Sep 26, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 26, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (84946fe): 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.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.0% [-4.0%, -4.0%] 1
All ❌✅ (primary) - - 0

Cycles

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

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

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.

Papercut: Suggest Default::default() when binding isn't initialized
9 participants