Skip to content

Prefer instant.elapsed() over Instant::now() - instant #8603

Closed
@frewsxcv

Description

@frewsxcv

What it does

Suggests using the helper shortcut method, which is shorter.

https://doc.rust-lang.org/stable/std/time/struct.Instant.html#method.elapsed

Lint Name

No response

Category

No response

Advantage

No response

Drawbacks

No response

Example

let prev_instant = Instant::now();
// ...
let duration = Instant::now() - prev_instant();

Could be written as:

let prev_instant = Instant::now();
// ...
let duration = prev_instant.elapsed();

Metadata

Metadata

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions