Change:
Run Or And you'll get this diagnostic (cargo miri setup makes it a warning, lol): I don't know what effect this has at runtime but it can't be good.
It's worse than one might think, because many AVR microarchitectures, including the atmega328 we nominally support, have only 2KiB of SRAM, which means that this line is literally impossible:
these targets should probably use some of the code in with perhaps a few more tweaks.
Good to know, 16-bit wasn't something we had in mind during development, in terms of less standard targets, we did test big endian with miri. I agree with the code in would be a better fit for such targets. What kind of tweaks did you have in mind?
There are other places in driftsort and ipnsort that use stack arrays, e.g: They are all size bound to <= 4KiB through various means, but still a poor fit for tiny chips.
I think that's necessary, I don't believe driftsort could ever meaningfully run on machines this small.
You already figured it out: dropping all the stack arrays to the absolute minimum. Note that you are not obligated to fix these targets, as usual.
I think it should be a single additional in the impl, so I don't mind doing it.
Yeah, we'd get CI failures way too often if we errored on warnings for tier 3 targets.
Related:
Who is using Tier 3 targets in CI?
Miri is, by running a test with . We should probably change that.
Thinking a bit more about it, is there any scenario where you'd compile Rust for 16-bit targets and don't want to use ? Independent of sort. I'd think that such targets are always binary-size limited and welcome any reduction of it.

Discussion:
<del> #![cfg_attr(feature = "optimize_for_size", allow(dead_code))] </del> <ins> #![cfg_attr(any(feature = "optimize_for_size", target_pointer_width = "16"), allow(dead_code))] </ins> use crate::marker::Freeze;

//! This module contains the entry points for `slice::sort`. <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> use crate::cmp; use crate::intrinsics; use crate::mem::{self, MaybeUninit, SizedTypeProperties}; <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> use crate::slice::sort::shared::smallsort::{ SMALL_SORT_GENERAL_SCRATCH_LEN, StableSmallSortTypeImpl, insertion_sort_shift_left, }; pub(crate) mod merge; <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> pub(crate) mod drift; <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> pub(crate) mod quicksort; <del> #[cfg(feature = "optimize_for_size")] </del> <ins> #[cfg(any(feature = "optimize_for_size", target_pointer_width = "16"))] </ins> pub(crate) mod tiny; /// Stable sort called driftsort by Orson Peters and Lukas Bergdoll.

cfg_if! { if #[cfg(target_pointer_width = "16")] { <del> let heap_buf = BufT::with_capacity(alloc_len); </del> <ins> let mut heap_buf = BufT::with_capacity(alloc_len); </ins> let scratch = heap_buf.as_uninit_slice_mut(); } else { // For small inputs 4KiB of stack storage suffices, which allows us to avoid

/// /// Deliberately don't inline the main sorting routine entrypoint to ensure the /// inlined insertion sort i-cache footprint remains minimal. <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> #[inline(never)] fn driftsort_main<T, F: FnMut(&T, &T) -> bool, BufT: BufGuard<T>>(v: &mut [T], is_less: &mut F) { // By allocating n elements of memory we can ensure the entire input can

use crate::intrinsics; use crate::mem::SizedTypeProperties; <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> use crate::slice::sort::shared::find_existing_run; <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> use crate::slice::sort::shared::smallsort::insertion_sort_shift_left; pub(crate) mod heapsort;

/// /// Deliberately don't inline the main sorting routine entrypoint to ensure the /// inlined insertion sort i-cache footprint remains minimal. <del> #[cfg(not(feature = "optimize_for_size"))] </del> <ins> #[cfg(not(any(feature = "optimize_for_size", target_pointer_width = "16")))] </ins> #[inline(never)] fn ipnsort<T, F>(v: &mut [T], is_less: &mut F) where