about summary refs log tree commit diff
path: root/tests/ui/consts/const-eval
AgeCommit message (Collapse)AuthorLines
2025-09-24const validation: better error for maybe-null referencesRalf Jung-19/+51
2025-09-24const-eval: improve and actually test the errors when pointers might be ↵Ralf Jung-7/+42
outside the range of a scalar
2025-09-08const-eval: disable pointer fragment supportRalf Jung-0/+54
2025-09-03don't uppercase error messagesSasha Pourcelot-167/+167
a more general version of https://github.com/rust-lang/rust/pull/146080. after a bit of hacking in [`fluent.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_fluent_macro/src/fluent.rs), i discovered that i'm not the only one that is bad at following guidelines :sweat_smile:. this pr lowercases the first letter of all the error messages in the codebase. (i did not change things that are traditionally uppercased such as _MIR_, _ABI_ or _C_) i think it's reasonable to run a `@bors try` so all the test suite is checked, as i cannot run some of the tests on my machine. i double checked (and replaced manually) all the old error messages, but better be safe than sorry. in the future i will try to add a check in `x test tidy` that errors if an error message starts with an uppercase letter.
2025-08-19bless tests with new lint messagesKarol Zwolak-1/+1
2025-08-17Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obkbors-27/+189
const-eval: full support for pointer fragments This fixes https://github.com/rust-lang/const-eval/issues/72 and makes `swap_nonoverlapping` fully work in const-eval by enhancing per-byte provenance tracking with tracking of *which* of the bytes of the pointer this one is. Later, if we see all the same bytes in the exact same order, we can treat it like a whole pointer again without ever risking a leak of the data bytes (that encode the offset into the allocation). This lifts the limitation that was discussed quite a bit in https://github.com/rust-lang/rust/pull/137280. For a concrete piece of code that used to fail and now works properly consider this example doing a byte-for-byte memcpy in const without using intrinsics: ```rust use std::{mem::{self, MaybeUninit}, ptr}; type Byte = MaybeUninit<u8>; const unsafe fn memcpy(dst: *mut Byte, src: *const Byte, n: usize) { let mut i = 0; while i < n { *dst.add(i) = *src.add(i); i += 1; } } const _MEMCPY: () = unsafe { let ptr = &42; let mut ptr2 = ptr::null::<i32>(); // Copy from ptr to ptr2. memcpy(&mut ptr2 as *mut _ as *mut _, &ptr as *const _ as *const _, mem::size_of::<&i32>()); assert!(*ptr2 == 42); }; ``` What makes this code tricky is that pointers are "opaque blobs" in const-eval, we cannot just let people look at the individual bytes since *we don't know what those bytes look like* -- that depends on the absolute address the pointed-to object will be placed at. The code above "breaks apart" a pointer into individual bytes, and then puts them back together in the same order elsewhere. This PR implements the logic to properly track how those individual bytes relate to the original pointer, and to recognize when they are in the right order again. We still reject constants where the final value contains a not-fully-put-together pointer: I have no idea how one could construct an LLVM global where one byte is defined as "the 3rd byte of a pointer to that other global over there" -- and even if LLVM supports this somehow, we can leave implementing that to a future PR. It seems unlikely to me anyone would even want this, but who knows.^^ This also changes the behavior of Miri, by tracking the order of bytes with provenance and only considering a pointer to have valid provenance if all bytes are in the original order again. This is related to https://github.com/rust-lang/unsafe-code-guidelines/issues/558. It means one cannot implement XOR linked lists with strict provenance any more, which is however only of theoretical interest. Practically I am curious if anyone will show up with any code that Miri now complains about - that would be interesting data. Cc `@rust-lang/opsem`
2025-08-14Rollup merge of #144631 - fneddy:fix_be_test_intrinsic_const_bad, ↵Jakub Beránek-4/+5
r=compiler-errors Fix test intrinsic-raw_eq-const-bad for big-endian The test fails on s390x and presumably other big-endian systems, due to print of raw values. To fix the tests remove the raw output values in the error note with normalize-stderr.
2025-08-06Add support for shortening `Instance` and use itEsteban Küber-1/+1
Replace ad-hoc type path shortening logic for recursive mono instantiation errors to use `tcx.short_string()` instead.
2025-07-30Fix tests for big-endianEduard Stefes-4/+5
The tests fail on s390x and presumably other big-endian systems, due to print of raw values and padding bytes. To fix the tests remove the raw output values in the error note with `normalize-stderr`.
2025-07-30const-eval: full support for pointer fragmentsRalf Jung-27/+189
2025-07-26Rollup merge of #144356 - GuillaumeGomez:gcc-ignore-tests, r=jieyouxuTrevor Gross-2/+4
Add `ignore-backends` annotations in failing GCC backend ui tests Follow-up of https://github.com/rust-lang/rust/pull/144125. In the GCC backend, we don't support all ui tests yet and we have a list of tests we currently ignore available [here](https://github.com/rust-lang/rustc_codegen_gcc/blob/master/tests/failing-ui-tests.txt). This PR adds the `ignore-backends` annotations to the corresponding ui tests. The second commit is a fix to compiletest, complaining about `ignore-backends`. r? ```@jieyouxu```
2025-07-24Rollup merge of #144014 - dianne:edition-guide-links, r=estebankLeón Orell Valerian Liehr-1/+1
don't link to the nightly version of the Edition Guide in stable lints As reported in rust-lang/rust#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them. This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang/rust#144006.
2025-07-23Add `ignore-backends` annotations in failing GCC backend ui testsGuillaume Gomez-2/+4
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-16future-incompat lints: don't link to the nightly edition-guide versiondianne-1/+1
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