Skip to content

Make FlatMapInPlaceVec an unsafe trait.#155951

Open
nnethercote wants to merge 1 commit intorust-lang:mainfrom
nnethercote:unsafe-FlatMapInPlaceVec
Open

Make FlatMapInPlaceVec an unsafe trait.#155951
nnethercote wants to merge 1 commit intorust-lang:mainfrom
nnethercote:unsafe-FlatMapInPlaceVec

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

Because the memory safety of FlatMapInPlace::flat_map_in_place depends on FlatMapInPlaceVec impls behaving correctly.

r? @chenyukang

Because the memory safety of `FlatMapInPlace::flat_map_in_place` depends
on `FlatMapInPlaceVec` impls behaving correctly.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 29, 2026
@nnethercote
Copy link
Copy Markdown
Contributor Author

Thanks to @programmerjake for pointing this out.

Copy link
Copy Markdown
Member

@Kivooeo Kivooeo left a comment

Choose a reason for hiding this comment

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

looks fine to me, feel free to r=me

View changes since this review

@nnethercote
Copy link
Copy Markdown
Contributor Author

@bors r=kivooeo rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

📌 Commit a940270 has been approved by kivooeo

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Apr 29, 2026
@Nikolay-Sitnikov
Copy link
Copy Markdown

Nikolay-Sitnikov commented Apr 29, 2026

...relies on impls of this trait implementing all the operations correctly.

Is the "correct way to implement this trait" explained in more detail somewhere else, or is that statement just referring to the obvious limitation of "operations must be pure/idempotent outside of the expected mutation"? It seems strange to have a comment requiring you to promise that you implemented the trait correctly, but no comments about what "correctly" means for this trait.

@nnethercote
Copy link
Copy Markdown
Contributor Author

The meaning of correct operation is left implicit because it's obvious. E.g. len should return the actual length not usize::MAX, set_len should actually set the len and not be a no-op, as_ptr should return a pointer to the start of the buffer and not to some random place, etc.

jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 29, 2026
…ec, r=kivooeo

Make `FlatMapInPlaceVec` an unsafe trait.

Because the memory safety of `FlatMapInPlace::flat_map_in_place` depends on `FlatMapInPlaceVec` impls behaving correctly.

r? @chenyukang
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 29, 2026
…ec, r=kivooeo

Make `FlatMapInPlaceVec` an unsafe trait.

Because the memory safety of `FlatMapInPlace::flat_map_in_place` depends on `FlatMapInPlaceVec` impls behaving correctly.

r? @chenyukang
rust-bors Bot pushed a commit that referenced this pull request Apr 29, 2026
Rollup of 9 pull requests

Successful merges:

 - #151742 (Remove redundant information in `rustc_abi::Variants`)
 - #155856 (std_detect: support detecting more features on aarch64 Windows)
 - #155861 (Suggest `[const] Trait` bounds in more places)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155916 (Update with new LLVM 22 target for `wasm32-wali-linux-musl` target)
 - #155935 (remap OUT_DIR paths to fix build script path leakage in crate metadata. )
 - #155950 (use the new `//@ needs-asm-mnemonic: ret` more)
 - #155949 (Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`)
 - #155951 (Make `FlatMapInPlaceVec` an unsafe trait.)
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants