about summary refs log tree commit diff
path: root/src/test/ui/consts
AgeCommit message (Collapse)AuthorLines
2020-09-23Bless testsDylan MacKenzie-38/+38
2020-09-24Auto merge of #77083 - KodrAus:revert/const-type-id, r=RalfJungbors-4/+7
revert const_type_id stabilization This reverts #72488, which is currently on beta and scheduled to stabilize in `1.47.0`, based on https://github.com/rust-lang/rust/pull/75923#issuecomment-696676511 It turns out we might not be quite ready to stabilize `TypeId` in const contexts before having a chance to rework its internals. Since `TypeId` is a bit of an oddity we want to be careful about how those internals are currently being relied on while making changes. That will be easier to do without having to also consider compile-time contexts. r? `@eddyb`
2020-09-23Make sure we keep emitting a hard errorOliver Scherer-13/+1
2020-09-23Make sure we report a future incompat error in all casesOliver Scherer-3/+3
2020-09-23Make sure we don't hide errors just because a lint has been emittedOliver Scherer-15/+8
2020-09-23Deduplicate errors in const to pat conversionOliver Scherer-113/+15
2020-09-23Rollup merge of #76898 - Aaron1011:fix/item-def-span, r=oli-obkDylan DPC-13/+7
Record `tcx.def_span` instead of `item.span` in crate metadata This was missed in PR #75465. As a result, a few places have been using the full body span of functions, instead of just the header span.
2020-09-23revert const_type_id stabilizationAshley Mannix-4/+7
This reverts commit e3856616ee2a894c7811a7017d98fafa7ba84dd8.
2020-09-22Bless testsDylan MacKenzie-122/+142
2020-09-21Rollup merge of #76807 - ecstatic-morse:const-checking-staged-api, r=oli-obkecstatic-morse-6/+63
Use const-checking to forbid use of unstable features in const-stable functions First step towards #76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
2020-09-21Record `tcx.def_span` instead of `item.span` in crate metadataAaron Hill-13/+7
This was missed in PR #75465. As a result, a few places have been using the full body span of functions, instead of just the header span.
2020-09-20Move const tests for `Option` to `library\core`Christiaan Dirkx-12/+0
Part of #76268
2020-09-20Stabilize some Option methods as constCDirkx-2/+0
Stabilize the following methods of `Option` as const: - `is_some` - `is_none` - `as_ref` Possible because of stabilization of #49146 (Allow if and match in constants).
2020-09-20Use precise errors during const to pat conversion instead of a catch-all on ↵Oliver Scherer-48/+47
the main constant
2020-09-20Implement destructuring for all aggregates and for referencesOliver Scherer-24/+2
2020-09-20Auto merge of #74949 - oli-obk:validate_const_eval_raw, r=RalfJungbors-66/+45
Validate constants during `const_eval_raw` This PR implements the groundwork for https://github.com/rust-lang/rust/issues/72396 * constants are now validated during `const_eval_raw` * to prevent cycle errors, we do not validate references to statics anymore beyond the fact that they are not dangling * the `const_eval` query ICEs if used on `static` items * as a side effect promoteds are now evaluated to `ConstValue::Scalar` again (since they are just a reference to the actual promoted allocation in most cases).
2020-09-19cleanup promotion const_kind checksRalf Jung-14/+54
in particular allow a few more promotions for consistency when they were already allowed in other contexts
2020-09-19Rollup merge of #76434 - RalfJung:black-box, r=Mark-SimulacrumRalf Jung-18/+13
do not inline black_box when building for Miri We cannot do the assembly trick in Miri, but let's at least make sure MIR inlining does not circumvent the black_box. Also use black_box instead of local optimization barriers in a few const tests.
2020-09-19Reflect the "do not call this query directly" mentality in its nameOliver Scherer-2/+2
2020-09-19Address review commentsOliver Scherer-16/+16
2020-09-19Fix rebase fallout and make the test work with debug infoOliver Scherer-3/+3
2020-09-19We can make const eval sound, it's just super expensiveOliver Scherer-7/+3
2020-09-19Clarify a statement in UB testOliver Scherer-1/+3
2020-09-19Stop using the `const_eval` query for initializers of staticsOliver Scherer-22/+14
As a side effect, we now represent most promoteds as `ConstValue::Scalar` again. This is useful because all implict promoteds are just references anyway and most explicit promoteds are numeric arguments to `asm!` or SIMD instructions.
2020-09-19Validate constants during `const_eval_raw`Oliver Scherer-28/+17
2020-09-16Test that `const_precise_live_drops` can't be depended upon stablyDylan MacKenzie-0/+57
2020-09-16Bless `miri-unleashed` testsDylan MacKenzie-6/+6
`const_mut_refs` doesn't actually work in a `const` or `static`
2020-09-12Make all methods of `Duration` constChristiaan Dirkx-67/+0
Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Also adds tests for these methods in a const context, moved the test to `library` as part of #76268. Possible because of #72449, which made the relevant `f32` and `f64` methods const. Tracking issue: #72440
2020-09-12Rollup merge of #76114 - marmeladema:duration-saturating-ops, r=shepmasterRalf Jung-16/+26
Add saturating methods for `Duration` In some project, I needed a `saturating_add` method for `Duration`. I implemented it myself but i thought it would be a nice addition to the standard library as it matches closely with the integers types. 3 new methods have been introduced and are gated by the new `duration_saturating_ops` unstable feature: * `Duration::saturating_add` * `Duration::saturating_sub` * `Duration::saturating_mul` If have left the tracking issue to `none` for now as I want first to understand if those methods would be acceptable at all. If agreed, I'll update the PR with the tracking issue. Further more, to match the behavior of integers types, I introduced 2 associated constants: * `Duration::MIN`: this one is somehow a duplicate from `Duration::zero()` method, but at the time this method was added, `MIN` was rejected as it was considered a different semantic (see https://github.com/rust-lang/rust/pull/72790#issuecomment-636511743). * `Duration::MAX` Both have been gated by the already existing unstable feature `duration_constants`, I can introduce a new unstable feature if needed or just re-use the `duration_saturating_ops`. We might have to decide whether: * `MIN` should be replaced by `ZERO`? * associated constants over methods?
2020-09-08Auto merge of #75585 - RalfJung:demotion, r=oli-obkbors-0/+50
Do not promote &mut of a non-ZST ever Since ~pre-1.0~ 1.36, we have accepted code like this: ```rust static mut TEST: &'static mut [i32] = { let x = &mut [1,2,3]; x }; ``` I tracked it back to https://github.com/rust-lang/rust/pull/21744, but unfortunately could not find any discussion or RFC that would explain why we thought this was a good idea. And it's not, it breaks all sorts of things -- see https://github.com/rust-lang/rust/issues/75556. To fix https://github.com/rust-lang/rust/issues/75556, we have to stop promoting non-ZST mutable references no matter the context, which is what this PR does. It's a breaking change. Notice that this still works, since it does not rely on promotion: ```rust static mut TEST: &'static mut [i32] = &mut [0,1,2]; ``` Cc `@rust-lang/wg-const-eval`
2020-09-08Add saturating methods for `Duration`marmeladema-16/+26
2020-09-07add missing feature flagRalf Jung-0/+1
2020-09-07Separate feature flagsRalf Jung-1/+2
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-07use black_box instead of local optimziation barriers in const tests where ↵Ralf Jung-19/+12
possible
2020-09-07Rollup merge of #76305 - CDirkx:const-tests, r=matkladDylan DPC-46/+0
Move various ui const tests to `library` Move: - `src\test\ui\consts\const-nonzero.rs` to `library\core` - `src\test\ui\consts\ascii.rs` to `library\core` - `src\test\ui\consts\cow-is-borrowed` to `library\alloc` Part of #76268 r? @matklad
2020-09-07Rollup merge of #76299 - CDirkx:ip-tests, r=matkladDylan DPC-111/+0
Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library` These tests are about the standard library, not the compiler itself, thus should live in `library`, see #76268.
2020-09-06add compile-fail test for &mut promotionRalf Jung-1/+34
2020-09-06do not premote non-ZST mutable references everRalf Jung-0/+17
2020-09-04Move various ui const tests to `library`Christiaan Dirkx-46/+0
Move: - `src\test\ui\consts\const-nonzero.rs` to `library\core` - `src\test\ui\consts\ascii.rs` to `library\core` - `src\test\ui\consts\cow-is-borrowed` to `library\alloc` Part of #76268
2020-09-03Auto merge of #73996 - da-x:short-unique-paths, r=petrochenkovbors-67/+64
diagnostics: shorten paths of unique symbols This is a step towards implementing a fix for #50310, and continuation of the discussion in [Pre-RFC: Nicer Types In Diagnostics - compiler - Rust Internals](https://internals.rust-lang.org/t/pre-rfc-nicer-types-in-diagnostics/11139). Impressed upon me from previous discussion in #21934 that an RFC for this is not needed, and I should just come up with code. The recent improvements to `use` suggestions that I've contributed have given rise to this implementation. Contrary to previous suggestions, it's rather simple logic, and I believe it only reduces the amount of cognitive load that a developer would need when reading type errors. ----- If a symbol name can only be imported from one place, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path to the last component. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable from anywhere.
2020-09-03Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library`Christiaan Dirkx-111/+0
These tests are about the standard library, not the compiler itself, thus should live in `library`, see #76268.
2020-09-03Rollup merge of #76142 - CDirkx:const-ip, r=ecstatic-morseDylan DPC-0/+58
Make all methods of `std::net::Ipv4Addr` const Make the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_global` (unstable) - `is_shared` (unstable) - `is_ietf_protocol_assignment` (unstable) - `is_benchmarking` (unstable) - `is_reserved` (unstable) - `is_multicast` - `is_broadcast` - `is_documentation` - `to_ipv6_compatible` - `to_ipv6_mapped` This would make all methods of `Ipv6Addr` const. Of these methods, `is_global`, `is_broadcast`, `to_ipv6_compatible`, and `to_ipv6_mapped` require a change in implementation. Part of #76205
2020-09-02pretty: trim paths of unique symbolsDan Aloni-67/+64
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-09-01Make all remaining methods of `std::net::Ipv4Addr` constChristiaan Dirkx-1/+18
Makes the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `is_global` - `is_reserved` - `is_broadcast` - `to_ipv6_compatible` - `to_ipv6_mapped` This results in all methods of `Ipv4Addr` being const. Also adds tests for these methods in a const context.
2020-09-01Add test for `Ipv4Addr` methods in a const contextChristiaan Dirkx-0/+41
2020-09-01Add trailing newline to `ipv6.rs`CDirkx-1/+1
2020-09-01Add test for `Ipv6Addr` methods in a const contextCDirkx-0/+53
2020-08-31Rollup merge of #76172 - ecstatic-morse:revert-75463, r=RalfJungTyler Mandry-15/+0
Revert #75463 This was approved by me prematurely. It needs T-libs approval. Sorry @CDirkx. r? @RalfJung
2020-08-31Rollup merge of #76139 - CDirkx:cow-is-borrowed, r=ecstatic-morseTyler Mandry-0/+15
Make `cow_is_borrowed` methods const Constify the following methods of `alloc::borrow::Cow`: - `is_borrowed` - `is_owned` Analogous to the const methods `is_some` and `is_none` for Option, and `is_ok` and `is_err` for Result. These methods are still unstable under `cow_is_borrowed`. Possible because of #49146 (Allow if and match in constants). Tracking issue: #65143
2020-09-01Add a test for constCDirkx-0/+15
Similar to the tests for Option and Result.