about summary refs log tree commit diff
path: root/tests/ui/closures/2229_closure_analysis
AgeCommit message (Collapse)AuthorLines
2023-12-18Fix ICE `ProjectionKinds Deref and Field were mismatched`Gurinder Singh-0/+27
2023-11-24Show number in error message even for one errorNilstrieb-22/+22
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-08Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwcobors-1/+14
patterns: reject raw pointers that are not just integers Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not. This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](https://github.com/rust-lang/rust/pull/116930#issuecomment-1784654073) for some more explanation and context. Also fixes https://github.com/rust-lang/rust/issues/116929. Cc `@oli-obk` `@lcnr`
2023-11-03Tweak spans for "adt defined here" noteNadrieril-2/+2
2023-10-28make pointer_structural_match warn-by-defaultRalf Jung-1/+14
2023-09-22Capture scrutinee of if let guards correctlyMatthew Jasper-0/+158
Previously we were always capturing by value.
2023-09-16Auto merge of #115315 - RalfJung:field-capture-packed-alignment, r=oli-obkbors-17/+12
closure field capturing: don't depend on alignment of packed fields This fixes the closure field capture part of https://github.com/rust-lang/rust/issues/115305: field capturing always stops at projections into packed structs, no matter the alignment of the field. This means changing a private field type from `u8` to `u64` can never change how closures capture fields, which is probably what we want. Here's an example where, before this PR, changing the type of a private field in a repr(Rust) struct can change the output of a program: ```rust #![allow(dead_code)] mod m { // before patch #[derive(Default)] pub struct S1(u8); // after patch #[derive(Default)] pub struct S2(u64); } struct NoisyDrop; impl Drop for NoisyDrop { fn drop(&mut self) { eprintln!("dropped!"); } } #[repr(packed)] struct MyType { field: m::S1, // output changes when this becomes S2 other_field: NoisyDrop, third_field: Vec<()>, } fn test(r: MyType) { let c = || { let _val = std::ptr::addr_of!(r.field); let _val = r.third_field; }; drop(c); eprintln!("before dropping"); } fn main() { test(MyType { field: Default::default(), other_field: NoisyDrop, third_field: Vec::new(), }); } ``` Of course this is a breaking change for the same reason that doing field capturing in the first place was a breaking change. Packed fields are relatively rare and depending on drop order is relatively rare, so I don't expect this to have much impact, but it's hard to be sure and even a crater run will only tell us so much. Also see the [nomination comment](https://github.com/rust-lang/rust/pull/115315#issuecomment-1702807825). Cc `@rust-lang/wg-rfc-2229` `@ehuss`
2023-09-03Improve clarity of diagnostic message on non-exhaustive matchesSebastian Toh-1/+1
2023-08-28closure field capturing: don't depend on alignment of packed fieldsRalf Jung-17/+12
2023-08-28Add note when matching on nested non-exhaustive enumsSebastian Toh-1/+2
2023-06-18Auto merge of #112636 - clubby789:no-capture-array-ref, r=cjgillotbors-18/+65
Don't capture `&[T; N]` when contents isn't read Fixes the check in #111831 Fixes #112607, although I decided to test the root cause rather than including the example in the issue as a test. cc `@BoxyUwU`
2023-06-15Don't capture &[T; N] when contents isn't readclubby789-18/+65
2023-06-14s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedListThe 8472-3/+3
2023-06-12Adjust UI tests for `unit_bindings`许杰友 Jieyou Xu (Joe)-1/+1
- 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-05-29add testslcnr-0/+78
2023-05-25Rollup merge of #111831 - clubby789:capture-slice-pat, r=cjgillotMichael Goulet-85/+196
Always capture slice when pattern requires checking the length Fixes #111751 cc ``@zirconium-n,`` I see you were assigned to this but I've fixed some similar issues in the past and had an idea on how to investigate this.
2023-05-25Always capture slice when pattern requires checking the lengthclubby789-85/+196
2023-05-21Rename `drop_ref` lint to `dropping_references`Urgau-3/+3
2023-05-21Rename `drop_copy` lint to `dropping_copy_types`Urgau-1/+1
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-1/+5
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-11Rollup merge of #108705 - clubby789:refutable-let-closure-borrow, r=cjgillotMatthias Krüger-0/+136
Prevent ICE with broken borrow in closure r? `@Nilstrieb` Fixes #108683 This solution isn't ideal, I'm hoping to find a way to continue compilation without ICEing.
2023-05-10Adjust tests for new drop and forget lintsUrgau-1/+5
2023-05-05tweak "make mut" spans when assigning to localsEzra Shaw-1/+1
2023-04-30Test precise capture with a multi-variant enum and exhaustive patternsTomasz Miąsko-0/+21
Add test checking that it is possible to capture fields of a multi-variant enum, when remaining variants are visibly uninhabited (under the `exhaustive_patterns` feature gate).
2023-04-30Bail out of MIR construction if `check_match` failsclubby789-0/+136
2023-04-28improve error notes for packed struct reference diagnosticbindsdev-1/+2
2023-04-21Run `check_match` and `check_liveness` when MIR is built instead of having ↵Oli Scherer-14/+14
an explicit phase for them
2023-03-27Fix subslice capture in closureclubby789-0/+39
2023-02-28Remove the `capture_disjoint_fields` featureclubby789-4/+1
2023-02-15Fix unintentional UB in ui testsBen Kimock-9/+9
2023-01-31make unaligned_reference a hard errorRalf Jung-19/+2
2023-01-15Tweak E0597Esteban Küber-15/+15
CC #99430
2023-01-11Move /src/test to /testsAlbert Larsan-0/+10257