Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #79
frewsxcv opened this issue Mar 29, 2022 · 2 comments · Fixed by #9264
Closed
Tracked by #79

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

frewsxcv opened this issue Mar 29, 2022 · 2 comments · Fixed by #9264
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Mar 29, 2022

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();
@frewsxcv frewsxcv added the A-lint Area: New lints label Mar 29, 2022
@Serial-ATA
Copy link
Contributor

@rustbot label +good-first-issue

@rustbot rustbot added the good-first-issue These issues are a good way to get started with Clippy label Apr 26, 2022
@Alastair-smith2
Copy link

@rustbot claim

bors added a commit that referenced this issue Aug 2, 2022
Add `elapsed_instant` lint

Closes #8603

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog: [`elapsed_instant`]: Add lint
@bors bors closed this as completed in 0696624 Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants