Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #40726

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ use channel;
use util::{cp_r, libdir, is_dylib, cp_filtered, copy, exe};

fn pkgname(build: &Build, component: &str) -> String {
assert!(component.starts_with("rust")); // does not work with cargo
format!("{}-{}", component, build.rust_package_vers())
if component == "cargo" {
format!("{}-{}", component, build.cargo_package_vers())
} else {
assert!(component.starts_with("rust"));
format!("{}-{}", component, build.rust_package_vers())
}
}

fn distdir(build: &Build) -> PathBuf {
Expand Down Expand Up @@ -533,7 +537,7 @@ pub fn cargo(build: &Build, stage: u32, target: &str) {
let src = build.src.join("cargo");
let etc = src.join("src/etc");
let release_num = build.cargo_release_num();
let name = format!("cargo-{}", build.package_vers(&release_num));
let name = pkgname(build, "cargo");
let version = build.cargo_info.version(build, &release_num);

let tmp = tmpdir(build);
Expand Down Expand Up @@ -591,12 +595,11 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
println!("Dist extended stage{} ({})", stage, target);

let dist = distdir(build);
let cargo_vers = build.cargo_release_num();
let rustc_installer = dist.join(format!("{}-{}.tar.gz",
pkgname(build, "rustc"),
target));
let cargo_installer = dist.join(format!("cargo-{}-{}.tar.gz",
build.package_vers(&cargo_vers),
let cargo_installer = dist.join(format!("{}-{}.tar.gz",
pkgname(build, "cargo"),
target));
let docs_installer = dist.join(format!("{}-{}.tar.gz",
pkgname(build, "rust-docs"),
Expand Down Expand Up @@ -674,7 +677,7 @@ pub fn extended(build: &Build, stage: u32, target: &str) {

cp_r(&work.join(&format!("{}-{}", pkgname(build, "rustc"), target)),
&pkg.join("rustc"));
cp_r(&work.join(&format!("cargo-nightly-{}", target)),
cp_r(&work.join(&format!("{}-{}", pkgname(build, "cargo"), target)),
&pkg.join("cargo"));
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-docs"), target)),
&pkg.join("rust-docs"));
Expand Down Expand Up @@ -726,7 +729,7 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rustc"), target))
.join("rustc"),
&exe.join("rustc"));
cp_r(&work.join(&format!("cargo-nightly-{}", target))
cp_r(&work.join(&format!("{}-{}", pkgname(build, "cargo"), target))
.join("cargo"),
&exe.join("cargo"));
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-docs"), target))
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,11 @@ impl Build {
self.package_vers(channel::CFG_RELEASE_NUM)
}

/// Returns the value of `package_vers` above for Cargo
fn cargo_package_vers(&self) -> String {
self.package_vers(&self.cargo_release_num())
}

/// Returns the `version` string associated with this compiler for Rust
/// itself.
///
Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/dist-x86-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN yum upgrade -y && yum install -y \
curl \
bzip2 \
gcc \
gcc-c++ \
make \
glibc-devel \
perl \
Expand Down
12 changes: 7 additions & 5 deletions src/ci/docker/dist-x86-linux/build-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ set -ex

source shared.sh

curl https://ftp.gnu.org/gnu/gcc/gcc-4.7.4/gcc-4.7.4.tar.bz2 | tar xjf -
cd gcc-4.7.4
GCC=4.8.5

curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.bz2 | tar xjf -
cd gcc-$GCC
./contrib/download_prerequisites
mkdir ../gcc-build
cd ../gcc-build
hide_output ../gcc-4.7.4/configure \
hide_output ../gcc-$GCC/configure \
--prefix=/rustroot \
--enable-languages=c,c++
hide_output make -j10
Expand All @@ -27,5 +29,5 @@ ln -nsf gcc /rustroot/bin/cc

cd ..
rm -rf gcc-build
rm -rf gcc-4.7.4
yum erase -y gcc binutils
rm -rf gcc-$GCC
yum erase -y gcc gcc-c++ binutils
31 changes: 31 additions & 0 deletions src/doc/unstable-book/src/sort-unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,35 @@ The tracking issue for this feature is: [#40585]

------------------------

The default `sort` method on slices is stable. In other words, it guarantees
that the original order of equal elements is preserved after sorting. The
method has several undesirable characteristics:

1. It allocates a sizable chunk of memory.
2. If you don't need stability, it is not as performant as it could be.

An alternative is the new `sort_unstable` feature, which includes these
methods for sorting slices:

1. `sort_unstable`
2. `sort_unstable_by`
3. `sort_unstable_by_key`

Unstable sorting is generally faster and makes no allocations. The majority
of real-world sorting needs doesn't require stability, so these methods can
very often come in handy.

Another important difference is that `sort` lives in `libstd` and
`sort_unstable` lives in `libcore`. The reason is that the former makes
allocations and the latter doesn't.

A simple example:

```rust
#![feature(sort_unstable)]

let mut v = [-5, 4, 1, -3, 2];

v.sort_unstable();
assert!(v == [-5, -3, 1, 2, 4]);
```
6 changes: 3 additions & 3 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,13 @@ pub trait Iterator {

/// Creates an iterator that both filters and maps.
///
/// The closure must return an [`Option<T>`]. `filter_map()` creates an
/// The closure must return an [`Option<T>`]. `filter_map` creates an
/// iterator which calls this closure on each element. If the closure
/// returns [`Some(element)`][`Some`], then that element is returned. If the
/// closure returns [`None`], it will try again, and call the closure on the
/// next element, seeing if it will return [`Some`].
///
/// Why `filter_map()` and not just [`filter()`].[`map`]? The key is in this
/// Why `filter_map` and not just [`filter`].[`map`]? The key is in this
/// part:
///
/// [`filter`]: #method.filter
Expand All @@ -534,7 +534,7 @@ pub trait Iterator {
///
/// In other words, it removes the [`Option<T>`] layer automatically. If your
/// mapping is already returning an [`Option<T>`] and you want to skip over
/// [`None`]s, then `filter_map()` is much, much nicer to use.
/// [`None`]s, then `filter_map` is much, much nicer to use.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl fmt::Display for Utf8Error {
Section: Iterators
*/

/// Iterator for the char (representing *Unicode Scalar Values*) of a string
/// Iterator for the char (representing *Unicode Scalar Values*) of a string.
///
/// Created with the method [`chars`].
///
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use hir::def_id::DefId;
use util::nodemap::NodeMap;
use syntax::ast;
use syntax::ext::base::MacroKind;
use syntax_pos::Span;
use hir;

#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down Expand Up @@ -116,6 +117,7 @@ pub type ExportMap = NodeMap<Vec<Export>>;
pub struct Export {
pub name: ast::Name, // The name of the target.
pub def: Def, // The definition of the target.
pub span: Span, // The span of the target definition.
}

impl CtorKind {
Expand Down
19 changes: 6 additions & 13 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl<'a, 'tcx> CrateMetadata {
},
ext.kind()
);
callback(def::Export { name: name, def: def });
callback(def::Export { name: name, def: def, span: DUMMY_SP });
}
}
return
Expand Down Expand Up @@ -720,6 +720,7 @@ impl<'a, 'tcx> CrateMetadata {
callback(def::Export {
def: def,
name: self.item_name(child_index),
span: self.entry(child_index).span.decode(self),
});
}
}
Expand All @@ -732,34 +733,26 @@ impl<'a, 'tcx> CrateMetadata {
}

let def_key = self.def_key(child_index);
let span = child.span.decode(self);
if let (Some(def), Some(name)) =
(self.get_def(child_index), def_key.disambiguated_data.data.get_opt_name()) {
callback(def::Export {
def: def,
name: name,
});
callback(def::Export { def: def, name: name, span: span });
// For non-reexport structs and variants add their constructors to children.
// Reexport lists automatically contain constructors when necessary.
match def {
Def::Struct(..) => {
if let Some(ctor_def_id) = self.get_struct_ctor_def_id(child_index) {
let ctor_kind = self.get_ctor_kind(child_index);
let ctor_def = Def::StructCtor(ctor_def_id, ctor_kind);
callback(def::Export {
def: ctor_def,
name: name,
});
callback(def::Export { def: ctor_def, name: name, span: span });
}
}
Def::Variant(def_id) => {
// Braced variants, unlike structs, generate unusable names in
// value namespace, they are reserved for possible future use.
let ctor_kind = self.get_ctor_kind(child_index);
let ctor_def = Def::VariantCtor(def_id, ctor_kind);
callback(def::Export {
def: ctor_def,
name: name,
});
callback(def::Export { def: ctor_def, name: name, span: span });
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ impl<'a> Resolver<'a> {
let ident = Ident::with_empty_ctxt(name);
let result = self.resolve_ident_in_module(module, ident, MacroNS, false, None);
if let Ok(binding) = result {
self.macro_exports.push(Export { name: name, def: binding.def() });
self.macro_exports.push(Export { name: name, def: binding.def(), span: span });
} else {
span_err!(self.session, span, E0470, "reexported macro not found");
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ impl<'a> Resolver<'a> {

if attr::contains_name(&item.attrs, "macro_export") {
let def = Def::Macro(def_id, MacroKind::Bang);
self.macro_exports.push(Export { name: ident.name, def: def });
self.macro_exports.push(Export { name: ident.name, def: def, span: item.span });
}
}

Expand Down
21 changes: 16 additions & 5 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc::ty;
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
use rustc::hir::def_id::DefId;
use rustc::hir::def::*;
use rustc::util::nodemap::FxHashSet;
use rustc::util::nodemap::FxHashMap;

use syntax::ast::{Ident, NodeId};
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
Expand Down Expand Up @@ -763,10 +763,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
*module.globs.borrow_mut() = Vec::new();

let mut reexports = Vec::new();
let mut exported_macro_names = FxHashMap();
if module as *const _ == self.graph_root as *const _ {
let mut exported_macro_names = FxHashSet();
for export in mem::replace(&mut self.macro_exports, Vec::new()).into_iter().rev() {
if exported_macro_names.insert(export.name) {
let macro_exports = mem::replace(&mut self.macro_exports, Vec::new());
for export in macro_exports.into_iter().rev() {
if exported_macro_names.insert(export.name, export.span).is_none() {
reexports.push(export);
}
}
Expand All @@ -786,7 +787,17 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
if !def.def_id().is_local() {
self.session.cstore.export_macros(def.def_id().krate);
}
reexports.push(Export { name: ident.name, def: def });
if let Def::Macro(..) = def {
if let Some(&span) = exported_macro_names.get(&ident.name) {
let msg =
format!("a macro named `{}` has already been exported", ident);
self.session.struct_span_err(span, &msg)
.span_label(span, &format!("`{}` already exported", ident))
.span_note(binding.span, "previous macro export here")
.emit();
}
}
reexports.push(Export { name: ident.name, def: def, span: binding.span });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,9 @@ impl fmt::Display for clean::ImportSource {
impl fmt::Display for clean::TypeBinding {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if f.alternate() {
write!(f, "{}={:#}", self.name, self.ty)
write!(f, "{} = {:#}", self.name, self.ty)
} else {
write!(f, "{}={}", self.name, self.ty)
write!(f, "{} = {}", self.name, self.ty)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
}
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
write!(w, "<h2 id='deref-methods'>Methods from \
{}&lt;Target={}&gt;</h2>", trait_, type_)?;
{}&lt;Target = {}&gt;</h2>", trait_, type_)?;
RenderMode::ForDeref { mut_: deref_mut_ }
}
};
Expand Down
19 changes: 19 additions & 0 deletions src/test/compile-fail/duplicate-check-macro-exports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2017 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(use_extern_macros)]

pub use std::panic; //~ NOTE previous macro export here

#[macro_export]
macro_rules! panic { () => {} } //~ ERROR a macro named `panic` has already been exported
//~| NOTE `panic` already exported

fn main() {}
18 changes: 18 additions & 0 deletions src/test/run-pass/macro-nested_definition_issue-31946.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 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.

fn main() {
println!("{}", {
macro_rules! foo {
($name:expr) => { concat!("hello ", $name) }
}
foo!("rust")
});
}
28 changes: 28 additions & 0 deletions src/test/rustdoc/doc-assoc-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2017 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.

pub struct Foo<T> {
x: T,
}

pub trait Bar {
type Fuu;

fn foo(foo: Self::Fuu);
}

// @has doc_assoc_item/struct.Foo.html '//*[@class="impl"]' 'impl<T: Bar<Fuu = u32>> Foo<T>'
impl<T: Bar<Fuu = u32>> Foo<T> {
pub fn new(t: T) -> Foo<T> {
Foo {
x: t,
}
}
}
Loading