about summary refs log tree commit diff
path: root/src/tools/clippy
AgeCommit message (Collapse)AuthorLines
2022-05-25try to cache region_scope_tree as a queryDing Xiang Fei-15/+3
2022-05-24Auto merge of #96098 - JakobDegen:always-return-place, r=oli-obkbors-2/+3
Refactor call terminator to always include destination place In #71117 people seemed to agree that call terminators should always have a destination place, even if the call was guaranteed to diverge. This implements that. Unsurprisingly, the diff touches a lot of code, but thankfully I had to do almost nothing interesting. The only interesting thing came up in const prop, where the stack frame having no return place was also used to indicate that the layout could not be computed (or similar). I replaced this with a ZST allocation, which should continue to do the right things. cc `@RalfJung` `@eddyb` who were involved in the original conversation r? rust-lang/mir-opt
2022-05-24Rollup merge of #97289 - compiler-errors:tcxify-clippy, r=Mark-SimulacrumYuki Okushi-24/+24
Lifetime variance fixes for clippy #97287 migrates rustc to a `Ty` type that is invariant over its lifetime `'tcx`, so I need to fix a bunch of places that assume that `Ty<'a>` and `Ty<'b>` can be shortened to some common lifetime. This is doable, since everything is already `'tcx`, so all this PR does is be a bit more explicit that elided lifetimes are actually `'tcx`. Split out from #97287 so the clippy team can review independently.
2022-05-23Refactor call terminator to always hold a destination placeJakob Degen-2/+3
2022-05-23Lifetime variance fixes for clippyMichael Goulet-24/+24
2022-05-23Rollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillotDylan DPC-1/+1
Remove feature: `crate` visibility modifier FCP completed in #53120.
2022-05-22Fix clippy explicit_write lint for new writeln implementationDavid Tolnay-2/+34
2022-05-22factor out the rvalue lifetime ruleDing Xiang Fei-46/+76
remove region_scope_tree from RegionCtxt Apply suggestions from code review Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-05-21Merge crate and restricted visibilitiesJacob Pratt-1/+1
2022-05-21Remove feature: `crate` visibility modifierJacob Pratt-1/+1
2022-05-21Fix lint registrationxFrednet-1/+0
2022-05-21Merge 'rust-clippy/master' into clippyupxFrednet-1711/+4449
2022-05-21Auto merge of #96923 - eholk:fix-fake-read, r=nikomatsakisbors-5/+5
Drop Tracking: Implement `fake_read` callback This PR updates drop tracking's use of `ExprUseVisitor` so that we treat `fake_read` events as borrows. Without doing this, we were not handling match expressions correctly, which showed up as a breakage in the `addassign-yield.rs` test. We did not previously notice this because we still had rather large temporary scopes that we held borrows for, which changed in #94309. This PR also includes a variant of the `addassign-yield.rs` test case to make sure we continue to have correct behavior here with drop tracking. r? `@nikomatsakis`
2022-05-18Auto merge of #96863 - SparrowLii:let, r=michaelwoeristerbors-12/+14
use `hir::Let` in `hir::Guard::IfLet` This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`
2022-05-17Auto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitorbors-2/+2
Rollup of 7 pull requests Successful merges: - #96329 (Add a couple tests for #90887 fixes) - #97009 (Allow `unused_macro_rules` in path tests) - #97075 (Add regression test for #81804) - #97079 (Change `Successors` to `impl Iterator<Item = BasicBlock>`) - #97080 (remove the `RelateResultCompare` trait) - #97093 (Migrate `maybe_recover_from_bad_type_plus` diagnostic) - #97102 (Update function pointer call error message) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-05-17Rollup merge of #97079 - SparrowLii:successors, r=lcnrYuki Okushi-2/+2
Change `Successors` to `impl Iterator<Item = BasicBlock>` This PR fixes the FIXME in `compiler\rustc_middle\src\mir\mod.rs`. This can omit several `&`, `*` or `cloned` operations on Successros' generated elements
2022-05-17Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwcobors-2/+1
Add a query for checking whether a function is an intrinsic. work towards #93145 This will reduce churn when we add more ways to declare intrinsics r? `@scottmcm`
2022-05-17Auto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgillotbors-35/+23
Retire `ItemLikeVisitor` trait Issue #95004 cc `@cjgillot`
2022-05-17Change `Successors` to `impl Iterator<Item = BasicBlock>`SparrowLii-2/+2
2022-05-16Add a query for checking whether a function is an intrinsic.Oli Scherer-2/+1
2022-05-14Auto merge of #96883 - jackh726:early-binder-2, r=oli-obkbors-8/+8
Add EarlyBinder Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L1308). Everything is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk. Either way, tracking when we have or haven't already substituted out these in rustc can be helpful. As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted. r? `@nikomatsakis`
2022-05-13Add bound_fn_sigJack Huey-2/+2
2022-05-13Add bound_type_ofJack Huey-6/+6
2022-05-13remove TestItemNamesVisitorMiguel Guarniz-35/+23
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-12Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwcobors-45/+27
don't encode only locally used attrs Part of https://github.com/rust-lang/compiler-team/issues/505. We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR. After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates. cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-11Bless clippy.Camille GILLOT-1/+9
2022-05-10Introduce EarlyBinderJack Huey-12/+12
2022-05-10Update clippy to new rake_read signatureEric Holk-5/+5
2022-05-10update clippylcnr-45/+27
2022-05-09fix clippySparrowLii-12/+14
2022-05-09Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiserbors-0/+182
Support tool lints with the `#[expect]` attribute (RFC 2383) This PR fixes the ICE https://github.com/rust-lang/rust/issues/94953 by making the assert for converted expectation IDs conditional. Additionally, it moves the lint expectation check into a separate query to support rustdoc and other tools. On the way, I've also added some tests to ensure that the attribute works for Clippy and rustdoc lints. The number of changes comes from the long test file. This may look like a monster PR, this may smell like a monster PR and this may be a monster PR, but it's a harmless monster. :sauropod: --- Closes: https://github.com/rust-lang/rust/issues/94953 cc: https://github.com/rust-lang/rust/issues/85549 r? `@wesleywiser` cc: `@rust-lang/rustdoc`
2022-05-08Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillotbors-26/+14
Track if a where bound comes from a impl Trait desugar With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering. r? `@cjgillot` cc `@estebank` (as the reviewer of #93803)
2022-05-08Test `expect` attribute for tool lints, clippy edition (RFC 2383)xFrednet-0/+182
2022-05-08Auto merge of #94206 - PrestonFrom:significant_drop, r=flip1995bors-0/+1201
Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions A new clippy lint for issue 93883 (https://github.com/rust-lang/rust/issues/93883). Relies on a new trait in `marker` (called `SignificantDrop` to enable linting), which is why this PR is for the rust-lang repo and not the clippy repo. changelog: new lint [`significant_drop_in_scrutinee`]
2022-05-07Track if a where bound comes from a impl Trait desugarflip1995-4/+8
With #93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a impl Trait or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during HIR lowering.
2022-05-06Lint for significant drops who may have surprising lifetimes #1Preston From-0/+1201
author Preston From <prestonfrom@gmail.com> 1645164142 -0600 committer Preston From <prestonfrom@gmail.com> 1650005351 -0600
2022-05-07Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, ↵bors-6/+6
r=cjgillot Remove ItemLikeVisitor impls from rustc_typeck Issue #95004 cc `@cjgillot`
2022-05-06Rollup merge of #96557 - nbdd0121:const, r=oli-obkGuillaume Gomez-1/+1
Allow inline consts to reference generic params Tracking issue: #76001 The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well. However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have: ```rust fn foo<T>() { let x = [4i32; std::mem::size_of::<T>()]; // NOT ALLOWED (for now) let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR! let x = [4i32; const { std::mem::size_of::<T>() }]; // NOT ALLOWED (for now) } ``` This would make inline consts super useful for compile-time checks and assertions: ```rust fn assert_zst<T>() { const { assert!(std::mem::size_of::<T>() == 0) }; } ``` This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do: ```rust fn assert_zst<T>() { struct F<T>(T); impl<T> F<T> { const V: () = assert!(std::mem::size_of::<T>() == 0); } let _ = F::<T>::V; } ``` It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either: ```rust fn foo<T>() -> usize { let (_, size): (PhantomData<T>, usize) = const { const fn my_size_of<T>() -> (PhantomData<T>, usize) { (PhantomData, std::mem::size_of::<T>()) } my_size_of() }; size } ``` ```@rustbot``` label: F-inline_const
2022-05-06use def_span and def_kind queries instead of calling tcx.hir() methodsMiguel Guarniz-6/+6
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-05(Partially) Revert "HACK: Move buggy lints to nursery"flip1995-22/+6
This reverts commit bb01aca86f66954b80798213711e8eadc4b26902. Partial: Keep regression tests
2022-05-05Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyupflip1995-2639/+6204
2022-05-05Bless clippy error msgGary Guo-1/+1
2022-05-04Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkovbors-1/+2
Overhaul `MacArgs` Motivation: - Clarify some code that I found hard to understand. - Eliminate one use of three places where `TokenKind::Interpolated` values are created. r? `@petrochenkov`
2022-05-05Overhaul `MacArgs::Eq`.Nicholas Nethercote-1/+2
The value in `MacArgs::Eq` is currently represented as a `Token`. Because of `TokenKind::Interpolated`, `Token` can be either a token or an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a literal or macro call AST fragment, and then is later lowered to a literal token. But this is very non-obvious. `Token` is a much more general type than what is needed. This commit restricts things, by introducing a new type `MacArgsEqKind` that is either an AST expression (pre-lowering) or an AST literal (post-lowering). The downside is that the code is a bit more verbose in a few places. The benefit is that makes it much clearer what the possibilities are (though also shorter in some other places). Also, it removes one use of `TokenKind::Interpolated`, taking us a step closer to removing that variant, which will let us make `Token` impl `Copy` and remove many "handle Interpolated" code paths in the parser. Things to note: - Error messages have improved. Messages like this: ``` unexpected token: `"bug" + "found"` ``` now say "unexpected expression", which makes more sense. Although arbitrary expressions can exist within tokens thanks to `TokenKind::Interpolated`, that's not obvious to anyone who doesn't know compiler internals. - In `parse_mac_args_common`, we no longer need to collect tokens for the value expression.
2022-05-03Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwcobors-2/+3
Make rustc_parse_format compile on stable This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.
2022-05-03Make rustc_parse_format compile on stablebjorn3-2/+3
This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.
2022-05-02rustc: Panic by default in `DefIdTree::parent`Vadim Petrochenkov-9/+9
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root. So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root. Same applies to `local_parent`/`opt_local_parent`.
2022-04-30Fix the clippy buildScott McMurray-0/+1
2022-04-30Bless tests.Camille GILLOT-14/+2
2022-04-30Store all generic bounds as where predicates.Camille GILLOT-43/+41