Skip to content

check that first arg to panic!() in const is &str - #80734

Merged
bors merged 1 commit into
rust-lang:masterfrom
abonander:ab/issue-66693
Mar 2, 2021
Merged

check that first arg to panic!() in const is &str#80734
bors merged 1 commit into
rust-lang:masterfrom
abonander:ab/issue-66693

Conversation

@abonander

@abonanderabonander commented Jan 5, 2021

Copy link
Copy Markdown
Contributor

closes#66693

TODO: regression test

cc @RalfJung for error message wording

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @oli-obk

(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 Jan 5, 2021
@rust-log-analyzer

This comment has been minimized.

@oli-obkoli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this affect any tests? If not, please add a test in a test that has the const_panic feature activated.

Comment threadcompiler/rustc_mir/src/transform/check_consts/validation.rs Outdated
Comment threadcompiler/rustc_mir/src/transform/check_consts/validation.rs Outdated
@abonander

Copy link
Copy Markdown
ContributorAuthor

does this affect any tests? If not, please add a test in a test that has the const_panic feature activated.

Yep, I was getting to that. I just wanted to post as draft for early feedback on the error message.

@oli-obk

Copy link
Copy Markdown
Contributor

Yep, I was getting to that. I just wanted to post as draft for early feedback on the error message.

oh duh, I should have read your main PR message properly..

@abonander
abonanderforce-pushed the ab/issue-66693 branch 3 times, most recently from f437c33 to c6c1997CompareJanuary 5, 2021 22:25
@rust-log-analyzer

This comment has been minimized.

Comment threadcompiler/rustc_mir/src/transform/check_consts/ops.rs Outdated
@abonander
abonanderforce-pushed the ab/issue-66693 branch 3 times, most recently from 9511e21 to a5e15c7CompareJanuary 8, 2021 00:37
Comment threadcompiler/rustc_mir/src/transform/check_consts/validation.rs Outdated
@abonander

Copy link
Copy Markdown
ContributorAuthor

@RalfJung@oli-obk I adjusted the wording, fixed the check and added UI tests. I noticed a discrepancy between panics in array length expressions and normal consts so I put them in separate files. Should the tests cover const fn as well?

@abonander
abonander marked this pull request as ready for review January 8, 2021 00:40
@rust-log-analyzer

This comment has been minimized.

@abonander
abonanderforce-pushed the ab/issue-66693 branch 2 times, most recently from 9bcdbad to aa12833CompareJanuary 8, 2021 03:23
@abonander

Copy link
Copy Markdown
ContributorAuthor

I went ahead and made sure to cover const fn as well.

@RalfJung

Copy link
Copy Markdown
Member

@RalfJung@oli-obk I adjusted the wording, fixed the check and added UI tests. I noticed a discrepancy between panics in array length expressions and normal consts so I put them in separate files. Should the tests cover const fn as well?

You can have more than one //~ ERROR in a single file, and that is usually preferred to group testcases.

@abonander

Copy link
Copy Markdown
ContributorAuthor

@RalfJung well the problem I had with arrays is that it seems their length expressions get const-evaluated in an earlier pass than const or static or const fn because the compiler would issue an error for let _ = [0i32; panic!(1)] and then exit before even visiting the other declarations. I assumed this was to be expected since arrays need to know their lengths for typechecking to finish, thus I separated the test cases into two files. Otherwise, I did combine test cases where I could.

@RalfJung

Copy link
Copy Markdown
Member

That's a good point, thanks. Maybe add a comment in the array-length-test-file explaining why this is a separate file.

Comment threadsrc/test/ui/consts/issue-66693-panic-in-array-len.rs Outdated
Comment threadsrc/test/ui/consts/issue-66693-panic-in-array-len.rs Outdated
@SergioBenitez

Copy link
Copy Markdown
Contributor

It seems like this is waiting on rather minor changes, is that right? @RalfJung I'm happy to push this forward if so.

@RalfJung

Copy link
Copy Markdown
Member

@SergioBenitez I left some comments that are all minor, yes (see the open discussions). I don't know if @oli-obk has further comments; he is more familiar with the const-checking code.

@abonander

abonander commented Feb 28, 2021

Copy link
Copy Markdown
ContributorAuthor

@RalfJung sorry, been busy with work. I think that's your nits addressed now.

@JohnCSimon if you want to update the triage label. (nevermind, I got it)

@abonander

Copy link
Copy Markdown
ContributorAuthor

@rustbot label: +S-waiting-on-review -S-waiting-on-author

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 28, 2021
@abonander
abonanderforce-pushed the ab/issue-66693 branch 2 times, most recently from 9b4f2a0 to 8765a3dCompareFebruary 28, 2021 19:12

@oli-obkoli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a nit, then this lgtm

Comment threadcompiler/rustc_mir/src/transform/check_consts/validation.rs Outdated
@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Mar 1, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 5a33f53 has been approved by oli-obk

@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 Mar 1, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2021
…laumeGomez
Rollup of 7 pull requests
Successful merges:
- rust-lang#80734 (check that first arg to `panic!()` in const is `&str`)
- rust-lang#81932 (Always compile rustdoc with debug logging enabled when `download-rustc` is set)
- rust-lang#82018 (Remove the dummy cache in `DocContext`; delete RenderInfo)
- rust-lang#82598 (Check stability and feature attributes in rustdoc)
- rust-lang#82655 (Highlight identifier span instead of whole pattern span in `unused` lint)
- rust-lang#82662 (Warn about unknown doc attributes)
- rust-lang#82676 (Change twice used large const table to static)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 865cf0c into rust-lang:masterMar 2, 2021
@rustbotrustbot added this to the 1.52.0 milestone Mar 2, 2021
@abonander
abonander deleted the ab/issue-66693 branch March 2, 2021 17:16
@camelidcamelid added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Mar 14, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)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.

const_panic: ICE on non-&str panic payload

10 participants

@abonander@rust-highfive@rust-log-analyzer@oli-obk@RalfJung@JohnCSimon@SergioBenitez@bors@camelid@rustbot