Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded fn main blocks from docs #64912

Merged
merged 1 commit into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 21 additions & 33 deletions src/liballoc/boxed.rs
Expand Up @@ -29,10 +29,8 @@
//! Nil,
//! }
//!
//! fn main() {
//! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil))));
//! println!("{:?}", list);
//! }
//! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil))));
//! println!("{:?}", list);
//! ```
//!
//! This will print `Cons(1, Cons(2, Nil))`.
Expand Down Expand Up @@ -375,14 +373,12 @@ impl<T: ?Sized> Box<T> {
/// ```
/// #![feature(box_into_raw_non_null)]
///
/// fn main() {
/// let x = Box::new(5);
/// let ptr = Box::into_raw_non_null(x);
/// let x = Box::new(5);
/// let ptr = Box::into_raw_non_null(x);
///
/// // Clean up the memory by converting the NonNull pointer back
/// // into a Box and letting the Box be dropped.
/// let x = unsafe { Box::from_raw(ptr.as_ptr()) };
/// }
/// // Clean up the memory by converting the NonNull pointer back
/// // into a Box and letting the Box be dropped.
/// let x = unsafe { Box::from_raw(ptr.as_ptr()) };
/// ```
#[unstable(feature = "box_into_raw_non_null", issue = "47336")]
#[inline]
Expand Down Expand Up @@ -428,23 +424,19 @@ impl<T: ?Sized> Box<T> {
/// Simple usage:
///
/// ```
/// fn main() {
/// let x = Box::new(41);
/// let static_ref: &'static mut usize = Box::leak(x);
/// *static_ref += 1;
/// assert_eq!(*static_ref, 42);
/// }
/// let x = Box::new(41);
/// let static_ref: &'static mut usize = Box::leak(x);
/// *static_ref += 1;
/// assert_eq!(*static_ref, 42);
/// ```
///
/// Unsized data:
///
/// ```
/// fn main() {
/// let x = vec![1, 2, 3].into_boxed_slice();
/// let static_ref = Box::leak(x);
/// static_ref[0] = 4;
/// assert_eq!(*static_ref, [4, 2, 3]);
/// }
/// let x = vec![1, 2, 3].into_boxed_slice();
/// let static_ref = Box::leak(x);
/// static_ref[0] = 4;
/// assert_eq!(*static_ref, [4, 2, 3]);
/// ```
#[stable(feature = "box_leak", since = "1.26.0")]
#[inline]
Expand Down Expand Up @@ -780,11 +772,9 @@ impl Box<dyn Any> {
/// }
/// }
///
/// fn main() {
/// let my_string = "Hello World".to_string();
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// }
/// let my_string = "Hello World".to_string();
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// ```
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any>> {
if self.is::<T>() {
Expand Down Expand Up @@ -814,11 +804,9 @@ impl Box<dyn Any + Send> {
/// }
/// }
///
/// fn main() {
/// let my_string = "Hello World".to_string();
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// }
/// let my_string = "Hello World".to_string();
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// ```
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any + Send>> {
<Box<dyn Any>>::downcast(self).map_err(|s| unsafe {
Expand Down
2 changes: 0 additions & 2 deletions src/liballoc/collections/btree/map.rs
Expand Up @@ -2226,14 +2226,12 @@ impl<'a, K: Ord, V: Default> Entry<'a, K, V> {
/// # Examples
///
/// ```
/// # fn main() {
/// use std::collections::BTreeMap;
///
/// let mut map: BTreeMap<&str, Option<usize>> = BTreeMap::new();
/// map.entry("poneyland").or_default();
///
/// assert_eq!(map["poneyland"], None);
/// # }
/// ```
pub fn or_default(self) -> &'a mut V {
match self {
Expand Down
8 changes: 3 additions & 5 deletions src/liballoc/rc.rs
Expand Up @@ -861,11 +861,9 @@ impl Rc<dyn Any> {
/// }
/// }
///
/// fn main() {
/// let my_string = "Hello World".to_string();
/// print_if_string(Rc::new(my_string));
/// print_if_string(Rc::new(0i8));
/// }
/// let my_string = "Hello World".to_string();
/// print_if_string(Rc::new(my_string));
/// print_if_string(Rc::new(0i8));
/// ```
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<dyn Any>> {
if (*self).is::<T>() {
Expand Down
11 changes: 3 additions & 8 deletions src/liballoc/slice.rs
Expand Up @@ -412,20 +412,15 @@ impl<T> [T] {
///
/// ```
/// #![feature(repeat_generic_slice)]
///
/// fn main() {
/// assert_eq!([1, 2].repeat(3), vec![1, 2, 1, 2, 1, 2]);
/// }
/// assert_eq!([1, 2].repeat(3), vec![1, 2, 1, 2, 1, 2]);
/// ```
///
/// A panic upon overflow:
///
/// ```should_panic
/// #![feature(repeat_generic_slice)]
/// fn main() {
/// // this will panic at runtime
/// b"0123456789abcdef".repeat(usize::max_value());
/// }
/// // this will panic at runtime
/// b"0123456789abcdef".repeat(usize::max_value());
/// ```
#[unstable(feature = "repeat_generic_slice",
reason = "it's on str, why not on slice?",
Expand Down
6 changes: 2 additions & 4 deletions src/liballoc/str.rs
Expand Up @@ -500,10 +500,8 @@ impl str {
/// A panic upon overflow:
///
/// ```should_panic
/// fn main() {
/// // this will panic at runtime
/// "0123456789abcdef".repeat(usize::max_value());
/// }
/// // this will panic at runtime
/// "0123456789abcdef".repeat(usize::max_value());
/// ```
#[stable(feature = "repeat_str", since = "1.16.0")]
pub fn repeat(&self, n: usize) -> String {
Expand Down
6 changes: 2 additions & 4 deletions src/liballoc/string.rs
Expand Up @@ -164,10 +164,8 @@ use crate::vec::Vec;
///
/// fn example_func<A: TraitExample>(example_arg: A) {}
///
/// fn main() {
/// let example_string = String::from("example_string");
/// example_func(&example_string);
/// }
/// let example_string = String::from("example_string");
/// example_func(&example_string);
/// ```
///
/// There are two options that would work instead. The first would be to
Expand Down
8 changes: 3 additions & 5 deletions src/liballoc/sync.rs
Expand Up @@ -1244,11 +1244,9 @@ impl Arc<dyn Any + Send + Sync> {
/// }
/// }
///
/// fn main() {
/// let my_string = "Hello World".to_string();
/// print_if_string(Arc::new(my_string));
/// print_if_string(Arc::new(0i8));
/// }
/// let my_string = "Hello World".to_string();
/// print_if_string(Arc::new(my_string));
/// print_if_string(Arc::new(0i8));
/// ```
pub fn downcast<T>(self) -> Result<Arc<T>, Self>
where
Expand Down
44 changes: 20 additions & 24 deletions src/liballoc/vec.rs
Expand Up @@ -389,28 +389,26 @@ impl<T> Vec<T> {
/// use std::ptr;
/// use std::mem;
///
/// fn main() {
/// let mut v = vec![1, 2, 3];
///
/// // Pull out the various important pieces of information about `v`
/// let p = v.as_mut_ptr();
/// let len = v.len();
/// let cap = v.capacity();
/// let mut v = vec![1, 2, 3];
///
/// unsafe {
/// // Cast `v` into the void: no destructor run, so we are in
/// // complete control of the allocation to which `p` points.
/// mem::forget(v);
/// // Pull out the various important pieces of information about `v`
/// let p = v.as_mut_ptr();
/// let len = v.len();
/// let cap = v.capacity();
///
/// // Overwrite memory with 4, 5, 6
/// for i in 0..len as isize {
/// ptr::write(p.offset(i), 4 + i);
/// }
/// unsafe {
/// // Cast `v` into the void: no destructor run, so we are in
/// // complete control of the allocation to which `p` points.
/// mem::forget(v);
///
/// // Put everything back together into a Vec
/// let rebuilt = Vec::from_raw_parts(p, len, cap);
/// assert_eq!(rebuilt, [4, 5, 6]);
/// // Overwrite memory with 4, 5, 6
/// for i in 0..len as isize {
/// ptr::write(p.offset(i), 4 + i);
/// }
///
/// // Put everything back together into a Vec
/// let rebuilt = Vec::from_raw_parts(p, len, cap);
/// assert_eq!(rebuilt, [4, 5, 6]);
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1391,12 +1389,10 @@ impl<T> Vec<T> {
/// ```
/// #![feature(vec_leak)]
///
/// fn main() {
/// let x = vec![1, 2, 3];
/// let static_ref: &'static mut [usize] = Vec::leak(x);
/// static_ref[0] += 1;
/// assert_eq!(static_ref, &[2, 2, 3]);
/// }
/// let x = vec![1, 2, 3];
/// let static_ref: &'static mut [usize] = Vec::leak(x);
/// static_ref[0] += 1;
/// assert_eq!(static_ref, &[2, 2, 3]);
/// ```
#[unstable(feature = "vec_leak", issue = "62195")]
#[inline]
Expand Down