1
Fork 0

fix most compiler/ doctests

This commit is contained in:
Elliot Roberts 2022-04-15 15:04:34 -07:00
parent bf611439e3
commit 7907385999
116 changed files with 666 additions and 609 deletions

View file

@ -25,9 +25,8 @@ of the reference because the backing allocation of the vector does not change.
This library enables this safe usage by keeping the owner and the reference
bundled together in a wrapper type that ensure that lifetime constraint:
```rust
# extern crate owning_ref;
# use owning_ref::OwningRef;
```
# use rustc_data_structures::owning_ref::OwningRef;
# fn main() {
fn return_owned_and_referenced() -> OwningRef<Vec<u8>, [u8]> {
let v = vec![1, 2, 3, 4];
@ -56,8 +55,7 @@ See the documentation around `OwningHandle` for more details.
## Basics
```
extern crate owning_ref;
use owning_ref::BoxRef;
use rustc_data_structures::owning_ref::BoxRef;
fn main() {
// Create an array owned by a Box.
@ -78,8 +76,7 @@ fn main() {
## Caching a reference to a struct field
```
extern crate owning_ref;
use owning_ref::BoxRef;
use rustc_data_structures::owning_ref::BoxRef;
fn main() {
struct Foo {
@ -106,8 +103,7 @@ fn main() {
## Caching a reference to an entry in a vector
```
extern crate owning_ref;
use owning_ref::VecRef;
use rustc_data_structures::owning_ref::VecRef;
fn main() {
let v = VecRef::new(vec![1, 2, 3, 4, 5]).map(|v| &v[3]);
@ -118,8 +114,7 @@ fn main() {
## Caching a subslice of a String
```
extern crate owning_ref;
use owning_ref::StringRef;
use rustc_data_structures::owning_ref::StringRef;
fn main() {
let s = StringRef::new("hello world".to_owned())
@ -132,8 +127,7 @@ fn main() {
## Reference counted slices that share ownership of the backing storage
```
extern crate owning_ref;
use owning_ref::RcRef;
use rustc_data_structures::owning_ref::RcRef;
use std::rc::Rc;
fn main() {
@ -155,8 +149,7 @@ fn main() {
## Atomic reference counted slices that share ownership of the backing storage
```
extern crate owning_ref;
use owning_ref::ArcRef;
use rustc_data_structures::owning_ref::ArcRef;
use std::sync::Arc;
fn main() {
@ -188,8 +181,7 @@ fn main() {
## References into RAII locks
```
extern crate owning_ref;
use owning_ref::RefRef;
use rustc_data_structures::owning_ref::RefRef;
use std::cell::{RefCell, Ref};
fn main() {
@ -219,8 +211,7 @@ When the owned container implements `DerefMut`, it is also possible to make
a _mutable owning reference_. (e.g., with `Box`, `RefMut`, `MutexGuard`)
```
extern crate owning_ref;
use owning_ref::RefMutRefMut;
use rustc_data_structures::owning_ref::RefMutRefMut;
use std::cell::{RefCell, RefMut};
fn main() {
@ -326,8 +317,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRef;
/// use rustc_data_structures::owning_ref::OwningRef;
///
/// fn main() {
/// let owning_ref = OwningRef::new(Box::new(42));
@ -362,8 +352,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRef;
/// use rustc_data_structures::owning_ref::OwningRef;
///
/// fn main() {
/// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4]));
@ -390,8 +379,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRef;
/// use rustc_data_structures::owning_ref::OwningRef;
///
/// fn main() {
/// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4]));
@ -441,8 +429,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::{OwningRef, Erased};
/// use rustc_data_structures::owning_ref::{OwningRef, Erased};
///
/// fn main() {
/// // N.B., using the concrete types here for explicitness.
@ -460,7 +447,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
/// let owning_ref_b: OwningRef<Box<Vec<(i32, bool)>>, i32>
/// = owning_ref_b.map(|a| &a[1].0);
///
/// let owning_refs: [OwningRef<Box<Erased>, i32>; 2]
/// let owning_refs: [OwningRef<Box<dyn Erased>, i32>; 2]
/// = [owning_ref_a.erase_owner(), owning_ref_b.erase_owner()];
///
/// assert_eq!(*owning_refs[0], 1);
@ -516,8 +503,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRefMut;
/// use rustc_data_structures::owning_ref::OwningRefMut;
///
/// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new(42));
@ -552,8 +538,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRefMut;
/// use rustc_data_structures::owning_ref::OwningRefMut;
///
/// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -580,8 +565,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRefMut;
/// use rustc_data_structures::owning_ref::OwningRefMut;
///
/// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -608,8 +592,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRefMut;
/// use rustc_data_structures::owning_ref::OwningRefMut;
///
/// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -638,8 +621,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::OwningRefMut;
/// use rustc_data_structures::owning_ref::OwningRefMut;
///
/// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -689,8 +671,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
///
/// # Example
/// ```
/// extern crate owning_ref;
/// use owning_ref::{OwningRefMut, Erased};
/// use rustc_data_structures::owning_ref::{OwningRefMut, Erased};
///
/// fn main() {
/// // N.B., using the concrete types here for explicitness.
@ -708,7 +689,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// let owning_ref_mut_b: OwningRefMut<Box<Vec<(i32, bool)>>, i32>
/// = owning_ref_mut_b.map_mut(|a| &mut a[1].0);
///
/// let owning_refs_mut: [OwningRefMut<Box<Erased>, i32>; 2]
/// let owning_refs_mut: [OwningRefMut<Box<dyn Erased>, i32>; 2]
/// = [owning_ref_mut_a.erase_owner(), owning_ref_mut_b.erase_owner()];
///
/// assert_eq!(*owning_refs_mut[0], 1);