From a42c0257c7ed05558f685a77db0de08379feeef8 Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Tue, 18 Apr 2017 13:40:00 -0300 Subject: [PATCH 01/16] Add bootstrap support for android --- src/bootstrap/bootstrap.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 2e33b4511949d..e27f4091b1914 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -415,7 +415,11 @@ def build_triple(self): # The goal here is to come up with the same triple as LLVM would, # at least for the subset of platforms we're willing to target. if ostype == 'Linux': - ostype = 'unknown-linux-gnu' + os = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding) + if os == 'Android': + ostype = 'linux-android' + else: + ostype = 'unknown-linux-gnu' elif ostype == 'FreeBSD': ostype = 'unknown-freebsd' elif ostype == 'DragonFly': @@ -472,15 +476,21 @@ def build_triple(self): cputype = 'i686' elif cputype in {'xscale', 'arm'}: cputype = 'arm' + if ostype == 'linux-android': + ostype = 'linux-androideabi' elif cputype == 'armv6l': cputype = 'arm' - ostype += 'eabihf' + if ostype == 'linux-android': + ostype = 'linux-androideabi' + else: + ostype += 'eabihf' elif cputype in {'armv7l', 'armv8l'}: cputype = 'armv7' - ostype += 'eabihf' - elif cputype == 'aarch64': - cputype = 'aarch64' - elif cputype == 'arm64': + if ostype == 'linux-android': + ostype = 'linux-androideabi' + else: + ostype += 'eabihf' + elif cputype in {'aarch64', 'arm64'}: cputype = 'aarch64' elif cputype == 'mips': if sys.byteorder == 'big': From 87d3272940806cdbad166e24cde28040e8395a26 Mon Sep 17 00:00:00 2001 From: kennytm Date: Tue, 18 Apr 2017 00:07:36 +0800 Subject: [PATCH 02/16] Pass `--format-version 1` to `cargo metadata`. Suppress warning introduced by rust-lang/cargo#3841. --- src/bootstrap/metadata.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/metadata.rs b/src/bootstrap/metadata.rs index 5918fe41e7c8b..7b6b01655df58 100644 --- a/src/bootstrap/metadata.rs +++ b/src/bootstrap/metadata.rs @@ -58,6 +58,7 @@ fn build_krate(build: &mut Build, krate: &str) { // the dependency graph and what `-p` arguments there are. let mut cargo = Command::new(&build.cargo); cargo.arg("metadata") + .arg("--format-version").arg("1") .arg("--manifest-path").arg(build.src.join(krate).join("Cargo.toml")); let output = output(&mut cargo); let output: Output = json::decode(&output).unwrap(); From f2bbd455b106bfb25f32a372b65143f13ca1293e Mon Sep 17 00:00:00 2001 From: kennytm Date: Tue, 18 Apr 2017 04:22:16 +0800 Subject: [PATCH 03/16] Support AddressSanitizer and ThreadSanitizer on x86_64-apple-darwin. ASan and TSan are supported on macOS, and this commit enables their support. The sanitizers are always built as *.dylib on Apple platforms, so they cannot be statically linked into the corresponding `rustc_?san.rlib`. The dylibs are directly copied to `lib/rustlib/x86_64-apple-darwin/lib/` instead. Note, although Xcode also ships with their own copies of ASan/TSan dylibs, we cannot use them due to version mismatch. There is a caveat: the sanitizer libraries are linked as @rpath, so the user needs to additionally pass `-C rpath`: rustc -Z sanitizer=address -C rpath file.rs ^~~~~~~~ Otherwise there will be a runtime error: dyld: Library not loaded: @rpath/libclang_rt.asan_osx_dynamic.dylib Referenced from: /path/to/executable Reason: image not found Abort trap: 6 The next commit includes a temporary change in compiler to force the linker to emit a usable @rpath. --- .travis.yml | 4 +-- src/bootstrap/compile.rs | 16 ++++++++++++ src/build_helper/lib.rs | 21 +++++++++++++++- src/librustc/session/config.rs | 2 +- src/librustc_asan/build.rs | 5 ++-- src/librustc_lsan/build.rs | 5 ++-- src/librustc_metadata/creader.rs | 25 +++++++++++++++---- src/librustc_msan/build.rs | 5 ++-- src/librustc_tsan/build.rs | 5 ++-- src/libstd/Cargo.toml | 4 +++ src/test/run-make/sanitizer-address/Makefile | 20 ++++++++++----- .../sanitizer-invalid-target/Makefile | 2 +- src/test/run-make/sanitizer-leak/Makefile | 8 +++--- src/test/run-make/sanitizer-memory/Makefile | 8 +++--- 14 files changed, 94 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5d56379dccebf..c5372609e9bc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,7 +54,7 @@ matrix: # version that we're using, 8.2, cannot compile LLVM for OSX 10.7. - env: > RUST_CHECK_TARGET=check - RUST_CONFIGURE_ARGS=--build=x86_64-apple-darwin + RUST_CONFIGURE_ARGS="--build=x86_64-apple-darwin --enable-sanitizers" SRC=. RUSTC_RETRY_LINKER_ON_SEGFAULT=1 SCCACHE_ERROR_LOG=/tmp/sccache.log @@ -98,7 +98,7 @@ matrix: install: *osx_install_sccache - env: > RUST_CHECK_TARGET=dist - RUST_CONFIGURE_ARGS="--target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-extended" + RUST_CONFIGURE_ARGS="--target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-extended --enable-sanitizers" SRC=. DEPLOY=1 RUSTC_RETRY_LINKER_ON_SEGFAULT=1 diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index cd87b27d4f1aa..a3d440ecdceab 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -115,6 +115,10 @@ pub fn std_link(build: &Build, if target.contains("musl") && !target.contains("mips") { copy_musl_third_party_objects(build, target, &libdir); } + + if build.config.sanitizers && target == "x86_64-apple-darwin" { + copy_apple_sanitizer_dylibs(&build.native_dir(target), "osx", &libdir); + } } /// Copies the crt(1,i,n).o startup objects @@ -126,6 +130,18 @@ fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) { } } +fn copy_apple_sanitizer_dylibs(native_dir: &Path, platform: &str, into: &Path) { + for &sanitizer in &["asan", "tsan"] { + let filename = format!("libclang_rt.{}_{}_dynamic.dylib", sanitizer, platform); + let mut src_path = native_dir.join(sanitizer); + src_path.push("build"); + src_path.push("lib"); + src_path.push("darwin"); + src_path.push(&filename); + copy(&src_path, &into.join(filename)); + } +} + /// Build and prepare startup objects like rsbegin.o and rsend.o /// /// These are primarily used on Windows right now for linking executables/dlls. diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index cb58a916fb797..da00b970da977 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -198,7 +198,11 @@ pub fn native_lib_boilerplate(src_name: &str, let out_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap()); let out_dir = PathBuf::from(out_dir).join(out_name); t!(create_dir_racy(&out_dir)); - println!("cargo:rustc-link-lib=static={}", link_name); + if link_name.contains('=') { + println!("cargo:rustc-link-lib={}", link_name); + } else { + println!("cargo:rustc-link-lib=static={}", link_name); + } println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display()); let timestamp = out_dir.join("rustbuild.timestamp"); @@ -209,6 +213,21 @@ pub fn native_lib_boilerplate(src_name: &str, } } +pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result { + let (link_name, search_path) = match &*env::var("TARGET").unwrap() { + "x86_64-unknown-linux-gnu" => ( + format!("clang_rt.{}-x86_64", sanitizer_name), + "build/lib/linux", + ), + "x86_64-apple-darwin" => ( + format!("dylib=clang_rt.{}_osx_dynamic", sanitizer_name), + "build/lib/darwin", + ), + _ => return Err(()), + }; + native_lib_boilerplate("compiler-rt", sanitizer_name, &link_name, search_path) +} + fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool { t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| { let meta = t!(e.metadata()); diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index fadb1844008c0..462fd57cbf17f 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -51,7 +51,7 @@ pub struct Config { pub uint_type: UintTy, } -#[derive(Clone, Hash)] +#[derive(Clone, Hash, Debug)] pub enum Sanitizer { Address, Leak, diff --git a/src/librustc_asan/build.rs b/src/librustc_asan/build.rs index 2df2e001e6ff2..3a80baa0485f5 100644 --- a/src/librustc_asan/build.rs +++ b/src/librustc_asan/build.rs @@ -12,14 +12,13 @@ extern crate build_helper; extern crate cmake; use std::env; -use build_helper::native_lib_boilerplate; +use build_helper::sanitizer_lib_boilerplate; use cmake::Config; fn main() { if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { - let native = match native_lib_boilerplate("compiler-rt", "asan", "clang_rt.asan-x86_64", - "build/lib/linux") { + let native = match sanitizer_lib_boilerplate("asan") { Ok(native) => native, _ => return, }; diff --git a/src/librustc_lsan/build.rs b/src/librustc_lsan/build.rs index 005163f41026c..da53571a24390 100644 --- a/src/librustc_lsan/build.rs +++ b/src/librustc_lsan/build.rs @@ -12,14 +12,13 @@ extern crate build_helper; extern crate cmake; use std::env; -use build_helper::native_lib_boilerplate; +use build_helper::sanitizer_lib_boilerplate; use cmake::Config; fn main() { if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { - let native = match native_lib_boilerplate("compiler-rt", "lsan", "clang_rt.lsan-x86_64", - "build/lib/linux") { + let native = match sanitizer_lib_boilerplate("lsan") { Ok(native) => native, _ => return, }; diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index a8ee999505e20..08cb0bdfc2d20 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -798,11 +798,26 @@ impl<'a> CrateLoader<'a> { fn inject_sanitizer_runtime(&mut self) { if let Some(ref sanitizer) = self.sess.opts.debugging_opts.sanitizer { - // Sanitizers can only be used with x86_64 Linux executables linked - // to `std` - if self.sess.target.target.llvm_target != "x86_64-unknown-linux-gnu" { - self.sess.err(&format!("Sanitizers only work with the \ - `x86_64-unknown-linux-gnu` target.")); + // Sanitizers can only be used on some tested platforms with + // executables linked to `std` + const ASAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", + "x86_64-apple-darwin"]; + const TSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", + "x86_64-apple-darwin"]; + const LSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; + const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; + + let supported_targets = match *sanitizer { + Sanitizer::Address => ASAN_SUPPORTED_TARGETS, + Sanitizer::Thread => TSAN_SUPPORTED_TARGETS, + Sanitizer::Leak => LSAN_SUPPORTED_TARGETS, + Sanitizer::Memory => MSAN_SUPPORTED_TARGETS, + }; + if !supported_targets.contains(&&*self.sess.target.target.llvm_target) { + self.sess.err(&format!("{:?}Sanitizer only works with the `{}` target", + sanitizer, + supported_targets.join("` or `") + )); return } diff --git a/src/librustc_msan/build.rs b/src/librustc_msan/build.rs index c438b5250463b..dcadbe86966e7 100644 --- a/src/librustc_msan/build.rs +++ b/src/librustc_msan/build.rs @@ -12,14 +12,13 @@ extern crate build_helper; extern crate cmake; use std::env; -use build_helper::native_lib_boilerplate; +use build_helper::sanitizer_lib_boilerplate; use cmake::Config; fn main() { if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { - let native = match native_lib_boilerplate("compiler-rt", "msan", "clang_rt.msan-x86_64", - "build/lib/linux") { + let native = match sanitizer_lib_boilerplate("msan") { Ok(native) => native, _ => return, }; diff --git a/src/librustc_tsan/build.rs b/src/librustc_tsan/build.rs index 055b344d2e947..5ea52f17a0fde 100644 --- a/src/librustc_tsan/build.rs +++ b/src/librustc_tsan/build.rs @@ -12,14 +12,13 @@ extern crate build_helper; extern crate cmake; use std::env; -use build_helper::native_lib_boilerplate; +use build_helper::sanitizer_lib_boilerplate; use cmake::Config; fn main() { if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { - let native = match native_lib_boilerplate("compiler-rt", "tsan", "clang_rt.tsan-x86_64", - "build/lib/linux") { + let native = match sanitizer_lib_boilerplate("tsan") { Ok(native) => native, _ => return, }; diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 46511452a7237..717892be2abad 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -23,6 +23,10 @@ compiler_builtins = { path = "../libcompiler_builtins" } std_unicode = { path = "../libstd_unicode" } unwind = { path = "../libunwind" } +[target.x86_64-apple-darwin.dependencies] +rustc_asan = { path = "../librustc_asan" } +rustc_tsan = { path = "../librustc_tsan" } + [target.x86_64-unknown-linux-gnu.dependencies] rustc_asan = { path = "../librustc_asan" } rustc_lsan = { path = "../librustc_lsan" } diff --git a/src/test/run-make/sanitizer-address/Makefile b/src/test/run-make/sanitizer-address/Makefile index 5931145f3a47d..61b25df1451b3 100644 --- a/src/test/run-make/sanitizer-address/Makefile +++ b/src/test/run-make/sanitizer-address/Makefile @@ -1,11 +1,19 @@ -include ../tools.mk -# NOTE the address sanitizer only supports x86_64 linux -ifdef SANITIZER_SUPPORT -all: - $(RUSTC) -g -Z sanitizer=address -Z print-link-args overflow.rs | grep -q librustc_asan - $(TMPDIR)/overflow 2>&1 | grep -q stack-buffer-overflow +# NOTE the address sanitizer only supports x86_64 linux and macOS + +ifeq ($(TARGET),x86_64-apple-darwin) +ASAN_SUPPORT=$(SANITIZER_SUPPORT) +EXTRA_RUSTFLAG=-C rpath else -all: +ifeq ($(TARGET),x86_64-unknown-linux-gnu) +ASAN_SUPPORT=$(SANITIZER_SUPPORT) +EXTRA_RUSTFLAG= +endif +endif +all: +ifeq ($(ASAN_SUPPORT),1) + $(RUSTC) -g -Z sanitizer=address -Z print-link-args $(EXTRA_RUSTFLAG) overflow.rs | grep -q librustc_asan + $(TMPDIR)/overflow 2>&1 | grep -q stack-buffer-overflow endif diff --git a/src/test/run-make/sanitizer-invalid-target/Makefile b/src/test/run-make/sanitizer-invalid-target/Makefile index 6a1ce8bab2fb6..82e32f0995202 100644 --- a/src/test/run-make/sanitizer-invalid-target/Makefile +++ b/src/test/run-make/sanitizer-invalid-target/Makefile @@ -1,4 +1,4 @@ -include ../tools.mk all: - $(RUSTC) -Z sanitizer=leak --target i686-unknown-linux-gnu hello.rs 2>&1 | grep -q 'Sanitizers only work with the `x86_64-unknown-linux-gnu` target' + $(RUSTC) -Z sanitizer=leak --target i686-unknown-linux-gnu hello.rs 2>&1 | grep -q 'LeakSanitizer only works with the `x86_64-unknown-linux-gnu` target' diff --git a/src/test/run-make/sanitizer-leak/Makefile b/src/test/run-make/sanitizer-leak/Makefile index f02d948fdc84f..b18dd1d45eda4 100644 --- a/src/test/run-make/sanitizer-leak/Makefile +++ b/src/test/run-make/sanitizer-leak/Makefile @@ -1,10 +1,10 @@ -include ../tools.mk -ifdef SANITIZER_SUPPORT all: +ifeq ($(TARGET),x86_64-unknown-linux-gnu) +ifdef SANITIZER_SUPPORT $(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | grep -q librustc_lsan $(TMPDIR)/leak 2>&1 | grep -q 'detected memory leaks' -else -all: - endif +endif + diff --git a/src/test/run-make/sanitizer-memory/Makefile b/src/test/run-make/sanitizer-memory/Makefile index 08682e5975e51..7502ef0e7a7b7 100644 --- a/src/test/run-make/sanitizer-memory/Makefile +++ b/src/test/run-make/sanitizer-memory/Makefile @@ -1,10 +1,10 @@ -include ../tools.mk -ifdef SANITIZER_SUPPORT all: +ifeq ($(TARGET),x86_64-unknown-linux-gnu) +ifdef SANITIZER_SUPPORT $(RUSTC) -g -Z sanitizer=memory -Z print-link-args uninit.rs | grep -q librustc_msan $(TMPDIR)/uninit 2>&1 | grep -q use-of-uninitialized-value -else -all: - endif +endif + From b455737e6702a1c8d237dbebfc97aea02432110c Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 20 Apr 2017 08:31:43 +0800 Subject: [PATCH 04/16] Force link with an absolute rpath when using sanitizer on macOS. --- src/librustc_trans/back/link.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 7c0522a9c8cf8..e42e69d2a76e2 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -1122,6 +1122,19 @@ fn add_upstream_rust_crates(cmd: &mut Linker, cnum: CrateNum) { let src = sess.cstore.used_crate_source(cnum); let cratepath = &src.rlib.unwrap().0; + + if sess.target.target.options.is_like_osx { + // On Apple platforms, the sanitizer is always built as a dylib, and + // LLVM will link to `@rpath/*.dylib`, so we need to specify an + // rpath to the library as well (the rpath should be absolute, see + // PR #41352 for details). + // + // FIXME: Remove this logic into librustc_*san once Cargo supports it + let rpath = cratepath.parent().unwrap(); + let rpath = rpath.to_str().expect("non-utf8 component in path"); + cmd.args(&["-Wl,-rpath".into(), "-Xlinker".into(), rpath.into()]); + } + let dst = tmpdir.join(cratepath.file_name().unwrap()); let cfg = archive_config(sess, &dst, Some(cratepath)); let mut archive = ArchiveBuilder::new(cfg); From d7efbec962b574cdea760be62ea8bb0fcae9d702 Mon Sep 17 00:00:00 2001 From: projektir Date: Thu, 20 Apr 2017 23:53:38 -0400 Subject: [PATCH 05/16] Adding links and examples for various mspc pages #29377 --- src/libstd/sync/mpsc/mod.rs | 283 ++++++++++++++++++++++++++++++++---- 1 file changed, 254 insertions(+), 29 deletions(-) diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 852675edc0238..757fe511a3f6f 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -297,12 +297,14 @@ mod sync; mod mpsc_queue; mod spsc_queue; -/// The receiving-half of Rust's channel type. This half can only be owned by -/// one thread. +/// The receiving half of Rust's [`channel`] (or [`sync_channel`]) type. +/// This half can only be owned by one thread. /// /// Messages sent to the channel can be retrieved using [`recv`]. /// -/// [`recv`]: ../../../std/sync/mpsc/struct.Receiver.html#method.recv +/// [`channel`]: fn.channel.html +/// [`sync_channel`]: fn.sync_channel.html +/// [`recv`]: struct.Receiver.html#method.recv /// /// # Examples /// @@ -336,51 +338,128 @@ unsafe impl Send for Receiver { } #[stable(feature = "rust1", since = "1.0.0")] impl !Sync for Receiver { } -/// An iterator over messages on a receiver, this iterator will block whenever -/// [`next`] is called, waiting for a new message, and [`None`] will be returned +/// An iterator over messages on a [`Receiver`], created by [`iter`]. +/// +/// This iterator will block whenever [`next`] is called, +/// waiting for a new message, and [`None`] will be returned /// when the corresponding channel has hung up. /// +/// [`iter`]: struct.Receiver.html#method.iter +/// [`Receiver`]: struct.Receiver.html /// [`next`]: ../../../std/iter/trait.Iterator.html#tymethod.next /// [`None`]: ../../../std/option/enum.Option.html#variant.None +/// +/// # Examples +/// +/// ```rust +/// use std::sync::mpsc::channel; +/// use std::thread; +/// +/// let (send, recv) = channel(); +/// +/// thread::spawn(move || { +/// send.send(1u8).unwrap(); +/// send.send(2u8).unwrap(); +/// send.send(3u8).unwrap(); +/// }); +/// +/// for x in recv.iter() { +/// println!("Got: {}", x); +/// } +/// ``` #[stable(feature = "rust1", since = "1.0.0")] #[derive(Debug)] pub struct Iter<'a, T: 'a> { rx: &'a Receiver } -/// An iterator that attempts to yield all pending values for a receiver. -/// [`None`] will be returned when there are no pending values remaining or if -/// the corresponding channel has hung up. +/// An iterator that attempts to yield all pending values for a [`Receiver`], +/// created by [`try_iter`]. +/// +/// [`None`] will be returned when there are no pending values remaining or +/// if the corresponding channel has hung up. /// -/// This Iterator will never block the caller in order to wait for data to +/// This iterator will never block the caller in order to wait for data to /// become available. Instead, it will return [`None`]. /// +/// [`Receiver`]: struct.Receiver.html +/// [`try_iter`]: struct.Receiver.html#method.try_iter /// [`None`]: ../../../std/option/enum.Option.html#variant.None +/// +/// # Examples +/// +/// ```rust +/// use std::sync::mpsc::channel; +/// use std::thread; +/// use std::time::Duration; +/// +/// let (sender, receiver) = channel(); +/// +/// // Nothing is in the buffer yet +/// assert!(receiver.try_iter().next().is_none()); +/// println!("Nothing in the buffer..."); +/// +/// thread::spawn(move || { +/// sender.send(1).unwrap(); +/// sender.send(2).unwrap(); +/// sender.send(3).unwrap(); +/// }); +/// +/// println!("Going to sleep..."); +/// thread::sleep(Duration::from_secs(2)); // block for two seconds +/// +/// for x in receiver.try_iter() { +/// println!("Got: {}", x); +/// } +/// ``` #[stable(feature = "receiver_try_iter", since = "1.15.0")] #[derive(Debug)] pub struct TryIter<'a, T: 'a> { rx: &'a Receiver } -/// An owning iterator over messages on a receiver, this iterator will block -/// whenever [`next`] is called, waiting for a new message, and [`None`] will be -/// returned when the corresponding channel has hung up. +/// An owning iterator over messages on a [`Receiver`], +/// created by **Receiver::into_iter**. +/// +/// This iterator will block whenever [`next`] +/// is called, waiting for a new message, and [`None`] will be +/// returned if the corresponding channel has hung up. /// +/// [`Receiver`]: struct.Receiver.html /// [`next`]: ../../../std/iter/trait.Iterator.html#tymethod.next /// [`None`]: ../../../std/option/enum.Option.html#variant.None /// +/// # Examples +/// +/// ```rust +/// use std::sync::mpsc::channel; +/// use std::thread; +/// +/// let (send, recv) = channel(); +/// +/// thread::spawn(move || { +/// send.send(1u8).unwrap(); +/// send.send(2u8).unwrap(); +/// send.send(3u8).unwrap(); +/// }); +/// +/// for x in recv.into_iter() { +/// println!("Got: {}", x); +/// } +/// ``` #[stable(feature = "receiver_into_iter", since = "1.1.0")] #[derive(Debug)] pub struct IntoIter { rx: Receiver } -/// The sending-half of Rust's asynchronous channel type. This half can only be +/// The sending-half of Rust's asynchronous [`channel`] type. This half can only be /// owned by one thread, but it can be cloned to send to other threads. /// /// Messages can be sent through this channel with [`send`]. /// -/// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send +/// [`channel`]: fn.channel.html +/// [`send`]: struct.Sender.html#method.send /// /// # Examples /// @@ -419,12 +498,55 @@ unsafe impl Send for Sender { } #[stable(feature = "rust1", since = "1.0.0")] impl !Sync for Sender { } -/// The sending-half of Rust's synchronous channel type. This half can only be -/// owned by one thread, but it can be cloned to send to other threads. +/// The sending-half of Rust's synchronous [`sync_channel`] type. +/// This half can only be owned by one thread, but it can be cloned +/// to send to other threads. +/// +/// Messages can be sent through this channel with [`send`] or [`try_send`]. +/// +/// [`send`] will block if there is no space in the internal buffer. +/// +/// [`sync_channel`]: fn.sync_channel.html +/// [`send`]: struct.SyncSender.html#method.send +/// [`try_send`]: struct.SyncSender.html#method.try_send +/// +/// # Examples +/// +/// ```rust +/// use std::sync::mpsc::sync_channel; +/// use std::thread; /// -/// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send -/// [`SyncSender::send`]: ../../../std/sync/mpsc/struct.SyncSender.html#method.send +/// // Create a sync_channel with buffer size 2 +/// let (sync_sender, receiver) = sync_channel(2); +/// let sync_sender2 = sync_sender.clone(); /// +/// // First thread owns sync_sender +/// thread::spawn(move || { +/// sync_sender.send(1).unwrap(); +/// sync_sender.send(2).unwrap(); +/// }); +/// +/// // Second thread owns sync_sender2 +/// thread::spawn(move || { +/// sync_sender2.send(3).unwrap(); +/// // thread will now block since the buffer is full +/// println!("Thread unblocked!"); +/// }); +/// +/// let mut msg; +/// +/// msg = receiver.recv().unwrap(); +/// println!("message {} received", msg); +/// +/// // "Thread unblocked!" will be printed now +/// +/// msg = receiver.recv().unwrap(); +/// println!("message {} received", msg); +/// +/// msg = receiver.recv().unwrap(); +/// +/// println!("message {} received", msg); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct SyncSender { inner: Arc>, @@ -823,8 +945,9 @@ impl SyncSender { /// Note that a successful send does *not* guarantee that the receiver will /// ever see the data if there is a buffer on this channel. Items may be /// enqueued in the internal buffer for the receiver to receive at a later - /// time. If the buffer size is 0, however, it can be guaranteed that the - /// receiver has indeed received the data if this function returns success. + /// time. If the buffer size is 0, however, the channel becomes a rendezvous + /// channel and it guarantees that the receiver has indeed received + /// the data if this function returns success. /// /// This function will never panic, but it may return [`Err`] if the /// [`Receiver`] has disconnected and is no longer able to receive @@ -832,6 +955,27 @@ impl SyncSender { /// /// [`Err`]: ../../../std/result/enum.Result.html#variant.Err /// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html + /// + /// # Examples + /// + /// ```rust + /// use std::sync::mpsc::sync_channel; + /// use std::thread; + /// + /// // Create a rendezvous sync_channel with buffer size 0 + /// let (sync_sender, receiver) = sync_channel(0); + /// + /// thread::spawn(move || { + /// println!("sending message..."); + /// sync_sender.send(1).unwrap(); + /// // Thread is now blocked until the message is received + /// + /// println!("...message received!"); + /// }); + /// + /// let msg = receiver.recv().unwrap(); + /// assert_eq!(1, msg); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn send(&self, t: T) -> Result<(), SendError> { self.inner.send(t).map_err(SendError) @@ -844,11 +988,48 @@ impl SyncSender { /// data. Compared with [`send`], this function has two failure cases /// instead of one (one for disconnection, one for a full buffer). /// - /// See [`SyncSender::send`] for notes about guarantees of whether the + /// See [`send`] for notes about guarantees of whether the /// receiver has received the data or not if this function is successful. /// - /// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send - /// [`SyncSender::send`]: ../../../std/sync/mpsc/struct.SyncSender.html#method.send + /// [`send`]: ../../../std/sync/mpsc/struct.SyncSender.html#method.send + /// + /// # Examples + /// + /// ```rust + /// use std::sync::mpsc::sync_channel; + /// use std::thread; + /// + /// // Create a sync_channel with buffer size 1 + /// let (sync_sender, receiver) = sync_channel(1); + /// let sync_sender2 = sync_sender.clone(); + /// + /// // First thread owns sync_sender + /// thread::spawn(move || { + /// sync_sender.send(1).unwrap(); + /// sync_sender.send(2).unwrap(); + /// // Thread blocked + /// }); + /// + /// // Second thread owns sync_sender2 + /// thread::spawn(move || { + /// // This will return an error and send + /// // no message if the buffer is full + /// sync_sender2.try_send(3).is_err(); + /// }); + /// + /// let mut msg; + /// msg = receiver.recv().unwrap(); + /// println!("message {} received", msg); + /// + /// msg = receiver.recv().unwrap(); + /// println!("message {} received", msg); + /// + /// // Third message may have never been sent + /// match receiver.try_recv() { + /// Ok(msg) => println!("message {} received", msg), + /// Err(_) => println!("the third message was never sent"), + /// } + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn try_send(&self, t: T) -> Result<(), TrySendError> { self.inner.try_send(t) @@ -894,6 +1075,21 @@ impl Receiver { /// /// This is useful for a flavor of "optimistic check" before deciding to /// block on a receiver. + /// + /// Compared with [`recv`], this function has two failure cases instead of one + /// (one for disconnection, one for an empty buffer). + /// + /// [`recv`]: struct.Receiver.html#method.recv + /// + /// # Examples + /// + /// ```rust + /// use std::sync::mpsc::{Receiver, channel}; + /// + /// let (_, receiver): (_, Receiver) = channel(); + /// + /// assert!(receiver.try_recv().is_err()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn try_recv(&self) -> Result { loop { @@ -949,8 +1145,8 @@ impl Receiver { /// /// This function will always block the current thread if there is no data /// available and it's possible for more data to be sent. Once a message is - /// sent to the corresponding [`Sender`], then this receiver will wake up and - /// return that message. + /// sent to the corresponding [`Sender`] (or [`SyncSender`]), then this + /// receiver will wake up and return that message. /// /// If the corresponding [`Sender`] has disconnected, or it disconnects while /// this call is blocking, this call will wake up and return [`Err`] to @@ -958,7 +1154,8 @@ impl Receiver { /// However, since channels are buffered, messages sent before the disconnect /// will still be properly received. /// - /// [`Sender`]: ../../../std/sync/mpsc/struct.Sender.html + /// [`Sender`]: struct.Sender.html + /// [`SyncSender`]: struct.SyncSender.html /// [`Err`]: ../../../std/result/enum.Result.html#variant.Err /// /// # Examples @@ -1040,8 +1237,8 @@ impl Receiver { /// /// This function will always block the current thread if there is no data /// available and it's possible for more data to be sent. Once a message is - /// sent to the corresponding [`Sender`], then this receiver will wake up and - /// return that message. + /// sent to the corresponding [`Sender`] (or [`SyncSender`]), then this + /// receiver will wake up and return that message. /// /// If the corresponding [`Sender`] has disconnected, or it disconnects while /// this call is blocking, this call will wake up and return [`Err`] to @@ -1049,7 +1246,8 @@ impl Receiver { /// However, since channels are buffered, messages sent before the disconnect /// will still be properly received. /// - /// [`Sender`]: ../../../std/sync/mpsc/struct.Sender.html + /// [`Sender`]: struct.Sender.html + /// [`SyncSender`]: struct.SyncSender.html /// [`Err`]: ../../../std/result/enum.Result.html#variant.Err /// /// # Examples @@ -1163,6 +1361,33 @@ impl Receiver { /// user by waiting for values. /// /// [`panic!`]: ../../../std/macro.panic.html + /// + /// # Examples + /// + /// ```rust + /// use std::sync::mpsc::channel; + /// use std::thread; + /// use std::time::Duration; + /// + /// let (sender, receiver) = channel(); + /// + /// // Nothing is in the buffer yet + /// assert!(receiver.try_iter().next().is_none()); + /// println!("Nothing in the buffer..."); + /// + /// thread::spawn(move || { + /// sender.send(1).unwrap(); + /// sender.send(2).unwrap(); + /// sender.send(3).unwrap(); + /// }); + /// + /// println!("Going to sleep..."); + /// thread::sleep(Duration::from_secs(2)); // block for two seconds + /// + /// for x in receiver.try_iter() { + /// println!("Got: {}", x); + /// } + /// ``` #[stable(feature = "receiver_try_iter", since = "1.15.0")] pub fn try_iter(&self) -> TryIter { TryIter { rx: self } From 2111aff682ee4ced9dca27defb4643cc78ab8762 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 8 Apr 2017 15:55:53 -0500 Subject: [PATCH 06/16] Add Vec::splice and String::splice --- src/libcollections/slice.rs | 6 +- src/libcollections/string.rs | 130 ++++++++++++++++++++++- src/libcollections/tests/lib.rs | 1 + src/libcollections/tests/string.rs | 8 ++ src/libcollections/tests/vec.rs | 10 ++ src/libcollections/vec.rs | 165 ++++++++++++++++++++++++++++- 6 files changed, 313 insertions(+), 7 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 7c3c825cfd1f5..2eef132374e58 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1519,13 +1519,9 @@ impl ToOwned for [T] { self.to_vec() } - // HACK(japaric): with cfg(test) the inherent `[T]::to_vec`, which is required for this method - // definition, is not available. Since we don't require this method for testing purposes, I'll - // just stub it - // NB see the slice::hack module in slice.rs for more information #[cfg(test)] fn to_owned(&self) -> Vec { - panic!("not available with cfg(test)") + hack::to_vec(self) } fn clone_into(&self, target: &mut Vec) { diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 8d6cf30511260..8090bc1996e41 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1316,7 +1316,7 @@ impl String { self.vec.clear() } - /// Create a draining iterator that removes the specified range in the string + /// Creates a draining iterator that removes the specified range in the string /// and yields the removed chars. /// /// Note: The element range is removed even if the iterator is not @@ -1382,6 +1382,63 @@ impl String { } } + /// Creates a splicing iterator that removes the specified range in the string, + /// replaces with the given string, and yields the removed chars. + /// The given string doesn’t need to be the same length as the range. + /// + /// Note: The element range is removed even if the iterator is not + /// consumed until the end. + /// + /// # Panics + /// + /// Panics if the starting point or end point do not lie on a [`char`] + /// boundary, or if they're out of bounds. + /// + /// [`char`]: ../../std/primitive.char.html + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(splice)] + /// let mut s = String::from("α is alpha, β is beta"); + /// let beta_offset = s.find('β').unwrap_or(s.len()); + /// + /// // Replace the range up until the β from the string + /// let t: String = s.splice(..beta_offset, "Α is capital alpha; ").collect(); + /// assert_eq!(t, "α is alpha, "); + /// assert_eq!(s, "Α is capital alpha; β is beta"); + /// ``` + #[unstable(feature = "splice", reason = "recently added", issue = "32310")] + pub fn splice<'a, 'b, R>(&'a mut self, range: R, replace_with: &'b str) -> Splice<'a, 'b> + where R: RangeArgument + { + // Memory safety + // + // The String version of Splice does not have the memory safety issues + // of the vector version. The data is just plain bytes. + // Because the range removal happens in Drop, if the Splice iterator is leaked, + // the removal will not happen. + let len = self.len(); + let start = *range.start().unwrap_or(&0); + let end = *range.end().unwrap_or(&len); + + // Take out two simultaneous borrows. The &mut String won't be accessed + // until iteration is over, in Drop. + let self_ptr = self as *mut _; + // slicing does the appropriate bounds checks + let chars_iter = self[start..end].chars(); + + Splice { + start: start, + end: end, + iter: chars_iter, + string: self_ptr, + replace_with: replace_with + } + } + /// Converts this `String` into a `Box`. /// /// This will drop any excess capacity. @@ -2145,3 +2202,74 @@ impl<'a> DoubleEndedIterator for Drain<'a> { #[unstable(feature = "fused", issue = "35602")] impl<'a> FusedIterator for Drain<'a> {} + +/// A splicing iterator for `String`. +/// +/// This struct is created by the [`splice()`] method on [`String`]. See its +/// documentation for more. +/// +/// [`splice()`]: struct.String.html#method.splice +/// [`String`]: struct.String.html +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +pub struct Splice<'a, 'b> { + /// Will be used as &'a mut String in the destructor + string: *mut String, + /// Start of part to remove + start: usize, + /// End of part to remove + end: usize, + /// Current remaining range to remove + iter: Chars<'a>, + replace_with: &'b str, +} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +unsafe impl<'a, 'b> Sync for Splice<'a, 'b> {} +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +unsafe impl<'a, 'b> Send for Splice<'a, 'b> {} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, 'b> Drop for Splice<'a, 'b> { + fn drop(&mut self) { + unsafe { + let vec = (*self.string).as_mut_vec(); + let range_len = self.end - self.start; + let replacement_len = self.replace_with.len(); + let tail_len = vec.len() - self.end; + if replacement_len > range_len { + vec.reserve(replacement_len - range_len); + } + if replacement_len != range_len { + let src = vec.as_ptr().offset(self.end as isize); + let dst = vec.as_mut_ptr().offset((self.start + replacement_len) as isize); + ptr::copy(src, dst, tail_len); + } + let src = self.replace_with.as_ptr(); + let dst = vec.as_mut_ptr().offset(self.start as isize); + ptr::copy(src, dst, replacement_len); + vec.set_len(self.start + replacement_len + tail_len); + } + } +} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, 'b> Iterator for Splice<'a, 'b> { + type Item = char; + + #[inline] + fn next(&mut self) -> Option { + self.iter.next() + } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } +} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, 'b> DoubleEndedIterator for Splice<'a, 'b> { + #[inline] + fn next_back(&mut self) -> Option { + self.iter.next_back() + } +} diff --git a/src/libcollections/tests/lib.rs b/src/libcollections/tests/lib.rs index 9c6e31d70a541..eae3bf3915f60 100644 --- a/src/libcollections/tests/lib.rs +++ b/src/libcollections/tests/lib.rs @@ -20,6 +20,7 @@ #![feature(pattern)] #![feature(placement_in_syntax)] #![feature(rand)] +#![feature(splice)] #![feature(step_by)] #![feature(str_escape)] #![feature(test)] diff --git a/src/libcollections/tests/string.rs b/src/libcollections/tests/string.rs index 2f021b9935d6a..faaa9a1830b07 100644 --- a/src/libcollections/tests/string.rs +++ b/src/libcollections/tests/string.rs @@ -419,6 +419,14 @@ fn test_drain() { assert_eq!(t, ""); } +#[test] +fn test_splice() { + let mut s = "Hello, world!".to_owned(); + let t: String = s.splice(7..12, "世界").collect(); + assert_eq!(s, "Hello, 世界!"); + assert_eq!(t, "world"); +} + #[test] fn test_extend_ref() { let mut a = "foo".to_string(); diff --git a/src/libcollections/tests/vec.rs b/src/libcollections/tests/vec.rs index 64c76142b59d6..e3453c70abaf2 100644 --- a/src/libcollections/tests/vec.rs +++ b/src/libcollections/tests/vec.rs @@ -579,6 +579,16 @@ fn test_drain_inclusive_out_of_bounds() { v.drain(5...5); } +#[test] +fn splice() { + let mut v = vec![1, 2, 3, 4, 5]; + let a = [10, 11, 12]; + v.splice(2..4, a.iter().cloned()); + assert_eq!(v, &[1, 2, 10, 11, 12, 5]); + v.splice(1..3, Some(20)); + assert_eq!(v, &[1, 20, 11, 12, 5]); +} + #[test] fn test_into_boxed_slice() { let xs = vec![1, 2, 3]; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 6deb87ae77204..bbb067ca4e3b6 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1057,7 +1057,7 @@ impl Vec { self.len += count; } - /// Create a draining iterator that removes the specified range in the vector + /// Creates a draining iterator that removes the specified range in the vector /// and yields the removed items. /// /// Note 1: The element range is removed even if the iterator is only @@ -1845,6 +1845,54 @@ impl Vec { } } } + + /// Creates a splicing iterator that replaces the specified range in the vector + /// with the given `replace_with` iterator and yields the removed items. + /// `replace_with` does not need to be the same length as `range`. + /// + /// Note 1: The element range is removed even if the iterator is not + /// consumed until the end. + /// + /// Note 2: It is unspecified how many elements are removed from the vector, + /// if the `Splice` value is leaked. + /// + /// Note 3: The input iterator `replace_with` is only consumed + /// when the `Splice` value is dropped. + /// + /// Note 4: This is optimal if: + /// + /// * The tail (elements in the vector after `range`) is empty, + /// * or `replace_with` yields fewer elements than `range`’s length + /// * or the lower bound of its `size_hint()` is exact. + /// + /// Otherwise, a temporary vector is allocated and the tail is moved twice. + /// + /// # Panics + /// + /// Panics if the starting point is greater than the end point or if + /// the end point is greater than the length of the vector. + /// + /// # Examples + /// + /// ``` + /// #![feature(splice)] + /// let mut v = vec![1, 2, 3]; + /// let new = [7, 8]; + /// let u: Vec<_> = v.splice(..2, new.iter().cloned()).collect(); + /// assert_eq!(v, &[7, 8, 3]); + /// assert_eq!(u, &[1, 2]); + /// ``` + #[inline] + #[unstable(feature = "splice", reason = "recently added", issue = "32310")] + pub fn splice(&mut self, range: R, replace_with: I) -> Splice + where R: RangeArgument, I: IntoIterator + { + Splice { + drain: self.drain(range), + replace_with: replace_with.into_iter(), + } + } + } #[stable(feature = "extend_ref", since = "1.2.0")] @@ -2344,3 +2392,118 @@ impl<'a, T> InPlace for PlaceBack<'a, T> { &mut *ptr } } + + +/// A splicing iterator for `Vec`. See the [`Vec::splice`](struct.Vec.html#method.splice) method. +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +pub struct Splice<'a, I: Iterator + 'a> { + drain: Drain<'a, I::Item>, + replace_with: I, +} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, I: Iterator> Iterator for Splice<'a, I> { + type Item = I::Item; + + fn next(&mut self) -> Option { + self.drain.next() + } + + fn size_hint(&self) -> (usize, Option) { + self.drain.size_hint() + } +} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, I: Iterator> DoubleEndedIterator for Splice<'a, I> { + fn next_back(&mut self) -> Option { + self.drain.next_back() + } +} + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {} + + +#[unstable(feature = "splice", reason = "recently added", issue = "32310")] +impl<'a, I: Iterator> Drop for Splice<'a, I> { + fn drop(&mut self) { + // exhaust drain first + while let Some(_) = self.drain.next() {} + + + unsafe { + if self.drain.tail_len == 0 { + let vec = &mut *self.drain.vec; + vec.extend(self.replace_with.by_ref()); + return + } + + // First fill the range left by drain(). + if !self.drain.fill(&mut self.replace_with) { + return + } + + // There may be more elements. Use the lower bound as an estimate. + // FIXME: Is the upper bound a better guess? Or something else? + let (lower_bound, _upper_bound) = self.replace_with.size_hint(); + if lower_bound > 0 { + self.drain.move_tail(lower_bound); + if !self.drain.fill(&mut self.replace_with) { + return + } + } + + // Collect any remaining elements. + // This is a zero-length vector which does not allocate if `lower_bound` was exact. + let mut collected = self.replace_with.by_ref().collect::>().into_iter(); + // Now we have an exact count. + if collected.len() > 0 { + self.drain.move_tail(collected.len()); + let filled = self.drain.fill(&mut collected); + debug_assert!(filled); + debug_assert_eq!(collected.len(), 0); + } + } + // Let `Drain::drop` move the tail back if necessary and restore `vec.len`. + } +} + +/// Private helper methods for `Splice::drop` +impl<'a, T> Drain<'a, T> { + /// The range from `self.vec.len` to `self.tail_start` contains elements + /// that have been moved out. + /// Fill that range as much as possible with new elements from the `replace_with` iterator. + /// Return whether we filled the entire range. (`replace_with.next()` didn’t return `None`.) + unsafe fn fill>(&mut self, replace_with: &mut I) -> bool { + let vec = &mut *self.vec; + let range_start = vec.len; + let range_end = self.tail_start; + let range_slice = slice::from_raw_parts_mut( + vec.as_mut_ptr().offset(range_start as isize), + range_end - range_start); + + for place in range_slice { + if let Some(new_item) = replace_with.next() { + ptr::write(place, new_item); + vec.len += 1; + } else { + return false + } + } + true + } + + /// Make room for inserting more elements before the tail. + unsafe fn move_tail(&mut self, extra_capacity: usize) { + let vec = &mut *self.vec; + let used_capacity = self.tail_start + self.tail_len; + vec.buf.reserve(used_capacity, extra_capacity); + + let new_tail_start = self.tail_start + extra_capacity; + let src = vec.as_ptr().offset(self.tail_start as isize); + let dst = vec.as_mut_ptr().offset(new_tail_start as isize); + ptr::copy(src, dst, self.tail_len); + self.tail_start = new_tail_start; + } +} From b85e2e4735fe78fffeecd2fce96d7ce40d22438c Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Sat, 8 Apr 2017 16:12:58 -0500 Subject: [PATCH 07/16] Update splice impl --- src/libcollections/string.rs | 13 +++++++++++-- src/libcollections/vec.rs | 15 +++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 8090bc1996e41..cc4f9b86be4d6 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1421,8 +1421,16 @@ impl String { // Because the range removal happens in Drop, if the Splice iterator is leaked, // the removal will not happen. let len = self.len(); - let start = *range.start().unwrap_or(&0); - let end = *range.end().unwrap_or(&len); + let start = match range.start() { + Included(&n) => n, + Excluded(&n) => n + 1, + Unbounded => 0, + }; + let end = match range.end() { + Included(&n) => n + 1, + Excluded(&n) => n, + Unbounded => len, + }; // Take out two simultaneous borrows. The &mut String won't be accessed // until iteration is over, in Drop. @@ -2210,6 +2218,7 @@ impl<'a> FusedIterator for Drain<'a> {} /// /// [`splice()`]: struct.String.html#method.splice /// [`String`]: struct.String.html +#[derive(Debug)] #[unstable(feature = "splice", reason = "recently added", issue = "32310")] pub struct Splice<'a, 'b> { /// Will be used as &'a mut String in the destructor diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index bbb067ca4e3b6..dc330d4b2590b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2394,7 +2394,14 @@ impl<'a, T> InPlace for PlaceBack<'a, T> { } -/// A splicing iterator for `Vec`. See the [`Vec::splice`](struct.Vec.html#method.splice) method. +/// A splicing iterator for `Vec`. +/// +/// This struct is created by the [`splice()`] method on [`Vec`]. See its +/// documentation for more. +/// +/// [`splice()`]: struct.Vec.html#method.splice +/// [`Vec`]: struct.Vec.html +#[derive(Debug)] #[unstable(feature = "splice", reason = "recently added", issue = "32310")] pub struct Splice<'a, I: Iterator + 'a> { drain: Drain<'a, I::Item>, @@ -2434,7 +2441,7 @@ impl<'a, I: Iterator> Drop for Splice<'a, I> { unsafe { if self.drain.tail_len == 0 { - let vec = &mut *self.drain.vec; + let vec = &mut *self.drain.vec.as_mut_ptr(); vec.extend(self.replace_with.by_ref()); return } @@ -2476,7 +2483,7 @@ impl<'a, T> Drain<'a, T> { /// Fill that range as much as possible with new elements from the `replace_with` iterator. /// Return whether we filled the entire range. (`replace_with.next()` didn’t return `None`.) unsafe fn fill>(&mut self, replace_with: &mut I) -> bool { - let vec = &mut *self.vec; + let vec = &mut *self.vec.as_mut_ptr(); let range_start = vec.len; let range_end = self.tail_start; let range_slice = slice::from_raw_parts_mut( @@ -2496,7 +2503,7 @@ impl<'a, T> Drain<'a, T> { /// Make room for inserting more elements before the tail. unsafe fn move_tail(&mut self, extra_capacity: usize) { - let vec = &mut *self.vec; + let vec = &mut *self.vec.as_mut_ptr(); let used_capacity = self.tail_start + self.tail_len; vec.buf.reserve(used_capacity, extra_capacity); From cec00bab1d5d74e5ad176fea0b2c5aab882f36e7 Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Sat, 8 Apr 2017 16:04:30 -0500 Subject: [PATCH 08/16] Improve splice docs and tests --- src/libcollections/string.rs | 4 +-- src/libcollections/tests/string.rs | 48 ++++++++++++++++++++++++++++++ src/libcollections/tests/vec.rs | 47 ++++++++++++++++++++++++++++- src/libcollections/vec.rs | 2 +- 4 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index cc4f9b86be4d6..e7085e94336ff 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1386,8 +1386,8 @@ impl String { /// replaces with the given string, and yields the removed chars. /// The given string doesn’t need to be the same length as the range. /// - /// Note: The element range is removed even if the iterator is not - /// consumed until the end. + /// Note: The element range is removed when the `Splice` is dropped, + /// even if the iterator is not consumed until the end. /// /// # Panics /// diff --git a/src/libcollections/tests/string.rs b/src/libcollections/tests/string.rs index faaa9a1830b07..a32f5e3357f38 100644 --- a/src/libcollections/tests/string.rs +++ b/src/libcollections/tests/string.rs @@ -427,6 +427,54 @@ fn test_splice() { assert_eq!(t, "world"); } +#[test] +#[should_panic] +fn test_splice_char_boundary() { + let mut s = "Hello, 世界!".to_owned(); + s.splice(..8, ""); +} + +#[test] +fn test_splice_inclusive_range() { + let mut v = String::from("12345"); + let t: String = v.splice(2...3, "789").collect(); + assert_eq!(v, "127895"); + assert_eq!(t, "34"); + let t2: String = v.splice(1...2, "A").collect(); + assert_eq!(v, "1A895"); + assert_eq!(t2, "27"); +} + +#[test] +#[should_panic] +fn test_splice_out_of_bounds() { + let mut s = String::from("12345"); + s.splice(5..6, "789"); +} + +#[test] +#[should_panic] +fn test_splice_inclusive_out_of_bounds() { + let mut s = String::from("12345"); + s.splice(5...5, "789"); +} + +#[test] +fn test_splice_empty() { + let mut s = String::from("12345"); + let t: String = s.splice(1..2, "").collect(); + assert_eq!(s, "1345"); + assert_eq!(t, "2"); +} + +#[test] +fn test_splice_unbounded() { + let mut s = String::from("12345"); + let t: String = s.splice(.., "").collect(); + assert_eq!(s, ""); + assert_eq!(t, "12345"); +} + #[test] fn test_extend_ref() { let mut a = "foo".to_string(); diff --git a/src/libcollections/tests/vec.rs b/src/libcollections/tests/vec.rs index e3453c70abaf2..f47940dc33aa1 100644 --- a/src/libcollections/tests/vec.rs +++ b/src/libcollections/tests/vec.rs @@ -580,7 +580,7 @@ fn test_drain_inclusive_out_of_bounds() { } #[test] -fn splice() { +fn test_splice() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; v.splice(2..4, a.iter().cloned()); @@ -589,6 +589,51 @@ fn splice() { assert_eq!(v, &[1, 20, 11, 12, 5]); } +#[test] +fn test_splice_inclusive_range() { + let mut v = vec![1, 2, 3, 4, 5]; + let a = [10, 11, 12]; + let t1: Vec<_> = v.splice(2...3, a.iter().cloned()).collect(); + assert_eq!(v, &[1, 2, 10, 11, 12, 5]); + assert_eq!(t1, &[3, 4]); + let t2: Vec<_> = v.splice(1...2, Some(20)).collect(); + assert_eq!(v, &[1, 20, 11, 12, 5]); + assert_eq!(t2, &[2, 10]); +} + +#[test] +#[should_panic] +fn test_splice_out_of_bounds() { + let mut v = vec![1, 2, 3, 4, 5]; + let a = [10, 11, 12]; + v.splice(5..6, a.iter().cloned()); +} + +#[test] +#[should_panic] +fn test_splice_inclusive_out_of_bounds() { + let mut v = vec![1, 2, 3, 4, 5]; + let a = [10, 11, 12]; + v.splice(5...5, a.iter().cloned()); +} + +#[test] +fn test_splice_items_zero_sized() { + let mut vec = vec![(), (), ()]; + let vec2 = vec![]; + let t: Vec<_> = vec.splice(1..2, vec2.iter().cloned()).collect(); + assert_eq!(vec, &[(), ()]); + assert_eq!(t, &[()]); +} + +#[test] +fn test_splice_unbounded() { + let mut vec = vec![1, 2, 3, 4, 5]; + let t: Vec<_> = vec.splice(.., None).collect(); + assert_eq!(vec, &[]); + assert_eq!(t, &[1, 2, 3, 4, 5]); +} + #[test] fn test_into_boxed_slice() { let xs = vec![1, 2, 3]; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index dc330d4b2590b..e5964385b1253 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1063,7 +1063,7 @@ impl Vec { /// Note 1: The element range is removed even if the iterator is only /// partially consumed or not consumed at all. /// - /// Note 2: It is unspecified how many elements are removed from the vector, + /// Note 2: It is unspecified how many elements are removed from the vector /// if the `Drain` value is leaked. /// /// # Panics From c3baa8c0a7c0f90c3630c5eacc8f8783505c90ec Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Sat, 8 Apr 2017 16:43:30 -0500 Subject: [PATCH 09/16] Use Vec::splice impl in string::Splice::drop() --- src/libcollections/string.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index e7085e94336ff..0a82fda09cb84 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -2242,21 +2242,7 @@ impl<'a, 'b> Drop for Splice<'a, 'b> { fn drop(&mut self) { unsafe { let vec = (*self.string).as_mut_vec(); - let range_len = self.end - self.start; - let replacement_len = self.replace_with.len(); - let tail_len = vec.len() - self.end; - if replacement_len > range_len { - vec.reserve(replacement_len - range_len); - } - if replacement_len != range_len { - let src = vec.as_ptr().offset(self.end as isize); - let dst = vec.as_mut_ptr().offset((self.start + replacement_len) as isize); - ptr::copy(src, dst, tail_len); - } - let src = self.replace_with.as_ptr(); - let dst = vec.as_mut_ptr().offset(self.start as isize); - ptr::copy(src, dst, replacement_len); - vec.set_len(self.start + replacement_len + tail_len); + vec.splice(self.start..self.end, self.replace_with.bytes()); } } } From 7b86ba0d8de53fece3c5e4a522dbde123f483a7c Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Sat, 8 Apr 2017 16:58:47 -0500 Subject: [PATCH 10/16] Add splice to the unstable book. --- src/doc/unstable-book/src/SUMMARY.md | 1 + .../src/library-features/splice.md | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/doc/unstable-book/src/library-features/splice.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 6134757304170..1adc59b84eac0 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -195,6 +195,7 @@ - [slice_rsplit](library-features/slice-rsplit.md) - [sort_internals](library-features/sort-internals.md) - [sort_unstable](library-features/sort-unstable.md) + - [splice](library-features/splice.md) - [step_by](library-features/step-by.md) - [step_trait](library-features/step-trait.md) - [str_checked_slicing](library-features/str-checked-slicing.md) diff --git a/src/doc/unstable-book/src/library-features/splice.md b/src/doc/unstable-book/src/library-features/splice.md new file mode 100644 index 0000000000000..ca7f78a8f79e5 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/splice.md @@ -0,0 +1,24 @@ +# `splice` + +The tracking issue for this feature is: [#32310] + +[#32310]: https://github.com/rust-lang/rust/issues/32310 + +------------------------ + +The `splice()` method on `Vec` and `String` allows you to replace a range +of values in a vector or string with another range of values, and returns +the replaced values. + +A simple example: + +```rust +#![feature(splice)] +let mut s = String::from("α is alpha, β is beta"); +let beta_offset = s.find('β').unwrap_or(s.len()); + +// Replace the range up until the β from the string +let t: String = s.splice(..beta_offset, "Α is capital alpha; ").collect(); +assert_eq!(t, "α is alpha, "); +assert_eq!(s, "Α is capital alpha; β is beta"); +``` \ No newline at end of file From f852e3fcbcdbcc42d7eb215b08bb3539f76b8ca1 Mon Sep 17 00:00:00 2001 From: steveklabnik Date: Mon, 24 Apr 2017 07:47:00 -0400 Subject: [PATCH 11/16] use the word 'length' in Vec::len's docs Fixes #37866 --- src/libcollections/vec.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 6deb87ae77204..1d443b19d80a7 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1147,7 +1147,8 @@ impl Vec { self.truncate(0) } - /// Returns the number of elements in the vector. + /// Returns the number of elements in the vector, also referred to + /// as its 'length'. /// /// # Examples /// From 612bb1f54e8c6c424b6664e16301354c545be34d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 24 Apr 2017 15:20:46 +0300 Subject: [PATCH 12/16] rustc: rename some of the queries to match tcx methods. --- src/librustc/cfg/construct.rs | 2 +- src/librustc/infer/mod.rs | 4 +- src/librustc/middle/dead.rs | 4 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/intrinsicck.rs | 2 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/mem_categorization.rs | 4 +- src/librustc/mir/mod.rs | 2 +- src/librustc/mir/tcx.rs | 2 +- src/librustc/traits/error_reporting.rs | 6 +- src/librustc/traits/mod.rs | 2 +- src/librustc/traits/object_safety.rs | 12 +- src/librustc/traits/project.rs | 8 +- src/librustc/traits/select.rs | 14 +- src/librustc/traits/specialize/mod.rs | 4 +- src/librustc/traits/util.rs | 6 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/instance.rs | 2 +- src/librustc/ty/item_path.rs | 4 +- src/librustc/ty/maps.rs | 14 +- src/librustc/ty/mod.rs | 68 ++++---- src/librustc/ty/relate.rs | 2 +- src/librustc/ty/sty.rs | 6 +- src/librustc/ty/subst.rs | 10 +- src/librustc/ty/util.rs | 10 +- src/librustc/ty/wf.rs | 2 +- src/librustc/util/ppaux.rs | 10 +- src/librustc_borrowck/borrowck/mod.rs | 4 +- src/librustc_const_eval/eval.rs | 6 +- src/librustc_const_eval/pattern.rs | 4 +- src/librustc_lint/builtin.rs | 18 +-- src/librustc_lint/types.rs | 6 +- src/librustc_metadata/cstore_impl.rs | 12 +- src/librustc_metadata/decoder.rs | 2 +- src/librustc_metadata/encoder.rs | 36 ++--- src/librustc_mir/build/scope.rs | 2 +- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/mir_map.rs | 2 +- src/librustc_mir/shim.rs | 8 +- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/librustc_mir/transform/type_check.rs | 2 +- src/librustc_passes/consts.rs | 2 +- src/librustc_privacy/lib.rs | 56 +++---- src/librustc_save_analysis/dump_visitor.rs | 2 +- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_trans/back/symbol_names.rs | 2 +- src/librustc_trans/base.rs | 2 +- src/librustc_trans/collector.rs | 4 +- src/librustc_trans/common.rs | 2 +- src/librustc_trans/debuginfo/mod.rs | 4 +- src/librustc_trans/trans_item.rs | 2 +- src/librustc_typeck/astconv.rs | 14 +- src/librustc_typeck/check/compare_method.rs | 24 +-- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/dropck.rs | 8 +- src/librustc_typeck/check/intrinsic.rs | 8 +- src/librustc_typeck/check/method/confirm.rs | 6 +- src/librustc_typeck/check/method/mod.rs | 6 +- src/librustc_typeck/check/method/probe.rs | 16 +- src/librustc_typeck/check/mod.rs | 74 ++++----- src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 34 ++-- src/librustc_typeck/check_unused.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 8 +- .../coherence/inherent_impls.rs | 2 +- src/librustc_typeck/coherence/mod.rs | 2 +- src/librustc_typeck/coherence/overlap.rs | 2 +- src/librustc_typeck/coherence/unsafety.rs | 2 +- src/librustc_typeck/collect.rs | 148 +++++++++--------- src/librustc_typeck/impl_wf_check.rs | 8 +- src/librustc_typeck/lib.rs | 4 +- src/librustc_typeck/variance/constraints.rs | 22 +-- src/librustc_typeck/variance/solve.rs | 3 +- src/librustc_typeck/variance/terms.rs | 3 +- src/librustdoc/clean/inline.rs | 52 +++--- src/librustdoc/clean/mod.rs | 28 ++-- src/librustdoc/clean/simplify.rs | 2 +- 77 files changed, 435 insertions(+), 437 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 20b322ec18951..d234e408a22dc 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -52,7 +52,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Find the tables for this body. let owner_def_id = tcx.hir.local_def_id(tcx.hir.body_owner(body.id())); - let tables = tcx.item_tables(owner_def_id); + let tables = tcx.typeck_tables_of(owner_def_id); let mut cfg_builder = CFGBuilder { tcx: tcx, diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 4d8b31a33cdef..e75513e924eec 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -450,7 +450,7 @@ impl<'a, 'tcx> InferEnv<'a, 'tcx> for hir::BodyId { Option>, Option>) { let item_id = tcx.hir.body_owner(self); - (Some(tcx.item_tables(tcx.hir.local_def_id(item_id))), + (Some(tcx.typeck_tables_of(tcx.hir.local_def_id(item_id))), None, Some(ty::ParameterEnvironment::for_item(tcx, item_id))) } @@ -1237,7 +1237,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { substs: &[Kind<'tcx>]) -> Ty<'tcx> { let default = if def.has_default { - let default = self.tcx.item_type(def.def_id); + let default = self.tcx.type_of(def.def_id); Some(type_variable::Default { ty: default.subst_spanned(self.tcx, substs, Some(span)), origin_span: span, diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 63d90d93bb51b..0be8484b78408 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -160,7 +160,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { match item.node { hir::ItemStruct(..) | hir::ItemUnion(..) => { let def_id = self.tcx.hir.local_def_id(item.id); - let def = self.tcx.lookup_adt_def(def_id); + let def = self.tcx.adt_def(def_id); self.struct_has_extern_repr = def.repr.c(); intravisit::walk_item(self, &item); @@ -433,7 +433,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { } fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool { - let field_type = self.tcx.item_type(self.tcx.hir.local_def_id(field.id)); + let field_type = self.tcx.type_of(self.tcx.hir.local_def_id(field.id)); let is_marker_field = match field_type.ty_to_def_id() { Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)), _ => false diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 8b26315915826..82e7d972c579a 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -998,7 +998,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { Def::Variant(variant_did) | Def::VariantCtor(variant_did, ..) => { let enum_did = tcx.parent_def_id(variant_did).unwrap(); - let downcast_cmt = if tcx.lookup_adt_def(enum_did).is_univariant() { + let downcast_cmt = if tcx.adt_def(enum_did).is_univariant() { cmt_pat } else { let cmt_pat_ty = cmt_pat.ty; diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index ecc0bb9fe497f..435dd05358d47 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -66,7 +66,7 @@ fn unpack_option_like<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> { fn def_id_is_transmute(&self, def_id: DefId) -> bool { - let intrinsic = match self.infcx.tcx.item_type(def_id).sty { + let intrinsic = match self.infcx.tcx.type_of(def_id).sty { ty::TyFnDef(.., bfty) => bfty.abi() == RustIntrinsic, _ => return false }; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index b7da8480c1cef..631046788629d 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1426,7 +1426,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { entry_ln: LiveNode, body: &hir::Body) { - let fn_ty = self.ir.tcx.item_type(self.ir.tcx.hir.local_def_id(id)); + let fn_ty = self.ir.tcx.type_of(self.ir.tcx.hir.local_def_id(id)); let fn_sig = match fn_ty.sty { ty::TyClosure(closure_def_id, substs) => { self.ir.tcx.closure_type(closure_def_id) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 188fcc9141492..677eca10d7bae 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1159,7 +1159,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { Def::VariantCtor(variant_did, ..) => { // univariant enums do not need downcasts let enum_did = self.tcx().parent_def_id(variant_did).unwrap(); - if !self.tcx().lookup_adt_def(enum_did).is_univariant() { + if !self.tcx().adt_def(enum_did).is_univariant() { self.cat_downcast(pat, cmt.clone(), cmt.ty, variant_did) } else { cmt @@ -1177,7 +1177,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { let expected_len = match def { Def::VariantCtor(def_id, CtorKind::Fn) => { let enum_def = self.tcx().parent_def_id(def_id).unwrap(); - self.tcx().lookup_adt_def(enum_def).variant_with_id(def_id).fields.len() + self.tcx().adt_def(enum_def).variant_with_id(def_id).fields.len() } Def::StructCtor(_, CtorKind::Fn) => { match self.pat_ty(&pat)?.sty { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index bfb72b5df7b2e..724d4f457deae 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1015,7 +1015,7 @@ impl<'tcx> Operand<'tcx> { ) -> Self { Operand::Constant(Constant { span: span, - ty: tcx.item_type(def_id).subst(tcx, substs), + ty: tcx.type_of(def_id).subst(tcx, substs), literal: Literal::Value { value: ConstVal::Function(def_id, substs) }, }) } diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index f40b9c6053753..b6020df072853 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -194,7 +194,7 @@ impl<'tcx> Rvalue<'tcx> { ) } AggregateKind::Adt(def, _, substs, _) => { - tcx.item_type(def.did).subst(tcx, substs) + tcx.type_of(def.did).subst(tcx, substs) } AggregateKind::Closure(did, substs) => { tcx.mk_closure_from_closure_substs(did, substs) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index ba340a40692c7..353677f4f2bed 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let mut self_match_impls = vec![]; let mut fuzzy_match_impls = vec![]; - self.tcx.lookup_trait_def(trait_ref.def_id) + self.tcx.trait_def(trait_ref.def_id) .for_each_relevant_impl(self.tcx, trait_self_ty, |def_id| { let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id); let impl_trait_ref = tcx @@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let trait_str = self.tcx.item_path_str(trait_ref.def_id); if let Some(istring) = item.value_str() { let istring = &*istring.as_str(); - let generics = self.tcx.item_generics(trait_ref.def_id); + let generics = self.tcx.generics_of(trait_ref.def_id); let generic_map = generics.types.iter().map(|param| { (param.name.as_str().to_string(), trait_ref.substs.type_for_def(param).to_string()) @@ -372,7 +372,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { trait_ref.skip_binder().self_ty(), true); let mut impl_candidates = Vec::new(); - let trait_def = self.tcx.lookup_trait_def(trait_ref.def_id()); + let trait_def = self.tcx.trait_def(trait_ref.def_id()); match simp { Some(simp) => trait_def.for_each_impl(self.tcx, |def_id| { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 281c1e253798c..a7f9cc74c4f58 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -641,7 +641,7 @@ pub fn get_vtable_methods<'a, 'tcx>( // do not hold for this particular set of type parameters. // Note that this method could then never be called, so we // do not want to try and trans it, in that case (see #23435). - let predicates = tcx.item_predicates(def_id).instantiate_own(tcx, substs); + let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs); if !normalize_and_test_predicates(tcx, predicates.predicates) { debug!("get_vtable_methods: predicates do not hold"); return None; diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index d190635bec306..f8d6058db3f2a 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -74,7 +74,7 @@ pub enum MethodViolationCode { impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn is_object_safe(self, trait_def_id: DefId) -> bool { // Because we query yes/no results frequently, we keep a cache: - let def = self.lookup_trait_def(trait_def_id); + let def = self.trait_def(trait_def_id); let result = def.object_safety().unwrap_or_else(|| { let result = self.object_safety_violations(trait_def_id).is_empty(); @@ -158,9 +158,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { substs: Substs::identity_for_item(self, trait_def_id) }); let predicates = if supertraits_only { - self.item_super_predicates(trait_def_id) + self.super_predicates_of(trait_def_id) } else { - self.item_predicates(trait_def_id) + self.predicates_of(trait_def_id) }; predicates .predicates @@ -199,7 +199,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // Search for a predicate like `Self : Sized` amongst the trait bounds. let free_substs = self.construct_free_substs(def_id, self.region_maps.node_extent(ast::DUMMY_NODE_ID)); - let predicates = self.item_predicates(def_id); + let predicates = self.predicates_of(def_id); let predicates = predicates.instantiate(self, free_substs).predicates; elaborate_predicates(self, predicates) .any(|predicate| { @@ -272,7 +272,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // The `Self` type is erased, so it should not appear in list of // arguments or return type apart from the receiver. - let ref sig = self.item_type(method.def_id).fn_sig(); + let ref sig = self.type_of(method.def_id).fn_sig(); for input_ty in &sig.skip_binder().inputs()[1..] { if self.contains_illegal_self_type_reference(trait_def_id, input_ty) { return Some(MethodViolationCode::ReferencesSelf); @@ -283,7 +283,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } // We can't monomorphize things like `fn foo(...)`. - if !self.item_generics(method.def_id).types.is_empty() { + if !self.generics_of(method.def_id).types.is_empty() { return Some(MethodViolationCode::Generic); } diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 3d8f9e41c675b..7e0954c92a660 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -279,7 +279,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a, ty::TyAnon(def_id, substs) if !substs.has_escaping_regions() => { // (*) // Only normalize `impl Trait` after type-checking, usually in trans. if self.selcx.projection_mode() == Reveal::All { - let generic_ty = self.tcx().item_type(def_id); + let generic_ty = self.tcx().type_of(def_id); let concrete_ty = generic_ty.subst(self.tcx(), substs); self.fold_ty(concrete_ty) } else { @@ -787,7 +787,7 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>( }; // If so, extract what we know from the trait and try to come up with a good answer. - let trait_predicates = selcx.tcx().item_predicates(def_id); + let trait_predicates = selcx.tcx().predicates_of(def_id); let bounds = trait_predicates.instantiate(selcx.tcx(), substs); let bounds = elaborate_predicates(selcx.tcx(), bounds.predicates); assemble_candidates_from_predicates(selcx, @@ -1288,7 +1288,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>( obligation.predicate.trait_ref); tcx.types.err } else { - tcx.item_type(node_item.item.def_id) + tcx.type_of(node_item.item.def_id) }; let substs = translate_substs(selcx.infcx(), impl_def_id, substs, node_item.node); Progress { @@ -1317,7 +1317,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>( -> Option> { let trait_def_id = selcx.tcx().impl_trait_ref(impl_def_id).unwrap().def_id; - let trait_def = selcx.tcx().lookup_trait_def(trait_def_id); + let trait_def = selcx.tcx().trait_def(trait_def_id); if !trait_def.is_complete(selcx.tcx()) { let impl_node = specialization_graph::Node::Impl(impl_def_id); diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 207016170faa2..cccc20e5b296b 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -842,7 +842,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { fn filter_negative_impls(&self, candidate: SelectionCandidate<'tcx>) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> { if let ImplCandidate(def_id) = candidate { - if self.tcx().trait_impl_polarity(def_id) == hir::ImplPolarity::Negative { + if self.tcx().impl_polarity(def_id) == hir::ImplPolarity::Negative { return Err(Unimplemented) } } @@ -1222,8 +1222,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { def_id={:?}, substs={:?}", def_id, substs); - let item_predicates = self.tcx().item_predicates(def_id); - let bounds = item_predicates.instantiate(self.tcx(), substs); + let predicates_of = self.tcx().predicates_of(def_id); + let bounds = predicates_of.instantiate(self.tcx(), substs); debug!("match_projection_obligation_against_definition_bounds: \ bounds={:?}", bounds); @@ -1432,7 +1432,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { { debug!("assemble_candidates_from_impls(obligation={:?})", obligation); - let def = self.tcx().lookup_trait_def(obligation.predicate.def_id()); + let def = self.tcx().trait_def(obligation.predicate.def_id()); def.for_each_relevant_impl( self.tcx(), @@ -1947,7 +1947,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // We can resolve the `impl Trait` to its concrete type, // which enforces a DAG between the functions requiring // the auto trait bounds in question. - vec![self.tcx().item_type(def_id).subst(self.tcx(), substs)] + vec![self.tcx().type_of(def_id).subst(self.tcx(), substs)] } } } @@ -2526,7 +2526,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { (&ty::TyAdt(def, substs_a), &ty::TyAdt(_, substs_b)) => { let fields = def .all_fields() - .map(|f| tcx.item_type(f.did)) + .map(|f| tcx.type_of(f.did)) .collect::>(); // The last field of the structure has to exist and contain type parameters. @@ -2844,7 +2844,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // obligation will normalize to `<$0 as Iterator>::Item = $1` and // `$1: Copy`, so we must ensure the obligations are emitted in // that order. - let predicates = tcx.item_predicates(def_id); + let predicates = tcx.predicates_of(def_id); assert_eq!(predicates.parent, None); let predicates = predicates.predicates.iter().flat_map(|predicate| { let predicate = normalize_with_depth(self, cause.clone(), recursion_depth, diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 5f02688be34bc..6c685851e2593 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -117,7 +117,7 @@ pub fn find_associated_item<'a, 'tcx>( assert!(!substs.needs_infer()); let trait_def_id = tcx.trait_id_of_impl(impl_data.impl_def_id).unwrap(); - let trait_def = tcx.lookup_trait_def(trait_def_id); + let trait_def = tcx.trait_def(trait_def_id); let ancestors = trait_def.ancestors(impl_data.impl_def_id); match ancestors.defs(tcx, item.name, item.kind).next() { @@ -175,7 +175,7 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // See RFC 1210 for more details and justification. // Currently we do not allow e.g. a negative impl to specialize a positive one - if tcx.trait_impl_polarity(impl1_def_id) != tcx.trait_impl_polarity(impl2_def_id) { + if tcx.impl_polarity(impl1_def_id) != tcx.impl_polarity(impl2_def_id) { return false; } diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index d4245ec9b2475..396c7dbd1a874 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -130,7 +130,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { match *predicate { ty::Predicate::Trait(ref data) => { // Predicates declared on the trait. - let predicates = tcx.item_super_predicates(data.def_id()); + let predicates = tcx.super_predicates_of(data.def_id()); let mut predicates: Vec<_> = predicates.predicates @@ -301,7 +301,7 @@ impl<'cx, 'gcx, 'tcx> Iterator for SupertraitDefIds<'cx, 'gcx, 'tcx> { None => { return None; } }; - let predicates = self.tcx.item_super_predicates(def_id); + let predicates = self.tcx.super_predicates_of(def_id); let visited = &mut self.visited; self.stack.extend( predicates.predicates @@ -368,7 +368,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } = super::normalize(selcx, ObligationCause::dummy(), &impl_trait_ref); - let predicates = selcx.tcx().item_predicates(impl_def_id); + let predicates = selcx.tcx().predicates_of(impl_def_id); let predicates = predicates.instantiate(selcx.tcx(), impl_substs); let Normalized { value: predicates, obligations: normalization_obligations2 } = super::normalize(selcx, ObligationCause::dummy(), &predicates); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index b20ac8ddbfc8a..ac7a72e66655f 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1258,7 +1258,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> { let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem); - let adt_def = self.lookup_adt_def(def_id); + let adt_def = self.adt_def(def_id); let substs = self.mk_substs(iter::once(Kind::from(ty))); self.mk_ty(TyAdt(adt_def, substs)) } diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index cfff3d0e57360..7dca28df9da39 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -52,7 +52,7 @@ impl<'tcx> InstanceDef<'tcx> { #[inline] pub fn def_ty<'a>(&self, tcx: ty::TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> { - tcx.item_type(self.def_id()) + tcx.type_of(self.def_id()) } #[inline] diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 3869910529055..9aa2caadd1d37 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -203,7 +203,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // for local crates, check whether type info is // available; typeck might not have completed yet self.maps.impl_trait_ref.borrow().contains_key(&impl_def_id) && - self.maps.ty.borrow().contains_key(&impl_def_id) + self.maps.type_of.borrow().contains_key(&impl_def_id) }; if !use_types { @@ -215,7 +215,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // users may find it useful. Currently, we omit the parent if // the impl is either in the same module as the self-type or // as the trait. - let self_ty = self.item_type(impl_def_id); + let self_ty = self.type_of(impl_def_id); let in_self_mod = match characteristic_def_id_of_type(self_ty) { None => false, Some(ty_def_id) => self.parent_def_id(ty_def_id) == Some(parent_def_id), diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 4595a8c4f7784..f743da24972af 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -175,7 +175,7 @@ impl> QueryDescription for M { } } -impl<'tcx> QueryDescription for queries::super_predicates<'tcx> { +impl<'tcx> QueryDescription for queries::super_predicates_of<'tcx> { fn describe(tcx: TyCtxt, def_id: DefId) -> String { format!("computing the supertraits of `{}`", tcx.item_path_str(def_id)) @@ -380,12 +380,12 @@ macro_rules! define_maps { // the driver creates (using several `rustc_*` crates). define_maps! { <'tcx> /// Records the type of every item. - pub ty: ItemSignature(DefId) -> Ty<'tcx>, + pub type_of: ItemSignature(DefId) -> Ty<'tcx>, /// Maps from the def-id of an item (trait/struct/enum/fn) to its /// associated generics and predicates. - pub generics: ItemSignature(DefId) -> &'tcx ty::Generics, - pub predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, + pub generics_of: ItemSignature(DefId) -> &'tcx ty::Generics, + pub predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, /// Maps from the def-id of a trait to the list of /// super-predicates. This is a subset of the full list of @@ -393,7 +393,7 @@ define_maps! { <'tcx> /// evaluate them even during type conversion, often before the /// full predicates are available (note that supertraits have /// additional acyclicity requirements). - pub super_predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, + pub super_predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, /// To avoid cycles within the predicates of a single item we compute /// per-type-parameter predicates for resolving `T::AssocTy`. @@ -411,7 +411,7 @@ define_maps! { <'tcx> /// Maps from def-id of a type or region parameter to its /// (inferred) variance. - pub variances: ItemSignature(DefId) -> Rc>, + pub variances_of: ItemSignature(DefId) -> Rc>, /// Maps from an impl/trait def-id to a list of the def-ids of its items pub associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc>, @@ -455,7 +455,7 @@ define_maps! { <'tcx> pub typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult, - pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>, + pub typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>, pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (), diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 352b6ab1d356f..d5cd3742ffccb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -165,9 +165,9 @@ impl<'a, 'gcx, 'tcx> ImplHeader<'tcx> { let header = ImplHeader { impl_def_id: impl_def_id, - self_ty: tcx.item_type(impl_def_id), + self_ty: tcx.type_of(impl_def_id), trait_ref: tcx.impl_trait_ref(impl_def_id), - predicates: tcx.item_predicates(impl_def_id).predicates + predicates: tcx.predicates_of(impl_def_id).predicates }.subst(tcx, impl_substs); let traits::Normalized { value: mut header, obligations } = @@ -727,7 +727,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> { instantiated: &mut InstantiatedPredicates<'tcx>, substs: &Substs<'tcx>) { if let Some(def_id) = self.parent { - tcx.item_predicates(def_id).instantiate_into(tcx, instantiated, substs); + tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs); } instantiated.predicates.extend(self.predicates.iter().map(|p| p.subst(tcx, substs))) } @@ -1633,7 +1633,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { #[inline] pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> GenericPredicates<'gcx> { - tcx.item_predicates(self.did) + tcx.predicates_of(self.did) } /// Returns an iterator over all fields contained @@ -1840,7 +1840,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { def_id: sized_trait, substs: tcx.mk_substs_trait(ty, &[]) }).to_predicate(); - let predicates = tcx.item_predicates(self.did).predicates; + let predicates = tcx.predicates_of(self.did).predicates; if predicates.into_iter().any(|p| p == sized_predicate) { vec![] } else { @@ -1881,7 +1881,7 @@ impl<'a, 'gcx, 'tcx> VariantDef { impl<'a, 'gcx, 'tcx> FieldDef { pub fn ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, subst: &Substs<'tcx>) -> Ty<'tcx> { - tcx.item_type(self.did).subst(tcx, subst) + tcx.type_of(self.did).subst(tcx, subst) } } @@ -2042,11 +2042,11 @@ impl<'gcx> ::std::ops::Deref for Attributes<'gcx> { impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn body_tables(self, body: hir::BodyId) -> &'gcx TypeckTables<'gcx> { - self.item_tables(self.hir.body_owner_def_id(body)) + self.typeck_tables_of(self.hir.body_owner_def_id(body)) } - pub fn item_tables(self, def_id: DefId) -> &'gcx TypeckTables<'gcx> { - queries::typeck_tables::get(self, DUMMY_SP, def_id) + pub fn typeck_tables_of(self, def_id: DefId) -> &'gcx TypeckTables<'gcx> { + queries::typeck_tables_of::get(self, DUMMY_SP, def_id) } pub fn expr_span(self, id: NodeId) -> Span { @@ -2136,7 +2136,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { .collect() } - pub fn trait_impl_polarity(self, id: DefId) -> hir::ImplPolarity { + pub fn impl_polarity(self, id: DefId) -> hir::ImplPolarity { queries::impl_polarity::get(self, DUMMY_SP, id) } @@ -2238,7 +2238,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { .map_or(false, |trait_ref| { self.associated_item_def_ids(trait_ref.def_id).is_empty() }); - self.trait_impl_polarity(def_id1) == self.trait_impl_polarity(def_id2) + self.impl_polarity(def_id1) == self.impl_polarity(def_id2) && trait1_is_empty && trait2_is_empty } @@ -2249,14 +2249,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { match def { Def::Variant(did) | Def::VariantCtor(did, ..) => { let enum_did = self.parent_def_id(did).unwrap(); - self.lookup_adt_def(enum_did).variant_with_id(did) + self.adt_def(enum_did).variant_with_id(did) } Def::Struct(did) | Def::Union(did) => { - self.lookup_adt_def(did).struct_variant() + self.adt_def(did).struct_variant() } Def::StructCtor(ctor_did, ..) => { let did = self.parent_def_id(ctor_did).expect("struct ctor has no parent"); - self.lookup_adt_def(did).struct_variant() + self.adt_def(did).struct_variant() } _ => bug!("expect_variant_def used with unexpected def {:?}", def) } @@ -2327,33 +2327,33 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // If the given item is in an external crate, looks up its type and adds it to // the type cache. Returns the type parameters and type. - pub fn item_type(self, did: DefId) -> Ty<'gcx> { - queries::ty::get(self, DUMMY_SP, did) + pub fn type_of(self, did: DefId) -> Ty<'gcx> { + queries::type_of::get(self, DUMMY_SP, did) } /// Given the did of a trait, returns its canonical trait ref. - pub fn lookup_trait_def(self, did: DefId) -> &'gcx TraitDef { + pub fn trait_def(self, did: DefId) -> &'gcx TraitDef { queries::trait_def::get(self, DUMMY_SP, did) } /// Given the did of an ADT, return a reference to its definition. - pub fn lookup_adt_def(self, did: DefId) -> &'gcx AdtDef { + pub fn adt_def(self, did: DefId) -> &'gcx AdtDef { queries::adt_def::get(self, DUMMY_SP, did) } /// Given the did of an item, returns its generics. - pub fn item_generics(self, did: DefId) -> &'gcx Generics { - queries::generics::get(self, DUMMY_SP, did) + pub fn generics_of(self, did: DefId) -> &'gcx Generics { + queries::generics_of::get(self, DUMMY_SP, did) } /// Given the did of an item, returns its full set of predicates. - pub fn item_predicates(self, did: DefId) -> GenericPredicates<'gcx> { - queries::predicates::get(self, DUMMY_SP, did) + pub fn predicates_of(self, did: DefId) -> GenericPredicates<'gcx> { + queries::predicates_of::get(self, DUMMY_SP, did) } /// Given the did of a trait, returns its superpredicates. - pub fn item_super_predicates(self, did: DefId) -> GenericPredicates<'gcx> { - queries::super_predicates::get(self, DUMMY_SP, did) + pub fn super_predicates_of(self, did: DefId) -> GenericPredicates<'gcx> { + queries::super_predicates_of::get(self, DUMMY_SP, did) } /// Given the did of an item, returns its MIR, borrowed immutably. @@ -2399,12 +2399,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.get_attrs(did).iter().any(|item| item.check_name(attr)) } - pub fn item_variances(self, item_id: DefId) -> Rc> { - queries::variances::get(self, DUMMY_SP, item_id) + pub fn variances_of(self, item_id: DefId) -> Rc> { + queries::variances_of::get(self, DUMMY_SP, item_id) } pub fn trait_has_default_impl(self, trait_def_id: DefId) -> bool { - let def = self.lookup_trait_def(trait_def_id); + let def = self.trait_def(trait_def_id); def.flags.get().intersects(TraitFlags::HAS_DEFAULT_IMPL) } @@ -2419,7 +2419,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // metadata and don't need to track edges. let _ignore = self.dep_graph.in_ignore(); - let def = self.lookup_trait_def(trait_id); + let def = self.trait_def(trait_id); if def.flags.get().intersects(TraitFlags::HAS_REMOTE_IMPLS) { return; } @@ -2553,7 +2553,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // let tcx = self.global_tcx(); - let generic_predicates = tcx.item_predicates(def_id); + let generic_predicates = tcx.predicates_of(def_id); let bounds = generic_predicates.instantiate(tcx, free_substs); let bounds = tcx.liberate_late_bound_regions(free_id_outlive, &ty::Binder(bounds)); let predicates = bounds.predicates; @@ -2678,12 +2678,12 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx [Ty<'tcx>] { - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); let result = tcx.intern_type_list(&def.variants.iter().flat_map(|v| { v.fields.last() }).flat_map(|f| { - def.sized_constraint_for_ty(tcx, tcx.item_type(f.did)) + def.sized_constraint_for_ty(tcx, tcx.type_of(f.did)) }).collect::>()); debug!("adt_sized_constraint: {:?} => {:?}", def, result); @@ -2695,7 +2695,7 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn adt_dtorck_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> DtorckConstraint<'tcx> { - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); let span = tcx.def_span(def_id); debug!("dtorck_constraint: {:?}", def); @@ -2703,7 +2703,7 @@ fn adt_dtorck_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let result = DtorckConstraint { outlives: vec![], dtorck_types: vec![ - tcx.mk_param_from_def(&tcx.item_generics(def_id).types[0]) + tcx.mk_param_from_def(&tcx.generics_of(def_id).types[0]) ] }; debug!("dtorck_constraint: {:?} => {:?}", def, result); @@ -2711,7 +2711,7 @@ fn adt_dtorck_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } let mut result = def.all_fields() - .map(|field| tcx.item_type(field.did)) + .map(|field| tcx.type_of(field.did)) .map(|fty| tcx.dtorck_constraint_for_ty(span, fty, 0, fty)) .collect::>() .unwrap_or(DtorckConstraint::empty()); diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index cef24d44d6875..58ebc843da106 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -126,7 +126,7 @@ fn relate_item_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, let variances; let opt_variances = if relation.tcx().variance_computed.get() { - variances = relation.tcx().item_variances(item_def_id); + variances = relation.tcx().variances_of(item_def_id); Some(&*variances) } else { None diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index d59248170344e..7857d07ed0910 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -262,7 +262,7 @@ impl<'a, 'gcx, 'acx, 'tcx> ClosureSubsts<'tcx> { pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'acx>) -> impl Iterator> + 'tcx { - let generics = tcx.item_generics(def_id); + let generics = tcx.generics_of(def_id); self.substs[self.substs.len()-generics.own_count()..].iter().map( |t| t.as_type().expect("unexpected region in upvars")) } @@ -285,7 +285,7 @@ impl<'a, 'gcx, 'tcx> ExistentialPredicate<'tcx> { (Trait(_), Trait(_)) => Ordering::Equal, (Projection(ref a), Projection(ref b)) => a.sort_key(tcx).cmp(&b.sort_key(tcx)), (AutoTrait(ref a), AutoTrait(ref b)) => - tcx.lookup_trait_def(*a).def_path_hash.cmp(&tcx.lookup_trait_def(*b).def_path_hash), + tcx.trait_def(*a).def_path_hash.cmp(&tcx.trait_def(*b).def_path_hash), (Trait(_), _) => Ordering::Less, (Projection(_), Trait(_)) => Ordering::Greater, (Projection(_), _) => Ordering::Less, @@ -841,7 +841,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> { // We want something here that is stable across crate boundaries. // The DefId isn't but the `deterministic_hash` of the corresponding // DefPath is. - let trait_def = tcx.lookup_trait_def(self.trait_ref.def_id); + let trait_def = tcx.trait_def(self.trait_ref.def_id); let def_path_hash = trait_def.def_path_hash; // An `ast::Name` is also not stable (it's just an index into an diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 14aebdf8418fe..961140d5eac60 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -185,7 +185,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { -> &'tcx Substs<'tcx> where FR: FnMut(&ty::RegionParameterDef, &[Kind<'tcx>]) -> &'tcx ty::Region, FT: FnMut(&ty::TypeParameterDef, &[Kind<'tcx>]) -> Ty<'tcx> { - let defs = tcx.item_generics(def_id); + let defs = tcx.generics_of(def_id); let mut substs = Vec::with_capacity(defs.count()); Substs::fill_item(&mut substs, tcx, defs, &mut mk_region, &mut mk_type); tcx.intern_substs(&substs) @@ -200,7 +200,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { where FR: FnMut(&ty::RegionParameterDef, &[Kind<'tcx>]) -> &'tcx ty::Region, FT: FnMut(&ty::TypeParameterDef, &[Kind<'tcx>]) -> Ty<'tcx> { - let defs = tcx.item_generics(def_id); + let defs = tcx.generics_of(def_id); let mut result = Vec::with_capacity(defs.count()); result.extend(self[..].iter().cloned()); Substs::fill_single(&mut result, defs, &mut mk_region, &mut mk_type); @@ -216,7 +216,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { FT: FnMut(&ty::TypeParameterDef, &[Kind<'tcx>]) -> Ty<'tcx> { if let Some(def_id) = defs.parent { - let parent_defs = tcx.item_generics(def_id); + let parent_defs = tcx.generics_of(def_id); Substs::fill_item(substs, tcx, parent_defs, mk_region, mk_type); } Substs::fill_single(substs, defs, mk_region, mk_type) @@ -297,7 +297,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { source_ancestor: DefId, target_substs: &Substs<'tcx>) -> &'tcx Substs<'tcx> { - let defs = tcx.item_generics(source_ancestor); + let defs = tcx.generics_of(source_ancestor); tcx.mk_substs(target_substs.iter().chain(&self[defs.own_count()..]).cloned()) } @@ -553,7 +553,7 @@ impl<'a, 'gcx, 'tcx> ty::TraitRef<'tcx> { trait_id: DefId, substs: &Substs<'tcx>) -> ty::TraitRef<'tcx> { - let defs = tcx.item_generics(trait_id); + let defs = tcx.generics_of(trait_id); ty::TraitRef { def_id: trait_id, diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index f68cf6f97f857..007647a3297c3 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -372,8 +372,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { ty::queries::coherent_trait::get(self, DUMMY_SP, (LOCAL_CRATE, drop_trait)); let mut dtor_did = None; - let ty = self.item_type(adt_did); - self.lookup_trait_def(drop_trait).for_each_relevant_impl(self, ty, |impl_did| { + let ty = self.type_of(adt_did); + self.trait_def(drop_trait).for_each_relevant_impl(self, ty, |impl_did| { if let Some(item) = self.associated_items(impl_did).next() { if let Ok(()) = validate(self, impl_did) { dtor_did = Some(item.def_id); @@ -422,7 +422,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } let impl_def_id = self.associated_item(dtor).container.id(); - let impl_generics = self.item_generics(impl_def_id); + let impl_generics = self.generics_of(impl_def_id); // We have a destructor - all the parameters that are not // pure_wrt_drop (i.e, don't have a #[may_dangle] attribute) @@ -445,12 +445,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // , and then look up which of the impl substs refer to // parameters marked as pure. - let impl_substs = match self.item_type(impl_def_id).sty { + let impl_substs = match self.type_of(impl_def_id).sty { ty::TyAdt(def_, substs) if def_ == def => substs, _ => bug!() }; - let item_substs = match self.item_type(def.did).sty { + let item_substs = match self.type_of(def.did).sty { ty::TyAdt(def_, substs) if def_ == def => substs, _ => bug!() }; diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 0b0e8a180cc36..6c7073de70bbd 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -443,7 +443,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { -> Vec> { let predicates = - self.infcx.tcx.item_predicates(def_id) + self.infcx.tcx.predicates_of(def_id) .instantiate(self.infcx.tcx, substs); let cause = self.cause(traits::ItemObligation(def_id)); predicates.predicates diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 2daf71d95addf..df5a2731c8900 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -104,7 +104,7 @@ pub fn parameterized(f: &mut fmt::Formatter, } } } - let mut generics = tcx.item_generics(item_def_id); + let mut generics = tcx.generics_of(item_def_id); let mut path_def_id = did; verbose = tcx.sess.verbose(); has_self = generics.has_self; @@ -114,7 +114,7 @@ pub fn parameterized(f: &mut fmt::Formatter, // Methods. assert!(is_value_path); child_types = generics.types.len(); - generics = tcx.item_generics(def_id); + generics = tcx.generics_of(def_id); num_regions = generics.regions.len(); num_types = generics.types.len(); @@ -144,7 +144,7 @@ pub fn parameterized(f: &mut fmt::Formatter, if !def.has_default { break; } - if tcx.item_type(def.def_id).subst(tcx, substs) != actual { + if tcx.type_of(def.def_id).subst(tcx, substs) != actual { break; } num_supplied_defaults += 1; @@ -772,11 +772,11 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { ty::tls::with(|tcx| { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the projections associated with the def_id. - let item_predicates = tcx.item_predicates(def_id); + let predicates_of = tcx.predicates_of(def_id); let substs = tcx.lift(&substs).unwrap_or_else(|| { tcx.intern_substs(&[]) }); - let bounds = item_predicates.instantiate(tcx, substs); + let bounds = predicates_of.instantiate(tcx, substs); let mut first = true; let mut is_sized = false; diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 142286bd834d0..99e533cbb83f3 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -87,7 +87,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) { let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap(); let body_id = tcx.hir.body_owned_by(owner_id); let attributes = tcx.get_attrs(owner_def_id); - let tables = tcx.item_tables(owner_def_id); + let tables = tcx.typeck_tables_of(owner_def_id); let mut bccx = &mut BorrowckCtxt { tcx: tcx, @@ -169,7 +169,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( { let owner_id = tcx.hir.body_owner(body_id); let owner_def_id = tcx.hir.local_def_id(owner_id); - let tables = tcx.item_tables(owner_def_id); + let tables = tcx.typeck_tables_of(owner_def_id); let mut bccx = BorrowckCtxt { tcx: tcx, diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index e9352f53c92d6..cc9892ee8c213 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -376,7 +376,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>, debug!("const call({:?})", call_args); let callee_cx = ConstContext { tcx: tcx, - tables: tcx.item_tables(def_id), + tables: tcx.typeck_tables_of(def_id), substs: substs, fn_args: Some(call_args) }; @@ -607,7 +607,7 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, Float(f) => cast_const_float(tcx, f, ty), Char(c) => cast_const_int(tcx, U32(c as u32), ty), Variant(v) => { - let adt = tcx.lookup_adt_def(tcx.parent_def_id(v).unwrap()); + let adt = tcx.adt_def(tcx.parent_def_id(v).unwrap()); let idx = adt.variant_index_with_id(v); cast_const_int(tcx, adt.discriminant_for_variant(tcx, idx), ty) } @@ -767,7 +767,7 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let cx = ConstContext { tcx, - tables: tcx.item_tables(def_id), + tables: tcx.typeck_tables_of(def_id), substs: substs, fn_args: None }; diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs index 0dfafeb6fb836..aea40b8553548 100644 --- a/src/librustc_const_eval/pattern.rs +++ b/src/librustc_const_eval/pattern.rs @@ -547,7 +547,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> { match def { Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => { let enum_id = self.tcx.parent_def_id(variant_id).unwrap(); - let adt_def = self.tcx.lookup_adt_def(enum_id); + let adt_def = self.tcx.adt_def(enum_id); if adt_def.variants.len() > 1 { let substs = match ty.sty { TypeVariants::TyAdt(_, substs) => substs, @@ -591,7 +591,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> { Some((def_id, _substs)) => { // Enter the inlined constant's tables temporarily. let old_tables = self.tables; - self.tables = tcx.item_tables(def_id); + self.tables = tcx.typeck_tables_of(def_id); let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) { tcx.hir.body(tcx.hir.body_owned_by(id)) } else { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 1c69f3cff172a..c8644820ac0d0 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { hir::ItemStruct(..) | hir::ItemUnion(..) => { let def_id = cx.tcx.hir.local_def_id(it.id); - self.check_heap_type(cx, it.span, cx.tcx.item_type(def_id)) + self.check_heap_type(cx, it.span, cx.tcx.type_of(def_id)) } _ => () } @@ -130,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { for struct_field in struct_def.fields() { let def_id = cx.tcx.hir.local_def_id(struct_field.id); self.check_heap_type(cx, struct_field.span, - cx.tcx.item_type(def_id)); + cx.tcx.type_of(def_id)); } } _ => (), @@ -504,21 +504,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { if ast_generics.is_parameterized() { return; } - let def = cx.tcx.lookup_adt_def(cx.tcx.hir.local_def_id(item.id)); + let def = cx.tcx.adt_def(cx.tcx.hir.local_def_id(item.id)); (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) } hir::ItemUnion(_, ref ast_generics) => { if ast_generics.is_parameterized() { return; } - let def = cx.tcx.lookup_adt_def(cx.tcx.hir.local_def_id(item.id)); + let def = cx.tcx.adt_def(cx.tcx.hir.local_def_id(item.id)); (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) } hir::ItemEnum(_, ref ast_generics) => { if ast_generics.is_parameterized() { return; } - let def = cx.tcx.lookup_adt_def(cx.tcx.hir.local_def_id(item.id)); + let def = cx.tcx.adt_def(cx.tcx.hir.local_def_id(item.id)); (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) } _ => return, @@ -582,10 +582,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { }; if self.impling_types.is_none() { - let debug_def = cx.tcx.lookup_trait_def(debug); + let debug_def = cx.tcx.trait_def(debug); let mut impls = NodeSet(); debug_def.for_each_impl(cx.tcx, |d| { - if let Some(ty_def) = cx.tcx.item_type(d).ty_to_def_id() { + if let Some(ty_def) = cx.tcx.type_of(d).ty_to_def_id() { if let Some(node_id) = cx.tcx.hir.as_local_node_id(ty_def) { impls.insert(node_id); } @@ -1094,7 +1094,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes { } fn def_id_is_transmute(cx: &LateContext, def_id: DefId) -> bool { - match cx.tcx.item_type(def_id).sty { + match cx.tcx.type_of(def_id).sty { ty::TyFnDef(.., bfty) if bfty.abi() == RustIntrinsic => (), _ => return false, } @@ -1151,7 +1151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields { if let hir::ItemUnion(ref vdata, _) = item.node { let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id); for field in vdata.fields() { - let field_ty = ctx.tcx.item_type(ctx.tcx.hir.local_def_id(field.id)); + let field_ty = ctx.tcx.type_of(ctx.tcx.hir.local_def_id(field.id)); if field_ty.needs_drop(ctx.tcx, param_env) { ctx.span_lint(UNIONS_WITH_DROP_FIELDS, field.span, diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 3e60d8a5ada09..c2181c9764c6c 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -660,7 +660,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) { let def_id = self.cx.tcx.hir.local_def_id(id); - let sig = self.cx.tcx.item_type(def_id).fn_sig(); + let sig = self.cx.tcx.type_of(def_id).fn_sig(); let sig = self.cx.tcx.erase_late_bound_regions(&sig); for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) { @@ -677,7 +677,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { fn check_foreign_static(&mut self, id: ast::NodeId, span: Span) { let def_id = self.cx.tcx.hir.local_def_id(id); - let ty = self.cx.tcx.item_type(def_id); + let ty = self.cx.tcx.type_of(def_id); self.check_type_for_ffi_and_report_errors(span, ty); } } @@ -724,7 +724,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { if let hir::ItemEnum(ref enum_definition, ref gens) = it.node { if gens.ty_params.is_empty() { // sizes only make sense for non-generic types - let t = cx.tcx.item_type(cx.tcx.hir.local_def_id(it.id)); + let t = cx.tcx.type_of(cx.tcx.hir.local_def_id(it.id)); let layout = cx.tcx.infer_ctxt((), Reveal::All).enter(|infcx| { let ty = cx.tcx.erase_regions(&t); ty.layout(&infcx).unwrap_or_else(|e| { diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 9e6a45e7f8b7c..f310279ea3c3a 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -69,10 +69,10 @@ macro_rules! provide { } provide! { <'tcx> tcx, def_id, cdata - ty => { cdata.get_type(def_id.index, tcx) } - generics => { tcx.alloc_generics(cdata.get_generics(def_id.index)) } - predicates => { cdata.get_predicates(def_id.index, tcx) } - super_predicates => { cdata.get_super_predicates(def_id.index, tcx) } + type_of => { cdata.get_type(def_id.index, tcx) } + generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) } + predicates_of => { cdata.get_predicates(def_id.index, tcx) } + super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) } trait_def => { tcx.alloc_trait_def(cdata.get_trait_def(def_id.index)) } @@ -81,7 +81,7 @@ provide! { <'tcx> tcx, def_id, cdata let _ = cdata; tcx.calculate_dtor(def_id, &mut |_,_| Ok(())) } - variances => { Rc::new(cdata.get_item_variances(def_id.index)) } + variances_of => { Rc::new(cdata.get_item_variances(def_id.index)) } associated_item_def_ids => { let mut result = vec![]; cdata.each_child_of_item(def_id.index, |child| result.push(child.def.def_id())); @@ -108,7 +108,7 @@ provide! { <'tcx> tcx, def_id, cdata mir } mir_const_qualif => { cdata.mir_const_qualif(def_id.index) } - typeck_tables => { cdata.item_body_tables(def_id.index, tcx) } + typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) } closure_kind => { cdata.closure_kind(def_id.index) } closure_type => { cdata.closure_ty(def_id.index, tcx) } inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index a9eae5281b241..1656d489269d0 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -367,7 +367,7 @@ impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::Slice>> for DecodeContext<' impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::AdtDef> for DecodeContext<'a, 'tcx> { fn specialized_decode(&mut self) -> Result<&'tcx ty::AdtDef, Self::Error> { let def_id = DefId::decode(self)?; - Ok(self.tcx().lookup_adt_def(def_id)) + Ok(self.tcx().adt_def(def_id)) } } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index ce9f0a73fe2b8..949949d2e1020 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -242,12 +242,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { fn encode_item_variances(&mut self, def_id: DefId) -> LazySeq { debug!("EntryBuilder::encode_item_variances({:?})", def_id); let tcx = self.tcx; - self.lazy_seq_from_slice(&tcx.item_variances(def_id)) + self.lazy_seq_from_slice(&tcx.variances_of(def_id)) } fn encode_item_type(&mut self, def_id: DefId) -> Lazy> { let tcx = self.tcx; - let ty = tcx.item_type(def_id); + let ty = tcx.type_of(def_id); debug!("EntryBuilder::encode_item_type({:?}) => {:?}", def_id, ty); self.lazy(&ty) } @@ -261,7 +261,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { (enum_did, Untracked(index)): (DefId, Untracked)) -> Entry<'tcx> { let tcx = self.tcx; - let def = tcx.lookup_adt_def(enum_did); + let def = tcx.adt_def(enum_did); let variant = &def.variants[index]; let def_id = variant.did; debug!("EntryBuilder::encode_enum_variant_info({:?})", def_id); @@ -341,7 +341,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { fn encode_fields(&mut self, adt_def_id: DefId) { - let def = self.tcx.lookup_adt_def(adt_def_id); + let def = self.tcx.adt_def(adt_def_id); for (variant_index, variant) in def.variants.iter().enumerate() { for (field_index, field) in variant.fields.iter().enumerate() { self.record(field.did, @@ -365,7 +365,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { usize)>)) -> Entry<'tcx> { let tcx = self.tcx; - let variant = &tcx.lookup_adt_def(adt_def_id).variants[variant_index]; + let variant = &tcx.adt_def(adt_def_id).variants[variant_index]; let field = &variant.fields[field_index]; let def_id = field.did; @@ -397,7 +397,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { fn encode_struct_ctor(&mut self, (adt_def_id, def_id): (DefId, DefId)) -> Entry<'tcx> { debug!("EntryBuilder::encode_struct_ctor({:?})", def_id); let tcx = self.tcx; - let variant = tcx.lookup_adt_def(adt_def_id).struct_variant(); + let variant = tcx.adt_def(adt_def_id).struct_variant(); let data = VariantData { ctor_kind: variant.ctor_kind, @@ -439,13 +439,13 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { fn encode_generics(&mut self, def_id: DefId) -> Lazy { debug!("EntryBuilder::encode_generics({:?})", def_id); let tcx = self.tcx; - self.lazy(tcx.item_generics(def_id)) + self.lazy(tcx.generics_of(def_id)) } fn encode_predicates(&mut self, def_id: DefId) -> Lazy> { debug!("EntryBuilder::encode_predicates({:?})", def_id); let tcx = self.tcx; - self.lazy(&tcx.item_predicates(def_id)) + self.lazy(&tcx.predicates_of(def_id)) } fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> { @@ -570,7 +570,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { let (ast, mir) = if let hir::ImplItemKind::Const(_, body) = ast_item.node { (Some(body), true) } else if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node { - let generics = self.tcx.item_generics(def_id); + let generics = self.tcx.generics_of(def_id); let types = generics.parent_types as usize + generics.types.len(); let needs_inline = types > 0 || attr::requests_inline(&ast_item.attrs); let is_const_fn = sig.constness == hir::Constness::Const; @@ -674,7 +674,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { hir::ItemTy(..) => EntryKind::Type, hir::ItemEnum(..) => EntryKind::Enum(get_repr_options(&tcx, def_id)), hir::ItemStruct(ref struct_def, _) => { - let variant = tcx.lookup_adt_def(def_id).struct_variant(); + let variant = tcx.adt_def(def_id).struct_variant(); // Encode def_ids for each field and method // for methods, write all the stuff get_trait_method @@ -694,7 +694,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { }), repr_options) } hir::ItemUnion(..) => { - let variant = tcx.lookup_adt_def(def_id).struct_variant(); + let variant = tcx.adt_def(def_id).struct_variant(); let repr_options = get_repr_options(&tcx, def_id); EntryKind::Union(self.lazy(&VariantData { @@ -716,7 +716,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { hir::ItemImpl(_, polarity, ..) => { let trait_ref = tcx.impl_trait_ref(def_id); let parent = if let Some(trait_ref) = trait_ref { - let trait_def = tcx.lookup_trait_def(trait_ref.def_id); + let trait_def = tcx.trait_def(trait_ref.def_id); trait_def.ancestors(def_id).skip(1).next().and_then(|node| { match node { specialization_graph::Node::Impl(parent) => Some(parent), @@ -748,12 +748,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { EntryKind::Impl(self.lazy(&data)) } hir::ItemTrait(..) => { - let trait_def = tcx.lookup_trait_def(def_id); + let trait_def = tcx.trait_def(def_id); let data = TraitData { unsafety: trait_def.unsafety, paren_sugar: trait_def.paren_sugar, has_default_impl: tcx.trait_has_default_impl(def_id), - super_predicates: self.lazy(&tcx.item_super_predicates(def_id)), + super_predicates: self.lazy(&tcx.super_predicates_of(def_id)), }; EntryKind::Trait(self.lazy(&data)) @@ -774,7 +774,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { .map(|foreign_item| tcx.hir.local_def_id(foreign_item.id).index)) } hir::ItemEnum(..) => { - let def = self.tcx.lookup_adt_def(def_id); + let def = self.tcx.adt_def(def_id); self.lazy_seq(def.variants.iter().map(|v| { assert!(v.did.is_local()); v.did.index @@ -782,7 +782,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { } hir::ItemStruct(..) | hir::ItemUnion(..) => { - let def = self.tcx.lookup_adt_def(def_id); + let def = self.tcx.adt_def(def_id); self.lazy_seq(def.struct_variant().fields.iter().map(|f| { assert!(f.did.is_local()); f.did.index @@ -919,7 +919,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { hir::ItemEnum(..) => { self.encode_fields(def_id); - let def = self.tcx.lookup_adt_def(def_id); + let def = self.tcx.adt_def(def_id); for (i, variant) in def.variants.iter().enumerate() { self.record(variant.did, EntryBuilder::encode_enum_variant_info, @@ -1539,7 +1539,7 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } pub fn get_repr_options<'a, 'tcx, 'gcx>(tcx: &TyCtxt<'a, 'tcx, 'gcx>, did: DefId) -> ReprOptions { - let ty = tcx.item_type(did); + let ty = tcx.type_of(did); match ty.sty { ty::TyAdt(ref def, _) => return def.repr, _ => bug!("{} is not an ADT", ty), diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index dd4190a412dac..95b20560c62a1 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -784,7 +784,7 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, TerminatorKind::Call { func: Operand::Constant(Constant { span: data.span, - ty: tcx.item_type(free_func).subst(tcx, substs), + ty: tcx.type_of(free_func).subst(tcx, substs), literal: Literal::Value { value: ConstVal::Function(free_func, substs), } diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index db9da2a280b94..e73eaafc4b9fe 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -140,7 +140,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { let substs = self.tcx.mk_substs_trait(self_ty, params); for item in self.tcx.associated_items(trait_def_id) { if item.kind == ty::AssociatedKind::Method && item.name == method_name { - let method_ty = self.tcx.item_type(item.def_id); + let method_ty = self.tcx.type_of(item.def_id); let method_ty = method_ty.subst(self.tcx, substs); return (method_ty, Literal::Value { diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index 9dfe1a34c9ce0..77f5c8ff124df 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -139,7 +139,7 @@ fn build_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) // types/lifetimes replaced) let fn_sig = cx.tables().liberated_fn_sigs[&id].clone(); - let ty = tcx.item_type(tcx.hir.local_def_id(id)); + let ty = tcx.type_of(tcx.hir.local_def_id(id)); let mut abi = fn_sig.abi; let implicit_argument = if let ty::TyClosure(..) = ty.sty { // HACK(eddyb) Avoid having RustCall on closures, diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 7f7377e5ffe3f..9e57472c23657 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -167,7 +167,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>, } else { param_env.free_substs }; - let fn_ty = tcx.item_type(def_id).subst(tcx, substs); + let fn_ty = tcx.type_of(def_id).subst(tcx, substs); let sig = tcx.erase_late_bound_regions(&fn_ty.fn_sig()); let span = tcx.def_span(def_id); @@ -290,7 +290,7 @@ fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>, call_kind={:?}, untuple_args={:?})", def_id, rcvr_adjustment, call_kind, untuple_args); - let fn_ty = tcx.item_type(def_id).subst(tcx, param_env.free_substs); + let fn_ty = tcx.type_of(def_id).subst(tcx, param_env.free_substs); let sig = tcx.erase_late_bound_regions(&fn_ty.fn_sig()); let span = tcx.def_span(def_id); @@ -332,7 +332,7 @@ fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>, CallKind::Direct(def_id) => ( Operand::Constant(Constant { span: span, - ty: tcx.item_type(def_id).subst(tcx, param_env.free_substs), + ty: tcx.type_of(def_id).subst(tcx, param_env.free_substs), literal: Literal::Value { value: ConstVal::Function(def_id, param_env.free_substs), }, @@ -422,7 +422,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, { let tcx = infcx.tcx; let def_id = tcx.hir.local_def_id(ctor_id); - let sig = match tcx.item_type(def_id).sty { + let sig = match tcx.type_of(def_id).sty { ty::TyFnDef(_, _, fty) => tcx.no_late_bound_regions(&fty) .expect("LBR in ADT constructor signature"), _ => bug!("unexpected type for ctor {:?}", def_id) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 526c1488ab480..3ef611dd3cafb 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -258,7 +258,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { let mut span = None; self.tcx - .lookup_trait_def(drop_trait_id) + .trait_def(drop_trait_id) .for_each_relevant_impl(self.tcx, self.mir.return_ty, |impl_did| { self.tcx.hir .as_local_node_id(impl_did) diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index bfb08de56d8bb..d2e4c1a964983 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -133,7 +133,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { Lvalue::Local(index) => LvalueTy::Ty { ty: self.mir.local_decls[index].ty }, Lvalue::Static(box Static { def_id, ty: sty }) => { let sty = self.sanitize_type(lvalue, sty); - let ty = self.tcx().item_type(def_id); + let ty = self.tcx().type_of(def_id); let ty = self.cx.normalize(&ty); if let Err(terr) = self.cx.eq_types(self.last_span, ty, sty) { span_mirbug!( diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index fdb6752213378..f275b4cafaf93 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -130,7 +130,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> { }; let outer_tables = self.tables; - self.tables = self.tcx.item_tables(self.tcx.hir.local_def_id(item_id)); + self.tables = self.tcx.typeck_tables_of(self.tcx.hir.local_def_id(item_id)); let body = self.tcx.hir.body(body_id); if !self.in_fn { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 92f7e48b6be48..fb1c5738206cc 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -88,7 +88,7 @@ struct ReachEverythingInTheInterfaceVisitor<'b, 'a: 'b, 'tcx: 'a> { impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { fn item_ty_level(&self, item_def_id: DefId) -> Option { - let ty_def_id = match self.tcx.item_type(item_def_id).sty { + let ty_def_id = match self.tcx.type_of(item_def_id).sty { ty::TyAdt(adt, _) => adt.did, ty::TyDynamic(ref obj, ..) if obj.principal().is_some() => obj.principal().unwrap().def_id(), @@ -236,7 +236,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemFn(..) | hir::ItemTy(..) => { if item_level.is_some() { - self.reach(item.id).generics().predicates().item_type(); + self.reach(item.id).generics().predicates().ty(); } } hir::ItemTrait(.., ref trait_item_refs) => { @@ -251,7 +251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { !trait_item_ref.defaultness.has_value() { // No type to visit. } else { - reach.item_type(); + reach.ty(); } } } @@ -264,7 +264,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { for impl_item_ref in impl_item_refs { let id = impl_item_ref.id.node_id; if trait_ref.is_some() || self.get(id).is_some() { - self.reach(id).generics().predicates().item_type(); + self.reach(id).generics().predicates().ty(); } } } @@ -278,7 +278,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { for variant in &def.variants { if self.get(variant.node.data.id()).is_some() { for field in variant.node.data.fields() { - self.reach(field.id).item_type(); + self.reach(field.id).ty(); } // Corner case: if the variant is reachable, but its // enum is not, make the enum reachable as well. @@ -290,7 +290,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { if self.get(foreign_item.id).is_some() { - self.reach(foreign_item.id).generics().predicates().item_type(); + self.reach(foreign_item.id).generics().predicates().ty(); } } } @@ -301,7 +301,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { self.reach(item.id).generics().predicates(); for field in struct_def.fields() { if self.get(field.id).is_some() { - self.reach(field.id).item_type(); + self.reach(field.id).ty(); } } } @@ -351,7 +351,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { if let hir::TyImplTrait(..) = ty.node { if self.get(ty.id).is_some() { // Reach the (potentially private) type and the API being exposed. - self.reach(ty.id).item_type().predicates(); + self.reach(ty.id).ty().predicates(); } } @@ -361,21 +361,21 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> { fn generics(&mut self) -> &mut Self { - for def in &self.ev.tcx.item_generics(self.item_def_id).types { + for def in &self.ev.tcx.generics_of(self.item_def_id).types { if def.has_default { - self.ev.tcx.item_type(def.def_id).visit_with(self); + self.ev.tcx.type_of(def.def_id).visit_with(self); } } self } fn predicates(&mut self) -> &mut Self { - self.ev.tcx.item_predicates(self.item_def_id).visit_with(self); + self.ev.tcx.predicates_of(self.item_def_id).visit_with(self); self } - fn item_type(&mut self) -> &mut Self { - self.ev.tcx.item_type(self.item_def_id).visit_with(self); + fn ty(&mut self) -> &mut Self { + self.ev.tcx.type_of(self.item_def_id).visit_with(self); self } @@ -924,21 +924,21 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> { fn generics(&mut self) -> &mut Self { - for def in &self.tcx.item_generics(self.item_def_id).types { + for def in &self.tcx.generics_of(self.item_def_id).types { if def.has_default { - self.tcx.item_type(def.def_id).visit_with(self); + self.tcx.type_of(def.def_id).visit_with(self); } } self } fn predicates(&mut self) -> &mut Self { - self.tcx.item_predicates(self.item_def_id).visit_with(self); + self.tcx.predicates_of(self.item_def_id).visit_with(self); self } - fn item_type(&mut self) -> &mut Self { - self.tcx.item_type(self.item_def_id).visit_with(self); + fn ty(&mut self) -> &mut Self { + self.tcx.type_of(self.item_def_id).visit_with(self); self } @@ -1104,7 +1104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // Subitems of these items have inherited publicity hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemFn(..) | hir::ItemTy(..) => { - self.check(item.id, item_visibility).generics().predicates().item_type(); + self.check(item.id, item_visibility).generics().predicates().ty(); // Recurse for e.g. `impl Trait` (see `visit_ty`). self.inner_visibility = item_visibility; @@ -1121,7 +1121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> !trait_item_ref.defaultness.has_value() { // No type to visit. } else { - check.item_type(); + check.ty(); } } } @@ -1130,7 +1130,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> for variant in &def.variants { for field in variant.node.data.fields() { - self.check(field.id, item_visibility).item_type(); + self.check(field.id, item_visibility).ty(); } } } @@ -1138,7 +1138,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> hir::ItemForeignMod(ref foreign_mod) => { for foreign_item in &foreign_mod.items { let vis = ty::Visibility::from_hir(&foreign_item.vis, item.id, tcx); - self.check(foreign_item.id, vis).generics().predicates().item_type(); + self.check(foreign_item.id, vis).generics().predicates().ty(); } } // Subitems of structs and unions have their own publicity @@ -1148,7 +1148,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> for field in struct_def.fields() { let field_visibility = ty::Visibility::from_hir(&field.vis, item.id, tcx); - self.check(field.id, min(item_visibility, field_visibility)).item_type(); + self.check(field.id, min(item_visibility, field_visibility)).ty(); } } // The interface is empty @@ -1157,7 +1157,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // Subitems of inherent impls have their own publicity hir::ItemImpl(.., None, _, ref impl_item_refs) => { let ty_vis = - self.check(item.id, ty::Visibility::Invisible).item_type().min_visibility; + self.check(item.id, ty::Visibility::Invisible).ty().min_visibility; self.check(item.id, ty_vis).generics().predicates(); for impl_item_ref in impl_item_refs { @@ -1165,7 +1165,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> let impl_item_vis = ty::Visibility::from_hir(&impl_item.vis, item.id, tcx); self.check(impl_item.id, min(impl_item_vis, ty_vis)) - .generics().predicates().item_type(); + .generics().predicates().ty(); // Recurse for e.g. `impl Trait` (see `visit_ty`). self.inner_visibility = impl_item_vis; @@ -1176,11 +1176,11 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // Subitems of trait impls have inherited publicity hir::ItemImpl(.., Some(_), _, ref impl_item_refs) => { let vis = self.check(item.id, ty::Visibility::Invisible) - .item_type().impl_trait_ref().min_visibility; + .ty().impl_trait_ref().min_visibility; self.check(item.id, vis).generics().predicates(); for impl_item_ref in impl_item_refs { let impl_item = self.tcx.hir.impl_item(impl_item_ref.id); - self.check(impl_item.id, vis).generics().predicates().item_type(); + self.check(impl_item.id, vis).generics().predicates().ty(); // Recurse for e.g. `impl Trait` (see `visit_ty`). self.inner_visibility = vis; @@ -1200,7 +1200,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> // e.g. `impl Iterator` has two predicates, // `X: Iterator` and `::Item == T`, // where `X` is the `impl Iterator` itself, - // stored in `item_predicates`, not in the `Ty` itself. + // stored in `predicates_of`, not in the `Ty` itself. self.check(ty.id, self.inner_visibility).predicates(); } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 3e8f7e11b6b43..9e3e727d4bdcd 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -114,7 +114,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, D>) { let item_def_id = self.tcx.hir.local_def_id(item_id); - match self.tcx.maps.typeck_tables.borrow().get(&item_def_id) { + match self.tcx.maps.typeck_tables_of.borrow().get(&item_def_id) { Some(tables) => { let old_tables = self.save_ctxt.tables; self.save_ctxt.tables = tables; diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index d822f7bea3a30..e2c399e85cd59 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -341,7 +341,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon); filter!(self.span_utils, sub_span, field.span, None); let def_id = self.tcx.hir.local_def_id(field.id); - let typ = self.tcx.item_type(def_id).to_string(); + let typ = self.tcx.type_of(def_id).to_string(); let span = field.span; let text = self.span_utils.snippet(field.span); diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs index f21864764ddf1..a96128fcf2f53 100644 --- a/src/librustc_trans/back/symbol_names.rs +++ b/src/librustc_trans/back/symbol_names.rs @@ -232,7 +232,7 @@ pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>, match key.disambiguated_data.data { DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => { - instance_ty = tcx.item_type(ty_def_id); + instance_ty = tcx.type_of(ty_def_id); break; } _ => { diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index ba119bd9ef069..e8cca7bc74f1a 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -1041,7 +1041,7 @@ pub fn find_exported_symbols(tcx: TyCtxt, reachable: &NodeSet) -> NodeSet { hir_map::NodeImplItem(&hir::ImplItem { node: hir::ImplItemKind::Method(..), .. }) => { let def_id = tcx.hir.local_def_id(id); - let generics = tcx.item_generics(def_id); + let generics = tcx.generics_of(def_id); let attributes = tcx.get_attrs(def_id); (generics.parent_types == 0 && generics.types.is_empty()) && // Functions marked with #[inline] are only ever translated diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 13bb0d371250f..93ec7e11606df 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -935,14 +935,14 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, ' continue; } - if !tcx.item_generics(method.def_id).types.is_empty() { + if !tcx.generics_of(method.def_id).types.is_empty() { continue; } let instance = monomorphize::resolve(scx, method.def_id, callee_substs); - let predicates = tcx.item_predicates(instance.def_id()).predicates + let predicates = tcx.predicates_of(instance.def_id()).predicates .subst(tcx, instance.substs); if !traits::normalize_and_test_predicates(tcx, predicates) { continue; diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 648ea92c84376..025062f7ddef9 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -563,7 +563,7 @@ pub fn def_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> { - let ty = shared.tcx().item_type(def_id); + let ty = shared.tcx().type_of(def_id); shared.tcx().trans_apply_param_substs(substs, &ty) } diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs index 1b7cf26853bc1..982ea5ffeb70b 100644 --- a/src/librustc_trans/debuginfo/mod.rs +++ b/src/librustc_trans/debuginfo/mod.rs @@ -237,7 +237,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, // Get_template_parameters() will append a `<...>` clause to the function // name if necessary. - let generics = cx.tcx().item_generics(fn_def_id); + let generics = cx.tcx().generics_of(fn_def_id); let substs = instance.substs.truncate_to(cx.tcx(), generics); let template_parameters = get_template_parameters(cx, &generics, @@ -382,7 +382,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fn get_type_parameter_names(cx: &CrateContext, generics: &ty::Generics) -> Vec { let mut names = generics.parent.map_or(vec![], |def_id| { - get_type_parameter_names(cx, cx.tcx().item_generics(def_id)) + get_type_parameter_names(cx, cx.tcx().generics_of(def_id)) }); names.extend(generics.types.iter().map(|param| param.name)); names diff --git a/src/librustc_trans/trans_item.rs b/src/librustc_trans/trans_item.rs index de35d1b7dd4c9..d8e139dc505b6 100644 --- a/src/librustc_trans/trans_item.rs +++ b/src/librustc_trans/trans_item.rs @@ -444,7 +444,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> { }, ty::TyClosure(def_id, ref closure_substs) => { self.push_def_path(def_id, output); - let generics = self.tcx.item_generics(self.tcx.closure_base_def_id(def_id)); + let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id)); let substs = closure_substs.substs.truncate_to(self.tcx, generics); self.push_type_params(substs, iter::empty(), output); } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 5137ae6ff4222..c186589989443 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -217,7 +217,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { // If the type is parameterized by this region, then replace this // region with the current anon region binding (in other words, // whatever & would get replaced with). - let decl_generics = tcx.item_generics(def_id); + let decl_generics = tcx.generics_of(def_id); let expected_num_region_params = decl_generics.regions.len(); let supplied_num_region_params = lifetimes.len(); if expected_num_region_params != supplied_num_region_params { @@ -238,7 +238,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF); let default_needs_object_self = |p: &ty::TypeParameterDef| { if is_object && p.has_default { - if ty::queries::ty::get(tcx, span, p.def_id).has_self_ty() { + if ty::queries::type_of::get(tcx, span, p.def_id).has_self_ty() { // There is no suitable inference default for a type parameter // that references self, in an object type. return true; @@ -307,7 +307,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { // This is a default type parameter. self.normalize_ty( span, - ty::queries::ty::get(tcx, span, def.def_id) + ty::queries::type_of::get(tcx, span, def.def_id) .subst_spanned(tcx, substs, Some(span)) ) } @@ -458,7 +458,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { debug!("create_substs_for_ast_trait_ref(trait_segment={:?})", trait_segment); - let trait_def = self.tcx().lookup_trait_def(trait_def_id); + let trait_def = self.tcx().trait_def(trait_def_id); match trait_segment.parameters { hir::AngleBracketedParameters(_) => { @@ -600,7 +600,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let substs = self.ast_path_substs_for_ty(span, did, item_segment); self.normalize_ty( span, - ty::queries::ty::get(self.tcx(), span, did).subst(self.tcx(), substs) + ty::queries::type_of::get(self.tcx(), span, did).subst(self.tcx(), substs) ) } @@ -1008,7 +1008,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let node_id = tcx.hir.as_local_node_id(did).unwrap(); let item_id = tcx.hir.get_parent_node(node_id); let item_def_id = tcx.hir.local_def_id(item_id); - let generics = tcx.item_generics(item_def_id); + let generics = tcx.generics_of(item_def_id); let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index]; tcx.mk_param(index, tcx.hir.name(node_id)) } @@ -1018,7 +1018,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { assert_eq!(opt_self_ty, None); self.prohibit_type_params(&path.segments); - let ty = ty::queries::ty::get(tcx, span, def_id); + let ty = ty::queries::type_of::get(tcx, span, def_id); if let Some(free_substs) = self.get_free_substs() { ty.subst(tcx, free_substs) } else { diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index ae70049cc5bdc..a38840552c23c 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -180,10 +180,10 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, debug!("compare_impl_method: trait_to_skol_substs={:?}", trait_to_skol_substs); - let impl_m_generics = tcx.item_generics(impl_m.def_id); - let trait_m_generics = tcx.item_generics(trait_m.def_id); - let impl_m_predicates = tcx.item_predicates(impl_m.def_id); - let trait_m_predicates = tcx.item_predicates(trait_m.def_id); + let impl_m_generics = tcx.generics_of(impl_m.def_id); + let trait_m_generics = tcx.generics_of(trait_m.def_id); + let impl_m_predicates = tcx.predicates_of(impl_m.def_id); + let trait_m_predicates = tcx.predicates_of(trait_m.def_id); // Check region bounds. check_region_bounds_on_impl_method(tcx, @@ -199,7 +199,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // environment. We can't just use `impl_env.caller_bounds`, // however, because we want to replace all late-bound regions with // region variables. - let impl_predicates = tcx.item_predicates(impl_m_predicates.parent.unwrap()); + let impl_predicates = tcx.predicates_of(impl_m_predicates.parent.unwrap()); let mut hybrid_preds = impl_predicates.instantiate(tcx, impl_to_skol_substs); debug!("compare_impl_method: impl_bounds={:?}", hybrid_preds); @@ -261,7 +261,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let tcx = infcx.tcx; let m_sig = |method: &ty::AssociatedItem| { - match tcx.item_type(method.def_id).sty { + match tcx.type_of(method.def_id).sty { ty::TyFnDef(_, _, f) => f, _ => bug!() } @@ -509,7 +509,7 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty::ImplContainer(_) => impl_trait_ref.self_ty(), ty::TraitContainer(_) => tcx.mk_self_type() }; - let method_ty = tcx.item_type(method.def_id); + let method_ty = tcx.type_of(method.def_id); let self_arg_ty = *method_ty.fn_sig().input(0).skip_binder(); match ExplicitSelf::determine(untransformed_self_ty, self_arg_ty) { ExplicitSelf::ByValue => "self".to_string(), @@ -567,8 +567,8 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_m: &ty::AssociatedItem, trait_item_span: Option) -> Result<(), ErrorReported> { - let impl_m_generics = tcx.item_generics(impl_m.def_id); - let trait_m_generics = tcx.item_generics(trait_m.def_id); + let impl_m_generics = tcx.generics_of(impl_m.def_id); + let trait_m_generics = tcx.generics_of(trait_m.def_id); let num_impl_m_type_params = impl_m_generics.types.len(); let num_trait_m_type_params = trait_m_generics.types.len(); if num_impl_m_type_params != num_trait_m_type_params { @@ -637,7 +637,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_span: Option) -> Result<(), ErrorReported> { let m_fty = |method: &ty::AssociatedItem| { - match tcx.item_type(method.def_id).sty { + match tcx.type_of(method.def_id).sty { ty::TyFnDef(_, _, f) => f, _ => bug!() } @@ -750,8 +750,8 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_to_skol_substs); // Compute skolemized form of impl and trait const tys. - let impl_ty = tcx.item_type(impl_c.def_id).subst(tcx, impl_to_skol_substs); - let trait_ty = tcx.item_type(trait_c.def_id).subst(tcx, trait_to_skol_substs); + let impl_ty = tcx.type_of(impl_c.def_id).subst(tcx, impl_to_skol_substs); + let trait_ty = tcx.type_of(trait_c.def_id).subst(tcx, trait_to_skol_substs); let mut cause = ObligationCause::misc(impl_c_span, impl_c_node_id); // There is no "body" here, so just pass dummy id. diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 4cc3f2dacdfe9..d92dafe690459 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -135,7 +135,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn has_no_input_arg(&self, method: &AssociatedItem) -> bool { match method.def() { Def::Method(def_id) => { - match self.tcx.item_type(def_id).sty { + match self.tcx.type_of(def_id).sty { ty::TypeVariants::TyFnDef(_, _, sig) => { sig.inputs().skip_binder().len() == 1 } diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index c125d7c02556f..8d26f00742975 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -42,8 +42,8 @@ use syntax_pos::Span; pub fn check_drop_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, drop_impl_did: DefId) -> Result<(), ErrorReported> { - let dtor_self_type = tcx.item_type(drop_impl_did); - let dtor_predicates = tcx.item_predicates(drop_impl_did); + let dtor_self_type = tcx.type_of(drop_impl_did); + let dtor_predicates = tcx.predicates_of(drop_impl_did); match dtor_self_type.sty { ty::TyAdt(adt_def, self_to_impl_substs) => { ensure_drop_params_and_item_params_correspond(tcx, @@ -85,7 +85,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>( let tcx = infcx.tcx; let mut fulfillment_cx = traits::FulfillmentContext::new(); - let named_type = tcx.item_type(self_type_did); + let named_type = tcx.type_of(self_type_did); let named_type = named_type.subst(tcx, &infcx.parameter_environment.free_substs); let drop_impl_span = tcx.def_span(drop_impl_did); @@ -175,7 +175,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // We can assume the predicates attached to struct/enum definition // hold. - let generic_assumptions = tcx.item_predicates(self_type_did); + let generic_assumptions = tcx.predicates_of(self_type_did); let assumptions_in_impl_context = generic_assumptions.instantiate(tcx, &self_to_impl_substs); let assumptions_in_impl_context = assumptions_in_impl_context.predicates; diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index bf7649242fa71..2a97bc1d98fe9 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -46,7 +46,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir::Unsafety::Unsafe, abi ))); - let i_n_tps = tcx.item_generics(def_id).types.len(); + let i_n_tps = tcx.generics_of(def_id).types.len(); if i_n_tps != n_tps { let span = match it.node { hir::ForeignItemFn(_, _, ref generics) => generics.span, @@ -64,7 +64,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, &ObligationCause::new(it.span, it.id, ObligationCauseCode::IntrinsicType), - tcx.item_type(def_id), + tcx.type_of(def_id), fty); } } @@ -324,7 +324,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; let def_id = tcx.hir.local_def_id(it.id); - let i_n_tps = tcx.item_generics(def_id).types.len(); + let i_n_tps = tcx.generics_of(def_id).types.len(); let name = it.name.as_str(); let (n_tps, inputs, output) = match &*name { @@ -367,7 +367,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut structural_to_nomimal = FxHashMap(); - let sig = tcx.item_type(def_id).fn_sig(); + let sig = tcx.type_of(def_id).fn_sig(); let sig = tcx.no_late_bound_regions(&sig).unwrap(); if intr.inputs.len() != sig.inputs().len() { span_err!(tcx.sess, it.span, E0444, diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 26ba965fe5cc6..f0a74ea4be92c 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -276,7 +276,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // If they were not explicitly supplied, just construct fresh // variables. let num_supplied_types = supplied_method_types.len(); - let method_generics = self.tcx.item_generics(pick.item.def_id); + let method_generics = self.tcx.generics_of(pick.item.def_id); let num_method_types = method_generics.types.len(); if num_supplied_types > 0 && num_supplied_types != num_method_types { @@ -358,14 +358,14 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // type/early-bound-regions substitutions performed. There can // be no late-bound regions appearing here. let def_id = pick.item.def_id; - let method_predicates = self.tcx.item_predicates(def_id) + let method_predicates = self.tcx.predicates_of(def_id) .instantiate(self.tcx, all_substs); let method_predicates = self.normalize_associated_types_in(self.span, &method_predicates); debug!("method_predicates after subst = {:?}", method_predicates); - let sig = self.tcx.item_type(def_id).fn_sig(); + let sig = self.tcx.type_of(def_id).fn_sig(); // Instantiate late-bound regions and substitute the trait // parameters into the method type to get the actual method type. diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 7dd2699a6eaf0..951683e7ffc90 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -232,7 +232,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let tcx = self.tcx; let method_item = self.associated_item(trait_def_id, m_name).unwrap(); let def_id = method_item.def_id; - let generics = tcx.item_generics(def_id); + let generics = tcx.generics_of(def_id); assert_eq!(generics.types.len(), 0); assert_eq!(generics.regions.len(), 0); @@ -245,7 +245,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // NB: Instantiate late-bound regions first so that // `instantiate_type_scheme` can normalize associated types that // may reference those regions. - let original_method_ty = tcx.item_type(def_id); + let original_method_ty = tcx.type_of(def_id); let fn_sig = original_method_ty.fn_sig(); let fn_sig = self.replace_late_bound_regions_with_fresh_var(span, infer::FnCall, @@ -272,7 +272,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // // Note that as the method comes from a trait, it should not have // any late-bound regions appearing in its bounds. - let bounds = self.tcx.item_predicates(def_id).instantiate(self.tcx, substs); + let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, substs); let bounds = match self.normalize_associated_types_in_as_infer_ok(span, &bounds) { InferOk { value, obligations: o } => { obligations.extend(o); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 80f9372eb54c4..6dd4fb7301bc3 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -661,7 +661,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { expected: ty::Ty<'tcx>) -> bool { match method.def() { Def::Method(def_id) => { - let fty = self.tcx.item_type(def_id).fn_sig(); + let fty = self.tcx.type_of(def_id).fn_sig(); self.probe(|_| { let substs = self.fresh_substs_for_item(self.span, method.def_id); let output = fty.output().subst(self.tcx, substs); @@ -706,7 +706,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { import_id: Option, trait_def_id: DefId, item: ty::AssociatedItem) { - let trait_def = self.tcx.lookup_trait_def(trait_def_id); + let trait_def = self.tcx.trait_def(trait_def_id); // FIXME(arielb1): can we use for_each_relevant_impl here? trait_def.for_each_impl(self.tcx, |impl_def_id| { @@ -760,7 +760,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } }; - let impl_type = self.tcx.item_type(impl_def_id); + let impl_type = self.tcx.type_of(impl_def_id); let impl_simplified_type = match ty::fast_reject::simplify_type(self.tcx, impl_type, false) { Some(simplified_type) => simplified_type, @@ -867,7 +867,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { def_id, substs); - let trait_predicates = self.tcx.item_predicates(def_id); + let trait_predicates = self.tcx.predicates_of(def_id); let bounds = trait_predicates.instantiate(self.tcx, substs); let predicates = bounds.predicates; debug!("assemble_projection_candidates: predicates={:?}", @@ -1185,7 +1185,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { let cause = traits::ObligationCause::misc(self.span, self.body_id); // Check whether the impl imposes obligations we have to worry about. - let impl_bounds = self.tcx.item_predicates(impl_def_id); + let impl_bounds = self.tcx.predicates_of(impl_def_id); let impl_bounds = impl_bounds.instantiate(self.tcx, substs); let traits::Normalized { value: impl_bounds, obligations: norm_obligations } = traits::normalize(selcx, cause.clone(), &impl_bounds); @@ -1294,7 +1294,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { impl_ty: Ty<'tcx>, substs: &Substs<'tcx>) -> Ty<'tcx> { - let self_ty = self.tcx.item_type(method).fn_sig().input(0); + let self_ty = self.tcx.type_of(method).fn_sig().input(0); debug!("xform_self_ty(impl_ty={:?}, self_ty={:?}, substs={:?})", impl_ty, self_ty, @@ -1307,7 +1307,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { // are given do not include type/lifetime parameters for the // method yet. So create fresh variables here for those too, // if there are any. - let generics = self.tcx.item_generics(method); + let generics = self.tcx.generics_of(method); assert_eq!(substs.types().count(), generics.parent_types as usize); assert_eq!(substs.regions().count(), generics.parent_regions as usize); @@ -1341,7 +1341,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { /// Get the type of an impl and generate substitutions with placeholders. fn impl_ty_and_substs(&self, impl_def_id: DefId) -> (Ty<'tcx>, &'tcx Substs<'tcx>) { - let impl_ty = self.tcx.item_type(impl_def_id); + let impl_ty = self.tcx.type_of(impl_def_id); let substs = Substs::for_item(self.tcx, impl_def_id, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 098e8c53a52c1..a27397fa444d8 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -628,7 +628,7 @@ fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum debug_assert!(crate_num == LOCAL_CRATE); tcx.sess.track_errors(|| { tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| { - tcx.item_tables(body_owner_def_id); + tcx.typeck_tables_of(body_owner_def_id); }); }) } @@ -636,7 +636,7 @@ fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum pub fn provide(providers: &mut Providers) { *providers = Providers { typeck_item_bodies, - typeck_tables, + typeck_tables_of, closure_type, closure_kind, adt_destructor, @@ -648,14 +648,14 @@ fn closure_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - tcx.item_tables(def_id).closure_tys[&node_id] + tcx.typeck_tables_of(def_id).closure_tys[&node_id] } fn closure_kind<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::ClosureKind { let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - tcx.item_tables(def_id).closure_kinds[&node_id] + tcx.typeck_tables_of(def_id).closure_kinds[&node_id] } fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -664,14 +664,14 @@ fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.calculate_dtor(def_id, &mut dropck::check_drop_impl) } -fn typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, +fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TypeckTables<'tcx> { // Closures' tables come from their outermost function, // as they are part of the same "inference environment". let outer_def_id = tcx.closure_base_def_id(def_id); if outer_def_id != def_id { - return tcx.item_tables(outer_def_id); + return tcx.typeck_tables_of(outer_def_id); } let id = tcx.hir.as_local_node_id(def_id).unwrap(); @@ -736,7 +736,7 @@ fn typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, Inherited::build(tcx, id).enter(|inh| { let fcx = if let Some(decl) = fn_decl { - let fn_sig = tcx.item_type(def_id).fn_sig(); + let fn_sig = tcx.type_of(def_id).fn_sig(); check_abi(tcx, span, fn_sig.abi()); @@ -752,7 +752,7 @@ fn typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, check_fn(&inh, fn_sig, decl, id, body) } else { let fcx = FnCtxt::new(&inh, body.value.id); - let expected_type = tcx.item_type(def_id); + let expected_type = tcx.type_of(def_id); let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type); fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized); @@ -946,7 +946,7 @@ fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: ast::NodeId, span: Span) { let def_id = tcx.hir.local_def_id(id); - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated check_representable(tcx, span, def_id); @@ -956,7 +956,7 @@ fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // if struct is packed and not aligned, check fields for alignment. // Checks for combining packed and align attrs on single struct are done elsewhere. - if tcx.lookup_adt_def(def_id).repr.packed() && tcx.lookup_adt_def(def_id).repr.align == 0 { + if tcx.adt_def(def_id).repr.packed() && tcx.adt_def(def_id).repr.align == 0 { check_packed(tcx, span, def_id); } } @@ -965,7 +965,7 @@ fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: ast::NodeId, span: Span) { let def_id = tcx.hir.local_def_id(id); - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated check_representable(tcx, span, def_id); } @@ -979,7 +979,7 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item // Consts can play a role in type-checking, so they are included here. hir::ItemStatic(..) | hir::ItemConst(..) => { - tcx.item_tables(tcx.hir.local_def_id(it.id)); + tcx.typeck_tables_of(tcx.hir.local_def_id(it.id)); } hir::ItemEnum(ref enum_definition, _) => { check_enum(tcx, @@ -1013,7 +1013,7 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item } hir::ItemTy(_, ref generics) => { let def_id = tcx.hir.local_def_id(it.id); - let pty_ty = tcx.item_type(def_id); + let pty_ty = tcx.type_of(def_id); check_bounds_are_used(tcx, generics, pty_ty); } hir::ItemForeignMod(ref m) => { @@ -1029,7 +1029,7 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item } } else { for item in &m.items { - let generics = tcx.item_generics(tcx.hir.local_def_id(item.id)); + let generics = tcx.generics_of(tcx.hir.local_def_id(item.id)); if !generics.types.is_empty() { let mut err = struct_span_err!(tcx.sess, item.span, E0044, "foreign items may not have type parameters"); @@ -1052,7 +1052,7 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item fn check_on_unimplemented<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, item: &hir::Item) { - let generics = tcx.item_generics(def_id); + let generics = tcx.generics_of(def_id); if let Some(ref attr) = item.attrs.iter().find(|a| { a.check_name("rustc_on_unimplemented") }) { @@ -1159,7 +1159,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if impl_trait_ref.references_error() { return; } // Locate trait definition and items - let trait_def = tcx.lookup_trait_def(impl_trait_ref.def_id); + let trait_def = tcx.trait_def(impl_trait_ref.def_id); let mut overridden_associated_type = None; let impl_items = || impl_item_refs.iter().map(|iiref| tcx.hir.impl_item(iiref.id)); @@ -1280,11 +1280,11 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let signature = |item: &ty::AssociatedItem| { match item.kind { ty::AssociatedKind::Method => { - format!("{}", tcx.item_type(item.def_id).fn_sig().0) + format!("{}", tcx.type_of(item.def_id).fn_sig().0) } ty::AssociatedKind::Type => format!("type {};", item.name.to_string()), ty::AssociatedKind::Const => { - format!("const {}: {:?};", item.name.to_string(), tcx.item_type(item.def_id)) + format!("const {}: {:?};", item.name.to_string(), tcx.type_of(item.def_id)) } } }; @@ -1330,7 +1330,7 @@ fn check_representable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, item_def_id: DefId) -> bool { - let rty = tcx.item_type(item_def_id); + let rty = tcx.type_of(item_def_id); // Check that it is possible to represent this type. This call identifies // (1) types that contain themselves and (2) types that contain a different @@ -1348,7 +1348,7 @@ fn check_representable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId) { - let t = tcx.item_type(def_id); + let t = tcx.type_of(def_id); match t.sty { ty::TyAdt(def, substs) if def.is_struct() => { let fields = &def.struct_variant().fields; @@ -1387,14 +1387,14 @@ fn check_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId) fn check_packed_inner<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, stack: &mut Vec) -> bool { - let t = tcx.item_type(def_id); + let t = tcx.type_of(def_id); if stack.contains(&def_id) { debug!("check_packed_inner: {:?} is recursive", t); return false; } match t.sty { ty::TyAdt(def, substs) if def.is_struct() => { - if tcx.lookup_adt_def(def.did).repr.align > 0 { + if tcx.adt_def(def.did).repr.align > 0 { return true; } // push struct def_id before checking fields @@ -1424,7 +1424,7 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, vs: &'tcx [hir::Variant], id: ast::NodeId) { let def_id = tcx.hir.local_def_id(id); - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); def.destructor(tcx); // force the destructor to be evaluated if vs.is_empty() && tcx.has_attr(def_id, "repr") { @@ -1445,7 +1445,7 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for v in vs { if let Some(e) = v.node.disr_expr { - tcx.item_tables(tcx.hir.local_def_id(e.node_id)); + tcx.typeck_tables_of(tcx.hir.local_def_id(e.node_id)); } } @@ -1493,7 +1493,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); let item_id = tcx.hir.ty_param_owner(node_id); let item_def_id = tcx.hir.local_def_id(item_id); - let generics = tcx.item_generics(item_def_id); + let generics = tcx.generics_of(item_def_id); let index = generics.type_param_to_index[&def_id.index]; ty::GenericPredicates { parent: None, @@ -1792,7 +1792,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// generic type scheme. fn instantiate_bounds(&self, span: Span, def_id: DefId, substs: &Substs<'tcx>) -> ty::InstantiatedPredicates<'tcx> { - let bounds = self.tcx.item_predicates(def_id); + let bounds = self.tcx.predicates_of(def_id); let result = bounds.instantiate(self.tcx, substs); let result = self.normalize_associated_types_in(span, &result); debug!("instantiate_bounds(bounds={:?}, substs={:?}) = {:?}", @@ -1817,8 +1817,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let ty_var = self.next_ty_var(TypeVariableOrigin::TypeInference(span)); self.anon_types.borrow_mut().insert(id, ty_var); - let item_predicates = self.tcx.item_predicates(def_id); - let bounds = item_predicates.instantiate(self.tcx, substs); + let predicates_of = self.tcx.predicates_of(def_id); + let bounds = predicates_of.instantiate(self.tcx, substs); for predicate in bounds.predicates { // Change the predicate to refer to the type variable, @@ -2614,7 +2614,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { span: Span, // (potential) receiver for this impl did: DefId) -> TypeAndSubsts<'tcx> { - let ity = self.tcx.item_type(did); + let ity = self.tcx.type_of(did); debug!("impl_self_ty: ity={:?}", ity); let substs = self.fresh_substs_for_item(span, did); @@ -4208,11 +4208,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Def::VariantCtor(def_id, ..) => { // Everything but the final segment should have no // parameters at all. - let mut generics = self.tcx.item_generics(def_id); + let mut generics = self.tcx.generics_of(def_id); if let Some(def_id) = generics.parent { // Variant and struct constructors use the // generics of their parent type definition. - generics = self.tcx.item_generics(def_id); + generics = self.tcx.generics_of(def_id); } type_segment = Some((segments.last().unwrap(), generics)); } @@ -4222,7 +4222,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Def::Const(def_id) | Def::Static(def_id, _) => { fn_segment = Some((segments.last().unwrap(), - self.tcx.item_generics(def_id))); + self.tcx.generics_of(def_id))); } // Case 3. Reference to a method or associated const. @@ -4236,9 +4236,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty::ImplContainer(_) => {} } - let generics = self.tcx.item_generics(def_id); + let generics = self.tcx.generics_of(def_id); if segments.len() >= 2 { - let parent_generics = self.tcx.item_generics(generics.parent.unwrap()); + let parent_generics = self.tcx.generics_of(generics.parent.unwrap()); type_segment = Some((&segments[segments.len() - 2], parent_generics)); } else { // `::assoc` will end up here, and so can `T::assoc`. @@ -4351,7 +4351,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.to_ty(ast_ty) } else if !infer_types && def.has_default { // No type parameter provided, but a default exists. - let default = self.tcx.item_type(def.def_id); + let default = self.tcx.type_of(def.def_id); self.normalize_ty( span, default.subst_spanned(self.tcx, substs, Some(span)) @@ -4367,7 +4367,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // The things we are substituting into the type should not contain // escaping late-bound regions, and nor should the base type scheme. - let ty = self.tcx.item_type(def.def_id()); + let ty = self.tcx.type_of(def.def_id()); assert!(!substs.has_escaping_regions()); assert!(!ty.has_escaping_regions()); @@ -4387,7 +4387,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // is inherent, there is no `Self` parameter, instead, the impl needs // type parameters, which we can infer by unifying the provided `Self` // with the substituted impl type. - let ty = self.tcx.item_type(impl_def_id); + let ty = self.tcx.type_of(impl_def_id); let impl_ty = self.instantiate_type_scheme(span, &substs, &ty); match self.sub_types(false, &self.misc(span), self_ty, impl_ty) { diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index dcef22da87964..3508ddbe5f489 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -1725,7 +1725,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { // ``` // // we can thus deduce that `>::SomeType : 'a`. - let trait_predicates = self.tcx.item_predicates(projection_ty.trait_ref.def_id); + let trait_predicates = self.tcx.predicates_of(projection_ty.trait_ref.def_id); assert_eq!(trait_predicates.parent, None); let predicates = trait_predicates.predicates.as_slice().to_vec(); traits::elaborate_predicates(self.tcx, predicates) diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 85c87adf9be68..5bb45cbb1ae8a 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -168,18 +168,18 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { let (mut implied_bounds, self_ty) = match item.container { ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()), ty::ImplContainer(def_id) => (fcx.impl_implied_bounds(def_id, span), - fcx.tcx.item_type(def_id)) + fcx.tcx.type_of(def_id)) }; match item.kind { ty::AssociatedKind::Const => { - let ty = fcx.tcx.item_type(item.def_id); + let ty = fcx.tcx.type_of(item.def_id); let ty = fcx.instantiate_type_scheme(span, free_substs, &ty); fcx.register_wf_obligation(ty, span, code.clone()); } ty::AssociatedKind::Method => { reject_shadowing_type_parameters(fcx.tcx, item.def_id); - let method_ty = fcx.tcx.item_type(item.def_id); + let method_ty = fcx.tcx.type_of(item.def_id); let method_ty = fcx.instantiate_type_scheme(span, free_substs, &method_ty); let predicates = fcx.instantiate_bounds(span, item.def_id, free_substs); let sig = method_ty.fn_sig(); @@ -191,7 +191,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { } ty::AssociatedKind::Type => { if item.defaultness.has_value() { - let ty = fcx.tcx.item_type(item.def_id); + let ty = fcx.tcx.type_of(item.def_id); let ty = fcx.instantiate_type_scheme(span, free_substs, &ty); fcx.register_wf_obligation(ty, span, code.clone()); } @@ -262,7 +262,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { // // 3) that the trait definition does not have any type parameters - let predicates = self.tcx.item_predicates(trait_def_id); + let predicates = self.tcx.predicates_of(trait_def_id); // We must exclude the Self : Trait predicate contained by all // traits. @@ -277,7 +277,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { } }); - let has_ty_params = self.tcx.item_generics(trait_def_id).types.len() > 1; + let has_ty_params = self.tcx.generics_of(trait_def_id).types.len() > 1; // We use an if-else here, since the generics will also trigger // an extraneous error message when we find predicates like @@ -334,7 +334,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { self.for_item(item).with_fcx(|fcx, this| { let free_substs = &fcx.parameter_environment.free_substs; let def_id = fcx.tcx.hir.local_def_id(item.id); - let ty = fcx.tcx.item_type(def_id); + let ty = fcx.tcx.type_of(def_id); let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &ty); let sig = item_ty.fn_sig(); @@ -354,7 +354,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { debug!("check_item_type: {:?}", item); self.for_item(item).with_fcx(|fcx, this| { - let ty = fcx.tcx.item_type(fcx.tcx.hir.local_def_id(item.id)); + let ty = fcx.tcx.type_of(fcx.tcx.hir.local_def_id(item.id)); let item_ty = fcx.instantiate_type_scheme(item.span, &fcx.parameter_environment .free_substs, @@ -393,7 +393,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { } } None => { - let self_ty = fcx.tcx.item_type(item_def_id); + let self_ty = fcx.tcx.type_of(item_def_id); let self_ty = fcx.instantiate_type_scheme(item.span, free_substs, &self_ty); fcx.register_wf_obligation(self_ty, ast_self_ty.span, this.code.clone()); } @@ -468,7 +468,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { let span = method_sig.decl.inputs[0].span; let free_substs = &fcx.parameter_environment.free_substs; - let method_ty = fcx.tcx.item_type(method.def_id); + let method_ty = fcx.tcx.type_of(method.def_id); let fty = fcx.instantiate_type_scheme(span, free_substs, &method_ty); let sig = fcx.tcx.liberate_late_bound_regions(free_id_outlive, &fty.fn_sig()); @@ -502,14 +502,14 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { ast_generics: &hir::Generics) { let item_def_id = self.tcx.hir.local_def_id(item.id); - let ty = self.tcx.item_type(item_def_id); + let ty = self.tcx.type_of(item_def_id); if self.tcx.has_error_field(ty) { return; } - let ty_predicates = self.tcx.item_predicates(item_def_id); + let ty_predicates = self.tcx.predicates_of(item_def_id); assert_eq!(ty_predicates.parent, None); - let variances = self.tcx.item_variances(item_def_id); + let variances = self.tcx.variances_of(item_def_id); let mut constrained_parameters: FxHashSet<_> = variances.iter().enumerate() @@ -561,8 +561,8 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> { } fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) { - let generics = tcx.item_generics(def_id); - let parent = tcx.item_generics(generics.parent.unwrap()); + let generics = tcx.generics_of(def_id); + let parent = tcx.generics_of(generics.parent.unwrap()); let impl_params: FxHashMap<_, _> = parent.types .iter() .map(|tp| (tp.name, tp.def_id)) @@ -631,7 +631,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let fields = struct_def.fields().iter() .map(|field| { - let field_ty = self.tcx.item_type(self.tcx.hir.local_def_id(field.id)); + let field_ty = self.tcx.type_of(self.tcx.hir.local_def_id(field.id)); let field_ty = self.instantiate_type_scheme(field.span, &self.parameter_environment .free_substs, @@ -660,7 +660,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None => { // Inherent impl: take implied bounds from the self type. - let self_ty = self.tcx.item_type(impl_def_id); + let self_ty = self.tcx.type_of(impl_def_id); let self_ty = self.instantiate_type_scheme(span, free_substs, &self_ty); vec![self_ty] } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index c9479c5cebc3e..a985ac61cb3a9 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -67,7 +67,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let item_def_id = tcx.hir.local_def_id(item_id); // this will have been written by the main typeck pass - if let Some(tables) = tcx.maps.typeck_tables.borrow().get(&item_def_id) { + if let Some(tables) = tcx.maps.typeck_tables_of.borrow().get(&item_def_id) { let imports = &tables.used_trait_imports; debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports); used_trait_imports.extend(imports); diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 47b41a75cf531..9377695376837 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -57,7 +57,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, _drop_did: DefId, impl_did: DefId) { - match tcx.item_type(impl_did).sty { + match tcx.type_of(impl_did).sty { ty::TyAdt(..) => {} _ => { // Destructors only work on nominal types. @@ -101,7 +101,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return; }; - let self_type = tcx.item_type(impl_did); + let self_type = tcx.type_of(impl_did); debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); @@ -192,7 +192,7 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, bug!("coerce_unsized_info: invoked for non-local def-id {:?}", impl_did) }); - let source = tcx.item_type(impl_did); + let source = tcx.type_of(impl_did); let trait_ref = tcx.impl_trait_ref(impl_did).unwrap(); assert_eq!(trait_ref.def_id, coerce_unsized_trait); let target = trait_ref.substs.type_at(1); @@ -259,7 +259,7 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, .filter_map(|(i, f)| { let (a, b) = (f.ty(tcx, substs_a), f.ty(tcx, substs_b)); - if tcx.item_type(f.did).is_phantom_data() { + if tcx.type_of(f.did).is_phantom_data() { // Ignore PhantomData fields return None; } diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index dc4bd7733fc21..58603900e135e 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for InherentCollect<'a, 'tcx> { } let def_id = self.tcx.hir.local_def_id(item.id); - let self_ty = self.tcx.item_type(def_id); + let self_ty = self.tcx.type_of(def_id); match self_ty.sty { ty::TyAdt(def, _) => { self.check_def_id(item, def.did); diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index b385ddc49c1ee..abfee989d65f6 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -47,7 +47,7 @@ fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) { } enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id); - let trait_def = tcx.lookup_trait_def(trait_ref.def_id); + let trait_def = tcx.trait_def(trait_ref.def_id); trait_def.record_local_impl(tcx, impl_def_id, trait_ref); } } diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index 74edc7bff495c..383a9e0e69542 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -41,7 +41,7 @@ pub fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) { let _task = tcx.dep_graph.in_task(DepNode::CoherenceOverlapCheck(trait_def_id)); - let def = tcx.lookup_trait_def(trait_def_id); + let def = tcx.trait_def(trait_def_id); // attempt to insert into the specialization graph let insert_result = def.add_impl_for_specialization(tcx, impl_def_id); diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 22247d2531aec..4463cff9c503f 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -34,7 +34,7 @@ impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> { None => {} Some(trait_ref) => { - let trait_def = self.tcx.lookup_trait_def(trait_ref.def_id); + let trait_def = self.tcx.trait_def(trait_ref.def_id); let unsafe_attr = impl_generics.and_then(|g| g.carries_unsafe_attr()); match (trait_def.unsafety, unsafe_attr, unsafety, polarity) { (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative) => { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 660ce837043c1..83727e9da0325 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -31,7 +31,7 @@ then types, or something like that) because the user can introduce arbitrary interdependencies. So instead we generally convert things lazilly and on demand, and include logic that checks for cycles. Demand is driven by calls to `AstConv::get_item_type_scheme` or -`AstConv::lookup_trait_def`. +`AstConv::trait_def`. Currently, we "convert" types and traits in two phases (note that conversion only affects the types of items / enum variants / methods; @@ -91,10 +91,10 @@ pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { pub fn provide(providers: &mut Providers) { *providers = Providers { - ty, - generics, - predicates, - super_predicates, + type_of, + generics_of, + predicates_of, + super_predicates_of, type_param_predicates, trait_def, adt_def, @@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { for param in &generics.ty_params { if param.default.is_some() { let def_id = self.tcx.hir.local_def_id(param.id); - self.tcx.item_type(def_id); + self.tcx.type_of(def_id); } } intravisit::walk_generics(self, generics); @@ -150,8 +150,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr) { if let hir::ExprClosure(..) = expr.node { let def_id = self.tcx.hir.local_def_id(expr.id); - self.tcx.item_generics(def_id); - self.tcx.item_type(def_id); + self.tcx.generics_of(def_id); + self.tcx.type_of(def_id); } intravisit::walk_expr(self, expr); } @@ -159,8 +159,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { fn visit_ty(&mut self, ty: &'tcx hir::Ty) { if let hir::TyImplTrait(..) = ty.node { let def_id = self.tcx.hir.local_def_id(ty.id); - self.tcx.item_generics(def_id); - self.tcx.item_predicates(def_id); + self.tcx.generics_of(def_id); + self.tcx.predicates_of(def_id); } intravisit::walk_ty(self, ty); } @@ -271,7 +271,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let param_id = tcx.hir.as_local_node_id(def_id).unwrap(); let param_owner = tcx.hir.ty_param_owner(param_id); let param_owner_def_id = tcx.hir.local_def_id(param_owner); - let generics = tcx.item_generics(param_owner_def_id); + let generics = tcx.generics_of(param_owner_def_id); let index = generics.type_param_to_index[&def_id.index]; let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id)); @@ -279,7 +279,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let parent = if item_def_id == param_owner_def_id { None } else { - tcx.item_generics(item_def_id).parent + tcx.generics_of(item_def_id).parent }; let mut result = parent.map_or(ty::GenericPredicates { @@ -452,43 +452,43 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { hir::ItemForeignMod(ref foreign_mod) => { for item in &foreign_mod.items { let def_id = tcx.hir.local_def_id(item.id); - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } } hir::ItemEnum(ref enum_definition, _) => { - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); convert_enum_variant_types(tcx, def_id, &enum_definition.variants); }, hir::ItemDefaultImpl(..) => { tcx.impl_trait_ref(def_id); } hir::ItemImpl(..) => { - tcx.item_generics(def_id); - tcx.item_type(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); tcx.impl_trait_ref(def_id); - tcx.item_predicates(def_id); + tcx.predicates_of(def_id); }, hir::ItemTrait(..) => { - tcx.item_generics(def_id); - tcx.lookup_trait_def(def_id); - ty::queries::super_predicates::get(tcx, it.span, def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.trait_def(def_id); + ty::queries::super_predicates_of::get(tcx, it.span, def_id); + tcx.predicates_of(def_id); }, hir::ItemStruct(ref struct_def, _) | hir::ItemUnion(ref struct_def, _) => { - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); for f in struct_def.fields() { let def_id = tcx.hir.local_def_id(f.id); - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } if !struct_def.is_struct() { @@ -497,14 +497,14 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { }, hir::ItemTy(_, ref generics) => { ensure_no_ty_param_bounds(tcx, it.span, generics, "type"); - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) => { - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } } } @@ -512,40 +512,40 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: ast::NodeId) { let trait_item = tcx.hir.expect_trait_item(trait_item_id); let def_id = tcx.hir.local_def_id(trait_item.id); - tcx.item_generics(def_id); + tcx.generics_of(def_id); match trait_item.node { hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(_, Some(_)) | hir::TraitItemKind::Method(..) => { - tcx.item_type(def_id); + tcx.type_of(def_id); } hir::TraitItemKind::Type(_, None) => {} }; - tcx.item_predicates(def_id); + tcx.predicates_of(def_id); } fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: ast::NodeId) { let def_id = tcx.hir.local_def_id(impl_item_id); - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } fn convert_variant_ctor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: ast::NodeId) { let def_id = tcx.hir.local_def_id(ctor_id); - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } fn convert_enum_variant_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, variants: &[hir::Variant]) { - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); let repr_type = def.repr.discr_type(); let initial = repr_type.initial_discriminant(tcx); let mut prev_discr = None::; @@ -583,9 +583,9 @@ fn convert_enum_variant_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for f in variant.node.data.fields() { let def_id = tcx.hir.local_def_id(f.id); - tcx.item_generics(def_id); - tcx.item_type(def_id); - tcx.item_predicates(def_id); + tcx.generics_of(def_id); + tcx.type_of(def_id); + tcx.predicates_of(def_id); } // Convert the ctor, if any. This also registers the variant as @@ -686,9 +686,9 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// Ensures that the super-predicates of the trait with def-id /// trait_def_id are converted and stored. This also ensures that /// the transitive super-predicates are converted; -fn super_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - trait_def_id: DefId) - -> ty::GenericPredicates<'tcx> { +fn super_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + trait_def_id: DefId) + -> ty::GenericPredicates<'tcx> { debug!("super_predicates(trait_def_id={:?})", trait_def_id); let trait_node_id = tcx.hir.as_local_node_id(trait_def_id).unwrap(); @@ -725,7 +725,7 @@ fn super_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Now require that immediate supertraits are converted, // which will, in turn, reach indirect supertraits. for bound in superbounds.iter().filter_map(|p| p.to_opt_poly_trait_ref()) { - ty::queries::super_predicates::get(tcx, item.span, bound.def_id()); + ty::queries::super_predicates_of::get(tcx, item.span, bound.def_id()); } ty::GenericPredicates { @@ -767,9 +767,9 @@ fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.alloc_trait_def(def) } -fn generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - def_id: DefId) - -> &'tcx ty::Generics { +fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + def_id: DefId) + -> &'tcx ty::Generics { use rustc::hir::map::*; use rustc::hir::*; @@ -873,7 +873,7 @@ fn generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut parent_has_self = false; let mut own_start = has_self as u32; let (parent_regions, parent_types) = parent_def_id.map_or((0, 0), |def_id| { - let generics = tcx.item_generics(def_id); + let generics = tcx.generics_of(def_id); assert_eq!(has_self, false); parent_has_self = generics.has_self; own_start = generics.count() as u32; @@ -958,9 +958,9 @@ fn generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }) } -fn ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - def_id: DefId) - -> Ty<'tcx> { +fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + def_id: DefId) + -> Ty<'tcx> { use rustc::hir::map::*; use rustc::hir::*; @@ -1017,7 +1017,7 @@ fn ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ItemEnum(..) | ItemStruct(..) | ItemUnion(..) => { - let def = tcx.lookup_adt_def(def_id); + let def = tcx.adt_def(def_id); let substs = Substs::identity_for_item(tcx, def_id); tcx.mk_adt(def, substs) } @@ -1049,12 +1049,12 @@ fn ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, NodeStructCtor(&ref def) | NodeVariant(&Spanned { node: hir::Variant_ { data: ref def, .. }, .. }) => { - let ty = tcx.item_type(tcx.hir.get_parent_did(node_id)); + let ty = tcx.type_of(tcx.hir.get_parent_did(node_id)); match *def { VariantData::Unit(..) | VariantData::Struct(..) => ty, VariantData::Tuple(ref fields, _) => { let inputs = fields.iter().map(|f| { - tcx.item_type(tcx.hir.local_def_id(f.id)) + tcx.type_of(tcx.hir.local_def_id(f.id)) }); let substs = Substs::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs, ty::Binder(tcx.mk_fn_sig( @@ -1089,7 +1089,7 @@ fn ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, NodeVariant(&Spanned { node: Variant_ { disr_expr: Some(e), .. }, .. }) if e.node_id == node_id => { - tcx.lookup_adt_def(tcx.hir.get_parent_did(node_id)) + tcx.adt_def(tcx.hir.get_parent_did(node_id)) .repr.discr_type().to_ty(tcx) } @@ -1104,7 +1104,7 @@ fn ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, NodeTy(&hir::Ty { node: TyImplTrait(..), .. }) => { let owner = tcx.hir.get_parent_did(node_id); - tcx.item_tables(owner).node_id_to_type(node_id) + tcx.typeck_tables_of(owner).node_id_to_type(node_id) } x => { @@ -1127,7 +1127,7 @@ fn impl_trait_ref<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } hir::ItemImpl(.., ref opt_trait_ref, _, _) => { opt_trait_ref.as_ref().map(|ast_trait_ref| { - let selfty = tcx.item_type(def_id); + let selfty = tcx.type_of(def_id); AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty) }) } @@ -1141,7 +1141,7 @@ fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); match tcx.hir.expect_item(node_id).node { hir::ItemImpl(_, polarity, ..) => polarity, - ref item => bug!("trait_impl_polarity: {:?} not an impl", item) + ref item => bug!("impl_polarity: {:?} not an impl", item) } } @@ -1205,9 +1205,9 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>( .filter(move |l| !tcx.named_region_map.late_bound.contains(&l.lifetime.id)) } -fn predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - def_id: DefId) - -> ty::GenericPredicates<'tcx> { +fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + def_id: DefId) + -> ty::GenericPredicates<'tcx> { use rustc::hir::map::*; use rustc::hir::*; @@ -1280,7 +1280,7 @@ fn predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, _ => &no_generics }; - let generics = tcx.item_generics(def_id); + let generics = tcx.generics_of(def_id); let parent_count = generics.parent_count() as u32; let has_own_self = generics.has_self && parent_count == 0; @@ -1291,7 +1291,7 @@ fn predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // on a trait we need to add in the supertrait bounds and bounds found on // associated types. if let Some((trait_ref, _)) = is_trait { - predicates = tcx.item_super_predicates(def_id).predicates; + predicates = tcx.super_predicates_of(def_id).predicates; // Add in a predicate that `Self:Trait` (where `Trait` is the // current trait). This is needed for builtin bounds. @@ -1410,7 +1410,7 @@ fn predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // in trait checking. See `setup_constraining_predicates` // for details. if let NodeItem(&Item { node: ItemImpl(..), .. }) = node { - let self_ty = tcx.item_type(def_id); + let self_ty = tcx.type_of(def_id); let trait_ref = tcx.impl_trait_ref(def_id); ctp::setup_constraining_predicates(&mut predicates, trait_ref, diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 5751dc5ab8a0a..1c44572fbb4af 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -95,9 +95,9 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_refs: &[hir::ImplItemRef]) { // Every lifetime used in an associated type must be constrained. - let impl_self_ty = tcx.item_type(impl_def_id); - let impl_generics = tcx.item_generics(impl_def_id); - let impl_predicates = tcx.item_predicates(impl_def_id); + let impl_self_ty = tcx.type_of(impl_def_id); + let impl_generics = tcx.generics_of(impl_def_id); + let impl_predicates = tcx.predicates_of(impl_def_id); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id); let mut input_parameters = ctp::parameters_for_impl(impl_self_ty, impl_trait_ref); @@ -120,7 +120,7 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item.kind == ty::AssociatedKind::Type && item.defaultness.has_value() }) .flat_map(|def_id| { - ctp::parameters_for(&tcx.item_type(def_id), true) + ctp::parameters_for(&tcx.type_of(def_id), true) }).collect(); for (ty_lifetime, lifetime) in impl_generics.regions.iter() .zip(&impl_hir_generics.lifetimes) diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 0754b52cf280a..94b4bfade9498 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -179,7 +179,7 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_id: ast::NodeId, main_span: Span) { let main_def_id = tcx.hir.local_def_id(main_id); - let main_t = tcx.item_type(main_def_id); + let main_t = tcx.type_of(main_def_id); match main_t.sty { ty::TyFnDef(..) => { match tcx.hir.find(main_id) { @@ -229,7 +229,7 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_id: ast::NodeId, start_span: Span) { let start_def_id = tcx.hir.local_def_id(start_id); - let start_t = tcx.item_type(start_def_id); + let start_t = tcx.type_of(start_def_id); match start_t.sty { ty::TyFnDef(..) => { match tcx.hir.find(start_id) { diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 1bde1eea37c39..5bbc285c3d5ce 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) => { - let generics = tcx.item_generics(did); + let generics = tcx.generics_of(did); // Not entirely obvious: constraints on structs/enums do not // affect the variance of their type parameters. See discussion @@ -89,14 +89,14 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { // // self.add_constraints_from_generics(generics); - for field in tcx.lookup_adt_def(did).all_fields() { + for field in tcx.adt_def(did).all_fields() { self.add_constraints_from_ty(generics, - tcx.item_type(field.did), + tcx.type_of(field.did), self.covariant); } } hir::ItemTrait(..) => { - let generics = tcx.item_generics(did); + let generics = tcx.generics_of(did); let trait_ref = ty::TraitRef { def_id: did, substs: Substs::identity_for_item(tcx, did) @@ -233,7 +233,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } else { // Parameter on an item defined within another crate: // variance already inferred, just look it up. - let variances = self.tcx().item_variances(item_def_id); + let variances = self.tcx().variances_of(item_def_id); self.constant_term(variances[index]) } } @@ -286,10 +286,10 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { trait_ref, variance); - let trait_generics = self.tcx().item_generics(trait_ref.def_id); + let trait_generics = self.tcx().generics_of(trait_ref.def_id); // This edge is actually implied by the call to - // `lookup_trait_def`, but I'm trying to be future-proof. See + // `trait_def`, but I'm trying to be future-proof. See // README.md for a discussion on dep-graph management. self.tcx().dep_graph.read(VarianceDepNode(trait_ref.def_id)); @@ -345,10 +345,10 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } ty::TyAdt(def, substs) => { - let adt_generics = self.tcx().item_generics(def.did); + let adt_generics = self.tcx().generics_of(def.did); // This edge is actually implied by the call to - // `lookup_trait_def`, but I'm trying to be future-proof. See + // `trait_def`, but I'm trying to be future-proof. See // README.md for a discussion on dep-graph management. self.tcx().dep_graph.read(VarianceDepNode(def.did)); @@ -362,10 +362,10 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { ty::TyProjection(ref data) => { let trait_ref = &data.trait_ref; - let trait_generics = self.tcx().item_generics(trait_ref.def_id); + let trait_generics = self.tcx().generics_of(trait_ref.def_id); // This edge is actually implied by the call to - // `lookup_trait_def`, but I'm trying to be future-proof. See + // `trait_def`, but I'm trying to be future-proof. See // README.md for a discussion on dep-graph management. self.tcx().dep_graph.read(VarianceDepNode(trait_ref.def_id)); diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index 6628c7c521fd1..27116cbbb7aef 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -137,8 +137,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { item_variances); } - tcx.maps.variances - .borrow_mut() + tcx.maps.variances_of.borrow_mut() .insert(item_def_id, Rc::new(item_variances)); } } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 890414e317c62..61ff154e458d3 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -178,8 +178,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { // parameters". if self.num_inferred() == inferreds_on_entry { let item_def_id = self.tcx.hir.local_def_id(item_id); - self.tcx.maps.variances - .borrow_mut() + self.tcx.maps.variances_of.borrow_mut() .insert(item_def_id, self.empty_variances.clone()); } } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 6016fd488f56c..d68ce47b4cf45 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -152,12 +152,12 @@ pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) { pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait { let trait_items = cx.tcx.associated_items(did).map(|item| item.clean(cx)).collect(); - let predicates = cx.tcx.item_predicates(did); - let generics = (cx.tcx.item_generics(did), &predicates).clean(cx); + let predicates = cx.tcx.predicates_of(did); + let generics = (cx.tcx.generics_of(did), &predicates).clean(cx); let generics = filter_non_trait_generics(did, generics); let (generics, supertrait_bounds) = separate_supertrait_bounds(generics); clean::Trait { - unsafety: cx.tcx.lookup_trait_def(did).unsafety, + unsafety: cx.tcx.trait_def(did).unsafety, generics: generics, items: trait_items, bounds: supertrait_bounds, @@ -165,7 +165,7 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait { } fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function { - let sig = cx.tcx.item_type(did).fn_sig(); + let sig = cx.tcx.type_of(did).fn_sig(); let constness = if cx.tcx.sess.cstore.is_const_fn(did) { hir::Constness::Const @@ -173,10 +173,10 @@ fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function { hir::Constness::NotConst }; - let predicates = cx.tcx.item_predicates(did); + let predicates = cx.tcx.predicates_of(did); clean::Function { decl: (did, sig).clean(cx), - generics: (cx.tcx.item_generics(did), &predicates).clean(cx), + generics: (cx.tcx.generics_of(did), &predicates).clean(cx), unsafety: sig.unsafety(), constness: constness, abi: sig.abi(), @@ -184,18 +184,18 @@ fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function { } fn build_enum(cx: &DocContext, did: DefId) -> clean::Enum { - let predicates = cx.tcx.item_predicates(did); + let predicates = cx.tcx.predicates_of(did); clean::Enum { - generics: (cx.tcx.item_generics(did), &predicates).clean(cx), + generics: (cx.tcx.generics_of(did), &predicates).clean(cx), variants_stripped: false, - variants: cx.tcx.lookup_adt_def(did).variants.clean(cx), + variants: cx.tcx.adt_def(did).variants.clean(cx), } } fn build_struct(cx: &DocContext, did: DefId) -> clean::Struct { - let predicates = cx.tcx.item_predicates(did); - let variant = cx.tcx.lookup_adt_def(did).struct_variant(); + let predicates = cx.tcx.predicates_of(did); + let variant = cx.tcx.adt_def(did).struct_variant(); clean::Struct { struct_type: match variant.ctor_kind { @@ -203,30 +203,30 @@ fn build_struct(cx: &DocContext, did: DefId) -> clean::Struct { CtorKind::Fn => doctree::Tuple, CtorKind::Const => doctree::Unit, }, - generics: (cx.tcx.item_generics(did), &predicates).clean(cx), + generics: (cx.tcx.generics_of(did), &predicates).clean(cx), fields: variant.fields.clean(cx), fields_stripped: false, } } fn build_union(cx: &DocContext, did: DefId) -> clean::Union { - let predicates = cx.tcx.item_predicates(did); - let variant = cx.tcx.lookup_adt_def(did).struct_variant(); + let predicates = cx.tcx.predicates_of(did); + let variant = cx.tcx.adt_def(did).struct_variant(); clean::Union { struct_type: doctree::Plain, - generics: (cx.tcx.item_generics(did), &predicates).clean(cx), + generics: (cx.tcx.generics_of(did), &predicates).clean(cx), fields: variant.fields.clean(cx), fields_stripped: false, } } fn build_type_alias(cx: &DocContext, did: DefId) -> clean::Typedef { - let predicates = cx.tcx.item_predicates(did); + let predicates = cx.tcx.predicates_of(did); clean::Typedef { - type_: cx.tcx.item_type(did).clean(cx), - generics: (cx.tcx.item_generics(did), &predicates).clean(cx), + type_: cx.tcx.type_of(did).clean(cx), + generics: (cx.tcx.generics_of(did), &predicates).clean(cx), } } @@ -326,7 +326,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { }); } - let for_ = tcx.item_type(did).clean(cx); + let for_ = tcx.type_of(did).clean(cx); // Only inline impl if the implementing type is // reachable in rustdoc generated documentation @@ -336,7 +336,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { } } - let predicates = tcx.item_predicates(did); + let predicates = tcx.predicates_of(did); let trait_items = tcx.associated_items(did).filter_map(|item| { match item.kind { ty::AssociatedKind::Const => { @@ -348,7 +348,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { Some(clean::Item { name: Some(item.name.clean(cx)), inner: clean::AssociatedConstItem( - tcx.item_type(item.def_id).clean(cx), + tcx.type_of(item.def_id).clean(cx), default, ), source: tcx.def_span(item.def_id).clean(cx), @@ -388,7 +388,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { } ty::AssociatedKind::Type => { let typedef = clean::Typedef { - type_: tcx.item_type(item.def_id).clean(cx), + type_: tcx.type_of(item.def_id).clean(cx), generics: clean::Generics { lifetimes: vec![], type_params: vec![], @@ -408,7 +408,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { } } }).collect::>(); - let polarity = tcx.trait_impl_polarity(did); + let polarity = tcx.impl_polarity(did); let trait_ = associated_trait.clean(cx).map(|bound| { match bound { clean::TraitBound(polyt, _) => polyt.trait_, @@ -432,7 +432,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { provided_trait_methods: provided, trait_: trait_, for_: for_, - generics: (tcx.item_generics(did), &predicates).clean(cx), + generics: (tcx.generics_of(did), &predicates).clean(cx), items: trait_items, polarity: Some(polarity.clean(cx)), }), @@ -496,14 +496,14 @@ fn print_inlined_const(cx: &DocContext, did: DefId) -> String { fn build_const(cx: &DocContext, did: DefId) -> clean::Constant { clean::Constant { - type_: cx.tcx.item_type(did).clean(cx), + type_: cx.tcx.type_of(did).clean(cx), expr: print_inlined_const(cx, did) } } fn build_static(cx: &DocContext, did: DefId, mutable: bool) -> clean::Static { clean::Static { - type_: cx.tcx.item_type(did).clean(cx), + type_: cx.tcx.type_of(did).clean(cx), mutability: if mutable {clean::Mutable} else {clean::Immutable}, expr: "\n\n\n".to_string(), // trigger the "[definition]" links } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cf872db682379..a25eb60d2a2fc 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -606,7 +606,7 @@ impl<'tcx> Clean for ty::TypeParameterDef { did: self.def_id, bounds: vec![], // these are filled in from the where-clauses default: if self.has_default { - Some(cx.tcx.item_type(self.def_id).clean(cx)) + Some(cx.tcx.type_of(self.def_id).clean(cx)) } else { None } @@ -1356,19 +1356,19 @@ impl<'tcx> Clean for ty::AssociatedItem { fn clean(&self, cx: &DocContext) -> Item { let inner = match self.kind { ty::AssociatedKind::Const => { - let ty = cx.tcx.item_type(self.def_id); + let ty = cx.tcx.type_of(self.def_id); AssociatedConstItem(ty.clean(cx), None) } ty::AssociatedKind::Method => { - let generics = (cx.tcx.item_generics(self.def_id), - &cx.tcx.item_predicates(self.def_id)).clean(cx); - let sig = cx.tcx.item_type(self.def_id).fn_sig(); + let generics = (cx.tcx.generics_of(self.def_id), + &cx.tcx.predicates_of(self.def_id)).clean(cx); + let sig = cx.tcx.type_of(self.def_id).fn_sig(); let mut decl = (self.def_id, sig).clean(cx); if self.method_has_self_argument { let self_ty = match self.container { ty::ImplContainer(def_id) => { - cx.tcx.item_type(def_id) + cx.tcx.type_of(def_id) } ty::TraitContainer(_) => cx.tcx.mk_self_type() }; @@ -1418,8 +1418,8 @@ impl<'tcx> Clean for ty::AssociatedItem { // are actually located on the trait/impl itself, so we need to load // all of the generics from there and then look for bounds that are // applied to this associated type in question. - let predicates = cx.tcx.item_predicates(did); - let generics = (cx.tcx.item_generics(did), &predicates).clean(cx); + let predicates = cx.tcx.predicates_of(did); + let generics = (cx.tcx.generics_of(did), &predicates).clean(cx); generics.where_predicates.iter().filter_map(|pred| { let (name, self_type, trait_, bounds) = match *pred { WherePredicate::BoundPredicate { @@ -1454,7 +1454,7 @@ impl<'tcx> Clean for ty::AssociatedItem { } let ty = if self.defaultness.has_value() { - Some(cx.tcx.item_type(self.def_id)) + Some(cx.tcx.type_of(self.def_id)) } else { None }; @@ -1922,9 +1922,9 @@ impl<'tcx> Clean for ty::Ty<'tcx> { ty::TyAnon(def_id, substs) => { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the projections associated with the def_id. - let item_predicates = cx.tcx.item_predicates(def_id); + let predicates_of = cx.tcx.predicates_of(def_id); let substs = cx.tcx.lift(&substs).unwrap(); - let bounds = item_predicates.instantiate(cx.tcx, substs); + let bounds = predicates_of.instantiate(cx.tcx, substs); ImplTrait(bounds.predicates.into_iter().filter_map(|predicate| { predicate.to_opt_poly_trait_ref().clean(cx) }).collect()) @@ -1963,7 +1963,7 @@ impl<'tcx> Clean for ty::FieldDef { stability: get_stability(cx, self.did), deprecation: get_deprecation(cx, self.did), def_id: self.did, - inner: StructFieldItem(cx.tcx.item_type(self.did).clean(cx)), + inner: StructFieldItem(cx.tcx.type_of(self.did).clean(cx)), } } } @@ -2116,7 +2116,7 @@ impl<'tcx> Clean for ty::VariantDef { CtorKind::Const => VariantKind::CLike, CtorKind::Fn => { VariantKind::Tuple( - self.fields.iter().map(|f| cx.tcx.item_type(f.did).clean(cx)).collect() + self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect() ) } CtorKind::Fictive => { @@ -2132,7 +2132,7 @@ impl<'tcx> Clean for ty::VariantDef { def_id: field.did, stability: get_stability(cx, field.did), deprecation: get_deprecation(cx, field.did), - inner: StructFieldItem(cx.tcx.item_type(field.did).clean(cx)) + inner: StructFieldItem(cx.tcx.type_of(field.did).clean(cx)) } }).collect() }) diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 7240f0aedbd27..be02d24e44151 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -153,7 +153,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId, if child == trait_ { return true } - let predicates = cx.tcx.item_super_predicates(child).predicates; + let predicates = cx.tcx.super_predicates_of(child).predicates; predicates.iter().filter_map(|pred| { if let ty::Predicate::Trait(ref pred) = *pred { if pred.0.trait_ref.self_ty().is_self() { From 9bde6b6d96ccb76825c8e3bca54c28727ceeed63 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 24 Apr 2017 17:23:36 +0300 Subject: [PATCH 13/16] rustc: expose the common DUMMY_SP query case as tcx methods. --- src/librustc/lint/context.rs | 4 +- src/librustc/middle/dead.rs | 3 +- src/librustc/middle/reachable.rs | 5 +- src/librustc/middle/stability.rs | 2 +- src/librustc/ty/maps.rs | 7 ++ src/librustc/ty/mod.rs | 79 ++----------------- src/librustc/ty/util.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 4 +- src/librustc_const_eval/eval.rs | 4 +- src/librustc_metadata/encoder.rs | 4 +- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/librustc_privacy/lib.rs | 4 +- src/librustc_trans/callee.rs | 5 +- src/librustc_typeck/check/mod.rs | 2 +- .../coherence/inherent_impls.rs | 4 +- .../coherence/inherent_impls_overlap.rs | 4 +- src/librustc_typeck/coherence/mod.rs | 9 +-- src/librustdoc/clean/inline.rs | 3 +- 18 files changed, 39 insertions(+), 108 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 20bf241a99906..6947e7c3f4085 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -43,7 +43,7 @@ use std::fmt; use syntax::attr; use syntax::ast; use syntax::symbol::Symbol; -use syntax_pos::{DUMMY_SP, MultiSpan, Span}; +use syntax_pos::{MultiSpan, Span}; use errors::{self, Diagnostic, DiagnosticBuilder}; use hir; use hir::def_id::LOCAL_CRATE; @@ -1234,7 +1234,7 @@ fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore, pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let _task = tcx.dep_graph.in_task(DepNode::LateLintCheck); - let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE); + let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let krate = tcx.hir.krate(); diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0be8484b78408..0840495ff77a8 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -26,7 +26,6 @@ use util::nodemap::FxHashSet; use syntax::{ast, codemap}; use syntax::attr; -use syntax::codemap::DUMMY_SP; use syntax_pos; // Any local node that may call something in its body block should be @@ -593,7 +592,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { } pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { - let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE); + let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let krate = tcx.hir.krate(); let live_symbols = find_live(tcx, access_levels, krate); let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols }; diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index be4ec16cd63aa..431760b6fcd65 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -28,7 +28,6 @@ use util::nodemap::{NodeSet, FxHashSet}; use syntax::abi::Abi; use syntax::ast; use syntax::attr; -use syntax::codemap::DUMMY_SP; use hir; use hir::def_id::LOCAL_CRATE; use hir::intravisit::{Visitor, NestedVisitorMap}; @@ -364,13 +363,13 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, } pub fn find_reachable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc { - ty::queries::reachable_set::get(tcx, DUMMY_SP, LOCAL_CRATE) + tcx.reachable_set(LOCAL_CRATE) } fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> Rc { debug_assert!(crate_num == LOCAL_CRATE); - let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE); + let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| { *ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib || diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 1e856f6716ef7..7431eb3fe96ef 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -656,7 +656,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let sess = &tcx.sess; - let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE); + let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); if tcx.stability.borrow().staged_api[&LOCAL_CRATE] && tcx.sess.features.borrow().staged_api { let krate = tcx.hir.krate(); diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index f743da24972af..3023e006d1b17 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -351,6 +351,13 @@ macro_rules! define_maps { } })* + impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> { + $($(#[$attr])* + pub fn $name(self, key: $K) -> $V { + queries::$name::get(self, DUMMY_SP, key) + })* + } + pub struct Providers<$tcx> { $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $V),* } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d5cd3742ffccb..9af8e2a3fc220 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1686,7 +1686,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr()); if let VariantDiscr::Explicit(expr_did) = v.discr { let substs = Substs::empty(); - match queries::const_eval::get(tcx, DUMMY_SP, (expr_did, substs)) { + match tcx.const_eval((expr_did, substs)) { Ok(ConstVal::Integral(v)) => { discr = v; } @@ -1725,7 +1725,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { } ty::VariantDiscr::Explicit(expr_did) => { let substs = Substs::empty(); - match queries::const_eval::get(tcx, DUMMY_SP, (expr_did, substs)) { + match tcx.const_eval((expr_did, substs)) { Ok(ConstVal::Integral(v)) => { explicit_value = v; break; @@ -1760,7 +1760,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { } pub fn destructor(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option { - queries::adt_destructor::get(tcx, DUMMY_SP, self.did) + tcx.adt_destructor(self.did) } /// Returns a list of types such that `Self: Sized` if and only @@ -2045,10 +2045,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.typeck_tables_of(self.hir.body_owner_def_id(body)) } - pub fn typeck_tables_of(self, def_id: DefId) -> &'gcx TypeckTables<'gcx> { - queries::typeck_tables_of::get(self, DUMMY_SP, def_id) - } - pub fn expr_span(self, id: NodeId) -> Span { match self.hir.find(id) { Some(hir_map::NodeExpr(e)) => { @@ -2136,24 +2132,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { .collect() } - pub fn impl_polarity(self, id: DefId) -> hir::ImplPolarity { - queries::impl_polarity::get(self, DUMMY_SP, id) - } - pub fn trait_relevant_for_never(self, did: DefId) -> bool { self.associated_items(did).any(|item| { item.relevant_for_never() }) } - pub fn coerce_unsized_info(self, did: DefId) -> adjustment::CoerceUnsizedInfo { - queries::coerce_unsized_info::get(self, DUMMY_SP, did) - } - - pub fn associated_item(self, def_id: DefId) -> AssociatedItem { - queries::associated_item::get(self, DUMMY_SP, def_id) - } - fn associated_item_from_trait_item_ref(self, parent_def_id: DefId, trait_item_ref: &hir::TraitItemRef) @@ -2207,10 +2191,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn associated_item_def_ids(self, def_id: DefId) -> Rc> { - queries::associated_item_def_ids::get(self, DUMMY_SP, def_id) - } - #[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait. pub fn associated_items(self, def_id: DefId) -> impl Iterator + 'a { @@ -2218,12 +2198,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { (0..def_ids.len()).map(move |i| self.associated_item(def_ids[i])) } - /// Returns the trait-ref corresponding to a given impl, or None if it is - /// an inherent impl. - pub fn impl_trait_ref(self, id: DefId) -> Option> { - queries::impl_trait_ref::get(self, DUMMY_SP, id) - } - /// Returns true if the impls are the same polarity and are implementing /// a trait which contains no items pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool { @@ -2325,40 +2299,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - // If the given item is in an external crate, looks up its type and adds it to - // the type cache. Returns the type parameters and type. - pub fn type_of(self, did: DefId) -> Ty<'gcx> { - queries::type_of::get(self, DUMMY_SP, did) - } - - /// Given the did of a trait, returns its canonical trait ref. - pub fn trait_def(self, did: DefId) -> &'gcx TraitDef { - queries::trait_def::get(self, DUMMY_SP, did) - } - - /// Given the did of an ADT, return a reference to its definition. - pub fn adt_def(self, did: DefId) -> &'gcx AdtDef { - queries::adt_def::get(self, DUMMY_SP, did) - } - - /// Given the did of an item, returns its generics. - pub fn generics_of(self, did: DefId) -> &'gcx Generics { - queries::generics_of::get(self, DUMMY_SP, did) - } - - /// Given the did of an item, returns its full set of predicates. - pub fn predicates_of(self, did: DefId) -> GenericPredicates<'gcx> { - queries::predicates_of::get(self, DUMMY_SP, did) - } - - /// Given the did of a trait, returns its superpredicates. - pub fn super_predicates_of(self, did: DefId) -> GenericPredicates<'gcx> { - queries::super_predicates_of::get(self, DUMMY_SP, did) - } - /// Given the did of an item, returns its MIR, borrowed immutably. pub fn item_mir(self, did: DefId) -> Ref<'gcx, Mir<'gcx>> { - queries::mir::get(self, DUMMY_SP, did).borrow() + self.mir(did).borrow() } /// Return the possibly-auto-generated MIR of a (DefId, Subst) pair. @@ -2367,7 +2310,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { { match instance { ty::InstanceDef::Item(did) if true => self.item_mir(did), - _ => queries::mir_shims::get(self, DUMMY_SP, instance).borrow(), + _ => self.mir_shims(instance).borrow(), } } @@ -2399,10 +2342,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.get_attrs(did).iter().any(|item| item.check_name(attr)) } - pub fn variances_of(self, item_id: DefId) -> Rc> { - queries::variances_of::get(self, DUMMY_SP, item_id) - } - pub fn trait_has_default_impl(self, trait_def_id: DefId) -> bool { let def = self.trait_def(trait_def_id); def.flags.get().intersects(TraitFlags::HAS_DEFAULT_IMPL) @@ -2437,14 +2376,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { def.flags.set(def.flags.get() | TraitFlags::HAS_REMOTE_IMPLS); } - pub fn closure_kind(self, def_id: DefId) -> ty::ClosureKind { - queries::closure_kind::get(self, DUMMY_SP, def_id) - } - - pub fn closure_type(self, def_id: DefId) -> ty::PolyFnSig<'tcx> { - queries::closure_type::get(self, DUMMY_SP, def_id) - } - /// Given the def_id of an impl, return the def_id of the trait it implements. /// If it implements no trait, return `None`. pub fn trait_id_of_impl(self, def_id: DefId) -> Option { diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 007647a3297c3..54e00efc08e77 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -369,7 +369,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { return None; }; - ty::queries::coherent_trait::get(self, DUMMY_SP, (LOCAL_CRATE, drop_trait)); + self.coherent_trait((LOCAL_CRATE, drop_trait)); let mut dtor_did = None; let ty = self.type_of(adt_did); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 99e533cbb83f3..401c878cd4010 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -42,7 +42,7 @@ use std::fmt; use std::rc::Rc; use std::hash::{Hash, Hasher}; use syntax::ast; -use syntax_pos::{DUMMY_SP, MultiSpan, Span}; +use syntax_pos::{MultiSpan, Span}; use errors::DiagnosticBuilder; use rustc::hir; @@ -63,7 +63,7 @@ pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| { - ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id); + tcx.borrowck(body_owner_def_id); }); } diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index cc9892ee8c213..e7ccf3cbdb8f2 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -27,7 +27,7 @@ use rustc::util::nodemap::DefIdMap; use syntax::ast; use rustc::hir::{self, Expr}; -use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::Span; use std::cmp::Ordering; @@ -773,7 +773,7 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) { - ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id); + tcx.mir_const_qualif(def_id); tcx.hir.body(tcx.hir.body_owned_by(id)) } else { tcx.sess.cstore.item_body(tcx, def_id) diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 949949d2e1020..4fd8d478717af 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -36,7 +36,7 @@ use syntax::ast::{self, CRATE_NODE_ID}; use syntax::codemap::Spanned; use syntax::attr; use syntax::symbol::Symbol; -use syntax_pos::{self, DUMMY_SP}; +use syntax_pos; use rustc::hir::{self, PatKind}; use rustc::hir::itemlikevisit::ItemLikeVisitor; @@ -1169,7 +1169,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { let body = tcx.hir.body_owned_by(id); Entry { - kind: EntryKind::Const(ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id)), + kind: EntryKind::Const(tcx.mir_const_qualif(def_id)), visibility: self.lazy(&ty::Visibility::Public), span: self.lazy(&tcx.def_span(def_id)), attributes: LazySeq::empty(), diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 3ef611dd3cafb..48f70c2685129 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -959,7 +959,7 @@ impl<'tcx> MirMapPass<'tcx> for QualifyAndPromoteConstants { let src = MirSource::from_node(tcx, id); if let MirSource::Const(_) = src { - ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id); + tcx.mir_const_qualif(def_id); continue; } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index fb1c5738206cc..06685665dd1d7 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -38,7 +38,7 @@ use rustc::ty::fold::TypeVisitor; use rustc::ty::maps::Providers; use rustc::util::nodemap::NodeSet; use syntax::ast; -use syntax_pos::{DUMMY_SP, Span}; +use syntax_pos::Span; use std::cmp; use std::mem::replace; @@ -1222,7 +1222,7 @@ pub fn provide(providers: &mut Providers) { pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc { tcx.dep_graph.with_ignore(|| { // FIXME - ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE) + tcx.privacy_access_levels(LOCAL_CRATE) }) } diff --git a/src/librustc_trans/callee.rs b/src/librustc_trans/callee.rs index 264e26e4594ca..78e0a524ef2dc 100644 --- a/src/librustc_trans/callee.rs +++ b/src/librustc_trans/callee.rs @@ -21,9 +21,8 @@ use declare; use llvm::{self, ValueRef}; use monomorphize::{self, Instance}; use rustc::hir::def_id::DefId; -use rustc::ty::{self, TypeFoldable}; +use rustc::ty::TypeFoldable; use rustc::ty::subst::Substs; -use syntax_pos::DUMMY_SP; use trans_item::TransItem; use type_of; @@ -105,7 +104,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, // *in Rust code* may unwind. Foreign items like `extern "C" { // fn foo(); }` are assumed not to unwind **unless** they have // a `#[unwind]` attribute. - if !ty::queries::is_foreign_item::get(tcx, DUMMY_SP, instance.def_id()) { + if !tcx.is_foreign_item(instance.def_id()) { attributes::unwind(llfn, true); unsafe { llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a27397fa444d8..1c0c68ae7d7cb 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -621,7 +621,7 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult } pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult { - ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE) + tcx.typeck_item_bodies(LOCAL_CRATE) } fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> CompileResult { diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 58603900e135e..45881bb3b783a 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -26,7 +26,7 @@ use rustc::util::nodemap::DefIdMap; use std::rc::Rc; use syntax::ast; -use syntax_pos::{DUMMY_SP, Span}; +use syntax_pos::Span; /// On-demand query: yields a map containing all types mapped to their inherent impls. pub fn crate_inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -67,7 +67,7 @@ pub fn inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // [the plan]: https://github.com/rust-lang/rust-roadmap/issues/4 let result = tcx.dep_graph.with_ignore(|| { - let crate_map = ty::queries::crate_inherent_impls::get(tcx, DUMMY_SP, ty_def_id.krate); + let crate_map = tcx.crate_inherent_impls(ty_def_id.krate); match crate_map.inherent_impls.get(&ty_def_id) { Some(v) => v.clone(), None => Rc::new(vec![]), diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 33280fb931aaf..34aec8ef1ac8c 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -14,8 +14,6 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::traits::{self, Reveal}; use rustc::ty::{self, TyCtxt}; -use syntax_pos::DUMMY_SP; - pub fn crate_inherent_impls_overlap_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) { assert_eq!(crate_num, LOCAL_CRATE); @@ -68,7 +66,7 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> { } fn check_for_overlapping_inherent_impls(&self, ty_def_id: DefId) { - let impls = ty::queries::inherent_impls::get(self.tcx, DUMMY_SP, ty_def_id); + let impls = self.tcx.inherent_impls(ty_def_id); for (i, &impl1_def_id) in impls.iter().enumerate() { for &impl2_def_id in &impls[(i + 1)..] { diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index abfee989d65f6..56ae9d545751f 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -16,11 +16,10 @@ // mappings. That mapping code resides here. use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc::ty::{self, TyCtxt, TypeFoldable}; +use rustc::ty::{TyCtxt, TypeFoldable}; use rustc::ty::maps::Providers; use syntax::ast; -use syntax_pos::DUMMY_SP; mod builtin; mod inherent_impls; @@ -132,7 +131,7 @@ fn coherent_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { for &trait_def_id in tcx.hir.krate().trait_impls.keys() { - ty::queries::coherent_trait::get(tcx, DUMMY_SP, (LOCAL_CRATE, trait_def_id)); + tcx.coherent_trait((LOCAL_CRATE, trait_def_id)); } unsafety::check(tcx); @@ -140,6 +139,6 @@ pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { overlap::check_default_impls(tcx); // these queries are executed for side-effects (error reporting): - ty::queries::crate_inherent_impls::get(tcx, DUMMY_SP, LOCAL_CRATE); - ty::queries::crate_inherent_impls_overlap_check::get(tcx, DUMMY_SP, LOCAL_CRATE); + tcx.crate_inherent_impls(LOCAL_CRATE); + tcx.crate_inherent_impls_overlap_check(LOCAL_CRATE); } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d68ce47b4cf45..71bb53e9b81c7 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -15,7 +15,6 @@ use std::io; use std::iter::once; use syntax::ast; -use syntax_pos::DUMMY_SP; use rustc::hir; use rustc::hir::def::{Def, CtorKind}; @@ -234,7 +233,7 @@ pub fn build_impls(cx: &DocContext, did: DefId) -> Vec { let tcx = cx.tcx; let mut impls = Vec::new(); - for &did in ty::queries::inherent_impls::get(tcx, DUMMY_SP, did).iter() { + for &did in tcx.inherent_impls(did).iter() { build_impl(cx, did, &mut impls); } From feae5a08a2d5d8db14a4b99a050dbc14a6bffb2a Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Mon, 24 Apr 2017 09:49:29 -0500 Subject: [PATCH 14/16] Add Splice forget test --- src/libcollections/tests/string.rs | 7 +++++++ src/libcollections/tests/vec.rs | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/libcollections/tests/string.rs b/src/libcollections/tests/string.rs index a32f5e3357f38..b1731b2a5dcaa 100644 --- a/src/libcollections/tests/string.rs +++ b/src/libcollections/tests/string.rs @@ -475,6 +475,13 @@ fn test_splice_unbounded() { assert_eq!(t, "12345"); } +#[test] +fn test_splice_forget() { + let mut s = String::from("12345"); + ::std::mem::forget(s.splice(2..4, "789")); + assert_eq!(s, "12345"); +} + #[test] fn test_extend_ref() { let mut a = "foo".to_string(); diff --git a/src/libcollections/tests/vec.rs b/src/libcollections/tests/vec.rs index f47940dc33aa1..29f18274962fe 100644 --- a/src/libcollections/tests/vec.rs +++ b/src/libcollections/tests/vec.rs @@ -634,6 +634,14 @@ fn test_splice_unbounded() { assert_eq!(t, &[1, 2, 3, 4, 5]); } +#[test] +fn test_splice_forget() { + let mut v = vec![1, 2, 3, 4, 5]; + let a = [10, 11, 12]; + ::std::mem::forget(v.splice(2..4, a.iter().cloned())); + assert_eq!(v, &[1, 2]); +} + #[test] fn test_into_boxed_slice() { let xs = vec![1, 2, 3]; From decf7598ef3a245ddaed9272091b3afc3466617f Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 24 Apr 2017 18:06:39 +0300 Subject: [PATCH 15/16] rustc: use tcx.at(span) to set the location of a query. --- src/librustc/middle/const_val.rs | 4 +- src/librustc/ty/maps.rs | 43 +++++++++++++++---- src/librustc/ty/mod.rs | 5 +-- src/librustc/ty/util.rs | 2 +- src/librustc_const_eval/eval.rs | 2 +- src/librustc_metadata/encoder.rs | 6 +-- src/librustc_mir/hair/cx/expr.rs | 2 +- src/librustc_mir/transform/qualify_consts.rs | 4 +- src/librustc_typeck/astconv.rs | 8 ++-- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 2 +- .../coherence/inherent_impls.rs | 2 +- src/librustc_typeck/collect.rs | 8 ++-- 13 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/librustc/middle/const_val.rs b/src/librustc/middle/const_val.rs index ec7b3c4dd8dff..74026abe64db2 100644 --- a/src/librustc/middle/const_val.rs +++ b/src/librustc/middle/const_val.rs @@ -14,7 +14,7 @@ pub use rustc_const_math::ConstInt; use hir; use hir::def::Def; use hir::def_id::DefId; -use ty::{self, TyCtxt}; +use ty::TyCtxt; use ty::subst::Substs; use util::common::ErrorReported; use rustc_const_math::*; @@ -228,7 +228,7 @@ pub fn eval_length(tcx: TyCtxt, let count_expr = &tcx.hir.body(count).value; let count_def_id = tcx.hir.body_owner_def_id(count); let substs = Substs::empty(); - match ty::queries::const_eval::get(tcx, count_expr.span, (count_def_id, substs)) { + match tcx.at(count_expr.span).const_eval((count_def_id, substs)) { Ok(Integral(Usize(count))) => { let val = count.as_u64(tcx.sess.target.uint_type); assert_eq!(val as usize as u64, val); diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 3023e006d1b17..1407e57dc2a6a 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -21,6 +21,7 @@ use util::nodemap::NodeSet; use rustc_data_structures::indexed_vec::IndexVec; use std::cell::{RefCell, RefMut}; +use std::ops::Deref; use std::rc::Rc; use syntax_pos::{Span, DUMMY_SP}; @@ -329,14 +330,6 @@ macro_rules! define_maps { Self::try_get_with(tcx, span, key, Clone::clone) } - $(#[$attr])* - pub fn get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) -> $V { - Self::try_get(tcx, span, key).unwrap_or_else(|e| { - tcx.report_cycle(e); - Value::from_cycle_error(tcx.global_tcx()) - }) - } - pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) { // FIXME(eddyb) Move away from using `DepTrackingMap` // so we don't have to explicitly ignore a false edge: @@ -351,10 +344,42 @@ macro_rules! define_maps { } })* + #[derive(Copy, Clone)] + pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { + pub tcx: TyCtxt<'a, 'gcx, 'tcx>, + pub span: Span, + } + + impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> { + type Target = TyCtxt<'a, 'gcx, 'tcx>; + fn deref(&self) -> &Self::Target { + &self.tcx + } + } + impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> { + /// Return a transparent wrapper for `TyCtxt` which uses + /// `span` as the location of queries performed through it. + pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> { + TyCtxtAt { + tcx: self, + span + } + } + + $($(#[$attr])* + pub fn $name(self, key: $K) -> $V { + self.at(DUMMY_SP).$name(key) + })* + } + + impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> { $($(#[$attr])* pub fn $name(self, key: $K) -> $V { - queries::$name::get(self, DUMMY_SP, key) + queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| { + self.report_cycle(e); + Value::from_cycle_error(self.global_tcx()) + }) })* } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 9af8e2a3fc220..a923ae154027b 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2699,9 +2699,8 @@ pub fn provide_extern(providers: &mut ty::maps::Providers) { /// A map for the local crate mapping each type to a vector of its /// inherent impls. This is not meant to be used outside of coherence; /// rather, you should request the vector for a specific type via -/// `ty::queries::inherent_impls::get(def_id)` so as to minimize your -/// dependencies (constructing this map requires touching the entire -/// crate). +/// `tcx.inherent_impls(def_id)` so as to minimize your dependencies +/// (constructing this map requires touching the entire crate). #[derive(Clone, Debug)] pub struct CrateInherentImpls { pub inherent_impls: DefIdMap>>, diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 54e00efc08e77..87921c80502e0 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -522,7 +522,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { ty::TyAdt(def, substs) => { let ty::DtorckConstraint { dtorck_types, outlives - } = ty::queries::adt_dtorck_constraint::get(self, span, def.did); + } = self.at(span).adt_dtorck_constraint(def.did); Ok(ty::DtorckConstraint { // FIXME: we can try to recursively `dtorck_constraint_on_ty` // there, but that needs some way to handle cycles. diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index e7ccf3cbdb8f2..9470316c7e7e0 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -299,7 +299,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>, match cx.tables.qpath_def(qpath, e.id) { Def::Const(def_id) | Def::AssociatedConst(def_id) => { - match ty::queries::const_eval::get(tcx, e.span, (def_id, substs)) { + match tcx.at(e.span).const_eval((def_id, substs)) { Ok(val) => val, Err(ConstEvalErr { kind: TypeckError, .. }) => { signal!(e, TypeckError); diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 4fd8d478717af..783e7604cdaf1 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -547,7 +547,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { let kind = match impl_item.kind { ty::AssociatedKind::Const => { EntryKind::AssociatedConst(container, - ty::queries::mir_const_qualif::get(self.tcx, ast_item.span, def_id)) + self.tcx.at(ast_item.span).mir_const_qualif(def_id)) } ty::AssociatedKind::Method => { let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node { @@ -656,7 +656,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { hir::ItemStatic(_, hir::MutMutable, _) => EntryKind::MutStatic, hir::ItemStatic(_, hir::MutImmutable, _) => EntryKind::ImmStatic, hir::ItemConst(..) => { - EntryKind::Const(ty::queries::mir_const_qualif::get(tcx, item.span, def_id)) + EntryKind::Const(tcx.at(item.span).mir_const_qualif(def_id)) } hir::ItemFn(_, _, constness, .., body) => { let data = FnData { @@ -732,7 +732,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> { let coerce_unsized_info = trait_ref.and_then(|t| { if Some(t.def_id) == tcx.lang_items.coerce_unsized_trait() { - Some(ty::queries::coerce_unsized_info::get(tcx, item.span, def_id)) + Some(tcx.at(item.span).coerce_unsized_info(def_id)) } else { None } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 736c076ea1544..7b267fa276b18 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -594,7 +594,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let c = &cx.tcx.hir.body(count).value; let def_id = cx.tcx.hir.body_owner_def_id(count); let substs = Substs::empty(); - let count = match ty::queries::const_eval::get(cx.tcx, c.span, (def_id, substs)) { + let count = match cx.tcx.at(c.span).const_eval((def_id, substs)) { Ok(ConstVal::Integral(ConstInt::Usize(u))) => u, Ok(other) => bug!("constant evaluation of repeat count yielded {:?}", other), Err(s) => cx.fatal_const_eval_err(&s, c.span, "expression") diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 48f70c2685129..afb775aa01e70 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -573,9 +573,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { if substs.types().next().is_some() { self.add_type(constant.ty); } else { - let bits = ty::queries::mir_const_qualif::get(self.tcx, - constant.span, - def_id); + let bits = self.tcx.at(constant.span).mir_const_qualif(def_id); let qualif = Qualif::from_bits(bits).expect("invalid mir_const_qualif"); self.add(qualif); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index c186589989443..c06e0bd5cede9 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -238,7 +238,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF); let default_needs_object_self = |p: &ty::TypeParameterDef| { if is_object && p.has_default { - if ty::queries::type_of::get(tcx, span, p.def_id).has_self_ty() { + if tcx.at(span).type_of(p.def_id).has_self_ty() { // There is no suitable inference default for a type parameter // that references self, in an object type. return true; @@ -307,7 +307,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { // This is a default type parameter. self.normalize_ty( span, - ty::queries::type_of::get(tcx, span, def.def_id) + tcx.at(span).type_of(def.def_id) .subst_spanned(tcx, substs, Some(span)) ) } @@ -600,7 +600,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let substs = self.ast_path_substs_for_ty(span, did, item_segment); self.normalize_ty( span, - ty::queries::type_of::get(self.tcx(), span, did).subst(self.tcx(), substs) + self.tcx().at(span).type_of(did).subst(self.tcx(), substs) ) } @@ -1018,7 +1018,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { assert_eq!(opt_self_ty, None); self.prohibit_type_params(&path.segments); - let ty = ty::queries::type_of::get(tcx, span, def_id); + let ty = tcx.at(span).type_of(def_id); if let Some(free_substs) = self.get_free_substs() { ty.subst(tcx, free_substs) } else { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 6dd4fb7301bc3..70d7336820659 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -479,7 +479,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId) { - let impl_def_ids = ty::queries::inherent_impls::get(self.tcx, self.span, def_id); + let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id); for &impl_def_id in impl_def_ids.iter() { self.assemble_inherent_impl_probe(impl_def_id); } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 9377695376837..57193b3584dfa 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -170,7 +170,7 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // course. if impl_did.is_local() { let span = tcx.def_span(impl_did); - ty::queries::coerce_unsized_info::get(tcx, span, impl_did); + tcx.at(span).coerce_unsized_info(impl_did); } } diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 45881bb3b783a..400aaf82fe428 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -14,7 +14,7 @@ //! for any change, but it is very cheap to compute. In practice, most //! code in the compiler never *directly* requests this map. Instead, //! it requests the inherent impls specific to some type (via -//! `ty::queries::inherent_impls::get(def_id)`). That value, however, +//! `tcx.inherent_impls(def_id)`). That value, however, //! is computed by selecting an idea from this table. use rustc::dep_graph::DepNode; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 83727e9da0325..099586e6bcc2a 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -207,7 +207,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> { def_id: DefId) -> ty::GenericPredicates<'tcx> { - ty::queries::type_param_predicates::get(self.tcx, span, (self.item_def_id, def_id)) + self.tcx.at(span).type_param_predicates((self.item_def_id, def_id)) } fn get_free_substs(&self) -> Option<&Substs<'tcx>> { @@ -475,7 +475,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { hir::ItemTrait(..) => { tcx.generics_of(def_id); tcx.trait_def(def_id); - ty::queries::super_predicates_of::get(tcx, it.span, def_id); + tcx.at(it.span).super_predicates_of(def_id); tcx.predicates_of(def_id); }, hir::ItemStruct(ref struct_def, _) | @@ -556,7 +556,7 @@ fn convert_enum_variant_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, prev_discr = Some(if let Some(e) = variant.node.disr_expr { let expr_did = tcx.hir.local_def_id(e.node_id); let substs = Substs::empty(); - let result = ty::queries::const_eval::get(tcx, variant.span, (expr_did, substs)); + let result = tcx.at(variant.span).const_eval((expr_did, substs)); // enum variant evaluation happens before the global constant check // so we need to report the real error @@ -725,7 +725,7 @@ fn super_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Now require that immediate supertraits are converted, // which will, in turn, reach indirect supertraits. for bound in superbounds.iter().filter_map(|p| p.to_opt_poly_trait_ref()) { - ty::queries::super_predicates_of::get(tcx, item.span, bound.def_id()); + tcx.at(item.span).super_predicates_of(bound.def_id()); } ty::GenericPredicates { From 009f45f8f1fcc0d0a6700fec8e0fd64d5aa739d2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 17 Apr 2017 17:24:05 -0700 Subject: [PATCH 16/16] Run tests for the cargo submodule in tree Previously the `cargotest` suite would run some arbitrary revision of Cargo's test suite, but now that we're bundling it in tree we should be running the Cargo submodule's test suite instead. --- cargo | 2 +- src/bootstrap/check.rs | 40 ++++++++++++++++++++++++++---------- src/bootstrap/lib.rs | 13 ++++++++++++ src/bootstrap/mk/Makefile.in | 1 + src/bootstrap/step.rs | 4 ++++ src/tools/cargotest/main.rs | 20 ------------------ 6 files changed, 48 insertions(+), 32 deletions(-) diff --git a/cargo b/cargo index 8326a3683a904..03efb7fc8b0db 160000 --- a/cargo +++ b/cargo @@ -1 +1 @@ -Subproject commit 8326a3683a9045d825e4fdc4021af340ee3b3755 +Subproject commit 03efb7fc8b0dbb54973ee1b6188f3faf14fffe36 diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index f8f641060c442..8ab07e9e5b564 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -78,14 +78,6 @@ pub fn linkcheck(build: &Build, host: &str) { pub fn cargotest(build: &Build, stage: u32, host: &str) { let ref compiler = Compiler::new(stage, host); - // Configure PATH to find the right rustc. NB. we have to use PATH - // and not RUSTC because the Cargo test suite has tests that will - // fail if rustc is not spelled `rustc`. - let path = build.sysroot(compiler).join("bin"); - let old_path = ::std::env::var("PATH").expect(""); - let sep = if cfg!(windows) { ";" } else {":" }; - let ref newpath = format!("{}{}{}", path.display(), sep, old_path); - // Note that this is a short, cryptic, and not scoped directory name. This // is currently to minimize the length of path on Windows where we otherwise // quickly run into path name limit constraints. @@ -95,9 +87,35 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) { let _time = util::timeit(); let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest")); build.prepare_tool_cmd(compiler, &mut cmd); - build.run(cmd.env("PATH", newpath) - .arg(&build.cargo) - .arg(&out_dir)); + build.run(cmd.arg(&build.cargo) + .arg(&out_dir) + .env("RUSTC", build.compiler_path(compiler)) + .env("RUSTDOC", build.rustdoc(compiler))) +} + +/// Runs `cargo test` for `cargo` packaged with Rust. +pub fn cargo(build: &Build, stage: u32, host: &str) { + let ref compiler = Compiler::new(stage, host); + + // Configure PATH to find the right rustc. NB. we have to use PATH + // and not RUSTC because the Cargo test suite has tests that will + // fail if rustc is not spelled `rustc`. + let path = build.sysroot(compiler).join("bin"); + let old_path = ::std::env::var("PATH").expect(""); + let sep = if cfg!(windows) { ";" } else {":" }; + let ref newpath = format!("{}{}{}", path.display(), sep, old_path); + + let mut cargo = build.cargo(compiler, Mode::Tool, host, "test"); + cargo.arg("--manifest-path").arg(build.src.join("cargo/Cargo.toml")); + + // Don't build tests dynamically, just a pain to work with + cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); + + // Don't run cross-compile tests, we may not have cross-compiled libstd libs + // available. + cargo.env("CFG_DISABLE_CROSS_TESTS", "1"); + + build.run(cargo.env("PATH", newpath)); } /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler. diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 5e046f41673e8..5f518ea56027d 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -557,6 +557,19 @@ impl Build { cargo.env("RUSTC_SAVE_ANALYSIS", "api".to_string()); } + // When being built Cargo will at some point call `nmake.exe` on Windows + // MSVC. Unfortunately `nmake` will read these two environment variables + // below and try to intepret them. We're likely being run, however, from + // MSYS `make` which uses the same variables. + // + // As a result, to prevent confusion and errors, we remove these + // variables from our environment to prevent passing MSYS make flags to + // nmake, causing it to blow up. + if cfg!(target_env = "msvc") { + cargo.env_remove("MAKE"); + cargo.env_remove("MAKEFLAGS"); + } + // Environment variables *required* needed throughout the build // // FIXME: should update code to not require this env var diff --git a/src/bootstrap/mk/Makefile.in b/src/bootstrap/mk/Makefile.in index 457ac825832ce..a5df741e2bfc8 100644 --- a/src/bootstrap/mk/Makefile.in +++ b/src/bootstrap/mk/Makefile.in @@ -55,6 +55,7 @@ check: check-aux: $(Q)$(BOOTSTRAP) test \ src/tools/cargotest \ + cargo \ src/test/pretty \ src/test/run-pass/pretty \ src/test/run-fail/pretty \ diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 17902a39df1e8..d811e1122c42f 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -470,6 +470,10 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .dep(|s| s.name("librustc")) .host(true) .run(move |s| check::cargotest(build, s.stage, s.target)); + rules.test("check-cargo", "cargo") + .dep(|s| s.name("tool-cargo")) + .host(true) + .run(move |s| check::cargo(build, s.stage, s.target)); rules.test("check-tidy", "src/tools/tidy") .dep(|s| s.name("tool-tidy").stage(0)) .default(true) diff --git a/src/tools/cargotest/main.rs b/src/tools/cargotest/main.rs index c7113edbf9e68..012ee835494e8 100644 --- a/src/tools/cargotest/main.rs +++ b/src/tools/cargotest/main.rs @@ -22,12 +22,6 @@ struct Test { } const TEST_REPOS: &'static [Test] = &[ - Test { - name: "cargo", - repo: "https://github.com/rust-lang/cargo", - sha: "0e1e34be7540bdaed4918457654fbf028cf69e56", - lock: None, - }, Test { name: "iron", repo: "https://github.com/iron/iron", @@ -61,20 +55,6 @@ const TEST_REPOS: &'static [Test] = &[ ]; fn main() { - // One of the projects being tested here is Cargo, and when being tested - // Cargo will at some point call `nmake.exe` on Windows MSVC. Unfortunately - // `nmake` will read these two environment variables below and try to - // intepret them. We're likely being run, however, from MSYS `make` which - // uses the same variables. - // - // As a result, to prevent confusion and errors, we remove these variables - // from our environment to prevent passing MSYS make flags to nmake, causing - // it to blow up. - if cfg!(target_env = "msvc") { - env::remove_var("MAKE"); - env::remove_var("MAKEFLAGS"); - } - let args = env::args().collect::>(); let ref cargo = args[1]; let out_dir = Path::new(&args[2]);