about summary refs log tree commit diff
path: root/tests/ui/consts
AgeCommit message (Collapse)AuthorLines
2024-09-14interpret: fix dealing with overflow during slice indexingRalf Jung-0/+22
2024-09-13Update tests for hidden references to mutable staticObei Sideg-6/+8
2024-09-13Auto merge of #129137 - camelid:lazy-def-macro-const, r=BoxyUwUbors-3/+3
Fix anon const def-creation when macros are involved Fixes #128016. Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s, which don't have associated `DefId`s. To deal with the fact that we don't have resolution information in `DefCollector`, we decided to implement a process where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we would avoid creating a def for it in `DefCollector`. If later, in AST lowering, we realized it turned out to be a unit struct literal, or we were lowering it to something that didn't use `hir::ConstArg`, we'd create its def there. However, let's say we have a macro `m!()` that expands to a reference to a free constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`), then in def collection, it appears to be a nontrivial anon const and we create a def. But the macro expands to something that looks like a trivial const arg, but is not, so in AST lowering we "fix" the mistake we assumed def collection made and create a def for it. This causes a duplicate definition ICE. The long-term fix for this is to delay the creation of defs for all expression-like nodes until AST lowering (see #128844 for an incomplete attempt at this). This would avoid issues like this one that are caused by hacky workarounds. However, doing this uncovers a pre-existing bug with opaque types that is quite involved to fix (see #129023). In the meantime, this PR fixes the bug by delaying def creation for anon consts whose bodies are macro invocations until after we expand the macro and know what is inside it. This is accomplished by adding information to create the anon const's def to the data in `Resolver.invocation_parents`. r? `@BoxyUwU`
2024-09-12Re-enable `ConstArgKind::Path` lowering by defaultNoah Lev-3/+3
...and remove the `const_arg_path` feature gate as a result. It was only a stopgap measure to fix the regression that the new lowering introduced (which should now be fixed by this PR).
2024-09-12Rollup merge of #130101 - RalfJung:const-cleanup, r=fee1-deadMatthias Krüger-3/+1
some const cleanup: remove unnecessary attributes, add const-hack indications I learned that we use `FIXME(const-hack)` on top of the "const-hack" label. That seems much better since it marks the right place in the code and moves around with the code. So I went through the PRs with that label and added appropriate FIXMEs in the code. IMO this means we can then remove the label -- Cc ``@rust-lang/wg-const-eval.`` I also noticed some const stability attributes that don't do anything useful, and removed them. r? ``@fee1-dead``
2024-09-11Rollup merge of #129835 - RalfJung:float-tests, r=workingjubileeJubilee-248/+0
enable const-float-classify test, and test_next_up/down on 32bit x86 The test_next_up/down tests have been disabled on all 32bit x86 targets, which goes too far -- they should definitely work on our (tier 1) i686 target, it is only without SSE that we might run into trouble due to https://github.com/rust-lang/rust/issues/114479. However, I cannot reproduce that trouble any more -- maybe that got fixed by https://github.com/rust-lang/rust/pull/123351? The const-float-classify test relied on const traits "because we can", and got disabled when const traits got removed. That's an unfortunate reduction in test coverage of our float functionality, so let's restore the test in a way that does not rely on const traits. The const-float tests are actually testing runtime behavior as well, and I don't think that runtime behavior is covered anywhere else. Probably they shouldn't be called "const-float", but we don't have a `tests/ui/float` folder... should I create one and move them there? Are there any other ui tests that should be moved there? I also removed some FIXME referring to not use x87 for Rust-to-Rust-calls -- that has happened in #123351 so this got fixed indeed. Does that mean we can simplify all that float code again? I am not sure how to test it. Is running the test suite with an i586 target enough? Cc ```@tgross35``` ```@workingjubilee```
2024-09-10move float tests into their own dirJubilee Young-248/+0
2024-09-10turn errors that should be impossible due to our static checks into ICEsRalf Jung-1/+4
2024-09-10const-eval interning: accpt interior mutable pointers in final value (but ↵Ralf Jung-472/+79
keep rejecting mutable references)
2024-09-09Ban non-array SIMDScott McMurray-16/+7
2024-09-08remove const_slice_index annotations, it never had a feature gate anywayRalf Jung-3/+1
2024-09-08const: make ptr.is_null() stop execution on ambiguityRalf Jung-0/+39
2024-09-07Rollup merge of #129555 - RalfJung:const_float_bits_conv, r=dtolnayMatthias Krüger-5/+3
stabilize const_float_bits_conv This stabilizes `const_float_bits_conv`, and thus fixes https://github.com/rust-lang/rust/issues/72447. With https://github.com/rust-lang/rust/pull/128596 having landed, this is entirely a libs-only question now. ```rust impl f32 { pub const fn to_bits(self) -> u32; pub const fn from_bits(v: u32) -> Self; pub const fn to_be_bytes(self) -> [u8; 4]; pub const fn to_le_bytes(self) -> [u8; 4] pub const fn to_ne_bytes(self) -> [u8; 4]; pub const fn from_be_bytes(bytes: [u8; 4]) -> Self; pub const fn from_le_bytes(bytes: [u8; 4]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self; } impl f64 { pub const fn to_bits(self) -> u64; pub const fn from_bits(v: u64) -> Self; pub const fn to_be_bytes(self) -> [u8; 8]; pub const fn to_le_bytes(self) -> [u8; 8] pub const fn to_ne_bytes(self) -> [u8; 8]; pub const fn from_be_bytes(bytes: [u8; 8]) -> Self; pub const fn from_le_bytes(bytes: [u8; 8]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self; } ```` Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
2024-09-04propagate `tainted_by_errors` in `MirBorrowckCtxt::emit_errors`Folkert de Vries-2/+8
2024-09-01stabilize const_float_bits_convRalf Jung-5/+3
2024-09-01Rollup merge of #129207 - GrigorenkoPV:elided-is-named, r=cjgillotMatthias Krüger-3/+23
Lint that warns when an elided lifetime ends up being a named lifetime As suggested in https://github.com/rust-lang/rust/issues/48686#issuecomment-1817334575 Fixes #48686
2024-08-31Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgrbors-2/+2
Rollup of 11 pull requests Successful merges: - #128523 (Add release notes for 1.81.0) - #129605 (Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen) - #129650 (Clean up `library/profiler_builtins/build.rs`) - #129651 (skip stage 0 target check if `BOOTSTRAP_SKIP_TARGET_SANITY` is set) - #129684 (Enable Miri to pass pointers through FFI) - #129762 (Update the `wasm-component-ld` binary dependency) - #129782 (couple more crash tests) - #129816 (tidy: say which feature gate has a stability issue mismatch) - #129818 (make the const-unstable-in-stable error more clear) - #129824 (Fix code examples buttons not appearing on click on mobile) - #129826 (library: Fix typo in `core::mem`) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-31make the const-unstable-in-stable error more clearRalf Jung-2/+2
2024-08-31Rollup merge of #129659 - RalfJung:const-fn-lang-feat, r=fee1-deadMatthias Krüger-0/+20
const fn stability checking: also check declared language features Fixes https://github.com/rust-lang/rust/issues/129656 `@oli-obk` I assume it is just an oversight that this didn't use `features().declared()`? Or is there a deep reason that this must only check `declared_lib_features`?
2024-08-31elided_named_lifetimes: bless & add testsPavel Grigorenko-3/+23
2024-08-31const fn stability checking: also check declared language featuresRalf Jung-0/+20
2024-08-28Rollup merge of #129613 - RalfJung:interpret-target-feat, r=saethlinMatthias Krüger-11/+6
interpret: do not make const-eval query result depend on tcx.sess The check against calling functions with missing target features uses `tcx.sess` to determine which target features are available. However, this can differ between different crates in a crate graph, so the same const-eval query can come to different conclusions about whether a constant evaluates successfully or not -- which is bad, we should consistently get the same result everywhere.
2024-08-27Rollup merge of #129507 - RalfJung:per-fn-const_precise_live_drops, ↵Matthias Krüger-0/+29
r=wesleywiser make it possible to enable const_precise_live_drops per-function This makes const_precise_live_drops work with rustc_allow_const_fn_unstable so that we can stabilize individual functions that rely on const_precise_live_drops. The goal is that we can use that to stabilize some of https://github.com/rust-lang/rust/issues/67441 without having to stabilize const_precise_live_drops.
2024-08-26Rollup merge of #129190 - rezwanahmedsami:master, r=tgross35Matthias Krüger-1/+69
Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs Fixes #129163 try-job: x86_64-msvc try-job: x86_64-mingw try-job: i686-msvc try-job: i686-mingw
2024-08-26interpret: do not make const-eval query result depend on tcx.sessRalf Jung-11/+6
2024-08-25tweak rustc_allow_const_fn_unstable hint, and add back test for ↵Ralf Jung-8/+16
stable-const-can-only-call-stable-const
2024-08-25make it possible to enable const_precise_live_drops per-functionRalf Jung-0/+29
2024-08-24Rollup merge of #129246 - BoxyUwU:feature_gate_const_arg_path, r=cjgillotMatthias Krüger-3/+3
Retroactively feature gate `ConstArgKind::Path` This puts the lowering introduced by #125915 under a feature gate until we fix the regressions introduced by it. Alternative to whole sale reverting the PR since it didn't seem like a very clean revert and I think this is generally a step in the right direction and don't want to get stuck landing and reverting the PR over and over :) cc #129137 ``@camelid,`` tests taken from there. beta is branching soon so I think it makes sense to not try and rush that fix through since it wont have much time to bake and if it has issues we can't simply revert it on beta. Fixes #128016
2024-08-24Rollup merge of #129199 - RalfJung:writes_through_immutable_pointer, ↵Matthias Krüger-52/+11
r=compiler-errors make writes_through_immutable_pointer a hard error This turns the lint added in https://github.com/rust-lang/rust/pull/118324 into a hard error. This has been reported in cargo's future-compat reports since Rust 1.76 (released in February). Given that const_mut_refs is still unstable, it should be impossible to even hit this error on stable: we did accidentally stabilize some functions that can cause this error, but that got reverted in https://github.com/rust-lang/rust/pull/117905. Still, let's do a crater run just to be sure. Given that this should only affect unstable code, I don't think it needs an FCP, but let's Cc ``@rust-lang/lang`` anyway -- any objection to making this unambiguous UB into a hard error during const-eval? This can be viewed as part of https://github.com/rust-lang/rust/pull/129195 which is already nominated for discussion.
2024-08-24Rollup merge of #128596 - RalfJung:const_fn_floating_point_arithmetic, ↵Matthias Krüger-139/+48
r=nnethercote stabilize const_fn_floating_point_arithmetic Part of https://github.com/rust-lang/rust/issues/128288 Fixes https://github.com/rust-lang/rust/issues/57241 The existing test `tests/ui/consts/const_let_eq_float.rs` ([link](https://github.com/RalfJung/rust/blob/const_fn_floating_point_arithmetic/tests/ui/consts/const_let_eq_float.rs)) covers the basics, and also Miri has extensive tests covering the interpreter's float machinery. Also, that machinery can already be used on stable inside `const`/`static` initializers, just not inside `const fn`. This was explicitly called out in https://github.com/rust-lang/rfcs/pull/3514 so in a sense t-lang just recently already FCP'd this, but let's hear from them whether they want another FCP for the stabilization here or whether that was covered by the FCP for the RFC. Cc ``@rust-lang/lang`` ### Open items - [x] Update the Reference: https://github.com/rust-lang/reference/pull/1566
2024-08-22stabilize const_fn_floating_point_arithmeticRalf Jung-139/+48
2024-08-22Do not rely on names to find lifetimes.Camille GILLOT-6/+6
2024-08-21Rollup merge of #129281 - Nadrieril:tweak-unreachable-lint-wording, r=estebankMatthias Krüger-4/+4
Tweak unreachable lint wording Some tweaks to the notes added in https://github.com/rust-lang/rust/pull/128034. r? `@estebank`
2024-08-19Reword the "unreachable pattern" explanationsNadrieril-4/+4
2024-08-19Retroactively feature gate `ConstArgKind::Path`Boxy-3/+3
2024-08-18stabilize raw_ref_opRalf Jung-49/+35
2024-08-18Added #[cfg(target_arch = x86_64)] to f16 and f128Rezwan ahmed sami-2/+7
2024-08-18Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rsRezwan ahmed sami-1/+64
2024-08-17make writes_through_immutable_pointer a hard errorRalf Jung-52/+11
2024-08-17more clear NAN names and fix broken_floats logicRalf Jung-12/+14
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-08-17disable problematic float-conv tests in i586 targetsRalf Jung-6/+13
also fix typo in const-float-bits-conv
2024-08-16float to/from bits and classify: update comments regarding non-conformant ↵Ralf Jung-183/+22
hardware
2024-08-13Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlinbors-77/+152
miri: make vtable addresses not globally unique Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair. To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.) r? `@saethlin` Fixes https://github.com/rust-lang/miri/issues/3737
2024-08-10Update testsNadrieril-2/+2
2024-08-09interpret: make identity upcasts a NOP again to avoid them generating a new ↵Ralf Jung-77/+152
random vtable
2024-08-01fix the way we detect overflow for inbounds arithmetic (and tweak the error ↵Ralf Jung-2/+2
message)
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-7/+7
2024-08-01on a signed deref check, mention the right pointer in the errorRalf Jung-16/+16
2024-07-27improve dangling/oob errors and make them more uniformRalf Jung-57/+59
2024-07-27miri: fix offset_from behavior on wildcard pointersRalf Jung-5/+5