11#![ allow( incomplete_features) ]
2+ #![ allow( unstable_name_collisions) ]
23#![ cfg_attr( feature = "no_std" , no_std) ]
34#![ cfg_attr( feature = "ptr_metadata" , feature( ptr_metadata, unsize) ) ]
45#![ cfg_attr( feature = "error_in_core" , feature( error_in_core) ) ]
56#![ cfg_attr( feature = "allocator_api" , feature( allocator_api) ) ]
6- #![ cfg_attr( all( doc, feature = "NIGHTLY" ) , feature( doc_auto_cfg) ) ]
7+ #![ cfg_attr( all( doc, nightly) , feature( doc_auto_cfg) ) ]
8+ #![ cfg_attr( nightly, feature( strict_provenance) ) ]
9+ #![ cfg_attr( nightly, warn( fuzzy_provenance_casts) ) ]
710#![ warn( missing_docs) ]
811#![ doc = include_str ! ( "../doc/crate.md" ) ]
912
@@ -465,10 +468,17 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
465468 /// let mut s: ContiguousMemory = ContiguousMemory::new();
466469 ///
467470 /// assert!(s.try_grow_to(1024).is_ok());
471+ /// ```
472+ ///
473+ /// The method returns an error if the system can't reserve requested
474+ /// memory:
475+ /// ```should_panic
476+ /// # use contiguous_mem::ContiguousMemory;
477+ /// # let mut s: ContiguousMemory = ContiguousMemory::new();
468478 ///
469479 /// let required_size: usize = usize::MAX; // bad read?
470480 /// // can't allocate all addressable memory
471- /// assert!(s.try_grow_to(required_size).is_err ());
481+ /// assert!(s.try_grow_to(required_size).is_ok ()); // PANIC!
472482 /// ```
473483 pub fn try_grow_to ( & mut self , new_capacity : usize ) -> Result < Option < MemoryBase > , MemoryError > {
474484 let mut base = WritableInner :: write ( & self . inner . base ) . unwrap ( ) ;
@@ -480,10 +490,10 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
480490 return Ok ( None ) ;
481491 } ;
482492
483- let prev_base = * base;
484- base. address = unsafe { self . inner . alloc . grow ( prev_base, new_capacity) ? } ;
493+ let new_addr = unsafe { self . inner . alloc . grow ( * base, new_capacity) ? } ;
485494
486- Ok ( if base. address != prev_base. address {
495+ Ok ( if new_addr != base. address {
496+ base. address = new_addr;
487497 Some ( * base)
488498 } else {
489499 None
@@ -656,15 +666,17 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
656666 ///
657667 /// assert!(s.try_reserve_exact(1024).is_ok());
658668 /// assert_eq!(s.capacity(), 1024);
669+ /// ```
659670 ///
660- /// let el_count: usize = 42;
661- /// let el_size: usize = 288230376151711744; // bad read?
671+ /// The method returns an error if the system can't reserve requested
672+ /// memory:
673+ /// ```should_panic
674+ /// # use contiguous_mem::ContiguousMemory;
675+ /// # let mut s: ContiguousMemory = ContiguousMemory::new();
662676 ///
663- /// let mut required_size: usize = 0;
664- /// for i in 0..el_count {
665- /// required_size += el_size;
666- /// }
667- /// assert!(s.try_reserve_exact(required_size).is_err());
677+ /// let required_size: usize = usize::MAX; // bad read?
678+ /// // can't allocate all addressable memory
679+ /// assert!(s.try_reserve_exact(required_size).is_ok()); // PANIC!
668680 /// ```
669681 pub fn try_reserve_exact (
670682 & mut self ,
0 commit comments