Skip to content

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

Merged
bors merged 1 commit into
rust-lang:masterfrom
chenyukang:fix-102087-add-binding-sugg
Sep 26, 2022
Merged

Suggest Default::default() when binding isn't initialized#102184
bors merged 1 commit into
rust-lang:masterfrom
chenyukang:fix-102087-add-binding-sugg

Conversation

@chenyukang

Copy link
Copy Markdown
Member

Fixes#102087

@rustbotrustbot 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
Copy Markdown
Contributor

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 23, 2022
@chenyukang

Copy link
Copy Markdown
MemberAuthor

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

Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
Comment threadsrc/test/ui/borrowck/borrowck-block-unint.stderr
@chenyukang
chenyukangforce-pushed the fix-102087-add-binding-sugg branch from 8356aa8 to 2bfab8eCompareSeptember 24, 2022 12:01
Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated

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

@nagisanagisaSep 24, 2022

Copy link
Copy Markdown
Member

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:

fnapple(_:u32){}fnbanana(){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
Copy Markdown
MemberAuthor

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;
| +++

Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Comment threadcompiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
@chenyukang
chenyukangforce-pushed the fix-102087-add-binding-sugg branch 2 times, most recently from 85582e6 to 21b9222CompareSeptember 24, 2022 15:06
@nagisa

Copy link
Copy Markdown
Member

This is quite awesome!

@bors r+

@bors

bors commented Sep 24, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 21b9222 has been approved by nagisa

It is now in the queue for this repository.

@borsbors 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
Fixesrust-lang#102087
@matthiaskrgr

Copy link
Copy Markdown
Member

@borsbors 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 commented Sep 25, 2022

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown
Member

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

bors commented Sep 25, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 8b2a008fd2edfd01c8f9ede3d5131dbea5d0d725 has been approved by nagisa

It is now in the queue for this repository.

@borsbors 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
Copy Markdown
Member

@bors r-

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

@borsbors 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
chenyukangforce-pushed the fix-102087-add-binding-sugg branch from 8b2a008 to 672e3f4CompareSeptember 25, 2022 23:57
@chenyukang

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown
Member

@bors r+

@bors

bors commented Sep 26, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 672e3f4 has been approved by nagisa

It is now in the queue for this repository.

@borsbors 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

bors commented Sep 26, 2022

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Sep 26, 2022

Copy link
Copy Markdown
Collaborator

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

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Sep 26, 2022
@bors
bors merged commit 84946fe into rust-lang:masterSep 26, 2022
@rustbotrustbot added this to the 1.66.0 milestone Sep 26, 2022
@rust-timer

Copy link
Copy Markdown
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.

mean1rangecount2
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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@chenyukang@rust-highfive@nagisa@bors@matthiaskrgr@rust-timer@Patryk27@lcnr@rustbot