Skip to content

Check that a box expression's type is Sized#88087

Merged
bors merged 3 commits into
rust-lang:masterfrom
jesyspa:issue-87935-box
Aug 21, 2021
Merged

Check that a box expression's type is Sized#88087
bors merged 3 commits into
rust-lang:masterfrom
jesyspa:issue-87935-box

Conversation

@jesyspa

@jesyspa jesyspa commented Aug 16, 2021

Copy link
Copy Markdown
Contributor

This resolves issue 87935.

This makes E0161 (move from an unsized rvalue) much less common. I've replaced the test to use this case, when a boxed dyn trait is passed by value, but that isn't an error when unsized_locals is enabled. I think it may be possible to get rid of E0161 entirely by checking that case earlier, but I'm not sure if that's desirable?

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @jackh726

(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 Aug 16, 2021
@jesyspa
jesyspa marked this pull request as ready for review August 16, 2021 17:14
@rust-log-analyzer

This comment has been minimized.

@jesyspa

jesyspa commented Aug 17, 2021

Copy link
Copy Markdown
Contributor Author

There's another possible implementation, where we issue E0161 for unsized box expressions even when unsized_locals are disabled. That approach keeps the checking in rustc_mir, but it currently emits duplicate errors for cases like rust fn foo(x: Box<[i32]>) { box *x; }

Given that the implementation in this PR gives a clearer error message, I think it's probably the better option.

@jackh726 jackh726 left a comment

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.

Why change the E0161 output?

Comment thread compiler/rustc_error_codes/src/error_codes/E0161.md Outdated
The code will not emit this warning once box expressions require a sized
type (since that error is emitted earlier in the flow).
New tests also check that we're not triggering this error
over-zealously.
@jackh726

Copy link
Copy Markdown
Member

Thanks! Going to @bors rollup=never in case there are any subtle changes here that need to be bisected.

@bors r+

@jackh726 jackh726 closed this Aug 20, 2021
@jackh726 jackh726 reopened this Aug 20, 2021
@jackh726

Copy link
Copy Markdown
Member

@bors r+ rollup=never

@bors

bors commented Aug 20, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit c75a930 has been approved by jackh726

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

Copy link
Copy Markdown
Member

I wonder if it's worth a new obligation cause code if we want to remove box syntax eventually anyway 🤔

@jackh726

Copy link
Copy Markdown
Member

Those are cheap :)

@bors

bors commented Aug 20, 2021

Copy link
Copy Markdown
Collaborator

⌛ Testing commit c75a930 with merge 1e3d632...

@bors

bors commented Aug 21, 2021

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 1e3d632 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 21, 2021
@bors
bors merged commit 1e3d632 into rust-lang:master Aug 21, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 21, 2021
@jesyspa

jesyspa commented Aug 21, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

I wonder if it's worth a new obligation cause code if we want to remove box syntax eventually anyway thinking

I don't think this will complicate it, since check_box can be removed in its entirety when the syntax goes away. The cost should only be paid by code that uses box expressions.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE with box syntax and unsized types

7 participants