From 658ea389fd753049bd8ef3f100ee4edb9c9f2a44 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 26 Nov 2017 12:09:35 -0500 Subject: [PATCH 01/17] rustc_llvm: remove stale references ...that were removed in 77c3bfa7429abf87b76ba84108df018d9e9d90e2. --- .gitignore | 1 - src/librustc_llvm/ffi.rs | 18 +++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 309fbd95345a4..57407a2399a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -95,7 +95,6 @@ config.stamp keywords.md lexer.ml src/etc/dl -src/librustc_llvm/llvmdeps.rs tmp.*.rs version.md version.ml diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index dd64d76bc0c51..1c2fa1bbb4848 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -505,17 +505,13 @@ pub mod debuginfo { pub enum ModuleBuffer {} -// Link to our native llvm bindings (things that we need to use the C++ api -// for) and because llvm is written in C++ we need to link against libstdc++ -// -// You'll probably notice that there is an omission of all LLVM libraries -// from this location. This is because the set of LLVM libraries that we -// link to is mostly defined by LLVM, and the `llvm-config` tool is used to -// figure out the exact set of libraries. To do this, the build system -// generates an llvmdeps.rs file next to this one which will be -// automatically updated whenever LLVM is updated to include an up-to-date -// set of the libraries we need to link to LLVM for. -#[link(name = "rustllvm", kind = "static")] // not quite true but good enough +// This annotation is primarily needed for MSVC where attributes like +// dllimport/dllexport are applied and need to be correct for everything to +// link successfully. The #[link] annotation here says "these symbols are +// included statically" which means that they're all exported with dllexport +// and from the rustc_llvm dynamic library. Otherwise the rustc_trans dynamic +// library would not be able to access these symbols. +#[link(name = "rustllvm", kind = "static")] extern "C" { // Create and destroy contexts. pub fn LLVMContextCreate() -> ContextRef; From 9067d9735a9ef96f64c32ed41c120faa0976c772 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 26 Nov 2017 16:25:49 -0500 Subject: [PATCH 02/17] rustc_llvm: use cc::Build::define --- src/librustc_llvm/build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 141a9a8d704d2..d860c6c44f024 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -154,13 +154,13 @@ fn main() { } for component in &components { - let mut flag = String::from("-DLLVM_COMPONENT_"); + let mut flag = String::from("LLVM_COMPONENT_"); flag.push_str(&component.to_uppercase()); - cfg.flag(&flag); + cfg.define(&flag, None); } if env::var_os("LLVM_RUSTLLVM").is_some() { - cfg.flag("-DLLVM_RUSTLLVM"); + cfg.define("LLVM_RUSTLLVM", None); } build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm")); From 94d02b896c3feb5e997b95a660e850c7ad8cbe74 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 26 Nov 2017 16:43:24 -0500 Subject: [PATCH 03/17] *: strip calls to cc::Build::compile The documentation states: "The name output should be the name of the library." and this is already done in more recently-added callers. --- src/bootstrap/native.rs | 2 +- src/liballoc_jemalloc/build.rs | 2 +- src/libprofiler_builtins/build.rs | 2 +- src/librustc_llvm/build.rs | 2 +- src/librustdoc/build.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index ac068ebe65178..a5408ee381bbb 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -316,7 +316,7 @@ impl Step for TestHelpers { .warnings(false) .debug(false) .file(build.src.join("src/rt/rust_test_helpers.c")) - .compile("librust_test_helpers.a"); + .compile("rust_test_helpers"); } } diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index a41a04d7cd4f6..de5006ad3960a 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -140,6 +140,6 @@ fn main() { cc::Build::new() .flag("-fvisibility=hidden") .file("pthread_atfork_dummy.c") - .compile("libpthread_atfork_dummy.a"); + .compile("pthread_atfork_dummy"); } } diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs index 8508b2dae2c56..dd88dd933f691 100644 --- a/src/libprofiler_builtins/build.rs +++ b/src/libprofiler_builtins/build.rs @@ -56,5 +56,5 @@ fn main() { cfg.file(Path::new("../libcompiler_builtins/compiler-rt/lib/profile").join(src)); } - cfg.compile("libprofiler-rt.a"); + cfg.compile("profiler-rt"); } diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index d860c6c44f024..f294ceb3f3832 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -169,7 +169,7 @@ fn main() { .file("../rustllvm/ArchiveWrapper.cpp") .cpp(true) .cpp_link_stdlib(None) // we handle this below - .compile("librustllvm.a"); + .compile("rustllvm"); let (llvm_kind, llvm_link_arg) = detect_llvm_link(major, minor, &llvm_config); diff --git a/src/librustdoc/build.rs b/src/librustdoc/build.rs index 97c9ca1e2d27c..276825bd31a75 100644 --- a/src/librustdoc/build.rs +++ b/src/librustdoc/build.rs @@ -27,6 +27,6 @@ fn main() { .warnings(false) .include(src_dir) .warnings(false) - .compile("libhoedown.a"); + .compile("hoedown"); } From c00ba79f5cc683182c8cd37b1f2b1b07f108db0a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 29 Nov 2017 19:23:41 +0100 Subject: [PATCH 04/17] Invert colors in important traits tooltip --- src/librustdoc/html/static/rustdoc.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index d7f4674908c58..7efe7e1ae3eb3 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -920,6 +920,12 @@ span.since { border-color: transparent black transparent transparent; } +.important-traits .tooltip .tooltiptext { + background-color: white; + color: black; + border: 1px solid #000; +} + pre.rust { position: relative; } From 326eb79cf61a4ff22b10467d60330417294b91dd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Nov 2017 15:00:52 -0800 Subject: [PATCH 05/17] rustbuild: Fix a typo with the Cargo book The usage of `Path::new` prevented out-of-tree builds (like the bots do) from working by accident! Closes #46195 --- src/bootstrap/doc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 9186699a3b583..3c12cfc4c7ffd 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -159,7 +159,7 @@ impl Step for CargoBook { let target = self.target; let name = self.name; - let src = PathBuf::from("src/tools/cargo/src/doc/book"); + let src = build.src.join("src/tools/cargo/src/doc/book"); let out = build.doc_out(target); t!(fs::create_dir_all(&out)); From 21228a82b05a759456a6f121a0b6ef85e39ab19f Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 29 Nov 2017 18:10:42 -0500 Subject: [PATCH 06/17] Remove librustdoc dependency on env_logger We want librustdoc to pickup the env_logger dependency from the sysroot. This ensures that the same copy of env_logger is used for both internal crates (e.g. librustc_driver, libsyntax) and librustdoc Closes #46383 --- src/Cargo.lock | 1 - src/librustdoc/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index e5e9775a924b4..a809721cf9023 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1966,7 +1966,6 @@ version = "0.0.0" dependencies = [ "build_helper 0.1.0", "cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "html-diff 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 55d2df5f28bd9..eca3ebe9130fd 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -11,7 +11,6 @@ path = "lib.rs" doctest = false [dependencies] -env_logger = { version = "0.4", default-features = false } log = "0.3" pulldown-cmark = { version = "0.1.0", default-features = false } html-diff = "0.0.5" From 91a41069115c70f95509fadae70e67c0effbed93 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 00:28:59 +0100 Subject: [PATCH 07/17] Fix rustoc item summaries that are headers Rustoc item summaries that are headers were not displayed at all because they started with whitespace. This PR fixes this and now removes the whitespace and then displays the block. --- src/librustdoc/html/render.rs | 4 +++- src/test/rustdoc/issue-46377.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/issue-46377.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index cf557b1c661d6..41918dfd3c315 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1819,7 +1819,9 @@ fn full_path(cx: &Context, item: &clean::Item) -> String { fn shorter<'a>(s: Option<&'a str>) -> String { match s { - Some(s) => s.lines().take_while(|line|{ + Some(s) => s.lines() + .skip_while(|s| s.chars().all(|c| c.is_whitespace())) + .take_while(|line|{ (*line).chars().any(|chr|{ !chr.is_whitespace() }) diff --git a/src/test/rustdoc/issue-46377.rs b/src/test/rustdoc/issue-46377.rs new file mode 100644 index 0000000000000..db8c7660df1d8 --- /dev/null +++ b/src/test/rustdoc/issue-46377.rs @@ -0,0 +1,13 @@ +// Copyright 2015 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. + +// @has 'issue_46377/index.html' '//*[@class="docblock-short"]' 'Check out this struct!' +/// # Check out this struct! +pub struct SomeStruct; From 2544b9fbf04d49c33ee86f90002334b716061254 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 29 Nov 2017 19:51:16 +0100 Subject: [PATCH 08/17] Update Cargo to Wed Nov 29 15:19:05 2017 +0000 https://github.com/rust-lang/cargo/commit/5bb478a518bcf75537409e8b71f6b7cc4af362df Pick up `workspace.default-members` support: https://github.com/rust-lang/cargo/pull/4743 --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 6529d418db18a..5bb478a518bcf 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 6529d418db18ac28622fc2fe0bade0d690c6bd71 +Subproject commit 5bb478a518bcf75537409e8b71f6b7cc4af362df From 5a00b7cb74ba1511c012c0163a29cd6972d64135 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Thu, 9 Nov 2017 00:46:15 +0200 Subject: [PATCH 09/17] make coercions to `!` in unreachable code a hard error This was added to cover up a lazy extra semicolon in #35849, but does not actually make sense. This is removed as a part of the stabilization of `never_type`. --- src/librustc/lint/builtin.rs | 9 ++++++- src/librustc_lint/lib.rs | 4 ++++ src/librustc_typeck/check/coercion.rs | 11 ++++++++- src/test/compile-fail/coerce-to-bang-cast.rs | 3 +++ src/test/compile-fail/coerce-to-bang.rs | 7 ++++++ .../compile-fail/diverging-fn-tail-35849.rs | 10 +++++--- src/test/run-pass/diverging-fn-tail-35849.rs | 2 +- src/test/ui/reachable/expr_unary.rs | 5 +++- src/test/ui/reachable/expr_unary.stderr | 24 +++++++++++++++---- 9 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index ef4a1c8c39949..1008da1e937a5 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -222,6 +222,12 @@ declare_lint! { "detect mut variables which don't need to be mutable" } +declare_lint! { + pub COERCE_NEVER, + Deny, + "detect coercion to !" +} + /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. #[derive(Copy, Clone)] @@ -263,7 +269,8 @@ impl LintPass for HardwiredLints { LATE_BOUND_LIFETIME_ARGUMENTS, DEPRECATED, UNUSED_UNSAFE, - UNUSED_MUT + UNUSED_MUT, + COERCE_NEVER ) } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index b4d439f0ba809..fc05f8f0dc245 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -247,6 +247,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(SAFE_PACKED_BORROWS), reference: "issue #46043 ", }, + FutureIncompatibleInfo { + id: LintId::of(COERCE_NEVER), + reference: "issue #46325 ", + }, ]); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 94422f93e5922..3e725d7ef415c 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -66,6 +66,7 @@ use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::{Coercion, InferResult, InferOk}; use rustc::infer::type_variable::TypeVariableOrigin; +use rustc::lint; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow}; use rustc::ty::{self, LvaluePreference, TypeAndMut, @@ -754,7 +755,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // type, but only if the source expression diverges. if target.is_never() && expr_diverges.always() { debug!("permit coercion to `!` because expr diverges"); - return Ok(target); + if self.can_eq(self.param_env, source, target).is_err() { + self.tcx.lint_node( + lint::builtin::COERCE_NEVER, + expr.id, + expr.span, + &format!("cannot coerce `{}` to !", source) + ); + return Ok(target); + } } let cause = self.cause(expr.span, ObligationCauseCode::ExprAssignable); diff --git a/src/test/compile-fail/coerce-to-bang-cast.rs b/src/test/compile-fail/coerce-to-bang-cast.rs index 0479f5cce6537..0d5bf6cd68cb8 100644 --- a/src/test/compile-fail/coerce-to-bang-cast.rs +++ b/src/test/compile-fail/coerce-to-bang-cast.rs @@ -12,8 +12,11 @@ fn foo(x: usize, y: !, z: usize) { } +#[deny(coerce_never)] fn cast_a() { let y = {return; 22} as !; + //~^ ERROR cannot coerce `i32` to ! + //~| hard error } fn cast_b() { diff --git a/src/test/compile-fail/coerce-to-bang.rs b/src/test/compile-fail/coerce-to-bang.rs index 870665bb49ee6..2cf568777d475 100644 --- a/src/test/compile-fail/coerce-to-bang.rs +++ b/src/test/compile-fail/coerce-to-bang.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(never_type)] +#![deny(coerce_never)] fn foo(x: usize, y: !, z: usize) { } @@ -17,6 +18,8 @@ fn call_foo_a() { // the coercion to `!`, but within same expression. Not clear that // these are the rules we want. foo(return, 22, 44); + //~^ ERROR cannot coerce `{integer}` to ! + //~| hard error } fn call_foo_b() { @@ -36,6 +39,8 @@ fn call_foo_d() { let b = 22; let c = 44; foo(a, b, c); // ... and hence a reference to `a` is expected to diverge. + //~^ ERROR cannot coerce `{integer}` to ! + //~| hard error } fn call_foo_e() { @@ -75,6 +80,8 @@ fn tuple_a() { fn tuple_b() { // Divergence happens before coercion: OK let x: (usize, !, usize) = (return, 44, 66); + //~^ ERROR cannot coerce `{integer}` to ! + //~| hard error } fn tuple_c() { diff --git a/src/test/compile-fail/diverging-fn-tail-35849.rs b/src/test/compile-fail/diverging-fn-tail-35849.rs index 3a27c08413328..a91c000bbf712 100644 --- a/src/test/compile-fail/diverging-fn-tail-35849.rs +++ b/src/test/compile-fail/diverging-fn-tail-35849.rs @@ -8,9 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn _converge() -> ! { - 42 //~ ERROR mismatched types +#[deny(coerce_never)] +fn assert_sizeof() -> ! { + unsafe { + ::std::mem::transmute::(panic!()) + //~^ ERROR cannot coerce `[u8; 8]` to ! + //~| hard error + } } fn main() { } - diff --git a/src/test/run-pass/diverging-fn-tail-35849.rs b/src/test/run-pass/diverging-fn-tail-35849.rs index 6c05a02e7183c..dfd99bcc9fb47 100644 --- a/src/test/run-pass/diverging-fn-tail-35849.rs +++ b/src/test/run-pass/diverging-fn-tail-35849.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(coerce_never)] fn assert_sizeof() -> ! { unsafe { ::std::mem::transmute::(panic!()) @@ -15,4 +16,3 @@ fn assert_sizeof() -> ! { } fn main() { } - diff --git a/src/test/ui/reachable/expr_unary.rs b/src/test/ui/reachable/expr_unary.rs index 6cff3ff964439..ad12cb876fe9b 100644 --- a/src/test/ui/reachable/expr_unary.rs +++ b/src/test/ui/reachable/expr_unary.rs @@ -12,11 +12,14 @@ #![allow(unused_assignments)] #![allow(dead_code)] #![deny(unreachable_code)] +#![deny(coerce_never)] #![feature(never_type)] fn foo() { let x: ! = ! { return; 22 }; //~ ERROR unreachable - //~^ ERROR cannot apply unary operator `!` to type `!` + //~^ ERROR cannot coerce + //~| hard error + //~| ERROR cannot apply unary operator `!` to type `!` } fn main() { } diff --git a/src/test/ui/reachable/expr_unary.stderr b/src/test/ui/reachable/expr_unary.stderr index f14824728a70c..39120f0bdf980 100644 --- a/src/test/ui/reachable/expr_unary.stderr +++ b/src/test/ui/reachable/expr_unary.stderr @@ -1,7 +1,7 @@ error: unreachable expression - --> $DIR/expr_unary.rs:18:28 + --> $DIR/expr_unary.rs:19:28 | -18 | let x: ! = ! { return; 22 }; //~ ERROR unreachable +19 | let x: ! = ! { return; 22 }; //~ ERROR unreachable | ^^ | note: lint level defined here @@ -10,11 +10,25 @@ note: lint level defined here 14 | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ +error: cannot coerce `{integer}` to ! + --> $DIR/expr_unary.rs:19:28 + | +19 | let x: ! = ! { return; 22 }; //~ ERROR unreachable + | ^^ + | +note: lint level defined here + --> $DIR/expr_unary.rs:15:9 + | +15 | #![deny(coerce_never)] + | ^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #46325 + error[E0600]: cannot apply unary operator `!` to type `!` - --> $DIR/expr_unary.rs:18:16 + --> $DIR/expr_unary.rs:19:16 | -18 | let x: ! = ! { return; 22 }; //~ ERROR unreachable +19 | let x: ! = ! { return; 22 }; //~ ERROR unreachable | ^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors From 666bb903000205a642f62a5bd3f6ccbdca47c5eb Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 28 Nov 2017 16:07:12 -0800 Subject: [PATCH 10/17] wasm: Update LLVM to fix a test This commit updates LLVM with some tweaks to the integer <-> floating point conversion instructions to ensure that `as` in Rust doesn't trap. Closes #46298 --- src/llvm | 2 +- src/test/run-pass/saturating-float-casts.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/llvm b/src/llvm index 487c636342ea1..6d08185a5cf48 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 487c636342ea1abe64d6387eade963a91a152aa9 +Subproject commit 6d08185a5cf488d0a853b065a8a3a6d7a29f084f diff --git a/src/test/run-pass/saturating-float-casts.rs b/src/test/run-pass/saturating-float-casts.rs index 4cd171f0ac089..c8fa49c62a0b6 100644 --- a/src/test/run-pass/saturating-float-casts.rs +++ b/src/test/run-pass/saturating-float-casts.rs @@ -10,7 +10,6 @@ // Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction. // compile-flags: -Z saturating-float-casts -// ignore-wasm32-bare FIXME(#46298) needs upstream llvm fixes #![feature(test, i128, i128_type, stmt_expr_attributes)] #![deny(overflowing_literals)] From 780f4ed882e7e6928210d300765c4836bcb49147 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 30 Nov 2017 14:34:09 +0100 Subject: [PATCH 11/17] incr.comp.: Make traits::VTable encodable and decodable. --- src/librustc/traits/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index a3a5c26ec186a..8d1bba4332276 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -282,7 +282,7 @@ pub type SelectionResult<'tcx, T> = Result, SelectionError<'tcx>>; /// ### The type parameter `N` /// /// See explanation on `VtableImplData`. -#[derive(Clone)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub enum Vtable<'tcx, N> { /// Vtable identifying a particular impl. VtableImpl(VtableImplData<'tcx, N>), @@ -327,14 +327,14 @@ pub enum Vtable<'tcx, N> { /// is `Obligation`, as one might expect. During trans, however, this /// is `()`, because trans only requires a shallow resolution of an /// impl, and nested obligations are satisfied later. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub struct VtableImplData<'tcx, N> { pub impl_def_id: DefId, pub substs: &'tcx Substs<'tcx>, pub nested: Vec } -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub struct VtableGeneratorData<'tcx, N> { pub closure_def_id: DefId, pub substs: ty::ClosureSubsts<'tcx>, @@ -343,7 +343,7 @@ pub struct VtableGeneratorData<'tcx, N> { pub nested: Vec } -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub struct VtableClosureData<'tcx, N> { pub closure_def_id: DefId, pub substs: ty::ClosureSubsts<'tcx>, @@ -352,20 +352,20 @@ pub struct VtableClosureData<'tcx, N> { pub nested: Vec } -#[derive(Clone)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub struct VtableAutoImplData { pub trait_def_id: DefId, pub nested: Vec } -#[derive(Clone)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub struct VtableBuiltinData { pub nested: Vec } /// A vtable for some object-safe trait `Foo` automatically derived /// for the object type `Foo`. -#[derive(PartialEq,Eq,Clone)] +#[derive(PartialEq, Eq, Clone, RustcEncodable, RustcDecodable)] pub struct VtableObjectData<'tcx, N> { /// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`. pub upcast_trait_ref: ty::PolyTraitRef<'tcx>, @@ -378,7 +378,7 @@ pub struct VtableObjectData<'tcx, N> { pub nested: Vec, } -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub struct VtableFnPointerData<'tcx, N> { pub fn_ty: Ty<'tcx>, pub nested: Vec From 4e74eb5ba0bbf60ab70a0680d1e07d7a0f59d383 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Nov 2017 07:59:35 -0800 Subject: [PATCH 12/17] rustc: Filter out bogus extern crate warnings Rustdoc has for some time now used the "everybody loops" pass in the compiler to avoid typechecking and otherwise avoid looking at implementation details. In #46115 the placement of this pass was pushed back in the compiler to after macro expansion to ensure that it works with macro-expanded code as well. This in turn caused the regression in #46271. The bug here was that the resolver was producing `def_id` instances for "possibly unused extern crates" which would then later get processed during typeck to actually issue lint warnings. The problem was that *after* resolution these `def_id` nodes were actually removed from the AST by the "everybody loops" pass. This later, when we tried to take a look at `def_id`, caused the compiler to panic. The fix applied here is a bit of a heavy hammer which is to just, in this one case, ignore the `extern crate` lints if the `def_id` looks "bogus" in any way (basically if it looks like the node was removed after resolution). The real underlying bug here is probably that the "everybody loops" AST pass is being stressed to much beyond what it was originally intended to do, but this should at least fix the ICE for now... Closes #46271 --- src/librustc_typeck/check_unused.rs | 19 +++++++++++++++++++ src/test/rustdoc/issue-46271.rs | 15 +++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/test/rustdoc/issue-46271.rs diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index b867a655b4a6a..f2f1e2938cb12 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -75,6 +75,25 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { tcx.hir.krate().visit_all_item_likes(&mut visitor); for &(def_id, span) in tcx.maybe_unused_extern_crates(LOCAL_CRATE).iter() { + // The `def_id` here actually was calculated during resolution (at least + // at the time of this writing) and is being shipped to us via a side + // channel of the tcx. There may have been extra expansion phases, + // however, which ended up removing the `def_id` *after* expansion such + // as the `ReplaceBodyWithLoop` pass (which is a bit of a hack, but hey) + // + // As a result we need to verify that `def_id` is indeed still valid for + // our AST and actually present in the HIR map. If it's not there then + // there's safely nothing to warn about, and otherwise we carry on with + // our execution. + // + // Note that if we carry through to the `extern_mod_stmt_cnum` query + // below it'll cause a panic because `def_id` is actually bogus at this + // point in time otherwise. + if let Some(id) = tcx.hir.as_local_node_id(def_id) { + if tcx.hir.find(id).is_none() { + continue + } + } let cnum = tcx.extern_mod_stmt_cnum(def_id).unwrap(); if tcx.is_compiler_builtins(cnum) { continue diff --git a/src/test/rustdoc/issue-46271.rs b/src/test/rustdoc/issue-46271.rs new file mode 100644 index 0000000000000..cc3be08c5688d --- /dev/null +++ b/src/test/rustdoc/issue-46271.rs @@ -0,0 +1,15 @@ +// 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. + +// hopefully this doesn't cause an ICE + +pub fn foo() { + extern crate std; +} From ccef9696f13b39b619f7b12d770a2908cc2ecdd3 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Kollasch" Date: Wed, 29 Nov 2017 11:31:09 -0600 Subject: [PATCH 13/17] NetBSD: add sysctl backend for std::env::current_exe Use the CTL_KERN.KERN_PROC_ARGS.-1.KERN_PROC_PATHNAME sysctl in preference over the /proc/curproc/exe symlink. Additionally, perform more validation of aformentioned symlink. Particularly on pre-8.x NetBSD this symlink will point to '/' when accurate information is unavailable. --- src/libstd/sys/unix/os.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 7e965b4b4c5b2..4f33a2b12fe5d 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -223,7 +223,34 @@ pub fn current_exe() -> io::Result { #[cfg(target_os = "netbsd")] pub fn current_exe() -> io::Result { - ::fs::read_link("/proc/curproc/exe") + fn sysctl() -> io::Result { + unsafe { + let mib = [libc::CTL_KERN, libc::KERN_PROC_ARGS, -1, libc::KERN_PROC_PATHNAME]; + let mut path_len: usize = 0; + cvt(libc::sysctl(mib.as_ptr(), mib.len() as ::libc::c_uint, + ptr::null_mut(), &mut path_len, + ptr::null(), 0))?; + if path_len <= 1 { + return Err(io::Error::new(io::ErrorKind::Other, + "KERN_PROC_PATHNAME sysctl returned zero-length string")) + } + let mut path: Vec = Vec::with_capacity(path_len); + cvt(libc::sysctl(mib.as_ptr(), mib.len() as ::libc::c_uint, + path.as_ptr() as *mut libc::c_void, &mut path_len, + ptr::null(), 0))?; + path.set_len(path_len - 1); // chop off NUL + Ok(PathBuf::from(OsString::from_vec(path))) + } + } + fn procfs() -> io::Result { + let curproc_exe = path::Path::new("/proc/curproc/exe"); + if curproc_exe.is_file() { + return ::fs::read_link(curproc_exe); + } + Err(io::Error::new(io::ErrorKind::Other, + "/proc/curproc/exe doesn't point to regular file.")) + } + sysctl().or_else(|_| procfs()) } #[cfg(any(target_os = "bitrig", target_os = "openbsd"))] From ec337b613ec5519a54f2948f9d8b7beea5cba86b Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:18:00 +0100 Subject: [PATCH 14/17] Show hidden items with rustdoc's document-private When using `#[doc(hidden)]` elements are hidden from docs even when the rustdoc flag `--document-private-items` is set. This behavior has been changed to display all hidden items when the flag is active. --- src/librustdoc/lib.rs | 1 - src/test/rustdoc/issue-46380.rs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/issue-46380.rs diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index fcb25f7aef3d4..967076779add0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -470,7 +470,6 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R { default_passes = false; passes = vec![ - String::from("strip-hidden"), String::from("collapse-docs"), String::from("unindent-comments"), ]; diff --git a/src/test/rustdoc/issue-46380.rs b/src/test/rustdoc/issue-46380.rs new file mode 100644 index 0000000000000..85f29ec4b02d1 --- /dev/null +++ b/src/test/rustdoc/issue-46380.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +// compile-flags: --document-private-items + +// @has issue_46380/struct.Hidden.html +#[doc(hidden)] +pub struct Hidden; From 1df13c057a7f1937170fe600d24256f0bf943ec2 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:18:36 +0100 Subject: [PATCH 15/17] Hide trait impl with private trait type parameter Trait's implementations with private type parameters were displayed in the implementing struct's documentation until now. With this change any trait implementation that uses a private type parameter is now hidden in the docs. --- src/librustdoc/passes/mod.rs | 9 +++++++++ src/test/rustdoc/issue-46380-2.rs | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/rustdoc/issue-46380-2.rs diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 77d97c84c99bf..3e15d3d3007ac 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -184,6 +184,15 @@ impl<'a> fold::DocFolder for ImplStripper<'a> { return None; } } + if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) { + for typaram in generics { + if let Some(did) = typaram.def_id() { + if did.is_local() && !self.retained.contains(&did) { + return None; + } + } + } + } } self.fold_item_recur(i) } diff --git a/src/test/rustdoc/issue-46380-2.rs b/src/test/rustdoc/issue-46380-2.rs new file mode 100644 index 0000000000000..93a1ee72013c3 --- /dev/null +++ b/src/test/rustdoc/issue-46380-2.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +pub trait PublicTrait {} + +// @has issue_46380_2/struct.Public.html +pub struct PublicStruct; + +// @!has - '//*[@class="impl"]' 'impl Add for Public' +impl PublicTrait for PublicStruct {} + +struct PrivateStruct; From 5f47c7f531a4a93a563e02a0d5206c5c7139801f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:43:21 +0100 Subject: [PATCH 16/17] Fix htmldocck naming After renaming the structs and enums the htmldocck strings still contained the old names. This lead to test failure. These htmldocck tests have been updated to use the proper names of the rust structs and traits. --- src/test/rustdoc/issue-46380-2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc/issue-46380-2.rs b/src/test/rustdoc/issue-46380-2.rs index 93a1ee72013c3..22408d3522a4b 100644 --- a/src/test/rustdoc/issue-46380-2.rs +++ b/src/test/rustdoc/issue-46380-2.rs @@ -10,10 +10,10 @@ pub trait PublicTrait {} -// @has issue_46380_2/struct.Public.html +// @has issue_46380_2/struct.PublicStruct.html pub struct PublicStruct; -// @!has - '//*[@class="impl"]' 'impl Add for Public' +// @!has - '//*[@class="impl"]' 'impl PublicTrait for PublicStruct' impl PublicTrait for PublicStruct {} struct PrivateStruct; From f2df1f5ec6648713791c07b5ca79fa4da87b7d74 Mon Sep 17 00:00:00 2001 From: Nikolay Merinov Date: Fri, 1 Dec 2017 14:28:14 +0500 Subject: [PATCH 17/17] build_helper: destination file can't be up to date when not exists Function "up_to_date" return incorrect result if mtime for all fetched sources is set to epoch time. Add existence check to function. --- src/build_helper/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index 97723e260f6cb..2b6e2828cfb4b 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -190,6 +190,9 @@ pub fn mtime(path: &Path) -> FileTime { /// /// Uses last-modified time checks to verify this. pub fn up_to_date(src: &Path, dst: &Path) -> bool { + if !dst.exists() { + return false; + } let threshold = mtime(dst); let meta = match fs::metadata(src) { Ok(meta) => meta,