eplace usages of vec![].into_iter with [].into_iter

This commit is contained in:
Lucas Kent 2021-12-17 18:36:18 +11:00
parent 23ce5fc465
commit 08829853d3
36 changed files with 116 additions and 122 deletions

View File

@ -791,7 +791,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
)));
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
vec![try_fn_ty, i8p, catch_fn_ty].into_iter(),
[try_fn_ty, i8p, catch_fn_ty].into_iter(),
tcx.types.i32,
false,
hir::Unsafety::Unsafe,

View File

@ -10,8 +10,8 @@ impl<T> ThinVec<T> {
fn test_from_iterator() {
assert_eq!(std::iter::empty().collect::<ThinVec<String>>().into_vec(), Vec::<String>::new());
assert_eq!(std::iter::once(42).collect::<ThinVec<_>>().into_vec(), vec![42]);
assert_eq!(vec![1, 2].into_iter().collect::<ThinVec<_>>().into_vec(), vec![1, 2]);
assert_eq!(vec![1, 2, 3].into_iter().collect::<ThinVec<_>>().into_vec(), vec![1, 2, 3]);
assert_eq!([1, 2].into_iter().collect::<ThinVec<_>>().into_vec(), vec![1, 2]);
assert_eq!([1, 2, 3].into_iter().collect::<ThinVec<_>>().into_vec(), vec![1, 2, 3]);
}
#[test]

View File

@ -14,7 +14,7 @@ fn test_from_iterator() {
);
assert_eq!(std::iter::once((42, true)).collect::<VecMap<_, _>>().into_vec(), vec![(42, true)]);
assert_eq!(
vec![(1, true), (2, false)].into_iter().collect::<VecMap<_, _>>().into_vec(),
[(1, true), (2, false)].into_iter().collect::<VecMap<_, _>>().into_vec(),
vec![(1, true), (2, false)]
);
}
@ -41,7 +41,7 @@ fn test_insert() {
#[test]
fn test_get() {
let v = vec![(1, true), (2, false)].into_iter().collect::<VecMap<_, _>>();
let v = [(1, true), (2, false)].into_iter().collect::<VecMap<_, _>>();
assert_eq!(v.get(&1), Some(&true));
assert_eq!(v.get(&2), Some(&false));
assert_eq!(v.get(&3), None);

View File

@ -455,7 +455,7 @@ impl DiagnosticSpan {
let backtrace_step = backtrace.next().map(|bt| {
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
let def_site_span =
Self::from_span_full(bt.def_site, false, None, None, vec![].into_iter(), je);
Self::from_span_full(bt.def_site, false, None, None, [].into_iter(), je);
Box::new(DiagnosticSpanMacroExpansion {
span: call_site,
macro_decl_name: bt.kind.descr(),

View File

@ -158,7 +158,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
for ch in data.as_str().chars() {
escaped.extend(ch.escape_debug());
}
let stream = vec![
let stream = [
Ident(sym::doc, false),
Eq,
TokenKind::lit(token::Str, Symbol::intern(&escaped), None),
@ -221,7 +221,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
let integer = TokenKind::lit(token::Integer, symbol, suffix);
let a = tokenstream::TokenTree::token(minus, span);
let b = tokenstream::TokenTree::token(integer, span);
return vec![a, b].into_iter().collect();
return [a, b].into_iter().collect();
}
TokenTree::Literal(self::Literal {
lit: token::Lit { kind: token::Float, symbol, suffix },
@ -232,7 +232,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
let float = TokenKind::lit(token::Float, symbol, suffix);
let a = tokenstream::TokenTree::token(minus, span);
let b = tokenstream::TokenTree::token(float, span);
return vec![a, b].into_iter().collect();
return [a, b].into_iter().collect();
}
TokenTree::Literal(self::Literal { lit, span }) => {
return tokenstream::TokenTree::token(Literal(lit), span).into();

View File

@ -56,7 +56,7 @@ impl NodeLabels<&'static str> {
match self {
UnlabelledNodes(len) => vec![None; len],
AllNodesLabelled(lbls) => lbls.into_iter().map(Some).collect(),
SomeNodesLabelled(lbls) => lbls.into_iter().collect(),
SomeNodesLabelled(lbls) => lbls,
}
}

View File

@ -13,7 +13,7 @@ fn test_all_except_most_recent() {
.keys()
.cloned()
.collect::<FxHashSet<PathBuf>>(),
vec![PathBuf::from("1"), PathBuf::from("2"), PathBuf::from("3"), PathBuf::from("4"),]
[PathBuf::from("1"), PathBuf::from("2"), PathBuf::from("3"), PathBuf::from("4"),]
.into_iter()
.collect::<FxHashSet<PathBuf>>()
);
@ -40,7 +40,7 @@ fn test_find_source_directory_in_iter() {
// Find newest
assert_eq!(
find_source_directory_in_iter(
vec![
[
PathBuf::from("crate-dir/s-3234-0000-svh"),
PathBuf::from("crate-dir/s-2234-0000-svh"),
PathBuf::from("crate-dir/s-1234-0000-svh")
@ -54,7 +54,7 @@ fn test_find_source_directory_in_iter() {
// Filter out "-working"
assert_eq!(
find_source_directory_in_iter(
vec![
[
PathBuf::from("crate-dir/s-3234-0000-working"),
PathBuf::from("crate-dir/s-2234-0000-svh"),
PathBuf::from("crate-dir/s-1234-0000-svh")
@ -66,12 +66,12 @@ fn test_find_source_directory_in_iter() {
);
// Handle empty
assert_eq!(find_source_directory_in_iter(vec![].into_iter(), &already_visited), None);
assert_eq!(find_source_directory_in_iter([].into_iter(), &already_visited), None);
// Handle only working
assert_eq!(
find_source_directory_in_iter(
vec![
[
PathBuf::from("crate-dir/s-3234-0000-working"),
PathBuf::from("crate-dir/s-2234-0000-working"),
PathBuf::from("crate-dir/s-1234-0000-working")

View File

@ -771,7 +771,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.suggest_boxing_for_return_impl_trait(
err,
ret_sp,
vec![then, else_sp].into_iter(),
[then, else_sp].into_iter(),
);
}
}
@ -807,11 +807,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
let sugg = arm_spans
.flat_map(|sp| {
vec![
(sp.shrink_to_lo(), "Box::new(".to_string()),
(sp.shrink_to_hi(), ")".to_string()),
]
.into_iter()
[(sp.shrink_to_lo(), "Box::new(".to_string()), (sp.shrink_to_hi(), ")".to_string())]
.into_iter()
})
.collect::<Vec<_>>();
err.multipart_suggestion(

View File

@ -540,8 +540,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// error[E0284]: type annotations needed
// --> file.rs:2:5
// |
// 2 | vec![Ok(2)].into_iter().collect()?;
// | ^^^^^^^ cannot infer type
// 2 | [Ok(2)].into_iter().collect()?;
// | ^^^^^^^ cannot infer type
// |
// = note: cannot resolve `<_ as std::ops::Try>::Ok == _`
if span.contains(*call_span) { *call_span } else { span }

View File

@ -550,8 +550,8 @@ impl<'a> Parser<'a> {
/// a diagnostic to suggest removing them.
///
/// ```ignore (diagnostic)
/// let _ = vec![1, 2, 3].into_iter().collect::<Vec<usize>>>>();
/// ^^ help: remove extra angle brackets
/// let _ = [1, 2, 3].into_iter().collect::<Vec<usize>>>>();
/// ^^ help: remove extra angle brackets
/// ```
///
/// If `true` is returned, then trailing brackets were recovered, tokens were consumed

View File

@ -17,12 +17,10 @@ pub fn target(target_cpu: String) -> Target {
linker: Some("avr-gcc".to_owned()),
executables: true,
eh_frame_header: false,
pre_link_args: vec![(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu)])]
.into_iter()
.collect(),
late_link_args: vec![(LinkerFlavor::Gcc, vec!["-lgcc".to_owned()])]
pre_link_args: [(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu)])]
.into_iter()
.collect(),
late_link_args: [(LinkerFlavor::Gcc, vec!["-lgcc".to_owned()])].into_iter().collect(),
max_atomic_width: Some(0),
atomic_cas: false,
..TargetOptions::default()

View File

@ -574,15 +574,15 @@ impl ToJson for StackProbeType {
fn to_json(&self) -> Json {
Json::Object(match self {
StackProbeType::None => {
vec![(String::from("kind"), "none".to_json())].into_iter().collect()
[(String::from("kind"), "none".to_json())].into_iter().collect()
}
StackProbeType::Inline => {
vec![(String::from("kind"), "inline".to_json())].into_iter().collect()
[(String::from("kind"), "inline".to_json())].into_iter().collect()
}
StackProbeType::Call => {
vec![(String::from("kind"), "call".to_json())].into_iter().collect()
[(String::from("kind"), "call".to_json())].into_iter().collect()
}
StackProbeType::InlineOrCall { min_llvm_version_for_inline } => vec![
StackProbeType::InlineOrCall { min_llvm_version_for_inline } => [
(String::from("kind"), "inline-or-call".to_json()),
(
String::from("min-llvm-version-for-inline"),

View File

@ -2247,7 +2247,7 @@ pub fn recursive_type_with_infinite_size_error(
spans
.iter()
.flat_map(|&span| {
vec![
[
(span.shrink_to_lo(), "Box<".to_string()),
(span.shrink_to_hi(), ">".to_string()),
]

View File

@ -1226,7 +1226,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
.returns
.iter()
.flat_map(|expr| {
vec![
[
(expr.span.shrink_to_lo(), "Box::new(".to_string()),
(expr.span.shrink_to_hi(), ")".to_string()),
]

View File

@ -1953,7 +1953,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Generator(_, ref substs, _) => {
let ty = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
let witness = substs.as_generator().witness();
t.rebind(vec![ty].into_iter().chain(iter::once(witness)).collect())
t.rebind([ty].into_iter().chain(iter::once(witness)).collect())
}
ty::GeneratorWitness(types) => {

View File

@ -1667,10 +1667,10 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
],
Applicability::MachineApplicable,
);
let sugg = vec![sp, cause.span]
let sugg = [sp, cause.span]
.into_iter()
.flat_map(|sp| {
vec![
[
(sp.shrink_to_lo(), "Box::new(".to_string()),
(sp.shrink_to_hi(), ")".to_string()),
]

View File

@ -86,7 +86,7 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
fn lang_items(tcx: TyCtxt<'_>) -> Vec<(hir::HirId, Vec<ty::Variance>)> {
let lang_items = tcx.lang_items();
let all = vec![
let all = [
(lang_items.phantom_data(), vec![ty::Covariant]),
(lang_items.unsafe_cell_type(), vec![ty::Invariant]),
];

View File

@ -728,7 +728,7 @@ fn test_range_large() {
#[test]
fn test_range_inclusive_max_value() {
let max = usize::MAX;
let map: BTreeMap<_, _> = vec![(max, 0)].into_iter().collect();
let map: BTreeMap<_, _> = [(max, 0)].into_iter().collect();
assert_eq!(map.range(max..=max).collect::<Vec<_>>(), &[(&max, &0)]);
}
@ -2128,7 +2128,7 @@ fn test_into_iter_drop_leak_height_1() {
#[test]
fn test_into_keys() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let vec = [(1, 'a'), (2, 'b'), (3, 'c')];
let map: BTreeMap<_, _> = vec.into_iter().collect();
let keys: Vec<_> = map.into_keys().collect();

View File

@ -669,7 +669,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut buf: VecDeque<i32> = vec![1].into_iter().collect();
/// let mut buf: VecDeque<i32> = [1].into_iter().collect();
/// buf.reserve_exact(10);
/// assert!(buf.capacity() >= 11);
/// ```
@ -692,7 +692,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut buf: VecDeque<i32> = vec![1].into_iter().collect();
/// let mut buf: VecDeque<i32> = [1].into_iter().collect();
/// buf.reserve(10);
/// assert!(buf.capacity() >= 11);
/// ```
@ -1153,7 +1153,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
/// let v: VecDeque<_> = [1, 2, 3].into_iter().collect();
/// let range = v.range(2..).copied().collect::<VecDeque<_>>();
/// assert_eq!(range, [3]);
///
@ -1188,7 +1188,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
/// let mut v: VecDeque<_> = [1, 2, 3].into_iter().collect();
/// for v in v.range_mut(2..) {
/// *v *= 2;
/// }
@ -1235,7 +1235,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
/// let mut v: VecDeque<_> = [1, 2, 3].into_iter().collect();
/// let drained = v.drain(2..).collect::<VecDeque<_>>();
/// assert_eq!(drained, [3]);
/// assert_eq!(v, [1, 2]);
@ -2025,7 +2025,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut buf: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
/// let mut buf: VecDeque<_> = [1, 2, 3].into_iter().collect();
/// let buf2 = buf.split_off(1);
/// assert_eq!(buf, [1]);
/// assert_eq!(buf2, [2, 3]);
@ -2091,8 +2091,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut buf: VecDeque<_> = vec![1, 2].into_iter().collect();
/// let mut buf2: VecDeque<_> = vec![3, 4].into_iter().collect();
/// let mut buf: VecDeque<_> = [1, 2].into_iter().collect();
/// let mut buf2: VecDeque<_> = [3, 4].into_iter().collect();
/// buf.append(&mut buf2);
/// assert_eq!(buf, [1, 2, 3, 4]);
/// assert_eq!(buf2, []);

View File

@ -304,7 +304,7 @@ fn test_show() {
let list: LinkedList<_> = (0..10).collect();
assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect();
let list: LinkedList<_> = ["just", "one", "test", "more"].into_iter().collect();
assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]");
}
@ -336,7 +336,7 @@ fn test_extend() {
assert_eq!(a.len(), 4);
assert!(a.iter().eq(&[1, 2, 3, 4]));
let b: LinkedList<_> = vec![5, 6, 7].into_iter().collect();
let b: LinkedList<_> = [5, 6, 7].into_iter().collect();
a.extend(b); // specializes to `append`
assert_eq!(a.len(), 7);
@ -375,7 +375,7 @@ fn drain_filter_empty() {
#[test]
fn drain_filter_zst() {
let mut list: LinkedList<_> = vec![(), (), (), (), ()].into_iter().collect();
let mut list: LinkedList<_> = [(), (), (), (), ()].into_iter().collect();
let initial_len = list.len();
let mut count = 0;
@ -398,7 +398,7 @@ fn drain_filter_zst() {
#[test]
fn drain_filter_false() {
let mut list: LinkedList<_> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let mut list: LinkedList<_> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let initial_len = list.len();
let mut count = 0;
@ -421,7 +421,7 @@ fn drain_filter_false() {
#[test]
fn drain_filter_true() {
let mut list: LinkedList<_> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let mut list: LinkedList<_> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let initial_len = list.len();
let mut count = 0;
@ -447,7 +447,7 @@ fn drain_filter_true() {
fn drain_filter_complex() {
{
// [+xxx++++++xxxxx++++x+x++]
let mut list = vec![
let mut list = [
1, 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37,
39,
]
@ -467,11 +467,10 @@ fn drain_filter_complex() {
{
// [xxx++++++xxxxx++++x+x++]
let mut list = vec![
2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 39,
]
.into_iter()
.collect::<LinkedList<_>>();
let mut list =
[2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 39]
.into_iter()
.collect::<LinkedList<_>>();
let removed = list.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>();
assert_eq!(removed.len(), 10);
@ -487,7 +486,7 @@ fn drain_filter_complex() {
{
// [xxx++++++xxxxx++++x+x]
let mut list =
vec![2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36]
[2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36]
.into_iter()
.collect::<LinkedList<_>>();
@ -504,7 +503,7 @@ fn drain_filter_complex() {
{
// [xxxxxxxxxx+++++++++++]
let mut list = vec![2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
let mut list = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
.into_iter()
.collect::<LinkedList<_>>();
@ -518,7 +517,7 @@ fn drain_filter_complex() {
{
// [+++++++++++xxxxxxxxxx]
let mut list = vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
let mut list = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
.into_iter()
.collect::<LinkedList<_>>();

View File

@ -489,7 +489,7 @@ fn test_from_iterator() {
b.extend(u.chars());
assert_eq!(s, b);
let c: String = vec![t, u].into_iter().collect();
let c: String = [t, u].into_iter().collect();
assert_eq!(s, c);
let mut d = t.to_string();

View File

@ -449,10 +449,10 @@ fn zero_sized_values() {
#[test]
fn test_partition() {
assert_eq!(vec![].into_iter().partition(|x: &i32| *x < 3), (vec![], vec![]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 4), (vec![1, 2, 3], vec![]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 2), (vec![1], vec![2, 3]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 0), (vec![], vec![1, 2, 3]));
assert_eq!([].into_iter().partition(|x: &i32| *x < 3), (vec![], vec![]));
assert_eq!([1, 2, 3].into_iter().partition(|x| *x < 4), (vec![1, 2, 3], vec![]));
assert_eq!([1, 2, 3].into_iter().partition(|x| *x < 2), (vec![1], vec![2, 3]));
assert_eq!([1, 2, 3].into_iter().partition(|x| *x < 0), (vec![], vec![1, 2, 3]));
}
#[test]
@ -924,7 +924,7 @@ fn test_into_iter_debug() {
#[test]
fn test_into_iter_count() {
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
assert_eq!([1, 2, 3].into_iter().count(), 3);
}
#[test]
@ -933,7 +933,7 @@ fn test_into_iter_clone() {
let v: Vec<i32> = it.collect();
assert_eq!(&v[..], slice);
}
let mut it = vec![1, 2, 3].into_iter();
let mut it = [1, 2, 3].into_iter();
iter_equal(it.clone(), &[1, 2, 3]);
assert_eq!(it.next(), Some(1));
let mut it = it.rev();
@ -972,7 +972,7 @@ fn test_into_iter_leak() {
#[test]
fn test_into_iter_advance_by() {
let mut i = vec![1, 2, 3, 4, 5].into_iter();
let mut i = [1, 2, 3, 4, 5].into_iter();
i.advance_by(0).unwrap();
i.advance_back_by(0).unwrap();
assert_eq!(i.as_slice(), [1, 2, 3, 4, 5]);
@ -1799,7 +1799,7 @@ fn test_stable_pointers() {
assert_eq!(*v0, 13);
next_then_drop(v.splice(5..8, vec![1])); // replacement is smaller than original range
assert_eq!(*v0, 13);
next_then_drop(v.splice(5..6, vec![1; 10].into_iter().filter(|_| true))); // lower bound not exact
next_then_drop(v.splice(5..6, [1; 10].into_iter().filter(|_| true))); // lower bound not exact
assert_eq!(*v0, 13);
// spare_capacity_mut

View File

@ -927,8 +927,8 @@ fn test_as_mut_slices() {
#[test]
fn test_append() {
let mut a: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
let mut b: VecDeque<_> = vec![4, 5, 6].into_iter().collect();
let mut a: VecDeque<_> = [1, 2, 3].into_iter().collect();
let mut b: VecDeque<_> = [4, 5, 6].into_iter().collect();
// normal append
a.append(&mut b);
@ -1209,7 +1209,7 @@ fn test_try_reserve() {
{
// Same basic idea, but with non-zero len
let mut ten_bytes: VecDeque<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let mut ten_bytes: VecDeque<u8> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 10).map_err(|e| e.kind()) {
panic!("isize::MAX shouldn't trigger an overflow!");
@ -1240,7 +1240,7 @@ fn test_try_reserve() {
{
// Same basic idea, but with interesting type size
let mut ten_u32s: VecDeque<u32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let mut ten_u32s: VecDeque<u32> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 10).map_err(|e| e.kind())
{
@ -1322,7 +1322,7 @@ fn test_try_reserve_exact() {
}
{
let mut ten_bytes: VecDeque<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let mut ten_bytes: VecDeque<u8> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
if let Err(CapacityOverflow) =
ten_bytes.try_reserve_exact(MAX_CAP - 10).map_err(|e| e.kind())
@ -1355,7 +1355,7 @@ fn test_try_reserve_exact() {
}
{
let mut ten_u32s: VecDeque<u32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
let mut ten_u32s: VecDeque<u32> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect();
if let Err(CapacityOverflow) =
ten_u32s.try_reserve_exact(MAX_CAP / 4 - 10).map_err(|e| e.kind())

View File

@ -91,7 +91,7 @@ pub use num::FloatToInt;
/// ```rust
/// use std::convert::identity;
///
/// let iter = vec![Some(1), None, Some(3)].into_iter();
/// let iter = [Some(1), None, Some(3)].into_iter();
/// let filtered = iter.filter_map(identity).collect::<Vec<_>>();
/// assert_eq!(vec![1, 3], filtered);
/// ```

View File

@ -19,7 +19,7 @@ use crate::ops::Try;
/// you can also [`map`] backwards:
///
/// ```rust
/// let v: Vec<i32> = vec![1, 2, 3].into_iter().map(|x| x + 1).rev().collect();
/// let v: Vec<i32> = [1, 2, 3].into_iter().map(|x| x + 1).rev().collect();
///
/// assert_eq!(v, [4, 3, 2]);
/// ```
@ -32,7 +32,7 @@ use crate::ops::Try;
/// ```rust
/// let mut c = 0;
///
/// for pair in vec!['a', 'b', 'c'].into_iter()
/// for pair in ['a', 'b', 'c'].into_iter()
/// .map(|letter| { c += 1; (letter, c) }) {
/// println!("{:?}", pair);
/// }
@ -49,7 +49,7 @@ use crate::ops::Try;
/// ```rust
/// let mut c = 0;
///
/// for pair in vec!['a', 'b', 'c'].into_iter()
/// for pair in ['a', 'b', 'c'].into_iter()
/// .map(|letter| { c += 1; (letter, c) })
/// .rev() {
/// println!("{:?}", pair);

View File

@ -124,7 +124,7 @@ pub trait FromIterator<A>: Sized {
/// Basic usage:
///
/// ```
/// let v = vec![1, 2, 3];
/// let v = [1, 2, 3];
/// let mut iter = v.into_iter();
///
/// assert_eq!(Some(1), iter.next());
@ -215,7 +215,7 @@ pub trait IntoIterator {
/// Basic usage:
///
/// ```
/// let v = vec![1, 2, 3];
/// let v = [1, 2, 3];
/// let mut iter = v.into_iter();
///
/// assert_eq!(Some(1), iter.next());

View File

@ -590,7 +590,7 @@ pub trait Iterator {
/// #[derive(PartialEq, Debug)]
/// struct NotClone(usize);
///
/// let v = vec![NotClone(0), NotClone(1), NotClone(2)];
/// let v = [NotClone(0), NotClone(1), NotClone(2)];
/// let mut it = v.into_iter().intersperse_with(|| NotClone(99));
///
/// assert_eq!(it.next(), Some(NotClone(0))); // The first element from `v`.
@ -1270,7 +1270,7 @@ pub trait Iterator {
/// `take` will limit itself to the size of the underlying iterator:
///
/// ```
/// let v = vec![1, 2];
/// let v = [1, 2];
/// let mut iter = v.into_iter().take(5);
/// assert_eq!(iter.next(), Some(1));
/// assert_eq!(iter.next(), Some(2));
@ -1604,7 +1604,7 @@ pub trait Iterator {
/// Basic usage:
///
/// ```
/// let mut words = vec!["hello", "world", "of", "Rust"].into_iter();
/// let mut words = ["hello", "world", "of", "Rust"].into_iter();
///
/// // Take the first two words.
/// let hello_world: Vec<_> = words.by_ref().take(2).collect();
@ -2700,7 +2700,7 @@ pub trait Iterator {
/// incomparable. You can work around this by using [`Iterator::reduce`]:
/// ```
/// assert_eq!(
/// vec![2.4, f32::NAN, 1.3]
/// [2.4, f32::NAN, 1.3]
/// .into_iter()
/// .reduce(f32::max)
/// .unwrap(),
@ -2738,7 +2738,7 @@ pub trait Iterator {
/// incomparable. You can work around this by using [`Iterator::reduce`]:
/// ```
/// assert_eq!(
/// vec![2.4, f32::NAN, 1.3]
/// [2.4, f32::NAN, 1.3]
/// .into_iter()
/// .reduce(f32::min)
/// .unwrap(),

View File

@ -270,7 +270,7 @@
//! let mut bt = BTreeMap::new();
//! bt.insert(20u8, "foo");
//! bt.insert(42u8, "bar");
//! let res = vec![0u8, 1, 11, 200, 22]
//! let res = [0u8, 1, 11, 200, 22]
//! .into_iter()
//! .map(|x| {
//! // `checked_sub()` returns `None` on error
@ -390,10 +390,10 @@
//! [impl-FromIterator]: Option#impl-FromIterator%3COption%3CA%3E%3E
//!
//! ```
//! let v = vec![Some(2), Some(4), None, Some(8)];
//! let v = [Some(2), Some(4), None, Some(8)];
//! let res: Option<Vec<_>> = v.into_iter().collect();
//! assert_eq!(res, None);
//! let v = vec![Some(2), Some(4), Some(8)];
//! let v = [Some(2), Some(4), Some(8)];
//! let res: Option<Vec<_>> = v.into_iter().collect();
//! assert_eq!(res, Some(vec![2, 4, 8]));
//! ```
@ -407,10 +407,10 @@
//! [impl-Sum]: Option#impl-Sum%3COption%3CU%3E%3E
//!
//! ```
//! let v = vec![None, Some(1), Some(2), Some(3)];
//! let v = [None, Some(1), Some(2), Some(3)];
//! let res: Option<i32> = v.into_iter().sum();
//! assert_eq!(res, None);
//! let v = vec![Some(1), Some(2), Some(21)];
//! let v = [Some(1), Some(2), Some(21)];
//! let res: Option<i32> = v.into_iter().product();
//! assert_eq!(res, Some(42));
//! ```

View File

@ -436,7 +436,7 @@
//! # use std::str::FromStr;
//! let mut results = vec![];
//! let mut errs = vec![];
//! let nums: Vec<_> = vec!["17", "not a number", "99", "-27", "768"]
//! let nums: Vec<_> = ["17", "not a number", "99", "-27", "768"]
//! .into_iter()
//! .map(u8::from_str)
//! // Save clones of the raw `Result` values to inspect
@ -462,10 +462,10 @@
//! [impl-FromIterator]: Result#impl-FromIterator%3CResult%3CA%2C%20E%3E%3E
//!
//! ```
//! let v = vec![Ok(2), Ok(4), Err("err!"), Ok(8)];
//! let v = [Ok(2), Ok(4), Err("err!"), Ok(8)];
//! let res: Result<Vec<_>, &str> = v.into_iter().collect();
//! assert_eq!(res, Err("err!"));
//! let v = vec![Ok(2), Ok(4), Ok(8)];
//! let v = [Ok(2), Ok(4), Ok(8)];
//! let res: Result<Vec<_>, &str> = v.into_iter().collect();
//! assert_eq!(res, Ok(vec![2, 4, 8]));
//! ```
@ -479,10 +479,10 @@
//! [impl-Sum]: Result#impl-Sum%3CResult%3CU%2C%20E%3E%3E
//!
//! ```
//! let v = vec![Err("error!"), Ok(1), Ok(2), Ok(3), Err("foo")];
//! let v = [Err("error!"), Ok(1), Ok(2), Ok(3), Err("foo")];
//! let res: Result<i32, &str> = v.into_iter().sum();
//! assert_eq!(res, Err("error!"));
//! let v: Vec<Result<i32, &str>> = vec![Ok(1), Ok(2), Ok(21)];
//! let v = [Ok(1), Ok(2), Ok(21)];
//! let res: Result<i32, &str> = v.into_iter().product();
//! assert_eq!(res, Ok(42));
//! ```

View File

@ -74,7 +74,7 @@ fn test_intersperse_with() {
struct NotClone {
u: u32,
}
let r = vec![NotClone { u: 0 }, NotClone { u: 1 }]
let r = [NotClone { u: 0 }, NotClone { u: 1 }]
.into_iter()
.intersperse_with(|| NotClone { u: 2 })
.collect::<Vec<_>>();
@ -120,7 +120,7 @@ fn test_intersperse_fold() {
#[test]
fn test_intersperse_collect_string() {
let contents = vec![1, 2, 3];
let contents = [1, 2, 3];
let contents_string = contents
.into_iter()

View File

@ -144,7 +144,7 @@ fn test_iterator_peekable_rfold() {
#[test]
fn test_iterator_peekable_next_if_eq() {
// first, try on references
let xs = vec!["Heart", "of", "Gold"];
let xs = ["Heart", "of", "Gold"];
let mut it = xs.into_iter().peekable();
// try before `peek()`
assert_eq!(it.next_if_eq(&"trillian"), None);
@ -157,7 +157,7 @@ fn test_iterator_peekable_next_if_eq() {
assert_eq!(it.next(), Some("Gold"));
// make sure comparison works for owned values
let xs = vec![String::from("Ludicrous"), "speed".into()];
let xs = [String::from("Ludicrous"), "speed".into()];
let mut it = xs.into_iter().peekable();
// make sure basic functionality works
assert_eq!(it.next_if_eq("Ludicrous"), Some("Ludicrous".into()));
@ -167,7 +167,7 @@ fn test_iterator_peekable_next_if_eq() {
#[test]
fn test_iterator_peekable_mut() {
let mut it = vec![1, 2, 3].into_iter().peekable();
let mut it = [1, 2, 3].into_iter().peekable();
if let Some(p) = it.peek_mut() {
if *p == 1 {
*p = 5;

View File

@ -456,25 +456,25 @@ fn test_find_map() {
#[test]
fn test_try_reduce() {
let v: Vec<usize> = vec![1, 2, 3, 4, 5];
let v = [1usize, 2, 3, 4, 5];
let sum = v.into_iter().try_reduce(|x, y| x.checked_add(y));
assert_eq!(sum, Some(Some(15)));
let v: Vec<usize> = vec![1, 2, 3, 4, 5, usize::MAX];
let v = [1, 2, 3, 4, 5, usize::MAX];
let sum = v.into_iter().try_reduce(|x, y| x.checked_add(y));
assert_eq!(sum, None);
let v: Vec<usize> = Vec::new();
let v: [usize; 0] = [];
let sum = v.into_iter().try_reduce(|x, y| x.checked_add(y));
assert_eq!(sum, Some(None));
let v = vec!["1", "2", "3", "4", "5"];
let v = ["1", "2", "3", "4", "5"];
let max = v.into_iter().try_reduce(|x, y| {
if x.parse::<usize>().ok()? > y.parse::<usize>().ok()? { Some(x) } else { Some(y) }
});
assert_eq!(max, Some(Some("5")));
let v = vec!["1", "2", "3", "4", "5"];
let v = ["1", "2", "3", "4", "5"];
let max: Result<Option<_>, <usize as std::str::FromStr>::Err> =
v.into_iter().try_reduce(|x, y| {
if x.parse::<usize>()? > y.parse::<usize>()? { Ok(x) } else { Ok(y) }

View File

@ -420,8 +420,8 @@ fn test_iterate() {
#[test]
fn test_keys() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = vec.into_iter().collect();
let pairs = [(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = pairs.into_iter().collect();
let keys: Vec<_> = map.keys().cloned().collect();
assert_eq!(keys.len(), 3);
assert!(keys.contains(&1));
@ -431,8 +431,8 @@ fn test_keys() {
#[test]
fn test_values() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = vec.into_iter().collect();
let pairs = [(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = pairs.into_iter().collect();
let values: Vec<_> = map.values().cloned().collect();
assert_eq!(values.len(), 3);
assert!(values.contains(&'a'));
@ -442,8 +442,8 @@ fn test_values() {
#[test]
fn test_values_mut() {
let vec = vec![(1, 1), (2, 2), (3, 3)];
let mut map: HashMap<_, _> = vec.into_iter().collect();
let pairs = [(1, 1), (2, 2), (3, 3)];
let mut map: HashMap<_, _> = pairs.into_iter().collect();
for value in map.values_mut() {
*value = (*value) * 2
}
@ -456,8 +456,8 @@ fn test_values_mut() {
#[test]
fn test_into_keys() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = vec.into_iter().collect();
let pairs = [(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = pairs.into_iter().collect();
let keys: Vec<_> = map.into_keys().collect();
assert_eq!(keys.len(), 3);
@ -468,8 +468,8 @@ fn test_into_keys() {
#[test]
fn test_into_values() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = vec.into_iter().collect();
let pairs = [(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = pairs.into_iter().collect();
let values: Vec<_> = map.into_values().collect();
assert_eq!(values.len(), 3);

View File

@ -232,7 +232,7 @@
//! ```
//! use std::collections::VecDeque;
//!
//! let vec = vec![1, 2, 3, 4];
//! let vec = [1, 2, 3, 4];
//! let buf: VecDeque<_> = vec.into_iter().collect();
//! ```
//!

View File

@ -2172,7 +2172,7 @@ mod use_keyword {}
/// i.next().unwrap_or_else(I::Item::default)
/// }
///
/// assert_eq!(first_or_default(vec![1, 2, 3].into_iter()), 1);
/// assert_eq!(first_or_default([1, 2, 3].into_iter()), 1);
/// assert_eq!(first_or_default(Vec::<i32>::new().into_iter()), 0);
/// ```
///

View File

@ -493,7 +493,7 @@ pub fn exclude_should_panic_option() {
#[test]
pub fn exact_filter_match() {
fn tests() -> Vec<TestDescAndFn> {
vec!["base", "base::test", "base::test1", "base::test2"]
["base", "base::test", "base::test1", "base::test2"]
.into_iter()
.map(|name| TestDescAndFn {
desc: TestDesc {