Skip to content

Commit 69ec350

Browse files
authored
Auto merge of #37497 - iirelu:proper-vec-brackets-2, r=steveklabnik
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.
2 parents f26eedb + e593c3b commit 69ec350

File tree

189 files changed

+511
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+511
-511
lines changed

src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ impl<T> [T] {
11701170
/// let x = s.into_vec();
11711171
/// // `s` cannot be used anymore because it has been converted into `x`.
11721172
///
1173-
/// assert_eq!(x, vec!(10, 40, 30));
1173+
/// assert_eq!(x, vec![10, 40, 30]);
11741174
/// ```
11751175
#[stable(feature = "rust1", since = "1.0.0")]
11761176
#[inline]

src/libcollections/vec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ use super::range::RangeArgument;
148148
/// [`Index`] trait. An example will be more explicit:
149149
///
150150
/// ```
151-
/// let v = vec!(0, 2, 4, 6);
151+
/// let v = vec![0, 2, 4, 6];
152152
/// println!("{}", v[1]); // it will display '2'
153153
/// ```
154154
///
155155
/// However be careful: if you try to access an index which isn't in the `Vec`,
156156
/// your software will panic! You cannot do this:
157157
///
158158
/// ```ignore
159-
/// let v = vec!(0, 2, 4, 6);
159+
/// let v = vec![0, 2, 4, 6];
160160
/// println!("{}", v[6]); // it will panic!
161161
/// ```
162162
///
@@ -173,7 +173,7 @@ use super::range::RangeArgument;
173173
/// // ...
174174
/// }
175175
///
176-
/// let v = vec!(0, 1);
176+
/// let v = vec![0, 1];
177177
/// read_slice(&v);
178178
///
179179
/// // ... and that's all!

src/libcore/option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,12 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
914914
/// ```
915915
/// use std::u16;
916916
///
917-
/// let v = vec!(1, 2);
917+
/// let v = vec![1, 2];
918918
/// let res: Option<Vec<u16>> = v.iter().map(|&x: &u16|
919919
/// if x == u16::MAX { None }
920920
/// else { Some(x + 1) }
921921
/// ).collect();
922-
/// assert!(res == Some(vec!(2, 3)));
922+
/// assert!(res == Some(vec![2, 3]));
923923
/// ```
924924
#[inline]
925925
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {

src/libcore/result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -977,12 +977,12 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
977977
/// ```
978978
/// use std::u32;
979979
///
980-
/// let v = vec!(1, 2);
980+
/// let v = vec![1, 2];
981981
/// let res: Result<Vec<u32>, &'static str> = v.iter().map(|&x: &u32|
982982
/// if x == u32::MAX { Err("Overflow!") }
983983
/// else { Ok(x + 1) }
984984
/// ).collect();
985-
/// assert!(res == Ok(vec!(2, 3)));
985+
/// assert!(res == Ok(vec![2, 3]));
986986
/// ```
987987
#[inline]
988988
fn from_iter<I: IntoIterator<Item=Result<A, E>>>(iter: I) -> Result<V, E> {

src/libgetopts/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,8 @@ Options:
16101610

16111611
#[test]
16121612
fn test_args_with_equals() {
1613-
let args = vec!("--one".to_string(), "A=B".to_string(),
1614-
"--two=C=D".to_string());
1613+
let args = vec!["--one".to_string(), "A=B".to_string(),
1614+
"--two=C=D".to_string()];
16151615
let opts = vec![optopt("o", "one", "One", "INFO"),
16161616
optopt("t", "two", "Two", "INFO")];
16171617
let matches = &match getopts(&args, &opts) {

src/libgraphviz/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
//! struct Edges(Vec<Ed>);
5959
//!
6060
//! pub fn render_to<W: Write>(output: &mut W) {
61-
//! let edges = Edges(vec!((0,1), (0,2), (1,3), (2,3), (3,4), (4,4)));
61+
//! let edges = Edges(vec![(0,1), (0,2), (1,3), (2,3), (3,4), (4,4)]);
6262
//! dot::render(&edges, output).unwrap()
6363
//! }
6464
//!
@@ -164,8 +164,8 @@
164164
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(usize,usize)> }
165165
//!
166166
//! pub fn render_to<W: Write>(output: &mut W) {
167-
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
168-
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
167+
//! let nodes = vec!["{x,y}","{x}","{y}","{}"];
168+
//! let edges = vec![(0,1), (0,2), (1,3), (2,3)];
169169
//! let graph = Graph { nodes: nodes, edges: edges };
170170
//!
171171
//! dot::render(&graph, output).unwrap()
@@ -226,8 +226,8 @@
226226
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(usize,usize)> }
227227
//!
228228
//! pub fn render_to<W: Write>(output: &mut W) {
229-
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
230-
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
229+
//! let nodes = vec!["{x,y}","{x}","{y}","{}"];
230+
//! let edges = vec![(0,1), (0,2), (1,3), (2,3)];
231231
//! let graph = Graph { nodes: nodes, edges: edges };
232232
//!
233233
//! dot::render(&graph, output).unwrap()

src/librand/chacha.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,17 @@ mod tests {
253253

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

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

268268

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

282282
assert_eq!(v,
283-
vec!(0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036,
283+
vec![0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036,
284284
0x49884684, 0x64efec72, 0x4be2d186, 0x3615b384,
285285
0x11cfa18e, 0xd3c50049, 0x75c775f6, 0x434c6530,
286-
0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4));
286+
0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4]);
287287
}
288288

289289
#[test]

src/librand/distributions/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -312,37 +312,37 @@ mod tests {
312312
}}
313313
}
314314

315-
t!(vec!(Weighted { weight: 1, item: 10 }),
315+
t!(vec![Weighted { weight: 1, item: 10 }],
316316
[10]);
317317

318318
// skip some
319-
t!(vec!(Weighted { weight: 0, item: 20 },
319+
t!(vec![Weighted { weight: 0, item: 20 },
320320
Weighted { weight: 2, item: 21 },
321321
Weighted { weight: 0, item: 22 },
322-
Weighted { weight: 1, item: 23 }),
322+
Weighted { weight: 1, item: 23 }],
323323
[21, 21, 23]);
324324

325325
// different weights
326-
t!(vec!(Weighted { weight: 4, item: 30 },
327-
Weighted { weight: 3, item: 31 }),
326+
t!(vec![Weighted { weight: 4, item: 30 },
327+
Weighted { weight: 3, item: 31 }],
328328
[30, 30, 30, 30, 31, 31, 31]);
329329

330330
// check that we're binary searching
331331
// correctly with some vectors of odd
332332
// length.
333-
t!(vec!(Weighted { weight: 1, item: 40 },
333+
t!(vec![Weighted { weight: 1, item: 40 },
334334
Weighted { weight: 1, item: 41 },
335335
Weighted { weight: 1, item: 42 },
336336
Weighted { weight: 1, item: 43 },
337-
Weighted { weight: 1, item: 44 }),
337+
Weighted { weight: 1, item: 44 }],
338338
[40, 41, 42, 43, 44]);
339-
t!(vec!(Weighted { weight: 1, item: 50 },
339+
t!(vec![Weighted { weight: 1, item: 50 },
340340
Weighted { weight: 1, item: 51 },
341341
Weighted { weight: 1, item: 52 },
342342
Weighted { weight: 1, item: 53 },
343343
Weighted { weight: 1, item: 54 },
344344
Weighted { weight: 1, item: 55 },
345-
Weighted { weight: 1, item: 56 }),
345+
Weighted { weight: 1, item: 56 }],
346346
[50, 51, 52, 53, 54, 55, 56]);
347347
}
348348

src/librand/isaac.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ mod tests {
662662
// Regression test that isaac is actually using the above vector
663663
let v = (0..10).map(|_| ra.next_u32()).collect::<Vec<_>>();
664664
assert_eq!(v,
665-
vec!(2558573138, 873787463, 263499565, 2103644246, 3595684709,
666-
4203127393, 264982119, 2765226902, 2737944514, 3900253796));
665+
vec![2558573138, 873787463, 263499565, 2103644246, 3595684709,
666+
4203127393, 264982119, 2765226902, 2737944514, 3900253796]);
667667

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

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

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

700700
let v = (0..10).map(|_| rb.next_u64()).collect::<Vec<_>>();
701701
assert_eq!(v,
702-
vec!(18143823860592706164, 8491801882678285927, 2699425367717515619,
702+
vec![18143823860592706164, 8491801882678285927, 2699425367717515619,
703703
17196852593171130876, 2606123525235546165, 15790932315217671084,
704704
596345674630742204, 9947027391921273664, 11788097613744130851,
705-
10391409374914919106));
705+
10391409374914919106]);
706706

707707
}
708708

src/librustc/cfg/construct.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
536536
fn add_contained_edge(&mut self,
537537
source: CFGIndex,
538538
target: CFGIndex) {
539-
let data = CFGEdgeData {exiting_scopes: vec!() };
539+
let data = CFGEdgeData {exiting_scopes: vec![] };
540540
self.graph.add_edge(source, target, data);
541541
}
542542

@@ -545,7 +545,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
545545
from_index: CFGIndex,
546546
to_loop: LoopScope,
547547
to_index: CFGIndex) {
548-
let mut data = CFGEdgeData {exiting_scopes: vec!() };
548+
let mut data = CFGEdgeData {exiting_scopes: vec![] };
549549
let mut scope = self.tcx.region_maps.node_extent(from_expr.id);
550550
let target_scope = self.tcx.region_maps.node_extent(to_loop.loop_id);
551551
while scope != target_scope {
@@ -559,7 +559,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
559559
_from_expr: &hir::Expr,
560560
from_index: CFGIndex) {
561561
let mut data = CFGEdgeData {
562-
exiting_scopes: vec!(),
562+
exiting_scopes: vec![],
563563
};
564564
for &LoopScope { loop_id: id, .. } in self.loop_scopes.iter().rev() {
565565
data.exiting_scopes.push(id);

src/librustc/infer/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
457457
}
458458
same_regions.push(SameRegions {
459459
scope_id: scope_id,
460-
regions: vec!(sub_fr.bound_region, sup_fr.bound_region)
460+
regions: vec![sub_fr.bound_region, sup_fr.bound_region]
461461
})
462462
}
463463
}
@@ -1359,7 +1359,7 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
13591359
region_names: &HashSet<ast::Name>)
13601360
-> P<hir::Ty> {
13611361
let mut new_ty = P(ty.clone());
1362-
let mut ty_queue = vec!(ty);
1362+
let mut ty_queue = vec![ty];
13631363
while !ty_queue.is_empty() {
13641364
let cur_ty = ty_queue.remove(0);
13651365
match cur_ty.node {

src/librustc/lint/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ impl LintStore {
127127

128128
pub fn new() -> LintStore {
129129
LintStore {
130-
lints: vec!(),
131-
early_passes: Some(vec!()),
132-
late_passes: Some(vec!()),
130+
lints: vec![],
131+
early_passes: Some(vec![]),
132+
late_passes: Some(vec![]),
133133
by_name: FnvHashMap(),
134134
levels: FnvHashMap(),
135135
future_incompatible: FnvHashMap(),
@@ -345,7 +345,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $ps:ident, $($args:expr),*) => ({
345345
// See also the hir version just below.
346346
pub fn gather_attrs(attrs: &[ast::Attribute])
347347
-> Vec<Result<(InternedString, Level, Span), Span>> {
348-
let mut out = vec!();
348+
let mut out = vec![];
349349
for attr in attrs {
350350
let r = gather_attr(attr);
351351
out.extend(r.into_iter());
@@ -355,7 +355,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
355355

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

360360
let level = match Level::from_str(&attr.name()) {
361361
None => return out,

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl LanguageItems {
5959
fn foo(_: LangItem) -> Option<DefId> { None }
6060

6161
LanguageItems {
62-
items: vec!($(foo($variant)),*),
62+
items: vec![$(foo($variant)),*],
6363
missing: Vec::new(),
6464
}
6565
}

src/librustc/session/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ macro_rules! options {
715715
true
716716
}
717717
v => {
718-
let mut passes = vec!();
718+
let mut passes = vec![];
719719
if parse_list(&mut passes, v) {
720720
*slot = SomePasses(passes);
721721
true
@@ -1293,7 +1293,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
12931293
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
12941294
.unwrap_or_else(|e| early_error(error_format, &e[..]));
12951295

1296-
let mut lint_opts = vec!();
1296+
let mut lint_opts = vec![];
12971297
let mut describe_lints = false;
12981298

12991299
for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {

src/librustc/session/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl Session {
272272
}
273273
return;
274274
}
275-
lints.insert(id, vec!((lint_id, sp, msg)));
275+
lints.insert(id, vec![(lint_id, sp, msg)]);
276276
}
277277
pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId {
278278
let id = self.next_node_id.get();

src/librustc/traits/project.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'a, 'b, 'gcx, 'tcx> AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> {
275275
AssociatedTypeNormalizer {
276276
selcx: selcx,
277277
cause: cause,
278-
obligations: vec!(),
278+
obligations: vec![],
279279
depth: depth,
280280
}
281281
}
@@ -396,7 +396,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
396396
cause, depth + 1, projection.to_predicate());
397397
Normalized {
398398
value: ty_var,
399-
obligations: vec!(obligation)
399+
obligations: vec![obligation]
400400
}
401401
})
402402
}
@@ -545,7 +545,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
545545
projected_ty);
546546
let result = Normalized {
547547
value: projected_ty,
548-
obligations: vec!()
548+
obligations: vec![]
549549
};
550550
infcx.projection_cache.borrow_mut()
551551
.complete(projection_ty, &result, true);
@@ -604,7 +604,7 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
604604
let new_value = selcx.infcx().next_ty_var();
605605
Normalized {
606606
value: new_value,
607-
obligations: vec!(trait_obligation)
607+
obligations: vec![trait_obligation]
608608
}
609609
}
610610

src/librustc/ty/walk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct TypeWalker<'tcx> {
2222

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

2828
/// Skips the subtree of types corresponding to the last type

0 commit comments

Comments
 (0)