Skip to content

Commit 576229f

Browse files
committed
Auto merge of #33005 - Manishearth:rollup, r=Manishearth
Rollup of 11 pull requests - Successful merges: #32923, #32926, #32929, #32931, #32935, #32945, #32946, #32964, #32970, #32973, #32997 - Failed merges:
2 parents 9debf51 + e563359 commit 576229f

File tree

17 files changed

+248
-79
lines changed

17 files changed

+248
-79
lines changed

src/bootstrap/bootstrap.py

+40-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import argparse
1212
import contextlib
13+
import hashlib
1314
import os
1415
import shutil
1516
import subprocess
@@ -18,13 +19,29 @@
1819

1920
def get(url, path, verbose=False):
2021
print("downloading " + url)
21-
# see http://serverfault.com/questions/301128/how-to-download
22-
if sys.platform == 'win32':
23-
run(["PowerShell.exe", "/nologo", "-Command",
24-
"(New-Object System.Net.WebClient).DownloadFile('" + url +
25-
"', '" + path + "')"], verbose=verbose)
26-
else:
27-
run(["curl", "-o", path, url], verbose=verbose)
22+
sha_url = url + ".sha256"
23+
sha_path = path + ".sha256"
24+
for _url, _path in ((url, path), (sha_url, sha_path)):
25+
# see http://serverfault.com/questions/301128/how-to-download
26+
if sys.platform == 'win32':
27+
run(["PowerShell.exe", "/nologo", "-Command",
28+
"(New-Object System.Net.WebClient)"
29+
".DownloadFile('{}', '{}')".format(_url, _path)],
30+
verbose=verbose)
31+
else:
32+
run(["curl", "-o", _path, _url], verbose=verbose)
33+
print("verifying " + path)
34+
with open(path, "rb") as f:
35+
found = hashlib.sha256(f.read()).hexdigest()
36+
with open(sha_path, "r") as f:
37+
expected, _ = f.readline().split()
38+
if found != expected:
39+
err = ("invalid checksum:\n"
40+
" found: {}\n"
41+
" expected: {}".format(found, expected))
42+
if verbose:
43+
raise RuntimeError(err)
44+
sys.exit(err)
2845

2946
def unpack(tarball, dst, verbose=False, match=None):
3047
print("extracting " + tarball)
@@ -57,9 +74,10 @@ def run(args, verbose=False):
5774
ret = subprocess.Popen(args)
5875
code = ret.wait()
5976
if code != 0:
60-
if not verbose:
61-
print("failed to run: " + ' '.join(args))
62-
raise RuntimeError("failed to run command")
77+
err = "failed to run: " + ' '.join(args)
78+
if verbose:
79+
raise RuntimeError(err)
80+
sys.exit(err)
6381

6482
class RustBuild:
6583
def download_rust_nightly(self):
@@ -210,7 +228,10 @@ def build_triple(self):
210228
if sys.platform == 'win32':
211229
return 'x86_64-pc-windows-msvc'
212230
else:
213-
raise
231+
err = "uname not found"
232+
if self.verbose:
233+
raise Exception(err)
234+
sys.exit(err)
214235

215236
# Darwin's `uname -s` lies and always returns i386. We have to use
216237
# sysctl instead.
@@ -253,7 +274,10 @@ def build_triple(self):
253274
cputype = 'x86_64'
254275
ostype = 'pc-windows-gnu'
255276
else:
256-
raise ValueError("unknown OS type: " + ostype)
277+
err = "unknown OS type: " + ostype
278+
if self.verbose:
279+
raise ValueError(err)
280+
sys.exit(err)
257281

258282
if cputype in {'i386', 'i486', 'i686', 'i786', 'x86'}:
259283
cputype = 'i686'
@@ -269,7 +293,10 @@ def build_triple(self):
269293
elif cputype in {'amd64', 'x86_64', 'x86-64', 'x64'}:
270294
cputype = 'x86_64'
271295
else:
272-
raise ValueError("unknown cpu type: " + cputype)
296+
err = "unknown cpu type: " + cputype
297+
if self.verbose:
298+
raise ValueError(err)
299+
sys.exit(err)
273300

274301
return cputype + '-' + ostype
275302

src/doc/book/closures.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,12 @@ fn factory() -> Box<Fn(i32) -> i32> {
492492

493493
Box::new(move |x| x + num)
494494
}
495-
# fn main() {
495+
fn main() {
496496
let f = factory();
497497

498498
let answer = f(1);
499499
assert_eq!(6, answer);
500-
# }
500+
}
501501
```
502502

503503
By making the inner closure a `move Fn`, we create a new stack frame for our

src/doc/book/getting-started.md

+4
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,12 @@ look something like this:
575575
name = "hello_world"
576576
version = "0.1.0"
577577
authors = ["Your Name <you@example.com>"]
578+
579+
[dependencies]
578580
```
579581

582+
Do not worry about the `[dependencies]` line, we will come back to it later.
583+
580584
Cargo has populated *Cargo.toml* with reasonable defaults based on the arguments
581585
you gave it and your `git` global configuration. You may notice that Cargo has
582586
also initialized the `hello_world` directory as a `git` repository.

src/liballoc_system/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ mod imp {
9696
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
9797
} else {
9898
let new_ptr = allocate(size, align);
99-
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
100-
deallocate(ptr, old_size, align);
99+
if !new_ptr.is_null() {
100+
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
101+
deallocate(ptr, old_size, align);
102+
}
101103
new_ptr
102104
}
103105
}

src/librustc/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ E0072: r##"
292292
When defining a recursive struct or enum, any use of the type being defined
293293
from inside the definition must occur behind a pointer (like `Box` or `&`).
294294
This is because structs and enums must have a well-defined size, and without
295-
the pointer the size of the type would need to be unbounded.
295+
the pointer, the size of the type would need to be unbounded.
296296
297297
Consider the following erroneous definition of a type for a list of bytes:
298298

src/librustc/middle/lang_items.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,19 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
189189
match self.items.items[item_index] {
190190
Some(original_def_id) if original_def_id != item_def_id => {
191191
let cstore = &self.session.cstore;
192-
let span = self.ast_map.span_if_local(item_def_id)
193-
.expect("we should have found local duplicate earlier");
194-
let mut err = struct_span_err!(self.session,
195-
span,
196-
E0152,
197-
"duplicate lang item found: `{}`.",
198-
LanguageItems::item_name(item_index));
192+
let name = LanguageItems::item_name(item_index);
193+
let mut err = match self.ast_map.span_if_local(item_def_id) {
194+
Some(span) => struct_span_err!(
195+
self.session,
196+
span,
197+
E0152,
198+
"duplicate lang item found: `{}`.",
199+
name),
200+
None => self.session.struct_err(&format!(
201+
"duplicate lang item in crate `{}`: `{}`.",
202+
cstore.crate_name(item_def_id.krate),
203+
name)),
204+
};
199205
if let Some(span) = self.ast_map.span_if_local(original_def_id) {
200206
span_note!(&mut err, span,
201207
"first defined here.");

src/librustc_trans/callee.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -582,15 +582,19 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
582582
debug!("get_fn: not casting pointer!");
583583

584584
attributes::from_fn_attrs(ccx, attrs, llfn);
585-
if let Some(id) = local_item {
585+
if local_item.is_some() {
586586
// FIXME(eddyb) Doubt all extern fn should allow unwinding.
587587
attributes::unwind(llfn, true);
588-
ccx.item_symbols().borrow_mut().insert(id, sym);
589588
}
590589

591590
llfn
592591
};
593592

593+
// Always insert into item_symbols, in case this item is exported.
594+
if let Some(id) = local_item {
595+
ccx.item_symbols().borrow_mut().insert(id, sym);
596+
}
597+
594598
ccx.instances().borrow_mut().insert(instance, llfn);
595599

596600
immediate_rvalue(llfn, fn_ptr_ty)

src/librustdoc/html/render.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
24892489
}
24902490

24912491
fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
2492-
link: AssocItemLink, render_static: bool,
2492+
link: AssocItemLink, render_static: bool, is_default_item: bool,
24932493
outer_version: Option<&str>) -> fmt::Result {
24942494
let shortty = shortty(item);
24952495
let name = item.name.as_ref().unwrap();
@@ -2540,17 +2540,16 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
25402540
_ => panic!("can't make docs for trait item with name {:?}", item.name)
25412541
}
25422542

2543-
match link {
2544-
AssocItemLink::Anchor if !is_static || render_static => {
2545-
document(w, cx, item)
2546-
},
2547-
_ => Ok(()),
2543+
if !is_default_item && (!is_static || render_static) {
2544+
document(w, cx, item)
2545+
} else {
2546+
Ok(())
25482547
}
25492548
}
25502549

25512550
write!(w, "<div class='impl-items'>")?;
25522551
for trait_item in &i.impl_.items {
2553-
doctraititem(w, cx, trait_item, link, render_header, outer_version)?;
2552+
doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?;
25542553
}
25552554

25562555
fn render_default_items(w: &mut fmt::Formatter,
@@ -2567,7 +2566,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
25672566
let did = i.trait_.as_ref().unwrap().def_id().unwrap();
25682567
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);
25692568

2570-
doctraititem(w, cx, trait_item, assoc_link, render_static,
2569+
doctraititem(w, cx, trait_item, assoc_link, render_static, true,
25712570
outer_version)?;
25722571
}
25732572
Ok(())

src/libsyntax/ext/expand.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ pub fn expand_item_mac(it: P<ast::Item>,
504504

505505
/// Expand a stmt
506506
fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
507+
// perform all pending renames
508+
let stmt = {
509+
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
510+
let mut rename_fld = IdentRenamer{renames:pending_renames};
511+
rename_fld.fold_stmt(stmt).expect_one("rename_fold didn't return one value")
512+
};
513+
507514
let (mac, style, attrs) = match stmt.node {
508515
StmtKind::Mac(mac, style, attrs) => (mac, style, attrs),
509516
_ => return expand_non_macro_stmt(stmt, fld)
@@ -717,14 +724,8 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> {
717724
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
718725
b.map(|Block {id, stmts, expr, rules, span}| {
719726
let new_stmts = stmts.into_iter().flat_map(|x| {
720-
// perform all pending renames
721-
let renamed_stmt = {
722-
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
723-
let mut rename_fld = IdentRenamer{renames:pending_renames};
724-
rename_fld.fold_stmt(x).expect_one("rename_fold didn't return one value")
725-
};
726-
// expand macros in the statement
727-
fld.fold_stmt(renamed_stmt).into_iter()
727+
// perform pending renames and expand macros in the statement
728+
fld.fold_stmt(x).into_iter()
728729
}).collect();
729730
let new_expr = expr.map(|x| {
730731
let expr = {

src/libsyntax/ext/tt/macro_rules.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result<bool, String> {
10141014
match *tok {
10151015
OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) |
10161016
Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true),
1017+
MatchNt(_, ref frag, _, _) if frag.name.as_str() == "block" => Ok(true),
10171018
Ident(i, _) if (i.name.as_str() == "as" ||
10181019
i.name.as_str() == "where") => Ok(true),
10191020
_ => Ok(false)

src/libsyntax/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use std::cmp;
4545
// The version numbers here correspond to the version in which the current status
4646
// was set. This is most important for knowing when a particular feature became
4747
// stable (active).
48-
// NB: The featureck.py script parses this information directly out of the source
49-
// so take care when modifying it.
48+
// NB: The tidy tool parses this information directly out of the source so take
49+
// care when modifying it.
5050
const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status)] = &[
5151
("globs", "1.0.0", None, Accepted),
5252
("macro_rules", "1.0.0", None, Accepted),

src/test/auxiliary/foreign_lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![crate_name="foreign_lib"]
12+
1213
#![feature(libc)]
1314

1415
pub mod rustrt {
@@ -19,3 +20,29 @@ pub mod rustrt {
1920
pub fn rust_get_test_int() -> libc::intptr_t;
2021
}
2122
}
23+
24+
pub mod rustrt2 {
25+
extern crate libc;
26+
27+
extern {
28+
pub fn rust_get_test_int() -> libc::intptr_t;
29+
}
30+
}
31+
32+
pub mod rustrt3 {
33+
// Different type, but same ABI (on all supported platforms).
34+
// Ensures that we don't ICE or trigger LLVM asserts when
35+
// importing the same symbol under different types.
36+
// See https://github.com/rust-lang/rust/issues/32740.
37+
extern {
38+
pub fn rust_get_test_int() -> *const u8;
39+
}
40+
}
41+
42+
pub fn local_uses() {
43+
unsafe {
44+
let x = rustrt::rust_get_test_int();
45+
assert_eq!(x, rustrt2::rust_get_test_int());
46+
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
47+
}
48+
}

src/test/compile-fail/issue-32922.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#![feature(rustc_attrs)]
12+
#![allow(warnings)]
13+
14+
macro_rules! foo { () => {
15+
let x = 1;
16+
macro_rules! bar { () => {x} }
17+
let _ = bar!();
18+
}}
19+
20+
macro_rules! bar { // test issue #31856
21+
($n:ident) => (
22+
let a = 1;
23+
let $n = a;
24+
)
25+
}
26+
27+
macro_rules! baz {
28+
($i:ident) => {
29+
let mut $i = 2;
30+
$i = $i + 1;
31+
}
32+
}
33+
34+
#[rustc_error]
35+
fn main() { //~ ERROR compilation successful
36+
foo! {};
37+
bar! {};
38+
39+
let mut a = true;
40+
baz!(a);
41+
}

src/test/compile-fail/macro-follow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ macro_rules! follow_expr {
5555
($e:expr $m:meta) => {}; //~ERROR `$e:expr` is followed by `$m:meta`
5656
}
5757
// FOLLOW(ty) = {OpenDelim(Brace), Comma, FatArrow, Colon, Eq, Gt, Semi, Or,
58-
// Ident(as), Ident(where), OpenDelim(Bracket)}
58+
// Ident(as), Ident(where), OpenDelim(Bracket), Nonterminal(Block)}
5959
macro_rules! follow_ty {
6060
($t:ty ()) => {}; //~WARN `$t:ty` is followed by `(`
6161
($t:ty []) => {}; // ok (RFC 1462)
@@ -67,7 +67,7 @@ macro_rules! follow_ty {
6767
($t:ty $t:ty) => {}; //~ERROR `$t:ty` is followed by `$t:ty`
6868
($t:ty $s:stmt) => {}; //~ERROR `$t:ty` is followed by `$s:stmt`
6969
($t:ty $p:path) => {}; //~ERROR `$t:ty` is followed by `$p:path`
70-
($t:ty $b:block) => {}; //~ERROR `$t:ty` is followed by `$b:block`
70+
($t:ty $b:block) => {}; // ok (RFC 1494)
7171
($t:ty $i:ident) => {}; //~ERROR `$t:ty` is followed by `$i:ident`
7272
($t:ty $t:tt) => {}; //~ERROR `$t:ty` is followed by `$t:tt`
7373
($t:ty $i:item) => {}; //~ERROR `$t:ty` is followed by `$i:item`
@@ -109,7 +109,7 @@ macro_rules! follow_path {
109109
($p:path $t:ty) => {}; //~ERROR `$p:path` is followed by `$t:ty`
110110
($p:path $s:stmt) => {}; //~ERROR `$p:path` is followed by `$s:stmt`
111111
($p:path $p:path) => {}; //~ERROR `$p:path` is followed by `$p:path`
112-
($p:path $b:block) => {}; //~ERROR `$p:path` is followed by `$b:block`
112+
($p:path $b:block) => {}; // ok (RFC 1494)
113113
($p:path $i:ident) => {}; //~ERROR `$p:path` is followed by `$i:ident`
114114
($p:path $t:tt) => {}; //~ERROR `$p:path` is followed by `$t:tt`
115115
($p:path $i:item) => {}; //~ERROR `$p:path` is followed by `$i:item`

0 commit comments

Comments
 (0)