Auto merge of #48768 - kennytm:rollup, r=kennytm

Rollup of 14 pull requests

- Successful merges: #48403, #48432, #48546, #48573, #48590, #48657, #48727, #48732, #48753, #48754, #48761, #48474, #48507, #47463
- Failed merges:
This commit is contained in:
bors 2018-03-06 15:01:21 +00:00
commit 2789b067da
66 changed files with 684 additions and 384 deletions

View File

@ -1,93 +0,0 @@
#!/usr/bin/env python
#
# Copyright 2012-2013 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.
#
# this script attempts to turn doc comment attributes (#[doc = "..."])
# into sugared-doc-comments (/** ... */ and /// ...)
#
# it sugarises all .rs/.rc files underneath the working directory
#
import sys
import os
import fnmatch
import re
DOC_PATTERN = '^(?P<indent>[\\t ]*)#\\[(\\s*)doc(\\s*)=' + \
'(\\s*)"(?P<text>(\\"|[^"])*?)"(\\s*)\\]' + \
'(?P<semi>;)?'
ESCAPES = [("\\'", "'"),
('\\"', '"'),
("\\n", "\n"),
("\\r", "\r"),
("\\t", "\t")]
def unescape(s):
for (find, repl) in ESCAPES:
s = s.replace(find, repl)
return s
def block_trim(s):
lns = s.splitlines()
# remove leading/trailing whitespace-lines
while lns and not lns[0].strip():
lns = lns[1:]
while lns and not lns[-1].strip():
lns = lns[:-1]
# remove leading horizontal whitespace
n = sys.maxsize
for ln in lns:
if ln.strip():
n = min(n, len(re.search('^\s*', ln).group()))
if n != sys.maxsize:
lns = [ln[n:] for ln in lns]
# strip trailing whitespace
lns = [ln.rstrip() for ln in lns]
return lns
def replace_doc(m):
indent = m.group('indent')
text = block_trim(unescape(m.group('text')))
if len(text) > 1:
inner = '!' if m.group('semi') else '*'
starify = lambda s: indent + ' *' + (' ' + s if s else '')
text = '\n'.join(map(starify, text))
repl = indent + '/*' + inner + '\n' + text + '\n' + indent + ' */'
else:
inner = '!' if m.group('semi') else '/'
repl = indent + '//' + inner + ' ' + text[0]
return repl
def sugarise_file(path):
s = open(path).read()
r = re.compile(DOC_PATTERN, re.MULTILINE | re.DOTALL)
ns = re.sub(r, replace_doc, s)
if s != ns:
open(path, 'w').write(ns)
for (dirpath, dirnames, filenames) in os.walk('.'):
for name in fnmatch.filter(filenames, '*.r[sc]'):
sugarise_file(os.path.join(dirpath, name))

View File

@ -964,7 +964,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
/// An owning iterator over the elements of a `BinaryHeap`.
@ -1019,7 +1019,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for IntoIter<T> {}
/// A draining iterator over the elements of a `BinaryHeap`.
@ -1065,7 +1065,7 @@ impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T: 'a> FusedIterator for Drain<'a, T> {}
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]

View File

@ -722,7 +722,7 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}

View File

@ -1156,7 +1156,7 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Iter<'a, K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1235,7 +1235,7 @@ impl<'a, K: 'a, V: 'a> ExactSizeIterator for IterMut<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1365,7 +1365,7 @@ impl<K, V> ExactSizeIterator for IntoIter<K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<K, V> FusedIterator for IntoIter<K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1395,7 +1395,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Keys<'a, K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1432,7 +1432,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Values<'a, K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1482,7 +1482,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {}
@ -1561,7 +1561,7 @@ impl<'a, K, V> Range<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Range<'a, K, V> {}
#[stable(feature = "btree_range", since = "1.17.0")]
@ -1630,7 +1630,7 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for RangeMut<'a, K, V> {}
impl<'a, K, V> RangeMut<'a, K, V> {

View File

@ -946,7 +946,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {
fn len(&self) -> usize { self.iter.len() }
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -971,7 +971,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {
fn len(&self) -> usize { self.iter.len() }
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for IntoIter<T> {}
#[stable(feature = "btree_range", since = "1.17.0")]
@ -997,7 +997,7 @@ impl<'a, T> DoubleEndedIterator for Range<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Range<'a, T> {}
/// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
@ -1044,7 +1044,7 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T: Ord> FusedIterator for Difference<'a, T> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1078,7 +1078,7 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T: Ord> FusedIterator for SymmetricDifference<'a, T> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1116,7 +1116,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T: Ord> FusedIterator for Intersection<'a, T> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1150,5 +1150,5 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T: Ord> FusedIterator for Union<'a, T> {}

View File

@ -96,7 +96,6 @@
#![feature(fmt_internals)]
#![feature(from_ref)]
#![feature(fundamental)]
#![feature(fused)]
#![feature(generic_param_attrs)]
#![feature(i128_type)]
#![feature(inclusive_range)]
@ -124,8 +123,9 @@
#![feature(allocator_internals)]
#![feature(on_unimplemented)]
#![feature(exact_chunks)]
#![feature(pointer_methods)]
#![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))]
#![cfg_attr(not(test), feature(fn_traits, placement_new_protocol, swap_with_slice, i128))]
#![cfg_attr(test, feature(test, box_heap))]
// Allow testing this library

View File

@ -897,7 +897,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -946,7 +946,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for IterMut<'a, T> {}
impl<'a, T> IterMut<'a, T> {
@ -1117,7 +1117,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for IntoIter<T> {}
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -43,6 +43,7 @@ use core::str as core_str;
use core::str::pattern::Pattern;
use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
use core::mem;
use core::ptr;
use core::iter::FusedIterator;
use std_unicode::str::{UnicodeStr, Utf16Encoder};
@ -171,7 +172,7 @@ impl<'a> Iterator for EncodeUtf16<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for EncodeUtf16<'a> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -2066,9 +2067,59 @@ impl str {
/// ```
#[stable(feature = "repeat_str", since = "1.16.0")]
pub fn repeat(&self, n: usize) -> String {
let mut s = String::with_capacity(self.len() * n);
s.extend((0..n).map(|_| self));
s
if n == 0 {
return String::new();
}
// If `n` is larger than zero, it can be split as
// `n = 2^expn + rem (2^expn > rem, expn >= 0, rem >= 0)`.
// `2^expn` is the number represented by the leftmost '1' bit of `n`,
// and `rem` is the remaining part of `n`.
// Using `Vec` to access `set_len()`.
let mut buf = Vec::with_capacity(self.len() * n);
// `2^expn` repetition is done by doubling `buf` `expn`-times.
buf.extend(self.as_bytes());
{
let mut m = n >> 1;
// If `m > 0`, there are remaining bits up to the leftmost '1'.
while m > 0 {
// `buf.extend(buf)`:
unsafe {
ptr::copy_nonoverlapping(
buf.as_ptr(),
(buf.as_mut_ptr() as *mut u8).add(buf.len()),
buf.len(),
);
// `buf` has capacity of `self.len() * n`.
let buf_len = buf.len();
buf.set_len(buf_len * 2);
}
m >>= 1;
}
}
// `rem` (`= n - 2^expn`) repetition is done by copying
// first `rem` repetitions from `buf` itself.
let rem_len = self.len() * n - buf.len(); // `self.len() * rem`
if rem_len > 0 {
// `buf.extend(buf[0 .. rem_len])`:
unsafe {
// This is non-overlapping since `2^expn > rem`.
ptr::copy_nonoverlapping(
buf.as_ptr(),
(buf.as_mut_ptr() as *mut u8).add(buf.len()),
rem_len,
);
// `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`).
let buf_cap = buf.capacity();
buf.set_len(buf_cap);
}
}
unsafe { String::from_utf8_unchecked(buf) }
}
/// Checks if all characters in this string are within the ASCII range.

View File

@ -2254,5 +2254,5 @@ impl<'a> DoubleEndedIterator for Drain<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for Drain<'a> {}

View File

@ -2273,7 +2273,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for IntoIter<T> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -2379,7 +2379,7 @@ impl<'a, T> ExactSizeIterator for Drain<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Drain<'a, T> {}
/// A place for insertion at the back of a `Vec`.

View File

@ -1991,7 +1991,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
@ -2084,7 +2084,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for IterMut<'a, T> {}
/// An owning iterator over the elements of a `VecDeque`.
@ -2140,7 +2140,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for IntoIter<T> {}
/// A draining iterator over the elements of a `VecDeque`.
@ -2247,7 +2247,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
#[stable(feature = "drain", since = "1.6.0")]
impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T: 'a> FusedIterator for Drain<'a, T> {}
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -10,6 +10,24 @@
//! Shareable mutable containers.
//!
//! Rust memory safety is based on this rule: Given an object `T`, it is only possible to
//! have one of the following:
//!
//! - Having several immutable references (`&T`) to the object (also known as **aliasing**).
//! - Having one mutable reference (`&mut T`) to the object (also known as **mutability**).
//!
//! This is enforced by the Rust compiler. However, there are situations where this rule is not
//! flexible enough. Sometimes it is required to have multiple references to an object and yet
//! mutate it.
//!
//! Shareable mutable containers exist to permit mutability in a controlled manner, even in the
//! presence of aliasing. Both `Cell<T>` and `RefCell<T>` allows to do this in a single threaded
//! way. However, neither `Cell<T>` nor `RefCell<T>` are thread safe (they do not implement
//! `Sync`). If you need to do aliasing and mutation between multiple threads it is possible to
//! use [`Mutex`](../../std/sync/struct.Mutex.html),
//! [`RwLock`](../../std/sync/struct.RwLock.html) or
//! [`atomic`](../../core/sync/atomic/index.html) types.
//!
//! Values of the `Cell<T>` and `RefCell<T>` types may be mutated through shared references (i.e.
//! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`)
//! references. We say that `Cell<T>` and `RefCell<T>` provide 'interior mutability', in contrast

View File

@ -79,7 +79,7 @@ pub const MAX: char = '\u{10ffff}';
/// Converts a `u32` to a `char`.
///
/// Note that all [`char`]s are valid [`u32`]s, and can be casted to one with
/// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with
/// [`as`]:
///
/// ```
@ -131,7 +131,7 @@ pub fn from_u32(i: u32) -> Option<char> {
/// Converts a `u32` to a `char`, ignoring validity.
///
/// Note that all [`char`]s are valid [`u32`]s, and can be casted to one with
/// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with
/// [`as`]:
///
/// ```
@ -643,7 +643,7 @@ impl ExactSizeIterator for EscapeUnicode {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for EscapeUnicode {}
#[stable(feature = "char_struct_display", since = "1.16.0")]
@ -756,7 +756,7 @@ impl ExactSizeIterator for EscapeDefault {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for EscapeDefault {}
#[stable(feature = "char_struct_display", since = "1.16.0")]
@ -790,7 +790,7 @@ impl Iterator for EscapeDebug {
#[stable(feature = "char_escape_debug", since = "1.20.0")]
impl ExactSizeIterator for EscapeDebug { }
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for EscapeDebug {}
#[stable(feature = "char_escape_debug", since = "1.20.0")]
@ -904,5 +904,5 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "decode_utf8", issue = "33906")]
impl<I: FusedIterator<Item = u8>> FusedIterator for DecodeUtf8<I> {}

View File

@ -1292,6 +1292,10 @@ extern "rust-intrinsic" {
/// Reverses the bytes in an integer type `T`.
pub fn bswap<T>(x: T) -> T;
/// Reverses the bits in an integer type `T`.
#[cfg(not(stage0))]
pub fn bitreverse<T>(x: T) -> T;
/// Performs checked integer addition.
/// The stabilized versions of this intrinsic are available on the integer
/// primitives via the `overflowing_add` method. For example,

View File

@ -1180,19 +1180,19 @@ pub trait Iterator {
///
/// // this iterator sequence is complex.
/// let sum = a.iter()
/// .cloned()
/// .filter(|&x| x % 2 == 0)
/// .fold(0, |sum, i| sum + i);
/// .cloned()
/// .filter(|x| x % 2 == 0)
/// .fold(0, |sum, i| sum + i);
///
/// println!("{}", sum);
///
/// // let's add some inspect() calls to investigate what's happening
/// let sum = a.iter()
/// .cloned()
/// .inspect(|x| println!("about to filter: {}", x))
/// .filter(|&x| x % 2 == 0)
/// .inspect(|x| println!("made it through filter: {}", x))
/// .fold(0, |sum, i| sum + i);
/// .cloned()
/// .inspect(|x| println!("about to filter: {}", x))
/// .filter(|x| x % 2 == 0)
/// .inspect(|x| println!("made it through filter: {}", x))
/// .fold(0, |sum, i| sum + i);
///
/// println!("{}", sum);
/// ```
@ -1200,6 +1200,7 @@ pub trait Iterator {
/// This will print:
///
/// ```text
/// 6
/// about to filter: 1
/// about to filter: 4
/// made it through filter: 4
@ -1230,8 +1231,7 @@ pub trait Iterator {
///
/// let iter = a.into_iter();
///
/// let sum: i32 = iter.take(5)
/// .fold(0, |acc, &i| acc + i );
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i );
///
/// assert_eq!(sum, 6);
///
@ -1245,9 +1245,7 @@ pub trait Iterator {
/// let mut iter = a.into_iter();
///
/// // instead, we add in a .by_ref()
/// let sum: i32 = iter.by_ref()
/// .take(2)
/// .fold(0, |acc, &i| acc + i );
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i );
///
/// assert_eq!(sum, 3);
///
@ -1304,9 +1302,7 @@ pub trait Iterator {
///
/// let a = [1, 2, 3];
///
/// let doubled: VecDeque<i32> = a.iter()
/// .map(|&x| x * 2)
/// .collect();
/// let doubled: VecDeque<i32> = a.iter().map(|&x| x * 2).collect();
///
/// assert_eq!(2, doubled[0]);
/// assert_eq!(4, doubled[1]);
@ -1318,9 +1314,7 @@ pub trait Iterator {
/// ```
/// let a = [1, 2, 3];
///
/// let doubled = a.iter()
/// .map(|&x| x * 2)
/// .collect::<Vec<i32>>();
/// let doubled = a.iter().map(|x| x * 2).collect::<Vec<i32>>();
///
/// assert_eq!(vec![2, 4, 6], doubled);
/// ```
@ -1331,9 +1325,7 @@ pub trait Iterator {
/// ```
/// let a = [1, 2, 3];
///
/// let doubled = a.iter()
/// .map(|&x| x * 2)
/// .collect::<Vec<_>>();
/// let doubled = a.iter().map(|x| x * 2).collect::<Vec<_>>();
///
/// assert_eq!(vec![2, 4, 6], doubled);
/// ```
@ -1344,9 +1336,9 @@ pub trait Iterator {
/// let chars = ['g', 'd', 'k', 'k', 'n'];
///
/// let hello: String = chars.iter()
/// .map(|&x| x as u8)
/// .map(|x| (x + 1) as char)
/// .collect();
/// .map(|&x| x as u8)
/// .map(|x| (x + 1) as char)
/// .collect();
///
/// assert_eq!("hello", hello);
/// ```
@ -1393,8 +1385,9 @@ pub trait Iterator {
/// ```
/// let a = [1, 2, 3];
///
/// let (even, odd): (Vec<i32>, Vec<i32>) = a.into_iter()
/// .partition(|&n| n % 2 == 0);
/// let (even, odd): (Vec<i32>, Vec<i32>) = a
/// .into_iter()
/// .partition(|&n| n % 2 == 0);
///
/// assert_eq!(even, vec![2]);
/// assert_eq!(odd, vec![1, 3]);
@ -1457,8 +1450,7 @@ pub trait Iterator {
/// let a = [1, 2, 3];
///
/// // the checked sum of all of the elements of the array
/// let sum = a.iter()
/// .try_fold(0i8, |acc, &x| acc.checked_add(x));
/// let sum = a.iter().try_fold(0i8, |acc, &x| acc.checked_add(x));
///
/// assert_eq!(sum, Some(6));
/// ```
@ -1556,8 +1548,7 @@ pub trait Iterator {
/// let a = [1, 2, 3];
///
/// // the sum of all of the elements of the array
/// let sum = a.iter()
/// .fold(0, |acc, &x| acc + x);
/// let sum = a.iter().fold(0, |acc, x| acc + x);
///
/// assert_eq!(sum, 6);
/// ```

View File

@ -344,7 +344,7 @@ pub use self::sources::{Once, once};
pub use self::traits::{FromIterator, IntoIterator, DoubleEndedIterator, Extend};
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::traits::{ExactSizeIterator, Sum, Product};
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
pub use self::traits::FusedIterator;
#[unstable(feature = "trusted_len", issue = "37572")]
pub use self::traits::TrustedLen;
@ -506,7 +506,7 @@ impl<I> ExactSizeIterator for Rev<I>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Rev<I>
where I: FusedIterator + DoubleEndedIterator {}
@ -589,7 +589,7 @@ impl<'a, I, T: 'a> ExactSizeIterator for Cloned<I>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, I, T: 'a> FusedIterator for Cloned<I>
where I: FusedIterator<Item=&'a T>, T: Clone
{}
@ -662,7 +662,7 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Cycle<I> where I: Clone + Iterator {}
/// An iterator for stepping iterators by a custom amount.
@ -1002,7 +1002,7 @@ impl<A, B> DoubleEndedIterator for Chain<A, B> where
}
// Note: *both* must be fused to handle double-ended iterators.
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A, B> FusedIterator for Chain<A, B>
where A: FusedIterator,
B: FusedIterator<Item=A::Item>,
@ -1262,7 +1262,7 @@ unsafe impl<A, B> TrustedRandomAccess for Zip<A, B>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A, B> FusedIterator for Zip<A, B>
where A: FusedIterator, B: FusedIterator, {}
@ -1404,7 +1404,7 @@ impl<B, I: ExactSizeIterator, F> ExactSizeIterator for Map<I, F>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<B, I: FusedIterator, F> FusedIterator for Map<I, F>
where F: FnMut(I::Item) -> B {}
@ -1553,7 +1553,7 @@ impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I: FusedIterator, P> FusedIterator for Filter<I, P>
where P: FnMut(&I::Item) -> bool {}
@ -1663,7 +1663,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F>
where F: FnMut(I::Item) -> Option<B> {}
@ -1818,7 +1818,7 @@ unsafe impl<I> TrustedRandomAccess for Enumerate<I>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Enumerate<I> where I: FusedIterator {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -1938,7 +1938,7 @@ impl<I: Iterator> Iterator for Peekable<I> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<I: ExactSizeIterator> ExactSizeIterator for Peekable<I> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I: FusedIterator> FusedIterator for Peekable<I> {}
impl<I: Iterator> Peekable<I> {
@ -2072,7 +2072,7 @@ impl<I: Iterator, P> Iterator for SkipWhile<I, P>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I, P> FusedIterator for SkipWhile<I, P>
where I: FusedIterator, P: FnMut(&I::Item) -> bool {}
@ -2151,7 +2151,7 @@ impl<I: Iterator, P> Iterator for TakeWhile<I, P>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I, P> FusedIterator for TakeWhile<I, P>
where I: FusedIterator, P: FnMut(&I::Item) -> bool {}
@ -2290,7 +2290,7 @@ impl<I> DoubleEndedIterator for Skip<I> where I: DoubleEndedIterator + ExactSize
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Skip<I> where I: FusedIterator {}
/// An iterator that only iterates over the first `n` iterations of `iter`.
@ -2371,7 +2371,7 @@ impl<I> Iterator for Take<I> where I: Iterator{
#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Take<I> where I: ExactSizeIterator {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Take<I> where I: FusedIterator {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -2517,7 +2517,7 @@ impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I, U, F> FusedIterator for FlatMap<I, U, F>
where I: FusedIterator, U: IntoIterator, F: FnMut(I::Item) -> U {}
@ -2605,7 +2605,7 @@ impl<I, U> DoubleEndedIterator for Flatten<I>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I, U> FusedIterator for Flatten<I>
where I: FusedIterator, U: Iterator,
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}
@ -2765,7 +2765,7 @@ pub struct Fuse<I> {
done: bool
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Fuse<I> where I: Iterator {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -2896,7 +2896,7 @@ unsafe impl<I> TrustedRandomAccess for Fuse<I>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> Iterator for Fuse<I> where I: FusedIterator {
#[inline]
fn next(&mut self) -> Option<<I as Iterator>::Item> {
@ -2938,7 +2938,7 @@ impl<I> Iterator for Fuse<I> where I: FusedIterator {
}
}
#[unstable(feature = "fused", reason = "recently added", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I> DoubleEndedIterator for Fuse<I>
where I: DoubleEndedIterator + FusedIterator
{
@ -3082,6 +3082,6 @@ impl<I: ExactSizeIterator, F> ExactSizeIterator for Inspect<I, F>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<I: FusedIterator, F> FusedIterator for Inspect<I, F>
where F: FnMut(&I::Item) {}

View File

@ -295,7 +295,7 @@ impl<A: Step> DoubleEndedIterator for ops::Range<A> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A: Step> FusedIterator for ops::Range<A> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -322,7 +322,7 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A: Step> FusedIterator for ops::RangeFrom<A> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -463,5 +463,5 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A: Step> FusedIterator for ops::RangeInclusive<A> {}

View File

@ -41,7 +41,7 @@ impl<A: Clone> DoubleEndedIterator for Repeat<A> {
fn next_back(&mut self) -> Option<A> { Some(self.element.clone()) }
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A: Clone> FusedIterator for Repeat<A> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -135,7 +135,7 @@ impl<A, F: FnMut() -> A> DoubleEndedIterator for RepeatWith<F> {
fn next_back(&mut self) -> Option<A> { self.next() }
}
#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
impl<A, F: FnMut() -> A> FusedIterator for RepeatWith<F> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -259,7 +259,7 @@ impl<T> ExactSizeIterator for Empty<T> {
#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<T> TrustedLen for Empty<T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for Empty<T> {}
// not #[derive] because that adds a Clone bound on T,
@ -340,7 +340,7 @@ impl<T> ExactSizeIterator for Once<T> {
#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<T> TrustedLen for Once<T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for Once<T> {}
/// Creates an iterator that yields an element exactly once.

View File

@ -959,10 +959,10 @@ impl<T, U, E> Product<Result<U, E>> for Result<T, E>
/// [`None`]: ../../std/option/enum.Option.html#variant.None
/// [`Iterator::fuse`]: ../../std/iter/trait.Iterator.html#method.fuse
/// [`Fuse`]: ../../std/iter/struct.Fuse.html
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
pub trait FusedIterator: Iterator {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {}
/// An iterator that reports an accurate length using size_hint.

View File

@ -321,6 +321,33 @@ $EndFeature, "
(self as $UnsignedT).swap_bytes() as Self
}
/// Reverses the bit pattern of the integer.
///
/// # Examples
///
/// Please note that this example is shared between integer types.
/// Which explains why `i16` is used here.
///
/// Basic usage:
///
/// ```
/// #![feature(reverse_bits)]
///
/// let n: i16 = 0b0000000_01010101;
/// assert_eq!(n, 85);
///
/// let m = n.reverse_bits();
///
/// assert_eq!(m as u16, 0b10101010_00000000);
/// assert_eq!(m, -22016);
/// ```
#[unstable(feature = "reverse_bits", issue = "48763")]
#[cfg(not(stage0))]
#[inline]
pub fn reverse_bits(self) -> Self {
(self as $UnsignedT).reverse_bits() as Self
}
doc_comment! {
concat!("Converts an integer from big endian to the target's endianness.
@ -1773,6 +1800,33 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, "
unsafe { intrinsics::bswap(self as $ActualT) as Self }
}
/// Reverses the bit pattern of the integer.
///
/// # Examples
///
/// Basic usage:
///
/// Please note that this example is shared between integer types.
/// Which explains why `u16` is used here.
///
/// ```
/// #![feature(reverse_bits)]
///
/// let n: u16 = 0b0000000_01010101;
/// assert_eq!(n, 85);
///
/// let m = n.reverse_bits();
///
/// assert_eq!(m, 0b10101010_00000000);
/// assert_eq!(m, 43520);
/// ```
#[unstable(feature = "reverse_bits", issue = "48763")]
#[cfg(not(stage0))]
#[inline]
pub fn reverse_bits(self) -> Self {
unsafe { intrinsics::bitreverse(self as $ActualT) as Self }
}
doc_comment! {
concat!("Converts an integer from big endian to the target's endianness.

View File

@ -1051,7 +1051,7 @@ impl<'a, A> DoubleEndedIterator for Iter<'a, A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> ExactSizeIterator for Iter<'a, A> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, A> FusedIterator for Iter<'a, A> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -1096,7 +1096,7 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, A> ExactSizeIterator for IterMut<'a, A> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, A> FusedIterator for IterMut<'a, A> {}
#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, A> TrustedLen for IterMut<'a, A> {}
@ -1133,7 +1133,7 @@ impl<A> DoubleEndedIterator for IntoIter<A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> ExactSizeIterator for IntoIter<A> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<A> FusedIterator for IntoIter<A> {}
#[unstable(feature = "trusted_len", issue = "37572")]

View File

@ -1038,7 +1038,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -1082,7 +1082,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for IterMut<'a, T> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -1125,7 +1125,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<T> FusedIterator for IntoIter<T> {}
#[unstable(feature = "trusted_len", issue = "37572")]

View File

@ -1455,7 +1455,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -1583,7 +1583,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for IterMut<'a, T> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -1731,7 +1731,7 @@ impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T, P> FusedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool {}
/// An iterator over the subslices of the vector which are separated
@ -1829,7 +1829,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T, P> FusedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {}
/// An iterator over subslices separated by elements that match a predicate
@ -1886,7 +1886,6 @@ impl<'a, T, P> SplitIter for RSplit<'a, T, P> where P: FnMut(&T) -> bool {
}
}
//#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "slice_rsplit", issue = "41020")]
impl<'a, T, P> FusedIterator for RSplit<'a, T, P> where P: FnMut(&T) -> bool {}
@ -1945,7 +1944,6 @@ impl<'a, T, P> DoubleEndedIterator for RSplitMut<'a, T, P> where
}
}
//#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "slice_rsplit", issue = "41020")]
impl<'a, T, P> FusedIterator for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool {}
@ -2082,7 +2080,7 @@ macro_rules! forward_iterator {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, $elem, P> FusedIterator for $name<'a, $elem, P>
where P: FnMut(&T) -> bool {}
}
@ -2188,7 +2186,7 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Windows<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Windows<'a, T> {}
#[doc(hidden)]
@ -2307,7 +2305,7 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for Chunks<'a, T> {}
#[doc(hidden)]
@ -2423,7 +2421,7 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T> FusedIterator for ChunksMut<'a, T> {}
#[doc(hidden)]
@ -2533,7 +2531,7 @@ impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "exact_chunks", issue = "47115")]
impl<'a, T> FusedIterator for ExactChunks<'a, T> {}
#[doc(hidden)]
@ -2630,7 +2628,7 @@ impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "exact_chunks", issue = "47115")]
impl<'a, T> FusedIterator for ExactChunksMut<'a, T> {}
#[doc(hidden)]

View File

@ -609,7 +609,7 @@ impl<'a> DoubleEndedIterator for Chars<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for Chars<'a> {}
impl<'a> Chars<'a> {
@ -702,7 +702,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for CharIndices<'a> {}
impl<'a> CharIndices<'a> {
@ -817,7 +817,7 @@ impl<'a> ExactSizeIterator for Bytes<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for Bytes<'a> {}
#[unstable(feature = "trusted_len", issue = "37572")]
@ -977,10 +977,10 @@ macro_rules! generate_pattern_iterators {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, P: Pattern<'a>> FusedIterator for $forward_iterator<'a, P> {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, P: Pattern<'a>> FusedIterator for $reverse_iterator<'a, P>
where P::Searcher: ReverseSearcher<'a> {}
@ -1337,7 +1337,7 @@ impl<'a> DoubleEndedIterator for Lines<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for Lines<'a> {}
/// Created with the method [`lines_any`].
@ -1403,7 +1403,7 @@ impl<'a> DoubleEndedIterator for LinesAny<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
#[allow(deprecated)]
impl<'a> FusedIterator for LinesAny<'a> {}

View File

@ -46,6 +46,7 @@
#![feature(try_trait)]
#![feature(exact_chunks)]
#![feature(atomic_nand)]
#![feature(reverse_bits)]
extern crate core;
extern crate test;

View File

@ -97,6 +97,17 @@ mod tests {
assert_eq!(_1.swap_bytes(), _1);
}
#[test]
fn test_reverse_bits() {
assert_eq!(A.reverse_bits().reverse_bits(), A);
assert_eq!(B.reverse_bits().reverse_bits(), B);
assert_eq!(C.reverse_bits().reverse_bits(), C);
// Swapping these should make no difference
assert_eq!(_0.reverse_bits(), _0);
assert_eq!(_1.reverse_bits(), _1);
}
#[test]
fn test_le() {
assert_eq!($T::from_le(A.to_le()), A);

View File

@ -2208,13 +2208,8 @@ impl<'a> State<'a> {
if self.next_comment().is_none() {
self.s.hardbreak()?;
}
loop {
match self.next_comment() {
Some(ref cmnt) => {
self.print_comment(cmnt)?;
}
_ => break,
}
while let Some(ref cmnt) = self.next_comment() {
self.print_comment(cmnt)?
}
Ok(())
}

View File

@ -206,11 +206,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
// Step 2: Mark all symbols that the symbols on the worklist touch.
fn propagate(&mut self) {
let mut scanned = FxHashSet();
loop {
let search_item = match self.worklist.pop() {
Some(item) => item,
None => break,
};
while let Some(search_item) = self.worklist.pop() {
if !scanned.insert(search_item) {
continue
}

View File

@ -415,13 +415,7 @@ impl<O: ForestObligation> ObligationForest<O> {
}
}
loop {
// non-standard `while let` to bypass #6393
let i = match error_stack.pop() {
Some(i) => i,
None => break
};
while let Some(i) = error_stack.pop() {
let node = &self.nodes[i];
match node.state.get() {

View File

@ -150,11 +150,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
// Detect literal value out of range [min, max] inclusive
// avoiding use of -min to prevent overflow/panic
if (negative && v > max + 1) ||
(!negative && v > max) {
cx.span_lint(OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t));
if (negative && v > max + 1) || (!negative && v > max) {
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {
report_bin_hex_error(
cx,
e,
ty::TyInt(t),
repr_str,
v,
negative,
);
return;
}
cx.span_lint(
OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t),
);
return;
}
}
@ -182,7 +194,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
let mut err = cx.struct_span_lint(
OVERFLOWING_LITERALS,
parent_expr.span,
"only u8 can be casted into char");
"only u8 can be cast into char");
err.span_suggestion(parent_expr.span,
&"use a char literal instead",
format!("'\\u{{{:X}}}'", lit_val));
@ -191,9 +203,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
}
}
}
cx.span_lint(OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t));
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {
report_bin_hex_error(
cx,
e,
ty::TyUint(t),
repr_str,
lit_val,
false,
);
return;
}
cx.span_lint(
OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t),
);
}
}
ty::TyFloat(t) => {
@ -338,6 +363,120 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
_ => false,
}
}
fn get_bin_hex_repr(cx: &LateContext, lit: &ast::Lit) -> Option<String> {
let src = cx.sess().codemap().span_to_snippet(lit.span).ok()?;
let firstch = src.chars().next()?;
if firstch == '0' {
match src.chars().nth(1) {
Some('x') | Some('b') => return Some(src),
_ => return None,
}
}
None
}
// This function finds the next fitting type and generates a suggestion string.
// It searches for fitting types in the following way (`X < Y`):
// - `iX`: if literal fits in `uX` => `uX`, else => `iY`
// - `-iX` => `iY`
// - `uX` => `uY`
//
// No suggestion for: `isize`, `usize`.
fn get_type_suggestion<'a>(
t: &ty::TypeVariants,
val: u128,
negative: bool,
) -> Option<String> {
use syntax::ast::IntTy::*;
use syntax::ast::UintTy::*;
macro_rules! find_fit {
($ty:expr, $val:expr, $negative:expr,
$($type:ident => [$($utypes:expr),*] => [$($itypes:expr),*]),+) => {
{
let _neg = if negative { 1 } else { 0 };
match $ty {
$($type => {
$(if !negative && val <= uint_ty_range($utypes).1 {
return Some(format!("{:?}", $utypes))
})*
$(if val <= int_ty_range($itypes).1 as u128 + _neg {
return Some(format!("{:?}", $itypes))
})*
None
},)*
_ => None
}
}
}
}
match t {
&ty::TyInt(i) => find_fit!(i, val, negative,
I8 => [U8] => [I16, I32, I64, I128],
I16 => [U16] => [I32, I64, I128],
I32 => [U32] => [I64, I128],
I64 => [U64] => [I128],
I128 => [U128] => []),
&ty::TyUint(u) => find_fit!(u, val, negative,
U8 => [U8, U16, U32, U64, U128] => [],
U16 => [U16, U32, U64, U128] => [],
U32 => [U32, U64, U128] => [],
U64 => [U64, U128] => [],
U128 => [U128] => []),
_ => None,
}
}
fn report_bin_hex_error(
cx: &LateContext,
expr: &hir::Expr,
ty: ty::TypeVariants,
repr_str: String,
val: u128,
negative: bool,
) {
let (t, actually) = match ty {
ty::TyInt(t) => {
let bits = int_ty_bits(t, cx.sess().target.isize_ty);
let actually = (val << (128 - bits)) as i128 >> (128 - bits);
(format!("{:?}", t), actually.to_string())
}
ty::TyUint(t) => {
let bits = uint_ty_bits(t, cx.sess().target.usize_ty);
let actually = (val << (128 - bits)) >> (128 - bits);
(format!("{:?}", t), actually.to_string())
}
_ => bug!(),
};
let mut err = cx.struct_span_lint(
OVERFLOWING_LITERALS,
expr.span,
&format!("literal out of range for {}", t),
);
err.note(&format!(
"the literal `{}` (decimal `{}`) does not fit into \
an `{}` and will become `{}{}`",
repr_str, val, t, actually, t
));
if let Some(sugg_ty) =
get_type_suggestion(&cx.tables.node_id_to_type(expr.hir_id).sty, val, negative)
{
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
let (sans_suffix, _) = repr_str.split_at(pos);
err.span_suggestion(
expr.span,
&format!("consider using `{}` instead", sugg_ty),
format!("{}{}", sans_suffix, sugg_ty),
);
} else {
err.help(&format!("consider using `{}` instead", sugg_ty));
}
}
err.emit();
}
}
}

View File

@ -77,19 +77,12 @@ impl Lower128Bit {
};
let bin_statement = block.statements.pop().unwrap();
let (source_info, place, lhs, mut rhs) = match bin_statement {
Statement {
source_info,
kind: StatementKind::Assign(
place,
Rvalue::BinaryOp(_, lhs, rhs))
} => (source_info, place, lhs, rhs),
Statement {
source_info,
kind: StatementKind::Assign(
place,
Rvalue::CheckedBinaryOp(_, lhs, rhs))
} => (source_info, place, lhs, rhs),
let source_info = bin_statement.source_info;
let (place, lhs, mut rhs) = match bin_statement.kind {
StatementKind::Assign(place, Rvalue::BinaryOp(_, lhs, rhs))
| StatementKind::Assign(place, Rvalue::CheckedBinaryOp(_, lhs, rhs)) => {
(place, lhs, rhs)
}
_ => bug!("Statement doesn't match pattern any more?"),
};

View File

@ -597,6 +597,12 @@ fn declare_intrinsic(cx: &CodegenCx, key: &str) -> Option<ValueRef> {
ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});

View File

@ -287,8 +287,8 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
], None)
},
"ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "ctpop" | "bswap" |
"add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" |
"overflowing_add" | "overflowing_sub" | "overflowing_mul" |
"bitreverse" | "add_with_overflow" | "sub_with_overflow" |
"mul_with_overflow" | "overflowing_add" | "overflowing_sub" | "overflowing_mul" |
"unchecked_div" | "unchecked_rem" | "unchecked_shl" | "unchecked_shr" => {
let ty = arg_tys[0];
match int_type_width_signed(ty, cx) {
@ -315,6 +315,10 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
&[args[0].immediate()], None)
}
}
"bitreverse" => {
bx.call(cx.get_intrinsic(&format!("llvm.bitreverse.i{}", width)),
&[args[0].immediate()], None)
}
"add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" => {
let intrinsic = format!("llvm.{}{}.with.overflow.i{}",
if signed { 's' } else { 'u' },

View File

@ -275,7 +275,8 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"volatile_store" =>
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_nil()),
"ctpop" | "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "bswap" =>
"ctpop" | "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" |
"bswap" | "bitreverse" =>
(1, vec![param(0)], param(0)),
"add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" =>

View File

@ -590,7 +590,7 @@ impl DoubleEndedIterator for EscapeDefault {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl ExactSizeIterator for EscapeDefault {}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for EscapeDefault {}
#[stable(feature = "std_debug", since = "1.16.0")]

View File

@ -620,7 +620,7 @@ impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {
///
/// ```
/// use std::collections::HashMap;
/// let mut map: HashMap<&str, isize> = HashMap::new();
/// let mut map: HashMap<&str, i32> = HashMap::new();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -637,7 +637,7 @@ impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {
///
/// ```
/// use std::collections::HashMap;
/// let mut map: HashMap<&str, isize> = HashMap::with_capacity(10);
/// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -724,7 +724,7 @@ impl<K, V, S> HashMap<K, V, S>
/// use std::collections::hash_map::RandomState;
///
/// let hasher = RandomState::new();
/// let map: HashMap<isize, isize> = HashMap::with_hasher(hasher);
/// let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
/// let hasher: &RandomState = map.hasher();
/// ```
#[stable(feature = "hashmap_public_hasher", since = "1.9.0")]
@ -741,7 +741,7 @@ impl<K, V, S> HashMap<K, V, S>
///
/// ```
/// use std::collections::HashMap;
/// let map: HashMap<isize, isize> = HashMap::with_capacity(100);
/// let map: HashMap<i32, i32> = HashMap::with_capacity(100);
/// assert!(map.capacity() >= 100);
/// ```
#[inline]
@ -770,7 +770,7 @@ impl<K, V, S> HashMap<K, V, S>
///
/// ```
/// use std::collections::HashMap;
/// let mut map: HashMap<&str, isize> = HashMap::new();
/// let mut map: HashMap<&str, i32> = HashMap::new();
/// map.reserve(10);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -849,7 +849,7 @@ impl<K, V, S> HashMap<K, V, S>
/// ```
/// use std::collections::HashMap;
///
/// let mut map: HashMap<isize, isize> = HashMap::with_capacity(100);
/// let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
/// map.insert(1, 2);
/// map.insert(3, 4);
/// assert!(map.capacity() >= 100);
@ -1306,7 +1306,7 @@ impl<K, V, S> HashMap<K, V, S>
/// ```
/// use std::collections::HashMap;
///
/// let mut map: HashMap<isize, isize> = (0..8).map(|x|(x, x*10)).collect();
/// let mut map: HashMap<i32, i32> = (0..8).map(|x|(x, x*10)).collect();
/// map.retain(|&k, _| k % 2 == 0);
/// assert_eq!(map.len(), 4);
/// ```
@ -1722,7 +1722,7 @@ impl<K, V, S> IntoIterator for HashMap<K, V, S>
/// map.insert("c", 3);
///
/// // Not possible with .iter()
/// let vec: Vec<(&str, isize)> = map.into_iter().collect();
/// let vec: Vec<(&str, i32)> = map.into_iter().collect();
/// ```
fn into_iter(self) -> IntoIter<K, V> {
IntoIter { inner: self.table.into_iter() }
@ -1750,7 +1750,7 @@ impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Iter<'a, K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1773,7 +1773,7 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
self.inner.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -1808,7 +1808,7 @@ impl<K, V> ExactSizeIterator for IntoIter<K, V> {
self.inner.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<K, V> FusedIterator for IntoIter<K, V> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -1840,7 +1840,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
self.inner.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Keys<'a, K, V> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1863,7 +1863,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
self.inner.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Values<'a, K, V> {}
#[stable(feature = "map_values_mut", since = "1.10.0")]
@ -1886,7 +1886,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> {
self.inner.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -1921,7 +1921,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> {
self.inner.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K, V> FusedIterator for Drain<'a, K, V> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -2786,24 +2786,24 @@ mod test_map {
assert_eq!(m2.len(), 2);
}
thread_local! { static DROP_VECTOR: RefCell<Vec<isize>> = RefCell::new(Vec::new()) }
thread_local! { static DROP_VECTOR: RefCell<Vec<i32>> = RefCell::new(Vec::new()) }
#[derive(Hash, PartialEq, Eq)]
struct Dropable {
struct Droppable {
k: usize,
}
impl Dropable {
fn new(k: usize) -> Dropable {
impl Droppable {
fn new(k: usize) -> Droppable {
DROP_VECTOR.with(|slot| {
slot.borrow_mut()[k] += 1;
});
Dropable { k: k }
Droppable { k: k }
}
}
impl Drop for Dropable {
impl Drop for Droppable {
fn drop(&mut self) {
DROP_VECTOR.with(|slot| {
slot.borrow_mut()[self.k] -= 1;
@ -2811,9 +2811,9 @@ mod test_map {
}
}
impl Clone for Dropable {
fn clone(&self) -> Dropable {
Dropable::new(self.k)
impl Clone for Droppable {
fn clone(&self) -> Droppable {
Droppable::new(self.k)
}
}
@ -2833,8 +2833,8 @@ mod test_map {
});
for i in 0..100 {
let d1 = Dropable::new(i);
let d2 = Dropable::new(i + 100);
let d1 = Droppable::new(i);
let d2 = Droppable::new(i + 100);
m.insert(d1, d2);
}
@ -2845,7 +2845,7 @@ mod test_map {
});
for i in 0..50 {
let k = Dropable::new(i);
let k = Droppable::new(i);
let v = m.remove(&k);
assert!(v.is_some());
@ -2892,8 +2892,8 @@ mod test_map {
});
for i in 0..100 {
let d1 = Dropable::new(i);
let d2 = Dropable::new(i + 100);
let d1 = Droppable::new(i);
let d2 = Droppable::new(i + 100);
hm.insert(d1, d2);
}
@ -2943,13 +2943,13 @@ mod test_map {
#[test]
fn test_empty_remove() {
let mut m: HashMap<isize, bool> = HashMap::new();
let mut m: HashMap<i32, bool> = HashMap::new();
assert_eq!(m.remove(&0), None);
}
#[test]
fn test_empty_entry() {
let mut m: HashMap<isize, bool> = HashMap::new();
let mut m: HashMap<i32, bool> = HashMap::new();
match m.entry(0) {
Occupied(_) => panic!(),
Vacant(_) => {}
@ -2960,7 +2960,7 @@ mod test_map {
#[test]
fn test_empty_iter() {
let mut m: HashMap<isize, bool> = HashMap::new();
let mut m: HashMap<i32, bool> = HashMap::new();
assert_eq!(m.drain().next(), None);
assert_eq!(m.keys().next(), None);
assert_eq!(m.values().next(), None);
@ -3461,7 +3461,7 @@ mod test_map {
fn test_entry_take_doesnt_corrupt() {
#![allow(deprecated)] //rand
// Test for #19292
fn check(m: &HashMap<isize, ()>) {
fn check(m: &HashMap<i32, ()>) {
for k in m.keys() {
assert!(m.contains_key(k),
"{} is in keys() but not in the map?", k);
@ -3570,7 +3570,7 @@ mod test_map {
#[test]
fn test_retain() {
let mut map: HashMap<isize, isize> = (0..100).map(|x|(x, x*10)).collect();
let mut map: HashMap<i32, i32> = (0..100).map(|x|(x, x*10)).collect();
map.retain(|&k, _| k % 2 == 0);
assert_eq!(map.len(), 50);

View File

@ -724,7 +724,7 @@ impl<T, S> HashSet<T, S>
/// use std::collections::HashSet;
///
/// let xs = [1,2,3,4,5,6];
/// let mut set: HashSet<isize> = xs.iter().cloned().collect();
/// let mut set: HashSet<i32> = xs.iter().cloned().collect();
/// set.retain(|&k| k % 2 == 0);
/// assert_eq!(set.len(), 3);
/// ```
@ -1097,7 +1097,7 @@ impl<'a, K> ExactSizeIterator for Iter<'a, K> {
self.iter.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K> FusedIterator for Iter<'a, K> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -1124,7 +1124,7 @@ impl<K> ExactSizeIterator for IntoIter<K> {
self.iter.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<K> FusedIterator for IntoIter<K> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -1155,7 +1155,7 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> {
self.iter.len()
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, K> FusedIterator for Drain<'a, K> {}
#[stable(feature = "std_debug", since = "1.16.0")]
@ -1208,7 +1208,7 @@ impl<'a, T, S> fmt::Debug for Intersection<'a, T, S>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T, S> FusedIterator for Intersection<'a, T, S>
where T: Eq + Hash,
S: BuildHasher
@ -1244,7 +1244,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T, S> FusedIterator for Difference<'a, T, S>
where T: Eq + Hash,
S: BuildHasher
@ -1283,7 +1283,7 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S>
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T, S> FusedIterator for SymmetricDifference<'a, T, S>
where T: Eq + Hash,
S: BuildHasher
@ -1307,7 +1307,7 @@ impl<'a, T, S> Clone for Union<'a, T, S> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a, T, S> FusedIterator for Union<'a, T, S>
where T: Eq + Hash,
S: BuildHasher
@ -1745,7 +1745,7 @@ mod test_set {
#[test]
fn test_retain() {
let xs = [1, 2, 3, 4, 5, 6];
let mut set: HashSet<isize> = xs.iter().cloned().collect();
let mut set: HashSet<i32> = xs.iter().cloned().collect();
set.retain(|&k| k % 2 == 0);
assert_eq!(set.len(), 3);
assert!(set.contains(&2));

View File

@ -875,6 +875,8 @@ impl CStr {
/// `ptr`.
/// * There is no guarantee that the memory pointed to by `ptr` contains a
/// valid nul terminator byte at the end of the string.
/// * It is not guaranteed that the memory pointed by `ptr` won't change
/// before the `CStr` has been destroyed.
///
/// > **Note**: This operation is intended to be a 0-cost cast but it is
/// > currently implemented with an up-front calculation of the length of

View File

@ -266,7 +266,6 @@
#![feature(float_from_str_radix)]
#![feature(fn_traits)]
#![feature(fnbox)]
#![feature(fused)]
#![feature(generic_param_attrs)]
#![feature(hashmap_hasher)]
#![feature(heap_api)]

View File

@ -905,7 +905,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for Iter<'a> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1008,7 +1008,7 @@ impl<'a> DoubleEndedIterator for Components<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for Components<'a> {}
#[stable(feature = "rust1", since = "1.0.0")]
@ -1076,7 +1076,7 @@ impl<'a> Iterator for Ancestors<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[unstable(feature = "path_ancestors", issue = "48581")]
impl<'a> FusedIterator for Ancestors<'a> {}
////////////////////////////////////////////////////////////////////////////////

View File

@ -428,20 +428,15 @@ impl fmt::Debug for Wtf8 {
formatter.write_str("\"")?;
let mut pos = 0;
loop {
match self.next_surrogate(pos) {
None => break,
Some((surrogate_pos, surrogate)) => {
write_str_escaped(
formatter,
unsafe { str::from_utf8_unchecked(
&self.bytes[pos .. surrogate_pos]
)},
)?;
write!(formatter, "\\u{{{:x}}}", surrogate)?;
pos = surrogate_pos + 3;
}
}
while let Some((surrogate_pos, surrogate)) = self.next_surrogate(pos) {
write_str_escaped(
formatter,
unsafe { str::from_utf8_unchecked(
&self.bytes[pos .. surrogate_pos]
)},
)?;
write!(formatter, "\\u{{{:x}}}", surrogate)?;
pos = surrogate_pos + 3;
}
write_str_escaped(
formatter,

View File

@ -70,7 +70,7 @@ impl Iterator for ToLowercase {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for ToLowercase {}
/// Returns an iterator that yields the uppercase equivalent of a `char`.
@ -92,7 +92,7 @@ impl Iterator for ToUppercase {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl FusedIterator for ToUppercase {}
#[derive(Debug, Clone)]

View File

@ -36,7 +36,6 @@
#![feature(str_internals)]
#![feature(decode_utf8)]
#![feature(fn_traits)]
#![feature(fused)]
#![feature(lang_items)]
#![feature(non_exhaustive)]
#![feature(staged_api)]

View File

@ -127,7 +127,6 @@ impl<I> Iterator for Utf16Encoder<I>
}
}
#[unstable(feature = "fused", issue = "35602")]
impl<I> FusedIterator for Utf16Encoder<I>
where I: FusedIterator<Item = char> {}
@ -186,5 +185,5 @@ impl<'a> DoubleEndedIterator for SplitWhitespace<'a> {
}
}
#[unstable(feature = "fused", issue = "35602")]
#[stable(feature = "fused", since = "1.26.0")]
impl<'a> FusedIterator for SplitWhitespace<'a> {}

View File

@ -132,6 +132,18 @@ impl<'a> StringReader<'a> {
self.advance_token()?;
Ok(ret_val)
}
fn fail_unterminated_raw_string(&self, pos: BytePos, hash_count: usize) {
let mut err = self.struct_span_fatal(pos, pos, "unterminated raw string");
err.span_label(self.mk_sp(pos, pos), "unterminated raw string");
if hash_count > 0 {
err.note(&format!("this raw string should be terminated with `\"{}`",
"#".repeat(hash_count)));
}
err.emit();
FatalError.raise();
}
fn fatal(&self, m: &str) -> FatalError {
self.fatal_span(self.peek_span, m)
}
@ -269,6 +281,15 @@ impl<'a> StringReader<'a> {
Self::push_escaped_char_for_msg(&mut m, c);
self.fatal_span_(from_pos, to_pos, &m[..])
}
fn struct_span_fatal(&self,
from_pos: BytePos,
to_pos: BytePos,
m: &str)
-> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), m)
}
fn struct_fatal_span_char(&self,
from_pos: BytePos,
to_pos: BytePos,
@ -1404,8 +1425,7 @@ impl<'a> StringReader<'a> {
}
if self.is_eof() {
let last_bpos = self.pos;
self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise();
self.fail_unterminated_raw_string(start_bpos, hash_count);
} else if !self.ch_is('"') {
let last_bpos = self.pos;
let curr_char = self.ch.unwrap();
@ -1421,8 +1441,7 @@ impl<'a> StringReader<'a> {
let mut valid = true;
'outer: loop {
if self.is_eof() {
let last_bpos = self.pos;
self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise();
self.fail_unterminated_raw_string(start_bpos, hash_count);
}
// if self.ch_is('"') {
// content_end_bpos = self.pos;
@ -1636,8 +1655,7 @@ impl<'a> StringReader<'a> {
}
if self.is_eof() {
let pos = self.pos;
self.fatal_span_(start_bpos, pos, "unterminated raw string").raise();
self.fail_unterminated_raw_string(start_bpos, hash_count);
} else if !self.ch_is('"') {
let pos = self.pos;
let ch = self.ch.unwrap();
@ -1653,8 +1671,7 @@ impl<'a> StringReader<'a> {
'outer: loop {
match self.ch {
None => {
let pos = self.pos;
self.fatal_span_(start_bpos, pos, "unterminated raw string").raise()
self.fail_unterminated_raw_string(start_bpos, hash_count);
}
Some('"') => {
content_end_bpos = self.pos;

View File

@ -3114,7 +3114,7 @@ impl<'a> Parser<'a> {
let expr_str = self.sess.codemap().span_to_snippet(expr.span)
.unwrap_or(pprust::expr_to_string(&expr));
err.span_suggestion(expr.span,
&format!("try {} the casted value", op_verb),
&format!("try {} the cast value", op_verb),
format!("({})", expr_str));
err.emit();

View File

@ -732,18 +732,13 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
let mut parser = parse::Parser::new(fmt_str);
let mut pieces = vec![];
loop {
match parser.next() {
Some(mut piece) => {
if !parser.errors.is_empty() {
break;
}
cx.verify_piece(&piece);
cx.resolve_name_inplace(&mut piece);
pieces.push(piece);
}
None => break,
while let Some(mut piece) = parser.next() {
if !parser.errors.is_empty() {
break;
}
cx.verify_piece(&piece);
cx.resolve_name_inplace(&mut piece);
pieces.push(piece);
}
let numbered_position_args = pieces.iter().any(|arg: &parse::Piece| {

View File

@ -322,12 +322,7 @@ impl Span {
pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
let mut prev_span = DUMMY_SP;
let mut result = vec![];
loop {
let info = match self.ctxt().outer().expn_info() {
Some(info) => info,
None => break,
};
while let Some(info) = self.ctxt().outer().expn_info() {
let (pre, post) = match info.callee.format {
ExpnFormat::MacroAttribute(..) => ("#[", "]"),
ExpnFormat::MacroBang(..) => ("", "!"),

View File

@ -18,7 +18,6 @@
// ignore-hexagon
// ignore-mips
// ignore-powerpc
// ignore-powerpc64
// ignore-s390x
// ignore-sparc
// ignore-wasm32

View File

@ -25,8 +25,6 @@
// ignore-mips64
// ignore-mips64el
// ignore-msp430
// ignore-powerpc64
// ignore-powerpc64le
// ignore-powerpc
// ignore-r600
// ignore-amdgcn

View File

@ -21,8 +21,6 @@
// ignore-mips64
// ignore-mips64el
// ignore-msp430
// ignore-powerpc64
// ignore-powerpc64le
// ignore-powerpc
// ignore-r600
// ignore-amdgcn

View File

@ -21,8 +21,6 @@
// ignore-mips64
// ignore-mips64el
// ignore-msp430
// ignore-powerpc64
// ignore-powerpc64le
// ignore-powerpc
// ignore-r600
// ignore-amdgcn

View File

@ -21,8 +21,6 @@
// ignore-mips64
// ignore-mips64el
// ignore-msp430
// ignore-powerpc64
// ignore-powerpc64le
// ignore-powerpc
// ignore-r600
// ignore-amdgcn

View File

@ -14,7 +14,6 @@
// ignore-mips
// ignore-mips64
// ignore-powerpc
// ignore-powerpc64
// See repr-transparent.rs
#![crate_type="lib"]

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that pointers to extern types can be casted from/to usize,
// Test that pointers to extern types can be cast from/to usize,
// despite being !Sized.
#![feature(extern_types)]

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(intrinsics)]
#![feature(intrinsics, i128_type)]
mod rusti {
extern "rust-intrinsic" {
@ -18,6 +18,7 @@ mod rusti {
pub fn cttz<T>(x: T) -> T;
pub fn cttz_nonzero<T>(x: T) -> T;
pub fn bswap<T>(x: T) -> T;
pub fn bitreverse<T>(x: T) -> T;
}
}
@ -29,106 +30,127 @@ pub fn main() {
assert_eq!(ctpop(0u16), 0); assert_eq!(ctpop(0i16), 0);
assert_eq!(ctpop(0u32), 0); assert_eq!(ctpop(0i32), 0);
assert_eq!(ctpop(0u64), 0); assert_eq!(ctpop(0i64), 0);
assert_eq!(ctpop(0u128), 0); assert_eq!(ctpop(0i128), 0);
assert_eq!(ctpop(1u8), 1); assert_eq!(ctpop(1i8), 1);
assert_eq!(ctpop(1u16), 1); assert_eq!(ctpop(1i16), 1);
assert_eq!(ctpop(1u32), 1); assert_eq!(ctpop(1i32), 1);
assert_eq!(ctpop(1u64), 1); assert_eq!(ctpop(1i64), 1);
assert_eq!(ctpop(1u128), 1); assert_eq!(ctpop(1i128), 1);
assert_eq!(ctpop(10u8), 2); assert_eq!(ctpop(10i8), 2);
assert_eq!(ctpop(10u16), 2); assert_eq!(ctpop(10i16), 2);
assert_eq!(ctpop(10u32), 2); assert_eq!(ctpop(10i32), 2);
assert_eq!(ctpop(10u64), 2); assert_eq!(ctpop(10i64), 2);
assert_eq!(ctpop(10u128), 2); assert_eq!(ctpop(10i128), 2);
assert_eq!(ctpop(100u8), 3); assert_eq!(ctpop(100i8), 3);
assert_eq!(ctpop(100u16), 3); assert_eq!(ctpop(100i16), 3);
assert_eq!(ctpop(100u32), 3); assert_eq!(ctpop(100i32), 3);
assert_eq!(ctpop(100u64), 3); assert_eq!(ctpop(100i64), 3);
assert_eq!(ctpop(100u128), 3); assert_eq!(ctpop(100i128), 3);
assert_eq!(ctpop(-1i8 as u8), 8); assert_eq!(ctpop(-1i8), 8);
assert_eq!(ctpop(-1i16 as u16), 16); assert_eq!(ctpop(-1i16), 16);
assert_eq!(ctpop(-1i32 as u32), 32); assert_eq!(ctpop(-1i32), 32);
assert_eq!(ctpop(-1i64 as u64), 64); assert_eq!(ctpop(-1i64), 64);
assert_eq!(ctpop(-1i128 as u128), 128); assert_eq!(ctpop(-1i128), 128);
assert_eq!(ctlz(0u8), 8); assert_eq!(ctlz(0i8), 8);
assert_eq!(ctlz(0u16), 16); assert_eq!(ctlz(0i16), 16);
assert_eq!(ctlz(0u32), 32); assert_eq!(ctlz(0i32), 32);
assert_eq!(ctlz(0u64), 64); assert_eq!(ctlz(0i64), 64);
assert_eq!(ctlz(0u128), 128); assert_eq!(ctlz(0i128), 128);
assert_eq!(ctlz(1u8), 7); assert_eq!(ctlz(1i8), 7);
assert_eq!(ctlz(1u16), 15); assert_eq!(ctlz(1i16), 15);
assert_eq!(ctlz(1u32), 31); assert_eq!(ctlz(1i32), 31);
assert_eq!(ctlz(1u64), 63); assert_eq!(ctlz(1i64), 63);
assert_eq!(ctlz(1u128), 127); assert_eq!(ctlz(1i128), 127);
assert_eq!(ctlz(10u8), 4); assert_eq!(ctlz(10i8), 4);
assert_eq!(ctlz(10u16), 12); assert_eq!(ctlz(10i16), 12);
assert_eq!(ctlz(10u32), 28); assert_eq!(ctlz(10i32), 28);
assert_eq!(ctlz(10u64), 60); assert_eq!(ctlz(10i64), 60);
assert_eq!(ctlz(10u128), 124); assert_eq!(ctlz(10i128), 124);
assert_eq!(ctlz(100u8), 1); assert_eq!(ctlz(100i8), 1);
assert_eq!(ctlz(100u16), 9); assert_eq!(ctlz(100i16), 9);
assert_eq!(ctlz(100u32), 25); assert_eq!(ctlz(100i32), 25);
assert_eq!(ctlz(100u64), 57); assert_eq!(ctlz(100i64), 57);
assert_eq!(ctlz(100u128), 121); assert_eq!(ctlz(100i128), 121);
assert_eq!(ctlz_nonzero(1u8), 7); assert_eq!(ctlz_nonzero(1i8), 7);
assert_eq!(ctlz_nonzero(1u16), 15); assert_eq!(ctlz_nonzero(1i16), 15);
assert_eq!(ctlz_nonzero(1u32), 31); assert_eq!(ctlz_nonzero(1i32), 31);
assert_eq!(ctlz_nonzero(1u64), 63); assert_eq!(ctlz_nonzero(1i64), 63);
assert_eq!(ctlz_nonzero(1u128), 127); assert_eq!(ctlz_nonzero(1i128), 127);
assert_eq!(ctlz_nonzero(10u8), 4); assert_eq!(ctlz_nonzero(10i8), 4);
assert_eq!(ctlz_nonzero(10u16), 12); assert_eq!(ctlz_nonzero(10i16), 12);
assert_eq!(ctlz_nonzero(10u32), 28); assert_eq!(ctlz_nonzero(10i32), 28);
assert_eq!(ctlz_nonzero(10u64), 60); assert_eq!(ctlz_nonzero(10i64), 60);
assert_eq!(ctlz_nonzero(10u128), 124); assert_eq!(ctlz_nonzero(10i128), 124);
assert_eq!(ctlz_nonzero(100u8), 1); assert_eq!(ctlz_nonzero(100i8), 1);
assert_eq!(ctlz_nonzero(100u16), 9); assert_eq!(ctlz_nonzero(100i16), 9);
assert_eq!(ctlz_nonzero(100u32), 25); assert_eq!(ctlz_nonzero(100i32), 25);
assert_eq!(ctlz_nonzero(100u64), 57); assert_eq!(ctlz_nonzero(100i64), 57);
assert_eq!(ctlz_nonzero(100u128), 121); assert_eq!(ctlz_nonzero(100i128), 121);
assert_eq!(cttz(-1i8 as u8), 0); assert_eq!(cttz(-1i8), 0);
assert_eq!(cttz(-1i16 as u16), 0); assert_eq!(cttz(-1i16), 0);
assert_eq!(cttz(-1i32 as u32), 0); assert_eq!(cttz(-1i32), 0);
assert_eq!(cttz(-1i64 as u64), 0); assert_eq!(cttz(-1i64), 0);
assert_eq!(cttz(-1i128 as u128), 0); assert_eq!(cttz(-1i128), 0);
assert_eq!(cttz(0u8), 8); assert_eq!(cttz(0i8), 8);
assert_eq!(cttz(0u16), 16); assert_eq!(cttz(0i16), 16);
assert_eq!(cttz(0u32), 32); assert_eq!(cttz(0i32), 32);
assert_eq!(cttz(0u64), 64); assert_eq!(cttz(0i64), 64);
assert_eq!(cttz(0u128), 128); assert_eq!(cttz(0i128), 128);
assert_eq!(cttz(1u8), 0); assert_eq!(cttz(1i8), 0);
assert_eq!(cttz(1u16), 0); assert_eq!(cttz(1i16), 0);
assert_eq!(cttz(1u32), 0); assert_eq!(cttz(1i32), 0);
assert_eq!(cttz(1u64), 0); assert_eq!(cttz(1i64), 0);
assert_eq!(cttz(1u128), 0); assert_eq!(cttz(1i128), 0);
assert_eq!(cttz(10u8), 1); assert_eq!(cttz(10i8), 1);
assert_eq!(cttz(10u16), 1); assert_eq!(cttz(10i16), 1);
assert_eq!(cttz(10u32), 1); assert_eq!(cttz(10i32), 1);
assert_eq!(cttz(10u64), 1); assert_eq!(cttz(10i64), 1);
assert_eq!(cttz(10u128), 1); assert_eq!(cttz(10i128), 1);
assert_eq!(cttz(100u8), 2); assert_eq!(cttz(100i8), 2);
assert_eq!(cttz(100u16), 2); assert_eq!(cttz(100i16), 2);
assert_eq!(cttz(100u32), 2); assert_eq!(cttz(100i32), 2);
assert_eq!(cttz(100u64), 2); assert_eq!(cttz(100i64), 2);
assert_eq!(cttz(100u128), 2); assert_eq!(cttz(100i128), 2);
assert_eq!(cttz_nonzero(-1i8 as u8), 0); assert_eq!(cttz_nonzero(-1i8), 0);
assert_eq!(cttz_nonzero(-1i16 as u16), 0); assert_eq!(cttz_nonzero(-1i16), 0);
assert_eq!(cttz_nonzero(-1i32 as u32), 0); assert_eq!(cttz_nonzero(-1i32), 0);
assert_eq!(cttz_nonzero(-1i64 as u64), 0); assert_eq!(cttz_nonzero(-1i64), 0);
assert_eq!(cttz_nonzero(-1i128 as u128), 0); assert_eq!(cttz_nonzero(-1i128), 0);
assert_eq!(cttz_nonzero(1u8), 0); assert_eq!(cttz_nonzero(1i8), 0);
assert_eq!(cttz_nonzero(1u16), 0); assert_eq!(cttz_nonzero(1i16), 0);
assert_eq!(cttz_nonzero(1u32), 0); assert_eq!(cttz_nonzero(1i32), 0);
assert_eq!(cttz_nonzero(1u64), 0); assert_eq!(cttz_nonzero(1i64), 0);
assert_eq!(cttz_nonzero(1u128), 0); assert_eq!(cttz_nonzero(1i128), 0);
assert_eq!(cttz_nonzero(10u8), 1); assert_eq!(cttz_nonzero(10i8), 1);
assert_eq!(cttz_nonzero(10u16), 1); assert_eq!(cttz_nonzero(10i16), 1);
assert_eq!(cttz_nonzero(10u32), 1); assert_eq!(cttz_nonzero(10i32), 1);
assert_eq!(cttz_nonzero(10u64), 1); assert_eq!(cttz_nonzero(10i64), 1);
assert_eq!(cttz_nonzero(10u128), 1); assert_eq!(cttz_nonzero(10i128), 1);
assert_eq!(cttz_nonzero(100u8), 2); assert_eq!(cttz_nonzero(100i8), 2);
assert_eq!(cttz_nonzero(100u16), 2); assert_eq!(cttz_nonzero(100i16), 2);
assert_eq!(cttz_nonzero(100u32), 2); assert_eq!(cttz_nonzero(100i32), 2);
assert_eq!(cttz_nonzero(100u64), 2); assert_eq!(cttz_nonzero(100i64), 2);
assert_eq!(cttz_nonzero(100u128), 2); assert_eq!(cttz_nonzero(100i128), 2);
assert_eq!(bswap(0x0Au8), 0x0A); // no-op
assert_eq!(bswap(0x0Ai8), 0x0A); // no-op
@ -138,5 +160,18 @@ pub fn main() {
assert_eq!(bswap(0x0ABBCC0Di32), 0x0DCCBB0A);
assert_eq!(bswap(0x0122334455667708u64), 0x0877665544332201);
assert_eq!(bswap(0x0122334455667708i64), 0x0877665544332201);
assert_eq!(bswap(0x0122334455667708u128), 0x08776655443322010000000000000000);
assert_eq!(bswap(0x0122334455667708i128), 0x08776655443322010000000000000000);
assert_eq!(bitreverse(0x0Au8), 0x50);
assert_eq!(bitreverse(0x0Ai8), 0x50);
assert_eq!(bitreverse(0x0A0Cu16), 0x3050);
assert_eq!(bitreverse(0x0A0Ci16), 0x3050);
assert_eq!(bitreverse(0x0ABBCC0Eu32), 0x7033DD50);
assert_eq!(bitreverse(0x0ABBCC0Ei32), 0x7033DD50);
assert_eq!(bitreverse(0x0122334455667708u64), 0x10EE66AA22CC4480);
assert_eq!(bitreverse(0x0122334455667708i64), 0x10EE66AA22CC4480);
assert_eq!(bitreverse(0x0122334455667708u128), 0x10EE66AA22CC44800000000000000000);
assert_eq!(bitreverse(0x0122334455667708i128), 0x10EE66AA22CC44800000000000000000);
}
}

View File

@ -14,7 +14,6 @@
// `FusedIterator` in std but I was not able to isolate that into an
// external crate.
#![feature(fused)]
use std::iter::FusedIterator;
struct Thing<'a>(&'a str);

View File

@ -12,9 +12,9 @@
fn main() {
const XYZ: char = 0x1F888 as char;
//~^ ERROR only u8 can be casted into char
//~^ ERROR only u8 can be cast into char
const XY: char = 129160 as char;
//~^ ERROR only u8 can be casted into char
//~^ ERROR only u8 can be cast into char
const ZYX: char = '\u{01F888}';
println!("{}", XYZ);
}

View File

@ -1,4 +1,4 @@
error: only u8 can be casted into char
error: only u8 can be cast into char
--> $DIR/cast_char.rs:14:23
|
LL | const XYZ: char = 0x1F888 as char;
@ -10,7 +10,7 @@ note: lint level defined here
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
error: only u8 can be casted into char
error: only u8 can be cast into char
--> $DIR/cast_char.rs:16:22
|
LL | const XY: char = 129160 as char;

View File

@ -5,7 +5,7 @@ LL | println!("{}", a as usize < long_name); //~ ERROR `<` is interpreted as
| ---------- ^ --------- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a as usize)`
| help: try comparing the cast value: `(a as usize)`
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:17:33
@ -14,7 +14,7 @@ LL | println!("{}{}", a as usize < long_name, long_name);
| ---------- ^ -------------------- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a as usize)`
| help: try comparing the cast value: `(a as usize)`
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:19:31
@ -23,7 +23,7 @@ LL | println!("{}", a as usize < 4); //~ ERROR `<` is interpreted as a start
| ---------- ^ - interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a as usize)`
| help: try comparing the cast value: `(a as usize)`
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:21:31
@ -32,7 +32,7 @@ LL | println!("{}{}", a: usize < long_name, long_name);
| -------- ^ -------------------- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a: usize)`
| help: try comparing the cast value: `(a: usize)`
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:23:29
@ -41,7 +41,7 @@ LL | println!("{}", a: usize < 4); //~ ERROR `<` is interpreted as a start o
| -------- ^ - interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a: usize)`
| help: try comparing the cast value: `(a: usize)`
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:28:20
@ -50,7 +50,7 @@ LL | < //~ ERROR `<` is interpreted as a start of generic
| ^ not interpreted as comparison
LL | 4);
| - interpreted as generic arguments
help: try comparing the casted value
help: try comparing the cast value
|
LL | println!("{}", (a
LL | as
@ -64,7 +64,7 @@ LL | < //~ ERROR `<` is interpreted as a start of generic
| ^ not interpreted as comparison
LL | 5);
| - interpreted as generic arguments
help: try comparing the casted value
help: try comparing the cast value
|
LL | println!("{}", (a
LL |
@ -81,7 +81,7 @@ LL | println!("{}", a as usize << long_name); //~ ERROR `<` is interpreted a
| ---------- ^^ --------- interpreted as generic arguments
| | |
| | not interpreted as shift
| help: try shifting the casted value: `(a as usize)`
| help: try shifting the cast value: `(a as usize)`
error: expected type, found `4`
--> $DIR/issue-22644.rs:42:28

View File

@ -5,7 +5,7 @@ LL | $i as u32 < 0 //~ `<` is interpreted as a start of generic argument
| --------- ^ - interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `($i as u32)`
| help: try comparing the cast value: `($i as u32)`
...
LL | is_plainly_printable!(c);
| ------------------------- in this macro invocation

View File

@ -0,0 +1,33 @@
// Copyright 2018 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.
// must-compile-successfully
#![feature(i128_type)]
fn main() {
let error = 255i8; //~WARNING literal out of range for i8
let ok = 0b1000_0001; // should be ok -> i32
let ok = 0b0111_1111i8; // should be ok -> 127i8
let fail = 0b1000_0001i8; //~WARNING literal out of range for i8
let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64
let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32
let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
//~^ WARNING literal out of range for i128
let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32
let fail = -0b1111_1111i8; //~WARNING literal out of range for i8
}

View File

@ -0,0 +1,58 @@
warning: literal out of range for i8
--> $DIR/type-overflow.rs:16:17
|
LL | let error = 255i8; //~WARNING literal out of range for i8
| ^^^^^
|
= note: #[warn(overflowing_literals)] on by default
warning: literal out of range for i8
--> $DIR/type-overflow.rs:21:16
|
LL | let fail = 0b1000_0001i8; //~WARNING literal out of range for i8
| ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1000_0001u8`
|
= note: the literal `0b1000_0001i8` (decimal `129`) does not fit into an `i8` and will become `-127i8`
warning: literal out of range for i64
--> $DIR/type-overflow.rs:23:16
|
LL | let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x8000_0000_0000_0000u64`
|
= note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into an `i64` and will become `-9223372036854775808i64`
warning: literal out of range for u32
--> $DIR/type-overflow.rs:25:16
|
LL | let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32
| ^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x1_FFFF_FFFFu64`
|
= note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into an `u32` and will become `4294967295u32`
warning: literal out of range for i128
--> $DIR/type-overflow.rs:27:22
|
LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into an `i128` and will become `-170141183460469231731687303715884105728i128`
= help: consider using `u128` instead
warning: literal out of range for i32
--> $DIR/type-overflow.rs:30:16
|
LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into an `i32` and will become `-2i32`
= help: consider using `i128` instead
warning: literal out of range for i8
--> $DIR/type-overflow.rs:32:17
|
LL | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8
| ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16`
|
= note: the literal `0b1111_1111i8` (decimal `255`) does not fit into an `i8` and will become `-1i8`

14
src/test/ui/raw_string.rs Normal file
View File

@ -0,0 +1,14 @@
// Copyright 2018 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.
fn main() {
let x = r##"lol"#;
//~^ ERROR unterminated raw string
}

View File

@ -0,0 +1,8 @@
error: unterminated raw string
--> $DIR/raw_string.rs:12:13
|
LL | let x = r##"lol"#;
| ^ unterminated raw string
|
= note: this raw string should be terminated with `"##`

View File

@ -43,7 +43,6 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
("mips", "mips"),
("msp430", "msp430"),
("powerpc", "powerpc"),
("powerpc64", "powerpc64"),
("s390x", "s390x"),
("sparc", "sparc"),
("x86_64", "x86_64"),