f7e2cb
--- thunderbird-78.9.0/Cargo.lock.D87019-thin-vec-big-endian.diff	2021-03-22 11:34:35.584716638 +0100
f7e2cb
+++ thunderbird-78.9.0/Cargo.lock	2021-03-22 12:29:14.140624979 +0100
f7e2cb
@@ -4792,9 +4792,9 @@ checksum = "8eaa81235c7058867fa8c0e7314f
f7e2cb
 
f7e2cb
 [[package]]
f7e2cb
 name = "thin-vec"
f7e2cb
-version = "0.1.2"
f7e2cb
+version = "0.2.1"
f7e2cb
 source = "registry+https://github.com/rust-lang/crates.io-index"
f7e2cb
-checksum = "3a93c9ade36a827a69257925808463db46ffcf193442fad01eb9bdc1d31aed81"
f7e2cb
+checksum = "dcc760ada4a9f56fc6d0e81bd143984ebc7bb1b875a6891aa2fa613ca7394fc0"
f7e2cb
 
f7e2cb
 [[package]]
f7e2cb
 name = "thiserror"
f7e2cb
--- thunderbird-78.9.0/gfx/webrender_bindings/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/gfx/webrender_bindings/Cargo.toml	2021-03-22 11:34:35.587716631 +0100
f7e2cb
@@ -20,7 +20,7 @@ nsstring = { path = "../../xpcom/rust/ns
f7e2cb
 bincode = "1.0"
f7e2cb
 uuid = { version = "0.8", features = ["v4"] }
f7e2cb
 fxhash = "0.2.1"
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 swgl = { path = "../wr/swgl" }
f7e2cb
 
f7e2cb
 [dependencies.webrender]
f7e2cb
--- thunderbird-78.9.0/intl/l10n/rust/fluent-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/intl/l10n/rust/fluent-ffi/Cargo.toml	2021-03-22 11:34:35.589716625 +0100
f7e2cb
@@ -10,4 +10,4 @@ fluent-pseudo = "0.2"
f7e2cb
 intl-memoizer = "0.4"
f7e2cb
 unic-langid = "0.8"
f7e2cb
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
--- thunderbird-78.9.0/intl/locale/rust/fluent-langneg-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/intl/locale/rust/fluent-langneg-ffi/Cargo.toml	2021-03-22 11:34:35.590716623 +0100
f7e2cb
@@ -9,7 +9,7 @@ edition = "2018"
f7e2cb
 nserror = { path = "../../../../xpcom/rust/nserror" }
f7e2cb
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
f7e2cb
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 fluent-langneg = { version = "0.12.1", features = ["cldr"] }
f7e2cb
 unic-langid = "0.8"
f7e2cb
 unic-langid-ffi = { path = "../unic-langid-ffi" }
f7e2cb
--- thunderbird-78.9.0/intl/locale/rust/unic-langid-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:16.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/intl/locale/rust/unic-langid-ffi/Cargo.toml	2021-03-22 11:34:35.591716620 +0100
f7e2cb
@@ -9,5 +9,5 @@ edition = "2018"
f7e2cb
 nserror = { path = "../../../../xpcom/rust/nserror" }
f7e2cb
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
f7e2cb
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 unic-langid = { version = "0.8", features = ["likelysubtags"] }
f7e2cb
--- thunderbird-78.9.0/netwerk/socket/neqo_glue/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:40.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/netwerk/socket/neqo_glue/Cargo.toml	2021-03-22 11:34:35.600716597 +0100
f7e2cb
@@ -14,7 +14,7 @@ neqo-common = { tag = "v0.2.4", git = "h
f7e2cb
 nserror = { path = "../../../xpcom/rust/nserror" }
f7e2cb
 nsstring = { path = "../../../xpcom/rust/nsstring" }
f7e2cb
 xpcom = { path = "../../../xpcom/rust/xpcom" }
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 
f7e2cb
 [dependencies.neqo-crypto]
f7e2cb
 tag = "v0.2.4"
f7e2cb
--- thunderbird-78.9.0/security/manager/ssl/cert_storage/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:52.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/security/manager/ssl/cert_storage/Cargo.toml	2021-03-22 11:34:35.601716594 +0100
f7e2cb
@@ -18,6 +18,6 @@ rust_cascade = "0.6.0"
f7e2cb
 sha2 = "^0.8"
f7e2cb
 storage_variant = { path = "../../../../storage/variant" }
f7e2cb
 tempfile = "3"
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 time = "0.1"
f7e2cb
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
f7e2cb
--- thunderbird-78.9.0/services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:49.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml	2021-03-22 11:34:35.603716589 +0100
f7e2cb
@@ -20,5 +20,5 @@ nserror = { path = "../../../../xpcom/ru
f7e2cb
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
f7e2cb
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
f7e2cb
 storage_variant = { path = "../../../../storage/variant" }
f7e2cb
-thin-vec = { version = "0.1", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 fxa-client = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b", features = ["gecko"] }
f7e2cb
--- thunderbird-78.9.0/services/sync/golden_gate/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:35:53.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/services/sync/golden_gate/Cargo.toml	2021-03-22 11:34:35.605716584 +0100
f7e2cb
@@ -19,5 +19,5 @@ sync15-traits = { git = "https://github.
f7e2cb
 xpcom = { path = "../../../xpcom/rust/xpcom" }
f7e2cb
 
f7e2cb
 [dependencies.thin-vec]
f7e2cb
-version = "0.1.0"
f7e2cb
+version = "0.2.1"
f7e2cb
 features = ["gecko-ffi"]
f7e2cb
--- thunderbird-78.9.0/third_party/rust/thin-vec/.cargo-checksum.json.D87019-thin-vec-big-endian.diff	2021-03-22 11:34:35.606716581 +0100
f7e2cb
+++ thunderbird-78.9.0/third_party/rust/thin-vec/.cargo-checksum.json	2021-03-22 12:30:38.588587238 +0100
f7e2cb
@@ -1 +1 @@
f7e2cb
-{"files":{"Cargo.toml":"7b164cc8a702a204a4732cb4da2940711b8e3be915c258e2a972d4874d767b4c","README.md":"c26d7101e3031e7dd8890ce938e50cad7a1e6adf7fc2f2b0d3c36b03afe68c0b","src/lib.rs":"9f2a087cabfe0b6f83818323bb9004b45fe7548c51376816fd8d4572256bd0e8","src/range.rs":"bac59bcb6230367a39c7e28ac15263e4526f966cd8c72015873017f17c115aaa"},"package":"3a93c9ade36a827a69257925808463db46ffcf193442fad01eb9bdc1d31aed81"}
f7e2cb
\ No newline at end of file
f7e2cb
+{"files":{"Cargo.toml":"754c05523d17eb7591c3ea2c9294e47c05fbb257fed04b78546fb2ec7cafa8b4","README.md":"c26d7101e3031e7dd8890ce938e50cad7a1e6adf7fc2f2b0d3c36b03afe68c0b","src/lib.rs":"627c6094c3f0286dba25bc73f5672c06c5061c25b01c513d213cbdda100673a2"},"package":"dcc760ada4a9f56fc6d0e81bd143984ebc7bb1b875a6891aa2fa613ca7394fc0"}
f7e2cb
--- thunderbird-78.9.0/third_party/rust/thin-vec/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/third_party/rust/thin-vec/Cargo.toml	2021-03-22 12:32:38.577621737 +0100
f7e2cb
@@ -11,8 +11,9 @@
f7e2cb
 # will likely look very different (and much more reasonable)
f7e2cb
 
f7e2cb
 [package]
f7e2cb
+edition = "2018"
f7e2cb
 name = "thin-vec"
f7e2cb
-version = "0.1.2"
f7e2cb
+version = "0.2.1"
f7e2cb
 authors = ["Alexis Beingessner <a.beingessner@gmail.com>"]
f7e2cb
 description = "a vec that takes up less space on the stack"
f7e2cb
 homepage = "https://github.com/gankro/thin-vec"
f7e2cb
--- thunderbird-78.9.0/third_party/rust/thin-vec/src/lib.rs.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:28.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/third_party/rust/thin-vec/src/lib.rs	2021-03-22 12:34:10.271595434 +0100
f7e2cb
@@ -1,47 +1,252 @@
f7e2cb
-mod range;
f7e2cb
+//! ThinVec is exactly the same as Vec, except that it stores its `len` and `capacity` in the buffer
f7e2cb
+//! it allocates.
f7e2cb
+//!
f7e2cb
+//! This makes the memory footprint of ThinVecs lower; notably in cases where space is reserved for
f7e2cb
+//! a non-existence ThinVec<T>. So `Vec<ThinVec<T>>` and `Option<ThinVec<T>>::None` will waste less
f7e2cb
+//! space. Being pointer-sized also means it can be passed/stored in registers.
f7e2cb
+//!
f7e2cb
+//! Of course, any actually constructed ThinVec will theoretically have a bigger allocation, but
f7e2cb
+//! the fuzzy nature of allocators means that might not actually be the case.
f7e2cb
+//!
f7e2cb
+//! Properties of Vec that are preserved:
f7e2cb
+//! * `ThinVec::new()` doesn't allocate (it points to a statically allocated singleton)
f7e2cb
+//! * reallocation can be done in place
f7e2cb
+//! * `size_of::<ThinVec<T>>()` == `size_of::<Option<ThinVec<T>>>()`
f7e2cb
+//!
f7e2cb
+//! Properties of Vec that aren't preserved:
f7e2cb
+//! * `ThinVec<T>` can't ever be zero-cost roundtripped to a `Box<[T]>`, `String`, or `*mut T`
f7e2cb
+//! * `from_raw_parts` doesn't exist
f7e2cb
+//! * ThinVec currently doesn't bother to not-allocate for Zero Sized Types (e.g. `ThinVec<()>`),
f7e2cb
+//!   but it could be done if someone cared enough to implement it.
f7e2cb
+//!
f7e2cb
+//!
f7e2cb
+//!
f7e2cb
+//! # Gecko FFI
f7e2cb
+//!
f7e2cb
+//! If you enable the gecko-ffi feature, ThinVec will verbatim bridge with the nsTArray type in
f7e2cb
+//! Gecko (Firefox). That is, ThinVec and nsTArray have identical layouts *but not ABIs*, 
f7e2cb
+//! so nsTArrays/ThinVecs an be natively manipulated by C++ and Rust, and ownership can be 
f7e2cb
+//! transferred across the FFI boundary (**IF YOU ARE CAREFUL, SEE BELOW!!**).
f7e2cb
+//!
f7e2cb
+//! While this feature is handy, it is also inherently dangerous to use because Rust and C++ do not
f7e2cb
+//! know about eachother. Specifically, this can be an issue with non-POD types (types which
f7e2cb
+//! have destructors, move constructors, or are `!Copy`).
f7e2cb
+//!
f7e2cb
+//! ## Do Not Pass By Value
f7e2cb
+//!
f7e2cb
+//! The biggest thing to keep in mind is that **FFI functions cannot pass ThinVec/nsTArray 
f7e2cb
+//! by-value**. That is, these are busted APIs:
f7e2cb
+//!
f7e2cb
+//! ```rust,ignore
f7e2cb
+//! // BAD WRONG
f7e2cb
+//! extern fn process_data(data: ThinVec<u32>) { ... }
f7e2cb
+//! // BAD WRONG
f7e2cb
+//! extern fn get_data() -> ThinVec<u32> { ... }
f7e2cb
+//! ```
f7e2cb
+//!
f7e2cb
+//! You must instead pass by-reference:
f7e2cb
+//!
f7e2cb
+//! ```rust
f7e2cb
+//! # use thin_vec::*;
f7e2cb
+//! # use std::mem;
f7e2cb
+//!
f7e2cb
+//! // Read-only access, ok!
f7e2cb
+//! extern fn process_data(data: &ThinVec<u32>) {
f7e2cb
+//!     for val in data {
f7e2cb
+//!         println!("{}", val);
f7e2cb
+//!     }
f7e2cb
+//! }
f7e2cb
+//! 
f7e2cb
+//! // Replace with empty instance to take ownership, ok!
f7e2cb
+//! extern fn consume_data(data: &mut ThinVec<u32>) {
f7e2cb
+//!     let owned = mem::replace(data, ThinVec::new());
f7e2cb
+//!     mem::drop(owned);
f7e2cb
+//! }
f7e2cb
+//! 
f7e2cb
+//! // Mutate input, ok!
f7e2cb
+//! extern fn add_data(dataset: &mut ThinVec<u32>) {
f7e2cb
+//!     dataset.push(37);
f7e2cb
+//!     dataset.push(12);
f7e2cb
+//! }
f7e2cb
+//! 
f7e2cb
+//! // Return via out-param, usually ok!
f7e2cb
+//! //
f7e2cb
+//! // WARNING: output must be initialized! (Empty nsTArrays are free, so just do it!)
f7e2cb
+//! extern fn get_data(output: &mut ThinVec<u32>) {
f7e2cb
+//!     *output = thin_vec![1, 2, 3, 4, 5];
f7e2cb
+//! }
f7e2cb
+//! ```
f7e2cb
+//!
f7e2cb
+//! Ignorable Explanation For Those Who Really Want To Know Why:
f7e2cb
+//!
f7e2cb
+//! > The fundamental issue is that Rust and C++ can't currently communicate about destructors, and
f7e2cb
+//! > the semantics of C++ require destructors of function arguments to be run when the function
f7e2cb
+//! > returns. Whether the callee or caller is responsible for this is also platform-specific, so
f7e2cb
+//! > trying to hack around it manually would be messy. 
f7e2cb
+//! >
f7e2cb
+//! > Also a type having a destructor changes its C++ ABI, because that type must actually exist 
f7e2cb
+//! > in memory (unlike a trivial struct, which is often passed in registers). We don't currently
f7e2cb
+//! > have a way to communicate to Rust that this is happening, so even if we worked out the
f7e2cb
+//! > destructor issue with say, MaybeUninit, it would still be a non-starter without some RFCs
f7e2cb
+//! > to add explicit rustc support.
f7e2cb
+//! >
f7e2cb
+//! > Realistically, the best answer here is to have a "heavier" bindgen that can secretly
f7e2cb
+//! > generate FFI glue so we can pass things "by value" and have it generate by-reference code
f7e2cb
+//! > behind our back (like the cxx crate does). This would muddy up debugging/searchfox though.
f7e2cb
+//!
f7e2cb
+//! ## Types Should Be Trivially Relocatable
f7e2cb
+//!
f7e2cb
+//! Types in Rust are always trivially relocatable (unless suitably borrowed/[pinned][]/hidden).
f7e2cb
+//! This means all Rust types are legal to relocate with a bitwise copy, you cannot provide
f7e2cb
+//! copy or move constructors to execute when this happens, and the old location won't have its
f7e2cb
+//! destructor run. This will cause problems for types which have a significant location
f7e2cb
+//! (types that intrusively point into themselves or have their location registered with a service).
f7e2cb
+//!
f7e2cb
+//! While relocations are generally predictable if you're very careful, **you should avoid using
f7e2cb
+//! types with significant locations with Rust FFI**.
f7e2cb
+//!
f7e2cb
+//! Specifically, ThinVec will trivially relocate its contents whenever it needs to reallocate its
f7e2cb
+//! buffer to change its capacity. This is the default reallocation strategy for nsTArray, and is
f7e2cb
+//! suitable for the vast majority of types. Just be aware of this limitation!
f7e2cb
+//!
f7e2cb
+//! ## Auto Arrays Are Dangerous
f7e2cb
+//!
f7e2cb
+//! ThinVec has *some* support for handling auto arrays which store their buffer on the stack, 
f7e2cb
+//! but this isn't well tested.
f7e2cb
+//!
f7e2cb
+//! Regardless of how much support we provide, Rust won't be aware of the buffer's limited lifetime,
f7e2cb
+//! so standard auto array safety caveats apply about returning/storing them! ThinVec won't ever
f7e2cb
+//! produce an auto array on its own, so this is only an issue for transferring an nsTArray into
f7e2cb
+//! Rust.
f7e2cb
+//!
f7e2cb
+//! ## Other Issues
f7e2cb
+//!
f7e2cb
+//! Standard FFI caveats also apply: 
f7e2cb
+//!
f7e2cb
+//!  * Rust is more strict about POD types being initialized (use MaybeUninit if you must)
f7e2cb
+//!  * `ThinVec<T>` has no idea if the C++ version of `T` has move/copy/assign/delete overloads
f7e2cb
+//!  * `nsTArray<T>` has no idea if the Rust version of `T` has a Drop/Clone impl
f7e2cb
+//!  * C++ can do all sorts of unsound things that Rust can't catch
f7e2cb
+//!  * C++ and Rust don't agree on how zero-sized/empty types should be handled
f7e2cb
+//!
f7e2cb
+//! The gecko-ffi feature will not work if you aren't linking with code that has nsTArray
f7e2cb
+//! defined. Specifically, we must share the symbol for nsTArray's empty singleton. You will get
f7e2cb
+//! linking errors if that isn't defined.
f7e2cb
+//!
f7e2cb
+//! The gecko-ffi feature also limits ThinVec to the legacy behaviors of nsTArray. Most notably,
f7e2cb
+//! nsTArray has a maximum capacity of i32::MAX (~2.1 billion items). Probably not an issue.
f7e2cb
+//! Probably.
f7e2cb
+//!
f7e2cb
+//! [pinned]: https://doc.rust-lang.org/std/pin/index.html
f7e2cb
 
f7e2cb
 use std::{fmt, io, ptr, mem, slice};
f7e2cb
 use std::collections::Bound;
f7e2cb
 use std::iter::FromIterator;
f7e2cb
 use std::slice::IterMut;
f7e2cb
-use std::ops::{Deref, DerefMut};
f7e2cb
+use std::ops::{Deref, DerefMut, RangeBounds};
f7e2cb
 use std::marker::PhantomData;
f7e2cb
 use std::alloc::*;
f7e2cb
 use std::cmp::*;
f7e2cb
 use std::hash::*;
f7e2cb
 use std::borrow::*;
f7e2cb
-use range::RangeArgument;
f7e2cb
 use std::ptr::NonNull;
f7e2cb
 
f7e2cb
-#[cfg(not(feature = "gecko-ffi"))]
f7e2cb
-type SizeType = usize;
f7e2cb
-#[cfg(feature = "gecko-ffi")]
f7e2cb
-type SizeType = u32;
f7e2cb
+use impl_details::*;
f7e2cb
 
f7e2cb
-#[cfg(feature = "gecko-ffi")]
f7e2cb
-const AUTO_MASK: u32 = 1 << 31;
f7e2cb
-#[cfg(feature = "gecko-ffi")]
f7e2cb
-const CAP_MASK: u32 = !AUTO_MASK;
f7e2cb
+// modules: a simple way to cfg a whole bunch of impl details at once
f7e2cb
 
f7e2cb
 #[cfg(not(feature = "gecko-ffi"))]
f7e2cb
-const MAX_CAP: usize = !0;
f7e2cb
-#[cfg(feature = "gecko-ffi")]
f7e2cb
-const MAX_CAP: usize = i32::max_value() as usize;
f7e2cb
+mod impl_details {
f7e2cb
+    pub type SizeType = usize;
f7e2cb
+    pub const MAX_CAP: usize = !0;
f7e2cb
 
f7e2cb
-#[cfg(not(feature = "gecko-ffi"))]
f7e2cb
-#[inline(always)]
f7e2cb
-fn assert_size(x: usize) -> SizeType { x }
f7e2cb
+    #[inline(always)]
f7e2cb
+    pub fn assert_size(x: usize) -> SizeType { x }
f7e2cb
+}
f7e2cb
 
f7e2cb
 #[cfg(feature = "gecko-ffi")]
f7e2cb
-#[inline]
f7e2cb
-fn assert_size(x: usize) -> SizeType {
f7e2cb
-    if x > MAX_CAP as usize {
f7e2cb
-        panic!("nsTArray size may not exceed the capacity of a 32-bit sized int");
f7e2cb
+mod impl_details {
f7e2cb
+    // Support for briding a gecko nsTArray verbatim into a ThinVec.
f7e2cb
+    //
f7e2cb
+    // ThinVec can't see copy/move/delete implementations
f7e2cb
+    // from C++
f7e2cb
+    //
f7e2cb
+    // The actual layout of an nsTArray is:
f7e2cb
+    //
f7e2cb
+    // ```cpp
f7e2cb
+    // struct {
f7e2cb
+    //   uint32_t mLength;
f7e2cb
+    //   uint32_t mCapacity: 31;
f7e2cb
+    //   uint32_t mIsAutoArray: 1;
f7e2cb
+    // }
f7e2cb
+    // ```
f7e2cb
+    //
f7e2cb
+    // Rust doesn't natively support bit-fields, so we manually mask
f7e2cb
+    // and shift the bit. When the "auto" bit is set, the header and buffer
f7e2cb
+    // are actually on the stack, meaning the ThinVec pointer-to-header
f7e2cb
+    // is essentially an "owned borrow", and therefore dangerous to handle.
f7e2cb
+    // There are no safety guards for this situation.
f7e2cb
+    //
f7e2cb
+    // On little-endian platforms, the auto bit will be the high-bit of
f7e2cb
+    // our capacity u32. On big-endian platforms, it will be the low bit.
f7e2cb
+    // Hence we need some platform-specific CFGs for the necessary masking/shifting.
f7e2cb
+    // 
f7e2cb
+    // ThinVec won't ever construct an auto array. They only happen when
f7e2cb
+    // bridging from C++. This means we don't need to ever set/preserve the bit.
f7e2cb
+    // We just need to be able to read and handle it if it happens to be there.
f7e2cb
+    //
f7e2cb
+    // Handling the auto bit mostly just means not freeing/reallocating the buffer.
f7e2cb
+
f7e2cb
+    pub type SizeType = u32;
f7e2cb
+
f7e2cb
+    pub const MAX_CAP: usize = i32::max_value() as usize;
f7e2cb
+
f7e2cb
+    // Little endian: the auto bit is the high bit, and the capacity is
f7e2cb
+    // verbatim. So we just need to mask off the high bit. Note that
f7e2cb
+    // this masking is unnecessary when packing, because assert_size
f7e2cb
+    // guards against the high bit being set.
f7e2cb
+    #[cfg(target_endian = "little")]
f7e2cb
+    pub fn pack_capacity(cap: SizeType) -> SizeType {
f7e2cb
+        cap as SizeType
f7e2cb
+    }
f7e2cb
+    #[cfg(target_endian = "little")]
f7e2cb
+    pub fn unpack_capacity(cap: SizeType) -> usize {
f7e2cb
+        (cap as usize) & !(1 << 31)
f7e2cb
+    }
f7e2cb
+    #[cfg(target_endian = "little")]
f7e2cb
+    pub fn is_auto(cap: SizeType) -> bool {
f7e2cb
+        (cap & (1 << 31)) != 0
f7e2cb
+    }
f7e2cb
+
f7e2cb
+    // Big endian: the auto bit is the low bit, and the capacity is
f7e2cb
+    // shifted up one bit. Masking out the auto bit is unnecessary,
f7e2cb
+    // as rust shifts always shift in 0's for unsigned integers.
f7e2cb
+    #[cfg(target_endian = "big")]
f7e2cb
+    pub fn pack_capacity(cap: SizeType) -> SizeType {
f7e2cb
+        (cap as SizeType) << 1
f7e2cb
+    }
f7e2cb
+    #[cfg(target_endian = "big")]
f7e2cb
+    pub fn unpack_capacity(cap: SizeType) -> usize {
f7e2cb
+        (cap >> 1) as usize
f7e2cb
+    }
f7e2cb
+    #[cfg(target_endian = "big")]
f7e2cb
+    pub fn is_auto(cap: SizeType) -> bool {
f7e2cb
+        (cap & 1) != 0
f7e2cb
     }
f7e2cb
-    x as SizeType
f7e2cb
+
f7e2cb
+    #[inline]
f7e2cb
+    pub fn assert_size(x: usize) -> SizeType {
f7e2cb
+        if x > MAX_CAP as usize {
f7e2cb
+            panic!("nsTArray size may not exceed the capacity of a 32-bit sized int");
f7e2cb
+        }
f7e2cb
+        x as SizeType
f7e2cb
+    }
f7e2cb
+
f7e2cb
 }
f7e2cb
 
f7e2cb
-/// The header of a ThinVec
f7e2cb
+/// The header of a ThinVec.
f7e2cb
+///
f7e2cb
+/// The _cap can be a bitfield, so use accessors to avoid trouble.
f7e2cb
 #[repr(C)]
f7e2cb
 struct Header {
f7e2cb
     _len: SizeType,
f7e2cb
@@ -53,38 +258,10 @@ impl Header {
f7e2cb
         self._len as usize
f7e2cb
     }
f7e2cb
 
f7e2cb
-    #[cfg(feature = "gecko-ffi")]
f7e2cb
-    fn cap(&self) -> usize {
f7e2cb
-        (self._cap & CAP_MASK) as usize
f7e2cb
-    }
f7e2cb
-
f7e2cb
-    #[cfg(not(feature = "gecko-ffi"))]
f7e2cb
-    fn cap(&self) -> usize {
f7e2cb
-        self._cap as usize
f7e2cb
-    }
f7e2cb
-
f7e2cb
     fn set_len(&mut self, len: usize) {
f7e2cb
         self._len = assert_size(len);
f7e2cb
     }
f7e2cb
 
f7e2cb
-    #[cfg(feature = "gecko-ffi")]
f7e2cb
-    fn set_cap(&mut self, cap: usize) {
f7e2cb
-        debug_assert!(cap & (CAP_MASK as usize) == cap);
f7e2cb
-        // FIXME: this is busted because it reads uninit memory
f7e2cb
-        // debug_assert!(!self.uses_stack_allocated_buffer());
f7e2cb
-        self._cap = assert_size(cap) & CAP_MASK;
f7e2cb
-    }
f7e2cb
-
f7e2cb
-    #[cfg(feature = "gecko-ffi")]
f7e2cb
-    fn uses_stack_allocated_buffer(&self) -> bool {
f7e2cb
-        self._cap & AUTO_MASK != 0
f7e2cb
-    }
f7e2cb
-
f7e2cb
-    #[cfg(not(feature = "gecko-ffi"))]
f7e2cb
-    fn set_cap(&mut self, cap: usize) {
f7e2cb
-        self._cap = assert_size(cap);
f7e2cb
-    }
f7e2cb
-
f7e2cb
     fn data<T>(&self) -> *mut T {
f7e2cb
         let header_size = mem::size_of::<Header>();
f7e2cb
         let padding = padding::<T>();
f7e2cb
@@ -102,6 +279,41 @@ impl Header {
f7e2cb
     }
f7e2cb
 }
f7e2cb
 
f7e2cb
+
f7e2cb
+#[cfg(feature = "gecko-ffi")]
f7e2cb
+impl Header {
f7e2cb
+    fn cap(&self) -> usize {
f7e2cb
+        unpack_capacity(self._cap)
f7e2cb
+    }
f7e2cb
+
f7e2cb
+    fn set_cap(&mut self, cap: usize) {
f7e2cb
+        // debug check that our packing is working
f7e2cb
+        debug_assert_eq!(unpack_capacity(pack_capacity(cap as SizeType)), cap);
f7e2cb
+        // FIXME: this assert is busted because it reads uninit memory
f7e2cb
+        // debug_assert!(!self.uses_stack_allocated_buffer());
f7e2cb
+
f7e2cb
+        // NOTE: this always stores a cleared auto bit, because set_cap
f7e2cb
+        // is only invoked by Rust, and Rust doesn't create auto arrays.
f7e2cb
+        self._cap = pack_capacity(assert_size(cap));
f7e2cb
+    }
f7e2cb
+
f7e2cb
+    fn uses_stack_allocated_buffer(&self) -> bool {
f7e2cb
+        is_auto(self._cap)
f7e2cb
+    }
f7e2cb
+}
f7e2cb
+
f7e2cb
+#[cfg(not(feature = "gecko-ffi"))]
f7e2cb
+impl Header {
f7e2cb
+    fn cap(&self) -> usize {
f7e2cb
+        self._cap as usize
f7e2cb
+    }
f7e2cb
+
f7e2cb
+    fn set_cap(&mut self, cap: usize) {
f7e2cb
+        self._cap = assert_size(cap);
f7e2cb
+    }
f7e2cb
+}
f7e2cb
+
f7e2cb
+
f7e2cb
 /// Singleton that all empty collections share.
f7e2cb
 /// Note: can't store non-zero ZSTs, we allocate in that case. We could
f7e2cb
 /// optimize everything to not do that (basically, make ptr == len and branch
f7e2cb
@@ -118,9 +330,7 @@ extern {
f7e2cb
 
f7e2cb
 // TODO: overflow checks everywhere
f7e2cb
 
f7e2cb
-// Utils
f7e2cb
-
f7e2cb
-fn oom() -> ! { std::process::abort() }
f7e2cb
+// Utils for computing layouts of allocations
f7e2cb
 
f7e2cb
 fn alloc_size<T>(cap: usize) -> usize {
f7e2cb
     // Compute "real" header size with pointer math
f7e2cb
@@ -165,9 +375,10 @@ fn layout<T>(cap: usize) -> Layout {
f7e2cb
 fn header_with_capacity<T>(cap: usize) -> NonNull<Header> {
f7e2cb
     debug_assert!(cap > 0);
f7e2cb
     unsafe {
f7e2cb
-        let header = alloc(layout::<T>(cap)) as *mut Header;
f7e2cb
+        let layout = layout::<T>(cap);
f7e2cb
+        let header = alloc(layout) as *mut Header;
f7e2cb
 
f7e2cb
-        if header.is_null() { oom() }
f7e2cb
+        if header.is_null() { handle_alloc_error(layout) }
f7e2cb
 
f7e2cb
         // "Infinite" capacity for zero-sized types:
f7e2cb
         (*header).set_cap(if mem::size_of::<T>() == 0 { MAX_CAP } else { cap });
f7e2cb
@@ -179,28 +390,8 @@ fn header_with_capacity<T>(cap: usize) -
f7e2cb
 
f7e2cb
 
f7e2cb
 
f7e2cb
-/// ThinVec is exactly the same as Vec, except that it stores its `len` and `capacity` in the buffer
f7e2cb
-/// it allocates.
f7e2cb
-///
f7e2cb
-/// This makes the memory footprint of ThinVecs lower; notably in cases where space is reserved for
f7e2cb
-/// a non-existence ThinVec<T>. So `Vec<ThinVec<T>>` and `Option<ThinVec<T>>::None` will waste less
f7e2cb
-/// space. Being pointer-sized also means it can be passed/stored in registers.
f7e2cb
-///
f7e2cb
-/// Of course, any actually constructed ThinVec will theoretically have a bigger allocation, but
f7e2cb
-/// the fuzzy nature of allocators means that might not actually be the case.
f7e2cb
-///
f7e2cb
-/// Properties of Vec that are preserved:
f7e2cb
-/// * `ThinVec::new()` doesn't allocate (it points to a statically allocated singleton)
f7e2cb
-/// * reallocation can be done in place
f7e2cb
-/// * `size_of::<ThinVec<T>>()` == `size_of::<Option<ThinVec<T>>>()`
f7e2cb
-///   * NOTE: This is only possible when the `unstable` feature is used.
f7e2cb
-///
f7e2cb
-/// Properties of Vec that aren't preserved:
f7e2cb
-/// * `ThinVec<T>` can't ever be zero-cost roundtripped to a `Box<[T]>`, `String`, or `*mut T`
f7e2cb
-/// * `from_raw_parts` doesn't exist
f7e2cb
-/// * ThinVec currently doesn't bother to not-allocate for Zero Sized Types (e.g. `ThinVec<()>`),
f7e2cb
-///   but it could be done if someone cared enough to implement it.
f7e2cb
-#[cfg_attr(feature = "gecko-ffi", repr(C))]
f7e2cb
+/// See the crate's top level documentation for a description of this type.
f7e2cb
+#[repr(C)]
f7e2cb
 pub struct ThinVec<T> {
f7e2cb
     ptr: NonNull<Header>,
f7e2cb
     boo: PhantomData<T>,
f7e2cb
@@ -630,15 +821,15 @@ impl<T> ThinVec<T> {
f7e2cb
     }
f7e2cb
 
f7e2cb
     pub fn drain<R>(&mut self, range: R) -> Drain<T>
f7e2cb
-        where R: RangeArgument<usize>
f7e2cb
+        where R: RangeBounds<usize>
f7e2cb
     {
f7e2cb
         let len = self.len();
f7e2cb
-        let start = match range.start() {
f7e2cb
+        let start = match range.start_bound() {
f7e2cb
             Bound::Included(&n) => n,
f7e2cb
             Bound::Excluded(&n) => n + 1,
f7e2cb
             Bound::Unbounded => 0,
f7e2cb
         };
f7e2cb
-        let end = match range.end() {
f7e2cb
+        let end = match range.end_bound() {
f7e2cb
             Bound::Included(&n) => n + 1,
f7e2cb
             Bound::Excluded(&n) => n,
f7e2cb
             Bound::Unbounded => len,
f7e2cb
@@ -688,11 +879,30 @@ impl<T> ThinVec<T> {
f7e2cb
                 alloc_size::<T>(new_cap),
f7e2cb
             ) as *mut Header;
f7e2cb
 
f7e2cb
-            if ptr.is_null() { oom() }
f7e2cb
+            if ptr.is_null() { handle_alloc_error(layout::<T>(new_cap)) }
f7e2cb
             (*ptr).set_cap(new_cap);
f7e2cb
             self.ptr = NonNull::new_unchecked(ptr);
f7e2cb
         } else {
f7e2cb
-            self.ptr = header_with_capacity::<T>(new_cap);
f7e2cb
+            let mut new_header = header_with_capacity::<T>(new_cap);
f7e2cb
+
f7e2cb
+            // If we get here and have a non-zero len, then we must be handling
f7e2cb
+            // a gecko auto array, and we have items in a stack buffer. We shouldn't
f7e2cb
+            // free it, but we should memcopy the contents out of it and mark it as empty.
f7e2cb
+            //
f7e2cb
+            // T is assumed to be trivially relocatable, as this is ~required
f7e2cb
+            // for Rust compatibility anyway. Furthermore, we assume C++ won't try
f7e2cb
+            // to unconditionally destroy the contents of the stack allocated buffer
f7e2cb
+            // (i.e. it's obfuscated behind a union).
f7e2cb
+            //
f7e2cb
+            // In effect, we are partially reimplementing the auto array move constructor
f7e2cb
+            // by leaving behind a valid empty instance.
f7e2cb
+            let len = self.len();
f7e2cb
+            if cfg!(feature = "gecko-ffi") && len > 0 {
f7e2cb
+                new_header.as_mut().data::<T>().copy_from_nonoverlapping(self.data_raw(), len);
f7e2cb
+                self.set_len(0);
f7e2cb
+            }
f7e2cb
+            
f7e2cb
+            self.ptr = new_header;
f7e2cb
         }
f7e2cb
     }
f7e2cb
 
f7e2cb
@@ -1093,10 +1303,7 @@ mod tests {
f7e2cb
         use std::mem::size_of;
f7e2cb
         assert_eq!(size_of::<ThinVec<u8>>(), size_of::<&u8>());
f7e2cb
 
f7e2cb
-        // We don't perform the null-pointer optimization on stable rust.
f7e2cb
-        if cfg!(feature = "unstable") {
f7e2cb
-            assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
f7e2cb
-        }
f7e2cb
+        assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
f7e2cb
     }
f7e2cb
 
f7e2cb
     #[test]
f7e2cb
@@ -1731,7 +1938,6 @@ mod std_tests {
f7e2cb
         assert_eq!(v, &[(), ()]);
f7e2cb
     }
f7e2cb
 
f7e2cb
-/* TODO: support inclusive ranges
f7e2cb
     #[test]
f7e2cb
     fn test_drain_inclusive_range() {
f7e2cb
         let mut v = thin_vec!['a', 'b', 'c', 'd', 'e'];
f7e2cb
@@ -1761,6 +1967,7 @@ mod std_tests {
f7e2cb
     }
f7e2cb
 
f7e2cb
     #[test]
f7e2cb
+    #[cfg(not(feature = "gecko-ffi"))]
f7e2cb
     fn test_drain_max_vec_size() {
f7e2cb
         let mut v = ThinVec::<()>::with_capacity(usize::max_value());
f7e2cb
         unsafe { v.set_len(usize::max_value()); }
f7e2cb
@@ -1781,7 +1988,6 @@ mod std_tests {
f7e2cb
         let mut v = thin_vec![1, 2, 3, 4, 5];
f7e2cb
         v.drain(5..=5);
f7e2cb
     }
f7e2cb
-*/
f7e2cb
 
f7e2cb
 /* TODO: implement splice?
f7e2cb
     #[test]
f7e2cb
@@ -2187,7 +2393,7 @@ mod std_tests {
f7e2cb
         assert!(v.capacity() >= 33)
f7e2cb
     }
f7e2cb
 
f7e2cb
-/* TODO: implement try_reserve 
f7e2cb
+/* TODO: implement try_reserve
f7e2cb
     #[test]
f7e2cb
     fn test_try_reserve() {
f7e2cb
 
f7e2cb
--- thunderbird-78.9.0/toolkit/components/cascade_bloom_filter/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:12.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/toolkit/components/cascade_bloom_filter/Cargo.toml	2021-03-22 11:37:44.287130273 +0100
f7e2cb
@@ -8,5 +8,5 @@ nserror = { path = "../../../xpcom/rust/
f7e2cb
 nsstring = { path = "../../../xpcom/rust/nsstring" }
f7e2cb
 rental = "0.5.5"
f7e2cb
 rust_cascade = "0.6.0"
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 xpcom = { path = "../../../xpcom/rust/xpcom" }
f7e2cb
--- thunderbird-78.9.0/toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:28.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml	2021-03-22 11:37:44.288130270 +0100
f7e2cb
@@ -13,7 +13,7 @@ moz_task = { path = "../../../../../xpco
f7e2cb
 nserror = { path = "../../../../../xpcom/rust/nserror" }
f7e2cb
 nsstring = { path = "../../../../../xpcom/rust/nsstring" }
f7e2cb
 once_cell = "1"
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 xpcom = { path = "../../../../../xpcom/rust/xpcom" }
f7e2cb
 serde = "1"
f7e2cb
 serde_json = "1"
f7e2cb
--- thunderbird-78.9.0/toolkit/components/kvstore/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/toolkit/components/kvstore/Cargo.toml	2021-03-22 11:37:44.289130267 +0100
f7e2cb
@@ -18,7 +18,7 @@ rkv = "0.10.2"
f7e2cb
 storage_variant = { path = "../../../storage/variant" }
f7e2cb
 xpcom = { path = "../../../xpcom/rust/xpcom" }
f7e2cb
 tempfile = "3"
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
f7e2cb
 
f7e2cb
 # Get rid of failure's dependency on backtrace. Eventually
f7e2cb
 # backtrace will move into Rust core, but we don't need it here.
f7e2cb
--- thunderbird-78.9.0/toolkit/components/places/bookmark_sync/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:25.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/toolkit/components/places/bookmark_sync/Cargo.toml	2021-03-22 11:37:44.289130267 +0100
f7e2cb
@@ -19,5 +19,5 @@ url = "2.0"
f7e2cb
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
f7e2cb
 
f7e2cb
 [dependencies.thin-vec]
f7e2cb
-version = "0.1.0"
f7e2cb
+version = "0.2.1"
f7e2cb
 features = ["gecko-ffi"]
f7e2cb
--- thunderbird-78.9.0/tools/profiler/rust-helper/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/tools/profiler/rust-helper/Cargo.toml	2021-03-22 11:37:44.290130265 +0100
f7e2cb
@@ -23,7 +23,7 @@ features = ["endian_fd", "elf32", "elf64
f7e2cb
 default-features = false
f7e2cb
 
f7e2cb
 [dependencies.thin-vec]
f7e2cb
-version = "0.1.0"
f7e2cb
+version = "0.2.1"
f7e2cb
 features = ["gecko-ffi"]
f7e2cb
 
f7e2cb
 [features]
f7e2cb
--- thunderbird-78.9.0/xpcom/rust/xpcom/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-19 22:36:33.000000000 +0100
f7e2cb
+++ thunderbird-78.9.0/xpcom/rust/xpcom/Cargo.toml	2021-03-22 11:37:44.291130262 +0100
f7e2cb
@@ -9,4 +9,4 @@ nsstring = { path = "../nsstring" }
f7e2cb
 nserror = { path = "../nserror" }
f7e2cb
 threadbound = "0.1"
f7e2cb
 xpcom_macros = { path = "xpcom_macros" }
f7e2cb
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
f7e2cb
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }