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

error-msg: expand suggestion for unused_def lint #109158

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

Ezrashaw
Copy link
Contributor

Fixes #108885

Expands let _ = .. suggestion into more positions.

@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2023

r? @oli-obk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 15, 2023
@Ezrashaw Ezrashaw force-pushed the expand-sugg-for-unused-lint branch from 629527c to 35103fe Compare March 15, 2023 10:30
@oli-obk
Copy link
Contributor

oli-obk commented Mar 15, 2023

r? @Nilstrieb

@rustbot rustbot assigned Noratrieb and unassigned oli-obk Mar 15, 2023
@@ -440,7 +432,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
cx,
def_id: *def_id,
note: *reason,
suggestion,
suggestion: (!is_inner)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only for the outermost one and not nested ones as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let-statements can't exist in the expression position. We don't want (get_result(), other_fn(), ...) to become (let _ = get_result(), other_fn(), ...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right, the spans

@@ -1390,7 +1390,7 @@ pub struct UnusedOp<'a> {
pub op: &'a str,
#[label]
pub label: Span,
#[suggestion(style = "verbose", code = "let _ = ", applicability = "machine-applicable")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could suggest using

_ = ...;

Instead? It silences the warning and looks a bit nicer & shorter IMO.

Copy link
Member

@Noratrieb Noratrieb Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, let _ is more widely used and understood and also nicer imo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it more idiomatic? I think the only reason let _ is used more, is that it was available since forever, while _ was added after that.

Copy link
Contributor Author

@Ezrashaw Ezrashaw Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, keep in mind that it is about more than just ignoring a value; you might want to bind it to a variable. Removing let preemptively makes using the value as opposed to ignoring it harder.

Also I'd like to keep the let anyway because it's much more common and IMHO conveys intent better.

@Noratrieb
Copy link
Member

Noratrieb commented Mar 15, 2023

I don't exactly love the structured suggestion (and would prefer a note myself), but it's already here so this just makes it more consistent, which is good.

@bors r+

Also the error reporting code of this lint is a huge mess and I'd love to see it improved (after I split it out from the checking phase some time ago)

@bors
Copy link
Contributor

bors commented Mar 15, 2023

📌 Commit 35103fe has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2023
@Ezrashaw
Copy link
Contributor Author

@Nilstrieb

Also the error reporting code of this lint is a huge mess and I'd love to see it improved (after I split it out from the checking phase some time ago)

Might work on this then! :)

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2023
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#108875 (rustdoc: fix type search for `Option` combinators)
 - rust-lang#108971 (error-msg: impl better suggestion for `E0532`)
 - rust-lang#109139 (rustdoc: DocFS: Replace rayon with threadpool and enable it for all targets)
 - rust-lang#109151 (Assert def-kind is correct for alias types)
 - rust-lang#109158 (error-msg: expand suggestion for `unused_def` lint)
 - rust-lang#109166 (make `define_opaque_types` fully explicit)
 - rust-lang#109171 (Some cleanups in our normalization logic)
 - rust-lang#109180 (Unequal → Not equal)
 - rust-lang#109185 (rustdoc: remove `std::` from primitive intra-doc link tooltips)
 - rust-lang#109192 (Mention UEFI target promotion in release notes for 1.67.0)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 36b8237 into rust-lang:master Mar 16, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 16, 2023
@Ezrashaw Ezrashaw deleted the expand-sugg-for-unused-lint branch March 17, 2023 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Irritating "unused" warning
6 participants