From 4aba7de2a77a95e2032eaf438e2e11b8e1a5eb82 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 29 Jul 2018 15:39:51 +0200 Subject: [PATCH 1/7] Clean generic impls code --- src/Cargo.lock | 163 ++++---------- src/librustdoc/clean/auto_trait.rs | 314 ++------------------------- src/librustdoc/clean/blanket_impl.rs | 170 +++++++++++++++ src/librustdoc/clean/def_ctor.rs | 65 ++++++ src/librustdoc/clean/finder_trait.rs | 154 +++++++++++++ src/librustdoc/clean/inline.rs | 26 ++- src/librustdoc/clean/mod.rs | 49 +++-- src/librustdoc/clean/simplify.rs | 2 +- 8 files changed, 508 insertions(+), 435 deletions(-) create mode 100644 src/librustdoc/clean/blanket_impl.rs create mode 100644 src/librustdoc/clean/def_ctor.rs create mode 100644 src/librustdoc/clean/finder_trait.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index 5f0d96c9c052c..61fd5eefa8cb1 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -226,7 +226,7 @@ dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "crates-io 0.18.0", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -247,8 +247,8 @@ dependencies = [ "libgit2-sys 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-workspace-hack 1.0.0", "rustfix 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -351,18 +351,20 @@ name = "clippy" version = "0.0.212" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", "clippy-mini-macro-test 0.2.0", "clippy_lints 0.0.212", "compiletest_rs 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-workspace-hack 1.0.0", "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -604,11 +606,6 @@ name = "crossbeam-utils" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "crossbeam-utils" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "crypto-hash" version = "0.3.1" @@ -1794,8 +1791,7 @@ dependencies = [ "rls-rustc 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-workspace-hack 1.0.0", - "rustfmt-nightly 0.9.0", + "rustfmt-nightly 0.9.0 (git+https://github.com/rust-lang-nursery/rustfmt?rev=7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1853,6 +1849,7 @@ name = "rls-vfs" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "racer 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1903,14 +1900,6 @@ dependencies = [ "rustc-ap-rustc_data_structures 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-arena" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-ap-rustc_cratesio_shim" version = "209.0.0" @@ -1920,15 +1909,6 @@ dependencies = [ "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-rustc_cratesio_shim" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-ap-rustc_data_structures" version = "209.0.0" @@ -1947,24 +1927,6 @@ dependencies = [ "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-rustc_data_structures" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-ap-rustc_errors" version = "209.0.0" @@ -1978,19 +1940,6 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-rustc_errors" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-ap-rustc_target" version = "209.0.0" @@ -2002,27 +1951,11 @@ dependencies = [ "rustc-ap-serialize 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-rustc_target" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-ap-serialize" version = "209.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc-ap-serialize" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "rustc-ap-syntax" version = "209.0.0" @@ -2038,21 +1971,6 @@ dependencies = [ "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-syntax" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_errors 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-ap-syntax_pos" version = "209.0.0" @@ -2066,19 +1984,6 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-ap-syntax_pos" -version = "211.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-arena 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-demangle" version = "0.1.8" @@ -2126,14 +2031,6 @@ name = "rustc-serialize" version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc-workspace-hack" -version = "1.0.0" -dependencies = [ - "syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc_allocator" version = "0.0.0" @@ -2564,6 +2461,32 @@ dependencies = [ "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustfmt-nightly" +version = "0.9.0" +source = "git+https://github.com/rust-lang-nursery/rustfmt?rev=7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b#7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b" +dependencies = [ + "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", + "isatty 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustfmt-nightly" version = "0.9.0" @@ -2580,9 +2503,9 @@ dependencies = [ "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3197,6 +3120,10 @@ name = "yaml-rust" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[patch.unused]] +name = "rustc-workspace-hack" +version = "1.0.0" + [metadata] "checksum aho-corasick 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c6d463cbe7ed28720b5b489e7c083eeb8f90d08be2a0d6bb9e1ffea9ce1afa" "checksum ammonia 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd4c682378117e4186a492b2252b9537990e1617f44aed9788b9a1149de45477" @@ -3237,7 +3164,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "285987a59c4d91388e749850e3cb7b3a92299668528caaacd08005b8f238c0ea" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ea52fab26a99d96cdff39d0ca75c9716125937f5dba2ab83923aaaf5928f684a" -"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" "checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4" "checksum curl 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "893713db705eab9847e050268507b0e2a2aad64e90a831874bd4e8e0d67f9523" "checksum curl-sys 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "de9cf174efdf90b5887c4e2e900769373c89c5e18152e8f3ed75b501a6f1c0fb" @@ -3367,21 +3293,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a" "checksum rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ecbc8541b4c341d6271eae10f869dd9d36db871afe184f5b6f9bffbd6ed0373f" "checksum rustc-ap-arena 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b098827864368459cbc7a79fbc54eafb92df7e00a46c0cda352b5a21583ee436" -"checksum rustc-ap-arena 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eec75ed880706dd9a05bc770c327ed142fa7d4b648d9757fbc71d821d68448a5" "checksum rustc-ap-rustc_cratesio_shim 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef4d923dea14fb085bca743fb982f6a3bc11c0d5d30b822bcf6fa16e9464a56c" -"checksum rustc-ap-rustc_cratesio_shim 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f5d54615bedbae65a976e0835edf0de90dd962ec818c0149fe181d5cd81da9e" "checksum rustc-ap-rustc_data_structures 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18c6a5c9edc6b4ae035cdc03af7d8662d39fad7879c5501d103e7087dfaebc80" -"checksum rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c51cc6e79eab25c7ea84a7e104e81e6f44cca32709df54c2cdb4e7059d7843" "checksum rustc-ap-rustc_errors 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9a1e9bdc597abd95cebce0c14c1da58943a9e5b8255530a0fec30659d144eb0b" -"checksum rustc-ap-rustc_errors 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff050095b7afb254506591ee7d3a5d0fb9c03c16f8c2741b588178085e563d49" "checksum rustc-ap-rustc_target 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "142ddef3dc12dda2bcd3412f0d96d3745413a8fbc2f224f0cc97afa04c071d89" -"checksum rustc-ap-rustc_target 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53c7a8c21c3b05f24998fa6ab9ded6269810a2f3ae12ff301c432c1e9fa8e111" "checksum rustc-ap-serialize 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b08f8f175b038a82caa7e51fc52b72ff96cfe8c1429755da30380dbd4199c7f" -"checksum rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4713c2c0c26a45ead8fb16fee88e16fecf999588ae6920847cbaeb19565b7f" "checksum rustc-ap-syntax 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4c802e0e1fbc64eddc21e0798527eb1f5fdbd5781d119bd2c44b6130afdc81cc" -"checksum rustc-ap-syntax 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "768e2698f912913be2ccd355b2dea62c978efc356f75db1400605f3642905d53" "checksum rustc-ap-syntax_pos 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "008d47cc54ed12a2784217b9e6630a7fa1c8dc3591a283f65ad4b7fa307d49d5" -"checksum rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a280dc8919aa7f684832ba3eeab2f6c96dbe2e2e4f6a922f7f0bdb3a9dd9e641" "checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c6d5a683c6ba4ed37959097e88d71c9e8e26659a3cb5be8b389078e7ad45306" @@ -3389,6 +3307,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a54aa04a10c68c1c4eacb4337fd883b435997ede17a9385784b990777686b09a" "checksum rustfix 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "756567f00f7d89c9f89a5c401b8b1caaa122e27240b9eaadd0bb52ee0b680b1b" +"checksum rustfmt-nightly 0.9.0 (git+https://github.com/rust-lang-nursery/rustfmt?rev=7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b)" = "" "checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637" "checksum schannel 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "dc1fabf2a7b6483a141426e1afd09ad543520a77ac49bd03c286e7696ccfd77f" "checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 23056218269b6..67f3d6217b60c 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -15,9 +15,9 @@ use rustc::ty::subst::Subst; use rustc::infer::InferOk; use rustc::middle::cstore::CrateStore; use std::fmt::Debug; -use syntax_pos::DUMMY_SP; -use core::DocAccessLevels; +use self::def_ctor::{get_def_ctor_from_def_id, get_def_ctor_from_node_id}; +use self::finder_trait::Finder; use super::*; @@ -34,186 +34,16 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { } pub fn get_with_def_id(&self, def_id: DefId) -> Vec { - let ty = self.cx.tcx.type_of(def_id); - - let def_ctor: fn(DefId) -> Def = match ty.sty { - ty::TyAdt(adt, _) => match adt.adt_kind() { - AdtKind::Struct => Def::Struct, - AdtKind::Enum => Def::Enum, - AdtKind::Union => Def::Union, - } - ty::TyInt(_) | - ty::TyUint(_) | - ty::TyFloat(_) | - ty::TyStr | - ty::TyBool | - ty::TyChar => return self.get_auto_trait_impls(def_id, &move |_: DefId| { - match ty.sty { - ty::TyInt(x) => Def::PrimTy(hir::TyInt(x)), - ty::TyUint(x) => Def::PrimTy(hir::TyUint(x)), - ty::TyFloat(x) => Def::PrimTy(hir::TyFloat(x)), - ty::TyStr => Def::PrimTy(hir::TyStr), - ty::TyBool => Def::PrimTy(hir::TyBool), - ty::TyChar => Def::PrimTy(hir::TyChar), - _ => unreachable!(), - } - }, None), - _ => { - debug!("Unexpected type {:?}", def_id); - return Vec::new() - } - }; - - self.get_auto_trait_impls(def_id, &def_ctor, None) + get_def_ctor_from_def_id(&self.cx, def_id, &|def_ctor| { + self.get_auto_trait_impls(def_id, &def_ctor, None) + }) } pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { - let item = &self.cx.tcx.hir.expect_item(id).node; - let did = self.cx.tcx.hir.local_def_id(id); - - let def_ctor = match *item { - hir::ItemKind::Struct(_, _) => Def::Struct, - hir::ItemKind::Union(_, _) => Def::Union, - hir::ItemKind::Enum(_, _) => Def::Enum, - _ => panic!("Unexpected type {:?} {:?}", item, id), - }; - - self.get_auto_trait_impls(did, &def_ctor, Some(name)) - } - - fn get_real_ty(&self, - def_id: DefId, - def_ctor: &F, - real_name: &Option, - generics: &ty::Generics, - ) -> hir::Ty - where F: Fn(DefId) -> Def { - let path = get_path_for_type(self.cx.tcx, def_id, def_ctor); - let mut segments = path.segments.into_vec(); - let last = segments.pop().unwrap(); - - segments.push(hir::PathSegment::new( - real_name.unwrap_or(last.ident), - self.generics_to_path_params(generics.clone()), - false, - )); - - let new_path = hir::Path { - span: path.span, - def: path.def, - segments: HirVec::from_vec(segments), - }; - - hir::Ty { - id: ast::DUMMY_NODE_ID, - node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), - span: DUMMY_SP, - hir_id: hir::DUMMY_HIR_ID, - } - } - - pub fn get_blanket_impls( - &self, - def_id: DefId, - def_ctor: &F, - name: Option, - generics: &ty::Generics, - ) -> Vec - where F: Fn(DefId) -> Def { - let ty = self.cx.tcx.type_of(def_id); - let mut traits = Vec::new(); - if self.cx.access_levels.borrow().is_doc_reachable(def_id) { - let real_name = name.clone().map(|name| Ident::from_str(&name)); - let param_env = self.cx.tcx.param_env(def_id); - for &trait_def_id in self.cx.all_traits.iter() { - if !self.cx.access_levels.borrow().is_doc_reachable(trait_def_id) || - self.cx.generated_synthetics - .borrow_mut() - .get(&(def_id, trait_def_id)) - .is_some() { - continue - } - self.cx.tcx.for_each_relevant_impl(trait_def_id, ty, |impl_def_id| { - self.cx.tcx.infer_ctxt().enter(|infcx| { - let t_generics = infcx.tcx.generics_of(impl_def_id); - let trait_ref = infcx.tcx.impl_trait_ref(impl_def_id).unwrap(); - - match infcx.tcx.type_of(impl_def_id).sty { - ::rustc::ty::TypeVariants::TyParam(_) => {}, - _ => return, - } - - let substs = infcx.fresh_substs_for_item(DUMMY_SP, def_id); - let ty = ty.subst(infcx.tcx, substs); - let param_env = param_env.subst(infcx.tcx, substs); - - let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); - let trait_ref = trait_ref.subst(infcx.tcx, impl_substs); - - // Require the type the impl is implemented on to match - // our type, and ignore the impl if there was a mismatch. - let cause = traits::ObligationCause::dummy(); - let eq_result = infcx.at(&cause, param_env) - .eq(trait_ref.self_ty(), ty); - if let Ok(InferOk { value: (), obligations }) = eq_result { - // FIXME(eddyb) ignoring `obligations` might cause false positives. - drop(obligations); - - let may_apply = infcx.predicate_may_hold(&traits::Obligation::new( - cause.clone(), - param_env, - trait_ref.to_predicate(), - )); - if !may_apply { - return - } - self.cx.generated_synthetics.borrow_mut() - .insert((def_id, trait_def_id)); - let trait_ = hir::TraitRef { - path: get_path_for_type(infcx.tcx, - trait_def_id, - hir::def::Def::Trait), - ref_id: ast::DUMMY_NODE_ID, - }; - let provided_trait_methods = - infcx.tcx.provided_trait_methods(trait_def_id) - .into_iter() - .map(|meth| meth.ident.to_string()) - .collect(); - - let ty = self.get_real_ty(def_id, def_ctor, &real_name, generics); - let predicates = infcx.tcx.predicates_of(impl_def_id); - - traits.push(Item { - source: infcx.tcx.def_span(impl_def_id).clean(self.cx), - name: None, - attrs: Default::default(), - visibility: None, - def_id: self.next_def_id(impl_def_id.krate), - stability: None, - deprecation: None, - inner: ImplItem(Impl { - unsafety: hir::Unsafety::Normal, - generics: (t_generics, &predicates).clean(self.cx), - provided_trait_methods, - trait_: Some(trait_.clean(self.cx)), - for_: ty.clean(self.cx), - items: infcx.tcx.associated_items(impl_def_id) - .collect::>() - .clean(self.cx), - polarity: None, - synthetic: false, - blanket_impl: Some(infcx.tcx.type_of(impl_def_id) - .clean(self.cx)), - }), - }); - debug!("{:?} => {}", trait_ref, may_apply); - } - }); - }); - } - } - traits + get_def_ctor_from_node_id(&self.cx, id, name, &|def_ctor, name| { + let did = self.cx.tcx.hir.local_def_id(id); + self.get_auto_trait_impls(did, &def_ctor, Some(name)) + }) } pub fn get_auto_trait_impls( @@ -263,7 +93,6 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { def_ctor, tcx.require_lang_item(lang_items::SyncTraitLangItem), ).into_iter()) - .chain(self.get_blanket_impls(def_id, def_ctor, name, &generics).into_iter()) .collect(); debug!( @@ -365,56 +194,6 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { None } - fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs { - let mut args = vec![]; - - for param in generics.params.iter() { - match param.kind { - ty::GenericParamDefKind::Lifetime => { - let name = if param.name == "" { - hir::ParamName::Plain(keywords::StaticLifetime.ident()) - } else { - hir::ParamName::Plain(ast::Ident::from_interned_str(param.name)) - }; - - args.push(hir::GenericArg::Lifetime(hir::Lifetime { - id: ast::DUMMY_NODE_ID, - span: DUMMY_SP, - name: hir::LifetimeName::Param(name), - })); - } - ty::GenericParamDefKind::Type {..} => { - args.push(hir::GenericArg::Type(self.ty_param_to_ty(param.clone()))); - } - } - } - - hir::GenericArgs { - args: HirVec::from_vec(args), - bindings: HirVec::new(), - parenthesized: false, - } - } - - fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { - debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); - hir::Ty { - id: ast::DUMMY_NODE_ID, - node: hir::TyKind::Path(hir::QPath::Resolved( - None, - P(hir::Path { - span: DUMMY_SP, - def: Def::TyParam(param.def_id), - segments: HirVec::from_vec(vec![ - hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) - ]), - }), - )), - span: DUMMY_SP, - hir_id: hir::DUMMY_HIR_ID, - } - } - fn find_auto_trait_generics( &self, did: DefId, @@ -531,7 +310,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { // Desired order is 'larger, smaller', so flip then if self.region_name(r1) != self.region_name(r2) { finished - .entry(self.region_name(r2).unwrap()) + .entry(self.region_name(r2).expect("no region_name found")) .or_insert_with(|| Vec::new()) .push(r1); } @@ -566,7 +345,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { (&RegionTarget::Region(r1), &RegionTarget::Region(r2)) => { if self.region_name(r1) != self.region_name(r2) { finished - .entry(self.region_name(r2).unwrap()) + .entry(self.region_name(r2).expect("no region name found")) .or_insert_with(|| Vec::new()) .push(r1) // Larger, smaller } @@ -663,7 +442,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { .flat_map(|(ty, mut bounds)| { if let Some(data) = ty_to_fn.get(&ty) { let (poly_trait, output) = - (data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned()); + (data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned()); let new_ty = match &poly_trait.trait_ { &Type::ResolvedPath { ref path, @@ -672,7 +451,8 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { ref is_generic, } => { let mut new_path = path.clone(); - let last_segment = new_path.segments.pop().unwrap(); + let last_segment = new_path.segments.pop() + .expect("segments were empty"); let (old_input, old_output) = match last_segment.args { GenericArgs::AngleBracketed { types, .. } => (types, None), @@ -830,7 +610,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { let mut for_generics = self.extract_for_generics(tcx, orig_p.clone()); assert!(bounds.len() == 1); - let mut b = bounds.pop().unwrap(); + let mut b = bounds.pop().expect("bounds were empty"); if b.is_sized_bound(self.cx) { has_sized.insert(ty.clone()); @@ -860,7 +640,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { _ => false, }; - let poly_trait = b.get_poly_trait().unwrap(); + let poly_trait = b.get_poly_trait().expect("Cannot get poly trait"); if is_fn { ty_to_fn @@ -913,7 +693,10 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { // FIXME: Remove this scope when NLL lands { let args = - &mut new_trait_path.segments.last_mut().unwrap().args; + &mut new_trait_path.segments + .last_mut() + .expect("segments were empty") + .args; match args { // Convert somethiung like ' = u8' @@ -1077,60 +860,11 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { _ => false, } } +} - // This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly - // refactoring either librustdoc or librustc. In particular, allowing new DefIds to be - // registered after the AST is constructed would require storing the defid mapping in a - // RefCell, decreasing the performance for normal compilation for very little gain. - // - // Instead, we construct 'fake' def ids, which start immediately after the last DefId in - // DefIndexAddressSpace::Low. In the Debug impl for clean::Item, we explicitly check for fake - // def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds - fn next_def_id(&self, crate_num: CrateNum) -> DefId { - let start_def_id = { - let next_id = if crate_num == LOCAL_CRATE { - self.cx - .tcx - .hir - .definitions() - .def_path_table() - .next_id(DefIndexAddressSpace::Low) - } else { - self.cx - .cstore - .def_path_table(crate_num) - .next_id(DefIndexAddressSpace::Low) - }; - - DefId { - krate: crate_num, - index: next_id, - } - }; - - let mut fake_ids = self.cx.fake_def_ids.borrow_mut(); - - let def_id = fake_ids.entry(crate_num).or_insert(start_def_id).clone(); - fake_ids.insert( - crate_num, - DefId { - krate: crate_num, - index: DefIndex::from_array_index( - def_id.index.as_array_index() + 1, - def_id.index.address_space(), - ), - }, - ); - - MAX_DEF_ID.with(|m| { - m.borrow_mut() - .entry(def_id.krate.clone()) - .or_insert(start_def_id); - }); - - self.cx.all_fake_def_ids.borrow_mut().insert(def_id); - - def_id.clone() +impl<'a, 'tcx: 'a, 'rcx: 'a> Finder<'a, 'tcx, 'rcx> for AutoTraitFinder<'a, 'tcx, 'rcx> { + fn get_cx(&self) -> &DocContext<'a, 'tcx, 'rcx> { + &self.cx } } diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs new file mode 100644 index 0000000000000..bb86688447e1e --- /dev/null +++ b/src/librustdoc/clean/blanket_impl.rs @@ -0,0 +1,170 @@ +// 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. + +use rustc::hir; +use rustc::traits; +use rustc::ty::ToPredicate; +use rustc::ty::subst::Subst; +use rustc::infer::InferOk; +use syntax_pos::DUMMY_SP; + +use core::DocAccessLevels; + +use super::*; + +use self::def_ctor::{get_def_ctor_from_def_id, get_def_ctor_from_node_id}; +use self::finder_trait::Finder; + +pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a> { + pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, +} + +impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { + pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> Self { + BlanketImplFinder { cx } + } + + pub fn get_with_def_id(&self, def_id: DefId) -> Vec { + get_def_ctor_from_def_id(&self.cx, def_id, &|def_ctor| { + self.get_blanket_impls(def_id, &def_ctor, None) + }) + } + + pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { + get_def_ctor_from_node_id(&self.cx, id, name, &|def_ctor, name| { + let did = self.cx.tcx.hir.local_def_id(id); + self.get_blanket_impls(did, &def_ctor, Some(name)) + }) + } + + pub fn get_blanket_impls( + &self, + def_id: DefId, + def_ctor: &F, + name: Option, + ) -> Vec + where F: Fn(DefId) -> Def { + let mut impls = Vec::new(); + if self.cx + .tcx + .get_attrs(def_id) + .lists("doc") + .has_word("hidden") + { + debug!( + "get_blanket_impls(def_id={:?}, def_ctor=...): item has doc('hidden'), \ + aborting", + def_id + ); + return impls; + } + if self.cx.access_levels.borrow().is_doc_reachable(def_id) { + let generics = self.cx.tcx.generics_of(def_id); + let ty = self.cx.tcx.type_of(def_id); + let real_name = name.clone().map(|name| Ident::from_str(&name)); + let param_env = self.cx.tcx.param_env(def_id); + for &trait_def_id in self.cx.all_traits.iter() { + if !self.cx.access_levels.borrow().is_doc_reachable(trait_def_id) || + self.cx.generated_synthetics + .borrow_mut() + .get(&(def_id, trait_def_id)) + .is_some() { + continue + } + self.cx.tcx.for_each_relevant_impl(trait_def_id, ty, |impl_def_id| { + self.cx.tcx.infer_ctxt().enter(|infcx| { + let t_generics = infcx.tcx.generics_of(impl_def_id); + let trait_ref = infcx.tcx.impl_trait_ref(impl_def_id) + .expect("Cannot get impl trait"); + + match infcx.tcx.type_of(impl_def_id).sty { + ::rustc::ty::TypeVariants::TyParam(_) => {}, + _ => return, + } + + let substs = infcx.fresh_substs_for_item(DUMMY_SP, def_id); + let ty = ty.subst(infcx.tcx, substs); + let param_env = param_env.subst(infcx.tcx, substs); + + let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); + let trait_ref = trait_ref.subst(infcx.tcx, impl_substs); + + // Require the type the impl is implemented on to match + // our type, and ignore the impl if there was a mismatch. + let cause = traits::ObligationCause::dummy(); + let eq_result = infcx.at(&cause, param_env) + .eq(trait_ref.self_ty(), ty); + if let Ok(InferOk { value: (), obligations }) = eq_result { + // FIXME(eddyb) ignoring `obligations` might cause false positives. + drop(obligations); + + let may_apply = infcx.predicate_may_hold(&traits::Obligation::new( + cause.clone(), + param_env, + trait_ref.to_predicate(), + )); + if !may_apply { + return + } + self.cx.generated_synthetics.borrow_mut() + .insert((def_id, trait_def_id)); + let trait_ = hir::TraitRef { + path: get_path_for_type(infcx.tcx, + trait_def_id, + hir::def::Def::Trait), + ref_id: ast::DUMMY_NODE_ID, + }; + let provided_trait_methods = + infcx.tcx.provided_trait_methods(trait_def_id) + .into_iter() + .map(|meth| meth.ident.to_string()) + .collect(); + + let ty = self.get_real_ty(def_id, def_ctor, &real_name, generics); + let predicates = infcx.tcx.predicates_of(impl_def_id); + + impls.push(Item { + source: infcx.tcx.def_span(impl_def_id).clean(self.cx), + name: None, + attrs: Default::default(), + visibility: None, + def_id: self.next_def_id(impl_def_id.krate), + stability: None, + deprecation: None, + inner: ImplItem(Impl { + unsafety: hir::Unsafety::Normal, + generics: (t_generics, &predicates).clean(self.cx), + provided_trait_methods, + trait_: Some(trait_.clean(self.cx)), + for_: ty.clean(self.cx), + items: infcx.tcx.associated_items(impl_def_id) + .collect::>() + .clean(self.cx), + polarity: None, + synthetic: false, + blanket_impl: Some(infcx.tcx.type_of(impl_def_id) + .clean(self.cx)), + }), + }); + debug!("{:?} => {}", trait_ref, may_apply); + } + }); + }); + } + } + impls + } +} + +impl<'a, 'tcx: 'a, 'rcx: 'a> Finder<'a, 'tcx, 'rcx> for BlanketImplFinder<'a, 'tcx, 'rcx> { + fn get_cx(&self) -> &DocContext<'a, 'tcx, 'rcx> { + &self.cx + } +} diff --git a/src/librustdoc/clean/def_ctor.rs b/src/librustdoc/clean/def_ctor.rs new file mode 100644 index 0000000000000..cb91f0d0be67d --- /dev/null +++ b/src/librustdoc/clean/def_ctor.rs @@ -0,0 +1,65 @@ +// 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. + +use core::DocContext; + +use super::*; + +pub fn get_def_ctor_from_def_id(cx: &DocContext, + def_id: DefId, + callback: &F, +) -> Vec +where F: Fn(&Fn(DefId) -> Def) -> Vec { + let ty = cx.tcx.type_of(def_id); + + match ty.sty { + ty::TyAdt(adt, _) => callback(&match adt.adt_kind() { + AdtKind::Struct => Def::Struct, + AdtKind::Enum => Def::Enum, + AdtKind::Union => Def::Union, + }), + ty::TyInt(_) | + ty::TyUint(_) | + ty::TyFloat(_) | + ty::TyStr | + ty::TyBool | + ty::TyChar => callback(&move |_: DefId| { + match ty.sty { + ty::TyInt(x) => Def::PrimTy(hir::TyInt(x)), + ty::TyUint(x) => Def::PrimTy(hir::TyUint(x)), + ty::TyFloat(x) => Def::PrimTy(hir::TyFloat(x)), + ty::TyStr => Def::PrimTy(hir::TyStr), + ty::TyBool => Def::PrimTy(hir::TyBool), + ty::TyChar => Def::PrimTy(hir::TyChar), + _ => unreachable!(), + } + }), + _ => { + debug!("Unexpected type {:?}", def_id); + Vec::new() + } + } +} + +pub fn get_def_ctor_from_node_id(cx: &DocContext, + id: ast::NodeId, + name: String, + callback: &F, +) -> Vec +where F: Fn(&Fn(DefId) -> Def, String) -> Vec { + let item = &cx.tcx.hir.expect_item(id).node; + + callback(&match *item { + hir::ItemKind::Struct(_, _) => Def::Struct, + hir::ItemKind::Union(_, _) => Def::Union, + hir::ItemKind::Enum(_, _) => Def::Enum, + _ => panic!("Unexpected type {:?} {:?}", item, id), + }, name) +} diff --git a/src/librustdoc/clean/finder_trait.rs b/src/librustdoc/clean/finder_trait.rs new file mode 100644 index 0000000000000..cc0f3c49d16fb --- /dev/null +++ b/src/librustdoc/clean/finder_trait.rs @@ -0,0 +1,154 @@ +// 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. + +use rustc::hir; +use syntax_pos::DUMMY_SP; + +use super::*; + +pub trait Finder<'a, 'tcx: 'a, 'rcx: 'a> { + fn get_cx(&self) -> &DocContext<'a, 'tcx, 'rcx>; + + // This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly + // refactoring either librustdoc or librustc. In particular, allowing new DefIds to be + // registered after the AST is constructed would require storing the defid mapping in a + // RefCell, decreasing the performance for normal compilation for very little gain. + // + // Instead, we construct 'fake' def ids, which start immediately after the last DefId in + // DefIndexAddressSpace::Low. In the Debug impl for clean::Item, we explicitly check for fake + // def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds + fn next_def_id(&self, crate_num: CrateNum) -> DefId { + let start_def_id = { + let next_id = if crate_num == LOCAL_CRATE { + self.get_cx() + .tcx + .hir + .definitions() + .def_path_table() + .next_id(DefIndexAddressSpace::Low) + } else { + self.get_cx() + .cstore + .def_path_table(crate_num) + .next_id(DefIndexAddressSpace::Low) + }; + + DefId { + krate: crate_num, + index: next_id, + } + }; + + let mut fake_ids = self.get_cx().fake_def_ids.borrow_mut(); + + let def_id = fake_ids.entry(crate_num).or_insert(start_def_id).clone(); + fake_ids.insert( + crate_num, + DefId { + krate: crate_num, + index: DefIndex::from_array_index( + def_id.index.as_array_index() + 1, + def_id.index.address_space(), + ), + }, + ); + + MAX_DEF_ID.with(|m| { + m.borrow_mut() + .entry(def_id.krate.clone()) + .or_insert(start_def_id); + }); + + self.get_cx().all_fake_def_ids.borrow_mut().insert(def_id); + + def_id.clone() + } + + fn get_real_ty(&self, + def_id: DefId, + def_ctor: &F, + real_name: &Option, + generics: &ty::Generics, + ) -> hir::Ty + where F: Fn(DefId) -> Def { + let path = get_path_for_type(self.get_cx().tcx, def_id, def_ctor); + let mut segments = path.segments.into_vec(); + let last = segments.pop().expect("segments were empty"); + + segments.push(hir::PathSegment::new( + real_name.unwrap_or(last.ident), + self.generics_to_path_params(generics.clone()), + false, + )); + + let new_path = hir::Path { + span: path.span, + def: path.def, + segments: HirVec::from_vec(segments), + }; + + hir::Ty { + id: ast::DUMMY_NODE_ID, + node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), + span: DUMMY_SP, + hir_id: hir::DUMMY_HIR_ID, + } + } + + fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs { + let mut args = vec![]; + + for param in generics.params.iter() { + match param.kind { + ty::GenericParamDefKind::Lifetime => { + let name = if param.name == "" { + hir::ParamName::Plain(keywords::StaticLifetime.ident()) + } else { + hir::ParamName::Plain(ast::Ident::from_interned_str(param.name)) + }; + + args.push(hir::GenericArg::Lifetime(hir::Lifetime { + id: ast::DUMMY_NODE_ID, + span: DUMMY_SP, + name: hir::LifetimeName::Param(name), + })); + } + ty::GenericParamDefKind::Type {..} => { + args.push(hir::GenericArg::Type(self.ty_param_to_ty(param.clone()))); + } + } + } + + hir::GenericArgs { + args: HirVec::from_vec(args), + bindings: HirVec::new(), + parenthesized: false, + } + } + + fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { + debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); + hir::Ty { + id: ast::DUMMY_NODE_ID, + node: hir::TyKind::Path(hir::QPath::Resolved( + None, + P(hir::Path { + span: DUMMY_SP, + def: Def::TyParam(param.def_id), + segments: HirVec::from_vec(vec![ + hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) + ]), + }), + )), + span: DUMMY_SP, + hir_id: hir::DUMMY_HIR_ID, + } + } +} diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 8b4df1b7b7d21..1c66c39b660b2 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -25,7 +25,13 @@ use rustc::util::nodemap::FxHashSet; use core::{DocContext, DocAccessLevels}; use doctree; -use clean::{self, GetDefId, ToSource, get_auto_traits_with_def_id}; +use clean::{ + self, + GetDefId, + ToSource, + get_auto_traits_with_def_id, + get_blanket_impls_with_def_id, +}; use super::Clean; @@ -168,7 +174,7 @@ pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) { } }); let fqn = if let clean::TypeKind::Macro = kind { - vec![crate_name, relative.last().unwrap()] + vec![crate_name, relative.last().expect("relative was empty")] } else { once(crate_name).chain(relative).collect() }; @@ -274,11 +280,14 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec = auto_impls.into_iter() - .filter(|i| renderinfo.inlined.insert(i.def_id)).collect(); + { + let mut renderinfo = cx.renderinfo.borrow_mut(); + let new_impls: Vec = auto_impls.into_iter() + .filter(|i| renderinfo.inlined.insert(i.def_id)).collect(); - impls.extend(new_impls); + impls.extend(new_impls); + } + impls.extend(get_blanket_impls_with_def_id(cx, did)); } // If this is the first time we've inlined something from another crate, then @@ -336,10 +345,13 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec = auto_impls.into_iter() - .filter(|i| renderinfo.inlined.insert(i.def_id)).collect(); + .chain(blanket_impls.into_iter()) + .filter(|i| renderinfo.inlined.insert(i.def_id)) + .collect(); impls.extend(new_impls); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4512a33ec4a21..8e70aaf2d3124 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -73,9 +73,13 @@ pub mod inline; pub mod cfg; mod simplify; mod auto_trait; +mod blanket_impl; +pub mod def_ctor; +mod finder_trait; use self::cfg::Cfg; use self::auto_trait::AutoTraitFinder; +use self::blanket_impl::BlanketImplFinder; thread_local!(static MAX_DEF_ID: RefCell> = RefCell::new(FxHashMap())); @@ -569,7 +573,7 @@ pub struct Module { impl Clean for doctree::Module { fn clean(&self, cx: &DocContext) -> Item { let name = if self.name.is_some() { - self.name.unwrap().clean(cx) + self.name.expect("No name provided").clean(cx) } else { "".to_string() }; @@ -1064,7 +1068,7 @@ fn span_of_attrs(attrs: &Attributes) -> syntax_pos::Span { return DUMMY_SP; } let start = attrs.doc_strings[0].span(); - let end = attrs.doc_strings.last().unwrap().span(); + let end = attrs.doc_strings.last().expect("No doc strings provided").span(); start.to(end) } @@ -1728,7 +1732,7 @@ impl Clean for hir::GenericParam { hir::GenericBound::Outlives(lt) => lt, _ => panic!(), }); - let name = bounds.next().unwrap().name.ident(); + let name = bounds.next().expect("no more bounds").name.ident(); let mut s = format!("{}: {}", self.name.ident(), name); for bound in bounds { s.push_str(&format!(" + {}", bound.name.ident())); @@ -1841,8 +1845,8 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty: fn clean(&self, cx: &DocContext) -> WherePredicate { let ty::OutlivesPredicate(ref a, ref b) = *self; WherePredicate::RegionPredicate { - lifetime: a.clean(cx).unwrap(), - bounds: vec![GenericBound::Outlives(b.clean(cx).unwrap())] + lifetime: a.clean(cx).expect("failed to clean lifetime"), + bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))] } } } @@ -1853,7 +1857,7 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region< WherePredicate::BoundPredicate { ty: ty.clean(cx), - bounds: vec![GenericBound::Outlives(lt.clean(cx).unwrap())] + bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))] } } } @@ -1947,7 +1951,7 @@ impl Clean for hir::GenericParam { hir::GenericBound::Outlives(lt) => lt, _ => panic!(), }); - let name = bounds.next().unwrap().name.ident(); + let name = bounds.next().expect("no more bounds").name.ident(); let mut s = format!("{}: {}", self.name.ident(), name); for bound in bounds { s.push_str(&format!(" + {}", bound.name.ident())); @@ -2933,7 +2937,7 @@ impl Clean for hir::Ty { }; if let Some(&hir::ItemKind::Ty(ref ty, ref generics)) = alias { - let provided_params = &path.segments.last().unwrap(); + let provided_params = &path.segments.last().expect("segments were empty"); let mut ty_substs = FxHashMap(); let mut lt_substs = FxHashMap(); provided_params.with_generic_args(|generic_args| { @@ -3006,7 +3010,7 @@ impl Clean for hir::Ty { segments: segments.into(), }; Type::QPath { - name: p.segments.last().unwrap().ident.name.clean(cx), + name: p.segments.last().expect("segments were empty").ident.name.clean(cx), self_type: box qself.clean(cx), trait_: box resolve_type(cx, trait_path.clean(cx), self.id) } @@ -3062,7 +3066,7 @@ impl<'tcx> Clean for Ty<'tcx> { ty::TyStr => Primitive(PrimitiveType::Str), ty::TySlice(ty) => Slice(box ty.clean(cx)), ty::TyArray(ty, n) => { - let mut n = cx.tcx.lift(&n).unwrap(); + let mut n = cx.tcx.lift(&n).expect("array lift failed"); if let ConstValue::Unevaluated(def_id, substs) = n.val { let param_env = cx.tcx.param_env(def_id); let cid = GlobalId { @@ -3084,7 +3088,7 @@ impl<'tcx> Clean for Ty<'tcx> { }, ty::TyFnDef(..) | ty::TyFnPtr(_) => { - let ty = cx.tcx.lift(self).unwrap(); + let ty = cx.tcx.lift(self).expect("TyFnPtr lift failed"); let sig = ty.fn_sig(cx.tcx); BareFunction(box BareFunctionDecl { unsafety: sig.unsafety(), @@ -3175,7 +3179,7 @@ impl<'tcx> Clean for Ty<'tcx> { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the projections associated with the def_id. let predicates_of = cx.tcx.predicates_of(def_id); - let substs = cx.tcx.lift(&substs).unwrap(); + let substs = cx.tcx.lift(&substs).expect("TyAnon lift failed"); let bounds = predicates_of.instantiate(cx.tcx, substs); let mut regions = vec![]; let mut has_sized = false; @@ -3314,6 +3318,7 @@ impl Clean> for doctree::Struct { fn clean(&self, cx: &DocContext) -> Vec { let name = self.name.clean(cx); let mut ret = get_auto_traits_with_node_id(cx, self.id, name.clone()); + ret.extend(get_blanket_impls_with_node_id(cx, self.id, name.clone())); *cx.current_item_name.borrow_mut() = Some(self.name); ret.push(Item { @@ -3340,6 +3345,7 @@ impl Clean> for doctree::Union { fn clean(&self, cx: &DocContext) -> Vec { let name = self.name.clean(cx); let mut ret = get_auto_traits_with_node_id(cx, self.id, name.clone()); + ret.extend(get_blanket_impls_with_node_id(cx, self.id, name.clone())); *cx.current_item_name.borrow_mut() = Some(self.name); ret.push(Item { @@ -3393,6 +3399,7 @@ impl Clean> for doctree::Enum { fn clean(&self, cx: &DocContext) -> Vec { let name = self.name.clean(cx); let mut ret = get_auto_traits_with_node_id(cx, self.id, name.clone()); + ret.extend(get_blanket_impls_with_node_id(cx, self.id, name.clone())); *cx.current_item_name.borrow_mut() = Some(self.name); ret.push(Item { @@ -3545,7 +3552,7 @@ pub struct Path { impl Path { pub fn last_name(&self) -> &str { - self.segments.last().unwrap().name.as_str() + self.segments.last().expect("segments were empty").name.as_str() } } @@ -3875,6 +3882,17 @@ pub fn get_auto_traits_with_def_id(cx: &DocContext, id: DefId) -> Vec { finder.get_with_def_id(id) } +pub fn get_blanket_impls_with_node_id(cx: &DocContext, id: ast::NodeId, name: String) -> Vec { + let finder = BlanketImplFinder::new(cx); + finder.get_with_node_id(id, name) +} + +pub fn get_blanket_impls_with_def_id(cx: &DocContext, id: DefId) -> Vec { + let finder = BlanketImplFinder::new(cx); + + finder.get_with_def_id(id) +} + fn get_name_if_possible(cx: &DocContext, node: NodeId) -> Option { match cx.tcx.hir.get(node) { Node::NodeItem(_) | @@ -4196,7 +4214,7 @@ fn print_const(cx: &DocContext, n: &ty::Const) -> String { }, _ => { let mut s = String::new(); - ::rustc::mir::fmt_const_val(&mut s, n).unwrap(); + ::rustc::mir::fmt_const_val(&mut s, n).expect("fmt_const_val failed"); // array lengths are obviously usize if s.ends_with("usize") { let n = s.len() - "usize".len(); @@ -4257,7 +4275,8 @@ fn register_def(cx: &DocContext, def: Def) -> DefId { Def::TyForeign(i) => (i, TypeKind::Foreign), Def::Const(i) => (i, TypeKind::Const), Def::Static(i, _) => (i, TypeKind::Static), - Def::Variant(i) => (cx.tcx.parent_def_id(i).unwrap(), TypeKind::Enum), + Def::Variant(i) => (cx.tcx.parent_def_id(i).expect("cannot get parent def id"), + TypeKind::Enum), Def::Macro(i, _) => (i, TypeKind::Macro), Def::SelfTy(Some(def_id), _) => (def_id, TypeKind::Trait), Def::SelfTy(_, Some(impl_def_id)) => { diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 30a55bf0d1809..9ea8bc536352a 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -96,7 +96,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec) -> Vec { if !trait_is_same_or_supertrait(cx, did, trait_did) { return false } - let last = path.segments.last_mut().unwrap(); + let last = path.segments.last_mut().expect("segments were empty"); match last.args { PP::AngleBracketed { ref mut bindings, .. } => { bindings.push(clean::TypeBinding { From 8301081c906b733576b15ee3125f23ff6d60c560 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 29 Jul 2018 16:30:39 +0200 Subject: [PATCH 2/7] Fix primitive blanket impls not showing up --- src/librustdoc/clean/blanket_impl.rs | 9 ++++----- src/test/rustdoc/primitive-generic-impl.rs | 18 ++++++++++++++++++ .../primitive/primitive-generic-impl.rs | 13 +++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc/primitive-generic-impl.rs create mode 100644 src/test/rustdoc/primitive/primitive-generic-impl.rs diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index bb86688447e1e..ade65ec99b14f 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -65,9 +65,9 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { ); return impls; } - if self.cx.access_levels.borrow().is_doc_reachable(def_id) { + let ty = self.cx.tcx.type_of(def_id); + if self.cx.access_levels.borrow().is_doc_reachable(def_id) || ty.is_primitive() { let generics = self.cx.tcx.generics_of(def_id); - let ty = self.cx.tcx.type_of(def_id); let real_name = name.clone().map(|name| Ident::from_str(&name)); let param_env = self.cx.tcx.param_env(def_id); for &trait_def_id in self.cx.all_traits.iter() { @@ -84,8 +84,8 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { let trait_ref = infcx.tcx.impl_trait_ref(impl_def_id) .expect("Cannot get impl trait"); - match infcx.tcx.type_of(impl_def_id).sty { - ::rustc::ty::TypeVariants::TyParam(_) => {}, + match trait_ref.self_ty().sty { + ty::TypeVariants::TyParam(_) => {}, _ => return, } @@ -153,7 +153,6 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { .clean(self.cx)), }), }); - debug!("{:?} => {}", trait_ref, may_apply); } }); }); diff --git a/src/test/rustdoc/primitive-generic-impl.rs b/src/test/rustdoc/primitive-generic-impl.rs new file mode 100644 index 0000000000000..b4351b8268c8b --- /dev/null +++ b/src/test/rustdoc/primitive-generic-impl.rs @@ -0,0 +1,18 @@ +// 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. + +#![crate_name = "foo"] + +// we need to reexport something from libstd so that `all_trait_implementations` is called. +pub use std::string::String; + +include!("primitive/primitive-generic-impl.rs"); + +// @has foo/primitive.i32.html '//h3[@id="impl-ToString"]//code' 'impl ToString for T' diff --git a/src/test/rustdoc/primitive/primitive-generic-impl.rs b/src/test/rustdoc/primitive/primitive-generic-impl.rs new file mode 100644 index 0000000000000..1ac1fc95338af --- /dev/null +++ b/src/test/rustdoc/primitive/primitive-generic-impl.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. + +#[doc(primitive = "i32")] +/// Some useless docs, wouhou! +mod i32 {} From e0f8f871f6bbec2008af5697b8975ffe12d4571d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 29 Jul 2018 16:47:31 +0200 Subject: [PATCH 3/7] Strengthen tests --- src/test/rustdoc/generic-impl.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/rustdoc/generic-impl.rs b/src/test/rustdoc/generic-impl.rs index e2665fd8f375b..46e02ed08e00a 100644 --- a/src/test/rustdoc/generic-impl.rs +++ b/src/test/rustdoc/generic-impl.rs @@ -17,6 +17,7 @@ pub struct Bar; // @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl ToString for T' pub struct Foo; +// @has foo/struct.Foo.html '//div[@class="sidebar-links"]/a[@href="#impl-ToString"]' 'ToString' impl fmt::Display for Foo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { From 2758de4b957fdd5f810db63b9128eaa9629770fa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 29 Jul 2018 19:32:07 +0200 Subject: [PATCH 4/7] Fix dyn objects --- src/librustdoc/clean/def_ctor.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/def_ctor.rs b/src/librustdoc/clean/def_ctor.rs index cb91f0d0be67d..b20a0c506b8ed 100644 --- a/src/librustdoc/clean/def_ctor.rs +++ b/src/librustdoc/clean/def_ctor.rs @@ -16,7 +16,7 @@ pub fn get_def_ctor_from_def_id(cx: &DocContext, def_id: DefId, callback: &F, ) -> Vec -where F: Fn(&Fn(DefId) -> Def) -> Vec { +where F: Fn(& dyn Fn(DefId) -> Def) -> Vec { let ty = cx.tcx.type_of(def_id); match ty.sty { @@ -53,7 +53,7 @@ pub fn get_def_ctor_from_node_id(cx: &DocContext, name: String, callback: &F, ) -> Vec -where F: Fn(&Fn(DefId) -> Def, String) -> Vec { +where F: Fn(& dyn Fn(DefId) -> Def, String) -> Vec { let item = &cx.tcx.hir.expect_item(id).node; callback(&match *item { From fc81adb3c221c4d5687685742f6235c37128e8e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 31 Jul 2018 22:40:55 +0200 Subject: [PATCH 5/7] Improve functions naming --- src/librustdoc/clean/auto_trait.rs | 6 +++--- src/librustdoc/clean/blanket_impl.rs | 6 +++--- src/librustdoc/clean/def_ctor.rs | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 67f3d6217b60c..289b174b6f44f 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -16,7 +16,7 @@ use rustc::infer::InferOk; use rustc::middle::cstore::CrateStore; use std::fmt::Debug; -use self::def_ctor::{get_def_ctor_from_def_id, get_def_ctor_from_node_id}; +use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; use self::finder_trait::Finder; use super::*; @@ -34,13 +34,13 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { } pub fn get_with_def_id(&self, def_id: DefId) -> Vec { - get_def_ctor_from_def_id(&self.cx, def_id, &|def_ctor| { + get_def_from_def_id(&self.cx, def_id, &|def_ctor| { self.get_auto_trait_impls(def_id, &def_ctor, None) }) } pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { - get_def_ctor_from_node_id(&self.cx, id, name, &|def_ctor, name| { + get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| { let did = self.cx.tcx.hir.local_def_id(id); self.get_auto_trait_impls(did, &def_ctor, Some(name)) }) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index ade65ec99b14f..05e57337c70e3 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -19,7 +19,7 @@ use core::DocAccessLevels; use super::*; -use self::def_ctor::{get_def_ctor_from_def_id, get_def_ctor_from_node_id}; +use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; use self::finder_trait::Finder; pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a> { @@ -32,13 +32,13 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { } pub fn get_with_def_id(&self, def_id: DefId) -> Vec { - get_def_ctor_from_def_id(&self.cx, def_id, &|def_ctor| { + get_def_from_def_id(&self.cx, def_id, &|def_ctor| { self.get_blanket_impls(def_id, &def_ctor, None) }) } pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec { - get_def_ctor_from_node_id(&self.cx, id, name, &|def_ctor, name| { + get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| { let did = self.cx.tcx.hir.local_def_id(id); self.get_blanket_impls(did, &def_ctor, Some(name)) }) diff --git a/src/librustdoc/clean/def_ctor.rs b/src/librustdoc/clean/def_ctor.rs index b20a0c506b8ed..4db211b7f1e70 100644 --- a/src/librustdoc/clean/def_ctor.rs +++ b/src/librustdoc/clean/def_ctor.rs @@ -12,9 +12,9 @@ use core::DocContext; use super::*; -pub fn get_def_ctor_from_def_id(cx: &DocContext, - def_id: DefId, - callback: &F, +pub fn get_def_from_def_id(cx: &DocContext, + def_id: DefId, + callback: &F, ) -> Vec where F: Fn(& dyn Fn(DefId) -> Def) -> Vec { let ty = cx.tcx.type_of(def_id); @@ -48,10 +48,10 @@ where F: Fn(& dyn Fn(DefId) -> Def) -> Vec { } } -pub fn get_def_ctor_from_node_id(cx: &DocContext, - id: ast::NodeId, - name: String, - callback: &F, +pub fn get_def_from_node_id(cx: &DocContext, + id: ast::NodeId, + name: String, + callback: &F, ) -> Vec where F: Fn(& dyn Fn(DefId) -> Def, String) -> Vec { let item = &cx.tcx.hir.expect_item(id).node; From 0bff861d3268de14426b1a8b4912aebf8330a009 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 Aug 2018 22:13:05 +0200 Subject: [PATCH 6/7] Remove FinderTrait and move its functions into DocContext --- src/librustdoc/clean/auto_trait.rs | 11 +- src/librustdoc/clean/blanket_impl.rs | 11 +- src/librustdoc/clean/finder_trait.rs | 154 --------------------------- src/librustdoc/clean/mod.rs | 9 +- src/librustdoc/core.rs | 145 ++++++++++++++++++++++++- 5 files changed, 150 insertions(+), 180 deletions(-) delete mode 100644 src/librustdoc/clean/finder_trait.rs diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 289b174b6f44f..61cd34ae7fd00 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -17,7 +17,6 @@ use rustc::middle::cstore::CrateStore; use std::fmt::Debug; use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; -use self::finder_trait::Finder; use super::*; @@ -168,14 +167,14 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { _ => unreachable!(), }; let real_name = name.map(|name| Ident::from_str(&name)); - let ty = self.get_real_ty(def_id, def_ctor, &real_name, &generics); + let ty = self.cx.get_real_ty(def_id, def_ctor, &real_name, &generics); return Some(Item { source: Span::empty(), name: None, attrs: Default::default(), visibility: None, - def_id: self.next_def_id(def_id.krate), + def_id: self.cx.next_def_id(def_id.krate), stability: None, deprecation: None, inner: ImplItem(Impl { @@ -862,12 +861,6 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { } } -impl<'a, 'tcx: 'a, 'rcx: 'a> Finder<'a, 'tcx, 'rcx> for AutoTraitFinder<'a, 'tcx, 'rcx> { - fn get_cx(&self) -> &DocContext<'a, 'tcx, 'rcx> { - &self.cx - } -} - // Replaces all ReVars in a type with ty::Region's, using the provided map struct RegionReplacer<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { vid_to_region: &'a FxHashMap>, diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 05e57337c70e3..386f46dbfedc2 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -20,7 +20,6 @@ use core::DocAccessLevels; use super::*; use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; -use self::finder_trait::Finder; pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a> { pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, @@ -127,7 +126,7 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { .map(|meth| meth.ident.to_string()) .collect(); - let ty = self.get_real_ty(def_id, def_ctor, &real_name, generics); + let ty = self.cx.get_real_ty(def_id, def_ctor, &real_name, generics); let predicates = infcx.tcx.predicates_of(impl_def_id); impls.push(Item { @@ -135,7 +134,7 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { name: None, attrs: Default::default(), visibility: None, - def_id: self.next_def_id(impl_def_id.krate), + def_id: self.cx.next_def_id(impl_def_id.krate), stability: None, deprecation: None, inner: ImplItem(Impl { @@ -161,9 +160,3 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { impls } } - -impl<'a, 'tcx: 'a, 'rcx: 'a> Finder<'a, 'tcx, 'rcx> for BlanketImplFinder<'a, 'tcx, 'rcx> { - fn get_cx(&self) -> &DocContext<'a, 'tcx, 'rcx> { - &self.cx - } -} diff --git a/src/librustdoc/clean/finder_trait.rs b/src/librustdoc/clean/finder_trait.rs deleted file mode 100644 index cc0f3c49d16fb..0000000000000 --- a/src/librustdoc/clean/finder_trait.rs +++ /dev/null @@ -1,154 +0,0 @@ -// 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. - -use rustc::hir; -use syntax_pos::DUMMY_SP; - -use super::*; - -pub trait Finder<'a, 'tcx: 'a, 'rcx: 'a> { - fn get_cx(&self) -> &DocContext<'a, 'tcx, 'rcx>; - - // This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly - // refactoring either librustdoc or librustc. In particular, allowing new DefIds to be - // registered after the AST is constructed would require storing the defid mapping in a - // RefCell, decreasing the performance for normal compilation for very little gain. - // - // Instead, we construct 'fake' def ids, which start immediately after the last DefId in - // DefIndexAddressSpace::Low. In the Debug impl for clean::Item, we explicitly check for fake - // def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds - fn next_def_id(&self, crate_num: CrateNum) -> DefId { - let start_def_id = { - let next_id = if crate_num == LOCAL_CRATE { - self.get_cx() - .tcx - .hir - .definitions() - .def_path_table() - .next_id(DefIndexAddressSpace::Low) - } else { - self.get_cx() - .cstore - .def_path_table(crate_num) - .next_id(DefIndexAddressSpace::Low) - }; - - DefId { - krate: crate_num, - index: next_id, - } - }; - - let mut fake_ids = self.get_cx().fake_def_ids.borrow_mut(); - - let def_id = fake_ids.entry(crate_num).or_insert(start_def_id).clone(); - fake_ids.insert( - crate_num, - DefId { - krate: crate_num, - index: DefIndex::from_array_index( - def_id.index.as_array_index() + 1, - def_id.index.address_space(), - ), - }, - ); - - MAX_DEF_ID.with(|m| { - m.borrow_mut() - .entry(def_id.krate.clone()) - .or_insert(start_def_id); - }); - - self.get_cx().all_fake_def_ids.borrow_mut().insert(def_id); - - def_id.clone() - } - - fn get_real_ty(&self, - def_id: DefId, - def_ctor: &F, - real_name: &Option, - generics: &ty::Generics, - ) -> hir::Ty - where F: Fn(DefId) -> Def { - let path = get_path_for_type(self.get_cx().tcx, def_id, def_ctor); - let mut segments = path.segments.into_vec(); - let last = segments.pop().expect("segments were empty"); - - segments.push(hir::PathSegment::new( - real_name.unwrap_or(last.ident), - self.generics_to_path_params(generics.clone()), - false, - )); - - let new_path = hir::Path { - span: path.span, - def: path.def, - segments: HirVec::from_vec(segments), - }; - - hir::Ty { - id: ast::DUMMY_NODE_ID, - node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), - span: DUMMY_SP, - hir_id: hir::DUMMY_HIR_ID, - } - } - - fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs { - let mut args = vec![]; - - for param in generics.params.iter() { - match param.kind { - ty::GenericParamDefKind::Lifetime => { - let name = if param.name == "" { - hir::ParamName::Plain(keywords::StaticLifetime.ident()) - } else { - hir::ParamName::Plain(ast::Ident::from_interned_str(param.name)) - }; - - args.push(hir::GenericArg::Lifetime(hir::Lifetime { - id: ast::DUMMY_NODE_ID, - span: DUMMY_SP, - name: hir::LifetimeName::Param(name), - })); - } - ty::GenericParamDefKind::Type {..} => { - args.push(hir::GenericArg::Type(self.ty_param_to_ty(param.clone()))); - } - } - } - - hir::GenericArgs { - args: HirVec::from_vec(args), - bindings: HirVec::new(), - parenthesized: false, - } - } - - fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { - debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); - hir::Ty { - id: ast::DUMMY_NODE_ID, - node: hir::TyKind::Path(hir::QPath::Resolved( - None, - P(hir::Path { - span: DUMMY_SP, - def: Def::TyParam(param.def_id), - segments: HirVec::from_vec(vec![ - hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) - ]), - }), - )), - span: DUMMY_SP, - hir_id: hir::DUMMY_HIR_ID, - } - } -} diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 8e70aaf2d3124..9dbd7d7b2607d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -37,8 +37,7 @@ use rustc::middle::lang_items; use rustc::mir::interpret::GlobalId; use rustc::hir::{self, GenericArg, HirVec}; use rustc::hir::def::{self, Def, CtorKind}; -use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc::hir::def_id::DefIndexAddressSpace; +use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::map::Node; use rustc::ty::subst::Substs; use rustc::ty::{self, TyCtxt, Region, RegionVid, Ty, AdtKind}; @@ -75,13 +74,13 @@ mod simplify; mod auto_trait; mod blanket_impl; pub mod def_ctor; -mod finder_trait; use self::cfg::Cfg; use self::auto_trait::AutoTraitFinder; use self::blanket_impl::BlanketImplFinder; -thread_local!(static MAX_DEF_ID: RefCell> = RefCell::new(FxHashMap())); +thread_local!(pub static MAX_DEF_ID: RefCell> = + RefCell::new(FxHashMap())); const FN_OUTPUT_NAME: &'static str = "Output"; @@ -4505,7 +4504,7 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option { } } -fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: F) -> hir::Path +pub fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: F) -> hir::Path where F: Fn(DefId) -> Def { struct AbsolutePathBuffer { names: Vec, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 84741f12ad183..3b7ae929ca146 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -11,8 +11,10 @@ use rustc_lint; use rustc_driver::{self, driver, target_features, abort_on_err}; use rustc::session::{self, config}; -use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; +use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CrateNum, LOCAL_CRATE}; use rustc::hir::def::Def; +use rustc::hir::{self, HirVec}; +use rustc::middle::cstore::CrateStore; use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, TyCtxt, AllArenas}; use rustc::hir::map as hir_map; @@ -24,11 +26,14 @@ use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; use rustc_target::spec::TargetTriple; -use syntax::ast::{Name, NodeId}; +use syntax::ast::{self, Ident, Name, NodeId}; use syntax::codemap; use syntax::edition::Edition; use syntax::feature_gate::UnstableFeatures; use syntax::json::JsonEmitter; +use syntax::ptr::P; +use syntax::symbol::keywords; +use syntax_pos::DUMMY_SP; use errors; use errors::emitter::{Emitter, EmitterWriter}; @@ -40,7 +45,7 @@ use std::path::PathBuf; use visit_ast::RustdocVisitor; use clean; -use clean::Clean; +use clean::{get_path_for_type, Clean, MAX_DEF_ID}; use html::render::RenderInfo; pub use rustc::session::config::{Input, CodegenOptions}; @@ -106,6 +111,140 @@ impl<'a, 'tcx, 'rcx, 'cstore> DocContext<'a, 'tcx, 'rcx, 'cstore> { *self.lt_substs.borrow_mut() = old_lts; r } + + // This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly + // refactoring either librustdoc or librustc. In particular, allowing new DefIds to be + // registered after the AST is constructed would require storing the defid mapping in a + // RefCell, decreasing the performance for normal compilation for very little gain. + // + // Instead, we construct 'fake' def ids, which start immediately after the last DefId in + // DefIndexAddressSpace::Low. In the Debug impl for clean::Item, we explicitly check for fake + // def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds + pub fn next_def_id(&self, crate_num: CrateNum) -> DefId { + let start_def_id = { + let next_id = if crate_num == LOCAL_CRATE { + self.tcx + .hir + .definitions() + .def_path_table() + .next_id(DefIndexAddressSpace::Low) + } else { + self.cstore + .def_path_table(crate_num) + .next_id(DefIndexAddressSpace::Low) + }; + + DefId { + krate: crate_num, + index: next_id, + } + }; + + let mut fake_ids = self.fake_def_ids.borrow_mut(); + + let def_id = fake_ids.entry(crate_num).or_insert(start_def_id).clone(); + fake_ids.insert( + crate_num, + DefId { + krate: crate_num, + index: DefIndex::from_array_index( + def_id.index.as_array_index() + 1, + def_id.index.address_space(), + ), + }, + ); + + MAX_DEF_ID.with(|m| { + m.borrow_mut() + .entry(def_id.krate.clone()) + .or_insert(start_def_id); + }); + + self.all_fake_def_ids.borrow_mut().insert(def_id); + + def_id.clone() + } + + pub fn get_real_ty(&self, + def_id: DefId, + def_ctor: &F, + real_name: &Option, + generics: &ty::Generics, + ) -> hir::Ty + where F: Fn(DefId) -> Def { + let path = get_path_for_type(self.tcx, def_id, def_ctor); + let mut segments = path.segments.into_vec(); + let last = segments.pop().expect("segments were empty"); + + segments.push(hir::PathSegment::new( + real_name.unwrap_or(last.ident), + self.generics_to_path_params(generics.clone()), + false, + )); + + let new_path = hir::Path { + span: path.span, + def: path.def, + segments: HirVec::from_vec(segments), + }; + + hir::Ty { + id: ast::DUMMY_NODE_ID, + node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), + span: DUMMY_SP, + hir_id: hir::DUMMY_HIR_ID, + } + } + + pub fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs { + let mut args = vec![]; + + for param in generics.params.iter() { + match param.kind { + ty::GenericParamDefKind::Lifetime => { + let name = if param.name == "" { + hir::ParamName::Plain(keywords::StaticLifetime.ident()) + } else { + hir::ParamName::Plain(ast::Ident::from_interned_str(param.name)) + }; + + args.push(hir::GenericArg::Lifetime(hir::Lifetime { + id: ast::DUMMY_NODE_ID, + span: DUMMY_SP, + name: hir::LifetimeName::Param(name), + })); + } + ty::GenericParamDefKind::Type {..} => { + args.push(hir::GenericArg::Type(self.ty_param_to_ty(param.clone()))); + } + } + } + + hir::GenericArgs { + args: HirVec::from_vec(args), + bindings: HirVec::new(), + parenthesized: false, + } + } + + pub fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { + debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); + hir::Ty { + id: ast::DUMMY_NODE_ID, + node: hir::TyKind::Path(hir::QPath::Resolved( + None, + P(hir::Path { + span: DUMMY_SP, + def: Def::TyParam(param.def_id), + segments: HirVec::from_vec(vec![ + hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) + ]), + }), + )), + span: DUMMY_SP, + hir_id: hir::DUMMY_HIR_ID, + } + } } pub trait DocAccessLevels { From d57f3a61c4721506d7fb33cc949cd640d13c939a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 4 Aug 2018 11:40:56 +0200 Subject: [PATCH 7/7] Update to master --- src/Cargo.lock | 163 ++++++++++++++++++++------- src/librustdoc/clean/auto_trait.rs | 7 +- src/librustdoc/clean/blanket_impl.rs | 8 +- 3 files changed, 128 insertions(+), 50 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 61fd5eefa8cb1..5f0d96c9c052c 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -226,7 +226,7 @@ dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "crates-io 0.18.0", - "crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -247,8 +247,8 @@ dependencies = [ "libgit2-sys 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-workspace-hack 1.0.0", "rustfix 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -351,20 +351,18 @@ name = "clippy" version = "0.0.212" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", "clippy-mini-macro-test 0.2.0", "clippy_lints 0.0.212", "compiletest_rs 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-workspace-hack 1.0.0", "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -606,6 +604,11 @@ name = "crossbeam-utils" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crossbeam-utils" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "crypto-hash" version = "0.3.1" @@ -1791,7 +1794,8 @@ dependencies = [ "rls-rustc 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfmt-nightly 0.9.0 (git+https://github.com/rust-lang-nursery/rustfmt?rev=7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b)", + "rustc-workspace-hack 1.0.0", + "rustfmt-nightly 0.9.0", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1849,7 +1853,6 @@ name = "rls-vfs" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "racer 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1900,6 +1903,14 @@ dependencies = [ "rustc-ap-rustc_data_structures 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-arena" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-rustc_cratesio_shim" version = "209.0.0" @@ -1909,6 +1920,15 @@ dependencies = [ "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-rustc_cratesio_shim" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-rustc_data_structures" version = "209.0.0" @@ -1927,6 +1947,24 @@ dependencies = [ "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-rustc_data_structures" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-rustc_errors" version = "209.0.0" @@ -1940,6 +1978,19 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-rustc_errors" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-rustc_target" version = "209.0.0" @@ -1951,11 +2002,27 @@ dependencies = [ "rustc-ap-serialize 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-rustc_target" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-serialize" version = "209.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rustc-ap-serialize" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-ap-syntax" version = "209.0.0" @@ -1971,6 +2038,21 @@ dependencies = [ "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-syntax" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_errors 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-syntax_pos" version = "209.0.0" @@ -1984,6 +2066,19 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-syntax_pos" +version = "211.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-arena 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.8" @@ -2031,6 +2126,14 @@ name = "rustc-serialize" version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rustc-workspace-hack" +version = "1.0.0" +dependencies = [ + "syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc_allocator" version = "0.0.0" @@ -2461,32 +2564,6 @@ dependencies = [ "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustfmt-nightly" -version = "0.9.0" -source = "git+https://github.com/rust-lang-nursery/rustfmt?rev=7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b#7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b" -dependencies = [ - "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", - "isatty 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustfmt-nightly" version = "0.9.0" @@ -2503,9 +2580,9 @@ dependencies = [ "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3120,10 +3197,6 @@ name = "yaml-rust" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -[[patch.unused]] -name = "rustc-workspace-hack" -version = "1.0.0" - [metadata] "checksum aho-corasick 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c6d463cbe7ed28720b5b489e7c083eeb8f90d08be2a0d6bb9e1ffea9ce1afa" "checksum ammonia 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd4c682378117e4186a492b2252b9537990e1617f44aed9788b9a1149de45477" @@ -3164,6 +3237,7 @@ version = "1.0.0" "checksum crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "285987a59c4d91388e749850e3cb7b3a92299668528caaacd08005b8f238c0ea" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ea52fab26a99d96cdff39d0ca75c9716125937f5dba2ab83923aaaf5928f684a" +"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" "checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4" "checksum curl 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "893713db705eab9847e050268507b0e2a2aad64e90a831874bd4e8e0d67f9523" "checksum curl-sys 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "de9cf174efdf90b5887c4e2e900769373c89c5e18152e8f3ed75b501a6f1c0fb" @@ -3293,13 +3367,21 @@ version = "1.0.0" "checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a" "checksum rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ecbc8541b4c341d6271eae10f869dd9d36db871afe184f5b6f9bffbd6ed0373f" "checksum rustc-ap-arena 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b098827864368459cbc7a79fbc54eafb92df7e00a46c0cda352b5a21583ee436" +"checksum rustc-ap-arena 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eec75ed880706dd9a05bc770c327ed142fa7d4b648d9757fbc71d821d68448a5" "checksum rustc-ap-rustc_cratesio_shim 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef4d923dea14fb085bca743fb982f6a3bc11c0d5d30b822bcf6fa16e9464a56c" +"checksum rustc-ap-rustc_cratesio_shim 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f5d54615bedbae65a976e0835edf0de90dd962ec818c0149fe181d5cd81da9e" "checksum rustc-ap-rustc_data_structures 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18c6a5c9edc6b4ae035cdc03af7d8662d39fad7879c5501d103e7087dfaebc80" +"checksum rustc-ap-rustc_data_structures 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c51cc6e79eab25c7ea84a7e104e81e6f44cca32709df54c2cdb4e7059d7843" "checksum rustc-ap-rustc_errors 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9a1e9bdc597abd95cebce0c14c1da58943a9e5b8255530a0fec30659d144eb0b" +"checksum rustc-ap-rustc_errors 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff050095b7afb254506591ee7d3a5d0fb9c03c16f8c2741b588178085e563d49" "checksum rustc-ap-rustc_target 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "142ddef3dc12dda2bcd3412f0d96d3745413a8fbc2f224f0cc97afa04c071d89" +"checksum rustc-ap-rustc_target 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53c7a8c21c3b05f24998fa6ab9ded6269810a2f3ae12ff301c432c1e9fa8e111" "checksum rustc-ap-serialize 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b08f8f175b038a82caa7e51fc52b72ff96cfe8c1429755da30380dbd4199c7f" +"checksum rustc-ap-serialize 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4713c2c0c26a45ead8fb16fee88e16fecf999588ae6920847cbaeb19565b7f" "checksum rustc-ap-syntax 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4c802e0e1fbc64eddc21e0798527eb1f5fdbd5781d119bd2c44b6130afdc81cc" +"checksum rustc-ap-syntax 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "768e2698f912913be2ccd355b2dea62c978efc356f75db1400605f3642905d53" "checksum rustc-ap-syntax_pos 209.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "008d47cc54ed12a2784217b9e6630a7fa1c8dc3591a283f65ad4b7fa307d49d5" +"checksum rustc-ap-syntax_pos 211.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a280dc8919aa7f684832ba3eeab2f6c96dbe2e2e4f6a922f7f0bdb3a9dd9e641" "checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c6d5a683c6ba4ed37959097e88d71c9e8e26659a3cb5be8b389078e7ad45306" @@ -3307,7 +3389,6 @@ version = "1.0.0" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a54aa04a10c68c1c4eacb4337fd883b435997ede17a9385784b990777686b09a" "checksum rustfix 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "756567f00f7d89c9f89a5c401b8b1caaa122e27240b9eaadd0bb52ee0b680b1b" -"checksum rustfmt-nightly 0.9.0 (git+https://github.com/rust-lang-nursery/rustfmt?rev=7e3dc8fae7ed84cc1879ef4e0bc6f00dfe059e1b)" = "" "checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637" "checksum schannel 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "dc1fabf2a7b6483a141426e1afd09ad543520a77ac49bd03c286e7696ccfd77f" "checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 61cd34ae7fd00..507aff0c3c727 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -9,11 +9,8 @@ // except according to those terms. use rustc::hir; -use rustc::traits::{self, auto_trait as auto}; -use rustc::ty::{self, ToPredicate, TypeFoldable}; -use rustc::ty::subst::Subst; -use rustc::infer::InferOk; -use rustc::middle::cstore::CrateStore; +use rustc::traits::auto_trait as auto; +use rustc::ty::{self, TypeFoldable}; use std::fmt::Debug; use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 386f46dbfedc2..5b352ffb725d0 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -21,12 +21,12 @@ use super::*; use self::def_ctor::{get_def_from_def_id, get_def_from_node_id}; -pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a> { - pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, +pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> { + pub cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>, } -impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> { - pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> Self { +impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> { + pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>) -> Self { BlanketImplFinder { cx } }