summary refs log tree commit diff
path: root/src/test/ui/consts
AgeCommit message (Collapse)AuthorLines
2021-11-25Rollup merge of #91185 - camelid:rm-force-overflow-checks, r=wesleywiserMatthias Krüger-1/+1
Remove `-Z force-overflow-checks` It was replaced several years ago by the stable option `-C overflow-checks`. The goal was to delete the `-Z` flag once users had migrated [1]. Now that it's been several years, it makes sense to delete the old flag. See also the discussion on Zulip [2]. [1]: https://github.com/rust-lang/rust/issues/33134#issuecomment-280484097 [2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/overflow.20checks/near/262497224 r? ```@wesleywiser``` cc ```@RalfJung```
2021-11-25Rollup merge of #91111 - cjgillot:hir-no-lower-attrs, r=michaelwoeristerMatthias Krüger-19/+1
Do not visit attributes in `ItemLowerer`. By default, AST visitors visit expressions that appear in key-value attributes. Those expressions should not be lowered to HIR, as they do not correspond to actually compiled code. Since an attribute cannot produce meaningful HIR, just skip them altogether. Fixes https://github.com/rust-lang/rust/issues/81886 Fixes https://github.com/rust-lang/rust/issues/90873 r? `@michaelwoerister`
2021-11-25Do not visit attributes in `LateResolutionVisitor`.Camille GILLOT-19/+1
2021-11-24Remove `-Z force-overflow-checks`Noah Lev-1/+1
It was replaced several years ago by the stable option `-C overflow-checks`. The goal was to delete the `-Z` flag once users had migrated [1]. Now that it's been several years, it makes sense to delete the old flag. See also the discussion on Zulip [2]. [1]: https://github.com/rust-lang/rust/issues/33134#issuecomment-280484097 [2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/overflow.20checks/near/262497224
2021-11-22`#![feature(inline_const)]` is no longer incompleteGary Guo-2/+1
2021-11-20Rollup merge of #90930 - Nilstrieb:fix-non-const-value-ice, r=estebankMatthias Krüger-0/+101
Fix `non-constant value` ICE (#90878) This also fixes the same suggestion, which was kind of broken, because it just searched for the last occurence of `const` to replace with a `let`. This works great in some cases, but when there is no const and a leading space to the file, it doesn't work and panic with overflow because it thought that it had found a const. I also changed the suggestion to only trigger if the `const` and the non-constant value are on the same line, because if they aren't, the suggestion is very likely to be wrong. Also don't trigger the suggestion if the found `const` is on line 0, because that triggers the ICE. Asking Esteban to review since he was the last one to change the relevant code. r? ``@estebank`` Fixes #90878
2021-11-20Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obkMatthias Krüger-6/+16
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912. r? ``````@oli-obk``````
2021-11-18CTFE SIMD: also test 1-element arrayRalf Jung-1/+10
2021-11-18fix CTFE/Miri simd_insert/extract on array-style repr(simd) typesRalf Jung-6/+7
2021-11-17Add a test with a leading newline for ICE #90878Nilstrieb-0/+17
2021-11-17Rollup merge of #90687 - jhpratt:const_panic, r=oli-obkMatthias Krüger-0/+46
Permit const panics in stable const contexts in stdlib Without this change, it is not possible to use `panic!` and similar (including `assert!`) in stable const contexts inside of stdlib. See #89542 for a real-world case that currently fails for this reason. This does _not_ affect any user code. For example, this snippet currently fails to compile: ```rust #[stable(feature = "foo", since = "1.0.0")] #[rustc_const_stable(feature = "foo", since = "1.0.0")] const fn foo() { assert!(false); assert!(false, "foo"); } ``` With the addition of `#[rustc_const_unstable]` to `core::panicking::panic`, the error no longer occurs. This snippet has been added verbatim in this PR as a UI test. To avoid needing to add `#![feature(core_panic)]` to libcore, the two instances of direct calls to `core::panicking::panic` have been switched to use the `panic!` macro. I am requesting prioritization because this is holding up other stabilizations such as #89542 (which is otherwise ready to merge and succeeds with this change)
2021-11-16Rollup merge of #90910 - RalfJung:const-discriminant-empty-enum, r=petrochenkovYuki Okushi-0/+7
fix getting the discriminant of a zero-variant enum Fixes https://github.com/rust-lang/rust/issues/89765
2021-11-16Rollup merge of #90892 - RalfJung:miri-partial-ptr-copy, r=oli-obkYuki Okushi-0/+38
fix ICE on Miri/CTFE copy of half a pointer Fixes https://github.com/rust-lang/miri/issues/1910 r? `````@oli-obk`````
2021-11-15Fix `non-constant value` ICE (#90878)Nilstrieb-0/+84
This also fixes the same suggestion, which was kind of broken, because it just searched for the last occurence of `const` to replace with a `let`. This works great in some cases, but when there is no const and a leading space to the file, it doesn't work and panic with overflow because it thought that it had found a const. I also changed the suggestion to only trigger if the `const` and the non-constant value are on the same line, because if they aren't, the suggestion is very likely to be wrong. Also don't trigger the suggestion if the found `const` is on line 0, because that triggers the ICE.
2021-11-14expand commentRalf Jung-0/+1
2021-11-14fix getting the discriminant of a zero-variant enumRalf Jung-0/+6
2021-11-14Move some tests to more reasonable directoriesCaio-0/+25
2021-11-13fix ICE on Miri/CTFE copy of half a pointerRalf Jung-0/+38
2021-11-13Auto merge of #89551 - jhpratt:stabilize-const_raw_ptr_deref, r=oli-obkbors-155/+73
Stabilize `const_raw_ptr_deref` for `*const T` This stabilizes dereferencing immutable raw pointers in const contexts. It does not stabilize `*mut T` dereferencing. This is behind the same feature gate as mutable references. closes https://github.com/rust-lang/rust/issues/51911
2021-11-08Permit const assertions in stdlibJacob Pratt-0/+46
2021-11-08Auto merge of #89488 - c410-f3r:testsssssss, r=petrochenkovbors-0/+94
Move some tests to more reasonable directories - 8 cc #73494 r? `@petrochenkov`
2021-11-07Auto merge of #90348 - Amanieu:asm_feature_gates, r=joshtriplettbors-1/+3
Add features gates for experimental asm features This PR splits off parts of `asm!` into separate features because they are not ready for stabilization. Specifically this adds: - `asm_const` for `const` operands. - `asm_sym` for `sym` operands. - `asm_experimental_arch` for architectures other than x86, x86_64, arm, aarch64 and riscv. r? `@nagisa`
2021-11-07Restrict tests that use needs-asm-support to non-experimentalAmanieu d'Antras-1/+3
architectures
2021-11-06Stabilize `const_raw_ptr_deref` for `*const T`Jacob Pratt-155/+73
This stabilizes dereferencing immutable raw pointers in const contexts. It does not stabilize `*mut T` dereferencing. This is placed behind the `const_raw_mut_ptr_deref` feature gate.
2021-11-06Move some tests to more reasonable directoriesCaio-0/+94
2021-11-03`addr_of!` grants mutable access, maybe?Tomasz Miąsko-6/+58
The exact set of permissions granted when forming a raw reference is currently undecided https://github.com/rust-lang/rust/issues/56604. To avoid presupposing any particular outcome, adjust the const qualification to be compatible with decision where raw reference constructed from `addr_of!` grants mutable access.
2021-10-31Test that promotion follows references when looking for dropTomasz Miąsko-9/+100
Noticed that this wasn't covered by any of existing tests. The const checking and const qualification, which currently shares the implementation with promotion, will likely need a different behaviour here (see issue #90193).
2021-10-29Auto merge of #90373 - tmiasko:union-qualification, r=oli-obkbors-0/+89
Use type based qualification for unions Union field access is currently qualified based on the qualification of a value previously assigned to the union. At the same time, every union access transmutes the content of the union, which might result in a different qualification. For example, consider constants A and B as defined below, under the current rules neither contains interior mutability, since a value used in the initial assignment did not contain `UnsafeCell` constructor. ```rust #![feature(untagged_unions)] union U { i: u32, c: std::cell::Cell<u32> } const A: U = U { i: 0 }; const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c }; ``` To avoid the issue, the changes here propose to consider the content of a union as opaque and use type based qualification for union types. Fixes #90268. `@rust-lang/wg-const-eval`
2021-10-28Use type based qualification for unionsTomasz Miąsko-0/+89
Union field access is currently qualified based on the qualification of a value previously assigned to the union. At the same time, every union access transmutes the content of the union, which might result in a different qualification. For example, consider constants A and B as defined below, under the current rules neither contains interior mutability, since a value used in the initial assignment did not contain `UnsafeCell` constructor. ```rust #![feature(untagged_unions)] union U { i: u32, c: std::cell::Cell<u32> } const A: U = U { i: 0 }; const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c }; ``` To avoid the issue, the changes here propose to consider the content of a union as opaque and use type based qualification for union types.
2021-10-26Consider indirect mutation during const qualification dataflowTomasz Miąsko-0/+93
Previously a local would be qualified if either one of two separate data flow computations indicated so. First determined if a local could contain the qualif, but ignored any forms of indirect mutation. Second determined if a local could be mutably borrowed (and so indirectly mutated), but which in turn ignored the qualif. The end result was incorrect because the effect of indirect mutation was effectivelly ignored in the all but the final stage of computation. In the new implementation the indirect mutation is directly incorporated into the qualif data flow. The local variable becomes immediately qualified once it is mutably borrowed and borrowed place type can contain the qualif. In general we will now reject additional programs, program that were prevously unintentionally accepted. There are also some cases which are now accepted but were previously rejected, because previous implementation didn't consider whether borrowed place could have the qualif under the consideration.
2021-10-23Reset qualifs when a storage of a local endsTomasz Miąsko-0/+20
to ensure that the local qualifs are affected by the state from previous loop iterations only if the local is kept alive. The change should be forward compatible with a stricter handling of indirect assignments, since storage dead invalidates all existing pointers to the local.
2021-10-22Rollup merge of #90069 - tmiasko:promoted-const-qualif, r=oli-obkYuki Okushi-0/+9
Fix const qualification when executed after promotion The const qualification was so far performed before the promotion and the implementation assumed that it will never encounter a promoted. With `const_precise_live_drops` feature, checking for live drops is delayed until after drop elaboration, which in turn runs after promotion. so the assumption is no longer true. When evaluating `NeedsNonConstDrop` it is now possible to encounter promoteds. Use type base qualification for the promoted. It is a sound approximation in general, and in the specific case of promoteds and `NeedsNonConstDrop` it is precise. Fixes #89938.
2021-10-19Reject closures in patternsTomasz Miąsko-0/+8
2021-10-19Rollup merge of #89997 - cameron1024:const-str-as-bytes-ice, r=JohnTitorMatthias Krüger-0/+28
Add test for issue #84957 - `str.as_bytes()` in a `const` expression Hi, this PR adds a test for issue #84957 . I'm quite new to rustc so let me know if there's anything else that needs doing 😄 Closes #84957
2021-10-19Fix const qualification when executed after promotionTomasz Miąsko-0/+9
The const qualification was so far performed before the promotion and the implementation assumed that it will never encounter a promoted. With `const_precise_live_drops` feature, checking for live drops is delayed until after drop elaboration, which in turn runs after promotion. so the assumption is no longer true. When evaluating `NeedsNonConstDrop` it is now possible to encounter promoteds. Use type base qualification for the promoted. It is a sound approximation in general, and in the specific case of promoteds and `NeedsNonConstDrop` it is precise.
2021-10-18Do not promote values with const drop that need to be droppedTomasz Miąsko-0/+39
Changes from #88558 allowed using `~const Drop` in constants by introducing a new `NeedsNonConstDrop` qualif. The new qualif was also used for promotion purposes, and allowed promotion to happen for values that needs to be dropped but which do have a const drop impl. Since for promoted the drop implementation is never executed, this lead to observable change in behaviour. For example: ```rust struct Panic(); impl const Drop for Panic { fn drop(&mut self) { panic!(); } } fn main() { let _ = &Panic(); } ``` Restore the use of `NeedsDrop` qualif during promotion to avoid the issue.
2021-10-18add test for issue 84957cameron-0/+28
2021-10-16Auto merge of #89860 - camsteffen:macro-semi, r=petrochenkovbors-7/+7
Remove trailing semicolon from macro call span Macro call site spans are now less surprising/more consistent since they no longer contain a semicolon after the macro call. The downside is that we need to do a little guesswork to get the semicolon in diagnostics. But this should not be noticeable since it is rare for the semicolon to not immediately follow the macro call.
2021-10-16Rollup merge of #89509 - jhpratt:stabilize-const_unreachable_unchecked, ↵Matthias Krüger-8/+5
r=oli-obk Stabilize `unreachable_unchecked` as `const fn` Closes #53188 This PR stabilizes `core::hint::unreachable_unchecked` as `const fn`. MIRI is able to detect when this method is called. Stabilization was delayed until `const_panic` was stabilized so as to avoid users calling this method in its place (thus resulting in runtime UB). With #89508, that is no longer an issue. ````@rustbot```` label +A-const-eval +A-const-fn +T-lang +S-blocked (not sure why it's T-lang, but that's what the tracking issue is)
2021-10-15Bless testsCameron Steffen-7/+7
2021-10-13Rollup merge of #89768 - hellow554:tests, r=Mark-SimulacrumYuki Okushi-0/+21
add some more testcases resolves #52893 resolves #68295 resolves #87750 resolves #88071 All these issues have been fixed according to glacier. Just adding a test so it can be closed. Can anybody tell me why the github keywords do not work? 🤔 Please edit this post if you can fix it.
2021-10-12add some more testcasesMarcel Hellwig-0/+21
2021-10-11Add enum_intrinsics_non_enums lintFlying-Toast-1/+1
2021-10-08bless warningsEliza Weisman-0/+1
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-04Rollup merge of #89482 - hkmatsumoto:patch-diagnostics, r=joshtriplettManish Goregaokar-9/+9
Follow the diagnostic output style guide Detected by #89455.
2021-10-04Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplettJubilee-194/+85
Stabilize `const_panic` Closes #51999 FCP completed in #89006 ```@rustbot``` label +A-const-eval +A-const-fn +T-lang cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04Stabilize `const_panic`Jacob Pratt-194/+85
2021-10-04Stabilize `unreachable_unchecked` as `const fn`Jacob Pratt-8/+5
2021-10-03Practice diagnostic message conventionHirochika Matsumoto-12/+12
2021-10-03Follow the diagnostic output style guideHirochika Matsumoto-9/+9