about summary refs log tree commit diff
path: root/tests/ui/lint
AgeCommit message (Collapse)AuthorLines
2023-08-01Rename incorrect_fn_null_checks to useless_ptr_null_checksUrgau-17/+17
2023-08-01Expand incorrect_fn_null_check lint with reference null checkingUrgau-9/+94
2023-07-29Improve diagnostics of the invalid_reference_casting lintUrgau-68/+121
2023-07-29Avoid linting on expression that are only UB with SB/TBUrgau-34/+19
2023-07-29Add support for deferred casting for the invalid_reference_casting lintUrgau-1/+12
2023-07-29Revert "Temporarily switch invalid_reference_casting lint to allow-by-default"Urgau-16/+11
This reverts commit f25ad54a4d0febbcb2b7e951835228b7b2320b49.
2023-07-29Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstriebbors-11/+16
Rename and allow `cast_ref_to_mut` lint This PR is a small subset of https://github.com/rust-lang/rust/pull/112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`). BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until https://github.com/rust-lang/rust/pull/112431 is merged. r? `@Nilstrieb`
2023-07-29Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, ↵bors-78/+127
r=compiler-errors make `noop_method_call` warn by default r? `@compiler-errors`
2023-07-28Rollup merge of #114164 - Enselic:lint-cap-trait-bounds, r=compiler-errorsMatthias Krüger-0/+8
Add regression test for `--cap-lints allow` and trait bounds warning Closes #43134 I have verified that the test fails if stderr begins to contain output by making sure the test fails when I add eprintln!("some output on stderr"); to the compiler (I added it to `fn build_session()`).
2023-07-28Add regression test for `--cap-lints allow` and trait bounds warningMartin Nordholts-0/+8
I have verified that the test fails if stderr begins to contain output by making sure the test fails when I add eprintln!("some output on stderr"); to the compiler (I added it to `fn build_session()`).
2023-07-26Auto merge of #113457 - davidtwco:lint-ctypes-issue-113436, r=oli-obkbors-0/+97
lint/ctypes: fix `()` return type checks Fixes #113436. `()` is normally FFI-unsafe, but is FFI-safe when used as a return type. It is also desirable that a transparent newtype for `()` is FFI-safe when used as a return type. In order to support this, when a type was deemed FFI-unsafe, because of a `()` type, and was used in return type - then the type was considered FFI-safe. However, this was the wrong approach - it didn't check that the `()` was part of a transparent newtype! The consequence of this is that the presence of a `()` type in a more complex return type would make it the entire type be considered safe (as long as the `()` type was the first that the lint found) - which is obviously incorrect. Instead, this logic is removed, and after [consultation with t-lang](https://github.com/rust-lang/rust/issues/113436#issuecomment-1640756721), I've fixed the bugs and inconsistencies and made `()` FFI-safe within types. I also refactor a function, but that's not too exciting.
2023-07-25Add regression test for invalid unused const in methodMartin Nordholts-0/+23
The warning can be reproduced with 1.63 but not with 1.64. $ rustc +1.63 tests/ui/lint/unused/const-local-var.rs warning: constant `F` is never used --> tests/ui/lint/unused/const-local-var.rs:14:9 | 14 | const F: i32 = 2; | ^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default $ rustc +1.64 tests/ui/lint/unused/const-local-var.rs Add a regression test to prevent the problem from re-appearing.
2023-07-23add suggestionDeadbeef-71/+125
2023-07-23fixDeadbeef-7/+7
2023-07-23make `noop_method_call` warn by defaultDeadbeef-14/+9
2023-07-22Make `unconditional_recursion` warning detect recursive dropsMartin Nordholts-0/+55
2023-07-21Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"David Tolnay-2/+4
This reverts commit 557359f92512ca88b62a602ebda291f17a953002, reversing changes made to 1e6c09a803fd543a98bfbe1624d697a55300a786.
2023-07-21lint/ctypes: only try normalizeDavid Wood-0/+12
Now that this lint runs on any external-ABI fn-ptr, normalization won't always succeed, so use `try_normalize_erasing_regions` instead. Signed-off-by: David Wood <david@davidtw.co>
2023-07-21Track exactness in `NaiveLayout` and use it for `SizeSkeleton` checksMoulins-4/+2
2023-07-19lint/ctypes: allow `()` within typesDavid Wood-47/+64
Consider `()` within types to be FFI-safe, and `()` to be FFI-safe as a return type (incl. when in a transparent newtype). Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint/ctypes: stricter `()` return type checksDavid Wood-0/+80
`()` is normally FFI-unsafe, but is FFI-safe when used as a return type. It is also desirable that a transparent newtype for `()` is FFI-safe when used as a return type. In order to support this, when an type was deemed FFI-unsafe, because of a `()` type, and was used in return type - then the type was considered FFI-safe. However, this was the wrong approach - it didn't check that the `()` was part of a transparent newtype! The consequence of this is that the presence of a `()` type in a more complex return type would make it the entire type be considered safe (as long as the `()` type was the first that the lint found) - which is obviously incorrect. Instead, this logic is removed, and a unit return type or a transparent wrapper around a unit is checked for directly for functions and fn-ptrs. Signed-off-by: David Wood <david@davidtw.co>
2023-07-18Fix removal span calculation of unused_qualifications suggestion许杰友 Jieyou Xu (Joe)-5/+28
2023-07-13Temporarily switch invalid_reference_casting lint to allow-by-defaultUrgau-11/+16
2023-07-13Rename cast_ref_to_mut lint to invalid_reference_castingUrgau-11/+11
2023-07-13Add machine-applicable suggestion for `unused_qualifications` lint许杰友 Jieyou Xu (Joe)-0/+4
2023-07-12Auto merge of #112945 - compiler-errors:tighten-span-of-adjustment-error, ↵bors-1/+1
r=oli-obk (re-)tighten sourceinfo span of adjustments in MIR Diagnostics rely on the spans of MIR statements being (approximately) correct in order to give suggestions relative to that span (i.e. `shrink_to_hi` and `shrink_to_lo`). I discovered that we're *intentionally* lowering THIR exprs with their parent expr's span if they come from adjustments that are due to a parent expression. While I understand why that may be desirable to demonstrate the relationship of an adjustment and the expression that requires it, it leads to 1. very verbose borrowck output 2. incorrect spans for suggestions Some diagnostics get around that by giving suggestions relative to other spans we've collected during MIR lowering, such as the span of the method's identifier (e.g. `name` in `.name()`), but this doesn't work too well when things come from desugaring. I assume it also has lead to numerous tweaks and complications to diagnostics code down the road, which this PR doesn't necessarily aim to fix but may open the gates to fixing later... The last three commits are simplifications due to the fact that we can assume that the move span actually points to what is being moved (and a test). This regressed in #89110, which was debated somewhat in #90286. cc `@Aaron1011` who originally made this change. r? diagnostics Fixes #113547 Fixes #111016
2023-07-11Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obkbors-0/+97
Uplift `clippy::fn_null_check` lint This PR aims at uplifting the `clippy::fn_null_check` lint into rustc. ## `incorrect_fn_null_checks` (warn-by-default) The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null. ### Example ```rust let fn_ptr: fn() = /* somehow obtained nullable function pointer */ if (fn_ptr as *const ()).is_null() { /* ... */ } ``` ### Explanation Function pointers are assumed to be non-null, checking for their nullity is incorrect. ----- Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler
2023-07-10Do not set up wrong span for adjustmentsMichael Goulet-1/+1
2023-07-10Uplift `clippy::fn_null_check` to rustcUrgau-0/+97
2023-07-07Remove normalization from `opaque_types_defined_by`Oli Scherer-1/+18
2023-07-03lint/ctypes: check other types for ext. fn-ptr tyDavid Wood-1/+126
Extend previous checks for external ABI fn-ptrs to use in internal statics, constants, type aliases and algebraic data types. Signed-off-by: David Wood <david.wood@huawei.com>
2023-07-03lint/ctypes: multiple external fn-ptrs in tyDavid Wood-1/+23
Extend previous commit's support for checking for external fn-ptrs in internal fn types to report errors for multiple found fn-ptrs. Signed-off-by: David Wood <david.wood@huawei.com>
2023-07-03lint/ctypes: ext. abi fn-ptr in internal abi fnDavid Wood-0/+21
Instead of skipping functions with internal ABIs, check that the signature doesn't contain any fn-ptr types with external ABIs that aren't FFI-safe. Signed-off-by: David Wood <david.wood@huawei.com>
2023-07-01Fix dropping_copy_types lint from linting in match-arm with side-effectsUrgau-0/+38
2023-06-16Add `AliasKind::Weak` for type aliases.Oli Scherer-24/+24
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
2023-06-15Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obkGuillaume Gomez-0/+123
Extend `unused_must_use` to cover block exprs Given code like ```rust #[must_use] fn foo() -> i32 { 42 } fn warns() { { foo(); } } fn does_not_warn() { { foo() }; } fn main() { warns(); does_not_warn(); } ``` ### Before This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: 1 warning emitted ``` ### After This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: unused return value of `foo` that must be used --> test.rs:14:9 | 14 | foo() | ^^^^^ | help: use `let _ = ...` to ignore the resulting value | 14 | let _ = foo(); | +++++++ + warning: 2 warnings emitted ``` Fixes #104253.
2023-06-15Rollup merge of #112517 - fee1-dead-contrib:sus-op-no-borrow, r=compiler-errorsGuillaume Gomez-0/+17
`suspicious_double_ref_op`: don't lint on `.borrow()` closes #112489
2023-06-15Rollup merge of #111212 - nicklimmm:issue-107896-fix, r=pnkfelixMatthias Krüger-2/+26
Add casting suggestion when assigning negative 2's complement bin or hex literal to a size compatible signed integer Fixes #107896 The issue stated the case for `iX::MIN` variants. This PR extends the cases for other negative values (in the 2's complement). Leveraged sign bits to detect such cases. Example cases: - <img width="845" alt="image" src="https://user-images.githubusercontent.com/65026286/236289682-19859f59-a9c5-48c5-b15f-78a935fbfcec.png"> - <img width="831" alt="image" src="https://user-images.githubusercontent.com/65026286/236289805-5b16488d-9138-4363-a1b6-a5c027c50aba.png"> - <img width="912" alt="image" src="https://user-images.githubusercontent.com/65026286/236290065-685a9777-034b-4def-83a8-cc4e20b1ed0c.png">
2023-06-15Extend `unused_must_use` to cover block exprs许杰友 Jieyou Xu (Joe)-0/+123
2023-06-12Adjust UI tests for `unit_bindings`许杰友 Jieyou Xu (Joe)-10/+10
- Either explicitly annotate `let x: () = expr;` where `x` has unit type, or remove the unit binding to leave only `expr;` instead. - Fix disjoint-capture-in-same-closure test
2023-06-11Update ui testNicky Lim-2/+26
2023-06-11`suspicious_double_ref_op`: don't lint on `.borrow()`Deadbeef-0/+17
2023-06-10Uplift improved version of `clippy::cmp_nan` to rustcUrgau-0/+399
2023-06-09Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errorsbors-0/+61
Uplift `clippy::undropped_manually_drops` lint This PR aims at uplifting the `clippy::undropped_manually_drops` lint. ## `undropped_manually_drops` (warn-by-default) The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop. ### Example ```rust struct S; drop(std::mem::ManuallyDrop::new(S)); ``` ### Explanation `ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either. ----- Mostly followed the instructions for uplifting an clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2023-06-08Uplift clippy::undropped_manually_drops to rustcUrgau-0/+61
2023-06-06Rollup merge of #112343 - GuillaumeGomez:extern-crate-missing-docs, r=notriddleMatthias Krüger-26/+31
Prevent emitting `missing_docs` for `pub extern crate` Fixes #112308. r? `@notriddle`
2023-06-06Add regression test for #112308Guillaume Gomez-26/+31
2023-06-05Ensure space is inserted after keyword in `unused_delims`clubby789-13/+89
2023-06-03remove type ascription feature gateyukang-2/+2
2023-05-31Uplift clippy::cast_ref_to_mut to rustcUrgau-0/+114