Skip to content
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

Tracking issue for box_syntax #49733

Open
aidanhs opened this Issue Apr 6, 2018 · 5 comments

Comments

Projects
None yet
7 participants
@aidanhs
Copy link
Member

aidanhs commented Apr 6, 2018

This is a tracking issue for the box_syntax feature, the special syntax for creating boxes, e.g. box 1usize (note: box patterns is separate and is tracked at at #29641)

This was previously under the same tracking issues as placement (#22181/#27779) but I didn't want to remove it (yet) due to widespread usage in the compiler (Box::new is implemented in terms of it) and in the wider ecosystem (unlike <- etc which only had a handful of crates using it).

Things to decide:

  • how should box syntax be phased out?
    • how easy is it to remove box syntax as a language feature? Can we just describe it as "will never be stabilised in its current form as it's an internal implementation detail, may be stabilised under a new design of placement")?
      • if it were possible to remove it as a language feature, is it reasonable to do so without a replacement in the form of working placement?
      • if we want to keep box syntax internally, should we rename (but keep reserved) the keyword to something else to deliberately break users and indicate it shouldn't be used for placement?
    • is there any reason for users to use box syntax (apart from it looking nice) given Box::new is inline always, or does that not work?
  • if we decide to keep this, there are a number of unresolved questions in #22181 about the syntax behaviour

Note: when removing this, be careful not to remove the syntax entirely in order to not cause another case of #50832

@aidanhs aidanhs referenced this issue Apr 6, 2018

Closed

Tracking issue for placement new #27779

0 of 4 tasks complete
@spacekookie

This comment has been minimized.

Copy link

spacekookie commented May 14, 2018

Do I understand it correctly that the box syntax is dependent on placement-new (which has now been unapproved as an RFC)?

Personally I like the idea of having some syntactic sugar for creating something as common as a box (it does look nice). But obviously it would need to be built on something that works.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented May 14, 2018

@spacekookie yes, the big deal for box syntax is placement new.

@ebkalderon ebkalderon referenced this issue May 24, 2018

Closed

Track nightly features #10

1 of 3 tasks complete
@oyvindln

This comment has been minimized.

Copy link
Contributor

oyvindln commented Jun 27, 2018

s there any reason for users to use box syntax (apart from it looking nice) given Box::new is inline always, or does that not work?

It doesn't optimize well, and even if it did, you would need some other way around it to avoid blowing up the stack in debug mode.
#41160

@mark-i-m

This comment has been minimized.

Copy link
Contributor

mark-i-m commented Oct 25, 2018

is there any reason for users to use box syntax (apart from it looking nice) given Box::new is inline always, or does that not work?

So this is perhaps a bit of a weird usecase, but it is the only reason I have used box at all: I do a lot of no_std projects where the stack doesn't grow automatically. In these cases, using Box::new(MyLargeStruct) will overrun the limited amount of stack space by allocating MyLargeStruct on the stack and copying it to the allocated space. Allocating and initializing in place is critical.

The obvious alternative is to use the allocator directly and unsafely construct a Box from it, but that's annoying and ugly.

See example here: https://github.com/mark-i-m/os2/blob/2ab9d589a4463bd3133157b5c1a2f9f6735a3432/kernel/process/sched.rs#L76-L83

@ice1000

This comment has been minimized.

Copy link

ice1000 commented Mar 10, 2019

In most cases people just want to simplify the Box::news everywhere. I really want a shorter version and box syntax sounds like a great idea.
Is there a recent plan of stabilizing box syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.