Skip to content

own_ref RFC initial commit - #4000

Open
CheaterCodes wants to merge 1 commit into
rust-lang:masterfrom
CheaterCodes:own_ref
Open

own_ref RFC initial commit#4000
CheaterCodes wants to merge 1 commit into
rust-lang:masterfrom
CheaterCodes:own_ref

Conversation

@CheaterCodes

@CheaterCodes CheaterCodes commented Aug 15, 2026

Copy link
Copy Markdown

Introduce owning references &own into the language, which allows passing ownership of the pointee without moving its value.
Owning references can be moved out of (including partial moves), and drop their pointee when dropped.

fn print_all(producers: &own [&own dyn FnOnce() -> String]) {
    for producer in producers {
        println!("Got value: {}", producer());
    }
}

Important

Since RFCs involve many conversations at once that can be difficult to follow, please use review comment threads on the text changes instead of direct comments on the RFC.

If you don't have a particular section of the RFC to comment on, you can click on the "Comment on this file" button on the top-right corner of the diff, to the right of the "Viewed" checkbox. This will create a separate thread even if others have commented on the file too.

Rendered

@CheaterCodes

Copy link
Copy Markdown
Author

To create the appropriate cross-links to relevant issues:


Probably the most commonly used unsized types are slices `[T]`.
Since they cannot be pased by value, they are always passed with indirection.
We use `&[T]` for read-only slices, `&mut T` for mutable slices.

@programmerjake programmerjake Aug 15, 2026

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.

Suggested change
We use `&[T]` for read-only slices, `&mut T` for mutable slices.
We use `&[T]` for read-only slices, `&mut [T]` for mutable slices.

View changes since the review

> Boxes provide ownership for this allocation, and
drop their contents when they go out of scope.

A `Box<T, Noop<'a>>` is neither a heap allocation, nor does it provide opwnership for its allocation.

@programmerjake programmerjake Aug 15, 2026

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.

quotes need to use > on every line. also ownership is misspelled

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants