about summary refs log tree commit diff
path: root/src/tools/clippy/clippy_lints
AgeCommit message (Collapse)AuthorLines
2022-10-20rustc_hir_typeck: fix clippylcnr-9/+10
2022-10-20Implement assertions and fixes to not emit empty spans without suggestionsKevin Per-9/+14
2022-10-19Implement -Ztrack-diagnosticsmejrs-0/+1
2022-10-14Remove CastCheckResult since it's unusedMichael Goulet-12/+17
2022-10-10Rollup merge of #99696 - WaffleLapkin:uplift, r=fee1-deadDylan DPC-129/+6
Uplift `clippy::for_loops_over_fallibles` lint into rustc This PR, as the title suggests, uplifts [`clippy::for_loops_over_fallibles`] lint into rustc. This lint warns for code like this: ```rust for _ in Some(1) {} for _ in Ok::<_, ()>(1) {} ``` i.e. directly iterating over `Option` and `Result` using `for` loop. There are a number of suggestions that this PR adds (on top of what clippy suggested): 1. If the argument (? is there a better name for that expression) of a `for` loop is a `.next()` call, then we can suggest removing it (or rather replacing with `.by_ref()` to allow iterator being used later) ```rust for _ in iter.next() {} // turns into for _ in iter.by_ref() {} ``` 2. (otherwise) We can suggest using `while let`, this is useful for non-iterator, iterator-like things like [async] channels ```rust for _ in rx.recv() {} // turns into while let Some(_) = rx.recv() {} ``` 3. If the argument type is `Result<impl IntoIterator, _>` and the body has a `Result<_, _>` type, we can suggest using `?` ```rust for _ in f() {} // turns into for _ in f()? {} ``` 4. To preserve the original behavior and clear intent, we can suggest using `if let` ```rust for _ in f() {} // turns into if let Some(_) = f() {} ``` (P.S. `Some` and `Ok` are interchangeable depending on the type) I still feel that the lint wording/look is somewhat off, so I'll be happy to hear suggestions (on how to improve suggestions :D)! Resolves #99272 [`clippy::for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
2022-10-10Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8KiYuki Okushi-2/+2
rename `ImplItemKind::TyAlias` to `ImplItemKind::Type` The naming of this variant seems inconsistent given that this is not really a "type alias", and the associated type variant for `TraitItemKind` is just called `Type`.
2022-10-09deprecate `clippy::for_loops_over_fallibles`Maybe Waffle-129/+6
2022-10-09ImplItemKind::TyAlias => ImplItemKind::TypeMichael Goulet-2/+2
2022-10-07Auto merge of #102091 - RalfJung:const_err, r=oli-obkbors-1/+0
make const_err a hard error This lint has been deny-by-default with future incompat wording since [Rust 1.51](https://github.com/rust-lang/rust/pull/80394) and the stable release of this week starts showing it in cargo's future compat reports. I can't wait to finally get rid of at least some of the mess in our const-err-reporting-code. ;) r? `@oli-obk` Fixes https://github.com/rust-lang/rust/issues/71800 Fixes https://github.com/rust-lang/rust/issues/100114
2022-10-07make const_err a hard errorRalf Jung-1/+0
2022-10-07Change InferCtxtBuilder from enter to buildCameron Steffen-63/+52
2022-10-07Introduce TypeErrCtxtCameron Steffen-2/+2
TypeErrCtxt optionally has a TypeckResults so that InferCtxt doesn't need to.
2022-10-06Merge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyupPhilipp Krones-13/+7
2022-10-06Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyupPhilipp Krones-2318/+3300
2022-10-04It's not about types or consts, but the lack of regionsOli Scherer-1/+1
2022-10-01Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebankbors-10/+9
Move lint level source explanation to the bottom So, uhhhhh r? `@estebank` ## User-facing change "note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic: ```diff - = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678> + = note: `#[warn(unsupported_calling_conventions)]` on by default ``` Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO. ## Developer-facing change `struct_span_lint` and similar methods have a different signature. Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)` After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion. Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere. ## Subtle problem By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings... I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate. ## P.S. I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2022-10-01clippy: adopt to the new lint APIMaybe Waffle-10/+9
2022-09-29Shrink `hir::def::Res`.Nicholas Nethercote-3/+8
`Res::SelfTy` currently has two `Option`s. When the second one is `Some` the first one is never consulted. So we can split it into two variants, `Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res` from 24 bytes to 12. This then shrinks `hir::Path` and `hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-27rustc_typeck to rustc_hir_analysislcnr-23/+23
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-24separate definitions and `HIR` ownersTakayuki Maeda-78/+78
fix a ui test use `into` fix clippy ui test fix a run-make-fulldeps test implement `IntoQueryParam<DefId>` for `OwnerId` use `OwnerId` for more queries change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-23Auto merge of #102056 - b-naber:unevaluated, r=lcnrbors-1/+1
Introduce mir::Unevaluated Previously the distinction between unevaluated constants in the type-system and in mir was not explicit and a little confusing. Probably better to introduce its own type for that. r? `@lcnr`
2022-09-23rename Unevaluated to UnevaluatedConstb-naber-1/+1
2022-09-22Rollup merge of #102123 - schteve:clippy-note, r=ManishearthMatthias Krüger-0/+4
Add note to clippy::non_expressive_names doc Addresses confusion in rust-lang/rust-clippy#9514 by updating the lint docs.
2022-09-22introduce mir::Unevaluatedb-naber-1/+1
2022-09-21Add note to clippy::non_expressive_names docSteve Heindel-0/+4
2022-09-21Merge commit '7248d06384c6a90de58c04c1f46be88821278d8b' into sync-from-clippyDavid Koloski-674/+543
2022-09-19remove the `Subst` trait, always use `EarlyBinder`lcnr-6/+2
2022-09-15Fix clippyest31-1/+1
2022-09-15Auto merge of #101811 - flip1995:clippyup, r=flip1995bors-3/+2
Clippy pre beta branch fix Before beta is branched on Friday, I want to move the `unused_peekable` lint that was added in this release cycle (1.65) to `nursery`. This lint was already reported twice (https://github.com/rust-lang/rust-clippy/issues/9456, https://github.com/rust-lang/rust-clippy/issues/9462) in a short time, so it is probably a good idea to fix it before it hits beta and then stable. r? `@Manishearth`
2022-09-14Temporarily move clippy::unused_peekable to nurseryPhilipp Krones-3/+2
2022-09-14Auto merge of #101212 - eholk:dyn-star, r=compiler-errorsbors-2/+2
Initial implementation of dyn* This PR adds extremely basic and incomplete support for [dyn*](https://smallcultfollowing.com/babysteps//blog/2022/03/29/dyn-can-we-make-dyn-sized/). The goal is to get something in tree behind a flag to make collaboration easier, and also to make sure the implementation so far is not unreasonable. This PR does quite a few things: * Introduce `dyn_star` feature flag * Adds parsing for `dyn* Trait` types * Defines `dyn* Trait` as a sized type * Adds support for explicit casts, like `42usize as dyn* Debug` * Including const evaluation of such casts * Adds codegen for drop glue so things are cleaned up properly when a `dyn* Trait` object goes out of scope * Adds codegen for method calls, at least for methods that take `&self` Quite a bit is still missing, but this gives us a starting point. Note that this is never intended to become stable surface syntax for Rust, but rather `dyn*` is planned to be used as an implementation detail for async functions in dyn traits. Joint work with `@nikomatsakis` and `@compiler-errors.` r? `@bjorn3`
2022-09-14Auto merge of #101709 - nnethercote:simplify-visitors-more, r=cjgillotbors-10/+10
Simplify visitors more A successor to #100392. r? `@cjgillot`
2022-09-13Address code review commentsEric Holk-19/+8
2022-09-13Auto merge of #100640 - reitermarkus:socket-display-buffer, r=thomccbors-26/+60
Use `DisplayBuffer` for socket addresses. Continuation of https://github.com/rust-lang/rust/pull/100625 for socket addresses. Renames `net::addr` to `net::addr::socket`, `net::ip` to `net::addr::ip` and `net::ip::display_buffer::IpDisplayBuffer` to `net::addr::display_buffer::DisplayBuffer`.
2022-09-12Make x.py check workEric Holk-9/+20
2022-09-12Simplify `clippy` fix.Markus Reiter-37/+22
2022-09-12Fix clippy.Markus Reiter-16/+65
2022-09-12Auto merge of #99334 - NiklasJonsson:84447/error-privacy, r=oli-obkbors-4/+3
rustc_error, rustc_private: Switch to stable hash containers Relates https://github.com/rust-lang/rust/issues/84447
2022-09-12Remove unused argument from `visit_poly_trait_ref`.Nicholas Nethercote-6/+6
2022-09-12Remove unused span argument from `walk_fn`.Nicholas Nethercote-4/+4
2022-09-10Auto merge of #98559 - jackh726:remove-reempty, r=oli-obkbors-1/+1
Remove ReEmpty r? rust-lang/types
2022-09-10rustc_error, rustc_private, rustc_ast: Switch to stable hash containersNiklas Jonsson-4/+3
2022-09-09Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyupPhilipp Krones-440/+737
2022-09-09Appease clippy againMichael Goulet-6/+4
2022-09-09Make clippy happyMichael Goulet-2/+4
2022-09-08Remove ReEmptyJack Huey-1/+1
2022-09-08Auto merge of #101577 - Dylan-DPC:rollup-l9xw7i7, r=Dylan-DPCbors-207/+207
Rollup of 7 pull requests Successful merges: - #98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes) - #101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2) - #101424 (Adjust and slightly generalize operator error suggestion) - #101496 (Allow lower_lifetime_binder receive a closure) - #101501 (Allow lint passes to be bound by `TyCtxt`) - #101515 (Recover from typo where == is used in place of =) - #101545 (Remove unnecessary `PartialOrd` and `Ord`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-09-08Rollup merge of #101501 - Jarcho:tcx_lint_passes, r=davidtwcoDylan DPC-207/+207
Allow lint passes to be bound by `TyCtxt` This will allow storing things like `Ty<'tcx>` inside late lint passes. It's already possible to store various id types so they're already implicitly bound to a specific `TyCtxt`. r? rust-lang/compiler
2022-09-08Auto merge of #101467 - nnethercote:shrink-hir-Ty-Pat, r=spastorinobors-6/+13
Shrink `hir::Ty` and `hir::Pat` r? `@ghost`