Skip to content

Commit

Permalink
Auto merge of #33005 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

- Successful merges: #32923, #32926, #32929, #32931, #32935, #32945, #32946, #32964, #32970, #32973, #32997
- Failed merges:
  • Loading branch information
bors committed Apr 15, 2016
2 parents 9debf51 + e563359 commit 576229f
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 79 deletions.
53 changes: 40 additions & 13 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import argparse
import contextlib
import hashlib
import os
import shutil
import subprocess
Expand All @@ -18,13 +19,29 @@

def get(url, path, verbose=False):
print("downloading " + url)
# see http://serverfault.com/questions/301128/how-to-download
if sys.platform == 'win32':
run(["PowerShell.exe", "/nologo", "-Command",
"(New-Object System.Net.WebClient).DownloadFile('" + url +
"', '" + path + "')"], verbose=verbose)
else:
run(["curl", "-o", path, url], verbose=verbose)
sha_url = url + ".sha256"
sha_path = path + ".sha256"
for _url, _path in ((url, path), (sha_url, sha_path)):
# see http://serverfault.com/questions/301128/how-to-download
if sys.platform == 'win32':
run(["PowerShell.exe", "/nologo", "-Command",
"(New-Object System.Net.WebClient)"
".DownloadFile('{}', '{}')".format(_url, _path)],
verbose=verbose)
else:
run(["curl", "-o", _path, _url], verbose=verbose)
print("verifying " + path)
with open(path, "rb") as f:
found = hashlib.sha256(f.read()).hexdigest()
with open(sha_path, "r") as f:
expected, _ = f.readline().split()
if found != expected:
err = ("invalid checksum:\n"
" found: {}\n"
" expected: {}".format(found, expected))
if verbose:
raise RuntimeError(err)
sys.exit(err)

def unpack(tarball, dst, verbose=False, match=None):
print("extracting " + tarball)
Expand Down Expand Up @@ -57,9 +74,10 @@ def run(args, verbose=False):
ret = subprocess.Popen(args)
code = ret.wait()
if code != 0:
if not verbose:
print("failed to run: " + ' '.join(args))
raise RuntimeError("failed to run command")
err = "failed to run: " + ' '.join(args)
if verbose:
raise RuntimeError(err)
sys.exit(err)

class RustBuild:
def download_rust_nightly(self):
Expand Down Expand Up @@ -210,7 +228,10 @@ def build_triple(self):
if sys.platform == 'win32':
return 'x86_64-pc-windows-msvc'
else:
raise
err = "uname not found"
if self.verbose:
raise Exception(err)
sys.exit(err)

# Darwin's `uname -s` lies and always returns i386. We have to use
# sysctl instead.
Expand Down Expand Up @@ -253,7 +274,10 @@ def build_triple(self):
cputype = 'x86_64'
ostype = 'pc-windows-gnu'
else:
raise ValueError("unknown OS type: " + ostype)
err = "unknown OS type: " + ostype
if self.verbose:
raise ValueError(err)
sys.exit(err)

if cputype in {'i386', 'i486', 'i686', 'i786', 'x86'}:
cputype = 'i686'
Expand All @@ -269,7 +293,10 @@ def build_triple(self):
elif cputype in {'amd64', 'x86_64', 'x86-64', 'x64'}:
cputype = 'x86_64'
else:
raise ValueError("unknown cpu type: " + cputype)
err = "unknown cpu type: " + cputype
if self.verbose:
raise ValueError(err)
sys.exit(err)

return cputype + '-' + ostype

Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ fn factory() -> Box<Fn(i32) -> i32> {

Box::new(move |x| x + num)
}
# fn main() {
fn main() {
let f = factory();

let answer = f(1);
assert_eq!(6, answer);
# }
}
```

By making the inner closure a `move Fn`, we create a new stack frame for our
Expand Down
4 changes: 4 additions & 0 deletions src/doc/book/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,12 @@ look something like this:
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]

[dependencies]
```

Do not worry about the `[dependencies]` line, we will come back to it later.

Cargo has populated *Cargo.toml* with reasonable defaults based on the arguments
you gave it and your `git` global configuration. You may notice that Cargo has
also initialized the `hello_world` directory as a `git` repository.
Expand Down
6 changes: 4 additions & 2 deletions src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ mod imp {
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
} else {
let new_ptr = allocate(size, align);
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
deallocate(ptr, old_size, align);
if !new_ptr.is_null() {
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
deallocate(ptr, old_size, align);
}
new_ptr
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ E0072: r##"
When defining a recursive struct or enum, any use of the type being defined
from inside the definition must occur behind a pointer (like `Box` or `&`).
This is because structs and enums must have a well-defined size, and without
the pointer the size of the type would need to be unbounded.
the pointer, the size of the type would need to be unbounded.
Consider the following erroneous definition of a type for a list of bytes:
Expand Down
20 changes: 13 additions & 7 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,19 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
match self.items.items[item_index] {
Some(original_def_id) if original_def_id != item_def_id => {
let cstore = &self.session.cstore;
let span = self.ast_map.span_if_local(item_def_id)
.expect("we should have found local duplicate earlier");
let mut err = struct_span_err!(self.session,
span,
E0152,
"duplicate lang item found: `{}`.",
LanguageItems::item_name(item_index));
let name = LanguageItems::item_name(item_index);
let mut err = match self.ast_map.span_if_local(item_def_id) {
Some(span) => struct_span_err!(
self.session,
span,
E0152,
"duplicate lang item found: `{}`.",
name),
None => self.session.struct_err(&format!(
"duplicate lang item in crate `{}`: `{}`.",
cstore.crate_name(item_def_id.krate),
name)),
};
if let Some(span) = self.ast_map.span_if_local(original_def_id) {
span_note!(&mut err, span,
"first defined here.");
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,19 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
debug!("get_fn: not casting pointer!");

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

llfn
};

// Always insert into item_symbols, in case this item is exported.
if let Some(id) = local_item {
ccx.item_symbols().borrow_mut().insert(id, sym);
}

ccx.instances().borrow_mut().insert(instance, llfn);

immediate_rvalue(llfn, fn_ptr_ty)
Expand Down
15 changes: 7 additions & 8 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
}

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

match link {
AssocItemLink::Anchor if !is_static || render_static => {
document(w, cx, item)
},
_ => Ok(()),
if !is_default_item && (!is_static || render_static) {
document(w, cx, item)
} else {
Ok(())
}
}

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

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

doctraititem(w, cx, trait_item, assoc_link, render_static,
doctraititem(w, cx, trait_item, assoc_link, render_static, true,
outer_version)?;
}
Ok(())
Expand Down
17 changes: 9 additions & 8 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,13 @@ pub fn expand_item_mac(it: P<ast::Item>,

/// Expand a stmt
fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
// perform all pending renames
let stmt = {
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
let mut rename_fld = IdentRenamer{renames:pending_renames};
rename_fld.fold_stmt(stmt).expect_one("rename_fold didn't return one value")
};

let (mac, style, attrs) = match stmt.node {
StmtKind::Mac(mac, style, attrs) => (mac, style, attrs),
_ => return expand_non_macro_stmt(stmt, fld)
Expand Down Expand Up @@ -717,14 +724,8 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> {
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
b.map(|Block {id, stmts, expr, rules, span}| {
let new_stmts = stmts.into_iter().flat_map(|x| {
// perform all pending renames
let renamed_stmt = {
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
let mut rename_fld = IdentRenamer{renames:pending_renames};
rename_fld.fold_stmt(x).expect_one("rename_fold didn't return one value")
};
// expand macros in the statement
fld.fold_stmt(renamed_stmt).into_iter()
// perform pending renames and expand macros in the statement
fld.fold_stmt(x).into_iter()
}).collect();
let new_expr = expr.map(|x| {
let expr = {
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result<bool, String> {
match *tok {
OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) |
Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true),
MatchNt(_, ref frag, _, _) if frag.name.as_str() == "block" => Ok(true),
Ident(i, _) if (i.name.as_str() == "as" ||
i.name.as_str() == "where") => Ok(true),
_ => Ok(false)
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use std::cmp;
// The version numbers here correspond to the version in which the current status
// was set. This is most important for knowing when a particular feature became
// stable (active).
// NB: The featureck.py script parses this information directly out of the source
// so take care when modifying it.
// NB: The tidy tool parses this information directly out of the source so take
// care when modifying it.
const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status)] = &[
("globs", "1.0.0", None, Accepted),
("macro_rules", "1.0.0", None, Accepted),
Expand Down
27 changes: 27 additions & 0 deletions src/test/auxiliary/foreign_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![crate_name="foreign_lib"]

#![feature(libc)]

pub mod rustrt {
Expand All @@ -19,3 +20,29 @@ pub mod rustrt {
pub fn rust_get_test_int() -> libc::intptr_t;
}
}

pub mod rustrt2 {
extern crate libc;

extern {
pub fn rust_get_test_int() -> libc::intptr_t;
}
}

pub mod rustrt3 {
// Different type, but same ABI (on all supported platforms).
// Ensures that we don't ICE or trigger LLVM asserts when
// importing the same symbol under different types.
// See https://github.com/rust-lang/rust/issues/32740.
extern {
pub fn rust_get_test_int() -> *const u8;
}
}

pub fn local_uses() {
unsafe {
let x = rustrt::rust_get_test_int();
assert_eq!(x, rustrt2::rust_get_test_int());
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
}
}
41 changes: 41 additions & 0 deletions src/test/compile-fail/issue-32922.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(rustc_attrs)]
#![allow(warnings)]

macro_rules! foo { () => {
let x = 1;
macro_rules! bar { () => {x} }
let _ = bar!();
}}

macro_rules! bar { // test issue #31856
($n:ident) => (
let a = 1;
let $n = a;
)
}

macro_rules! baz {
($i:ident) => {
let mut $i = 2;
$i = $i + 1;
}
}

#[rustc_error]
fn main() { //~ ERROR compilation successful
foo! {};
bar! {};

let mut a = true;
baz!(a);
}
6 changes: 3 additions & 3 deletions src/test/compile-fail/macro-follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ macro_rules! follow_expr {
($e:expr $m:meta) => {}; //~ERROR `$e:expr` is followed by `$m:meta`
}
// FOLLOW(ty) = {OpenDelim(Brace), Comma, FatArrow, Colon, Eq, Gt, Semi, Or,
// Ident(as), Ident(where), OpenDelim(Bracket)}
// Ident(as), Ident(where), OpenDelim(Bracket), Nonterminal(Block)}
macro_rules! follow_ty {
($t:ty ()) => {}; //~WARN `$t:ty` is followed by `(`
($t:ty []) => {}; // ok (RFC 1462)
Expand All @@ -67,7 +67,7 @@ macro_rules! follow_ty {
($t:ty $t:ty) => {}; //~ERROR `$t:ty` is followed by `$t:ty`
($t:ty $s:stmt) => {}; //~ERROR `$t:ty` is followed by `$s:stmt`
($t:ty $p:path) => {}; //~ERROR `$t:ty` is followed by `$p:path`
($t:ty $b:block) => {}; //~ERROR `$t:ty` is followed by `$b:block`
($t:ty $b:block) => {}; // ok (RFC 1494)
($t:ty $i:ident) => {}; //~ERROR `$t:ty` is followed by `$i:ident`
($t:ty $t:tt) => {}; //~ERROR `$t:ty` is followed by `$t:tt`
($t:ty $i:item) => {}; //~ERROR `$t:ty` is followed by `$i:item`
Expand Down Expand Up @@ -109,7 +109,7 @@ macro_rules! follow_path {
($p:path $t:ty) => {}; //~ERROR `$p:path` is followed by `$t:ty`
($p:path $s:stmt) => {}; //~ERROR `$p:path` is followed by `$s:stmt`
($p:path $p:path) => {}; //~ERROR `$p:path` is followed by `$p:path`
($p:path $b:block) => {}; //~ERROR `$p:path` is followed by `$b:block`
($p:path $b:block) => {}; // ok (RFC 1494)
($p:path $i:ident) => {}; //~ERROR `$p:path` is followed by `$i:ident`
($p:path $t:tt) => {}; //~ERROR `$p:path` is followed by `$t:tt`
($p:path $i:item) => {}; //~ERROR `$p:path` is followed by `$i:item`
Expand Down
Loading

0 comments on commit 576229f

Please sign in to comment.