Skip to content

Commit

Permalink
Auto merge of #37497 - iirelu:proper-vec-brackets-2, r=steveklabnik
Browse files Browse the repository at this point in the history
Make all vec! macros use square brackets: Attempt 2

[The last PR](#37476) ended with tears after a valiant struggle with git. I managed to clean up the completely broken history of that into a brand spanking new PR! Yay!

Original:

> Everyone hates the old syntax. I hope. Otherwise this PR has some controversy I wasn't expecting.

> This would be the perfect time to write a lint recommending vec![..] when you use another style.

> Disclaimer: I may have broken something. If I have, I'll fix them when the tests come in. Luckily the chance for a non-syntactical error is pretty low in all this.
  • Loading branch information
bors committed Oct 31, 2016
2 parents f26eedb + e593c3b commit 69ec350
Show file tree
Hide file tree
Showing 189 changed files with 511 additions and 511 deletions.
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ impl<T> [T] {
/// let x = s.into_vec();
/// // `s` cannot be used anymore because it has been converted into `x`.
///
/// assert_eq!(x, vec!(10, 40, 30));
/// assert_eq!(x, vec![10, 40, 30]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ use super::range::RangeArgument;
/// [`Index`] trait. An example will be more explicit:
///
/// ```
/// let v = vec!(0, 2, 4, 6);
/// let v = vec![0, 2, 4, 6];
/// println!("{}", v[1]); // it will display '2'
/// ```
///
/// However be careful: if you try to access an index which isn't in the `Vec`,
/// your software will panic! You cannot do this:
///
/// ```ignore
/// let v = vec!(0, 2, 4, 6);
/// let v = vec![0, 2, 4, 6];
/// println!("{}", v[6]); // it will panic!
/// ```
///
Expand All @@ -173,7 +173,7 @@ use super::range::RangeArgument;
/// // ...
/// }
///
/// let v = vec!(0, 1);
/// let v = vec![0, 1];
/// read_slice(&v);
///
/// // ... and that's all!
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,12 +914,12 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// ```
/// use std::u16;
///
/// let v = vec!(1, 2);
/// let v = vec![1, 2];
/// let res: Option<Vec<u16>> = v.iter().map(|&x: &u16|
/// if x == u16::MAX { None }
/// else { Some(x + 1) }
/// ).collect();
/// assert!(res == Some(vec!(2, 3)));
/// assert!(res == Some(vec![2, 3]));
/// ```
#[inline]
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,12 +977,12 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
/// ```
/// use std::u32;
///
/// let v = vec!(1, 2);
/// let v = vec![1, 2];
/// let res: Result<Vec<u32>, &'static str> = v.iter().map(|&x: &u32|
/// if x == u32::MAX { Err("Overflow!") }
/// else { Ok(x + 1) }
/// ).collect();
/// assert!(res == Ok(vec!(2, 3)));
/// assert!(res == Ok(vec![2, 3]));
/// ```
#[inline]
fn from_iter<I: IntoIterator<Item=Result<A, E>>>(iter: I) -> Result<V, E> {
Expand Down
4 changes: 2 additions & 2 deletions src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,8 +1610,8 @@ Options:

#[test]
fn test_args_with_equals() {
let args = vec!("--one".to_string(), "A=B".to_string(),
"--two=C=D".to_string());
let args = vec!["--one".to_string(), "A=B".to_string(),
"--two=C=D".to_string()];
let opts = vec![optopt("o", "one", "One", "INFO"),
optopt("t", "two", "Two", "INFO")];
let matches = &match getopts(&args, &opts) {
Expand Down
10 changes: 5 additions & 5 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
//! struct Edges(Vec<Ed>);
//!
//! pub fn render_to<W: Write>(output: &mut W) {
//! let edges = Edges(vec!((0,1), (0,2), (1,3), (2,3), (3,4), (4,4)));
//! let edges = Edges(vec![(0,1), (0,2), (1,3), (2,3), (3,4), (4,4)]);
//! dot::render(&edges, output).unwrap()
//! }
//!
Expand Down Expand Up @@ -164,8 +164,8 @@
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(usize,usize)> }
//!
//! pub fn render_to<W: Write>(output: &mut W) {
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
//! let nodes = vec!["{x,y}","{x}","{y}","{}"];
//! let edges = vec![(0,1), (0,2), (1,3), (2,3)];
//! let graph = Graph { nodes: nodes, edges: edges };
//!
//! dot::render(&graph, output).unwrap()
Expand Down Expand Up @@ -226,8 +226,8 @@
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(usize,usize)> }
//!
//! pub fn render_to<W: Write>(output: &mut W) {
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
//! let nodes = vec!["{x,y}","{x}","{y}","{}"];
//! let edges = vec![(0,1), (0,2), (1,3), (2,3)];
//! let graph = Graph { nodes: nodes, edges: edges };
//!
//! dot::render(&graph, output).unwrap()
Expand Down
12 changes: 6 additions & 6 deletions src/librand/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,17 @@ mod tests {

let v = (0..16).map(|_| ra.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(0xade0b876, 0x903df1a0, 0xe56a5d40, 0x28bd8653,
vec![0xade0b876, 0x903df1a0, 0xe56a5d40, 0x28bd8653,
0xb819d2bd, 0x1aed8da0, 0xccef36a8, 0xc70d778b,
0x7c5941da, 0x8d485751, 0x3fe02477, 0x374ad8b8,
0xf4b8436a, 0x1ca11815, 0x69b687c3, 0x8665eeb2));
0xf4b8436a, 0x1ca11815, 0x69b687c3, 0x8665eeb2]);

let v = (0..16).map(|_| ra.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(0xbee7079f, 0x7a385155, 0x7c97ba98, 0x0d082d73,
vec![0xbee7079f, 0x7a385155, 0x7c97ba98, 0x0d082d73,
0xa0290fcb, 0x6965e348, 0x3e53c612, 0xed7aee32,
0x7621b729, 0x434ee69c, 0xb03371d5, 0xd539d874,
0x281fed31, 0x45fb0a51, 0x1f0ae1ac, 0x6f4d794b));
0x281fed31, 0x45fb0a51, 0x1f0ae1ac, 0x6f4d794b]);


let seed: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
Expand All @@ -280,10 +280,10 @@ mod tests {
}

assert_eq!(v,
vec!(0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036,
vec![0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036,
0x49884684, 0x64efec72, 0x4be2d186, 0x3615b384,
0x11cfa18e, 0xd3c50049, 0x75c775f6, 0x434c6530,
0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4));
0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4]);
}

#[test]
Expand Down
18 changes: 9 additions & 9 deletions src/librand/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,37 +312,37 @@ mod tests {
}}
}

t!(vec!(Weighted { weight: 1, item: 10 }),
t!(vec![Weighted { weight: 1, item: 10 }],
[10]);

// skip some
t!(vec!(Weighted { weight: 0, item: 20 },
t!(vec![Weighted { weight: 0, item: 20 },
Weighted { weight: 2, item: 21 },
Weighted { weight: 0, item: 22 },
Weighted { weight: 1, item: 23 }),
Weighted { weight: 1, item: 23 }],
[21, 21, 23]);

// different weights
t!(vec!(Weighted { weight: 4, item: 30 },
Weighted { weight: 3, item: 31 }),
t!(vec![Weighted { weight: 4, item: 30 },
Weighted { weight: 3, item: 31 }],
[30, 30, 30, 30, 31, 31, 31]);

// check that we're binary searching
// correctly with some vectors of odd
// length.
t!(vec!(Weighted { weight: 1, item: 40 },
t!(vec![Weighted { weight: 1, item: 40 },
Weighted { weight: 1, item: 41 },
Weighted { weight: 1, item: 42 },
Weighted { weight: 1, item: 43 },
Weighted { weight: 1, item: 44 }),
Weighted { weight: 1, item: 44 }],
[40, 41, 42, 43, 44]);
t!(vec!(Weighted { weight: 1, item: 50 },
t!(vec![Weighted { weight: 1, item: 50 },
Weighted { weight: 1, item: 51 },
Weighted { weight: 1, item: 52 },
Weighted { weight: 1, item: 53 },
Weighted { weight: 1, item: 54 },
Weighted { weight: 1, item: 55 },
Weighted { weight: 1, item: 56 }),
Weighted { weight: 1, item: 56 }],
[50, 51, 52, 53, 54, 55, 56]);
}

Expand Down
16 changes: 8 additions & 8 deletions src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ mod tests {
// Regression test that isaac is actually using the above vector
let v = (0..10).map(|_| ra.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(2558573138, 873787463, 263499565, 2103644246, 3595684709,
4203127393, 264982119, 2765226902, 2737944514, 3900253796));
vec![2558573138, 873787463, 263499565, 2103644246, 3595684709,
4203127393, 264982119, 2765226902, 2737944514, 3900253796]);

let seed: &[_] = &[12345, 67890, 54321, 9876];
let mut rb: IsaacRng = SeedableRng::from_seed(seed);
Expand All @@ -674,8 +674,8 @@ mod tests {

let v = (0..10).map(|_| rb.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(3676831399, 3183332890, 2834741178, 3854698763, 2717568474,
1576568959, 3507990155, 179069555, 141456972, 2478885421));
vec![3676831399, 3183332890, 2834741178, 3854698763, 2717568474,
1576568959, 3507990155, 179069555, 141456972, 2478885421]);
}
#[test]
#[rustfmt_skip]
Expand All @@ -685,10 +685,10 @@ mod tests {
// Regression test that isaac is actually using the above vector
let v = (0..10).map(|_| ra.next_u64()).collect::<Vec<_>>();
assert_eq!(v,
vec!(547121783600835980, 14377643087320773276, 17351601304698403469,
vec![547121783600835980, 14377643087320773276, 17351601304698403469,
1238879483818134882, 11952566807690396487, 13970131091560099343,
4469761996653280935, 15552757044682284409, 6860251611068737823,
13722198873481261842));
13722198873481261842]);

let seed: &[_] = &[12345, 67890, 54321, 9876];
let mut rb: Isaac64Rng = SeedableRng::from_seed(seed);
Expand All @@ -699,10 +699,10 @@ mod tests {

let v = (0..10).map(|_| rb.next_u64()).collect::<Vec<_>>();
assert_eq!(v,
vec!(18143823860592706164, 8491801882678285927, 2699425367717515619,
vec![18143823860592706164, 8491801882678285927, 2699425367717515619,
17196852593171130876, 2606123525235546165, 15790932315217671084,
596345674630742204, 9947027391921273664, 11788097613744130851,
10391409374914919106));
10391409374914919106]);

}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
fn add_contained_edge(&mut self,
source: CFGIndex,
target: CFGIndex) {
let data = CFGEdgeData {exiting_scopes: vec!() };
let data = CFGEdgeData {exiting_scopes: vec![] };
self.graph.add_edge(source, target, data);
}

Expand All @@ -545,7 +545,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
from_index: CFGIndex,
to_loop: LoopScope,
to_index: CFGIndex) {
let mut data = CFGEdgeData {exiting_scopes: vec!() };
let mut data = CFGEdgeData {exiting_scopes: vec![] };
let mut scope = self.tcx.region_maps.node_extent(from_expr.id);
let target_scope = self.tcx.region_maps.node_extent(to_loop.loop_id);
while scope != target_scope {
Expand All @@ -559,7 +559,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
_from_expr: &hir::Expr,
from_index: CFGIndex) {
let mut data = CFGEdgeData {
exiting_scopes: vec!(),
exiting_scopes: vec![],
};
for &LoopScope { loop_id: id, .. } in self.loop_scopes.iter().rev() {
data.exiting_scopes.push(id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
same_regions.push(SameRegions {
scope_id: scope_id,
regions: vec!(sub_fr.bound_region, sup_fr.bound_region)
regions: vec![sub_fr.bound_region, sup_fr.bound_region]
})
}
}
Expand Down Expand Up @@ -1359,7 +1359,7 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
region_names: &HashSet<ast::Name>)
-> P<hir::Ty> {
let mut new_ty = P(ty.clone());
let mut ty_queue = vec!(ty);
let mut ty_queue = vec![ty];
while !ty_queue.is_empty() {
let cur_ty = ty_queue.remove(0);
match cur_ty.node {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ impl LintStore {

pub fn new() -> LintStore {
LintStore {
lints: vec!(),
early_passes: Some(vec!()),
late_passes: Some(vec!()),
lints: vec![],
early_passes: Some(vec![]),
late_passes: Some(vec![]),
by_name: FnvHashMap(),
levels: FnvHashMap(),
future_incompatible: FnvHashMap(),
Expand Down Expand Up @@ -345,7 +345,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $ps:ident, $($args:expr),*) => ({
// See also the hir version just below.
pub fn gather_attrs(attrs: &[ast::Attribute])
-> Vec<Result<(InternedString, Level, Span), Span>> {
let mut out = vec!();
let mut out = vec![];
for attr in attrs {
let r = gather_attr(attr);
out.extend(r.into_iter());
Expand All @@ -355,7 +355,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])

pub fn gather_attr(attr: &ast::Attribute)
-> Vec<Result<(InternedString, Level, Span), Span>> {
let mut out = vec!();
let mut out = vec![];

let level = match Level::from_str(&attr.name()) {
None => return out,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl LanguageItems {
fn foo(_: LangItem) -> Option<DefId> { None }

LanguageItems {
items: vec!($(foo($variant)),*),
items: vec![$(foo($variant)),*],
missing: Vec::new(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ macro_rules! options {
true
}
v => {
let mut passes = vec!();
let mut passes = vec![];
if parse_list(&mut passes, v) {
*slot = SomePasses(passes);
true
Expand Down Expand Up @@ -1293,7 +1293,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
.unwrap_or_else(|e| early_error(error_format, &e[..]));

let mut lint_opts = vec!();
let mut lint_opts = vec![];
let mut describe_lints = false;

for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl Session {
}
return;
}
lints.insert(id, vec!((lint_id, sp, msg)));
lints.insert(id, vec![(lint_id, sp, msg)]);
}
pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId {
let id = self.next_node_id.get();
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'a, 'b, 'gcx, 'tcx> AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> {
AssociatedTypeNormalizer {
selcx: selcx,
cause: cause,
obligations: vec!(),
obligations: vec![],
depth: depth,
}
}
Expand Down Expand Up @@ -396,7 +396,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
cause, depth + 1, projection.to_predicate());
Normalized {
value: ty_var,
obligations: vec!(obligation)
obligations: vec![obligation]
}
})
}
Expand Down Expand Up @@ -545,7 +545,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
projected_ty);
let result = Normalized {
value: projected_ty,
obligations: vec!()
obligations: vec![]
};
infcx.projection_cache.borrow_mut()
.complete(projection_ty, &result, true);
Expand Down Expand Up @@ -604,7 +604,7 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
let new_value = selcx.infcx().next_ty_var();
Normalized {
value: new_value,
obligations: vec!(trait_obligation)
obligations: vec![trait_obligation]
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct TypeWalker<'tcx> {

impl<'tcx> TypeWalker<'tcx> {
pub fn new(ty: Ty<'tcx>) -> TypeWalker<'tcx> {
TypeWalker { stack: vec!(ty), last_subtree: 1, }
TypeWalker { stack: vec![ty], last_subtree: 1, }
}

/// Skips the subtree of types corresponding to the last type
Expand Down
Loading

0 comments on commit 69ec350

Please sign in to comment.