diff --git a/src/Cargo.lock b/src/Cargo.lock index 80864340960..61f46bfbe5b 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -251,6 +251,14 @@ dependencies = [ "gcc 0.3.50 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "collections" +version = "0.0.0" +dependencies = [ + "alloc 0.0.0", + "core 0.0.0", +] + [[package]] name = "compiler_builtins" version = "0.0.0" @@ -1586,6 +1594,7 @@ dependencies = [ "alloc_jemalloc 0.0.0", "alloc_system 0.0.0", "build_helper 0.1.0", + "collections 0.0.0", "compiler_builtins 0.0.0", "core 0.0.0", "gcc 0.3.50 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 4d58620ca64..f92e6f50eb3 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -550,6 +550,7 @@ pub fn rust_src(build: &Build) { "src/liballoc_jemalloc", "src/liballoc_system", "src/libbacktrace", + "src/libcollections", "src/libcompiler_builtins", "src/libcore", "src/liblibc", diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 23a38f6a896..30f631ca2df 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -254,7 +254,7 @@ pub fn std(build: &Build, stage: u32, target: &str) { // for which docs must be built. if !build.config.compiler_docs { cargo.arg("--no-deps"); - for krate in &["alloc", "core", "std", "std_unicode"] { + for krate in &["alloc", "collections", "core", "std", "std_unicode"] { cargo.arg("-p").arg(krate); // Create all crate output directories first to make sure rustdoc uses // relative links. diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 56cbb4cecf2..dc9dac73627 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -242,11 +242,18 @@ Arguments: let cwd = t!(env::current_dir()); let paths = matches.free[1..].iter().map(|p| cwd.join(p)).collect::>(); + let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| { + if fs::metadata("config.toml").is_ok() { + Some(PathBuf::from("config.toml")) + } else { + None + } + }); // All subcommands can have an optional "Available paths" section if matches.opt_present("verbose") { let flags = Flags::parse(&["build".to_string()]); - let mut config = Config::default(); + let mut config = Config::parse(&flags.build, cfg_file.clone()); config.build = flags.build.clone(); let mut build = Build::new(flags, config); metadata::build(&mut build); @@ -307,14 +314,6 @@ Arguments: }; - let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| { - if fs::metadata("config.toml").is_ok() { - Some(PathBuf::from("config.toml")) - } else { - None - } - }); - let mut stage = matches.opt_str("stage").map(|j| j.parse().unwrap()); if matches.opt_present("incremental") { diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 12daa24e857..78432b6a965 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -154,19 +154,19 @@ token : simple_token | ident | literal | symbol | whitespace token ;

-| | | | | | -|----------|----------|----------|----------|---------| -| abstract | alignof | as | become | box | -| break | const | continue | crate | do | -| else | enum | extern | false | final | -| fn | for | if | impl | in | -| let | loop | macro | match | mod | -| move | mut | offsetof | override | priv | -| proc | pub | pure | ref | return | -| Self | self | sizeof | static | struct | -| super | trait | true | type | typeof | -| unsafe | unsized | use | virtual | where | -| while | yield | | | | +| | | | | | +|----------|----------|----------|----------|----------| +| _ | abstract | alignof | as | become | +| box | break | const | continue | crate | +| do | else | enum | extern | false | +| final | fn | for | if | impl | +| in | let | loop | macro | match | +| mod | move | mut | offsetof | override | +| priv | proc | pub | pure | ref | +| return | Self | self | sizeof | static | +| struct | super | trait | true | type | +| typeof | unsafe | unsized | use | virtual | +| where | while | yield | | | Each of these keywords has special meaning in its grammar, and all of them are diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index d8f742735a8..d7c36829211 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -108,6 +108,7 @@ - [char_escape_debug](library-features/char-escape-debug.md) - [coerce_unsized](library-features/coerce-unsized.md) - [collection_placement](library-features/collection-placement.md) + - [collections](library-features/collections.md) - [collections_range](library-features/collections-range.md) - [command_envs](library-features/command-envs.md) - [compiler_builtins_lib](library-features/compiler-builtins-lib.md) diff --git a/src/doc/unstable-book/src/library-features/collections.md b/src/doc/unstable-book/src/library-features/collections.md new file mode 100644 index 00000000000..5c937833c9e --- /dev/null +++ b/src/doc/unstable-book/src/library-features/collections.md @@ -0,0 +1,5 @@ +# `collections` + +This feature is internal to the Rust compiler and is not intended for general use. + +------------------------ diff --git a/src/libcollections/Cargo.toml b/src/libcollections/Cargo.toml new file mode 100644 index 00000000000..800e36161d2 --- /dev/null +++ b/src/libcollections/Cargo.toml @@ -0,0 +1,12 @@ +[package] +authors = ["The Rust Project Developers"] +name = "collections" +version = "0.0.0" + +[lib] +name = "collections" +path = "lib.rs" + +[dependencies] +alloc = { path = "../liballoc" } +core = { path = "../libcore" } diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs new file mode 100644 index 00000000000..de5d6df328c --- /dev/null +++ b/src/libcollections/lib.rs @@ -0,0 +1,72 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "collections"] +#![crate_type = "rlib"] +#![allow(unused_attributes)] +#![unstable(feature = "collections", + reason = "this library is unlikely to be stabilized in its current \ + form or name", + issue = "27783")] +#![rustc_deprecated(since = "1.20.0", + reason = "collections moved to `alloc`")] +#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "https://doc.rust-lang.org/favicon.ico", + html_root_url = "https://doc.rust-lang.org/nightly/", + issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", + test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] +#![no_std] +#![needs_allocator] +#![deny(warnings)] + +#![feature(alloc)] +#![feature(collections_range)] +#![feature(macro_reexport)] +#![feature(needs_allocator)] +#![feature(staged_api)] + +//! Collection types +//! +//! See [`std::collections`](../std/collections/index.html) for a detailed +//! discussion of collections in Rust. + +#[macro_reexport(vec, format)] +extern crate alloc; + +pub use alloc::Bound; + +pub use alloc::binary_heap; +pub use alloc::borrow; +pub use alloc::fmt; +pub use alloc::linked_list; +pub use alloc::range; +pub use alloc::slice; +pub use alloc::str; +pub use alloc::string; +pub use alloc::vec; +pub use alloc::vec_deque; + +pub use alloc::btree_map; +pub use alloc::btree_set; + +#[doc(no_inline)] +pub use alloc::binary_heap::BinaryHeap; +#[doc(no_inline)] +pub use alloc::btree_map::BTreeMap; +#[doc(no_inline)] +pub use alloc::btree_set::BTreeSet; +#[doc(no_inline)] +pub use alloc::linked_list::LinkedList; +#[doc(no_inline)] +pub use alloc::vec_deque::VecDeque; +#[doc(no_inline)] +pub use alloc::string::String; +#[doc(no_inline)] +pub use alloc::vec::Vec; diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 4918e37eb35..5a007285e48 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -618,7 +618,10 @@ impl<'a, 'b> StrSearcher<'a, 'b> { } unsafe impl<'a, 'b> Searcher<'a> for StrSearcher<'a, 'b> { - fn haystack(&self) -> &'a str { self.haystack } + #[inline] + fn haystack(&self) -> &'a str { + self.haystack + } #[inline] fn next(&mut self) -> SearchStep { diff --git a/src/librustc_const_eval/_match.rs b/src/librustc_const_eval/_match.rs index c1dc5f5f7a2..98d90188312 100644 --- a/src/librustc_const_eval/_match.rs +++ b/src/librustc_const_eval/_match.rs @@ -774,21 +774,26 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>, }, ty::TyRef(_, ref ty_and_mut) => vec![ty_and_mut.ty], ty::TyAdt(adt, substs) => { - adt.variants[ctor.variant_index_for_adt(adt)].fields.iter().map(|field| { - let is_visible = adt.is_enum() - || field.vis.is_accessible_from(cx.module, cx.tcx); - if is_visible { - field.ty(cx.tcx, substs) - } else { - // Treat all non-visible fields as nil. They - // can't appear in any other pattern from - // this match (because they are private), - // so their type does not matter - but - // we don't want to know they are - // uninhabited. - cx.tcx.mk_nil() - } - }).collect() + if adt.is_box() { + // Use T as the sub pattern type of Box. + vec![substs[0].as_type().unwrap()] + } else { + adt.variants[ctor.variant_index_for_adt(adt)].fields.iter().map(|field| { + let is_visible = adt.is_enum() + || field.vis.is_accessible_from(cx.module, cx.tcx); + if is_visible { + field.ty(cx.tcx, substs) + } else { + // Treat all non-visible fields as nil. They + // can't appear in any other pattern from + // this match (because they are private), + // so their type does not matter - but + // we don't want to know they are + // uninhabited. + cx.tcx.mk_nil() + } + }).collect() + } } _ => vec![], } diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index f93af4c1920..b516cbd08ca 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -15,6 +15,7 @@ alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true } alloc_system = { path = "../liballoc_system" } panic_unwind = { path = "../libpanic_unwind", optional = true } panic_abort = { path = "../libpanic_abort" } +collections = { path = "../libcollections" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } rand = { path = "../librand" } diff --git a/src/test/compile-fail/issue-11740.rs b/src/test/compile-fail/issue-11740.rs new file mode 100644 index 00000000000..0bda06be9e8 --- /dev/null +++ b/src/test/compile-fail/issue-11740.rs @@ -0,0 +1,38 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] +#![allow(warnings)] + +struct Attr { + name: String, + value: String, +} + +struct Element { + attrs: Vec>, +} + +impl Element { + pub unsafe fn get_attr<'a>(&'a self, name: &str) { + self.attrs + .iter() + .find(|attr| { + let attr: &&Box = std::mem::transmute(attr); + true + }); + } +} + +#[rustc_error] +fn main() { //~ ERROR compilation successful + let element = Element { attrs: Vec::new() }; + let _ = unsafe { element.get_attr("foo") }; +} diff --git a/src/test/compile-fail/issue-19601.rs b/src/test/compile-fail/issue-19601.rs new file mode 100644 index 00000000000..02b4932cea8 --- /dev/null +++ b/src/test/compile-fail/issue-19601.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] +#![allow(warnings)] + +trait A {} +struct B where B: A> { t: T } + +#[rustc_error] +fn main() { //~ ERROR compilation successful +} diff --git a/src/test/compile-fail/issue-22603.rs b/src/test/compile-fail/issue-22603.rs new file mode 100644 index 00000000000..d08f916b870 --- /dev/null +++ b/src/test/compile-fail/issue-22603.rs @@ -0,0 +1,23 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures, fn_traits, rustc_attrs)] + +struct Foo; + +impl FnOnce<(A,)> for Foo { + type Output = (); + extern "rust-call" fn call_once(self, (_,): (A,)) { + } +} +#[rustc_error] +fn main() { //~ ERROR compilation successful + println!("{:?}", Foo("bar")); +} diff --git a/src/test/compile-fail/issue-22789.rs b/src/test/compile-fail/issue-22789.rs new file mode 100644 index 00000000000..cba1c367bb9 --- /dev/null +++ b/src/test/compile-fail/issue-22789.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures, fn_traits, rustc_attrs)] + +#[rustc_error] +fn main() { //~ ERROR compilation successful + let k = |x: i32| { x + 1 }; + Fn::call(&k, (0,)); +} diff --git a/src/test/compile-fail/issue-26614.rs b/src/test/compile-fail/issue-26614.rs new file mode 100644 index 00000000000..c128fb3b479 --- /dev/null +++ b/src/test/compile-fail/issue-26614.rs @@ -0,0 +1,27 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] +#![allow(warnings)] + +trait Mirror { + type It; +} + +impl Mirror for T { + type It = Self; +} + + +#[rustc_error] +fn main() { //~ ERROR compilation successful + let c: ::It = 5; + const CCCC: ::It = 5; +} diff --git a/src/test/run-pass/issue-42679.rs b/src/test/run-pass/issue-42679.rs new file mode 100644 index 00000000000..312835225ed --- /dev/null +++ b/src/test/run-pass/issue-42679.rs @@ -0,0 +1,31 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(box_syntax)] +#![feature(box_patterns)] + +#[derive(Debug, PartialEq)] +enum Test { + Foo(usize), + Bar(isize), +} + +fn main() { + let a = box Test::Foo(10); + let b = box Test::Bar(-20); + match (a, b) { + (_, box Test::Foo(_)) => unreachable!(), + (box Test::Foo(x), b) => { + assert_eq!(x, 10); + assert_eq!(b, box Test::Bar(-20)); + }, + _ => unreachable!(), + } +} diff --git a/src/test/ui/coercion-missing-tail-expected-type.rs b/src/test/ui/coercion-missing-tail-expected-type.rs index 489ad817ea8..15ce79a054f 100644 --- a/src/test/ui/coercion-missing-tail-expected-type.rs +++ b/src/test/ui/coercion-missing-tail-expected-type.rs @@ -14,6 +14,10 @@ fn plus_one(x: i32) -> i32 { x + 1; } +fn foo() -> Result { + Ok(1); +} + fn main() { let x = plus_one(5); println!("X = {}", x); diff --git a/src/test/ui/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion-missing-tail-expected-type.stderr index 28a99e58eca..e96bc425e0b 100644 --- a/src/test/ui/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion-missing-tail-expected-type.stderr @@ -15,5 +15,22 @@ help: consider removing this semicolon: 14 | x + 1; | ^ +error[E0308]: mismatched types + --> $DIR/coercion-missing-tail-expected-type.rs:17:29 + | +17 | fn foo() -> Result { + | _____________________________^ +18 | | Ok(1); +19 | | } + | |_^ expected enum `std::result::Result`, found () + | + = note: expected type `std::result::Result` + found type `()` +help: consider removing this semicolon: + --> $DIR/coercion-missing-tail-expected-type.rs:18:10 + | +18 | Ok(1); + | ^ + error: aborting due to previous error(s)