Skip to content

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

@dishmaker

Description

@dishmaker

I tried this code:

https://doc.rust-lang.org/std/fs/struct.FileTimes.html#method.set_modified

let ft = FileTimes::new();

ft.set_modified(modified);

I expected to see this happen: changed modified time.

Instead, this happened: nothing, because set_modified returns Self.

Maybe #[must_use] would prevent such bugs.

Meta

Related:

rustc --version --verbose:

rustc 1.95.0-nightly (db3e99bba 2026-02-04)
binary: rustc
commit-hash: db3e99bbab28c6ca778b13222becdea54533d908
commit-date: 2026-02-04
host: x86_64-pc-windows-msvc
release: 1.95.0-nightly
LLVM version: 22.1.0

Metadata

Metadata

Assignees

Labels

A-filesystemArea: `std::fs`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions