Refinement of paragraph referenced by [this issue](https://github.com/rust-lang/rust/issues/31927).
The paragraph in question had been adjusted already, but I've made some further clarifications which should help with readability and not leave the reader any `dangling pointers`.
improved by using `memchr` to search for newlines][1.7m].
* [`f32::to_degrees` and `f32::to_radians` are stable][1.7f]. The
`f64` variants were stabilized previously.
-* [`BTreeMap` was rewritten to use less memory improve performance of
- insertion and iteration, the latter by as much as 5x`][1.7bm].
+* [`BTreeMap` was rewritten to use less memory and improve the performance
+ of insertion and iteration, the latter by as much as 5x`][1.7bm].
* [`BTreeSet` and its iterators, `Iter`, `IntoIter`, and `Range` are
covariant over their contained type][1.7bt].
* [`LinkedList` and its iterators, `Iter` and `IntoIter` are covariant
[unsafe]: unsafe.html
-Furthermore, any type stored in a `static` must be `Sync`, and may not have
+Furthermore, any type stored in a `static` must be `Sync`, and must not have
a [`Drop`][drop] implementation.
[drop]: drop.html
# Initializing
-Both `const` and `static` have requirements for giving them a value. They may
-only be given a value that’s a constant expression. In other words, you cannot
-use the result of a function call or anything similarly complex or at runtime.
+Both `const` and `static` have requirements for giving them a value. They must
+be given a value that’s a constant expression. In other words, you cannot use
+the result of a function call or anything similarly complex or at runtime.
# Which construct should I use?
the loop. In the case of a `for` loop, the head is the call-expression
controlling the loop. If the label is present, then `continue 'foo` returns
control to the head of the loop with label `'foo`, which need not be the
-innermost label enclosing the `break` expression, but must enclose it.
+innermost label enclosing the `continue` expression, but must enclose it.
A `continue` expression is only permitted in the body of a loop.
/// Converts a string slice to a raw pointer.
///
/// As string slices are a slice of bytes, the raw pointer points to a
- /// `u8`. This pointer will be pointing to the first byte of the string
+ /// [`u8`]. This pointer will be pointing to the first byte of the string
/// slice.
///
+ /// [`u8`]: primitive.u8.html
+ ///
/// # Examples
///
/// Basic usage:
/// assert_eq!(None, chars.next());
/// ```
///
- /// Remember, `char`s may not match your human intuition about characters:
+ /// Remember, [`char`]s may not match your human intuition about characters:
///
/// ```
/// let y = "y̆";
pub fn chars(&self) -> Chars {
core_str::StrExt::chars(self)
}
- /// Returns an iterator over the `char`s of a string slice, and their
+ /// Returns an iterator over the [`char`]s of a string slice, and their
/// positions.
///
/// As a string slice consists of valid UTF-8, we can iterate through a
- /// string slice by `char`. This method returns an iterator of both
- /// these `char`s, as well as their byte positions.
+ /// string slice by [`char`]. This method returns an iterator of both
+ /// these [`char`]s, as well as their byte positions.
///
- /// The iterator yields tuples. The position is first, the `char` is
+ /// The iterator yields tuples. The position is first, the [`char`] is
/// second.
///
+ /// [`char`]: primitive.char.html
+ ///
/// # Examples
///
/// Basic usage:
/// assert_eq!(None, char_indices.next());
/// ```
///
- /// Remember, `char`s may not match your human intuition about characters:
+ /// Remember, [`char`]s may not match your human intuition about characters:
///
/// ```
/// let y = "y̆";
/// Returns the byte index of the first character of this string slice that
/// matches the pattern.
///
- /// Returns `None` if the pattern doesn't match.
+ /// Returns [`None`] if the pattern doesn't match.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
///
/// [`char`]: primitive.char.html
+ /// [`None`]: option/enum.Option.html#variant.None
///
/// # Examples
///
/// Returns the byte index of the last character of this string slice that
/// matches the pattern.
///
- /// Returns `None` if the pattern doesn't match.
+ /// Returns [`None`] if the pattern doesn't match.
///
/// The pattern can be a `&str`, [`char`], or a closure that determines if
/// a character matches.
///
/// [`char`]: primitive.char.html
+ /// [`None`]: option/enum.Option.html#variant.None
///
/// # Examples
///
/// An iterator over substrings of `self`, separated by characters
/// matched by a pattern and yielded in reverse order.
///
- /// The pattern can be a simple `&str`, `char`, or a closure that
+ /// The pattern can be a simple `&str`, [`char`], or a closure that
/// determines the split.
/// Additional libraries might provide more complex patterns like
/// regular expressions.
///
- /// Equivalent to `split`, except that the trailing substring is
+ /// [`char`]: primitive.char.html
+ ///
+ /// Equivalent to [`split()`], except that the trailing substring is
/// skipped if empty.
///
+ /// [`split()`]: #method.split
+ ///
/// This method can be used for string data that is _terminated_,
/// rather than _separated_ by a pattern.
///
/// # Iterator behavior
///
/// The returned iterator requires that the pattern supports a reverse
- /// search, and it will be a `[DoubleEndedIterator]` if a forward/reverse
+ /// search, and it will be a [`DoubleEndedIterator`] if a forward/reverse
/// search yields the same elements.
///
/// [`DoubleEndedIterator`]: iter/trait.DoubleEndedIterator.html
///
/// # Errors
///
- /// Will return `Err` if it's not possible to parse this string slice into
+ /// Will return [`Err`] if it's not possible to parse this string slice into
/// the desired type.
///
+ /// [`Err`]: str/trait.FromStr.html#associatedtype.Err
+ ///
/// # Example
///
/// Basic usage
/// assert_eq!(4, four);
/// ```
///
- /// Using the 'turbofish' instead of annotationg `four`:
+ /// Using the 'turbofish' instead of annotating `four`:
///
/// ```
/// let four = "4".parse::<u32>();
result
}
- /// Returns the lowercase equivalent of this string slice, as a new `String`.
+ /// Returns the lowercase equivalent of this string slice, as a new [`String`].
///
/// 'Lowercase' is defined according to the terms of the Unicode Derived Core Property
/// `Lowercase`.
///
+ /// [`String`]: string/struct.String.html
+ ///
/// # Examples
///
/// Basic usage:
}
}
- /// Returns the uppercase equivalent of this string slice, as a new `String`.
+ /// Returns the uppercase equivalent of this string slice, as a new [`String`].
///
/// 'Uppercase' is defined according to the terms of the Unicode Derived Core Property
/// `Uppercase`.
///
+ /// [`String`]: string/struct.String.html
+ ///
/// # Examples
///
/// Basic usage:
self.chars().flat_map(|c| c.escape_unicode()).collect()
}
- /// Converts a `Box<str>` into a `String` without copying or allocating.
+ /// Converts a `Box<str>` into a [`String`] without copying or allocating.
+ ///
+ /// [`String`]: string/struct.String.html
///
/// # Examples
///
}
}
Part::Copy(buf) => {
- out[..buf.len()].clone_from_slice(buf);
+ out[..buf.len()].copy_from_slice(buf);
}
}
Some(len)
/// (It may still leave partially written bytes in the buffer; do not rely on that.)
pub fn write(&self, out: &mut [u8]) -> Option<usize> {
if out.len() < self.sign.len() { return None; }
- out[..self.sign.len()].clone_from_slice(self.sign);
+ out[..self.sign.len()].copy_from_slice(self.sign);
let mut written = self.sign.len();
for part in self.parts {
#![feature(box_syntax)]
#![feature(cell_extras)]
#![feature(const_fn)]
+#![feature(copy_from_slice)]
#![feature(core_float)]
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
// check significant digits
for i in 1..cut.unwrap_or(expected.len() - 1) {
- expected_[..i].clone_from_slice(&expected[..i]);
+ expected_[..i].copy_from_slice(&expected[..i]);
let mut expectedk_ = expectedk;
if expected[i] >= b'5' {
// check if this is a rounding-to-even case.
// check infinite zero digits
if let Some(cut) = cut {
for i in cut..expected.len()-1 {
- expected_[..cut].clone_from_slice(&expected[..cut]);
+ expected_[..cut].copy_from_slice(&expected[..cut]);
for c in &mut expected_[cut..i] { *c = b'0'; }
try_exact!(f(&decoded) => &mut buf, &expected_[..i], expectedk;
test(attr(deny(warnings))))]
#![cfg_attr(not(stage0), deny(warnings))]
+#![feature(copy_from_slice)]
#![feature(rustc_private)]
#![feature(staged_api)]
// of the page and segfault.
let mut b = [0; 8];
- b.clone_from_slice(&d.data[d.end - 8..d.end]);
+ b.copy_from_slice(&d.data[d.end - 8..d.end]);
let data = unsafe { (*(b.as_ptr() as *const u64)).to_be() };
let len = d.end - d.start;
if len < 8 {
{
let last_size_pos = last_size_pos as usize;
let data = &self.writer.get_ref()[last_size_pos + 4..cur_pos as usize];
- buf[..size].clone_from_slice(data);
+ buf[..size].copy_from_slice(data);
}
// overwrite the size and data and continue
#![feature(cell_extras)]
#![feature(collections)]
#![feature(const_fn)]
+#![feature(copy_from_slice)]
#![feature(enumset)]
#![feature(iter_arith)]
#![feature(libc)]
self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_foreign_item, late_passes, it);
hir_visit::walk_foreign_item(cx, it);
+ run_lints!(cx, check_foreign_item_post, late_passes, it);
})
}
body: &'v hir::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, late_passes, fk, decl, body, span, id);
hir_visit::walk_fn(self, fk, decl, body, span);
+ run_lints!(self, check_fn_post, late_passes, fk, decl, body, span, id);
}
fn visit_variant_data(&mut self,
fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
run_lints!(self, check_mod, late_passes, m, s, n);
hir_visit::walk_mod(self, m);
+ run_lints!(self, check_mod_post, late_passes, m, s, n);
}
fn visit_local(&mut self, l: &hir::Local) {
run_lints!(cx, check_trait_item, late_passes, trait_item);
cx.visit_ids(|v| v.visit_trait_item(trait_item));
hir_visit::walk_trait_item(cx, trait_item);
+ run_lints!(cx, check_trait_item_post, late_passes, trait_item);
});
}
run_lints!(cx, check_impl_item, late_passes, impl_item);
cx.visit_ids(|v| v.visit_impl_item(impl_item));
hir_visit::walk_impl_item(cx, impl_item);
+ run_lints!(cx, check_impl_item_post, late_passes, impl_item);
});
}
self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_foreign_item, early_passes, it);
ast_visit::walk_foreign_item(cx, it);
+ run_lints!(cx, check_foreign_item_post, early_passes, it);
})
}
body: &'v ast::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, early_passes, fk, decl, body, span, id);
ast_visit::walk_fn(self, fk, decl, body, span);
+ run_lints!(self, check_fn_post, early_passes, fk, decl, body, span, id);
}
fn visit_variant_data(&mut self,
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) {
run_lints!(self, check_mod, early_passes, m, s, n);
ast_visit::walk_mod(self, m);
+ run_lints!(self, check_mod_post, early_passes, m, s, n);
}
fn visit_local(&mut self, l: &ast::Local) {
run_lints!(cx, check_trait_item, early_passes, trait_item);
cx.visit_ids(|v| v.visit_trait_item(trait_item));
ast_visit::walk_trait_item(cx, trait_item);
+ run_lints!(cx, check_trait_item_post, early_passes, trait_item);
});
}
run_lints!(cx, check_impl_item, early_passes, impl_item);
cx.visit_ids(|v| v.visit_impl_item(impl_item));
ast_visit::walk_impl_item(cx, impl_item);
+ run_lints!(cx, check_impl_item_post, early_passes, impl_item);
});
}
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
fn check_crate_post(&mut self, _: &LateContext, _: &hir::Crate) { }
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
+ fn check_mod_post(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
+ fn check_foreign_item_post(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
fn check_item(&mut self, _: &LateContext, _: &hir::Item) { }
fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { }
fn check_local(&mut self, _: &LateContext, _: &hir::Local) { }
fn check_generics(&mut self, _: &LateContext, _: &hir::Generics) { }
fn check_fn(&mut self, _: &LateContext,
_: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { }
+ fn check_fn_post(&mut self, _: &LateContext,
+ _: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { }
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
+ fn check_trait_item_post(&mut self, _: &LateContext, _: &hir::TraitItem) { }
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
+ fn check_impl_item_post(&mut self, _: &LateContext, _: &hir::ImplItem) { }
fn check_struct_def(&mut self, _: &LateContext,
_: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &LateContext,
fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { }
fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { }
fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
+ fn check_mod_post(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
+ fn check_foreign_item_post(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { }
fn check_item_post(&mut self, _: &EarlyContext, _: &ast::Item) { }
fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { }
fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { }
fn check_fn(&mut self, _: &EarlyContext,
_: ast_visit::FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
+ fn check_fn_post(&mut self, _: &EarlyContext,
+ _: ast_visit::FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
fn check_trait_item(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
+ fn check_trait_item_post(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
fn check_impl_item(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
+ fn check_impl_item_post(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
fn check_struct_def(&mut self, _: &EarlyContext,
_: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &EarlyContext,
let bits = &mut self.scope_kills[start.. end];
debug!("{} add_kills_from_flow_exits flow_exit={:?} bits={} [before]",
self.analysis_name, flow_exit, mut_bits_to_string(bits));
- bits.clone_from_slice(&orig_kills[..]);
+ bits.copy_from_slice(&orig_kills[..]);
debug!("{} add_kills_from_flow_exits flow_exit={:?} bits={} [after]",
self.analysis_name, flow_exit, mut_bits_to_string(bits));
}
let (start, end) = self.dfcx.compute_id_range(node_index);
// Initialize local bitvector with state on-entry.
- in_out.clone_from_slice(&self.dfcx.on_entry[start.. end]);
+ in_out.copy_from_slice(&self.dfcx.on_entry[start.. end]);
// Compute state on-exit by applying transfer function to
// state on-entry.
None
}
}
+
+ fn size_hint(&self) -> (usize, Option<usize>) {
+ let size = self.vec.as_slice().len();
+ (size, Some(size))
+ }
}
impl<T> IntoIterator for VecPerParamSpace<T> {
#![cfg_attr(not(stage0), deny(warnings))]
#![feature(box_syntax)]
+#![feature(copy_from_slice)]
#![feature(libc)]
#![feature(rand)]
#![feature(rustc_private)]
let buffer_remaining = size - self.buffer_idx;
if input.len() >= buffer_remaining {
self.buffer[self.buffer_idx..size]
- .clone_from_slice(&input[..buffer_remaining]);
+ .copy_from_slice(&input[..buffer_remaining]);
self.buffer_idx = 0;
func(&self.buffer);
i += buffer_remaining;
} else {
self.buffer[self.buffer_idx..self.buffer_idx + input.len()]
- .clone_from_slice(input);
+ .copy_from_slice(input);
self.buffer_idx += input.len();
return;
}
// data left in the input vector will be less than the buffer size and the buffer will
// be empty.
let input_remaining = input.len() - i;
- self.buffer[..input_remaining].clone_from_slice(&input[i..]);
+ self.buffer[..input_remaining].copy_from_slice(&input[i..]);
self.buffer_idx += input_remaining;
}
&id,
resolve::MakeGlobMap::No,
|tcx, mir_map, _, _| {
- let mir_map = mir_map.unwrap();
-
- for (nodeid, mir) in &mir_map.map {
- try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(*nodeid)));
- try!(write_mir_pretty(mir, &mut out));
+ if let Some(mir_map) = mir_map {
+ for (nodeid, mir) in &mir_map.map {
+ try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(*nodeid)));
+ try!(write_mir_pretty(mir, &mut out));
+ }
}
-
Ok(())
}), &sess)
}
&id,
resolve::MakeGlobMap::No,
|tcx, mir_map, _, _| {
- let mir_map = mir_map.unwrap();
- try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(nodeid)));
- let mir = mir_map.map.get(&nodeid).unwrap_or_else(|| {
- sess.fatal(&format!("no MIR map entry for node {}", nodeid))
- });
- write_mir_pretty(mir, &mut out)
+ if let Some(mir_map) = mir_map {
+ try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(nodeid)));
+ let mir = mir_map.map.get(&nodeid).unwrap_or_else(|| {
+ sess.fatal(&format!("no MIR map entry for node {}", nodeid))
+ });
+ try!(write_mir_pretty(mir, &mut out));
+ }
+ Ok(())
}), &sess)
}
let pos = pos as usize;
let space = self.inner.len() - pos;
let (left, right) = buf.split_at(cmp::min(space, buf.len()));
- self.inner[pos..pos + left.len()].clone_from_slice(left);
+ self.inner[pos..pos + left.len()].copy_from_slice(left);
self.inner.extend_from_slice(right);
}
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let amt = cmp::min(buf.len(), self.len());
let (a, b) = self.split_at(amt);
- buf[..amt].clone_from_slice(a);
+ buf[..amt].copy_from_slice(a);
*self = b;
Ok(amt)
}
"failed to fill whole buffer"));
}
let (a, b) = self.split_at(buf.len());
- buf.clone_from_slice(a);
+ buf.copy_from_slice(a);
*self = b;
Ok(())
}
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
let amt = cmp::min(data.len(), self.len());
let (a, b) = mem::replace(self, &mut []).split_at_mut(amt);
- a.clone_from_slice(&data[..amt]);
+ a.copy_from_slice(&data[..amt]);
*self = b;
Ok(amt)
}
#![feature(collections)]
#![feature(collections_bound)]
#![feature(const_fn)]
+#![feature(copy_from_slice)]
#![feature(core_float)]
#![feature(core_intrinsics)]
#![feature(decode_utf16)]
fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> Ipv6Addr {
assert!(head.len() + tail.len() <= 8);
let mut gs = [0; 8];
- gs[..head.len()].clone_from_slice(head);
- gs[(8 - tail.len()) .. 8].clone_from_slice(tail);
+ gs[..head.len()].copy_from_slice(head);
+ gs[(8 - tail.len()) .. 8].copy_from_slice(tail);
Ipv6Addr::new(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7])
}
///
/// *[See also the `std::f32` module](f32/index.html).*
///
+/// However, please note that examples are shared between the `f64` and `f32`
+/// primitive types. So it's normal if you see usage of `f64` in there.
+///
mod prim_f32 { }
#[doc(primitive = "f64")]
///
/// *[See also the `std::f64` module](f64/index.html).*
///
+/// However, please note that examples are shared between the `f64` and `f32`
+/// primitive types. So it's normal if you see usage of `f32` in there.
+///
mod prim_f64 { }
#[doc(primitive = "i8")]
Some((surrogate_pos, _)) => {
pos = surrogate_pos + 3;
self.bytes[surrogate_pos..pos]
- .clone_from_slice(UTF8_REPLACEMENT_CHARACTER);
+ .copy_from_slice(UTF8_REPLACEMENT_CHARACTER);
},
None => return unsafe { String::from_utf8_unchecked(self.bytes) }
}
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z unstable-options --unpretty=mir
+
+fn main() {
+ let x: () = 0; //~ ERROR: mismatched types
+}