Skip to content

Add experimental fallible::Vec#157394

Open
ChrisDenton wants to merge 1 commit into
rust-lang:mainfrom
ChrisDenton:fallible-vec
Open

Add experimental fallible::Vec#157394
ChrisDenton wants to merge 1 commit into
rust-lang:mainfrom
ChrisDenton:fallible-vec

Conversation

@ChrisDenton
Copy link
Copy Markdown
Member

@ChrisDenton ChrisDenton commented Jun 3, 2026

Tracking issue: #157392

There are a few things to be aware of here:

  1. This is still experimental. It might be removed at any time so we have to be careful about any interdependency between this and Vec
  2. Vec is a pretty crucial part of rust's standard library. We have to be extremely careful touching its code. We might regress performance or make debugging worse.

With that in mind, this PR does the minimum necessary for an MVP fallible::Vec. The only actually new thing it adds is fallible push and push_mut methods. The rest just forwards to Vec equivalents. Further APIs can be added (carefully) afterwards.

I apologise for the number of lines changed in the PR but they are mostly copy/pasted docs (I wanted them for the testable examples mostly). We should probably find a better way of duplicating them but I think this works for a minimally intrusive experiment.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 3, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 3, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Copy Markdown
Member Author

 -	   = note: multiple `impl`s satisfying `Vec<_>: aux::Trait` found in the `unstable_impl_method_selection_aux` crate:
 -	           - impl aux::Trait for Vec<u32>;
 -	           - impl aux::Trait for Vec<u64>
 +	   = note: multiple `impl`s satisfying `std::vec::Vec<_>: aux::Trait` found in the `unstable_impl_method_selection_aux` crate:
 +	           - impl aux::Trait for std::vec::Vec<u32>;
 +	           - impl aux::Trait for std::vec::Vec<u64>

Ooph, that's unfortunate. Simplest thing is to rename this type. But I do wonder if that could be fixed.

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/consts/too_generic_eval_ice.current/too_generic_eval_ice.current.stderr`
diff of stderr:

30    |
31    = help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
32    = help: the following other types implement trait `PartialEq<Rhs>`:
+              `&[T]` implements `PartialEq<FallibleVec<U, A>>`
33              `&[T]` implements `PartialEq<Vec<U, A>>`
34              `&[T]` implements `PartialEq<[U; N]>`
35              `&[u8; N]` implements `PartialEq<ByteStr>`

36              `&[u8; N]` implements `PartialEq<ByteString>`
37              `&[u8]` implements `PartialEq<ByteStr>`
38              `&[u8]` implements `PartialEq<ByteString>`
-              `&mut [T]` implements `PartialEq<Vec<U, A>>`
-              `&mut [T]` implements `PartialEq<[U; N]>`
-            and 11 others
+              `&mut [T]` implements `PartialEq<FallibleVec<U, A>>`
+            and 14 others
42 
43 error: aborting due to 4 previous errors
44 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/too_generic_eval_ice.rs`

error in revision `current`: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/too_generic_eval_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/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "current" "--check-cfg" "cfg(test,FALSE,current,next)" "--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/aarch64-unknown-linux-gnu/test/ui/consts/too_generic_eval_ice.current" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: constant expression depends on a generic parameter
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:13
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |             ^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:9
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |         ^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:30
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |                              ^^
   |
   = note: this may fail depending on what value the parameter takes

error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:30
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |                              ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]`
   |
   = help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             `&[T]` implements `PartialEq<FallibleVec<U, A>>`
             `&[T]` implements `PartialEq<Vec<U, A>>`
             `&[T]` implements `PartialEq<[U; N]>`
             `&[u8; N]` implements `PartialEq<ByteStr>`
             `&[u8; N]` implements `PartialEq<ByteString>`
             `&[u8]` implements `PartialEq<ByteStr>`
             `&[u8]` implements `PartialEq<ByteString>`
             `&mut [T]` implements `PartialEq<FallibleVec<U, A>>`
           and 14 others

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
---
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/macros/assert-ne-no-invalid-help-issue-146204/assert-ne-no-invalid-help-issue-146204.stderr`
diff of stderr:

6    |
7    = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
8    = help: the following other types implement trait `PartialEq<Rhs>`:
+              `&[T]` implements `PartialEq<FallibleVec<U, A>>`
9              `&[T]` implements `PartialEq<Vec<U, A>>`
10              `&[T]` implements `PartialEq<[U; N]>`
11              `&[u8; N]` implements `PartialEq<ByteStr>`

12              `&[u8; N]` implements `PartialEq<ByteString>`
13              `&[u8]` implements `PartialEq<ByteStr>`
14              `&[u8]` implements `PartialEq<ByteString>`
-              `&mut [T]` implements `PartialEq<Vec<U, A>>`
-              `&mut [T]` implements `PartialEq<[U; N]>`
-            and 11 others
+              `&mut [T]` implements `PartialEq<FallibleVec<U, A>>`
+            and 14 others
18 
19 error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
20   --> $DIR/assert-ne-no-invalid-help-issue-146204.rs:19:5

24    |
25    = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
26    = help: the following other types implement trait `PartialEq<Rhs>`:
+              `&[T]` implements `PartialEq<FallibleVec<U, A>>`
27              `&[T]` implements `PartialEq<Vec<U, A>>`
28              `&[T]` implements `PartialEq<[U; N]>`
29              `&[u8; N]` implements `PartialEq<ByteStr>`

30              `&[u8; N]` implements `PartialEq<ByteString>`
31              `&[u8]` implements `PartialEq<ByteStr>`
32              `&[u8]` implements `PartialEq<ByteString>`
-              `&mut [T]` implements `PartialEq<Vec<U, A>>`
-              `&mut [T]` implements `PartialEq<[U; N]>`
-            and 11 others
+              `&mut [T]` implements `PartialEq<FallibleVec<U, A>>`
+            and 14 others
36 
37 error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
38   --> $DIR/assert-ne-no-invalid-help-issue-146204.rs:5:30


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args macros/assert-ne-no-invalid-help-issue-146204.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/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.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/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-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/aarch64-unknown-linux-gnu/test/ui/macros/assert-ne-no-invalid-help-issue-146204" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
##[error]  --> /checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs:16:5
   |
LL |     assert_ne!(buf, b"----");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `[u8; 4] == &[u8; 4]`
   |
   = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             `&[T]` implements `PartialEq<FallibleVec<U, A>>`
             `&[T]` implements `PartialEq<Vec<U, A>>`
             `&[T]` implements `PartialEq<[U; N]>`
             `&[u8; N]` implements `PartialEq<ByteStr>`
             `&[u8; N]` implements `PartialEq<ByteString>`
             `&[u8]` implements `PartialEq<ByteStr>`
             `&[u8]` implements `PartialEq<ByteString>`
             `&mut [T]` implements `PartialEq<FallibleVec<U, A>>`
           and 14 others

error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
##[error]  --> /checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs:19:5
   |
LL |     assert_eq!(buf, b"----");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `[u8; 4] == &[u8; 4]`
   |
   = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             `&[T]` implements `PartialEq<FallibleVec<U, A>>`
             `&[T]` implements `PartialEq<Vec<U, A>>`
             `&[T]` implements `PartialEq<[U; N]>`
             `&[u8; N]` implements `PartialEq<ByteStr>`
             `&[u8; N]` implements `PartialEq<ByteString>`
             `&[u8]` implements `PartialEq<ByteStr>`
             `&[u8]` implements `PartialEq<ByteString>`
             `&mut [T]` implements `PartialEq<FallibleVec<U, A>>`
           and 14 others

error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
##[error]  --> /checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs:5:30
   |
LL |                 if *left_val == *right_val {
   |                              ^^ no implementation for `[u8; 4] == &[u8; 4]`
...
LL |     local_assert_ne!(buf, b"----");
   |     ------------------------------ in this macro invocation
   |
   = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
   = note: this error originates in the macro `local_assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider dereferencing here
   |
LL |                 if *left_val == **right_val {
   |                                 +

error: aborting due to 3 previous errors

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants