summary refs log tree commit diff
path: root/src/test/ui/consts
AgeCommit message (Collapse)AuthorLines
2020-12-21Auto merge of #79270 - RalfJung:array-repeat-consts, r=oli-obkbors-0/+27
Acknowledge that `[CONST; N]` is stable When `const_in_array_repeat_expressions` (RFC 2203) got unstably implemented as part of https://github.com/rust-lang/rust/pull/61749, accidentally, the special case of repeating a *constant* got stabilized immediately. That is why the following code works on stable: ```rust const EMPTY: Vec<i32> = Vec::new(); pub const fn bar() -> [Vec<i32>; 2] { [EMPTY; 2] } fn main() { let x = bar(); } ``` In contrast, if we had written `[expr; 2]` for some expression that is not *literally* a constant but could be evaluated at compile-time (e.g. `(EMPTY,).0`), this would have failed. We could take back this stabilization as it was clearly accidental. However, I propose we instead just officially accept this and stabilize a small subset of RFC 2203, while leaving the more complex case of general expressions that could be evaluated at compile-time unstable. Making that case work well is pretty much blocked on inline `const` expressions (to avoid relying too much on [implicit promotion](https://github.com/rust-lang/const-eval/blob/master/promotion.md)), so it could take a bit until it comes to full fruition. `[CONST; N]` is an uncontroversial subset of this feature that has no semantic ambiguities, does not rely on promotion, and basically provides the full expressive power of RFC 2203 but without the convenience (people have to define constants to repeat them, possibly using associated consts if generics are involved). Well, I said "no semantic ambiguities", that is only almost true... the one point I am not sure about is `[CONST; 0]`. There are two possible behaviors here: either this is equivalent to `let x = CONST; [x; 0]`, or it is a NOP (if we argue that the constant is never actually instantiated). The difference between the two is that if `CONST` has a destructor, it should run in the former case (but currently doesn't, due to https://github.com/rust-lang/rust/issues/74836); but should not run if it is considered a NOP. For regular `[x; 0]` there seems to be consensus on running drop (there isn't really an alternative); any opinions for the `CONST` special case? Should this instantiate the const only to immediately run its destructors? That seems somewhat silly to me. After all, the `let`-expansion does *not* work in general, for `N > 1`. Cc `@rust-lang/lang` `@rust-lang/wg-const-eval` Cc https://github.com/rust-lang/rust/issues/49147
2020-12-20make sure [CONST; N] drops N timesRalf Jung-2/+16
2020-12-20add test that repeating non-Copy constants worksRalf Jung-0/+13
2020-12-19also const-check FakeReadRalf Jung-0/+5
2020-12-10re-bless testsRalf Jung-0/+34
2020-12-09remove a hack that seems to only benefit a few very special casesRalf Jung-3/+31
2020-12-09make sure we do not promote things with interior mutabilityRalf Jung-7/+22
2020-12-03Auto merge of #79594 - vn-ki:const-eval-intrinsic, r=oli-obkbors-112/+235
add const_allocate intrinsic r? `@oli-obk` fixes #75390
2020-12-02rename MemoryKind::Heap to ConstHeap; bless testVishnunarayan K I-7/+14
2020-12-02add comment and bless some testsVishnunarayan K I-110/+93
2020-12-01review comment and one more testVishnunarayan K I-11/+23
2020-12-01review commentsVishnunarayan K I-1/+43
2020-12-01Rollup merge of #79444 - sasurau4:test/move-const-ip, r=matkladMara Bos-13/+0
Move const ip in ui test to unit test Helps with #76268 r? ``@matklad``
2020-12-01Rollup merge of #79227 - sasurau4:test/move-cell-test-to-lib-core, r=jyn514Mara Bos-13/+0
Remove const_fn_feature_flags test ## Overview Helps with #76268 I found `const_fn_feature_flags` is targeting feature-gate and remove it. r? ``@matklad``
2020-12-01add const_allocate intrisicVishnunarayan K I-0/+79
2020-11-30Make ui test that are run-pass and do not test the compiler itself library testsChristiaan Dirkx-70/+0
2020-11-29Update tests to remove old numeric constantsbstrie-86/+68
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-11-26Move const ip in ui test to unit testDaiki Ihara-13/+0
2020-11-26remove const-fn-feature-flags testDaiki Ihara-13/+0
2020-11-25Resolve inference variables before trying to remove overloaded indexingAaron Hill-0/+11
Fixes #79152 This code was already set up to handle indexing an array. However, it appears that we never end up with an inference variable for the slice case, so the missing call to `resolve_vars_if_possible` had no effect until now.
2020-11-23Rollup merge of #76829 - tspiteri:const-int-pow, r=oli-obkJonas Schievink-1/+0
stabilize const_int_pow This also requires stabilizing constctlz for const ctlz_nonzero.
2020-11-23Auto merge of #76226 - CDirkx:const-ipaddr, r=dtolnaybors-0/+13
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `std::net::IpAddr` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198). Possible because of the recent stabilization of const control flow. Part of #76225 and #76205.
2020-11-23stabilize const_int_powTrevor Spiteri-1/+0
Also stabilize constctlz for const ctlz_nonzero. The public methods stabilized const by this commit are: * `{i*,u*}::checked_pow` * `{i*,u*}::saturating_pow` * `{i*,u*}::wrapping_pow` * `{i*,u*}::overflowing_pow` * `{i*,u*}::pow` * `u*::next_power_of_two` * `u*::checked_next_power_of_two` * `u*::wrapping_next_power_of_two` (the method itself is still unstable)
2020-11-23Stabilize `IpAddr::is_ipv4` and `is_ipv6` as constChristiaan Dirkx-0/+13
Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `IpAddr`. Possible because of the recent stabilization of const control flow. Also adds a test for these methods in a const context.
2020-11-21Fix comments of toogeneris testNgo Iok Ui-5/+3
2020-11-20Exhaustively match in variant count instrinsicNgo Iok Ui-0/+54
2020-11-14Auto merge of #79049 - tmiasko:lower-intrinsics, r=jonas-schievinkbors-5/+0
Lower intrinsics calls: forget, size_of, unreachable, wrapping_* This allows constant propagation to evaluate `size_of` and `wrapping_*`, and unreachable propagation to propagate a call to `unreachable`. The lowering is performed as a MIR optimization, rather than during MIR building to preserve the special status of intrinsics with respect to unsafety checks and promotion. Currently enabled by default to determine the performance impact (no significant impact expected). In practice only useful when combined with inlining since intrinsics are rarely used directly (with exception of `unreachable` and `discriminant_value` used by built-in derive macros). Closes #32716.
2020-11-14Lower intrinsics calls: forget, size_of, unreachable, wrapping_*Tomasz Miąsko-5/+0
This allows constant propagation to evaluate `size_of` and `wrapping_*`, and unreachable propagation to propagate a call to `unreachable`. The lowering is performed as a MIR optimization, rather than during MIR building to preserve the special status of intrinsics with respect to unsafety checks and promotion.
2020-11-12fix tests and formattingVishnunarayan K I-40/+8
2020-11-12add error_occured field to ConstQualifs, fix #76064Vishnunarayan K I-0/+16
2020-11-10Rollup merge of #78669 - sasurau4:test/check-pass-consts, r=jyn514Jonas Schievink-4/+4
Use check-pass instead of build-pass in some consts ui test suits Helps with #62277 Changed tests modified by https://github.com/rust-lang/rust/pull/57175 because of the stabilization `#![feature(const_let)]`. They should be compile-fail because the feature gate checking disallow the feature before stabilization. So the feature gate checking have nothing to do with codegen according to https://rustc-dev-guide.rust-lang.org/feature-gate-ck.html.
2020-11-10use check-pass instead of build-pass in consts ui test suitsDaiki Ihara-4/+4
2020-11-09Add `#[cfg(panic = "...")]`David Hewitt-3/+3
2020-11-05update dangling-alloc-id-ice testVishnunarayan K I-15/+2
2020-11-04make intern_const_alloc_recursive return error fix #78655Vishnunarayan K I-0/+40
2020-10-26move &mut-in-const check from interning to validationRalf Jung-3/+5
2020-10-26move UnsafeCell-in-const check from interning to validationRalf Jung-6/+11
2020-10-25Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obkYuki Okushi-10/+10
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
2020-10-25Auto merge of #77526 - RalfJung:dont-promote-unions, r=lcnrbors-1/+16
stop promoting union field accesses in 'const' Turns out that promotion of union field accesses is the only difference between "promotion in `const`/`static` bodies" and "explicit promotion". So if we can remove this, we have finally achieved what I thought to already be the case -- that the bodies of `const`/`static` initializers behave the same as explicit promotion contexts. The reason we do not want to promote union field accesses is that they can introduce UB, i.e., they can go wrong. We want to [minimize the ways promoteds can fail to evaluate](https://github.com/rust-lang/const-eval/issues/53). Also this change makes things more consistent overall, removing a special case that was added without much consideration (as far as I can tell). Cc `@rust-lang/wg-const-eval`
2020-10-24Rollup merge of #78072 - Nadrieril:cleanup-constant-matching, r=varkorJonas Schievink-0/+98
Cleanup constant matching in exhaustiveness checking This supercedes https://github.com/rust-lang/rust/pull/77390. I made the `Opaque` constructor work. I have opened two issues https://github.com/rust-lang/rust/issues/78071 and https://github.com/rust-lang/rust/issues/78057 from the discussion we had on the previous PR. They are not regressions nor directly related to the current PR so I thought we'd deal with them separately. I left a FIXME somewhere because I didn't know how to compare string constants for equality. There might even be some unicode things that need to happen there. In the meantime I preserved previous behavior. EDIT: I accidentally fixed #78071
2020-10-22Add test for const panic!(CONST).Mara Bos-17/+45
2020-10-22Rollup merge of #78172 - wesleywiser:close_77062, r=oli-obkYuki Okushi-0/+5
Add test case for #77062 Closes #77062
2020-10-22Rollup merge of #77420 - ecstatic-morse:const-checking-raw-mut-ref, r=davidtwcoYuki Okushi-25/+17
Unify const-checking structured errors for `&mut` and `&raw mut` Resolves #77414 as well as a FIXME.
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-10/+10
2020-10-21Add a test for #53708Nadrieril-0/+11
This issue was accidentally fixed recently, probably by #70743
2020-10-20Add test case for #77062Wesley Wiser-0/+5
Closes #77062
2020-10-18Add some testsNadrieril-0/+87
2020-10-18we can test std and core panic macros togetherRalf Jung-70/+90
2020-10-17Suggest minimal subset features in `incomplete_features` lintYuki Okushi-0/+1
2020-10-05Remove `fn` from feature nameDylan MacKenzie-3/+3