Skip to content

Commit 2f66e56

Browse files
committed
rust: 1.70 compat hack
Signed-off-by: Hector Martin <[email protected]>
1 parent 8391f19 commit 2f66e56

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

rust/alloc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
207207
// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
208208
#![feature(intra_doc_pointers)]
209+
#![feature(cfg_version)]
209210

210211
// Allow testing this library
211212
#[cfg(test)]

rust/alloc/vec/into_iter.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use core::ops::Deref;
1818
use core::ptr::{self, NonNull};
1919
use core::slice::{self};
2020

21+
#[cfg(version("1.70"))]
22+
type AdvanceRet = core::num::NonZeroUsize;
23+
#[cfg(not(version("1.70")))]
24+
type AdvanceRet = usize;
25+
2126
/// An iterator that moves out of a vector.
2227
///
2328
/// This `struct` is created by the `into_iter` method on [`Vec`](super::Vec)
@@ -215,7 +220,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
215220
}
216221

217222
#[inline]
218-
fn advance_by(&mut self, n: usize) -> Result<(), usize> {
223+
fn advance_by(&mut self, n: usize) -> Result<(), AdvanceRet> {
219224
let step_size = self.len().min(n);
220225
let to_drop = ptr::slice_from_raw_parts_mut(self.ptr as *mut T, step_size);
221226
if T::IS_ZST {
@@ -230,6 +235,9 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
230235
ptr::drop_in_place(to_drop);
231236
}
232237
if step_size < n {
238+
#[cfg(version("1.70"))]
239+
return Err(AdvanceRet::new(step_size).unwrap());
240+
#[cfg(not(version("1.70")))]
233241
return Err(step_size);
234242
}
235243
Ok(())
@@ -315,7 +323,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
315323
}
316324

317325
#[inline]
318-
fn advance_back_by(&mut self, n: usize) -> Result<(), usize> {
326+
fn advance_back_by(&mut self, n: usize) -> Result<(), AdvanceRet> {
319327
let step_size = self.len().min(n);
320328
if T::IS_ZST {
321329
// SAFETY: same as for advance_by()
@@ -330,6 +338,9 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
330338
ptr::drop_in_place(to_drop);
331339
}
332340
if step_size < n {
341+
#[cfg(version("1.70"))]
342+
return Err(AdvanceRet::new(step_size).unwrap());
343+
#[cfg(not(version("1.70")))]
333344
return Err(step_size);
334345
}
335346
Ok(())

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
277277
# Compile Rust sources (.rs)
278278
# ---------------------------------------------------------------------------
279279

280-
rust_allowed_features := allocator_api,new_uninit,type_alias_impl_trait
280+
rust_allowed_features := allocator_api,new_uninit,type_alias_impl_trait$(shell expr $$($(RUSTC) --version | cut -d' ' -f2) \> 1.69.0 >/dev/null && echo -n ,impl_trait_in_assoc_type)
281281

282282
rust_common_cmd = \
283283
RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \

0 commit comments

Comments
 (0)