Make the Box one-liner more descriptive#101655
Conversation
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
|
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 |
dtolnay
left a comment
There was a problem hiding this comment.
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.
|
Would it be valid to create a Box that points to an object living on the stack? |
|
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); |
|
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. |
|
@bors r+ rollup |
…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
I would like to avoid a definition that relies on itself.
r? @GuillaumeGomez