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

Make the Box one-liner more descriptive #101655

Merged
merged 2 commits into from
Nov 22, 2022
Merged

Conversation

dns2utf8
Copy link
Contributor

I would like to avoid a definition that relies on itself.

r? @GuillaumeGomez

@rustbot
Copy link
Collaborator

rustbot commented Sep 10, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 10, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 10, 2022
@GuillaumeGomez
Copy link
Member

Looks good to me but I'll let the final approval to someone from the libs-api team have the final word.

r? @rust-lang/libs-api

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

I am hesitant about calling this "heap allocation for an owned value". It's 100% equally suitable to heap allocating a borrowed value. What you put in the Box can really be arbitrary.

@dtolnay dtolnay assigned dtolnay and unassigned GuillaumeGomez Oct 9, 2022
@dns2utf8
Copy link
Contributor Author

Would it be valid to create a Box that points to an object living on the stack?
I am at EuroRust currently, would love to chat :)

@dtolnay
Copy link
Member

dtolnay commented Oct 13, 2022

Box<T> itself always points to the heap, so no. But that is different from whether the value it points to is an owned value or borrowed. For example the following puts a borrowed value on the heap. It borrows from data on the stack.

let x = Struct { ... };
let b = Box::new(&x);

@dtolnay
Copy link
Member

dtolnay commented Nov 21, 2022

I pushed an alternative wording that avoids referring to T's type as being an owned type, just the fact that Box<T> owns a value of that type.

@dtolnay
Copy link
Member

dtolnay commented Nov 21, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 21, 2022

📌 Commit 70cee5a has been approved by dtolnay

It is now in the queue for this repository.

@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 Nov 21, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 22, 2022
…earth

Rollup of 7 pull requests

Successful merges:

 - rust-lang#83608 (Add slice methods for indexing via an array of indices.)
 - rust-lang#95583 (Deprecate the unstable `ptr_to_from_bits` feature)
 - rust-lang#101655 (Make the Box one-liner more descriptive)
 - rust-lang#102207 (Constify remaining `Layout` methods)
 - rust-lang#103193 (mark sys_common::once::generic::Once::new const-stable)
 - rust-lang#104622 (Use clang for the UEFI targets)
 - rust-lang#104638 (Move macro_rules diagnostics to diagnostics module)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2f8dbe3 into rust-lang:master Nov 22, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants