rust icon indicating copy to clipboard operation
rust copied to clipboard

Implement `push_mut`

Open balt-dev opened this issue 10 months ago • 34 comments

Implementation of rust-lang/rust#135974.

balt-dev avatar Jan 24 '25 05:01 balt-dev

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ibraheemdev (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

rustbot avatar Jan 24 '25 05:01 rustbot

Sorry if I did this wrong, it's my first time!

balt-dev avatar Jan 24 '25 05:01 balt-dev

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)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
  g++ \
  make \
---

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,cpp
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#12 3.536 Building wheels for collected packages: reuse
#12 3.538   Building wheel for reuse (pyproject.toml): started
#12 3.748   Building wheel for reuse (pyproject.toml): finished with status 'done'
#12 3.749   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=be6760d5849de4a58bbe52b85ca57a55f2b32b518b17029a5ad2e530db0d4303
#12 3.749   Stored in directory: /tmp/pip-ephem-wheel-cache-704yth8x/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#12 3.752 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#12 4.148 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
#12 4.149 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
#12 4.706 Collecting virtualenv
#12 4.706 Collecting virtualenv
#12 4.780   Downloading virtualenv-20.29.1-py3-none-any.whl (4.3 MB)
#12 4.865      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 52.1 MB/s eta 0:00:00
#12 4.928 Collecting platformdirs<5,>=3.9.1
#12 4.939   Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB)
#12 4.983 Collecting filelock<4,>=3.12.2
#12 5.019 Collecting distlib<1,>=0.3.7
#12 5.031   Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
#12 5.039      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 80.7 MB/s eta 0:00:00
#12 5.039      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 80.7 MB/s eta 0:00:00
#12 5.119 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#12 5.303 Successfully installed distlib-0.3.9 filelock-3.17.0 platformdirs-4.3.6 virtualenv-20.29.1
#12 DONE 5.4s

#13 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#13 DONE 0.0s
---
DirectMap4k:      122816 kB
DirectMap2M:     6168576 kB
DirectMap1G:    12582912 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
    Finished `dev` profile [unoptimized] target(s) in 0.05s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
downloading https://static.rust-lang.org/dist/2025-01-08/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
fmt check
Diff in /checkout/library/alloc/src/vec/mod.rs:2468:
     ///
     /// ```
     /// #![feature(push_mut)]
+    ///
     /// let mut vec = vec![];
     /// // Polonius moment.
     /// // Polonius moment.
     /// let last = if let Some(v) = vec.last_mut() { v } else { vec.push_mut(0) };
Build completed unsuccessfully in 0:01:10
  local time: Fri Jan 24 05:52:17 UTC 2025
  network time: Fri, 24 Jan 2025 05:52:17 GMT
##[error]Process completed with exit code 1.

rust-log-analyzer avatar Jan 24 '25 05:01 rust-log-analyzer

A single trailing whitespace. Oops.

balt-dev avatar Jan 25 '25 20:01 balt-dev

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

Click to see the possible cause of the failure (guessed by this bot)
#22 exporting to docker image format
#22 sending tarball 27.3s done
#22 DONE 33.4s
##[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-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
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-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--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-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
---- [ui] tests/ui/stable-mir-print/basic_function.rs stdout ----
Saved the actual stdout to "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/stable-mir-print/basic_function/basic_function.stdout"
diff of stdout:

17     let mut _0: Vec<i32>;
18     let mut _2: Vec<i32>;
19     let mut _3: &Vec<i32>;
-     let  _4: ();
-     let mut _5: &mut Vec<i32>;
+     let mut _4: &mut Vec<i32>;
+     let mut _5: &mut i32;
22     debug vec => _1;
23     debug new_vec => _2;
24     bb0: {

26         _2 = <Vec<i32> as Clone>::clone(move _3) -> [return: bb1, unwind continue];
28     bb1: {
-         _5 = &mut _2;
-         _5 = &mut _2;
-         _4 = Vec::<i32>::push(move _5, 1_i32) -> [return: bb2, unwind: bb3];
+         _4 = &mut _2;
+         _5 = Vec::<i32>::push_mut(move _4, 1_i32) -> [return: bb4, unwind: bb2];
32     bb2: {
-         _0 = move _2;
-         return;
-         return;
+         drop(_2) -> [return: bb3, unwind terminate];
36     bb3: {
36     bb3: {
-         drop(_2) -> [return: bb4, unwind terminate];
+         resume;
39     bb4: {
-         resume;
+         _0 = move _2;
+         return;
+         return;
41     }
42 }
43 fn demux(_1: u8) -> u8 {

The actual stdout differed from the expected stdout.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args stable-mir-print/basic_function.rs`
To only update this specific test, also pass `--test-args stable-mir-print/basic_function.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
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/stable-mir-print/basic_function.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(test,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/stable-mir-print/basic_function" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "unpretty=stable-mir" "-Z" "mir-opt-level=3"
// WARNING: This is highly experimental output it's intended for stable-mir developers only.
// WARNING: This is highly experimental output it's intended for stable-mir developers only.
// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir.
fn foo(_1: i32) -> i32 {
    let mut _0: i32;
    let mut _2: (i32, bool);
    debug i => _1;
    bb0: {
        _2 = CheckedAdd(_1, 1_i32);
        assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", _1, 1_i32) -> [success: bb1, unwind continue];
    bb1: {
    bb1: {
        _0 = move (_2.0: i32);
    }
}
fn bar(_1: &mut Vec<i32>) -> Vec<i32> {
    let mut _0: Vec<i32>;
    let mut _0: Vec<i32>;
    let mut _2: Vec<i32>;
    let mut _3: &Vec<i32>;
    let mut _4: &mut Vec<i32>;
    let mut _5: &mut i32;
    debug vec => _1;
    debug new_vec => _2;
    bb0: {
        _3 = &(*_1);
        _2 = <Vec<i32> as Clone>::clone(move _3) -> [return: bb1, unwind continue];
    bb1: {
        _4 = &mut _2;
        _4 = &mut _2;
        _5 = Vec::<i32>::push_mut(move _4, 1_i32) -> [return: bb4, unwind: bb2];
    bb2: {
    bb2: {
        drop(_2) -> [return: bb3, unwind terminate];
    bb3: {
        resume;
    }
    bb4: {
    bb4: {
        _0 = move _2;
        return;
    }
}
fn demux(_1: u8) -> u8 {
    let mut _0: u8;
    debug input => _1;
    bb0: {
        switchInt(_1) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1];
    bb1: {
        _0 = 0_u8;
        goto -> bb5;
    }

rust-log-analyzer avatar Jan 25 '25 21:01 rust-log-analyzer

I'm not sure we should be touching Vec::push here.. maybe just duplicate the implementation?

ibraheemdev avatar Jan 25 '25 22:01 ibraheemdev

Alright, I'll do that soon.

balt-dev avatar Jan 26 '25 00:01 balt-dev

I finally got around to duplicating the implementation. College has been eating my time like a child with Halloween candy, sorry.

balt-dev avatar Feb 17 '25 22:02 balt-dev

@rustbot review

balt-dev avatar Feb 22 '25 03:02 balt-dev

@balt-dev Thanks for your contribution From wg-triage. Any updates on this PR?

alex-semenyuk avatar Apr 06 '25 10:04 alex-semenyuk

I'm sorry, college has been quite a time sink for me and I haven't had the time to follow up as of recent - I will when I can, promise!

balt-dev avatar Apr 07 '25 12:04 balt-dev

It's been a rough few months. ._.

balt-dev avatar May 30 '25 04:05 balt-dev

:warning: Warning :warning:

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    • 6a697602ce71a1621027076fae3ce764ca65c1c4

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust.git master
    $ git push --force-with-lease
    

rustbot avatar May 31 '25 01:05 rustbot

hm.

balt-dev avatar May 31 '25 05:05 balt-dev

I think I messed up my fork so bad I'll have to reset it and put my code in from scratch in order to get rid of the merge commit. At least it's copy/pasteable?

balt-dev avatar May 31 '25 05:05 balt-dev

Some changes occurred in src/tools/cargo

cc @ehuss

rustbot avatar May 31 '25 05:05 rustbot

:warning: Warning :warning:

  • Some commits in this PR modify submodules.

rustbot avatar May 31 '25 05:05 rustbot

What the hell is going on!?

balt-dev avatar May 31 '25 05:05 balt-dev

For the record: I ended up discarding my commits entirely, instead force-pushing the latest commit on the main repo to my fork, and then putting my changes back. I didn't touch src/tools/cargo at all (although it seems the latest commit, 7a7bcbbcdbf2845164a94377d0e0efebb737ffd3, did).

balt-dev avatar May 31 '25 05:05 balt-dev

The job aarch64-gnu-llvm-19-2 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
+    /// Appends an element to the back of a collection, returning a reference to it.
     ///
     /// # Panics
     ///
Diff in /checkout/library/alloc/src/vec/mod.rs:2517:
     /// # #[allow(unused)]
     /// #[derive(PartialEq, Eq, Debug)]
     /// struct Item { identifier: &'static str, count: usize }
-    /// 
+    ///
     /// impl Default for Item {
     ///     fn default() -> Self {
     ///         return Self { identifier: "stone", count: 64 }
Diff in /checkout/library/alloc/src/vec/mod.rs:2580:
     ///
     /// Takes *O*(1) time.
     #[inline]
-
     // Since there's currently no way to have multiple unstable attributes on the same item, I compromised.
     // Uncomment/delete the respective attribute when its respective issue stabilizes, since this falls under both.
     #[unstable(feature = "push_mut", issue = "135974")]
Diff in /checkout/library/alloc/src/vec/mod.rs:2587:
     // #[unstable(feature = "vec_push_within_capacity", issue = "100486")]
-
     #[must_use = "if you don't need a reference to the value, use Vec::push_within_capacity instead"]
     pub fn push_mut_within_capacity(&mut self, value: T) -> Result<&mut T, T> {
         if self.len == self.buf.capacity() {
fmt: checked 6030 files
Build completed unsuccessfully in 0:00:42
  local time: Sat May 31 05:21:46 UTC 2025
  network time: Sat, 31 May 2025 05:21:46 GMT
##[error]Process completed with exit code 1.

rust-log-analyzer avatar May 31 '25 05:05 rust-log-analyzer

@rustbot review

I need help fixing this mess.

balt-dev avatar May 31 '25 12:05 balt-dev

I've fixed your branch so as to not touch any submodules.

traviscross avatar May 31 '25 18:05 traviscross

Thank you!!

balt-dev avatar Jun 01 '25 15:06 balt-dev

Should https://github.com/rust-lang/libs-team/issues/579 be lumped in with this implementation? I don't see why not.

balt-dev avatar Jun 03 '25 04:06 balt-dev

Yes, I'd expect that should be OK. (It can always be broken out later if the reviewer prefers.)

traviscross avatar Jun 03 '25 14:06 traviscross

I'm happy to review Vec::insert_mut along with this PR, but also fine to merge after the review comment is addressed.

ibraheemdev avatar Jun 08 '25 20:06 ibraheemdev

:warning: Warning :warning:

  • Some commits in this PR modify submodules.

rustbot avatar Jun 09 '25 00:06 rustbot

...again?

balt-dev avatar Jun 09 '25 00:06 balt-dev

Sigh....

balt-dev avatar Jun 09 '25 00:06 balt-dev

@traviscross How'd you fix the submodules?

balt-dev avatar Jun 09 '25 01:06 balt-dev