Skip to content

add Dir::try_clone - #163007

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:dirfd-clone
Sep 20, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:dirfd-clone

Conversation

@RalfJung

Copy link
Copy Markdown
Member

There's no try_clone listed on #120426 but I assume that's a standard operation for all kinds of file descriptors?

Cc @the8472 @ChrisDenton

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 19, 2026
@rustbot

rustbot commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 7 candidates

@ChrisDenton

Copy link
Copy Markdown
Member

IIRC @the8472 had concerns about cloning directory handles on Unix.

@the8472

the8472 commented Sep 19, 2026

Copy link
Copy Markdown
Member

Did I? On platforms where it implements AsFd and From<OwnedFd> the cloning already is reachable via as_fd().try_clone_to_owned().into(), so on this it should be fine.
Platforms that use the path fallback are fine too.
Maybe on some nichI think there's wasi that doesn't have dup or something?

Maybe you're thinking of the conversions between ReadDir and Dir? Those are problematic, need to be fallible and we need to reimplement ReadDir to use getdents instead of readdir because fdopendir says

Upon successful return from fdopendir(), the file descriptor is under the control of the system, and if any attempt is made to close the file descriptor, or to modify the state of the associated description, other than by means of closedir(), readdir(), readdir_r(), rewinddir(), or [XSI] [Option Start] seekdir(), [Option End] the behavior is undefined.

I assume that "undefined" really just means "unspecified", but... anyway, different topic.

@ChrisDenton

Copy link
Copy Markdown
Member

Maybe you're thinking of the conversions between ReadDir and Dir?

Ah, yeah, that must have been it.

@ChrisDenton

Copy link
Copy Markdown
Member

In that case, this seems fine.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1b3f10d has been approved by ChrisDenton

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 Sep 19, 2026
@RalfJung RalfJung mentioned this pull request Sep 19, 2026
1 of 12 tasks
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 19, 2026
add Dir::try_clone

There's no `try_clone` listed on rust-lang#120426 but I assume that's a standard operation for all kinds of file descriptors?

Cc @the8472 @ChrisDenton
rust-bors Bot pushed a commit that referenced this pull request Sep 19, 2026
Rollup of 6 pull requests

Successful merges:

 - #162228 (tests: Run more pauth tests in CI and make them pass)
 - #162990 (post GH comment on types nominations)
 - #162705 (Trigger "C array" parse error recovery in far fewer cases)
 - #162988 (recover `true` and `false` in type position as `bool`)
 - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics)
 - #163007 (add Dir::try_clone)
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 19, 2026
add Dir::try_clone

There's no `try_clone` listed on rust-lang#120426 but I assume that's a standard operation for all kinds of file descriptors?

Cc @the8472 @ChrisDenton
rust-bors Bot pushed a commit that referenced this pull request Sep 19, 2026
Rollup of 13 pull requests

Successful merges:

 - #158515 (Make let-else respect macro_rules expr metavariable grouping)
 - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor)
 - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner)
 - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes)
 - #162990 (post GH comment on types nominations)
 - #154665 (add safety section for mem::zeroed)
 - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription)
 - #162705 (Trigger "C array" parse error recovery in far fewer cases)
 - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt)
 - #162988 (recover `true` and `false` in type position as `bool`)
 - #162995 (Constify `impl FromStr for NonZero<T>`)
 - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics)
 - #163007 (add Dir::try_clone)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 19, 2026
add Dir::try_clone

There's no `try_clone` listed on rust-lang#120426 but I assume that's a standard operation for all kinds of file descriptors?

Cc @the8472 @ChrisDenton
rust-bors Bot pushed a commit that referenced this pull request Sep 19, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #158515 (Make let-else respect macro_rules expr metavariable grouping)
 - #162726 (std: fix unix socket address panic on a full sun_path)
 - #160028 (Better account for `Self` that might be a typo of `self`)
 - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor)
 - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner)
 - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes)
 - #162990 (post GH comment on types nominations)
 - #154665 (add safety section for mem::zeroed)
 - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription)
 - #162705 (Trigger "C array" parse error recovery in far fewer cases)
 - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt)
 - #162988 (recover `true` and `false` in type position as `bool`)
 - #162995 (Constify `impl FromStr for NonZero<T>`)
 - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics)
 - #163007 (add Dir::try_clone)
rust-bors Bot pushed a commit that referenced this pull request Sep 20, 2026
Rollup of 17 pull requests

Successful merges:

 - #158515 (Make let-else respect macro_rules expr metavariable grouping)
 - #160028 (Better account for `Self` that might be a typo of `self`)
 - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor)
 - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner)
 - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes)
 - #162990 (post GH comment on types nominations)
 - #153662 (Suggest fully qualified path on method name collision)
 - #154665 (add safety section for mem::zeroed)
 - #159787 (Prefer ModId in more places)
 - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription)
 - #162705 (Trigger "C array" parse error recovery in far fewer cases)
 - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt)
 - #162988 (recover `true` and `false` in type position as `bool`)
 - #162995 (Constify `impl FromStr for NonZero<T>`)
 - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics)
 - #163007 (add Dir::try_clone)
 - #163039 (Use verbose suggestion for parenthetical `Fn` notation and fully-qualified path on ambiguous assoc item)
rust-bors Bot pushed a commit that referenced this pull request Sep 20, 2026
Rollup of 17 pull requests

Successful merges:

 - #158515 (Make let-else respect macro_rules expr metavariable grouping)
 - #160028 (Better account for `Self` that might be a typo of `self`)
 - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor)
 - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner)
 - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes)
 - #162990 (post GH comment on types nominations)
 - #153662 (Suggest fully qualified path on method name collision)
 - #154665 (add safety section for mem::zeroed)
 - #159787 (Prefer ModId in more places)
 - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription)
 - #162705 (Trigger "C array" parse error recovery in far fewer cases)
 - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt)
 - #162988 (recover `true` and `false` in type position as `bool`)
 - #162995 (Constify `impl FromStr for NonZero<T>`)
 - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics)
 - #163007 (add Dir::try_clone)
 - #163039 (Use verbose suggestion for parenthetical `Fn` notation and fully-qualified path on ambiguous assoc item)
@rust-bors
rust-bors Bot merged commit 55518ef into rust-lang:main Sep 20, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 20, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 20, 2026
Rollup merge of #163007 - RalfJung:dirfd-clone, r=ChrisDenton

add Dir::try_clone

There's no `try_clone` listed on #120426 but I assume that's a standard operation for all kinds of file descriptors?

Cc @the8472 @ChrisDenton
@RalfJung
RalfJung deleted the dirfd-clone branch September 21, 2026 11:12
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.

4 participants