From 17f7f0515fc31dc54cb18d67029ed71340112c6e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 28 Dec 2016 10:53:43 -0800 Subject: [PATCH 1/8] std: Don't build docs for misc facade crates Retain the same behavior as stable. Closes #38319 --- src/bootstrap/doc.rs | 3 ++- src/liballoc_jemalloc/Cargo.toml | 1 + src/liballoc_system/Cargo.toml | 1 + src/libcompiler_builtins/Cargo.toml | 1 + src/libpanic_abort/Cargo.toml | 1 + src/libpanic_unwind/Cargo.toml | 1 + src/librand/Cargo.toml | 1 + src/libunwind/Cargo.toml | 1 + src/rustc/libc_shim/Cargo.toml | 1 + src/rustc/std_shim/Cargo.toml | 1 + 10 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 30c7fefad8745..6a6af295932cc 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -146,7 +146,8 @@ pub fn std(build: &Build, stage: u32, target: &str) { let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc"); cargo.arg("--manifest-path") .arg(build.src.join("src/rustc/std_shim/Cargo.toml")) - .arg("--features").arg(build.std_features()); + .arg("--features").arg(build.std_features()) + .arg("-p").arg("std"); build.run(&mut cargo); cp_r(&out_dir, &out) } diff --git a/src/liballoc_jemalloc/Cargo.toml b/src/liballoc_jemalloc/Cargo.toml index 25b3c8a3a0a83..01393be9949ae 100644 --- a/src/liballoc_jemalloc/Cargo.toml +++ b/src/liballoc_jemalloc/Cargo.toml @@ -9,6 +9,7 @@ links = "jemalloc" name = "alloc_jemalloc" path = "lib.rs" test = false +doc = false [dependencies] core = { path = "../libcore" } diff --git a/src/liballoc_system/Cargo.toml b/src/liballoc_system/Cargo.toml index 88e8e2d7adbc3..8e3c2c0b9cc66 100644 --- a/src/liballoc_system/Cargo.toml +++ b/src/liballoc_system/Cargo.toml @@ -7,6 +7,7 @@ version = "0.0.0" name = "alloc_system" path = "lib.rs" test = false +doc = false [dependencies] core = { path = "../libcore" } diff --git a/src/libcompiler_builtins/Cargo.toml b/src/libcompiler_builtins/Cargo.toml index 79570dc025219..1a549ae823ac5 100644 --- a/src/libcompiler_builtins/Cargo.toml +++ b/src/libcompiler_builtins/Cargo.toml @@ -9,6 +9,7 @@ name = "compiler_builtins" path = "lib.rs" test = false bench = false +doc = false [dependencies] core = { path = "../libcore" } diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml index d90d2864813c9..e0eac41f49ec9 100644 --- a/src/libpanic_abort/Cargo.toml +++ b/src/libpanic_abort/Cargo.toml @@ -7,6 +7,7 @@ version = "0.0.0" path = "lib.rs" test = false bench = false +doc = false [dependencies] core = { path = "../libcore" } diff --git a/src/libpanic_unwind/Cargo.toml b/src/libpanic_unwind/Cargo.toml index 90c16fff6f1f1..a978ea16e9e74 100644 --- a/src/libpanic_unwind/Cargo.toml +++ b/src/libpanic_unwind/Cargo.toml @@ -7,6 +7,7 @@ version = "0.0.0" path = "lib.rs" test = false bench = false +doc = false [dependencies] alloc = { path = "../liballoc" } diff --git a/src/librand/Cargo.toml b/src/librand/Cargo.toml index 86b061db05413..eda5f217565de 100644 --- a/src/librand/Cargo.toml +++ b/src/librand/Cargo.toml @@ -6,6 +6,7 @@ version = "0.0.0" [lib] name = "rand" path = "lib.rs" +doc = false [dependencies] core = { path = "../libcore" } diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml index 36f361b723894..fbd9789d2f52d 100644 --- a/src/libunwind/Cargo.toml +++ b/src/libunwind/Cargo.toml @@ -9,6 +9,7 @@ name = "unwind" path = "lib.rs" test = false bench = false +doc = false [dependencies] core = { path = "../libcore" } diff --git a/src/rustc/libc_shim/Cargo.toml b/src/rustc/libc_shim/Cargo.toml index e501766fbed15..39df3528be369 100644 --- a/src/rustc/libc_shim/Cargo.toml +++ b/src/rustc/libc_shim/Cargo.toml @@ -17,6 +17,7 @@ name = "libc" path = "../../liblibc/src/lib.rs" test = false bench = false +doc = false [dependencies] core = { path = "../../libcore" } diff --git a/src/rustc/std_shim/Cargo.toml b/src/rustc/std_shim/Cargo.toml index 18680dc4fd9a1..1fa9177243536 100644 --- a/src/rustc/std_shim/Cargo.toml +++ b/src/rustc/std_shim/Cargo.toml @@ -27,6 +27,7 @@ authors = ["The Rust Project Developers"] [lib] name = "std_shim" path = "lib.rs" +doc = false [dependencies] std = { path = "../../libstd" } From cb6ecf01637e254550f6d8853e53561ea8acb7e2 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 25 Dec 2016 18:44:19 +0200 Subject: [PATCH 2/8] clear discriminant drop flag at the bottom of a ladder Fixes #38437. --- .../borrowck/mir/elaborate_drops.rs | 77 ++++++++++--------- src/test/run-pass/issue-38437.rs | 54 +++++++++++++ 2 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 src/test/run-pass/issue-38437.rs diff --git a/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs b/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs index 4f49bfc9725b3..88e5bae483d73 100644 --- a/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs +++ b/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs @@ -481,54 +481,55 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { is_cleanup: bool) -> Vec { - let mut succ = succ; let mut unwind_succ = if is_cleanup { None } else { c.unwind }; - let mut update_drop_flag = true; + + let mut succ = self.new_block( + c, c.is_cleanup, TerminatorKind::Goto { target: succ } + ); + + // Always clear the "master" drop flag at the bottom of the + // ladder. This is needed because the "master" drop flag + // protects the ADT's discriminant, which is invalidated + // after the ADT is dropped. + self.set_drop_flag( + Location { block: succ, statement_index: 0 }, + c.path, + DropFlagState::Absent + ); fields.iter().rev().enumerate().map(|(i, &(ref lv, path))| { - let drop_block = match path { - Some(path) => { - debug!("drop_ladder: for std field {} ({:?})", i, lv); - - self.elaborated_drop_block(&DropCtxt { - source_info: c.source_info, - is_cleanup: is_cleanup, - init_data: c.init_data, - lvalue: lv, - path: path, - succ: succ, - unwind: unwind_succ, - }) - } - None => { - debug!("drop_ladder: for rest field {} ({:?})", i, lv); - - let blk = self.complete_drop(&DropCtxt { - source_info: c.source_info, - is_cleanup: is_cleanup, - init_data: c.init_data, - lvalue: lv, - path: c.path, - succ: succ, - unwind: unwind_succ, - }, update_drop_flag); - - // the drop flag has been updated - updating - // it again would clobber it. - update_drop_flag = false; - - blk - } + succ = if let Some(path) = path { + debug!("drop_ladder: for std field {} ({:?})", i, lv); + + self.elaborated_drop_block(&DropCtxt { + source_info: c.source_info, + is_cleanup: is_cleanup, + init_data: c.init_data, + lvalue: lv, + path: path, + succ: succ, + unwind: unwind_succ, + }) + } else { + debug!("drop_ladder: for rest field {} ({:?})", i, lv); + + self.complete_drop(&DropCtxt { + source_info: c.source_info, + is_cleanup: is_cleanup, + init_data: c.init_data, + lvalue: lv, + path: c.path, + succ: succ, + unwind: unwind_succ, + }, false) }; - succ = drop_block; unwind_succ = unwind_ladder.as_ref().map(|p| p[i]); - - drop_block + succ }).collect() } diff --git a/src/test/run-pass/issue-38437.rs b/src/test/run-pass/issue-38437.rs new file mode 100644 index 0000000000000..a6e7df1c0102c --- /dev/null +++ b/src/test/run-pass/issue-38437.rs @@ -0,0 +1,54 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that drop elaboration clears the "master" discriminant +// drop flag even if it protects no fields. + +struct Good(usize); +impl Drop for Good { + #[inline(never)] + fn drop(&mut self) { + println!("dropping Good({})", self.0); + } +} + +struct Void; +impl Drop for Void { + #[inline(never)] + fn drop(&mut self) { + panic!("Suddenly, a Void appears."); + } +} + +enum E { + Never(Void), + Fine(Good) +} + +fn main() { + let mut go = true; + + loop { + let next; + match go { + true => next = E::Fine(Good(123)), + false => return, + } + + match next { + E::Never(_) => return, + E::Fine(_good) => go = false, + } + + // `next` is dropped and StorageDead'd here. We must reset the + // discriminant's drop flag to avoid random variants being + // dropped. + } +} From b27410f70223f63c520188295909c2e1bd5b1d3f Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 22 Dec 2016 08:27:26 +0000 Subject: [PATCH 3/8] Fix non-termination in `resolve`. --- src/librustc_resolve/lib.rs | 3 ++- src/test/compile-fail/recursive-reexports.rs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 509ee704e2ea2..848d5aa0cc3af 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2946,6 +2946,7 @@ impl<'a> Resolver<'a> { let mut lookup_results = Vec::new(); let mut worklist = Vec::new(); + let mut seen_modules = FxHashSet(); worklist.push((self.graph_root, Vec::new(), false)); while let Some((in_module, @@ -3001,7 +3002,7 @@ impl<'a> Resolver<'a> { if !in_module_is_extern || name_binding.vis == ty::Visibility::Public { // add the module to the lookup let is_extern = in_module_is_extern || name_binding.is_extern_crate(); - if !worklist.iter().any(|&(m, ..)| m.def() == module.def()) { + if seen_modules.insert(module.def_id().unwrap()) { worklist.push((module, path_segments, is_extern)); } } diff --git a/src/test/compile-fail/recursive-reexports.rs b/src/test/compile-fail/recursive-reexports.rs index 6fd52beeec62c..aa444d45eeb7a 100644 --- a/src/test/compile-fail/recursive-reexports.rs +++ b/src/test/compile-fail/recursive-reexports.rs @@ -10,6 +10,8 @@ // aux-build:recursive_reexports.rs -fn f() -> recursive_reexports::S {} //~ ERROR undeclared +extern crate recursive_reexports; + +fn f() -> recursive_reexports::S {} //~ ERROR type name `recursive_reexports::S` is undefined fn main() {} From d1acf0946074a9cb7f3da53ac0de78a3544a3e2f Mon Sep 17 00:00:00 2001 From: Austin Hicks Date: Wed, 21 Dec 2016 17:59:30 -0500 Subject: [PATCH 4/8] Disable field reordering --- src/librustc/ty/layout.rs | 4 +++ src/test/run-pass/type-sizes.rs | 7 ---- src/test/ui/print_type_sizes/nullable.stdout | 35 +++++++++++--------- src/test/ui/print_type_sizes/packed.stdout | 10 +++--- src/test/ui/print_type_sizes/padding.stdout | 16 ++++----- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 53ed103ad9141..ebac30c8e506e 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -575,6 +575,10 @@ impl<'a, 'gcx, 'tcx> Struct { }); } + // Disable field reordering until we can decide what to do. + // The odd pattern here avoids a warning about the value never being read. + if can_optimize { can_optimize = false } + let (optimize, sort_ascending) = match kind { StructKind::AlwaysSizedUnivariant => (can_optimize, false), StructKind::MaybeUnsizedUnivariant => (can_optimize, false), diff --git a/src/test/run-pass/type-sizes.rs b/src/test/run-pass/type-sizes.rs index 6614a76107f85..bbb01eaaf46b9 100644 --- a/src/test/run-pass/type-sizes.rs +++ b/src/test/run-pass/type-sizes.rs @@ -31,10 +31,6 @@ enum e3 { a([u16; 0], u8), b } -// Test struct field reordering to make sure it actually reorders. -struct WillOptimize1(u8, u16, u8); -struct WillOptimize2 { a: u8, b: u16, c: u8} - pub fn main() { assert_eq!(size_of::(), 1 as usize); assert_eq!(size_of::(), 4 as usize); @@ -58,7 +54,4 @@ pub fn main() { assert_eq!(size_of::(), 8 as usize); assert_eq!(size_of::(), 8 as usize); assert_eq!(size_of::(), 4 as usize); - - assert_eq!(size_of::(), 4); - assert_eq!(size_of::(), 4); } diff --git a/src/test/ui/print_type_sizes/nullable.stdout b/src/test/ui/print_type_sizes/nullable.stdout index 830678f174f88..dd999c4a5e4c7 100644 --- a/src/test/ui/print_type_sizes/nullable.stdout +++ b/src/test/ui/print_type_sizes/nullable.stdout @@ -1,22 +1,25 @@ -print-type-size type: `IndirectNonZero`: 12 bytes, alignment: 4 bytes -print-type-size field `.nested`: 8 bytes -print-type-size field `.post`: 2 bytes +print-type-size type: `IndirectNonZero`: 20 bytes, alignment: 4 bytes print-type-size field `.pre`: 1 bytes -print-type-size end padding: 1 bytes -print-type-size type: `MyOption>`: 12 bytes, alignment: 4 bytes -print-type-size variant `Some`: 12 bytes -print-type-size field `.0`: 12 bytes -print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes -print-type-size variant `Record`: 7 bytes -print-type-size field `.val`: 4 bytes -print-type-size field `.post`: 2 bytes -print-type-size field `.pre`: 1 bytes -print-type-size end padding: 1 bytes -print-type-size type: `NestedNonZero`: 8 bytes, alignment: 4 bytes -print-type-size field `.val`: 4 bytes +print-type-size padding: 3 bytes +print-type-size field `.nested`: 12 bytes, alignment: 4 bytes print-type-size field `.post`: 2 bytes +print-type-size end padding: 2 bytes +print-type-size type: `MyOption>`: 20 bytes, alignment: 4 bytes +print-type-size variant `Some`: 20 bytes +print-type-size field `.0`: 20 bytes +print-type-size type: `EmbeddedDiscr`: 12 bytes, alignment: 4 bytes +print-type-size variant `Record`: 10 bytes +print-type-size field `.pre`: 1 bytes +print-type-size padding: 3 bytes +print-type-size field `.val`: 4 bytes, alignment: 4 bytes +print-type-size field `.post`: 2 bytes +print-type-size end padding: 2 bytes +print-type-size type: `NestedNonZero`: 12 bytes, alignment: 4 bytes print-type-size field `.pre`: 1 bytes -print-type-size end padding: 1 bytes +print-type-size padding: 3 bytes +print-type-size field `.val`: 4 bytes, alignment: 4 bytes +print-type-size field `.post`: 2 bytes +print-type-size end padding: 2 bytes print-type-size type: `MyOption>`: 4 bytes, alignment: 4 bytes print-type-size variant `Some`: 4 bytes print-type-size field `.0`: 4 bytes diff --git a/src/test/ui/print_type_sizes/packed.stdout b/src/test/ui/print_type_sizes/packed.stdout index 83fd333c9c7fc..1278a7d7c92c6 100644 --- a/src/test/ui/print_type_sizes/packed.stdout +++ b/src/test/ui/print_type_sizes/packed.stdout @@ -1,11 +1,13 @@ -print-type-size type: `Padded`: 12 bytes, alignment: 4 bytes -print-type-size field `.g`: 4 bytes -print-type-size field `.h`: 2 bytes +print-type-size type: `Padded`: 16 bytes, alignment: 4 bytes print-type-size field `.a`: 1 bytes print-type-size field `.b`: 1 bytes +print-type-size padding: 2 bytes +print-type-size field `.g`: 4 bytes, alignment: 4 bytes print-type-size field `.c`: 1 bytes +print-type-size padding: 1 bytes +print-type-size field `.h`: 2 bytes, alignment: 2 bytes print-type-size field `.d`: 1 bytes -print-type-size end padding: 2 bytes +print-type-size end padding: 3 bytes print-type-size type: `Packed`: 10 bytes, alignment: 1 bytes print-type-size field `.a`: 1 bytes print-type-size field `.b`: 1 bytes diff --git a/src/test/ui/print_type_sizes/padding.stdout b/src/test/ui/print_type_sizes/padding.stdout index 0eaff7118b35c..bb95f790bd9e4 100644 --- a/src/test/ui/print_type_sizes/padding.stdout +++ b/src/test/ui/print_type_sizes/padding.stdout @@ -1,12 +1,10 @@ print-type-size type: `E1`: 12 bytes, alignment: 4 bytes -print-type-size discriminant: 1 bytes -print-type-size variant `A`: 7 bytes +print-type-size discriminant: 4 bytes +print-type-size variant `A`: 5 bytes +print-type-size field `.0`: 4 bytes print-type-size field `.1`: 1 bytes -print-type-size padding: 2 bytes -print-type-size field `.0`: 4 bytes, alignment: 4 bytes -print-type-size variant `B`: 11 bytes -print-type-size padding: 3 bytes -print-type-size field `.0`: 8 bytes, alignment: 4 bytes +print-type-size variant `B`: 8 bytes +print-type-size field `.0`: 8 bytes print-type-size type: `E2`: 12 bytes, alignment: 4 bytes print-type-size discriminant: 1 bytes print-type-size variant `A`: 7 bytes @@ -17,7 +15,7 @@ print-type-size variant `B`: 11 bytes print-type-size padding: 3 bytes print-type-size field `.0`: 8 bytes, alignment: 4 bytes print-type-size type: `S`: 8 bytes, alignment: 4 bytes -print-type-size field `.g`: 4 bytes print-type-size field `.a`: 1 bytes print-type-size field `.b`: 1 bytes -print-type-size end padding: 2 bytes +print-type-size padding: 2 bytes +print-type-size field `.g`: 4 bytes, alignment: 4 bytes From 9b2833bb78b3d1d01034cc68aabb929fa6bef204 Mon Sep 17 00:00:00 2001 From: Austin Hicks Date: Mon, 19 Dec 2016 21:14:27 -0500 Subject: [PATCH 5/8] Fix closure debuginfo. --- src/librustc_trans/mir/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index 12cbfcef7d26b..94dc9a5fdb489 100644 --- a/src/librustc_trans/mir/mod.rs +++ b/src/librustc_trans/mir/mod.rs @@ -10,14 +10,13 @@ use libc::c_uint; use llvm::{self, ValueRef}; -use rustc::ty; +use rustc::ty::{self, layout}; use rustc::mir; use rustc::mir::tcx::LvalueTy; use session::config::FullDebugInfo; use base; use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext, C_null}; use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind, FunctionDebugContext}; -use machine; use type_of; use syntax_pos::{DUMMY_SP, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos}; @@ -494,10 +493,15 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>, llval }; - let llclosurety = type_of::type_of(bcx.ccx(), closure_ty); + let layout = bcx.ccx().layout_of(closure_ty); + let offsets = match *layout { + layout::Univariant { ref variant, .. } => &variant.offsets[..], + _ => bug!("Closures are only supposed to be Univariant") + }; + for (i, (decl, ty)) in mir.upvar_decls.iter().zip(upvar_tys).enumerate() { - let byte_offset_of_var_in_env = - machine::llelement_offset(bcx.ccx(), llclosurety, i); + let byte_offset_of_var_in_env = offsets[i].bytes(); + let ops = unsafe { [llvm::LLVMRustDIBuilderCreateOpDeref(), From 94cfed12c2a1ce95a9b0b3f79c14c860885754be Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 19 Dec 2016 09:45:42 -0800 Subject: [PATCH 6/8] rustbuild: Update Cargo download location I updated the beta compiler used to bootstrap the master branch in #38438 with the intention of fixing Travis OSX linkage issues but I mistakenly forgot that the PR only updated rustc, not Cargo itself. Cargo has a new release process with downloads in a different location, so this commit updates rustbuild to download from this new location by tracking revisions instead of Cargo nightly dates. --- src/bootstrap/bootstrap.py | 22 +++++++++------------- src/stage0.txt | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 0dda7f12007a4..82a546f195e23 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -81,7 +81,7 @@ def verify(path, sha_path, verbose): with open(path, "rb") as f: found = hashlib.sha256(f.read()).hexdigest() with open(sha_path, "r") as f: - expected, _ = f.readline().split() + expected = f.readline().split()[0] verified = found == expected if not verified: print("invalid checksum:\n" @@ -146,7 +146,7 @@ class RustBuild(object): def download_stage0(self): cache_dst = os.path.join(self.build_dir, "cache") rustc_cache = os.path.join(cache_dst, self.stage0_rustc_date()) - cargo_cache = os.path.join(cache_dst, self.stage0_cargo_date()) + cargo_cache = os.path.join(cache_dst, self.stage0_cargo_rev()) if not os.path.exists(rustc_cache): os.makedirs(rustc_cache) if not os.path.exists(cargo_cache): @@ -179,21 +179,17 @@ def download_stage0(self): if self.cargo().startswith(self.bin_root()) and \ (not os.path.exists(self.cargo()) or self.cargo_out_of_date()): self.print_what_it_means_to_bootstrap() - channel = self.stage0_cargo_channel() - filename = "cargo-{}-{}.tar.gz".format(channel, self.build) - url = "https://static.rust-lang.org/cargo-dist/" + self.stage0_cargo_date() + filename = "cargo-nightly-{}.tar.gz".format(self.build) + url = "https://s3.amazonaws.com/rust-lang-ci/cargo-builds/" + self.stage0_cargo_rev() tarball = os.path.join(cargo_cache, filename) if not os.path.exists(tarball): get("{}/{}".format(url, filename), tarball, verbose=self.verbose) unpack(tarball, self.bin_root(), match="cargo", verbose=self.verbose) with open(self.cargo_stamp(), 'w') as f: - f.write(self.stage0_cargo_date()) + f.write(self.stage0_cargo_rev()) - def stage0_cargo_date(self): - return self._cargo_date - - def stage0_cargo_channel(self): - return self._cargo_channel + def stage0_cargo_rev(self): + return self._cargo_rev def stage0_rustc_date(self): return self._rustc_date @@ -217,7 +213,7 @@ def cargo_out_of_date(self): if not os.path.exists(self.cargo_stamp()) or self.clean: return True with open(self.cargo_stamp(), 'r') as f: - return self.stage0_cargo_date() != f.read() + return self.stage0_cargo_rev() != f.read() def bin_root(self): return os.path.join(self.build_dir, self.build, "stage0") @@ -467,7 +463,7 @@ def main(): data = stage0_data(rb.rust_root) rb._rustc_channel, rb._rustc_date = data['rustc'].split('-', 1) - rb._cargo_channel, rb._cargo_date = data['cargo'].split('-', 1) + rb._cargo_rev = data['cargo'] start_time = time() diff --git a/src/stage0.txt b/src/stage0.txt index 398483d3ebf1f..43310a2c36070 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -13,4 +13,4 @@ # released on `$date` rustc: 1.14.0-2016-12-18 -cargo: nightly-2016-11-16 +cargo: fbeea902d2c9a5be6d99cc35681565d8f7832592 From 2b450e3211fd0996ed34cf57dd81ded9b0e5a052 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Thu, 15 Dec 2016 21:10:29 +0000 Subject: [PATCH 7/8] rustbuild: Stop building docs for libtest by default They cause the search index from the std docs to get overwritten just like #34800. Part of #38319. --- src/bootstrap/step.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 35eb98e4723f2..66220f9dde3d1 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -458,7 +458,7 @@ pub fn build_rules(build: &Build) -> Rules { for (krate, path, default) in krates("test_shim") { rules.doc(&krate.doc_step, path) .dep(|s| s.name("libtest")) - .default(default && build.config.docs) + .default(default && build.config.compiler_docs) .run(move |s| doc::test(build, s.stage, s.target)); } for (krate, path, default) in krates("rustc-main") { From b8ea9fa1fc15cfcd7e5df689a12ad56e57ca1f2d Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 9 Dec 2016 11:08:39 +0000 Subject: [PATCH 8/8] Demote most backwards incompatible ambiguity errors from RFC 1560 to warnings. --- src/librustc/lint/builtin.rs | 7 +++ src/librustc_lint/lib.rs | 4 ++ src/librustc_resolve/lib.rs | 56 +++++++++++++------ src/librustc_resolve/macros.rs | 1 + src/librustc_resolve/resolve_imports.rs | 41 ++++++++++---- .../imports/rfc-1560-warning-cycle.rs | 30 ++++++++++ 6 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 src/test/compile-fail/imports/rfc-1560-warning-cycle.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 02c1ece163497..667c2590fa996 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -211,6 +211,12 @@ declare_lint! { not named `mod.rs`" } +declare_lint! { + pub LEGACY_IMPORTS, + Warn, + "detects names that resolve to ambiguous glob imports with RFC 1560" +} + declare_lint! { pub DEPRECATED, Warn, @@ -257,6 +263,7 @@ impl LintPass for HardwiredLints { PATTERNS_IN_FNS_WITHOUT_BODY, EXTRA_REQUIREMENT_IN_IMPL, LEGACY_DIRECTORY_OWNERSHIP, + LEGACY_IMPORTS, DEPRECATED ) } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 6c9a3e99a0458..a53d43b2a257a 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -234,6 +234,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP), reference: "issue #37872 ", }, + FutureIncompatibleInfo { + id: LintId::of(LEGACY_IMPORTS), + reference: "issue #38260 ", + }, ]); // Register renamed and removed lints diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 848d5aa0cc3af..325fc11fdeb7e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -64,7 +64,7 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{PathSegment, PathParameters, QSelf, TraitItemKind, TraitRef, Ty, TyKind}; -use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::{Span, DUMMY_SP, MultiSpan}; use errors::DiagnosticBuilder; use std::cell::{Cell, RefCell}; @@ -896,6 +896,7 @@ enum NameBindingKind<'a> { Ambiguity { b1: &'a NameBinding<'a>, b2: &'a NameBinding<'a>, + legacy: bool, } } @@ -907,6 +908,7 @@ struct AmbiguityError<'a> { lexical: bool, b1: &'a NameBinding<'a>, b2: &'a NameBinding<'a>, + legacy: bool, } impl<'a> NameBinding<'a> { @@ -914,6 +916,7 @@ impl<'a> NameBinding<'a> { match self.kind { NameBindingKind::Module(module) => Some(module), NameBindingKind::Import { binding, .. } => binding.module(), + NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.module(), _ => None, } } @@ -923,6 +926,7 @@ impl<'a> NameBinding<'a> { NameBindingKind::Def(def) => def, NameBindingKind::Module(module) => module.def().unwrap(), NameBindingKind::Import { binding, .. } => binding.def(), + NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.def(), NameBindingKind::Ambiguity { .. } => Def::Err, } } @@ -1349,11 +1353,14 @@ impl<'a> Resolver<'a> { self.record_use(name, ns, binding, span) } NameBindingKind::Import { .. } => false, - NameBindingKind::Ambiguity { b1, b2 } => { + NameBindingKind::Ambiguity { b1, b2, legacy } => { self.ambiguity_errors.push(AmbiguityError { - span: span, name: name, lexical: false, b1: b1, b2: b2, + span: span, name: name, lexical: false, b1: b1, b2: b2, legacy: legacy, }); - true + if legacy { + self.record_use(name, ns, b1, span); + } + !legacy } _ => false } @@ -3066,26 +3073,39 @@ impl<'a> Resolver<'a> { self.report_shadowing_errors(); let mut reported_spans = FxHashSet(); - for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors { + for &AmbiguityError { span, name, b1, b2, lexical, legacy } in &self.ambiguity_errors { if !reported_spans.insert(span) { continue } let participle = |binding: &NameBinding| { if binding.is_import() { "imported" } else { "defined" } }; let msg1 = format!("`{}` could resolve to the name {} here", name, participle(b1)); let msg2 = format!("`{}` could also resolve to the name {} here", name, participle(b2)); - self.session.struct_span_err(span, &format!("`{}` is ambiguous", name)) - .span_note(b1.span, &msg1) - .span_note(b2.span, &msg2) - .note(&if !lexical && b1.is_glob_import() { - format!("consider adding an explicit import of `{}` to disambiguate", name) - } else if let Def::Macro(..) = b1.def() { - format!("macro-expanded {} do not shadow", - if b1.is_import() { "macro imports" } else { "macros" }) - } else { - format!("macro-expanded {} do not shadow when used in a macro invocation path", - if b1.is_import() { "imports" } else { "items" }) - }) - .emit(); + let note = if !lexical && b1.is_glob_import() { + format!("consider adding an explicit import of `{}` to disambiguate", name) + } else if let Def::Macro(..) = b1.def() { + format!("macro-expanded {} do not shadow", + if b1.is_import() { "macro imports" } else { "macros" }) + } else { + format!("macro-expanded {} do not shadow when used in a macro invocation path", + if b1.is_import() { "imports" } else { "items" }) + }; + if legacy { + let id = match b2.kind { + NameBindingKind::Import { directive, .. } => directive.id, + _ => unreachable!(), + }; + let mut span = MultiSpan::from_span(span); + span.push_span_label(b1.span, msg1); + span.push_span_label(b2.span, msg2); + let msg = format!("`{}` is ambiguous", name); + self.session.add_lint(lint::builtin::LEGACY_IMPORTS, id, span, msg); + } else { + self.session.struct_span_err(span, &format!("`{}` is ambiguous", name)) + .span_note(b1.span, &msg1) + .span_note(b2.span, &msg2) + .note(¬e) + .emit(); + } } for &PrivacyError(span, name, binding) in &self.privacy_errors { diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 6c02967672d84..613829bab8be3 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -288,6 +288,7 @@ impl<'a> Resolver<'a> { Some(shadower) if shadower.def() != binding.def() => { self.ambiguity_errors.push(AmbiguityError { span: span, name: name, b1: shadower, b2: binding, lexical: true, + legacy: false, }); return Ok(shadower); } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 890891fd09018..208c43d898ce0 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -159,6 +159,7 @@ impl<'a> Resolver<'a> { binding.def() != shadowed_glob.def() { self.ambiguity_errors.push(AmbiguityError { span: span, name: name, lexical: false, b1: binding, b2: shadowed_glob, + legacy: false, }); } } @@ -336,9 +337,9 @@ impl<'a> Resolver<'a> { } pub fn ambiguity(&mut self, b1: &'a NameBinding<'a>, b2: &'a NameBinding<'a>) - -> &'a NameBinding<'a> { + -> &'a NameBinding<'a> { self.arenas.alloc_name_binding(NameBinding { - kind: NameBindingKind::Ambiguity { b1: b1, b2: b2 }, + kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: false }, vis: if b1.vis.is_at_least(b2.vis, self) { b1.vis } else { b2.vis }, span: b1.span, expansion: Mark::root(), @@ -726,7 +727,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { } for (&(name, ns), resolution) in module.resolutions.borrow().iter() { - let resolution = resolution.borrow(); + let resolution = &mut *resolution.borrow_mut(); let binding = match resolution.binding { Some(binding) => binding, None => continue, @@ -743,14 +744,34 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { } } - if let NameBindingKind::Import { binding: orig_binding, directive, .. } = binding.kind { - if ns == TypeNS && orig_binding.is_variant() && - !orig_binding.vis.is_at_least(binding.vis, self) { - let msg = format!("variant `{}` is private, and cannot be reexported \ - (error E0364), consider declaring its enum as `pub`", - name); - self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg); + match binding.kind { + NameBindingKind::Import { binding: orig_binding, directive, .. } => { + if ns == TypeNS && orig_binding.is_variant() && + !orig_binding.vis.is_at_least(binding.vis, self) { + let msg = format!("variant `{}` is private, and cannot be reexported \ + (error E0364), consider declaring its enum as `pub`", + name); + self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg); + } + } + NameBindingKind::Ambiguity { b1, b2, .. } + if b1.is_glob_import() && b2.is_glob_import() => { + let (orig_b1, orig_b2) = match (&b1.kind, &b2.kind) { + (&NameBindingKind::Import { binding: b1, .. }, + &NameBindingKind::Import { binding: b2, .. }) => (b1, b2), + _ => continue, + }; + let (b1, b2) = match (orig_b1.vis, orig_b2.vis) { + (ty::Visibility::Public, ty::Visibility::Public) => continue, + (ty::Visibility::Public, _) => (b1, b2), + (_, ty::Visibility::Public) => (b2, b1), + _ => continue, + }; + resolution.binding = Some(self.arenas.alloc_name_binding(NameBinding { + kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: true }, ..*b1 + })); } + _ => {} } } diff --git a/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs b/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs new file mode 100644 index 0000000000000..bed10c87ae185 --- /dev/null +++ b/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs @@ -0,0 +1,30 @@ +// 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 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(unused)] + +pub struct Foo; + +mod bar { + struct Foo; + + mod baz { + use *; //~ NOTE `Foo` could resolve to the name imported here + use bar::*; //~ NOTE `Foo` could also resolve to the name imported here + fn f(_: Foo) {} + //~^ WARN `Foo` is ambiguous + //~| WARN hard error in a future release + //~| NOTE see issue #38260 + } +} + +#[rustc_error] +fn main() {} //~ ERROR compilation successful