diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 3ab4c4f12982d..75151faa3e454 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -134,8 +134,8 @@ use crate::iter::{FromIterator, FusedIterator, TrustedLen}; use crate::pin::Pin; use crate::{ - convert, fmt, hint, mem, - ops::{self, Deref, DerefMut}, + convert, fmt, hint, mem, ptr, + ops::{self, Deref, DerefMut, Range}, }; /// The `Option` type. See [the module level documentation](self) for more. @@ -1257,6 +1257,16 @@ impl Clone for Option { } } +// Range is not Copy even if T is copy (see #27186), +// so provide an efficient implementation. +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for Option> { + #[inline] + fn clone(&self) -> Self { + // SAFETY: 'self' is not Drop so memcpy is OK. + unsafe { ptr::read(self as *const Self) } + } +} #[stable(feature = "rust1", since = "1.0.0")] impl Default for Option {