Skip to content

Commit 490dcdb

Browse files
committed
---
yaml --- r: 272803 b: refs/heads/beta c: d5aeb76 h: refs/heads/master i: 272801: 30342bb 272799: 04c45ad
1 parent fab6ab0 commit 490dcdb

File tree

16 files changed

+190
-21
lines changed

16 files changed

+190
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 84e6e04d83d02e09e8b659267e415ec8b5bc2a24
26+
refs/heads/beta: d5aeb769e998ed40a0dc935a0648f9bf1bd4292e
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/bootstrap/build/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn check(build: &mut Build) {
7979
}
8080

8181
// Make sure musl-root is valid if specified
82-
if target.contains("musl") {
82+
if target.contains("musl") && target.contains("x86_64") {
8383
match build.config.musl_root {
8484
Some(ref root) => {
8585
if fs::metadata(root.join("lib/libc.a")).is_err() {

branches/beta/src/doc/book/vectors.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,36 @@ for i in v {
115115
}
116116
```
117117

118+
Note: You cannot use the vector again once you have iterated by taking ownership of the vector.
119+
You can iterate the vector multiple times by taking a reference to the vector whilst iterating.
120+
For example, the following code does not compile.
121+
122+
```rust,ignore
123+
let mut v = vec![1, 2, 3, 4, 5];
124+
125+
for i in v {
126+
println!("Take ownership of the vector and its element {}", i);
127+
}
128+
129+
for i in v {
130+
println!("Take ownership of the vector and its element {}", i);
131+
}
132+
```
133+
134+
Whereas the following works perfectly,
135+
136+
```rust
137+
let mut v = vec![1, 2, 3, 4, 5];
138+
139+
for i in &v {
140+
println!("This is a reference to {}", i);
141+
}
142+
143+
for i in &v {
144+
println!("This is a reference to {}", i);
145+
}
146+
```
147+
118148
Vectors have many more useful methods, which you can read about in [their
119149
API documentation][vec].
120150

branches/beta/src/libcore/str/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,6 @@ fn eq_slice(a: &str, b: &str) -> bool {
10951095
/// faster than comparing each byte in a loop.
10961096
#[inline]
10971097
unsafe fn cmp_slice(a: &str, b: &str, len: usize) -> i32 {
1098-
// NOTE: In theory n should be libc::size_t and not usize, but libc is not available here
1099-
#[allow(improper_ctypes)]
11001098
extern { fn memcmp(s1: *const i8, s2: *const i8, n: usize) -> i32; }
11011099
memcmp(a.as_ptr() as *const i8, b.as_ptr() as *const i8, len)
11021100
}

branches/beta/src/librustc_trans/trans/consts.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,17 @@ pub fn addr_of(ccx: &CrateContext,
161161
gv
162162
}
163163

164-
fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef {
164+
/// Deref a constant pointer
165+
fn load_const(cx: &CrateContext, v: ValueRef, t: Ty) -> ValueRef {
165166
let v = match cx.const_unsized().borrow().get(&v) {
166167
Some(&v) => v,
167168
None => v
168169
};
169-
unsafe {
170-
llvm::LLVMGetInitializer(v)
170+
let d = unsafe { llvm::LLVMGetInitializer(v) };
171+
if t.is_bool() {
172+
unsafe { llvm::LLVMConstTrunc(d, Type::i1(cx).to_ref()) }
173+
} else {
174+
d
171175
}
172176
}
173177

@@ -178,7 +182,7 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
178182
match ty.builtin_deref(true, ty::NoPreference) {
179183
Some(mt) => {
180184
if type_is_sized(cx.tcx(), mt.ty) {
181-
(const_deref_ptr(cx, v), mt.ty)
185+
(load_const(cx, v, mt.ty), mt.ty)
182186
} else {
183187
// Derefing a fat pointer does not change the representation,
184188
// just the type to the unsized contents.
@@ -588,7 +592,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
588592
let is_float = ty.is_fp();
589593
let signed = ty.is_signed();
590594

591-
let (te2, _) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
595+
let (te2, ty2) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
596+
debug!("const_expr_unadjusted: te2={}, ty={:?}",
597+
cx.tn().val_to_string(te2),
598+
ty2);
592599

593600
try!(check_binary_expr_validity(cx, e, ty, te1, te2, trueconst));
594601

@@ -671,13 +678,13 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
671678
};
672679
let (arr, len) = match bt.sty {
673680
ty::TyArray(_, u) => (bv, C_uint(cx, u)),
674-
ty::TySlice(_) | ty::TyStr => {
681+
ty::TySlice(..) | ty::TyStr => {
675682
let e1 = const_get_elt(cx, bv, &[0]);
676-
(const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1]))
683+
(load_const(cx, e1, bt), const_get_elt(cx, bv, &[1]))
677684
},
678685
ty::TyRef(_, mt) => match mt.ty.sty {
679686
ty::TyArray(_, u) => {
680-
(const_deref_ptr(cx, bv), C_uint(cx, u))
687+
(load_const(cx, bv, mt.ty), C_uint(cx, u))
681688
},
682689
_ => cx.sess().span_bug(base.span,
683690
&format!("index-expr base must be a vector \
@@ -891,7 +898,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
891898
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
892899
}
893900
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
894-
const_deref_ptr(cx, try!(get_const_val(cx, def_id, e, param_substs)))
901+
load_const(cx, try!(get_const_val(cx, def_id, e, param_substs)),
902+
ety)
895903
}
896904
Def::Variant(enum_did, variant_did) => {
897905
let vinfo = cx.tcx().lookup_adt_def(enum_did).variant_with_id(variant_did);

branches/beta/src/librustdoc/html/static/rustdoc.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,19 @@ a.test-arrow {
616616
}
617617

618618
.sidebar .location {
619-
float: left;
619+
float: right;
620620
margin: 0px;
621-
padding: 5px;
622-
width: 60%;
621+
padding: 3px 10px 1px 10px;
622+
min-height: 39px;
623623
background: inherit;
624624
text-align: left;
625625
font-size: 24px;
626626
}
627627

628+
.sidebar .location:empty {
629+
padding: 0;
630+
}
631+
628632
.sidebar img {
629633
width: 35px;
630634
margin-top: 5px;

branches/beta/src/libstd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
}
2929

3030
if target.contains("unknown-linux") {
31-
if target.contains("musl") {
31+
if target.contains("musl") && target.contains("x86_64") {
3232
println!("cargo:rustc-link-lib=static=unwind");
3333
} else {
3434
println!("cargo:rustc-link-lib=dl");

branches/beta/src/libsyntax/ext/base.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ pub struct ExtCtxt<'a> {
552552

553553
pub syntax_env: SyntaxEnv,
554554
pub recursion_count: usize,
555+
556+
pub filename: Option<String>,
557+
pub mod_path_stack: Vec<InternedString>,
558+
pub in_block: bool,
555559
}
556560

557561
impl<'a> ExtCtxt<'a> {
@@ -570,6 +574,10 @@ impl<'a> ExtCtxt<'a> {
570574
exported_macros: Vec::new(),
571575
syntax_env: env,
572576
recursion_count: 0,
577+
578+
filename: None,
579+
mod_path_stack: Vec::new(),
580+
in_block: false,
573581
}
574582
}
575583

branches/beta/src/libsyntax/ext/expand.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
11831183
}
11841184

11851185
impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
1186+
fn fold_crate(&mut self, c: Crate) -> Crate {
1187+
self.cx.filename = Some(self.cx.parse_sess.codemap().span_to_filename(c.span));
1188+
noop_fold_crate(c, self)
1189+
}
1190+
11861191
fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
11871192
expand_expr(expr, self)
11881193
}
@@ -1192,7 +1197,27 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
11921197
}
11931198

11941199
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
1195-
expand_item(item, self)
1200+
use std::mem::replace;
1201+
let result;
1202+
if let ast::ItemKind::Mod(ast::Mod { inner, .. }) = item.node {
1203+
if item.span.contains(inner) {
1204+
self.push_mod_path(item.ident, &item.attrs);
1205+
result = expand_item(item, self);
1206+
self.pop_mod_path();
1207+
} else {
1208+
let filename = if inner != codemap::DUMMY_SP {
1209+
Some(self.cx.parse_sess.codemap().span_to_filename(inner))
1210+
} else { None };
1211+
let orig_filename = replace(&mut self.cx.filename, filename);
1212+
let orig_mod_path_stack = replace(&mut self.cx.mod_path_stack, Vec::new());
1213+
result = expand_item(item, self);
1214+
self.cx.filename = orig_filename;
1215+
self.cx.mod_path_stack = orig_mod_path_stack;
1216+
}
1217+
} else {
1218+
result = expand_item(item, self);
1219+
}
1220+
result
11961221
}
11971222

11981223
fn fold_item_kind(&mut self, item: ast::ItemKind) -> ast::ItemKind {
@@ -1204,7 +1229,10 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
12041229
}
12051230

12061231
fn fold_block(&mut self, block: P<Block>) -> P<Block> {
1207-
expand_block(block, self)
1232+
let was_in_block = ::std::mem::replace(&mut self.cx.in_block, true);
1233+
let result = expand_block(block, self);
1234+
self.cx.in_block = was_in_block;
1235+
result
12081236
}
12091237

12101238
fn fold_arm(&mut self, arm: ast::Arm) -> ast::Arm {
@@ -1230,6 +1258,21 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
12301258
}
12311259
}
12321260

1261+
impl<'a, 'b> MacroExpander<'a, 'b> {
1262+
fn push_mod_path(&mut self, id: Ident, attrs: &[ast::Attribute]) {
1263+
let default_path = id.name.as_str();
1264+
let file_path = match ::attr::first_attr_value_str_by_name(attrs, "path") {
1265+
Some(d) => d,
1266+
None => default_path,
1267+
};
1268+
self.cx.mod_path_stack.push(file_path)
1269+
}
1270+
1271+
fn pop_mod_path(&mut self) {
1272+
self.cx.mod_path_stack.pop().unwrap();
1273+
}
1274+
}
1275+
12331276
fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
12341277
/* this discards information in the case of macro-defining macros */
12351278
Span {

branches/beta/src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ext::tt::macro_parser::{Success, Error, Failure};
1616
use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
1717
use ext::tt::macro_parser::parse;
1818
use parse::lexer::new_tt_reader;
19-
use parse::parser::Parser;
19+
use parse::parser::{Parser, Restrictions};
2020
use parse::token::{self, special_idents, gensym_ident, NtTT, Token};
2121
use parse::token::Token::*;
2222
use print;
@@ -195,6 +195,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
195195
imported_from,
196196
rhs);
197197
let mut p = Parser::new(cx.parse_sess(), cx.cfg(), Box::new(trncbr));
198+
p.filename = cx.filename.clone();
199+
p.mod_path_stack = cx.mod_path_stack.clone();
200+
p.restrictions = match cx.in_block {
201+
true => Restrictions::NO_NONINLINE_MOD,
202+
false => Restrictions::empty(),
203+
};
198204
p.check_unknown_macro_variable();
199205
// Let the context choose how to interpret the result.
200206
// Weird, but useful for X-macros.

branches/beta/src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub struct Parser<'a> {
273273
/// extra detail when the same error is seen twice
274274
pub obsolete_set: HashSet<ObsoleteSyntax>,
275275
/// Used to determine the path to externally loaded source files
276+
pub filename: Option<String>,
276277
pub mod_path_stack: Vec<InternedString>,
277278
/// Stack of spans of open delimiters. Used for error message.
278279
pub open_braces: Vec<Span>,
@@ -354,6 +355,9 @@ impl<'a> Parser<'a> {
354355
{
355356
let tok0 = rdr.real_token();
356357
let span = tok0.sp;
358+
let filename = if span != codemap::DUMMY_SP {
359+
Some(sess.codemap().span_to_filename(span))
360+
} else { None };
357361
let placeholder = TokenAndSpan {
358362
tok: token::Underscore,
359363
sp: span,
@@ -382,6 +386,7 @@ impl<'a> Parser<'a> {
382386
quote_depth: 0,
383387
obsolete_set: HashSet::new(),
384388
mod_path_stack: Vec::new(),
389+
filename: filename,
385390
open_braces: Vec::new(),
386391
owns_directory: true,
387392
root_module_name: None,
@@ -5325,7 +5330,7 @@ impl<'a> Parser<'a> {
53255330
id: ast::Ident,
53265331
outer_attrs: &[ast::Attribute],
53275332
id_sp: Span) -> PResult<'a, ModulePathSuccess> {
5328-
let mut prefix = PathBuf::from(&self.sess.codemap().span_to_filename(self.span));
5333+
let mut prefix = PathBuf::from(self.filename.as_ref().unwrap());
53295334
prefix.pop();
53305335
let mut dir_path = prefix;
53315336
for part in &self.mod_path_stack {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 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+
// Test that macro-expanded non-inline modules behave correctly
12+
13+
macro_rules! mod_decl {
14+
($i:ident) => { mod $i; }
15+
}
16+
17+
mod macro_expanded_mod_helper {
18+
mod_decl!(foo); // This should search in the folder `macro_expanded_mod_helper`
19+
}
20+
21+
fn main() {
22+
mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2016 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+
// ignore-test
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2016 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+
// ignore-test
12+
13+
mod_decl!(bar);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 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+
const ERROR_CONST: bool = true;
12+
13+
fn get() -> bool {
14+
false || ERROR_CONST
15+
}
16+
17+
pub fn main() {
18+
assert_eq!(get(), true);
19+
}

branches/beta/src/test/rustdoc/issue-27362.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// aux-build:issue-27362.rs
1212
// ignore-cross-compile
13+
// ignore-test This test fails on beta/stable #32019
1314

1415
extern crate issue_27362;
1516
pub use issue_27362 as quux;

0 commit comments

Comments
 (0)