rust icon indicating copy to clipboard operation
rust copied to clipboard

Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const

Open RalfJung opened this issue 1 year ago • 21 comments
trafficstars

This stabilizes const_mut_refs and const_refs_to_cell. That allows a bunch of things on stable:

  • Mentioning &mut types
  • Creating &mut and *mut values
  • Creating &T and *const T values where T contains interior mutability
  • Dereferencing &mut and *mut values (both for reads and writes)

The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error:

#[allow(invalid_reference_casting)]
const _: () = {
    let mut val = 15;
    let ptr = &val as *const i32 as *mut i32;
    unsafe { *ptr = 16; }
};

The main limitation that is enforced is that the final value of a const (or non-mut static) may not contain &mut values nor interior mutable & values. This is necessary because the memory those references point to becomes read-only when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression:

  • A static analysis rejects (interior) mutable references when the referee looks like it may outlive the current MIR body.
  • To be extra sure, this static check is complemented by a "safety net" of dynamic checks. ("Dynamic" in the sense of "running during/after const-evaluation, e.g. at runtime of this code" -- in contrast to "static" which works entirely by looking at the MIR without evaluating it.)
    • After the final value is computed, we do a type-driven traversal of the entire value, and if we find any &mut or interior-mutable & we error out.
    • However, the type-driven traversal cannot traverse union or raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs. This part of the "safety net" is only active for mutable references since with shared references, it has false positives.

Altogether this should prevent people from leaking (interior) mutable references out of the const initializer.

While updating the tests I learned that surprisingly, this code gets rejected:

const _: Vec<i32> = {
    let mut x = Vec::<i32>::new(); //~ ERROR destructor of `Vec<i32>` cannot be evaluated at compile-time
    let r = &mut x;
    let y = x;
    y
};

The analysis that rejects destructors in const is very conservative when it sees an &mut being created to x, and then considers x to be always live. See here for a longer explanation. const_precise_live_drops will solve this, so I consider this problem to be tracked by https://github.com/rust-lang/rust/issues/73255.

Cc @rust-lang/wg-const-eval @rust-lang/lang Fixes https://github.com/rust-lang/rust/issues/57349 Fixes https://github.com/rust-lang/rust/issues/80384

RalfJung avatar Aug 17 '24 12:08 RalfJung

r? @estebank

rustbot has assigned @estebank. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Aug 17 '24 12:08 rustbot

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

rustbot avatar Aug 17 '24 12:08 rustbot

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#13 2.618 Building wheels for collected packages: reuse
#13 2.620   Building wheel for reuse (pyproject.toml): started
#13 2.863   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 2.864   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132715 sha256=dfa09868353292d98f811d3efdb0d54d07389e808efc71d68e3b93c514bf8bec
#13 2.864   Stored in directory: /tmp/pip-ephem-wheel-cache-cwvcl1xb/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#13 2.867 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#13 3.257 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#13 3.257 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#13 3.773 Collecting virtualenv
#13 3.773 Collecting virtualenv
#13 3.808   Downloading virtualenv-20.26.3-py3-none-any.whl (5.7 MB)
#13 3.879      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.7/5.7 MB 82.3 MB/s eta 0:00:00
#13 3.918 Collecting distlib<1,>=0.3.7
#13 3.921   Downloading distlib-0.3.8-py2.py3-none-any.whl (468 kB)
#13 3.928      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 KB 87.2 MB/s eta 0:00:00
#13 3.961 Collecting filelock<4,>=3.12.2
#13 3.963   Downloading filelock-3.15.4-py3-none-any.whl (16 kB)
#13 3.992 Collecting platformdirs<5,>=3.9.1
#13 3.995   Downloading platformdirs-4.2.2-py3-none-any.whl (18 kB)
#13 4.075 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 4.262 Successfully installed distlib-0.3.8 filelock-3.15.4 platformdirs-4.2.2 virtualenv-20.26.3
#13 DONE 4.3s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      221120 kB
DirectMap2M:     8167424 kB
DirectMap1G:    10485760 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://ci-artifacts.rust-lang.org/rustc-builds-alt/426a60abc213b28a7c7198e475476b6e650d871f/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
extracting /checkout/obj/build/cache/llvm-426a60abc213b28a7c7198e475476b6e650d871f-true/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz to /checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm
---
##[endgroup]
fmt check
fmt: checked 5493 files
tidy check
tidy error: file `/checkout/tests/ui/consts/const-eval/issue-114994-fail.rs` no longer exists and should be removed from the exclusions in `src/tools/tidy/src/issues.txt`
tidy error: file `/checkout/tests/ui/consts/const-eval/issue-114994.rs` no longer exists and should be removed from the exclusions in `src/tools/tidy/src/issues.txt`
tidy error: /checkout/tests/ui/static/raw-ref-deref-without-unsafe.rs: leading newline
tidy error: /checkout/tests/ui/static/raw-ref-deref-without-unsafe.rs: leading newline
##[error]tidy error: /checkout/library/core/tests/lib.rs:30: line not in alphabetical order
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (24.1)
  Downloading pip-24.2-py3-none-any.whl.metadata (3.6 kB)
Downloading pip-24.2-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 73.2 MB/s eta 0:00:00
Installing collected packages: pip
---
Successfully installed pip-24.2
linting python files
All checks passed!
checking C++ file formatting
some tidy checks failed
Command has failed. Rerun with -v to see more details.
  local time: Sat Aug 17 12:42:35 UTC 2024
  network time: Sat, 17 Aug 2024 12:42:35 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

rust-log-analyzer avatar Aug 17 '24 12:08 rust-log-analyzer

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
assertion failed: progress.is_finished()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

FAILED TEST: tests/ui/missing_const_for_fn/could_be_const.rs
command: CLIPPY_CONF_DIR="tests" RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "--error-format=json" "--emit=metadata" "-Aunused" "-Ainternal_features" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Dwarnings" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps" "--extern=clippy_config=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_config-5cb2662642d944d5.rlib" "--extern=clippy_lints=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-615fcdc2d139e2f5.rlib" "--extern=clippy_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-f24bf63863a7ecad.rlib" "--extern=futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libfutures-51007212676bc4d7.rlib" "--extern=if_chain=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-49fd91c51cbf146b.rlib" "--extern=itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-5b58552e029722f2.rlib" "--extern=parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libparking_lot-d305caadebee1c78.rlib" "--extern=quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libquote-c7a7b5bff16134e2.rlib" "--extern=regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libregex-6c9cd5e89eb65a39.rlib" "--extern=serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libserde-1e0d66824ae1083d.rlib" "--extern=serde_derive=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libserde_derive-2233436f0b800125.so" "--extern=syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libsyn-91b42af8abdc8b28.rlib" "--extern=tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libtokio-38bf9cf4165a3cda.rlib" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui_test/tests/ui/missing_const_for_fn" "tests/ui/missing_const_for_fn/could_be_const.rs" "--edition" "2021"
error: actual output differed from expected
Execute `cargo uibless` to update `tests/ui/missing_const_for_fn/could_be_const.stderr` to the actual output
--- tests/ui/missing_const_for_fn/could_be_const.stderr
+++ <stderr output>
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:20:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:19:5
    |
 LL | /     fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:27:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:26:1
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:46:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:45:1
    |
 LL | / unsafe fn four() -> i32 {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:52:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:51:1
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:61:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:60:1
    |
 LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:75:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:74:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:74:9
    |
 LL | /         pub fn b(self, a: &A) -> B {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:85:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:84:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:84:5
    |
 LL | /     fn const_fn_stabilized_before_msrv(byte: u8) {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:97:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:96:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:96:1
    |
 LL | / fn msrv_1_46() -> i32 {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:117:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:116:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:116:1
    |
 LL | fn d(this: D) {}
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:125:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:124:9
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:170:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:169:9
    |
 LL | /         pub fn new(strings: Vec<String>) -> Self {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:175:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:174:9
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:205:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:204:5
    |
 LL |     fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
 error: aborting due to 21 previous errors
 


rust-log-analyzer avatar Aug 17 '24 13:08 rust-log-analyzer

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
assertion failed: progress.is_finished()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

FAILED TEST: tests/ui/missing_const_for_fn/could_be_const.rs
command: CLIPPY_CONF_DIR="tests" RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "--error-format=json" "--emit=metadata" "-Aunused" "-Ainternal_features" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Dwarnings" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps" "--extern=clippy_config=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_config-5cb2662642d944d5.rlib" "--extern=clippy_lints=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-615fcdc2d139e2f5.rlib" "--extern=clippy_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-f24bf63863a7ecad.rlib" "--extern=futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libfutures-51007212676bc4d7.rlib" "--extern=if_chain=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-49fd91c51cbf146b.rlib" "--extern=itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-5b58552e029722f2.rlib" "--extern=parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libparking_lot-d305caadebee1c78.rlib" "--extern=quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libquote-c7a7b5bff16134e2.rlib" "--extern=regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libregex-6c9cd5e89eb65a39.rlib" "--extern=serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libserde-1e0d66824ae1083d.rlib" "--extern=serde_derive=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libserde_derive-2233436f0b800125.so" "--extern=syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libsyn-91b42af8abdc8b28.rlib" "--extern=tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libtokio-38bf9cf4165a3cda.rlib" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui_test/tests/ui/missing_const_for_fn" "tests/ui/missing_const_for_fn/could_be_const.rs" "--edition" "2021"
error: actual output differed from expected
Execute `cargo uibless` to update `tests/ui/missing_const_for_fn/could_be_const.stderr` to the actual output
--- tests/ui/missing_const_for_fn/could_be_const.stderr
+++ <stderr output>
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:21:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:19:5
    |
 LL | /     fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:28:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:26:1
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:47:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:45:1
    |
 LL | / unsafe fn four() -> i32 {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:53:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:51:1
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:62:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:60:1
    |
 LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:76:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:74:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:74:9
    |
 LL | /         pub fn b(self, a: &A) -> B {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:86:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:84:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:84:5
    |
 LL | /     fn const_fn_stabilized_before_msrv(byte: u8) {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:98:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:96:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:96:1
    |
 LL | / fn msrv_1_46() -> i32 {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:118:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:116:1
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:116:1
    |
 LL | fn d(this: D) {}
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:126:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:124:9
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:171:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:169:9
    |
 LL | /         pub fn new(strings: Vec<String>) -> Self {
 
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:176:9
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:174:9
---
 error: this could be a `const fn`
-  --> tests/ui/missing_const_for_fn/could_be_const.rs:206:5
+  --> tests/ui/missing_const_for_fn/could_be_const.rs:204:5
    |
 LL |     fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
 error: aborting due to 21 previous errors
 


rust-log-analyzer avatar Aug 17 '24 13:08 rust-log-analyzer

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
------
 > importing cache manifest from ghcr.io/rust-lang/rust-ci-cache:20d3b4d4a2629cbf7865cdbf92fe47512a7c96658c24253a045ff38e8075cd7fb37ca6fcadfa6e6d093333943ad24f6fc4f163ec5b74fd940de9d5bb03eb4d3b:
------
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
  Downloaded boml v0.3.1
   Compiling boml v0.3.1
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished `release` profile [optimized] target(s) in 3.64s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --mini-tests --std-tests`
Using system GCC
[BUILD] example
[AOT] mini_core_hello_world
/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc/mini_core_hello_world
abc

rust-log-analyzer avatar Aug 17 '24 14:08 rust-log-analyzer

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 2.812 Building wheels for collected packages: reuse
#16 2.813   Building wheel for reuse (pyproject.toml): started
#16 3.059   Building wheel for reuse (pyproject.toml): finished with status 'done'
#16 3.060   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132715 sha256=dfa09868353292d98f811d3efdb0d54d07389e808efc71d68e3b93c514bf8bec
#16 3.061   Stored in directory: /tmp/pip-ephem-wheel-cache-b603bks9/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#16 3.063 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#16 3.452 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#16 3.452 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#16 DONE 3.5s

rust-log-analyzer avatar Aug 17 '24 15:08 rust-log-analyzer

r? fee1-dead

fee1-dead avatar Aug 17 '24 15:08 fee1-dead

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
------
 > importing cache manifest from ghcr.io/rust-lang/rust-ci-cache:20d3b4d4a2629cbf7865cdbf92fe47512a7c96658c24253a045ff38e8075cd7fb37ca6fcadfa6e6d093333943ad24f6fc4f163ec5b74fd940de9d5bb03eb4d3b:
------
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
  Downloaded boml v0.3.1
   Compiling boml v0.3.1
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished `release` profile [optimized] target(s) in 3.66s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --mini-tests --std-tests`
Using system GCC
[BUILD] example
[AOT] mini_core_hello_world
/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc/mini_core_hello_world
abc
---
1 error[E0080]: it is undefined behavior to use this value
-   --> $DIR/alloc_intrinsic_uninit.rs:8:1
+   --> $DIR/alloc_intrinsic_uninit.rs:7:1
3    |
4 LL | const BAR: &i32 = unsafe { &*(intrinsics::const_allocate(4, 4) as *mut i32) };
5    | ^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected an integer

The actual 32bit.stderr differed from the expected 32bit.stderr.
Actual 32bit.stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/heap/alloc_intrinsic_uninit/alloc_intrinsic_uninit.32bit.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/const-eval/heap/alloc_intrinsic_uninit.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/const-eval/heap/alloc_intrinsic_uninit.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=i686-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/heap/alloc_intrinsic_uninit" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=x86_64-linux-gnu-gcc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/heap/alloc_intrinsic_uninit/auxiliary"
--- stderr -------------------------------
error[E0080]: it is undefined behavior to use this value
##[error]  --> /checkout/tests/ui/consts/const-eval/heap/alloc_intrinsic_uninit.rs:7:1
   |
   |
LL | const BAR: &i32 = unsafe { &*(intrinsics::const_allocate(4, 4) as *mut i32) };
   | ^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected an integer
   |
   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
   = note: the raw bytes of the constant (size: 4, align: 4) {
               ╾─a3<imm>─╼                                     │ ╾──╼

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
---
-   --> $DIR/interior-mut-const-via-union.rs:35:1
+   --> $DIR/interior-mut-const-via-union.rs:34:1
3    |
4 LL | fn main() {
5    | ^^^^^^^^^ constructing invalid value at .<deref>.y.<enum-variant(B)>.0: encountered `UnsafeCell` in read-only memory
10            }
11 
12 note: erroneous constant encountered
-   --> $DIR/interior-mut-const-via-union.rs:37:25
-   --> $DIR/interior-mut-const-via-union.rs:37:25
+   --> $DIR/interior-mut-const-via-union.rs:36:25
14    |
15 LL |     let _: &'static _ = &C;

17 
18 note: erroneous constant encountered
-   --> $DIR/interior-mut-const-via-union.rs:37:25
-   --> $DIR/interior-mut-const-via-union.rs:37:25
+   --> $DIR/interior-mut-const-via-union.rs:36:25
20    |
21 LL |     let _: &'static _ = &C;


The actual 32bit.stderr differed from the expected 32bit.stderr.
Actual 32bit.stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/interior-mut-const-via-union/interior-mut-const-via-union.32bit.stderr
Actual 32bit.stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/interior-mut-const-via-union/interior-mut-const-via-union.32bit.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/interior-mut-const-via-union.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/interior-mut-const-via-union.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=i686-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/interior-mut-const-via-union" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=x86_64-linux-gnu-gcc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/interior-mut-const-via-union/auxiliary"
--- stderr -------------------------------
error[E0080]: it is undefined behavior to use this value
##[error]  --> /checkout/tests/ui/consts/interior-mut-const-via-union.rs:34:1
   |
   |
LL | fn main() { //~ ERROR it is undefined behavior to use this value
   | ^^^^^^^^^ constructing invalid value at .<deref>.y.<enum-variant(B)>.0: encountered `UnsafeCell` in read-only memory
   |
   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
   = note: the raw bytes of the constant (size: 4, align: 4) {
           }

note: erroneous constant encountered
  --> /checkout/tests/ui/consts/interior-mut-const-via-union.rs:36:25
  --> /checkout/tests/ui/consts/interior-mut-const-via-union.rs:36:25
   |
LL |     let _: &'static _ = &C;

note: erroneous constant encountered
  --> /checkout/tests/ui/consts/interior-mut-const-via-union.rs:36:25
   |
   |
LL |     let _: &'static _ = &C;
   |
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
------------------------------------------

rust-log-analyzer avatar Aug 17 '24 16:08 rust-log-analyzer

Turns out this is less entangled with https://github.com/rust-lang/rust/pull/128543 than I thought, so I rebased this PR away from the other one.

RalfJung avatar Aug 18 '24 09:08 RalfJung

:umbrella: The latest upstream changes (presumably #129261) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 19 '24 10:08 bors

I made a slightly concerning discovery... with this PR, this will be possible on stable:

use std::cell::UnsafeCell;

const C: () = {
    let mut x = UnsafeCell::new(0);
    let ptr = (&*&mut x).get(); // just x.get() would not work!
};

For some reason we const-stabilized UnsafeCell::get many years ago. So far it should have been basically impossibly to call that function, but by combining stable mutable references with the fact that &* (a reborrow) bypasses the interior mutability check, the above code is now accepted.

So while this PR does not stabilize const_refs_to_cell, it makes it so that the const_refs_to_cell feature gate can be fairly easily circumvented at least in some cases.

I am debating whether

  1. we should try to revert the const-stabilization of UnsafeCell::get (and UnsafeCell::get_raw)
  2. we should adjust the const checking for interior mutable & to detect the above case, and hope that this actually covers all the cases
  3. we should stabilize const_refs_to_cell while we are at it (but IMO we have to figure out this question before we do that)

RalfJung avatar Aug 21 '24 15:08 RalfJung

I have now implemented option 2, which seems like a sensible thing to do anyway. The above example now requires the const_refs_to_cell feature gate, as it should.

There might still be ways to get &UnsafeCell references, but they are extremely dubious.

RalfJung avatar Aug 21 '24 20:08 RalfJung

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
------
 > importing cache manifest from ghcr.io/rust-lang/rust-ci-cache:20d3b4d4a2629cbf7865cdbf92fe47512a7c96658c24253a045ff38e8075cd7fb37ca6fcadfa6e6d093333943ad24f6fc4f163ec5b74fd940de9d5bb03eb4d3b:
------
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
-   --> $DIR/mutable_memory_validation.rs:15:1
+ error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
+   --> $DIR/mutable_memory_validation.rs:15:36
3    |
4 LL | const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
-    | ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in read-only memory
6    |
6    |
-    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
-    = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
-                HEX_DUMP
+    = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
+    = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
+    = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
12 error: aborting due to 1 previous error
13 

- For more information about this error, try `rustc --explain E0080`.
---
To only update this specific test, also pass `--test-args statics/mutable_memory_validation.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/statics/mutable_memory_validation.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/statics/mutable_memory_validation" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/statics/mutable_memory_validation/auxiliary"
--- stderr -------------------------------
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
##[error]  --> /checkout/tests/ui/statics/mutable_memory_validation.rs:15:36
   |
   |
LL | const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
   |
   = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
   = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
   = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
------------------------------------------

rust-log-analyzer avatar Aug 21 '24 20:08 rust-log-analyzer

I have now implemented option 2, which seems like a sensible thing to do anyway. The above example now requires the const_refs_to_cell feature gate, as it should.

~~It looks like const_refs_to_cell could use a tracking issue~~ It's right here, why could I not find it https://github.com/rust-lang/rust/issues/80384

tgross35 avatar Aug 21 '24 21:08 tgross35

Hm, but this will still work on stable unfortunately:

use std::cell::UnsafeCell;

const FOO: i32 = unsafe {
    let mut x = UnsafeCell::new(42);
    let y: &UnsafeCell<i32> = std::mem::transmute(&mut x);
    *y.get() = 13;
    *y.get()
};

fn main() {
    assert_eq!(FOO, 13);
}

This is mutating x via interior mutability. Though at least it has to first create a mutable reference to bypass the no-interior-mutability check...

RalfJung avatar Aug 22 '24 08:08 RalfJung

Thinking about this some more... I don't think this has to be a blocker. It is still the case that you can't have an &expr with interior mutability that way, so pointers like y above will not have the shared_ref flag set in their compile-time provenance, so if somehow one of those pointers ends up in the final value of the constant they should be rejected.

At this point I don't even know how many dozens of hours of work lifetime extension of tail expressions in static/const has caused. All I know is I deeply despise this feature.^^ It's probably the rustc feature with the worst ratio between "amount of work needed to make it make sense" and "benefit it brings to Rust programmers"...

RalfJung avatar Aug 22 '24 11:08 RalfJung

:umbrella: The latest upstream changes (presumably #129521) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 25 '24 11:08 bors

:umbrella: The latest upstream changes (presumably #129508) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 26 '24 11:08 bors

https://github.com/rust-lang/rust/pull/129508 re-did the logic for checking whether a borrow can escape the current constant or not. It now uses MIR dataflow to directly compute the actual property we care about.

So let's avoid all those tricky questions about using mutable references to create interior mutable references by simply stabilizing const_mut_refs together with const_refs_to_cell. :)

RalfJung avatar Aug 26 '24 12:08 RalfJung

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
------
 > importing cache manifest from ghcr.io/rust-lang/rust-ci-cache:20d3b4d4a2629cbf7865cdbf92fe47512a7c96658c24253a045ff38e8075cd7fb37ca6fcadfa6e6d093333943ad24f6fc4f163ec5b74fd940de9d5bb03eb4d3b:
------
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
- LL |         self.0
-    |         ^^^^
-    |
-    = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
-    = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
-    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
- 
11 error[E0015]: cannot call non-const fn `<R as Deref>::deref` in constant functions
13    |


40    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
41    = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
- error: aborting due to 4 previous errors
+ error: aborting due to 3 previous errors
44 
45 Some errors have detailed explanations: E0015, E0493, E0658.
---
To only update this specific test, also pass `--test-args self/arbitrary-self-from-method-substs-ice.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/self/arbitrary-self-from-method-substs-ice.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary-self-from-method-substs-ice" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/arbitrary-self-from-method-substs-ice/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0015]: cannot call non-const fn `<R as Deref>::deref` in constant functions
   |
LL |         self.0
   |         ^^^^^^
   |
---

error[E0493]: destructor of `R` cannot be evaluated at compile-time
##[error]  --> /checkout/tests/ui/self/arbitrary-self-from-method-substs-ice.rs:10:43
   |
LL |     const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
   |                                           ^^^^ the destructor for this type cannot be evaluated in constant functions
LL |     }
   |     - value is dropped here

error[E0658]: `R` cannot be used as the type of `self` without the `arbitrary_self_types` feature
error[E0658]: `R` cannot be used as the type of `self` without the `arbitrary_self_types` feature
##[error]  --> /checkout/tests/ui/self/arbitrary-self-from-method-substs-ice.rs:10:49
   |
LL |     const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
   |
   = note: see issue #44874 <https://github.com/rust-lang/rust/issues/44874> for more information
   = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
   = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0015, E0493, E0658.
For more information about an error, try `rustc --explain E0015`.

rust-log-analyzer avatar Aug 26 '24 13:08 rust-log-analyzer

:umbrella: The latest upstream changes (presumably #129841) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 01 '24 07:09 bors

:umbrella: The latest upstream changes (presumably #129777) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 03 '24 04:09 bors

We discussed this in triage and were feeling good about this. Let's propose...

@rfcbot fcp merge

traviscross avatar Sep 04 '24 17:09 traviscross

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [x] @joshtriplett
  • [x] @nikomatsakis
  • [x] @pnkfelix
  • [x] @scottmcm
  • [x] @tmandry
  • [x] @traviscross

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. See this document for info about what commands tagged team members can give me.

rfcbot avatar Sep 04 '24 17:09 rfcbot

@rfcbot merge

This all makes sense to me.

nikomatsakis avatar Sep 04 '24 17:09 nikomatsakis

@rfcbot reviewed

nikomatsakis avatar Sep 04 '24 17:09 nikomatsakis

:bell: This is now entering its final comment period, as per the review above. :bell:

rfcbot avatar Sep 04 '24 17:09 rfcbot

@rfcbot reviewed

I'm assuming that by "dynamic" we mean "during const eval" and "ICE" is (I think) meant to be "post monomorphization error".

tmandry avatar Sep 04 '24 17:09 tmandry

I'm assuming that by "dynamic" we mean "during const eval"

Yes.

and "ICE" is (I think) meant to be "post monomorphization error".

No it's an actual ICE. It is never supposed to happen, I want the compiler to say "this is a bug" if it ever happens.

RalfJung avatar Sep 04 '24 17:09 RalfJung