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

Port clippy lint redundant_field_names to compiler #87512

Closed
wants to merge 10 commits into from

Conversation

fee1-dead
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive
Copy link
Collaborator

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

⚠️ Warning ⚠️

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2021
@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead marked this pull request as draft July 27, 2021 15:23
@camsteffen
Copy link
Contributor

I think we should remove the lint from Clippy in the same PR.

The lint really should be named redundant_field_initializers or field_init_same_name or field_init_repeats_name.

Are we okay with uplifting this, warn by default, with the possibility of enhancing it if we allow Struct { &foo }? (I think that's fine).

Can we put this in the nonstandard-style group? It seems like rustc is lacking a "style" group for slightly more picky lints. Someone will say that such lints belong in Clippy, but I'm not so sure. This lint feels like it could be in rustc.

If this lint triggers in macros for $a: $b, that's probably a deal-breaker. Maybe we can detect cases like $a: $a.

@fee1-dead
Copy link
Member Author

Can we put this in the nonstandard-style group?

I don't think so because AFAIK that group is only used for lints with nonstandard naming conventions.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 31, 2021

☔ The latest upstream changes (presumably #86754) made this pull request unmergeable. Please resolve the merge conflicts.

@fee1-dead fee1-dead force-pushed the clippy-lint branch 2 times, most recently from 499bf00 to 59ac5e3 Compare July 31, 2021 04:00
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead marked this pull request as ready for review August 1, 2021 10:36
@bors
Copy link
Contributor

bors commented Aug 2, 2021

☔ The latest upstream changes (presumably #86031) made this pull request unmergeable. Please resolve the merge conflicts.

@fee1-dead fee1-dead marked this pull request as draft August 2, 2021 09:57
@fee1-dead fee1-dead marked this pull request as ready for review August 8, 2021 08:46
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member

This could be considered in the same category, but it is not an instance of code that seems like it was intended to be used, or reflective of a misunderstanding as with a false invocation of unsafe, it is simply a bit of repetition. This has usually not merited a lint in rustc, and indeed the language actually favors repetition as with e.g. trailing commas where it would make things easier to rename and refactor... as might be a sensible choice here.

Many lints have been uplifted from clippy in the past, and I would honestly be happy to see more. But what I mean is that previously many of the lints that were uplifted from clippy were correctness lints (of which there are even now many that seem like good candidates) and were both motivated and granted on such a reason. Most of the interest I have seen expressed that aim, and your excerpt comes right next to these quotes:

Care should be taken when adding warnings to avoid warning fatigue, and avoid false-positives where there really isn't a problem with the code.

Code that is very likely to be incorrect, dangerous, or confusing, but the language technically allows

Yes, there are projects that have an MSRV below 1.17: serde is one of them.

@Mark-Simulacrum
Copy link
Member

@joshtriplett said in this zulip thread that he would like to see clippy lints uplifted.

I am pretty sure that the interpretation here is not that all clippy lints should be uplifted, but rather that approval of lints for uplift via targeted PRs or T-lang MCPs is much more likely to be a successful path toward a decision, as opposed to the prior art at the time of that comment, which was an issue proposing lots of lints to be moved.

Personally, I tend to agree with @workingjubilee that it feels like this lint definitely belongs either in clippy or as an allow-by-default lint; it's primarily a stylistic lint, and doesn't necessarily mean that all people will want to write their code like this. I'd personally be frustrated when seeing a warning on this pattern because the code is equally correct either way and not really significantly more verbose or anything like that.

@Mark-Simulacrum Mark-Simulacrum added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 12, 2021
@camsteffen
Copy link
Contributor

Without a lint category, it doesn't really make sense to uplift. I think rustc should have an allow-by-default category for lints like this:

  • clearly more idiomatic
  • purely stylistic, non-critical, low-risk
  • lints usage of a language feature or prelude items (generally not std API usage)
  • the scope of the lint is clear and simple with no perceivable future enhancements

Some candidates: needless_return, write_with_newline, writeln_empty_string, redundant_pattern, redundant_static_lifetimes, single_match, unused_unit

There is a very large gap between rustc lints and Clippy lints in terms of stability, false positive rate, lint pickiness, opinionatedness. Of course some of the "blame" falls squarely on Clippy to fix bugs, remove un-useful lints, etc. But Clippy will likely never have the level of stability that rustc has as it is sort of a playground for new lints. A rustc lint category can bridge that gap a bit for people who want rustc to be just a little more picky, but in a highly stable way.

@workingjubilee
Copy link
Member

workingjubilee commented Sep 20, 2021

I understand Clippy has a lot of highly experimental lints, but are we sure there isn't any chance that Clippy could make the first move on growing such a "low stress" mode where it just emits warnings on lints with stronger consensus behind them? It would seem an appropriate "proof of concept" for the idea, at least.

Clippy is often run in CI for Rust projects and if it denies something then CI doesn't pass. And a lot of projects run -D warnings in CI, so if Clippy is pretty unstable on warnings then that is probably a bit of a problem, too. It may be a good idea to more actively rein that in somewhat, or at least use the nursery category a bit more freely when it becomes apparent a lint is more half-baked than expected.

@bors
Copy link
Contributor

bors commented Sep 26, 2021

☔ The latest upstream changes (presumably #88316) made this pull request unmergeable. Please resolve the merge conflicts.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 9, 2021
@fee1-dead fee1-dead added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 11, 2021
@nikomatsakis
Copy link
Contributor

@rfcbot fcp close

We discussed in the @rust-lang/lang meeting today. The consensus of the meeting was that we ought to close this PR. We generally prefer to limit uplift to lints that fix known bugs and have a very limited set of "false warnings". This case seems to be a conventions question and we would prefer to keep such work within clippy.

Thanks @fee1-dead for raising the question!

@rfcbot
Copy link

rfcbot commented Oct 12, 2021

Team member @nikomatsakis has proposed to close this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-close This PR / issue is in PFCP or FCP with a disposition to close it. labels Oct 12, 2021
@nikomatsakis
Copy link
Contributor

One side note: My actual preference would be to remove most style lints but to have rustfmt silently remove and edit cases like this. That way we don't bother our users with it but we also see the edits applied consistently across Rust code. I think that would be best discussed with the @rust-lang/wg-rustfmt team, though, and perhaps even wants an RFC for broader discussion (I think it's a bit of a policy change from how rustfmt does things now).

@calebcartwright
Copy link
Member

One side note: My actual preference would be to remove most style lints but to have rustfmt silently remove and edit cases like this. That way we don't bother our users with it but we also see the edits applied consistently across Rust code. I think that would be best discussed with the @rust-lang/wg-rustfmt team, though, and perhaps even wants an RFC for broader discussion (I think it's a bit of a policy change from how rustfmt does things now).

fwiw we do already have a number of these covered via config options in rustfmt (e.g. I gather use_field_init_shorthand could be of use in this case), but they're often turned off by default.

As you alluded to, we don't have the flexibility today to intentionally change rustfmt in such a way that an updated version introduces formatting changes. However, there's at least a couple changes I think we need to try to get pushed through anyway to get rid of some odd formatting behavior that's no longer necessary, and that could potentially provide a window for the some of the other changes you have in mind too (if we do end up introducing formatting changes then they'd ideally come in one batch so users can rustup update && cargo fmt once and be done with it).

Will likely be a topic of discussion at an upcoming dev tools meeting

@rfcbot
Copy link

rfcbot commented Oct 19, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 19, 2021
@scottmcm
Copy link
Member

I'm totally ok with this staying in clippy, so I've ✅'d here.

That said, I wonder if there's a more restricted subset of this that's unambiguous enough to have in rustc, like how unused_parens doesn't actually lint on all unnecessary parens -- we don't lint (1 * 2) + 3, for example.

For example, I might not say that rustc should lint on

   Foo {
       x: foo(),
       y: y,
       z: bar(),
   }

but I would be happy for it to lint on

    Foo { x: x, y: y, z: z }

(like one might see in Foo::new)

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 29, 2021
@rfcbot
Copy link

rfcbot commented Oct 29, 2021

The final comment period, with a disposition to close, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Oct 29, 2021
@fee1-dead fee1-dead closed this Oct 29, 2021
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. disposition-close This PR / issue is in PFCP or FCP with a disposition to close it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.