about summary refs log tree commit diff
path: root/tests/ui/consts/const-eval
AgeCommit message (Collapse)AuthorLines
2025-07-18Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJungMatthias Krüger-86/+150
Show the offset, length and memory of uninit read errors r? ``@RalfJung`` I want to improve memory dumps in general. Not sure yet how to do so best within rust diagnostics, but in a perfect world I could generate a dummy in-memory file (that contains the rendered memory dump) that we then can then provide regular rustc `Span`s to. So we'd basically report normal diagnostics for them with squiggly lines and everything.
2025-07-18Rollup merge of #143925 - oli-obk:slice-const-partialeq, r=fee1-deadMatthias Krüger-4/+5
Make slice comparisons const This needed a fix for `derive_const`, too, as it wasn't usable in libcore anymore as trait impls need const stability attributes. I think we can't use the same system as normal trait impls while `const_trait_impl` is still unstable. r? ```@fee1-dead``` cc rust-lang/rust#143800
2025-07-18Show the memory of uninit readsOli Scherer-78/+142
2025-07-17Report the range of uninit bytes in CTFE errorsOli Scherer-15/+15
2025-07-17Make `derive_const` usable within libcore againOli Scherer-4/+5
Also make it *only* usable on nightly
2025-07-17Rollup merge of #143595 - fee1-dead-contrib:push-sylpykzkmynr, ↵León Orell Valerian Liehr-26/+201
r=RalfJung,fee1-dead add `const_make_global`; err for `const_allocate` ptrs if didn't call Implements as discussed on Zulip: [#t-compiler/const-eval > const heap](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const.20heap/with/527125421) r? ```@rust-lang/wg-const-eval``` Fixes https://github.com/rust-lang/rust/issues/129233
2025-07-16const heap: fix ICE on forgotten make_globalRalf Jung-12/+5
2025-07-16Comment more code and make tests clearerDeadbeef-11/+24
Co-Authored-By: Ralf Jung <post@ralfj.de>
2025-07-16add `const_make_global`; err for `const_allocate` ptrs if didn't callDeadbeef-8/+177
Co-Authored-By: Ralf Jung <post@ralfj.de> Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-15constify some methods using `SliceIndex`Oli Scherer-7/+8
2025-06-22Implement DesugaringKind::FormatLiteralmejrs-1/+1
2025-06-08Auto merge of #142008 - RalfJung:const-eval-error-here, r=oli-obkbors-171/+171
const-eval error: always say in which item the error occurred I don't see why "is this generic" should make a difference. It may be reasonable to key this on whether the error occurs in a `const fn` that was invoked by a const (making it non-obvious which constant it is) vs inside the body of the const. r? `@oli-obk`
2025-06-07const-eval error: always say in which item the error occurredRalf Jung-171/+171
also adjust the wording a little so that we don't say "the error occurred here" for two different spans
2025-06-06reword suggestion messageEsteban Küber-1/+1
2025-06-02Clarify why we are talking about a failed const eval at a random placeOli Scherer-167/+167
2025-06-02Use the informative error as the main const eval error messageOli Scherer-1232/+1162
2025-05-29Rollup merge of #141571 - RalfJung:float-tests, r=tgross35Jacob Pratt-46/+0
coretests: extend and simplify float tests Also de-duplicate tests by removing a ui test that duplicates the tests in core. r? `@tgross35`
2025-05-28coretests: add abs() and copysign() tests, and remove now-unnecessary ui testRalf Jung-46/+0
2025-05-28Auto merge of #141668 - tgross35:rollup-03gg6lf, r=tgross35bors-39/+26
Rollup of 8 pull requests Successful merges: - rust-lang/rust#140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`) - rust-lang/rust#140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`) - rust-lang/rust#141252 (gvn: bail out unavoidable non-ssa locals in repeat) - rust-lang/rust#141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored) - rust-lang/rust#141551 (Make two transmute-related MIR lints into HIR lint) - rust-lang/rust#141591 (ci: fix llvm test coverage) - rust-lang/rust#141647 (Bump master `stage0` compiler) - rust-lang/rust#141659 (Add `Result::map_or_default` and `Option::map_or_default`) r? `@ghost` `@rustbot` modify labels: rollup
2025-05-27Rollup merge of #141551 - compiler-errors:hir-lints, r=BoxyUwUTrevor Gross-39/+26
Make two transmute-related MIR lints into HIR lint Make `PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS` (rust-lang/rust#130540) and `UNNECESSARY_TRANSMUTES` (rust-lang/rust#136083) into "normal" HIR-based lints. Funny enough this came up in the review of the latter (https://github.com/rust-lang/rust/pull/136083#issuecomment-2614301413), but I guess it just was overlooked. But anywyas, there's no reason for these to be MIR lints; in fact, it makes the suggestions for them a bit more complicated than necessary. Note that there's probably a few more simplifications and improvements to be done here. Follow-ups can be done in a separate PR, especially if they're about the messaging and suggestions themselves, which I didn't write.
2025-05-27Auto merge of #129658 - saethlin:spare-a-crumb, r=jhprattbors-10/+2
Add some track_caller info to precondition panics Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful. I thought of this while looking at https://github.com/rust-lang/rust/pull/129642#issuecomment-2311703898. The changes to `tests/ui/const*` happen because the const-eval interpreter skips `#[track_caller]` frames in its backtraces. The perf implications of this are: * Increased debug binary sizes. The caller_location implementation requires that the additional data we want to display here be stored in const allocations, which are deduplicated but not across crates. There is no impact on optimized build sizes. The panic path and the caller location data get optimized out. * The compile time hit to opt-incr-patched bitmaps happens because the patch changes the line number of some function calls with precondition checks, causing us to go from 0 dirty CGUs to 1 dirty CGU. * The other compile time hits are marginal but real, and due to doing a handful of new queries. Adding more useful data isn't completely free.
2025-05-25const-check: stop recommending the use of rustc_allow_const_fn_unstableRalf Jung-6/+1
2025-05-25Make PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS into a HIR lintMichael Goulet-39/+26
2025-05-21Add some track_caller info to precondition panicsBen Kimock-10/+2
2025-05-20make std::intrinsic functions actually be intrinsicsRalf Jung-3/+3
2025-05-02Rollup merge of #140521 - RalfJung:oob-error, r=saethlinMatthias Krüger-8/+8
interpret: better error message for out-of-bounds pointer arithmetic and accesses Fixes https://github.com/rust-lang/rust/issues/93881 r? `@saethlin`
2025-05-01Clean up "const" situation in format_args!().Mara Bos-4/+4
Rather than marking the Argument::new_display etc. functions as non-const, this marks the Arguments::new_v1 functions as non-const.
2025-04-30interpret: better error message for out-of-bounds pointer arithmetic and ↵Ralf Jung-8/+8
accesses
2025-04-30Rollup merge of #139624 - m-ou-se:unconst-format-args, r=jhprattMatthias Krüger-1/+14
Don't allow flattened format_args in const. Fixes https://github.com/rust-lang/rust/issues/139136 Fixes https://github.com/rust-lang/rust/issues/139621 We allow `format_args!("a")` in const, but don't allow any format_args with arguments in const, such as `format_args!("{}", arg)`. However, we accidentally allow `format_args!("hello {}", "world")` in const, as it gets flattened to `format_args!("hello world")`. This also applies to panic in const. This wasn't supposed to happen. I added protection against this in the format args flattening code, ~~but I accidentally marked a function as const that shouldn't have been const~~ but this was removed in https://github.com/rust-lang/rust/pull/135139. This is a breaking change. The crater found no breakage, however. This breaks things like: ```rust const _: () = if false { panic!("a {}", "a") }; ``` and ```rust const F: std::fmt::Arguments<'static> = format_args!("a {}", "a"); ```
2025-04-30Add test for format_args!("{}", 0) in const.Mara Bos-1/+14
2025-04-30compiletest: Make diagnostic kind mandatory on line annotationsVadim Petrochenkov-290/+318
2025-04-24Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etcbendn-5/+7
2025-04-08UI tests: add missing diagnostic kinds where possibleVadim Petrochenkov-13/+13
2025-03-25compiletest: Support matching on diagnostics without a spanVadim Petrochenkov-0/+9
2025-03-14Do not suggest using `-Zmacro-backtrace` for builtin macrosEsteban Küber-50/+0
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-11Implement `#[define_opaque]` attribute for functions.Oli Scherer-14/+33
2025-03-01Rollup merge of #136503 - estebank:const-panic, r=RalfJungMatthias Krüger-180/+127
Tweak output of const panic diagnostic ### Shorten span of panic failures in const context Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown. ``` error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:11:9 | LL | MaybeUninit::<!>::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ panic: aborted execution: attempted to instantiate uninhabited type `!` ``` ``` error[E0080]: evaluation of `Fail::<i32>::C` failed --> $DIR/collect-in-dead-closure.rs:9:19 | LL | const C: () = panic!(); | ^^^^^^^^ explicit panic | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ``` error[E0080]: evaluation of constant value failed --> $DIR/uninhabited.rs:87:9 | LL | assert!(false); | ^^^^^^^^^^^^^^ assertion failed: false | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ### Remove duplicated span from const eval frame list When the primary span for a const error is the same as the first frame in the const error report, skip it. ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ the failure occurred here = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ note: inside `_CONST` --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered --> $DIR/issue-88434-removal-index-should-be-less.rs:3:23 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^^ ``` r? ``@oli-obk``
2025-02-28Shorten span of panic failures in const contextEsteban Küber-180/+127
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown. ``` error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:11:9 | LL | MaybeUninit::<!>::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!` ``` ``` error[E0080]: evaluation of `Fail::<i32>::C` failed --> $DIR/collect-in-dead-closure.rs:9:19 | LL | const C: () = panic!(); | ^^^^^^^^ evaluation panicked: explicit panic | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ``` error[E0080]: evaluation of constant value failed --> $DIR/uninhabited.rs:41:9 | LL | assert!(false); | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- When the primary span for a const error is the same as the first frame in the const error report, skip it. ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ evaluation panicked: explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ the failure occurred here = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ note: inside `_CONST` --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- Revert order of constant evaluation errors Point at the code the user wrote first and std functions last. ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ evaluation panicked: Some error occurred | note: called from `my_fn` --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred | note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ```
2025-02-27make `simd_insert` and `simd_extract` `const fn`sFolkert de Vries-16/+1
2025-02-27remove most `simd_` intrinsic declaration in testsFolkert de Vries-5/+11
instead, we can just import the intrinsics from core
2025-01-30Auto merge of #134824 - niklasf:int_from_ascii, r=ibraheemdevbors-4/+8
Implement `int_from_ascii` (#134821) Provides unstable `T::from_ascii()` and `T::from_ascii_radix()` for integer types `T`, as drafted in tracking issue #134821. To deduplicate documentation without additional macros, implementations of `isize` and `usize` no longer delegate to equivalent integer types. After #132870 they are inlined anyway.
2025-01-27Remove all dead files inside tests/ui/León Orell Valerian Liehr-18/+0
2025-01-25Fix typo in const stability error messageDeadbeef-1/+1
2025-01-07Update tests.Mara Bos-1/+1
2025-01-05[generic_assert] Constify methods used by the formatting systemCaio-23/+3
2025-01-01Try to write the panic message with a single `write_all` callJohn Kåre Alsaker-0/+1
2024-12-27Implement `int_from_ascii` (#134821)Niklas Fiekas-4/+8
Provides unstable `T::from_ascii()` and `T::from_ascii_radix()` for integer types `T`, as drafted in tracking issue #134821. To deduplicate documentation without additional macros, implementations of `isize` and `usize` no longer delegate to equivalent integer types. After #132870 they are inlined anyway.
2024-12-27Remove the `-test` suffix from normalize directivesZalathar-27/+27
2024-12-23Note def descr in NonConstFunctionCallMichael Goulet-7/+7
2024-12-12Filter empty lines, comments and delimiters from previous to last multiline ↵Esteban Küber-5/+0
span rendering