Skip to content

Fix dead code warning when inline const is used in pattern - #88036

Merged
bors merged 2 commits into
rust-lang:masterfrom
nbdd0121:const3
Aug 19, 2021
Merged

Fix dead code warning when inline const is used in pattern#88036
bors merged 2 commits into
rust-lang:masterfrom
nbdd0121:const3

Conversation

@nbdd0121

Copy link
Copy Markdown
Member

Fixes#78171

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @petrochenkov

(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 Aug 14, 2021
@petrochenkov

Copy link
Copy Markdown
Contributor

I'd never guess that const { ... } patterns use PatKind::Lit internally.
@bors r+

@bors

bors commented Aug 14, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 17d18e3822d5e5876fbf9d2ddd6d2b4a6783e117 has been approved by petrochenkov

@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 Aug 14, 2021
@nbdd0121

Copy link
Copy Markdown
MemberAuthor

Actually this approach doesn't catch const { foo() }..2 case. Might be better to save in_pat and set it to false when visiting a AnonConst and restore it after visiting.

@nbdd0121

Copy link
Copy Markdown
MemberAuthor

Added a test case for using inline const in range pattern

@nbdd0121

Copy link
Copy Markdown
MemberAuthor

I'd never guess that const { ... } patterns use PatKind::Lit internally.

It's surprising to me as well, but I guess that's probably the easiest way to implement it since it'll need to have a P<Expr> anyway.

Comment threadcompiler/rustc_passes/src/dead.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

Might be better to save in_pat and set it to false when visiting a AnonConst and restore it after visiting.

Yeah, it's a better approach, it should also fix cases like

constfnone() -> i32{1}structS<constC:i32>;fnmain(){matchS::<1>{S::<{one()}> => {}}}

Could you actually add this case too?
And merge all the cases into a single test file, no need to run rustc multiple times to test all of this.

@bors r-

@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 Aug 15, 2021
@nbdd0121

Copy link
Copy Markdown
MemberAuthor

Added and merged

@petrochenkov

Copy link
Copy Markdown
Contributor

Thanks!
@bors r+

@bors

bors commented Aug 15, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit e62ecdc has been approved by petrochenkov

@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 Aug 15, 2021
camsteffen added a commit to camsteffen/rust that referenced this pull request Aug 15, 2021
Fix dead code warning when inline const is used in pattern
Fixesrust-lang#78171
@camsteffencamsteffen mentioned this pull request Aug 15, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2021
…laumeGomez
Rollup of 10 pull requests
Successful merges:
- rust-lang#87818 (Fix anchors display in rustdoc)
- rust-lang#87983 (Use more accurate spans when proposing adding lifetime to item)
- rust-lang#88012 (Change WASI's `RawFd` from `u32` to `c_int` (`i32`).)
- rust-lang#88031 (Make `BuildHasher` object safe)
- rust-lang#88036 (Fix dead code warning when inline const is used in pattern)
- rust-lang#88082 (Take into account jobs number for rustdoc GUI tests)
- rust-lang#88109 (Fix environment variable getter docs)
- rust-lang#88111 (Add background-color on clickable definitions in source code)
- rust-lang#88129 (Fix dataflow graphviz bug, make dataflow graphviz modules public)
- rust-lang#88136 (Move private_unused.rs test to impl-trait)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 016f691 into rust-lang:masterAug 19, 2021
@rustbotrustbot added this to the 1.56.0 milestone Aug 19, 2021
@nbdd0121
nbdd0121 deleted the const3 branch September 4, 2021 02:55
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dead_code lint triggers even though function is used in const pattern

6 participants

@nbdd0121@rust-highfive@petrochenkov@bors@klensy@rustbot