Skip to content

Add #[must_use] to FileTimes::set_accessed and set_modified#152522

Closed
yashhzd wants to merge 1 commit intorust-lang:mainfrom
yashhzd:fix/filetimes-must-use
Closed

Add #[must_use] to FileTimes::set_accessed and set_modified#152522
yashhzd wants to merge 1 commit intorust-lang:mainfrom
yashhzd:fix/filetimes-must-use

Conversation

@yashhzd
Copy link

@yashhzd yashhzd commented Feb 12, 2026

Summary

FileTimes::set_accessed and FileTimes::set_modified take self by value and return Self (builder pattern). Without #[must_use], calling ft.set_modified(time) without using the return value silently does nothing, which is a common source of bugs.

This PR adds #[must_use] to both methods so that the compiler warns when the return value is discarded.

Example of the bug this prevents:

let ft = FileTimes::new();
ft.set_modified(modified); // silently does nothing - no warning!

With this change, the compiler will emit a warning for the above code, guiding users to use the builder pattern correctly:

let ft = FileTimes::new().set_modified(modified); // correct usage

Fixes #152231

These methods take `self` by value and return `Self` (builder pattern).
Without `#[must_use]`, calling `ft.set_modified(time)` without using
the return value silently does nothing, which is a common mistake.

Fixes rust-lang#152231
@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 Feb 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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 8 candidates
  • Random selection from ChrisDenton, Mark-Simulacrum

@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@chenyukang
Copy link
Member

there is already a PR for it: #152232

@chenyukang
Copy link
Member

chenyukang commented Feb 12, 2026

Hi. It looks like you used an LLM without reviewing its output sufficiently. At that point we become the reviewer of the LLM output, with you relaying our reviews back to the LLM as a proxy. That is a lot of work without a clear benefit, while being also frustrating for reviewers.

I am thus closing and locking this PR.

This is a moderation warning. Repeated instances of such comments or contributions will result in a ban from our project. You can contact the moderation team to discuss your warning.

@chenyukang chenyukang closed this Feb 12, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 12, 2026
@rust-lang rust-lang locked as spam and limited conversation to collaborators Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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.

FileTimes::set_modified does not modify the time, but returns FileTimes

4 participants