Skip to content

Commit 637ca4e

Browse files
author
Keegan McAllister
committed
Export vec!() from libcollections
Fixes #16806. The duplication of code with libstd is unfortunate, but there's already a lot of that exported from core::macros.
1 parent 8ccbf4f commit 637ca4e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/libcollections/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,4 +574,5 @@ mod std {
574574
mod collections {
575575
pub use hash; // deriving(Hsah)
576576
pub use string; // format!()
577+
pub use vec; // vec!()
577578
}

src/libcollections/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#![macro_escape]
1212

1313
/// Creates a `std::vec::Vec` containing the arguments.
14+
#[macro_export]
1415
macro_rules! vec(
1516
($($e:expr),*) => ({
1617
// leading _ to allow empty construction without a warning.
17-
let mut _temp = ::vec::Vec::new();
18+
let mut _temp = ::collections::vec::Vec::new();
1819
$(_temp.push($e);)*
1920
_temp
2021
});

src/test/run-pass/vec-macro-no-std.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(phase)]
12+
#![no_std]
13+
14+
#[phase(plugin, link)]
15+
extern crate core;
16+
17+
#[phase(plugin, link)]
18+
extern crate collections;
19+
20+
extern crate native;
21+
22+
use core::option::Some;
23+
use collections::vec::Vec;
24+
use collections::MutableSeq;
25+
26+
// Issue #16806
27+
28+
fn main() {
29+
let x: Vec<u8> = vec!(0, 1, 2);
30+
match x.last() {
31+
Some(&2) => (),
32+
_ => fail!(),
33+
}
34+
}

0 commit comments

Comments
 (0)