about summary refs log tree commit diff
path: root/src/test/ui/drop
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-3703/+0
2023-01-04Move testsCaio-0/+22
2022-12-11Move testsCaio-0/+77
2022-12-04Also avoid creating a terminating scope in mixed chainsest31-0/+19
This avoids creation of a terminating scope in chains that contain both && and ||, because also there we know that a terminating scope is not neccessary: all the chain members are already in such terminating scopes. Also add a mixed && / || test.
2022-12-03Remove drop order twist of && and || and make them associativeest31-7/+108
Previously a short circuiting && chain would drop the first element after all the other elements, and otherwise follow evaluation order, so code like: f(1).g() && f(2).g() && f(3).g() && f(4).g() would drop the temporaries in the order 2,3,4,1. This made && and || non-associative regarding drop order, so adding ()'s to the expression would change drop order: f(1).g() && (f(2).g() && f(3).g()) && f(4).g() for example would drop in the order 3,2,4,1. As, except for the bool result, there is no data returned by the sub-expressions of the short circuiting binops, we can safely discard of any temporaries created by the sub-expr. Previously, code was already putting the rhs's into terminating scopes, but missed it for the lhs's. This commit addresses this "twist". In the expression, we now also put the lhs into a terminating scope. The drop order for the above expressions is 1,2,3,4 now.
2022-11-23Suggest `.clone()` or `ref binding` on E0382Esteban Küber-0/+5
2022-10-20Move some tests for more reasonable placesCaio-0/+162
2022-10-16Don't consider `Let` exprs terminating scopesNathan Whitaker-2/+14
2022-10-15Rollup merge of #102998 - nathanwhit:let-chains-drop-order, r=eholkDylan DPC-0/+64
Drop temporaries created in a condition, even if it's a let chain Fixes #100513. During the lowering from AST to HIR we wrap expressions acting as conditions in a `DropTemps` expression so that any temporaries created in the condition are dropped after the condition is executed. Effectively this means we transform ```rust if Some(1).is_some() { .. } ``` into (roughly) ```rust if { let _t = Some(1).is_some(); _t } { .. } ``` so that if we create any temporaries, they're lifted into the new scope surrounding the condition, so for example something along the lines of ```rust if { let temp = Some(1); let _t = temp.is_some(); _t }. ``` Before this PR, if the condition contained any let expressions we would not introduce that new scope, instead leaving the condition alone. This meant that in a let-chain like ```rust if get_drop("first").is_some() && let None = get_drop("last") { println!("second"); } else { .. } ``` the temporary created for `get_drop("first")` would be lifted into the _surrounding block_, which caused it to be dropped after the execution of the entire `if` expression. After this PR, we wrap everything but the `let` expression in terminating scopes. The upside to this solution is that it's minimally invasive, but the downside is that in the worst case, an expression with `let` exprs interspersed like ```rust if get_drop("first").is_some() && let Some(_a) = get_drop("fifth") && get_drop("second").is_some() && let Some(_b) = get_drop("fourth") { .. } ``` gets _multiple_ new scopes, roughly ```rust if { let _t = get_drop("first").is_some(); _t } && let Some(_a) = get_drop("fifth") && { let _t = get_drop("second").is_some(); _t } && let Some(_b) = get_drop("fourth") { .. } ``` so instead of all of the temporaries being dropped at the end of the entire condition, they will be dropped right after they're evaluated (before the subsequent `let` expr). So while I'd say the drop behavior around let-chains is _less_ surprising after this PR, it still might not exactly match what people might expect. For tests, I've just extended the drop order tests added in #100526. I'm not sure if that's the best way to go about it, though, so suggestions are welcome.
2022-10-13Validate MIR in the `drop_order` testNathan Whitaker-0/+1
2022-10-13Move some tests to more reasonable directoriesCaio-0/+44
2022-10-12Let chains should still drop temporariesNathan Whitaker-0/+63
by the end of the condition's execution
2022-10-09allow or avoid for loops over option in compiler and testsMaybe Waffle-7/+7
2022-09-26Auto merge of #102184 - chenyukang:fix-102087-add-binding-sugg, r=nagisabors-0/+5
Suggest Default::default() when binding isn't initialized Fixes #102087
2022-09-26fix #102087, Suggest Default::default() when binding isn't initializedyukang-0/+5
2022-09-25Rollup merge of #102194 - fee1-dead-contrib:improve-const-drop, r=oli-obkfee1-dead-3/+3
Note the type when unable to drop values in compile time
2022-09-24Note the type when unable to drop values in compile timeDeadbeef-3/+3
2022-09-23Restore ignore tagFlorian Bartels-5/+0
This test case actually requires std::process.
2022-08-16Do not allow Drop impl on foreign fundamental typesMichael Goulet-0/+32
2022-08-14Add tests for the drop behavior of some control flow constructsNilstrieb-0/+145
In #100513 it was shown that the drop behavior of let_chains is not correct currently. Since drop behavior is something pretty subtle, this adds explicit tests for the drop behavior of `if`, `if let` and `match` to make sure that it does not regress in the future. The `println!`s were left in to make debugging easier in case something goes wrong, but they are not required for the test.
2022-08-03Warn about dead tuple struct fieldsFabian Wolff-9/+9
2022-07-07Tweak wording and spansEsteban Küber-2/+2
2022-07-07On partial uninit error point at where we need initEsteban Küber-3/+5
When a binding is declared without a value, borrowck verifies that all codepaths have *one* assignment to them to initialize them fully. If there are any cases where a condition can be met that leaves the binding uninitialized or we attempt to initialize a field of an unitialized binding, we emit E0381. We now look at all the statements that initialize the binding, and use them to explore branching code paths that *don't* and point at them. If we find *no* potential places where an assignment to the binding might be missing, we display the spans of all the existing initializers to provide some context.
2022-06-12Fix some test annotationsbjorn3-0/+1
These are necessary for running the rustc test suite with cg_clif
2022-05-24Modify MIR building to drop `foo` in `[foo; 0]`Jakob Degen-0/+164
2021-12-09Add needs-unwind to tests that depend on panickingDavid Koloski-0/+4
This directive isn't automatically set by compiletest or x.py, but can be turned on manually for targets that require it.
2021-11-23Auto merge of #90788 - ecstatic-morse:issue-90752, r=wesleywiserbors-0/+73
Mark places as initialized when mutably borrowed Fixes the example in #90752, but does not handle some corner cases involving raw pointers and unsafe. See [this comment](https://github.com/rust-lang/rust/issues/90752#issuecomment-965822895) for more information, or the second test. Although I talked about both `MaybeUninitializedPlaces` and `MaybeInitializedPlaces` in #90752, this PR only changes the latter. That's because "maybe uninitialized" is the conservative choice, and marking them as definitely initialized (`!maybe_uninitialized`) when a mutable borrow is created could lead to problems if `addr_of_mut` to an uninitialized local is allowed. Additionally, places cannot become uninitialized via a mutable reference, so if a place is definitely initialized, taking a mutable reference to it should not change that. I think it's correct to ignore interior mutability as nbdd0121 suggests below. Their analysis doesn't work inside of `core::cell`, which *does* have access to `UnsafeCell`'s field, but that won't be an issue unless we explicitly instantiate one with an `enum` within that module. r? `@wesleywiser`
2021-11-14Move some tests to more reasonable directoriesCaio-0/+18
2021-11-13Add raw pointer variant of #90752 with incorrect behaviorDylan MacKenzie-0/+41
2021-11-13Add regression test for #90752Dylan MacKenzie-0/+32
2021-11-06Move some tests to more reasonable directoriesCaio-0/+53
2021-09-26Remove box syntax from most places in src/test outside of the issues direst31-11/+5
2021-09-01Fix drop handling for `if let` expressionsMatthew Jasper-0/+7
MIR lowering for `if let` expressions is now more complicated now that `if let` exists in HIR. This PR adds a scope for the variables bound in an `if let` expression and then uses an approach similar to how we handle loops to ensure that we reliably drop the correct variables.
2021-08-24Also fix “a RwLock*”Frank Steffahn-1/+1
2021-06-04removed more uses of feature gatemarcusdunn-1/+0
2021-02-04Revert "Avoid leaking block expression values"Felix S. Klock II-379/+223
This reverts commit 4fef39113a514bb270f5661a82fdba17d3e41dbb.
2021-02-03Allow/fix non_fmt_panic in tests.Mara Bos-3/+3
2021-01-16Move some tests to more reasonable directories - 2Caio-0/+103
Address comments Update limits
2021-01-11Move some tests to more reasonable directoriesCaio-0/+30
2020-12-04Avoid leaking block expression valuesMatthew Jasper-223/+379
2020-11-29Update tests to remove old numeric constantsbstrie-2/+0
Part of #68490. Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros. For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.
2020-10-16stabilize union with 'ManuallyDrop' fields and 'impl Drop for Union'Ralf Jung-1/+1
2020-09-15Stabilize move_ref_patternAmjad Alsharafi-3/+0
2020-03-07test(bindings_after_at): add dynamic drop tests for bindings_after_atMatthew Kuo-0/+48
2020-02-09Auto merge of #68376 - Centril:move-ref-patterns, r=matthewjasperbors-0/+18
Initial implementation of `#![feature(move_ref_pattern)]` Following up on #45600, under the gate `#![feature(move_ref_pattern)]`, `(ref x, mut y)` is allowed subject to restrictions necessary for soundness. The match checking implementation and tests for `#![feature(bindings_after_at)]` is also adjusted as necessary. Closes #45600. Tracking issue: #68354. r? @matthewjasper
2020-02-02move_ref_patterns: introduce testsMazdak Farrokhzad-0/+18
bindings_after_at: harden tests
2020-02-02Add a resume type parameter to `Generator`Jonas Schievink-1/+1
2020-01-18slice_patterns: remove gates in testsMazdak Farrokhzad-5/+3
2019-12-09Add more tests for borrowck and dropck slice pattern handlingMatthew Jasper-0/+32
2019-10-25Re-enable Emscripten's exception handling supportThomas Lively-2/+2
Passes LLVM codegen and Emscripten link-time flags for exception handling if and only if the panic strategy is `unwind`. Sets the default panic strategy for Emscripten targets to `unwind`. Re-enables tests that depend on unwinding support for Emscripten, including `should_panic` tests.