From 38ddb446b9da85532fc4a1540eff45509b0b9289 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 14 Jan 2018 08:25:18 +0100 Subject: [PATCH 01/19] Check for deadlinks from the summary during book generation Previously, any deadlinks from a book's SUMMARY.md wouldn't cause any errors or warnings or similar but mdbook would simply create a page with blank content. This has kept bug #47394 hidden. It should have been detected back in the PR when those wrongly named files got added to the book. PR #47414 was one component of the solution. This change is a second line of defense for the unstable book and a first line of defense for any other book. We also update mdbook to the most recent version. --- src/Cargo.lock | 6 +++--- src/tools/rustbook/Cargo.toml | 2 +- src/tools/rustbook/src/main.rs | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 8fbf3535264..249fabea411 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1114,7 +1114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mdbook" -version = "0.0.26" +version = "0.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1697,7 +1697,7 @@ name = "rustbook" version = "0.1.0" dependencies = [ "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)", - "mdbook 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "mdbook 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2882,7 +2882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" "checksum markup5ever 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "047150a0e03b57e638fc45af33a0b63a0362305d5b9f92ecef81df472a4cceb0" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" -"checksum mdbook 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "8a1ac668292d1e5c7b1c6fd64f70d3a85105b8069a89558a0d67bdb2ff298ca1" +"checksum mdbook 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "1ee8ba20c002000546681dc78d7f7e91fd35832058b1e2fdd492ca842bb6e9be" "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" diff --git a/src/tools/rustbook/Cargo.toml b/src/tools/rustbook/Cargo.toml index 4aa096246bc..bc35cbe9fbb 100644 --- a/src/tools/rustbook/Cargo.toml +++ b/src/tools/rustbook/Cargo.toml @@ -8,5 +8,5 @@ license = "MIT/Apache-2.0" clap = "2.25.0" [dependencies.mdbook] -version = "0.0.26" +version = "0.0.28" default-features = false diff --git a/src/tools/rustbook/src/main.rs b/src/tools/rustbook/src/main.rs index a0c3e811a7a..50f4364e448 100644 --- a/src/tools/rustbook/src/main.rs +++ b/src/tools/rustbook/src/main.rs @@ -52,12 +52,14 @@ fn main() { // Build command implementation pub fn build(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let book = MDBook::new(&book_dir).read_config()?; + let mut book = MDBook::new(&book_dir).read_config()?; - let mut book = match args.value_of("dest-dir") { - Some(dest_dir) => book.with_destination(dest_dir), - None => book, - }; + // Set this to allow us to catch bugs in advance. + book.config.build.create_missing = false; + + if let Some(dest_dir) = args.value_of("dest-dir") { + book.config.build.build_dir = PathBuf::from(dest_dir); + } book.build()?; From f4bcfc5317258c77e25ab5c0f3eec5599287fdbd Mon Sep 17 00:00:00 2001 From: Petr Sumbera Date: Thu, 18 Jan 2018 04:26:01 -0800 Subject: [PATCH 02/19] Fixes sparc64 cabi fixes. Argument up to 16 bytes size is provided in registers. Return value up to 32 bytes size is stored in registers. Fixes: #46679 --- src/librustc_trans/cabi_sparc64.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc_trans/cabi_sparc64.rs b/src/librustc_trans/cabi_sparc64.rs index fb94b09d626..6c5d3254191 100644 --- a/src/librustc_trans/cabi_sparc64.rs +++ b/src/librustc_trans/cabi_sparc64.rs @@ -24,7 +24,7 @@ fn is_homogeneous_aggregate<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, arg: &mut ArgTyp let valid_unit = match unit.kind { RegKind::Integer => false, RegKind::Float => true, - RegKind::Vector => arg.layout.size.bits() == 128 + RegKind::Vector => arg.layout.size.bits() == 256 }; if valid_unit { @@ -50,7 +50,7 @@ fn classify_ret_ty<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>) } let size = ret.layout.size; let bits = size.bits(); - if bits <= 128 { + if bits <= 256 { let unit = if bits <= 8 { Reg::i8() } else if bits <= 16 { @@ -84,6 +84,11 @@ fn classify_arg_ty<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>) } let total = arg.layout.size; + if total.bits() > 128 { + arg.make_indirect(cx); + return; + } + arg.cast_to(Uniform { unit: Reg::i64(), total From af632bc1c51a6a240c5e68b7eecc59440322ea62 Mon Sep 17 00:00:00 2001 From: Petr Sumbera Date: Thu, 18 Jan 2018 10:24:16 -0800 Subject: [PATCH 03/19] Removed uneeded change. --- src/librustc_trans/cabi_sparc64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/cabi_sparc64.rs b/src/librustc_trans/cabi_sparc64.rs index 6c5d3254191..8d560865287 100644 --- a/src/librustc_trans/cabi_sparc64.rs +++ b/src/librustc_trans/cabi_sparc64.rs @@ -24,7 +24,7 @@ fn is_homogeneous_aggregate<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, arg: &mut ArgTyp let valid_unit = match unit.kind { RegKind::Integer => false, RegKind::Float => true, - RegKind::Vector => arg.layout.size.bits() == 256 + RegKind::Vector => arg.layout.size.bits() == 128 }; if valid_unit { From 1203b3d892b6f8424f6540173e31af1cda304e36 Mon Sep 17 00:00:00 2001 From: Petr Sumbera Date: Thu, 18 Jan 2018 11:03:49 -0800 Subject: [PATCH 04/19] Removed uneeded argument to make_indirect. --- src/librustc_trans/cabi_sparc64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/cabi_sparc64.rs b/src/librustc_trans/cabi_sparc64.rs index 8d560865287..b3fc6a68061 100644 --- a/src/librustc_trans/cabi_sparc64.rs +++ b/src/librustc_trans/cabi_sparc64.rs @@ -85,7 +85,7 @@ fn classify_arg_ty<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, arg: &mut ArgType<'tcx>) let total = arg.layout.size; if total.bits() > 128 { - arg.make_indirect(cx); + arg.make_indirect(); return; } From 66d53ca9e540eb564ab9ac3420a13ceac7a77a65 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Thu, 18 Jan 2018 21:09:34 +0100 Subject: [PATCH 05/19] Make liballoc_jemalloc work on CloudABI. The automated builds for CloudABI in dist-various-2 don't use --disable-jemalloc, even though my original container image did. Instead of setting that flag, let's go the extra mile of making jemalloc work. CloudABI's C library already uses jemalloc and now exposes the API extensions used by us. --- src/liballoc_jemalloc/build.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index 440c9fbf2f6..0aa46dc6d20 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -29,13 +29,20 @@ fn main() { // for targets like emscripten, even if we don't use it. let target = env::var("TARGET").expect("TARGET was not set"); let host = env::var("HOST").expect("HOST was not set"); - if target.contains("bitrig") || target.contains("cloudabi") || target.contains("emscripten") || - target.contains("fuchsia") || target.contains("msvc") || target.contains("openbsd") || - target.contains("redox") || target.contains("rumprun") || target.contains("wasm32") { + if target.contains("bitrig") || target.contains("emscripten") || target.contains("fuchsia") || + target.contains("msvc") || target.contains("openbsd") || target.contains("redox") || + target.contains("rumprun") || target.contains("wasm32") { println!("cargo:rustc-cfg=dummy_jemalloc"); return; } + // CloudABI ships with a copy of jemalloc that has been patched to + // work well with sandboxing. Don't attempt to build our own copy, + // as it won't build. + if target.contains("cloudabi") { + return; + } + if target.contains("android") { println!("cargo:rustc-link-lib=gcc"); } else if !target.contains("windows") && !target.contains("musl") { From ebfa6c709aecb12a164695912785643d916e75fb Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Sun, 14 Jan 2018 21:11:40 -0600 Subject: [PATCH 06/19] Change the --unpretty flag to -Z unpretty -Z unpretty no longer requires -Z unstable-options. Also, I mildly changed the syntax of the flag to match the other -Z flags. All uses of the flag take the form `unpretty=something` where something can either `string` or `string=string` (see the help messages of the CLI). --- src/librustc/session/config.rs | 36 ++++++++++++------- src/librustc_driver/lib.rs | 5 +-- src/librustc_driver/pretty.rs | 8 ++--- src/test/compile-fail/issue-37665.rs | 2 +- src/test/compile-fail/mir-unpretty.rs | 2 +- src/test/run-make/hir-tree/Makefile | 3 +- .../pretty-print-path-suffix/Makefile | 6 ++-- src/tools/compiletest/src/runtest.rs | 3 +- 8 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 69b86416afa..8efd6b458e9 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -778,6 +778,8 @@ macro_rules! options { Some(::rustc_back::LinkerFlavor::one_of()); pub const parse_optimization_fuel: Option<&'static str> = Some("crate=integer"); + pub const parse_unpretty: Option<&'static str> = + Some("`string` or `string=string`"); } #[allow(dead_code)] @@ -965,6 +967,17 @@ macro_rules! options { } } } + + fn parse_unpretty(slot: &mut Option, v: Option<&str>) -> bool { + match v { + None => false, + Some(s) if s.split('=').count() <= 2 => { + *slot = Some(s.to_string()); + true + } + _ => false, + } + } } ) } @@ -1102,13 +1115,13 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "write syntax and type analysis (in JSON format) information, in \ addition to normal output"), flowgraph_print_loans: bool = (false, parse_bool, [UNTRACKED], - "include loan analysis data in --unpretty flowgraph output"), + "include loan analysis data in -Z unpretty flowgraph output"), flowgraph_print_moves: bool = (false, parse_bool, [UNTRACKED], - "include move analysis data in --unpretty flowgraph output"), + "include move analysis data in -Z unpretty flowgraph output"), flowgraph_print_assigns: bool = (false, parse_bool, [UNTRACKED], - "include assignment analysis data in --unpretty flowgraph output"), + "include assignment analysis data in -Z unpretty flowgraph output"), flowgraph_print_all: bool = (false, parse_bool, [UNTRACKED], - "include all dataflow analysis data in --unpretty flowgraph output"), + "include all dataflow analysis data in -Z unpretty flowgraph output"), print_region_graph: bool = (false, parse_bool, [UNTRACKED], "prints region inference graph. \ Use with RUST_REGION_GRAPH=help for more info"), @@ -1239,6 +1252,13 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED], "in dep-info output, omit targets for tracking dependencies of the dep-info files \ themselves"), + unpretty: Option = (None, parse_unpretty, [UNTRACKED], + "Present the input source, unstable (and less-pretty) variants; + valid types are any of the types for `--pretty`, as well as: + `flowgraph=` (graphviz formatted flowgraph for node), + `everybody_loops` (all function bodies replaced with `loop {}`), + `hir` (the HIR), `hir,identified`, or + `hir,typed` (HIR with types for each node)."), } pub fn default_lib_output() -> CrateType { @@ -1512,14 +1532,6 @@ pub fn rustc_optgroups() -> Vec { `expanded` (crates expanded), or `expanded,identified` (fully parenthesized, AST nodes with IDs).", "TYPE"), - opt::opt("", "unpretty", - "Present the input source, unstable (and less-pretty) variants; - valid types are any of the types for `--pretty`, as well as: - `flowgraph=` (graphviz formatted flowgraph for node), - `everybody_loops` (all function bodies replaced with `loop {}`), - `hir` (the HIR), `hir,identified`, or - `hir,typed` (HIR with types for each node).", - "TYPE"), ]); opts } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 237656eb43c..a985fa073ef 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -292,8 +292,9 @@ fn parse_pretty(sess: &Session, } else { None }; - if pretty.is_none() && sess.unstable_options() { - matches.opt_str("unpretty").map(|a| { + + if pretty.is_none() { + sess.opts.debugging_opts.unpretty.as_ref().map(|a| { // extended with unstable pretty-print variants pretty::parse_pretty(sess, &a, true) }) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 6ce6929af5c..a771cdad70f 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -66,7 +66,7 @@ pub enum PpSourceMode { pub enum PpFlowGraphMode { Default, /// Drops the labels from the edges in the flowgraph output. This - /// is mostly for use in the --unpretty flowgraph run-make tests, + /// is mostly for use in the -Z unpretty flowgraph run-make tests, /// since the labels are largely uninteresting in those cases and /// have become a pain to maintain. UnlabelledEdges, @@ -1006,7 +1006,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, move |annotation, _| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); - let hir_map = annotation.hir_map().expect("--unpretty missing HIR map"); + let hir_map = annotation.hir_map().expect("-Z unpretty missing HIR map"); let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(), &sess.parse_sess, src_name, @@ -1019,7 +1019,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, pp_state.print_node(node)?; pp_state.s.space()?; let path = annotation.node_path(node_id) - .expect("--unpretty missing node paths"); + .expect("-Z unpretty missing node paths"); pp_state.synth_comment(path)?; pp_state.s.hardbreak()?; } @@ -1071,7 +1071,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, ofile: Option<&Path>) { let nodeid = if let Some(uii) = uii { debug!("pretty printing for {:?}", uii); - Some(uii.to_one_node_id("--unpretty", sess, &hir_map)) + Some(uii.to_one_node_id("-Z unpretty", sess, &hir_map)) } else { debug!("pretty printing for whole crate"); None diff --git a/src/test/compile-fail/issue-37665.rs b/src/test/compile-fail/issue-37665.rs index 98e62965235..81ed4375e77 100644 --- a/src/test/compile-fail/issue-37665.rs +++ b/src/test/compile-fail/issue-37665.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -Z unstable-options --unpretty=mir +// compile-flags: -Z unpretty=mir // ignore-cloudabi no std::path use std::path::MAIN_SEPARATOR; diff --git a/src/test/compile-fail/mir-unpretty.rs b/src/test/compile-fail/mir-unpretty.rs index 8950bef6a46..fa936502157 100644 --- a/src/test/compile-fail/mir-unpretty.rs +++ b/src/test/compile-fail/mir-unpretty.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -Z unstable-options --unpretty=mir +// compile-flags: -Z unpretty=mir fn main() { let x: () = 0; //~ ERROR: mismatched types diff --git a/src/test/run-make/hir-tree/Makefile b/src/test/run-make/hir-tree/Makefile index bedb2b7d6aa..2e100b269e1 100644 --- a/src/test/run-make/hir-tree/Makefile +++ b/src/test/run-make/hir-tree/Makefile @@ -4,6 +4,5 @@ # the string constant we would expect to see. all: - $(RUSTC) -o $(TMPDIR)/input.hir -Z unstable-options \ - --unpretty=hir-tree input.rs + $(RUSTC) -o $(TMPDIR)/input.hir -Z unpretty=hir-tree input.rs $(CGREP) '"Hello, Rustaceans!\n"' < $(TMPDIR)/input.hir diff --git a/src/test/run-make/pretty-print-path-suffix/Makefile b/src/test/run-make/pretty-print-path-suffix/Makefile index d5300501179..899457fc748 100644 --- a/src/test/run-make/pretty-print-path-suffix/Makefile +++ b/src/test/run-make/pretty-print-path-suffix/Makefile @@ -1,9 +1,9 @@ -include ../tools.mk all: - $(RUSTC) -o $(TMPDIR)/foo.out -Z unstable-options --unpretty hir=foo input.rs - $(RUSTC) -o $(TMPDIR)/nest_foo.out -Z unstable-options --unpretty hir=nest::foo input.rs - $(RUSTC) -o $(TMPDIR)/foo_method.out -Z unstable-options --unpretty hir=foo_method input.rs + $(RUSTC) -o $(TMPDIR)/foo.out -Z unpretty=hir=foo input.rs + $(RUSTC) -o $(TMPDIR)/nest_foo.out -Z unpretty=hir=nest::foo input.rs + $(RUSTC) -o $(TMPDIR)/foo_method.out -Z unpretty=hir=foo_method input.rs diff -u $(TMPDIR)/foo.out foo.pp diff -u $(TMPDIR)/nest_foo.out nest_foo.pp diff -u $(TMPDIR)/foo_method.out foo_method.pp diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index efbe5e32fcd..bf5fc00428d 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -466,8 +466,7 @@ impl<'test> TestCx<'test> { let mut rustc = Command::new(&self.config.rustc_path); rustc .arg("-") - .arg("-Zunstable-options") - .args(&["--unpretty", &pretty_type]) + .args(&["-Z", &format!("unpretty={}", pretty_type)]) .args(&["--target", &self.config.target]) .arg("-L") .arg(&aux_dir) From db41f1e1cfa0d817a96830fecbdcf70d249597e7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 18 Jan 2018 19:44:41 -0300 Subject: [PATCH 07/19] Add rustc-args option to test runner --- src/bootstrap/check.rs | 1 + src/bootstrap/flags.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index ed110762cb3..a8a1f871cf5 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -750,6 +750,7 @@ impl Step for Compiletest { flags.push("-g".to_string()); } flags.push("-Zmiri -Zunstable-options".to_string()); + flags.push(build.config.cmd.rustc_args().join(" ")); if let Some(linker) = build.linker(target) { cmd.arg("--linker").arg(linker); diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index b5d51598fab..0816c4dfe3d 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -54,6 +54,7 @@ pub enum Subcommand { Test { paths: Vec, test_args: Vec, + rustc_args: Vec, fail_fast: bool, }, Bench { @@ -150,6 +151,12 @@ To learn more about a subcommand, run `./x.py -h`"); "test" => { opts.optflag("", "no-fail-fast", "Run all tests regardless of failure"); opts.optmulti("", "test-args", "extra arguments", "ARGS"); + opts.optmulti( + "", + "rustc-args", + "extra options to pass the compiler when running tests", + "ARGS", + ); }, "bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); }, "clean" => { opts.optflag("", "all", "clean all build artifacts"); }, @@ -283,6 +290,7 @@ Arguments: Subcommand::Test { paths, test_args: matches.opt_strs("test-args"), + rustc_args: matches.opt_strs("rustc-args"), fail_fast: !matches.opt_present("no-fail-fast"), } } @@ -362,6 +370,15 @@ impl Subcommand { } } + pub fn rustc_args(&self) -> Vec<&str> { + match *self { + Subcommand::Test { ref rustc_args, .. } => { + rustc_args.iter().flat_map(|s| s.split_whitespace()).collect() + } + _ => Vec::new(), + } + } + pub fn fail_fast(&self) -> bool { match *self { Subcommand::Test { fail_fast, .. } => fail_fast, From 101f1e1193624c8a6dc050d294e7ccbd49609bb0 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 18 Jan 2018 21:24:35 +0530 Subject: [PATCH 08/19] Add regression test for #29723 fixes #29723 --- src/test/ui/issue-29723.rs | 25 +++++++++++++++++++++++++ src/test/ui/issue-29723.stderr | 13 +++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/test/ui/issue-29723.rs create mode 100644 src/test/ui/issue-29723.stderr diff --git a/src/test/ui/issue-29723.rs b/src/test/ui/issue-29723.rs new file mode 100644 index 00000000000..9f36486e813 --- /dev/null +++ b/src/test/ui/issue-29723.rs @@ -0,0 +1,25 @@ +// 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(nll)] + +// test for https://github.com/rust-lang/rust/issues/29723 + +fn foo() { + let s = String::new(); + let _s = match 0 { + 0 if { drop(s); false } => String::from("oops"), + _ => { + // This should trigger an error, + // s could have been moved from. + s + } + }; +} diff --git a/src/test/ui/issue-29723.stderr b/src/test/ui/issue-29723.stderr new file mode 100644 index 00000000000..061c3d49323 --- /dev/null +++ b/src/test/ui/issue-29723.stderr @@ -0,0 +1,13 @@ +error[E0382]: use of moved value: `s` + --> $DIR/issue-29723.rs:22:13 + | +18 | 0 if { drop(s); false } => String::from("oops"), + | - value moved here +... +22 | s + | ^ value used here after move + | + = note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + +error: aborting due to previous error + From 297595532cbbd79dbb6a90dc400da8e5e0911395 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 19 Jan 2018 08:24:06 -0500 Subject: [PATCH 09/19] s/foo/main/ --- src/test/ui/issue-29723.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/issue-29723.rs b/src/test/ui/issue-29723.rs index 9f36486e813..248e44dcc02 100644 --- a/src/test/ui/issue-29723.rs +++ b/src/test/ui/issue-29723.rs @@ -12,7 +12,7 @@ // test for https://github.com/rust-lang/rust/issues/29723 -fn foo() { +fn main() { let s = String::new(); let _s = match 0 { 0 if { drop(s); false } => String::from("oops"), From 9d629c641e3656ee7f84c570703c5e427a166cd0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 19 Jan 2018 16:45:54 -0500 Subject: [PATCH 10/19] add ERROR annotation --- src/test/ui/issue-29723.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/issue-29723.rs b/src/test/ui/issue-29723.rs index 248e44dcc02..54785accdb7 100644 --- a/src/test/ui/issue-29723.rs +++ b/src/test/ui/issue-29723.rs @@ -20,6 +20,7 @@ fn main() { // This should trigger an error, // s could have been moved from. s + //~ ERROR use of moved value: `s` } }; } From 67f922bfcceb4219c4c65e1dfaaca9368337f46a Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 19 Jan 2018 16:46:07 -0500 Subject: [PATCH 11/19] fix line --- src/test/ui/issue-29723.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/issue-29723.rs b/src/test/ui/issue-29723.rs index 54785accdb7..f31e965ae01 100644 --- a/src/test/ui/issue-29723.rs +++ b/src/test/ui/issue-29723.rs @@ -20,7 +20,7 @@ fn main() { // This should trigger an error, // s could have been moved from. s - //~ ERROR use of moved value: `s` + //~^ ERROR use of moved value: `s` } }; } From e2f6b280ea13e48bff86254549988e61eee37139 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 19 Jan 2018 21:43:53 -0800 Subject: [PATCH 12/19] Update DW_OP_plus to DW_OP_plus_uconst LLVM <= 4.0 used a non-standard interpretation of `DW_OP_plus`. In the DWARF standard, this adds two items on the expressions stack. LLVM's behavior was more like DWARF's `DW_OP_plus_uconst` -- adding a constant that follows the op. The patch series starting with [D33892] switched to the standard DWARF interpretation, so we need to follow. [D33892]: https://reviews.llvm.org/D33892 --- src/librustc_llvm/ffi.rs | 2 +- src/librustc_trans/mir/mod.rs | 2 +- src/rustllvm/RustWrapper.cpp | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index b97e37f4c8f..f51e51a88b1 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -1546,7 +1546,7 @@ extern "C" { InlinedAt: MetadataRef) -> ValueRef; pub fn LLVMRustDIBuilderCreateOpDeref() -> i64; - pub fn LLVMRustDIBuilderCreateOpPlus() -> i64; + pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64; pub fn LLVMRustWriteTypeToString(Type: TypeRef, s: RustStringRef); pub fn LLVMRustWriteValueToString(value_ref: ValueRef, s: RustStringRef); diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index 3064e2f7c7a..b367eb6548d 100644 --- a/src/librustc_trans/mir/mod.rs +++ b/src/librustc_trans/mir/mod.rs @@ -547,7 +547,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let ops = unsafe { [llvm::LLVMRustDIBuilderCreateOpDeref(), - llvm::LLVMRustDIBuilderCreateOpPlus(), + llvm::LLVMRustDIBuilderCreateOpPlusUconst(), byte_offset_of_var_in_env as i64, llvm::LLVMRustDIBuilderCreateOpDeref()] }; diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 95130d596e1..0fe533d447b 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -866,7 +866,14 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() { return dwarf::DW_OP_deref; } -extern "C" int64_t LLVMRustDIBuilderCreateOpPlus() { return dwarf::DW_OP_plus; } +extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() { +#if LLVM_VERSION_GE(5, 0) + return dwarf::DW_OP_plus_uconst; +#else + // older LLVM used `plus` to behave like `plus_uconst`. + return dwarf::DW_OP_plus; +#endif +} extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) { RawRustStringOstream OS(Str); From e47cc69697b47f69d18d3c767b136c987a943645 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sat, 20 Jan 2018 21:45:35 +0100 Subject: [PATCH 13/19] Add testing coverage for assigning to immutable thread-locals. It is currently allowed to perform such assignments when not making use of NLL. NLL already does this right, but let's add a test in place to ensure it never regresses. --- .../nll/constant-thread-locals-issue-47053.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/compile-fail/nll/constant-thread-locals-issue-47053.rs diff --git a/src/test/compile-fail/nll/constant-thread-locals-issue-47053.rs b/src/test/compile-fail/nll/constant-thread-locals-issue-47053.rs new file mode 100644 index 00000000000..c7dc84c1a91 --- /dev/null +++ b/src/test/compile-fail/nll/constant-thread-locals-issue-47053.rs @@ -0,0 +1,21 @@ +// Copyright 2018 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. + +// Regression test for issue #47053 + +#![feature(nll)] +#![feature(thread_local)] + +#[thread_local] +static FOO: isize = 5; + +fn main() { + FOO = 6; //~ ERROR cannot assign to immutable item `FOO` [E0594] +} From 643e71e2e125a1859793f729bdb2149bc0e6b23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 3 Dec 2017 14:10:04 +0100 Subject: [PATCH 14/19] Remove the IGNORED_ATTR_NAMES thread local --- src/librustc/ich/hcx.rs | 21 ++++++--------------- src/librustc/ich/mod.rs | 2 +- src/librustc/session/mod.rs | 6 ++++++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 2945b1ab912..67f6c0c2e49 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -19,8 +19,8 @@ use session::Session; use std::cmp::Ord; use std::hash as std_hash; -use std::cell::RefCell; use std::collections::HashMap; +use std::cell::RefCell; use syntax::ast; @@ -36,8 +36,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvi use rustc_data_structures::accumulate_vec::AccumulateVec; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; -thread_local!(static IGNORED_ATTR_NAMES: RefCell> = - RefCell::new(FxHashSet())); +pub fn compute_ignored_attr_names() -> FxHashSet { + debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0); + ich::IGNORED_ATTRIBUTES.iter().map(|&s| Symbol::intern(s)).collect() +} /// This is the context state available during incr. comp. hashing. It contains /// enough information to transform DefIds and HirIds into stable DefPaths (i.e. @@ -90,15 +92,6 @@ impl<'gcx> StableHashingContext<'gcx> { -> Self { let hash_spans_initial = !sess.opts.debugging_opts.incremental_ignore_spans; - debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0); - IGNORED_ATTR_NAMES.with(|names| { - let mut names = names.borrow_mut(); - if names.is_empty() { - names.extend(ich::IGNORED_ATTRIBUTES.iter() - .map(|&s| Symbol::intern(s))); - } - }); - StableHashingContext { sess, body_resolver: BodyResolver(krate), @@ -186,9 +179,7 @@ impl<'gcx> StableHashingContext<'gcx> { #[inline] pub fn is_ignored_attr(&self, name: Symbol) -> bool { - IGNORED_ATTR_NAMES.with(|names| { - names.borrow().contains(&name) - }) + self.sess.ignored_attr_names.contains(&name) } pub fn hash_hir_item_like(&mut self, f: F) { diff --git a/src/librustc/ich/mod.rs b/src/librustc/ich/mod.rs index cbd76ee14db..ce1bd07b14c 100644 --- a/src/librustc/ich/mod.rs +++ b/src/librustc/ich/mod.rs @@ -13,7 +13,7 @@ pub use self::fingerprint::Fingerprint; pub use self::caching_codemap_view::CachingCodemapView; pub use self::hcx::{StableHashingContext, NodeIdHashingMode, - hash_stable_trait_impls}; + hash_stable_trait_impls, compute_ignored_attr_names}; mod fingerprint; mod caching_codemap_view; mod hcx; diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 94fcfb7e2aa..36f716a4a76 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -14,6 +14,7 @@ pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo}; use hir::def_id::CrateNum; use ich::Fingerprint; +use ich; use lint; use middle::allocator::AllocatorKind; use middle::dependency_format; @@ -28,6 +29,7 @@ use errors::{self, DiagnosticBuilder, DiagnosticId}; use errors::emitter::{Emitter, EmitterWriter}; use syntax::json::JsonEmitter; use syntax::feature_gate; +use syntax::symbol::Symbol; use syntax::parse; use syntax::parse::ParseSess; use syntax::{ast, codemap}; @@ -112,6 +114,9 @@ pub struct Session { incr_comp_session: RefCell, + /// A cache of attributes ignored by StableHashingContext + pub ignored_attr_names: FxHashSet, + /// Some measurements that are being gathered during compilation. pub perf_stats: PerfStats, @@ -975,6 +980,7 @@ pub fn build_session_(sopts: config::Options, injected_panic_runtime: Cell::new(None), imported_macro_spans: RefCell::new(HashMap::new()), incr_comp_session: RefCell::new(IncrCompSession::NotInitialized), + ignored_attr_names: ich::compute_ignored_attr_names(), perf_stats: PerfStats { svh_time: Cell::new(Duration::from_secs(0)), incr_comp_hashes_time: Cell::new(Duration::from_secs(0)), From e1bffbdf66cecc442e8d9e20642df82a155e2aa0 Mon Sep 17 00:00:00 2001 From: Ryan Cumming Date: Mon, 22 Jan 2018 20:58:21 +1100 Subject: [PATCH 15/19] Fix spurious warning on empty proc macro crates While attempting to reproduce rust-lang/rust#47086 I noticed the following warning: ```shell > rustc /dev/null --crate-type proc-macro warning: unused variable: `registrar` --> /dev/null:0:1 ``` As there are no macros to register the automatically generated registrar function for the crate has no body. As a result its `registrar` argument is unused triggering the above warning. The warning is confusing and not easily actionable by the developer. It could also be triggered legitimately by e.g. having all of the macros in a crate #[cfg]'ed out. Fix by naming the generated argument `_registrar` inside `mk_registrar()`. This suppresses the unused variable warning. --- src/libsyntax_ext/proc_macro_registrar.rs | 2 +- .../proc-macro/auxiliary/empty-crate.rs | 14 ++++++++++++++ .../run-pass-fulldeps/proc-macro/empty-crate.rs | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass-fulldeps/proc-macro/auxiliary/empty-crate.rs create mode 100644 src/test/run-pass-fulldeps/proc-macro/empty-crate.rs diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs index 8c5276e1d74..0ba21e6b366 100644 --- a/src/libsyntax_ext/proc_macro_registrar.rs +++ b/src/libsyntax_ext/proc_macro_registrar.rs @@ -381,7 +381,7 @@ fn mk_registrar(cx: &mut ExtCtxt, let __internal = Ident::from_str("__internal"); let registry = Ident::from_str("Registry"); - let registrar = Ident::from_str("registrar"); + let registrar = Ident::from_str("_registrar"); let register_custom_derive = Ident::from_str("register_custom_derive"); let register_attr_proc_macro = Ident::from_str("register_attr_proc_macro"); let register_bang_proc_macro = Ident::from_str("register_bang_proc_macro"); diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/empty-crate.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/empty-crate.rs new file mode 100644 index 00000000000..b45d4bf41d6 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/empty-crate.rs @@ -0,0 +1,14 @@ +// Copyright 2018 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. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] +#![deny(unused_variables)] diff --git a/src/test/run-pass-fulldeps/proc-macro/empty-crate.rs b/src/test/run-pass-fulldeps/proc-macro/empty-crate.rs new file mode 100644 index 00000000000..38a2716aee7 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/empty-crate.rs @@ -0,0 +1,17 @@ +// Copyright 2018 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. + +// aux-build:empty-crate.rs +// ignore-stage1 + +#[macro_use] +extern crate empty_crate; + +fn main() {} From c3fabceab15442b2d4a13774cb07019bc7ec5bc5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 22 Jan 2018 18:18:40 +0100 Subject: [PATCH 16/19] Inline some rustc_driver function --- src/librustc_driver/driver.rs | 30 +++++++++--------------------- src/librustc_driver/lib.rs | 31 +++++++++++++------------------ 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 468a08b1fd9..f19ffc0e12a 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -51,14 +51,12 @@ use std::iter; use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::mpsc; -use syntax::{ast, diagnostics, visit}; -use syntax::attr; +use syntax::{self, ast, attr, diagnostics, visit}; use syntax::ext::base::ExtCtxt; use syntax::fold::Folder; use syntax::parse::{self, PResult}; use syntax::util::node_count::NodeCounter; use syntax_pos::FileName; -use syntax; use syntax_ext; use derive_registrar; @@ -274,10 +272,6 @@ pub fn compile_input(trans: Box, Ok(()) } -fn keep_hygiene_data(sess: &Session) -> bool { - sess.opts.debugging_opts.keep_hygiene_data -} - pub fn source_name(input: &Input) -> FileName { match *input { Input::File(ref ifile) => ifile.clone().into(), @@ -851,7 +845,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, || lint::check_ast_crate(sess, &krate)); // Discard hygiene data, which isn't required after lowering to HIR. - if !keep_hygiene_data(sess) { + if !sess.opts.debugging_opts.keep_hygiene_data { syntax::ext::hygiene::clear_markings(); } @@ -915,18 +909,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate, mpsc::Receiver>, CompileResult) -> R { - macro_rules! try_with_f { - ($e: expr, ($($t:tt)*)) => { - match $e { - Ok(x) => x, - Err(x) => { - f($($t)*, Err(x)); - return Err(x); - } - } - } - } - let time_passes = sess.time_passes(); let query_result_on_disk_cache = time(time_passes, @@ -987,7 +969,13 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate, || stability::check_unstable_api_usage(tcx)); // passes are timed inside typeck - try_with_f!(typeck::check_crate(tcx), (tcx, analysis, rx)); + match typeck::check_crate(tcx) { + Ok(x) => x, + Err(x) => { + f(tcx, analysis, rx, Err(x)); + return Err(x); + } + } time(time_passes, "const checking", diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index de5559c8b14..c05004d1c15 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -669,7 +669,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { control.after_hir_lowering.stop = Compilation::Stop; } - if save_analysis(sess) { + if sess.opts.debugging_opts.save_analysis { enable_save_analysis(&mut control); } @@ -704,10 +704,6 @@ pub fn enable_save_analysis(control: &mut CompileController) { control.make_glob_map = resolve::MakeGlobMap::Yes; } -fn save_analysis(sess: &Session) -> bool { - sess.opts.debugging_opts.save_analysis -} - impl RustcDefaultCalls { pub fn list_metadata(sess: &Session, cstore: &CrateStore, @@ -1329,20 +1325,19 @@ pub fn diagnostics_registry() -> errors::registry::Registry { Registry::new(&all_errors) } -pub fn get_args() -> Vec { - env::args_os().enumerate() - .map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| { - early_error(ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg)) - })) - .collect() -} - pub fn main() { env_logger::init().unwrap(); - let result = run(|| run_compiler(&get_args(), - &mut RustcDefaultCalls, - None, - None)); + let result = run(|| { + let args = env::args_os().enumerate() + .map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| { + early_error(ErrorOutputType::default(), + &format!("Argument {} is not valid Unicode: {:?}", i, arg)) + })) + .collect::>(); + run_compiler(&args, + &mut RustcDefaultCalls, + None, + None) + }); process::exit(result as i32); } From 90aef18cb0488c2595177520f95824bcd99edf2c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 22 Jan 2018 15:08:57 -0300 Subject: [PATCH 17/19] Add dynamic-drop test to nll tests also --- src/test/run-pass/dynamic-drop.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/run-pass/dynamic-drop.rs b/src/test/run-pass/dynamic-drop.rs index 09318e7256f..e2a51bbf14b 100644 --- a/src/test/run-pass/dynamic-drop.rs +++ b/src/test/run-pass/dynamic-drop.rs @@ -8,6 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// revisions:lexical nll +#![cfg_attr(nll, feature(nll))] + // ignore-wasm32-bare compiled with panic=abort by default #![feature(generators, generator_trait, untagged_unions, slice_patterns, advanced_slice_patterns)] From 7cc3cb29bdbf1c22e2bb5be6ae3798029de3d4d8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 22 Jan 2018 22:49:44 +0100 Subject: [PATCH 18/19] Fix quoted search --- src/librustdoc/html/static/main.js | 4 ++-- src/test/rustdoc-js/quoted.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc-js/quoted.js diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index a9a5bd5de05..fa911f68139 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -600,7 +600,7 @@ var lev_distance = MAX_LEV_DISTANCE + 1; if (obj.name === val.name) { if (literalSearch === true) { - if (val.generics.length !== 0) { + if (val.generics && val.generics.length !== 0) { if (obj.generics && obj.length >= val.generics.length) { var elems = obj.generics.slice(0); var allFound = true; @@ -637,7 +637,7 @@ } // Names didn't match so let's check if one of the generic types could. if (literalSearch === true) { - if (obj.generics.length > 0) { + if (obj.generics && obj.generics.length > 0) { for (var x = 0; x < obj.generics.length; ++x) { if (obj.generics[x] === val.name) { return true; diff --git a/src/test/rustdoc-js/quoted.js b/src/test/rustdoc-js/quoted.js new file mode 100644 index 00000000000..dcb85b5de04 --- /dev/null +++ b/src/test/rustdoc-js/quoted.js @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +const QUERY = '"error"'; + +const EXPECTED = { + 'others': [ + { 'path': 'std', 'name': 'error' }, + { 'path': 'std::fmt', 'name': 'Error' }, + { 'path': 'std::io', 'name': 'Error' }, + ], + 'in_args': [], + 'returned': [ + { 'path': 'std::fmt::LowerExp', 'name': 'fmt' }, + ], +}; From 04a884726a5a332aefd0af96c8d702b0830e5375 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Tue, 23 Jan 2018 01:04:24 +0000 Subject: [PATCH 19/19] rustdoc: Show when traits are auto traits --- src/librustdoc/clean/inline.rs | 2 ++ src/librustdoc/clean/mod.rs | 11 +++++++++++ src/librustdoc/doctree.rs | 1 + src/librustdoc/html/render.rs | 3 ++- src/librustdoc/visit_ast.rs | 3 ++- src/test/rustdoc/auto-traits.rs | 23 +++++++++++++++++++++++ src/test/rustdoc/auxiliary/auto-traits.rs | 13 +++++++++++++ 7 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc/auto-traits.rs create mode 100644 src/test/rustdoc/auxiliary/auto-traits.rs diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index b8c34d78d30..3cdc558080a 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -146,12 +146,14 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait { let generics = filter_non_trait_generics(did, generics); let (generics, supertrait_bounds) = separate_supertrait_bounds(generics); let is_spotlight = load_attrs(cx, did).has_doc_flag("spotlight"); + let is_auto = cx.tcx.trait_is_auto(did); clean::Trait { unsafety: cx.tcx.trait_def(did).unsafety, generics, items: trait_items, bounds: supertrait_bounds, is_spotlight, + is_auto, } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cc75664cacb..c43aec79447 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1523,6 +1523,7 @@ pub struct Trait { pub generics: Generics, pub bounds: Vec, pub is_spotlight: bool, + pub is_auto: bool, } impl Clean for doctree::Trait { @@ -1543,11 +1544,21 @@ impl Clean for doctree::Trait { generics: self.generics.clean(cx), bounds: self.bounds.clean(cx), is_spotlight: is_spotlight, + is_auto: self.is_auto.clean(cx), }), } } } +impl Clean for hir::IsAuto { + fn clean(&self, _: &DocContext) -> bool { + match *self { + hir::IsAuto::Yes => true, + hir::IsAuto::No => false, + } + } +} + impl Clean for hir::TraitRef { fn clean(&self, cx: &DocContext) -> Type { resolve_type(cx, self.path.clean(cx), self.ref_id) diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 776ec7f409c..430236f30c4 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -196,6 +196,7 @@ pub struct Constant { } pub struct Trait { + pub is_auto: hir::IsAuto, pub unsafety: hir::Unsafety, pub name: Name, pub items: hir::HirVec, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index cfa09ea30a8..fae6f9ec6a3 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2339,9 +2339,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, // Output the trait definition write!(w, "
")?;
     render_attributes(w, it)?;
-    write!(w, "{}{}trait {}{}{}",
+    write!(w, "{}{}{}trait {}{}{}",
            VisSpace(&it.visibility),
            UnsafetySpace(t.unsafety),
+           if t.is_auto { "auto " } else { "" },
            it.name.as_ref().unwrap(),
            t.generics,
            bounds)?;
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index 1cb52d735bb..ed69bce11a0 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -494,11 +494,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                 };
                 om.constants.push(s);
             },
-            hir::ItemTrait(_, unsafety, ref gen, ref b, ref item_ids) => {
+            hir::ItemTrait(is_auto, unsafety, ref gen, ref b, ref item_ids) => {
                 let items = item_ids.iter()
                                     .map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
                                     .collect();
                 let t = Trait {
+                    is_auto,
                     unsafety,
                     name,
                     items,
diff --git a/src/test/rustdoc/auto-traits.rs b/src/test/rustdoc/auto-traits.rs
new file mode 100644
index 00000000000..1753c0ebf73
--- /dev/null
+++ b/src/test/rustdoc/auto-traits.rs
@@ -0,0 +1,23 @@
+// Copyright 2018 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.
+
+// aux-build:auto-traits.rs
+
+#![feature(optin_builtin_traits)]
+
+#![crate_name = "foo"]
+
+extern crate auto_traits;
+
+// @has 'foo/trait.Foo.html' '//pre' 'pub unsafe auto trait Foo'
+pub unsafe auto trait Foo {}
+
+// @has 'foo/trait.Bar.html' '//pre' 'pub unsafe auto trait Bar'
+pub use auto_traits::Bar;
diff --git a/src/test/rustdoc/auxiliary/auto-traits.rs b/src/test/rustdoc/auxiliary/auto-traits.rs
new file mode 100644
index 00000000000..70299334b46
--- /dev/null
+++ b/src/test/rustdoc/auxiliary/auto-traits.rs
@@ -0,0 +1,13 @@
+// Copyright 2018 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(optin_builtin_traits)]
+
+pub unsafe auto trait Bar {}