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

Use the precise namespace for Reverse #8461

Closed
ken-matsui opened this issue Feb 22, 2022 · 1 comment · Fixed by #8462
Closed

Use the precise namespace for Reverse #8461

ken-matsui opened this issue Feb 22, 2022 · 1 comment · Fixed by #8462
Assignees
Labels
A-lint Area: New lints

Comments

@ken-matsui
Copy link
Contributor

ken-matsui commented Feb 22, 2022

What it does

I would say the unnecessary_sort_by lint should use the precise namespace for Reverse.

Currently, it shows help like the following:

help: try: `args.sort_by_key(|b| Reverse(b.name()))`

It is not obvious where Reverse is; for instance, if users' code includes Reverse such as struct or impl, then this suggestion misleads them.
Accordingly, I would suggest using the precise namespace for Reverse as std::cmp::Reverse.

help: try: `args.sort_by_key(|b| std::cmp::Reverse(b.name()))`

Lint Name

unnecessary_sort_by

Example

The current help could be:

 error: use Vec::sort_by_key here instead
   --> $DIR/unnecessary_sort_by.rs:94:9
    |
 LL |         args.sort_by(|a, b| b.name().cmp(&a.name()));
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|b| Reverse(b.name()))`
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|b| std::cmp::Reverse(b.name()))`
@ken-matsui ken-matsui added the A-lint Area: New lints label Feb 22, 2022
@ken-matsui
Copy link
Contributor Author

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant