summary refs log tree commit diff
path: root/src/tools/clippy/tests
AgeCommit message (Collapse)AuthorLines
2024-04-25Auto merge of #12617 - y21:issue-12616, r=Alexendoobors-0/+33
avoid an ICE in `ptr_as_ptr` when getting the def_id of a local Fixes #12616 `Res::def_id` can panic, so avoid calling it in favor of `opt_def_id`, so we can gracefully handle resolutions that don't have a `DefId` (e.g. local variables) and get a false negative in the worst case, rather than an ICE changelog: Fix ICE in [`ptr_as_ptr`] when the cast expression is a function call to a local variable
2024-04-25Auto merge of #12508 - y21:issue12506, r=llogiqbors-87/+115
Fix infinite loop in `cast_sign_loss` when peeling unwrap method calls Fixes #12506 The lint wants to peel method calls but didn't actually reassign the expression, leading to an infinite loop. ---- changelog: Fix infinite loop in [`cast_sign_loss`] when having two chained `.unwrap()` calls
2024-04-25Auto merge of #12486 - J-ZhengLi:issue12435, r=y21bors-4/+130
don't lint [`mixed_attributes_style`] when mixing docs and other attrs fixes: #12435 fixes: #12436 fixes: #12530 --- changelog: don't lint [`mixed_attributes_style`] when mixing different kind of attrs; and move it to late pass;
2024-03-09Allow lint where we don't careNadrieril-19/+21
2024-03-07Merge commit '93f0a9a91f58c9b2153868f458402155fb6265bb' into ↵Philipp Krones-457/+1550
clippy-subtree-update
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-3/+8
2024-03-01If suggestion would leave an empty line, delete itclubby789-14/+0
2024-02-29Rollup merge of #121669 - nnethercote:count-stashed-errs-again, r=estebankGuillaume Gomez-0/+17
Count stashed errors again Stashed diagnostics are such a pain. Their "might be emitted, might not" semantics messes with lots of things. #120828 and #121206 made some big changes to how they work, improving some things, but still leaving some problems, as seen by the issues caused by #121206. This PR aims to fix all of them by restricting them in a way that eliminates the "might be emitted, might not" semantics while still allowing 98% of their benefit. Details in the individual commit logs. r? `@oli-obk`
2024-02-29Overhaul how stashed diagnostics work, again.Nicholas Nethercote-0/+17
Stashed errors used to be counted as errors, but could then be cancelled, leading to `ErrorGuaranteed` soundness holes. #120828 changed that, closing the soundness hole. But it introduced other difficulties because you sometimes have to account for pending stashed errors when making decisions about whether errors have occured/will occur and it's easy to overlook these. This commit aims for a middle ground. - Stashed errors (not warnings) are counted immediately as emitted errors, avoiding the possibility of forgetting to consider them. - The ability to cancel (or downgrade) stashed errors is eliminated, by disallowing the use of `steal_diagnostic` with errors, and introducing the more restrictive methods `try_steal_{modify,replace}_and_emit_err` that can be used instead. Other things: - `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both return `Option<ErrorGuaranteed>`, which enables the removal of two `delayed_bug` calls and one `Ty::new_error_with_message` call. This is possible because we store error guarantees in `DiagCtxt::stashed_diagnostics`. - Storing the guarantees also saves us having to maintain a counter. - Calls to the `stashed_err_count` method are no longer necessary alongside calls to `has_errors`, which is a nice simplification, and eliminates two more `span_delayed_bug` calls and one FIXME comment. - Tests are added for three of the four fixed PRs mentioned below. - `issue-121108.rs`'s output improved slightly, omitting a non-useful error message. Fixes #121451. Fixes #121477. Fixes #121504. Fixes #121508.
2024-02-28Use `LitKind::Err` for floats with empty exponents.Nicholas Nethercote-12/+1
This prevents a follow-up type error in a test, which seems fine.
2024-02-27Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into ↵Philipp Krones-9416/+11604
clippy-subtree-update
2024-02-25Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkinbors-73/+86
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-20Auto merge of #121087 - oli-obk:eager_const_failures, r=lcnrbors-64/+23
Always evaluate free constants and statics, even if previous errors occurred work towards https://github.com/rust-lang/rust/issues/79738 We will need to evaluate static items before the `definitions.freeze()` below, as we will start creating new `DefId`s (for nested allocations) within the `eval_static_initializer` query. But even without that motivation, this is a good change. Hard errors should always be reported and not silenced if other errors happened earlier.
2024-02-19Always evaluate free constants and statics, even if previous errors occurredOli Scherer-64/+23
2024-02-19Remove suspicious auto trait lintSantiago Pastorino-27/+26
2024-02-17Allow newly added non_local_definitions lint in clippyUrgau-73/+86
2024-02-14Fix msg for verbose suggestions with confusable capitalizationEsteban Küber-1/+1
When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions). The logic to do this was already present, but implemented incorrectly.
2024-02-12Rollup merge of #118983 - Urgau:invalid_ref_casting-bigger-layout, r=oli-obkMatthias Krüger-11/+11
Warn on references casting to bigger memory layout This PR extends the [`invalid_reference_casting`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#invalid-reference-casting) lint (*deny-by-default*) which currently lint on `&T -> &mut T` casting to also lint on `&(mut) A -> &(mut) B` where `size_of::<B>() > size_of::<A>()` (bigger memory layout requirement). The goal is to detect such cases: ```rust let u8_ref: &u8 = &0u8; let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) }; //~^ ERROR casting references to a bigger memory layout is undefined behavior let mat3 = Mat3 { a: Vec3(0i32, 0, 0), b: Vec3(0, 0, 0), c: Vec3(0, 0, 0) }; let mat3 = unsafe { &*(&mat3 as *const _ as *const [[i64; 3]; 3]) }; //~^ ERROR casting references to a bigger memory layout is undefined behavior ``` This is added to help people who write unsafe code, especially when people have matrix struct that they cast to simple array of arrays. EDIT: One caveat, due to the [`&Header`](https://github.com/rust-lang/unsafe-code-guidelines/issues/256) uncertainty the lint only fires when it can find the underline allocation. ~~I have manually tested all the new expressions that warn against Miri, and they all report immediate UB.~~ r? ``@est31``
2024-02-12Avoid UB in clippy transmute_ptr_to_ptr UI testUrgau-11/+11
2024-02-12Tweak delayed bug mentions.Nicholas Nethercote-1/+1
Now that we have both `delayed_bug` and `span_delayed_bug`, it makes sense to use the generic term "delayed bug" more.
2024-02-08Merge commit '60cb29c5e4f9772685c9873752196725c946a849' into clippyupPhilipp Krones-239/+2231
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-2/+2
2024-02-05Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillotMatthias Krüger-20/+12
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error. This is part of implementing https://github.com/rust-lang/rfcs/pull/3535. Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint. https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-01-31Don't hash lints differently to non-lints.Nicholas Nethercote-2/+15
`Diagnostic::keys`, which is used for hashing and equating diagnostics, has a surprising behaviour: it ignores children, but only for lints. This was added in #88493 to fix some duplicated diagnostics, but it doesn't seem necessary any more. This commit removes the special case and only four tests have changed output, with additional errors. And those additional errors aren't exact duplicates, they're just similar. For example, in src/tools/clippy/tests/ui/same_name_method.rs we currently have this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ ``` and with this change we also get this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:81:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ ``` I think printing this second argument is reasonable, possibly even preferable to hiding it. And the other cases are similar.
2024-01-26remove illegal_floating_point_literal_pattern lintRalf Jung-20/+12
2024-01-26Rollup merge of #120345 - flip1995:clippy-subtree-update, r=ManishearthMatthias Krüger-499/+1987
Clippy subtree update r? `@Manishearth` Closes https://github.com/rust-lang/rust-clippy/issues/12148
2024-01-26Auto merge of #116167 - RalfJung:structural-eq, r=lcnrbors-17/+0
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good. Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-25Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into ↵Philipp Krones-499/+1987
clippy-subtree-update
2024-01-24remove StructuralEq traitRalf Jung-17/+0
2024-01-23We don't look into static items anymore during const propOli Scherer-9/+2
2024-01-23Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.Nicholas Nethercote-3/+3
2024-01-23Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.Nicholas Nethercote-4/+4
2024-01-22Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8KiMatthias Krüger-0/+1
Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>` addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
2024-01-16Deal with additional wrapping of async closure body in clippyMichael Goulet-1/+5
2024-01-12Improve `let_underscore_lock`Nilstrieb-0/+1
- lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>`
2024-01-12Rollup merge of #119819 - chenyukang:yukang-fix-118183-lint, r=davidtwcoGuillaume Gomez-5/+25
Check rust lints when an unknown lint is detected Fixes #118183
2024-01-12check rust lints when an unknown lint is detectedyukang-5/+25
2024-01-11Merge commit '26ac6aab023393c94edf42f38f6ad31196009643'Philipp Krones-435/+3413
2024-01-05Rollup merge of #119151 - Jules-Bertholet:no-foreign-doc-hidden-suggest, ↵Matthias Krüger-2/+0
r=davidtwco Hide foreign `#[doc(hidden)]` paths in import suggestions Stops the compiler from suggesting to import foreign `#[doc(hidden)]` paths. ```@rustbot``` label A-suggestion-diagnostics
2024-01-05Rollup merge of #119148 - estebank:bare-traits, r=davidtwcoMichael Goulet-1/+1
Tweak suggestions for bare trait used as a type ``` error[E0782]: trait objects must include the `dyn` keyword --> $DIR/not-on-bare-trait-2021.rs:11:11 | LL | fn bar(x: Foo) -> Foo { | ^^^ | help: use a generic type parameter, constrained by the trait `Foo` | LL | fn bar<T: Foo>(x: T) -> Foo { | ++++++++ ~ help: you can also use `impl Foo`, but users won't be able to specify the type paramer when calling the `fn`, having to rely exclusively on type inference | LL | fn bar(x: impl Foo) -> Foo { | ++++ help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch | LL | fn bar(x: &dyn Foo) -> Foo { | ++++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/not-on-bare-trait-2021.rs:11:19 | LL | fn bar(x: Foo) -> Foo { | ^^^ | help: use `impl Foo` to return an opaque type, as long as you return a single underlying type | LL | fn bar(x: Foo) -> impl Foo { | ++++ help: alternatively, you can return an owned trait object | LL | fn bar(x: Foo) -> Box<dyn Foo> { | +++++++ + ``` Fix #119525: ``` error[E0038]: the trait `Ord` cannot be made into an object --> $DIR/bare-trait-dont-suggest-dyn.rs:3:33 | LL | fn ord_prefer_dot(s: String) -> Ord { | ^^^ `Ord` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/cmp.rs:LL:COL | = note: the trait cannot be made into an object because it uses `Self` as a type parameter ::: $SRC_DIR/core/src/cmp.rs:LL:COL | = note: the trait cannot be made into an object because it uses `Self` as a type parameter help: consider using an opaque type instead | LL | fn ord_prefer_dot(s: String) -> impl Ord { | ++++ ```
2024-01-03Track `HirId` instead of `Span` in `ObligationCauseCode::SizedArgumentType`Esteban Küber-1/+1
This gets us more accurate suggestions.
2024-01-02Remove #[allow(unused_tuple_struct_fields)] from Clippy testsJake Goulding-70/+59
2023-12-28Merge commit 'ac4c2094a6030530661bee3876e0228ddfeb6b8b' into clippy-subtree-syncPhilipp Krones-161/+1536
2023-12-26Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkovMichael Goulet-0/+4
Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s The rest of 'em affect diagnostics, so leave them alone... for now. cc #115178
2023-12-26Make some non-diagnostic-affecting QPath::LangItem into regular qpathsMichael Goulet-0/+4
2023-12-25Fix clippy's usage of Body's coroutine_kindMichael Goulet-4/+18
Also fixes a bug where we weren't peeling blocks from async bodies
2023-12-20Hide foreign `#[doc(hidden)]` paths in import suggestionsJules Bertholet-2/+0
2023-12-16Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyupPhilipp Krones-235/+2028
2023-12-06Drop clippy::vtable_address_comparisonsUrgau-177/+67
2023-12-02Auto merge of #118507 - flip1995:clippy-subtree-sync, r=matthiaskrgrbors-267/+1947
Clippy subtree sync r? `@Manishearth`