From 48e3da6d5910d119d4afefd7d06340390db6968d Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 27 Apr 2019 07:23:31 -0700 Subject: [PATCH 001/109] remove dead code: requires_move_before_drop --- src/libstd/sys/redox/fast_thread_local.rs | 4 ---- src/libstd/sys/unix/fast_thread_local.rs | 4 ---- src/libstd/sys/windows/fast_thread_local.rs | 4 ---- src/libstd/thread/local.rs | 15 +++------------ 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index 1202708a4769..fd278bfe39ac 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -105,7 +105,3 @@ pub unsafe extern fn destroy_value(ptr: *mut u8) { ptr::drop_in_place((*ptr).inner.get()); } } - -pub fn requires_move_before_drop() -> bool { - false -} diff --git a/src/libstd/sys/unix/fast_thread_local.rs b/src/libstd/sys/unix/fast_thread_local.rs index 17478dce4fe5..c34c2e6e786e 100644 --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -82,7 +82,3 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { } } } - -pub fn requires_move_before_drop() -> bool { - false -} diff --git a/src/libstd/sys/windows/fast_thread_local.rs b/src/libstd/sys/windows/fast_thread_local.rs index 0ccc67e3fd54..31d0bd1e72ed 100644 --- a/src/libstd/sys/windows/fast_thread_local.rs +++ b/src/libstd/sys/windows/fast_thread_local.rs @@ -2,7 +2,3 @@ #![cfg(target_thread_local)] pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; - -pub fn requires_move_before_drop() -> bool { - false -} diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index bfc1deddf7bd..0d5e1f2af38a 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -344,7 +344,7 @@ pub mod fast { use crate::fmt; use crate::mem; use crate::ptr; - use crate::sys::fast_thread_local::{register_dtor, requires_move_before_drop}; + use crate::sys::fast_thread_local::register_dtor; pub struct Key { inner: UnsafeCell>, @@ -395,17 +395,8 @@ pub mod fast { // destructor as running for this thread so calls to `get` will return // `None`. (*ptr).dtor_running.set(true); - - // Some implementations may require us to move the value before we drop - // it as it could get re-initialized in-place during destruction. - // - // Hence, we use `ptr::read` on those platforms (to move to a "safe" - // location) instead of drop_in_place. - if requires_move_before_drop() { - ptr::read((*ptr).inner.get()); - } else { - ptr::drop_in_place((*ptr).inner.get()); - } + + ptr::drop_in_place((*ptr).inner.get()); } } From ae4be16e407061828fe604b1ccbd61181b14a3f1 Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 27 Apr 2019 07:38:01 -0700 Subject: [PATCH 002/109] redox had a copy of fast thread local (oversight?) --- src/libstd/sys/redox/fast_thread_local.rs | 105 +--------------------- 1 file changed, 1 insertion(+), 104 deletions(-) diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index fd278bfe39ac..67b92d490b23 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -1,107 +1,4 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "0")] -use crate::cell::{Cell, UnsafeCell}; -use crate::mem; -use crate::ptr; - - -pub struct Key { - inner: UnsafeCell>, - - // Metadata to keep track of the state of the destructor. Remember that - // these variables are thread-local, not global. - dtor_registered: Cell, - dtor_running: Cell, -} - -unsafe impl Sync for Key { } - -impl Key { - pub const fn new() -> Key { - Key { - inner: UnsafeCell::new(None), - dtor_registered: Cell::new(false), - dtor_running: Cell::new(false) - } - } - - pub fn get(&'static self) -> Option<&'static UnsafeCell>> { - unsafe { - if mem::needs_drop::() && self.dtor_running.get() { - return None - } - self.register_dtor(); - } - Some(&self.inner) - } - - unsafe fn register_dtor(&self) { - if !mem::needs_drop::() || self.dtor_registered.get() { - return - } - - register_dtor(self as *const _ as *mut u8, - destroy_value::); - self.dtor_registered.set(true); - } -} - -pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { - // The fallback implementation uses a vanilla OS-based TLS key to track - // the list of destructors that need to be run for this thread. The key - // then has its own destructor which runs all the other destructors. - // - // The destructor for DTORS is a little special in that it has a `while` - // loop to continuously drain the list of registered destructors. It - // *should* be the case that this loop always terminates because we - // provide the guarantee that a TLS key cannot be set after it is - // flagged for destruction. - use crate::sys_common::thread_local as os; - - static DTORS: os::StaticKey = os::StaticKey::new(Some(run_dtors)); - type List = Vec<(*mut u8, unsafe extern fn(*mut u8))>; - if DTORS.get().is_null() { - let v: Box = box Vec::new(); - DTORS.set(Box::into_raw(v) as *mut u8); - } - let list: &mut List = &mut *(DTORS.get() as *mut List); - list.push((t, dtor)); - - unsafe extern fn run_dtors(mut ptr: *mut u8) { - while !ptr.is_null() { - let list: Box = Box::from_raw(ptr as *mut List); - for (ptr, dtor) in list.into_iter() { - dtor(ptr); - } - ptr = DTORS.get(); - DTORS.set(ptr::null_mut()); - } - } -} - -pub unsafe extern fn destroy_value(ptr: *mut u8) { - let ptr = ptr as *mut Key; - // Right before we run the user destructor be sure to flag the - // destructor as running for this thread so calls to `get` will return - // `None`. - (*ptr).dtor_running.set(true); - - // The macOS implementation of TLS apparently had an odd aspect to it - // where the pointer we have may be overwritten while this destructor - // is running. Specifically if a TLS destructor re-accesses TLS it may - // trigger a re-initialization of all TLS variables, paving over at - // least some destroyed ones with initial values. - // - // This means that if we drop a TLS value in place on macOS that we could - // revert the value to its original state halfway through the - // destructor, which would be bad! - // - // Hence, we use `ptr::read` on macOS (to move to a "safe" location) - // instead of drop_in_place. - if cfg!(target_os = "macos") { - ptr::read((*ptr).inner.get()); - } else { - ptr::drop_in_place((*ptr).inner.get()); - } -} +pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; \ No newline at end of file From 430a091cd80c0e4b6bf44f6a19463a832e566f97 Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 27 Apr 2019 08:01:32 -0700 Subject: [PATCH 003/109] ensure fast thread local lookups occur once per access on macos --- src/libstd/sys/redox/fast_thread_local.rs | 6 +++++- src/libstd/sys/unix/fast_thread_local.rs | 17 +++++++++++++++++ src/libstd/sys/windows/fast_thread_local.rs | 4 ++++ src/libstd/thread/local.rs | 11 ++++++----- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index 67b92d490b23..c34cd575db70 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -1,4 +1,8 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "0")] -pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; \ No newline at end of file +pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; + +pub unsafe fn lookup_once(ptr: *const &T) -> &T { + *ptr +} diff --git a/src/libstd/sys/unix/fast_thread_local.rs b/src/libstd/sys/unix/fast_thread_local.rs index c34c2e6e786e..28fb98005410 100644 --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -82,3 +82,20 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { } } } + +#[cfg(not(target_os = "macos"))] +pub unsafe fn lookup_once(ptr: *const &T) -> &T { + *ptr +} + +#[cfg(target_os = "macos")] +pub unsafe fn lookup_once(ptr: *const &T) -> &T { + // On macos, thread_local lookups can result in terrible code due to + // aggressive rerunning of the macos equivalent of `__tls_get_addr` - four + // lookups per actual reference in user code. + // + // Using a read_volatile on a value holding fast Key's address tricks the + // optimizer into only calling the macos get_addr equivalent once per time + // requested by the user. + crate::ptr::read_volatile(ptr) +} diff --git a/src/libstd/sys/windows/fast_thread_local.rs b/src/libstd/sys/windows/fast_thread_local.rs index 31d0bd1e72ed..566d5524fd7c 100644 --- a/src/libstd/sys/windows/fast_thread_local.rs +++ b/src/libstd/sys/windows/fast_thread_local.rs @@ -2,3 +2,7 @@ #![cfg(target_thread_local)] pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; + +pub unsafe fn lookup_once(ptr: *const &T) -> &T { + *ptr +} diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 0d5e1f2af38a..9ce2fcf23522 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -344,7 +344,7 @@ pub mod fast { use crate::fmt; use crate::mem; use crate::ptr; - use crate::sys::fast_thread_local::register_dtor; + use crate::sys::fast_thread_local::{lookup_once, register_dtor}; pub struct Key { inner: UnsafeCell>, @@ -371,11 +371,12 @@ pub mod fast { } pub unsafe fn get(&self) -> Option<&'static UnsafeCell>> { - if mem::needs_drop::() && self.dtor_running.get() { + let this = lookup_once(&self); + if mem::needs_drop::() && this.dtor_running.get() { return None } - self.register_dtor(); - Some(&*(&self.inner as *const _)) + this.register_dtor(); + Some(&*(&this.inner as *const _)) } unsafe fn register_dtor(&self) { @@ -395,7 +396,7 @@ pub mod fast { // destructor as running for this thread so calls to `get` will return // `None`. (*ptr).dtor_running.set(true); - + ptr::drop_in_place((*ptr).inner.get()); } } From 7acfb99adc013d4b77c611cfc51bade551205f5a Mon Sep 17 00:00:00 2001 From: tyler Date: Tue, 30 Apr 2019 18:24:38 -0700 Subject: [PATCH 004/109] Revert "ensure fast thread local lookups occur once per access on macos" This reverts commit d252f3b77f3b7d4cd59620588f9d026633c05816. --- src/libstd/sys/redox/fast_thread_local.rs | 6 +----- src/libstd/sys/unix/fast_thread_local.rs | 17 ----------------- src/libstd/sys/windows/fast_thread_local.rs | 4 ---- src/libstd/thread/local.rs | 11 +++++------ 4 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index c34cd575db70..67b92d490b23 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -1,8 +1,4 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "0")] -pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; - -pub unsafe fn lookup_once(ptr: *const &T) -> &T { - *ptr -} +pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; \ No newline at end of file diff --git a/src/libstd/sys/unix/fast_thread_local.rs b/src/libstd/sys/unix/fast_thread_local.rs index 28fb98005410..c34c2e6e786e 100644 --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -82,20 +82,3 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { } } } - -#[cfg(not(target_os = "macos"))] -pub unsafe fn lookup_once(ptr: *const &T) -> &T { - *ptr -} - -#[cfg(target_os = "macos")] -pub unsafe fn lookup_once(ptr: *const &T) -> &T { - // On macos, thread_local lookups can result in terrible code due to - // aggressive rerunning of the macos equivalent of `__tls_get_addr` - four - // lookups per actual reference in user code. - // - // Using a read_volatile on a value holding fast Key's address tricks the - // optimizer into only calling the macos get_addr equivalent once per time - // requested by the user. - crate::ptr::read_volatile(ptr) -} diff --git a/src/libstd/sys/windows/fast_thread_local.rs b/src/libstd/sys/windows/fast_thread_local.rs index 566d5524fd7c..31d0bd1e72ed 100644 --- a/src/libstd/sys/windows/fast_thread_local.rs +++ b/src/libstd/sys/windows/fast_thread_local.rs @@ -2,7 +2,3 @@ #![cfg(target_thread_local)] pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; - -pub unsafe fn lookup_once(ptr: *const &T) -> &T { - *ptr -} diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 9ce2fcf23522..0d5e1f2af38a 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -344,7 +344,7 @@ pub mod fast { use crate::fmt; use crate::mem; use crate::ptr; - use crate::sys::fast_thread_local::{lookup_once, register_dtor}; + use crate::sys::fast_thread_local::register_dtor; pub struct Key { inner: UnsafeCell>, @@ -371,12 +371,11 @@ pub mod fast { } pub unsafe fn get(&self) -> Option<&'static UnsafeCell>> { - let this = lookup_once(&self); - if mem::needs_drop::() && this.dtor_running.get() { + if mem::needs_drop::() && self.dtor_running.get() { return None } - this.register_dtor(); - Some(&*(&this.inner as *const _)) + self.register_dtor(); + Some(&*(&self.inner as *const _)) } unsafe fn register_dtor(&self) { @@ -396,7 +395,7 @@ pub mod fast { // destructor as running for this thread so calls to `get` will return // `None`. (*ptr).dtor_running.set(true); - + ptr::drop_in_place((*ptr).inner.get()); } } From dfe51a7249e04431526cf3b4779316aabef53cca Mon Sep 17 00:00:00 2001 From: tyler Date: Thu, 2 May 2019 22:40:52 -0700 Subject: [PATCH 005/109] restructure thread_local! for better codegen (especially on macos) --- src/libstd/sys/redox/fast_thread_local.rs | 2 +- src/libstd/thread/local.rs | 285 ++++++++++++++-------- src/test/ui/issues/issue-43733.rs | 6 +- src/test/ui/issues/issue-43733.stderr | 8 +- 4 files changed, 195 insertions(+), 106 deletions(-) diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index 67b92d490b23..05464787a05d 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -1,4 +1,4 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "0")] -pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; \ No newline at end of file +pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 0d5e1f2af38a..7ff81bd9a173 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -2,10 +2,7 @@ #![unstable(feature = "thread_local_internals", issue = "0")] -use crate::cell::UnsafeCell; use crate::fmt; -use crate::hint; -use crate::mem; /// A thread local storage key which owns its contents. /// @@ -92,10 +89,7 @@ pub struct LocalKey { // trivially devirtualizable by LLVM because the value of `inner` never // changes and the constant should be readonly within a crate. This mainly // only runs into problems when TLS statics are exported across crates. - inner: unsafe fn() -> Option<&'static UnsafeCell>>, - - // initialization routine to invoke to create a value - init: fn() -> T, + inner: unsafe fn() -> Option<&'static T>, } #[stable(feature = "std_debug", since = "1.16.0")] @@ -159,10 +153,7 @@ macro_rules! __thread_local_inner { #[inline] fn __init() -> $t { $init } - unsafe fn __getit() -> $crate::option::Option< - &'static $crate::cell::UnsafeCell< - $crate::option::Option<$t>>> - { + unsafe fn __getit() -> $crate::option::Option<&'static $t> { #[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] static __KEY: $crate::thread::__StaticLocalKeyInner<$t> = $crate::thread::__StaticLocalKeyInner::new(); @@ -182,11 +173,11 @@ macro_rules! __thread_local_inner { static __KEY: $crate::thread::__OsLocalKeyInner<$t> = $crate::thread::__OsLocalKeyInner::new(); - __KEY.get() + __KEY.get(__init) } unsafe { - $crate::thread::LocalKey::new(__getit, __init) + $crate::thread::LocalKey::new(__getit) } } }; @@ -221,11 +212,9 @@ impl LocalKey { #[unstable(feature = "thread_local_internals", reason = "recently added to create a key", issue = "0")] - pub const unsafe fn new(inner: unsafe fn() -> Option<&'static UnsafeCell>>, - init: fn() -> T) -> LocalKey { + pub const unsafe fn new(inner: unsafe fn() -> Option<&'static T>) -> LocalKey { LocalKey { inner, - init, } } @@ -246,37 +235,6 @@ impl LocalKey { after it is destroyed") } - unsafe fn init(&self, slot: &UnsafeCell>) -> &T { - // Execute the initialization up front, *then* move it into our slot, - // just in case initialization fails. - let value = (self.init)(); - let ptr = slot.get(); - - // note that this can in theory just be `*ptr = Some(value)`, but due to - // the compiler will currently codegen that pattern with something like: - // - // ptr::drop_in_place(ptr) - // ptr::write(ptr, Some(value)) - // - // Due to this pattern it's possible for the destructor of the value in - // `ptr` (e.g., if this is being recursively initialized) to re-access - // TLS, in which case there will be a `&` and `&mut` pointer to the same - // value (an aliasing violation). To avoid setting the "I'm running a - // destructor" flag we just use `mem::replace` which should sequence the - // operations a little differently and make this safe to call. - mem::replace(&mut *ptr, Some(value)); - - // After storing `Some` we want to get a reference to the contents of - // what we just stored. While we could use `unwrap` here and it should - // always work it empirically doesn't seem to always get optimized away, - // which means that using something like `try_with` can pull in - // panicking code and cause a large size bloat. - match *ptr { - Some(ref x) => x, - None => hint::unreachable_unchecked(), - } - } - /// Acquires a reference to the value in this TLS key. /// /// This will lazily initialize the value if this thread has not referenced @@ -293,13 +251,68 @@ impl LocalKey { F: FnOnce(&T) -> R, { unsafe { - let slot = (self.inner)().ok_or(AccessError { + let thread_local = (self.inner)().ok_or(AccessError { _private: (), })?; - Ok(f(match *slot.get() { - Some(ref inner) => inner, - None => self.init(slot), - })) + Ok(f(thread_local)) + } + } +} + +mod lazy { + use crate::cell::UnsafeCell; + use crate::mem; + use crate::hint; + + pub struct LazyKeyInner { + inner: UnsafeCell>, + } + + impl LazyKeyInner { + pub const fn new() -> LazyKeyInner { + LazyKeyInner { + inner: UnsafeCell::new(None), + } + } + + #[inline] + pub unsafe fn get(&self) -> Option<&'static T> { + (*self.inner.get()).as_ref() + } + + pub unsafe fn initialize T>(&self, init: F) -> &'static T { + // Execute the initialization up front, *then* move it into our slot, + // just in case initialization fails. + let value = init(); + let ptr = self.inner.get(); + + // note that this can in theory just be `*ptr = Some(value)`, but due to + // the compiler will currently codegen that pattern with something like: + // + // ptr::drop_in_place(ptr) + // ptr::write(ptr, Some(value)) + // + // Due to this pattern it's possible for the destructor of the value in + // `ptr` (e.g., if this is being recursively initialized) to re-access + // TLS, in which case there will be a `&` and `&mut` pointer to the same + // value (an aliasing violation). To avoid setting the "I'm running a + // destructor" flag we just use `mem::replace` which should sequence the + // operations a little differently and make this safe to call. + mem::replace(&mut *ptr, Some(value)); + + // After storing `Some` we want to get a reference to the contents of + // what we just stored. While we could use `unwrap` here and it should + // always work it empirically doesn't seem to always get optimized away, + // which means that using something like `try_with` can pull in + // panicking code and cause a large size bloat. + match *ptr { + Some(ref x) => x, + None => hint::unreachable_unchecked(), + } + } + + pub unsafe fn take(&mut self) -> Option { + (*self.inner.get()).take() } } } @@ -309,11 +322,12 @@ impl LocalKey { #[doc(hidden)] #[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] pub mod statik { + use super::lazy::LazyKeyInner; use crate::cell::UnsafeCell; use crate::fmt; pub struct Key { - inner: UnsafeCell>, + inner: LazyKeyInner, } unsafe impl Sync for Key { } @@ -327,12 +341,17 @@ pub mod statik { impl Key { pub const fn new() -> Key { Key { - inner: UnsafeCell::new(None), + inner: LazyKeyInner::new(), } } - pub unsafe fn get(&self) -> Option<&'static UnsafeCell>> { - Some(&*(&self.inner as *const _)) + #[inline] + pub unsafe fn get(&self, init: fn() -> T) -> Option<&'static T> { + let value = match self.inner.get() { + Some(ref value) => value, + None => self.inner.initialize(init), + }; + Some(value) } } } @@ -340,19 +359,33 @@ pub mod statik { #[doc(hidden)] #[cfg(target_thread_local)] pub mod fast { - use crate::cell::{Cell, UnsafeCell}; + use super::lazy::LazyKeyInner; + use crate::cell::Cell; use crate::fmt; use crate::mem; - use crate::ptr; use crate::sys::fast_thread_local::register_dtor; + #[derive(Copy, Clone)] + enum DtorState { + Unregistered, + Registered, + RunningOrHasRun, + } + pub struct Key { - inner: UnsafeCell>, + // If `LazyKeyInner::get` returns `None`, that indicates either: + // * The value has never been initialized + // * The value is being recursively initialized + // * The value has already been destroyed or is being destroyed + // To determine which kind of `None`, check `dtor_state`. + // + // This is very optimizer friendly for the fast path - initialized but + // not yet dropped. + inner: LazyKeyInner, // Metadata to keep track of the state of the destructor. Remember that - // these variables are thread-local, not global. - dtor_registered: Cell, - dtor_running: Cell, + // this variable is thread-local, not global. + dtor_state: Cell, } impl fmt::Debug for Key { @@ -364,45 +397,84 @@ pub mod fast { impl Key { pub const fn new() -> Key { Key { - inner: UnsafeCell::new(None), - dtor_registered: Cell::new(false), - dtor_running: Cell::new(false) + inner: LazyKeyInner::new(), + dtor_state: Cell::new(DtorState::Unregistered), } } - pub unsafe fn get(&self) -> Option<&'static UnsafeCell>> { - if mem::needs_drop::() && self.dtor_running.get() { - return None + #[inline] + pub unsafe fn get T>(&self, init: F) -> Option<&'static T> { + match self.inner.get() { + Some(val) => Some(val), + None => { + if mem::needs_drop::() { + self.try_initialize_drop(init) + } else { + Some(self.try_initialize_nodrop(init)) + } + } } - self.register_dtor(); - Some(&*(&self.inner as *const _)) } - unsafe fn register_dtor(&self) { - if !mem::needs_drop::() || self.dtor_registered.get() { - return + // `try_initialize_nodrop` is only called once per fast thread local + // variable, except in corner cases where it is being recursively + // initialized. + // + // Macos: Inlining this function causes two `tlv_get_addr` calls to be + // performed for every call to `Key::get`. + // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 + #[inline(never)] + #[cold] + unsafe fn try_initialize_nodrop T>(&self, init: F) -> &'static T { + self.inner.initialize(init) + } + + // `try_initialize_drop` is only called once per fast thread local + // variable, except in corner cases where thread_local dtors reference + // other thread_local's, or it is being recursively initialized. + #[inline(never)] + #[cold] + unsafe fn try_initialize_drop T>(&self, init: F) -> Option<&'static T> { + // We don't put a `needs_drop` check around this and call it a day + // because this function is not inlined. Unwrapping code gets + // generated for callers of `LocalKey::with` even if we always + // return `Some` here. + match self.dtor_state.get() { + DtorState::Unregistered => { + // dtor registration happens before initialization. + register_dtor(self as *const _ as *mut u8, + destroy_value::); + self.dtor_state.set(DtorState::Registered); + } + DtorState::Registered => { + // recursively initialized + } + DtorState::RunningOrHasRun => { + return None + } } - register_dtor(self as *const _ as *mut u8, - destroy_value::); - self.dtor_registered.set(true); + Some(self.inner.initialize(init)) } } unsafe extern fn destroy_value(ptr: *mut u8) { let ptr = ptr as *mut Key; - // Right before we run the user destructor be sure to flag the - // destructor as running for this thread so calls to `get` will return - // `None`. - (*ptr).dtor_running.set(true); - - ptr::drop_in_place((*ptr).inner.get()); + + // Right before we run the user destructor be sure to set the + // `Option` to `None`, and `dtor_state` to `RunningOrHasRun`. This + // causes future calls to `get` to run `try_initialize_drop` again, + // which will now fail, and return `None`. + let value = (*ptr).inner.take(); + (*ptr).dtor_state.set(DtorState::RunningOrHasRun); + drop(value); } } #[doc(hidden)] pub mod os { - use crate::cell::{Cell, UnsafeCell}; + use super::lazy::LazyKeyInner; + use crate::cell::Cell; use crate::fmt; use crate::marker; use crate::ptr; @@ -423,8 +495,8 @@ pub mod os { unsafe impl Sync for Key { } struct Value { + inner: LazyKeyInner, key: &'static Key, - value: UnsafeCell>, } impl Key { @@ -435,24 +507,43 @@ pub mod os { } } - pub unsafe fn get(&'static self) -> Option<&'static UnsafeCell>> { + pub unsafe fn get(&'static self, init: fn() -> T) -> Option<&'static T> { let ptr = self.os.get() as *mut Value; - if !ptr.is_null() { - if ptr as usize == 1 { - return None + if ptr as usize > 1 { + match (*ptr).inner.get() { + Some(ref value) => return Some(value), + None => {}, } - return Some(&(*ptr).value); + } + self.try_initialize(init) + } + + // `try_initialize` is only called once per os thread local variable, + // except in corner cases where thread_local dtors reference other + // thread_local's, or it is being recursively initialized. + unsafe fn try_initialize(&'static self, init: fn() -> T) -> Option<&'static T> { + let ptr = self.os.get() as *mut Value; + if ptr as usize == 1 { + // destructor is running + return None } - // If the lookup returned null, we haven't initialized our own - // local copy, so do that now. - let ptr: Box> = box Value { - key: self, - value: UnsafeCell::new(None), + let ptr = if ptr.is_null() { + // If the lookup returned null, we haven't initialized our own + // local copy, so do that now. + let ptr: Box> = box Value { + inner: LazyKeyInner::new(), + key: self, + }; + let ptr = Box::into_raw(ptr); + self.os.set(ptr as *mut u8); + ptr + } else { + // recursive initialization + ptr }; - let ptr = Box::into_raw(ptr); - self.os.set(ptr as *mut u8); - Some(&(*ptr).value) + + Some((*ptr).inner.initialize(init)) } } diff --git a/src/test/ui/issues/issue-43733.rs b/src/test/ui/issues/issue-43733.rs index 91192e3360c2..ba599ff7ce4d 100644 --- a/src/test/ui/issues/issue-43733.rs +++ b/src/test/ui/issues/issue-43733.rs @@ -13,11 +13,9 @@ static __KEY: std::thread::__FastLocalKeyInner = static __KEY: std::thread::__OsLocalKeyInner = std::thread::__OsLocalKeyInner::new(); -fn __getit() -> std::option::Option< - &'static std::cell::UnsafeCell< - std::option::Option>> +fn __getit(init: fn() -> Foo) -> std::option::Option<&'static Foo> { - __KEY.get() //~ ERROR call to unsafe function is unsafe + __KEY.get(init) //~ ERROR call to unsafe function is unsafe } static FOO: std::thread::LocalKey = diff --git a/src/test/ui/issues/issue-43733.stderr b/src/test/ui/issues/issue-43733.stderr index c48f9baf2719..0ea931d7fb6e 100644 --- a/src/test/ui/issues/issue-43733.stderr +++ b/src/test/ui/issues/issue-43733.stderr @@ -1,13 +1,13 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or block - --> $DIR/issue-43733.rs:20:5 + --> $DIR/issue-43733.rs:18:5 | -LL | __KEY.get() - | ^^^^^^^^^^^ call to unsafe function +LL | __KEY.get(init) + | ^^^^^^^^^^^^^^^ call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior error[E0133]: call to unsafe function is unsafe and requires unsafe function or block - --> $DIR/issue-43733.rs:24:5 + --> $DIR/issue-43733.rs:22:5 | LL | std::thread::LocalKey::new(__getit, Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function From b266ba7850d3996b0f19f66d7a28478acfdcdbaf Mon Sep 17 00:00:00 2001 From: tyler Date: Thu, 2 May 2019 23:27:03 -0700 Subject: [PATCH 006/109] update test to match new doc(hidden) thread_local api --- src/test/ui/issues/issue-43733.rs | 6 +++--- src/test/ui/issues/issue-43733.stderr | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/issues/issue-43733.rs b/src/test/ui/issues/issue-43733.rs index ba599ff7ce4d..a602d7667c48 100644 --- a/src/test/ui/issues/issue-43733.rs +++ b/src/test/ui/issues/issue-43733.rs @@ -13,13 +13,13 @@ static __KEY: std::thread::__FastLocalKeyInner = static __KEY: std::thread::__OsLocalKeyInner = std::thread::__OsLocalKeyInner::new(); -fn __getit(init: fn() -> Foo) -> std::option::Option<&'static Foo> +fn __getit() -> std::option::Option<&'static Foo> { - __KEY.get(init) //~ ERROR call to unsafe function is unsafe + __KEY.get(Default::default) //~ ERROR call to unsafe function is unsafe } static FOO: std::thread::LocalKey = - std::thread::LocalKey::new(__getit, Default::default); + std::thread::LocalKey::new(__getit); //~^ ERROR call to unsafe function is unsafe fn main() { diff --git a/src/test/ui/issues/issue-43733.stderr b/src/test/ui/issues/issue-43733.stderr index 0ea931d7fb6e..ee6a3b065d6e 100644 --- a/src/test/ui/issues/issue-43733.stderr +++ b/src/test/ui/issues/issue-43733.stderr @@ -1,16 +1,16 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or block --> $DIR/issue-43733.rs:18:5 | -LL | __KEY.get(init) - | ^^^^^^^^^^^^^^^ call to unsafe function +LL | __KEY.get(Default::default) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior error[E0133]: call to unsafe function is unsafe and requires unsafe function or block --> $DIR/issue-43733.rs:22:5 | -LL | std::thread::LocalKey::new(__getit, Default::default); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function +LL | std::thread::LocalKey::new(__getit); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior From 516c03d5102d0ffb5cc1b86451d837c26d2a0f6a Mon Sep 17 00:00:00 2001 From: tyler Date: Fri, 3 May 2019 09:46:16 -0700 Subject: [PATCH 007/109] fix another test --- src/test/compile-fail/issue-43733-2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/issue-43733-2.rs b/src/test/compile-fail/issue-43733-2.rs index 2943089674d5..8e3c93ac251e 100644 --- a/src/test/compile-fail/issue-43733-2.rs +++ b/src/test/compile-fail/issue-43733-2.rs @@ -23,6 +23,6 @@ use std::thread::__FastLocalKeyInner as Key; static __KEY: Key<()> = Key::new(); //~^ ERROR `std::cell::UnsafeCell>` cannot be shared between threads -//~| ERROR `std::cell::Cell` cannot be shared between threads safely [E0277] +//~| ERROR `std::cell::Cell` cannot be shared between threads safely [E0277] fn main() {} From f5e56eeff6e0ed186410a358db565ab959648aba Mon Sep 17 00:00:00 2001 From: tyler Date: Fri, 3 May 2019 16:26:54 -0700 Subject: [PATCH 008/109] clang tidy fixes --- src/test/compile-fail/issue-43733-2.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/compile-fail/issue-43733-2.rs b/src/test/compile-fail/issue-43733-2.rs index 8e3c93ac251e..c14592187ab7 100644 --- a/src/test/compile-fail/issue-43733-2.rs +++ b/src/test/compile-fail/issue-43733-2.rs @@ -23,6 +23,7 @@ use std::thread::__FastLocalKeyInner as Key; static __KEY: Key<()> = Key::new(); //~^ ERROR `std::cell::UnsafeCell>` cannot be shared between threads -//~| ERROR `std::cell::Cell` cannot be shared between threads safely [E0277] +//~| ERROR `std::cell::Cell` cannot be shared between threads +// safely [E0277] fn main() {} From 060d8bb6b014f9e9c8b697c5ecd6d86159f122b9 Mon Sep 17 00:00:00 2001 From: tyler Date: Fri, 3 May 2019 17:01:53 -0700 Subject: [PATCH 009/109] add #[allow(unused)] --- src/libstd/thread/local.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 7ff81bd9a173..a56a34deba22 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -311,6 +311,7 @@ mod lazy { } } + #[allow(unused)] pub unsafe fn take(&mut self) -> Option { (*self.inner.get()).take() } From 1a7f774914d8d3c2a16e40332ad43270c461ec71 Mon Sep 17 00:00:00 2001 From: tyler Date: Fri, 10 May 2019 17:29:43 -0700 Subject: [PATCH 010/109] - remove unnecessary inlines - add comment explaining that the fast::Key data structure was carefully constructed for fast access on OSX - remove inline(never) from the initializer for types where `needs_drop::()` is false --- src/libstd/thread/local.rs | 39 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index a56a34deba22..e6f096a8da53 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -275,7 +275,6 @@ mod lazy { } } - #[inline] pub unsafe fn get(&self) -> Option<&'static T> { (*self.inner.get()).as_ref() } @@ -346,7 +345,6 @@ pub mod statik { } } - #[inline] pub unsafe fn get(&self, init: fn() -> T) -> Option<&'static T> { let value = match self.inner.get() { Some(ref value) => value, @@ -373,6 +371,11 @@ pub mod fast { RunningOrHasRun, } + // This data structure has been carefully constructed so that the fast path + // only contains one branch on x86. That optimization is necessary to avoid + // duplicated tls lookups on OSX. + // + // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 pub struct Key { // If `LazyKeyInner::get` returns `None`, that indicates either: // * The value has never been initialized @@ -403,38 +406,32 @@ pub mod fast { } } - #[inline] pub unsafe fn get T>(&self, init: F) -> Option<&'static T> { match self.inner.get() { Some(val) => Some(val), - None => { - if mem::needs_drop::() { - self.try_initialize_drop(init) - } else { - Some(self.try_initialize_nodrop(init)) - } - } + None => self.try_initialize(init), } } - // `try_initialize_nodrop` is only called once per fast thread local - // variable, except in corner cases where it is being recursively - // initialized. - // - // Macos: Inlining this function causes two `tlv_get_addr` calls to be - // performed for every call to `Key::get`. - // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 - #[inline(never)] + // `try_initialize` is only called once per fast thread local variable, + // except in corner cases where it is being recursively initialized. #[cold] - unsafe fn try_initialize_nodrop T>(&self, init: F) -> &'static T { - self.inner.initialize(init) + unsafe fn try_initialize T>(&self, init: F) -> Option<&'static T> { + if mem::needs_drop::() { + self.try_initialize_drop(init) + } else { + Some(self.inner.initialize(init)) + } } // `try_initialize_drop` is only called once per fast thread local // variable, except in corner cases where thread_local dtors reference // other thread_local's, or it is being recursively initialized. + // + // Macos: Inlining this function causes two `tlv_get_addr` calls to be + // performed for every call to `Key::get`. + // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 #[inline(never)] - #[cold] unsafe fn try_initialize_drop T>(&self, init: F) -> Option<&'static T> { // We don't put a `needs_drop` check around this and call it a day // because this function is not inlined. Unwrapping code gets From c3241d0ba03ff1e90ffdb4cd434660f81194b438 Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 11 May 2019 10:14:40 -0700 Subject: [PATCH 011/109] cold was necessary on try_initialize_nodrop to get more straight line asm --- src/libstd/thread/local.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index e6f096a8da53..998d9dcc6833 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -432,6 +432,7 @@ pub mod fast { // performed for every call to `Key::get`. // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 #[inline(never)] + #[cold] unsafe fn try_initialize_drop T>(&self, init: F) -> Option<&'static T> { // We don't put a `needs_drop` check around this and call it a day // because this function is not inlined. Unwrapping code gets From 2b3642b95b04b4078405f4bc20ba537ce5512c00 Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 11 May 2019 10:42:44 -0700 Subject: [PATCH 012/109] remove trailing whitespace --- src/libstd/thread/local.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 998d9dcc6833..1a12457646a1 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -374,7 +374,7 @@ pub mod fast { // This data structure has been carefully constructed so that the fast path // only contains one branch on x86. That optimization is necessary to avoid // duplicated tls lookups on OSX. - // + // // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 pub struct Key { // If `LazyKeyInner::get` returns `None`, that indicates either: From 9289d03c9d263ac32a9dd0a5c581779fe1def7d3 Mon Sep 17 00:00:00 2001 From: tyler Date: Wed, 15 May 2019 07:18:24 -0700 Subject: [PATCH 013/109] llvm makes good inlining choices with only the #[cold] attribute --- src/libstd/thread/local.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 1a12457646a1..733c772a1f5f 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -414,46 +414,42 @@ pub mod fast { } // `try_initialize` is only called once per fast thread local variable, - // except in corner cases where it is being recursively initialized. + // except in corner cases where thread_local dtors reference other + // thread_local's, or it is being recursively initialized. + // + // Macos: Inlining this function can cause two `tlv_get_addr` calls to + // be performed for every call to `Key::get`. The #[cold] hint makes + // that less likely. + // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 #[cold] unsafe fn try_initialize T>(&self, init: F) -> Option<&'static T> { - if mem::needs_drop::() { - self.try_initialize_drop(init) - } else { + if !mem::needs_drop::() || self.try_register_dtor() { Some(self.inner.initialize(init)) + } else { + None } } - // `try_initialize_drop` is only called once per fast thread local + // `try_register_dtor` is only called once per fast thread local // variable, except in corner cases where thread_local dtors reference // other thread_local's, or it is being recursively initialized. - // - // Macos: Inlining this function causes two `tlv_get_addr` calls to be - // performed for every call to `Key::get`. - // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 - #[inline(never)] - #[cold] - unsafe fn try_initialize_drop T>(&self, init: F) -> Option<&'static T> { - // We don't put a `needs_drop` check around this and call it a day - // because this function is not inlined. Unwrapping code gets - // generated for callers of `LocalKey::with` even if we always - // return `Some` here. + unsafe fn try_register_dtor(&self) -> bool { match self.dtor_state.get() { DtorState::Unregistered => { // dtor registration happens before initialization. register_dtor(self as *const _ as *mut u8, destroy_value::); self.dtor_state.set(DtorState::Registered); + true } DtorState::Registered => { // recursively initialized + true } DtorState::RunningOrHasRun => { - return None + false } } - - Some(self.inner.initialize(init)) } } From 2c3796172ba2d41f15294e116cd8d993f026b7c2 Mon Sep 17 00:00:00 2001 From: tyler Date: Wed, 15 May 2019 14:35:24 -0700 Subject: [PATCH 014/109] fix wasm unused import in thread local implementation --- src/libstd/thread/local.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 733c772a1f5f..9b355aa2023f 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -323,7 +323,6 @@ mod lazy { #[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] pub mod statik { use super::lazy::LazyKeyInner; - use crate::cell::UnsafeCell; use crate::fmt; pub struct Key { From 97a6c932e02fcd7f55fdad9aef76c5619f91f481 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Sun, 12 May 2019 23:55:58 +0200 Subject: [PATCH 015/109] Implement nth_back for slice::{Iter, IterMut} --- src/libcore/slice/mod.rs | 76 +++++++++++++++++++++++++++----------- src/libcore/tests/slice.rs | 13 +++++++ 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 8731f4867535..016891b29b72 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -3014,6 +3014,28 @@ macro_rules! iterator { {$( $mut_:tt )*}, {$($extra:tt)*} ) => { + // Returns the first element and moves the start of the iterator forwards by 1. + // Greatly improves performance compared to an inlined function. The iterator + // must not be empty. + macro_rules! next_unchecked { + ($self: ident) => {& $( $mut_ )* *$self.post_inc_start(1)} + } + + // Returns the last element and moves the end of the iterator backwards by 1. + // Greatly improves performance compared to an inlined function. The iterator + // must not be empty. + macro_rules! next_back_unchecked { + ($self: ident) => {& $( $mut_ )* *$self.pre_dec_end(1)} + } + + // Shrinks the iterator when T is a ZST, by moving the end of the iterator + // backwards by `n`. `n` must not exceed `self.len()`. + macro_rules! zst_shrink { + ($self: ident, $n: ident) => { + $self.end = ($self.end as * $raw_mut u8).wrapping_offset(-$n) as * $raw_mut T; + } + } + impl<'a, T> $name<'a, T> { // Helper function for creating a slice from the iterator. #[inline(always)] @@ -3023,12 +3045,11 @@ macro_rules! iterator { // Helper function for moving the start of the iterator forwards by `offset` elements, // returning the old start. - // Unsafe because the offset must be in-bounds or one-past-the-end. + // Unsafe because the offset must not exceed `self.len()`. #[inline(always)] unsafe fn post_inc_start(&mut self, offset: isize) -> * $raw_mut T { if mem::size_of::() == 0 { - // This is *reducing* the length. `ptr` never changes with ZST. - self.end = (self.end as * $raw_mut u8).wrapping_offset(-offset) as * $raw_mut T; + zst_shrink!(self, offset); self.ptr } else { let old = self.ptr; @@ -3039,11 +3060,11 @@ macro_rules! iterator { // Helper function for moving the end of the iterator backwards by `offset` elements, // returning the new end. - // Unsafe because the offset must be in-bounds or one-past-the-end. + // Unsafe because the offset must not exceed `self.len()`. #[inline(always)] unsafe fn pre_dec_end(&mut self, offset: isize) -> * $raw_mut T { if mem::size_of::() == 0 { - self.end = (self.end as * $raw_mut u8).wrapping_offset(-offset) as * $raw_mut T; + zst_shrink!(self, offset); self.ptr } else { self.end = self.end.offset(-offset); @@ -3080,7 +3101,7 @@ macro_rules! iterator { if is_empty!(self) { None } else { - Some(& $( $mut_ )* *self.post_inc_start(1)) + Some(next_unchecked!(self)) } } } @@ -3109,11 +3130,10 @@ macro_rules! iterator { } return None; } - // We are in bounds. `offset` does the right thing even for ZSTs. + // We are in bounds. `post_inc_start` does the right thing even for ZSTs. unsafe { - let elem = Some(& $( $mut_ )* *self.ptr.add(n)); - self.post_inc_start((n as isize).wrapping_add(1)); - elem + self.post_inc_start(n as isize); + Some(next_unchecked!(self)) } } @@ -3130,13 +3150,13 @@ macro_rules! iterator { let mut accum = init; unsafe { while len!(self) >= 4 { - accum = f(accum, & $( $mut_ )* *self.post_inc_start(1))?; - accum = f(accum, & $( $mut_ )* *self.post_inc_start(1))?; - accum = f(accum, & $( $mut_ )* *self.post_inc_start(1))?; - accum = f(accum, & $( $mut_ )* *self.post_inc_start(1))?; + accum = f(accum, next_unchecked!(self))?; + accum = f(accum, next_unchecked!(self))?; + accum = f(accum, next_unchecked!(self))?; + accum = f(accum, next_unchecked!(self))?; } while !is_empty!(self) { - accum = f(accum, & $( $mut_ )* *self.post_inc_start(1))?; + accum = f(accum, next_unchecked!(self))?; } } Try::from_ok(accum) @@ -3207,11 +3227,25 @@ macro_rules! iterator { if is_empty!(self) { None } else { - Some(& $( $mut_ )* *self.pre_dec_end(1)) + Some(next_back_unchecked!(self)) } } } + #[inline] + fn nth_back(&mut self, n: usize) -> Option<$elem> { + if n >= len!(self) { + // This iterator is now empty. + self.end = self.ptr; + return None; + } + // We are in bounds. `pre_dec_end` does the right thing even for ZSTs. + unsafe { + self.pre_dec_end(n as isize); + Some(next_back_unchecked!(self)) + } + } + #[inline] fn try_rfold(&mut self, init: B, mut f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try @@ -3220,14 +3254,14 @@ macro_rules! iterator { let mut accum = init; unsafe { while len!(self) >= 4 { - accum = f(accum, & $( $mut_ )* *self.pre_dec_end(1))?; - accum = f(accum, & $( $mut_ )* *self.pre_dec_end(1))?; - accum = f(accum, & $( $mut_ )* *self.pre_dec_end(1))?; - accum = f(accum, & $( $mut_ )* *self.pre_dec_end(1))?; + accum = f(accum, next_back_unchecked!(self))?; + accum = f(accum, next_back_unchecked!(self))?; + accum = f(accum, next_back_unchecked!(self))?; + accum = f(accum, next_back_unchecked!(self))?; } // inlining is_empty everywhere makes a huge performance difference while !is_empty!(self) { - accum = f(accum, & $( $mut_ )* *self.pre_dec_end(1))?; + accum = f(accum, next_back_unchecked!(self))?; } } Try::from_ok(accum) diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index acf6b03791f0..e52879064466 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -88,6 +88,19 @@ fn test_iterator_nth() { assert_eq!(iter.nth(1).unwrap(), &v[4]); } +#[test] +fn test_iterator_nth_back() { + let v: &[_] = &[0, 1, 2, 3, 4]; + for i in 0..v.len() { + assert_eq!(v.iter().nth_back(i).unwrap(), &v[v.len() - i - 1]); + } + assert_eq!(v.iter().nth_back(v.len()), None); + + let mut iter = v.iter(); + assert_eq!(iter.nth_back(2).unwrap(), &v[2]); + assert_eq!(iter.nth_back(1).unwrap(), &v[0]); +} + #[test] fn test_iterator_last() { let v: &[_] = &[0, 1, 2, 3, 4]; From e80a37558df5ac9828caccd48459fdb7be488f5b Mon Sep 17 00:00:00 2001 From: Andrea Corradi Date: Thu, 2 May 2019 14:35:43 +0000 Subject: [PATCH 016/109] Add custom nth_back for Skip --- src/libcore/iter/adapters/mod.rs | 14 +++++++++++++ src/libcore/tests/iter.rs | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index 518442efe741..c2edcd22f953 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -1509,6 +1509,20 @@ impl DoubleEndedIterator for Skip where I: DoubleEndedIterator + ExactSize } } + #[inline] + fn nth_back(&mut self, n: usize) -> Option { + let len = self.len(); + if n < len { + self.iter.nth_back(n) + } else { + if len > 0 { + // consume the original iterator + self.iter.nth_back(len-1); + } + None + } + } + fn try_rfold(&mut self, init: Acc, mut fold: Fold) -> R where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try { diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 7dfb1adad9ee..7e3190f8a20d 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -2280,6 +2280,40 @@ fn test_skip_try_folds() { assert_eq!(iter.next_back(), Some(24)); } +#[test] +fn test_skip_nth_back() { + let xs = [0, 1, 2, 3, 4, 5]; + let mut it = xs.iter().skip(2); + assert_eq!(it.nth_back(0), Some(&5)); + assert_eq!(it.nth_back(1), Some(&3)); + assert_eq!(it.nth_back(0), Some(&2)); + assert_eq!(it.nth_back(0), None); + + let ys = [2, 3, 4, 5]; + let mut ity = ys.iter(); + let mut it = xs.iter().skip(2); + assert_eq!(it.nth_back(1), ity.nth_back(1)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + assert_eq!(it.nth_back(0), ity.nth_back(0)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + assert_eq!(it.nth_back(0), ity.nth_back(0)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + assert_eq!(it.nth_back(0), ity.nth_back(0)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + + let mut it = xs.iter().skip(2); + assert_eq!(it.nth_back(4), None); + assert_eq!(it.nth_back(0), None); + + let mut it = xs.iter(); + it.by_ref().skip(2).nth_back(3); + assert_eq!(it.next_back(), Some(&1)); + + let mut it = xs.iter(); + it.by_ref().skip(2).nth_back(10); + assert_eq!(it.next_back(), Some(&1)); +} + #[test] fn test_take_try_folds() { let f = &|acc, x| i32::checked_add(2*acc, x); From 45bb4097b4bb2670f93d0836d40d31bbde38aab2 Mon Sep 17 00:00:00 2001 From: Edward Barnard Date: Mon, 3 Jun 2019 22:11:57 +0100 Subject: [PATCH 017/109] Only show methods that appear in the impl block for types in the Implementors and Implementations on Foreign Types sections of trait documentation pages. --- src/librustdoc/html/render.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 3555e2e7498b..88ac5aa58d64 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3066,7 +3066,7 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter<' _ => false, }; render_impl(w, cx, implementor, AssocItemLink::Anchor(None), RenderMode::Normal, - implementor.impl_item.stable_since(), false, Some(use_absolute), false)?; + implementor.impl_item.stable_since(), false, Some(use_absolute), false, false)?; Ok(()) } @@ -3077,7 +3077,7 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter<'_>, let did = i.trait_did().unwrap(); let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods); render_impl(w, cx, i, assoc_link, - RenderMode::Normal, containing_item.stable_since(), true, None, false)?; + RenderMode::Normal, containing_item.stable_since(), true, None, false, true)?; } Ok(()) } @@ -3307,7 +3307,7 @@ fn item_trait( ); render_impl(w, cx, &implementor, assoc_link, RenderMode::Normal, implementor.impl_item.stable_since(), false, - None, true)?; + None, true, false)?; } write_loading_content(w, "")?; } @@ -3979,7 +3979,7 @@ fn render_assoc_items(w: &mut fmt::Formatter<'_>, }; for i in &non_trait { render_impl(w, cx, i, AssocItemLink::Anchor(None), render_mode, - containing_item.stable_since(), true, None, false)?; + containing_item.stable_since(), true, None, false, true)?; } } if let AssocItemRender::DerefFor { .. } = what { @@ -4161,7 +4161,8 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result { fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocItemLink<'_>, render_mode: RenderMode, outer_version: Option<&str>, show_def_docs: bool, - use_absolute: Option, is_on_foreign_type: bool) -> fmt::Result { + use_absolute: Option, is_on_foreign_type: bool, + show_default_items: bool) -> fmt::Result { if render_mode == RenderMode::Normal { let id = cx.derive_id(match i.inner_impl().trait_ { Some(ref t) => if is_on_foreign_type { @@ -4345,9 +4346,13 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt // If we've implemented a trait, then also emit documentation for all // default items which weren't overridden in the implementation block. - if let Some(t) = trait_ { - render_default_items(w, cx, t, &i.inner_impl(), - render_mode, outer_version, show_def_docs)?; + // We don't emit documentation for default items if they appear in the + // Implementations on Foreign Types or Implementors sections. + if show_default_items { + if let Some(t) = trait_ { + render_default_items(w, cx, t, &i.inner_impl(), + render_mode, outer_version, show_def_docs)?; + } } write!(w, "")?; From 5fa8b52835e01efc7ba7b5020a1a4dd99b3a9717 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Jun 2019 23:17:14 +0200 Subject: [PATCH 018/109] move stray run-pass const tests into const/ folder --- src/test/run-pass/{ctfe => consts}/assoc-const.rs | 0 src/test/run-pass/{ctfe => consts}/bswap-const.rs | 0 .../run-pass/{ctfe => consts}/chained-constants-stackoverflow.rs | 0 .../run-pass/{ctfe => consts}/const-block-non-item-statement-3.rs | 0 .../run-pass/{ctfe => consts}/const-block-non-item-statement.rs | 0 src/test/run-pass/{ctfe => consts}/const-fn-type-name.rs | 0 src/test/run-pass/{ => consts}/const-int-conversion.rs | 0 src/test/run-pass/{ => consts}/const-int-overflowing.rs | 0 src/test/run-pass/{ => consts}/const-int-rotate.rs | 0 src/test/run-pass/{ => consts}/const-int-saturating-arith.rs | 0 src/test/run-pass/{ => consts}/const-int-sign.rs | 0 src/test/run-pass/{ => consts}/const-int-wrapping.rs | 0 src/test/run-pass/{ => consts}/const-needs_drop.rs | 0 src/test/run-pass/{ctfe => consts}/deref_in_pattern.rs | 0 src/test/run-pass/{ctfe => consts}/ice-48279.rs | 0 src/test/run-pass/{ctfe => consts}/issue-37550.rs | 0 src/test/run-pass/{ctfe => consts}/issue-broken-mir.rs | 0 src/test/run-pass/{ctfe => consts}/locals-in-const-fn.rs | 0 src/test/run-pass/{ctfe => consts}/match-const-fn-structs.rs | 0 src/test/run-pass/{ctfe => consts}/mozjs-error.rs | 0 src/test/run-pass/{ctfe => consts}/non-scalar-cast.rs | 0 src/test/run-pass/{ctfe => consts}/promotion.rs | 0 src/test/run-pass/{ctfe => consts}/references.rs | 0 src/test/run-pass/{ctfe => consts}/repeat_match.rs | 0 src/test/run-pass/{ctfe => consts}/return-in-const-fn.rs | 0 src/test/run-pass/{ctfe => consts}/signed_enum_discr.rs | 0 src/test/run-pass/{ctfe => consts}/transmute-const.rs | 0 src/test/run-pass/{ctfe => consts}/tuple-struct-constructors.rs | 0 28 files changed, 0 insertions(+), 0 deletions(-) rename src/test/run-pass/{ctfe => consts}/assoc-const.rs (100%) rename src/test/run-pass/{ctfe => consts}/bswap-const.rs (100%) rename src/test/run-pass/{ctfe => consts}/chained-constants-stackoverflow.rs (100%) rename src/test/run-pass/{ctfe => consts}/const-block-non-item-statement-3.rs (100%) rename src/test/run-pass/{ctfe => consts}/const-block-non-item-statement.rs (100%) rename src/test/run-pass/{ctfe => consts}/const-fn-type-name.rs (100%) rename src/test/run-pass/{ => consts}/const-int-conversion.rs (100%) rename src/test/run-pass/{ => consts}/const-int-overflowing.rs (100%) rename src/test/run-pass/{ => consts}/const-int-rotate.rs (100%) rename src/test/run-pass/{ => consts}/const-int-saturating-arith.rs (100%) rename src/test/run-pass/{ => consts}/const-int-sign.rs (100%) rename src/test/run-pass/{ => consts}/const-int-wrapping.rs (100%) rename src/test/run-pass/{ => consts}/const-needs_drop.rs (100%) rename src/test/run-pass/{ctfe => consts}/deref_in_pattern.rs (100%) rename src/test/run-pass/{ctfe => consts}/ice-48279.rs (100%) rename src/test/run-pass/{ctfe => consts}/issue-37550.rs (100%) rename src/test/run-pass/{ctfe => consts}/issue-broken-mir.rs (100%) rename src/test/run-pass/{ctfe => consts}/locals-in-const-fn.rs (100%) rename src/test/run-pass/{ctfe => consts}/match-const-fn-structs.rs (100%) rename src/test/run-pass/{ctfe => consts}/mozjs-error.rs (100%) rename src/test/run-pass/{ctfe => consts}/non-scalar-cast.rs (100%) rename src/test/run-pass/{ctfe => consts}/promotion.rs (100%) rename src/test/run-pass/{ctfe => consts}/references.rs (100%) rename src/test/run-pass/{ctfe => consts}/repeat_match.rs (100%) rename src/test/run-pass/{ctfe => consts}/return-in-const-fn.rs (100%) rename src/test/run-pass/{ctfe => consts}/signed_enum_discr.rs (100%) rename src/test/run-pass/{ctfe => consts}/transmute-const.rs (100%) rename src/test/run-pass/{ctfe => consts}/tuple-struct-constructors.rs (100%) diff --git a/src/test/run-pass/ctfe/assoc-const.rs b/src/test/run-pass/consts/assoc-const.rs similarity index 100% rename from src/test/run-pass/ctfe/assoc-const.rs rename to src/test/run-pass/consts/assoc-const.rs diff --git a/src/test/run-pass/ctfe/bswap-const.rs b/src/test/run-pass/consts/bswap-const.rs similarity index 100% rename from src/test/run-pass/ctfe/bswap-const.rs rename to src/test/run-pass/consts/bswap-const.rs diff --git a/src/test/run-pass/ctfe/chained-constants-stackoverflow.rs b/src/test/run-pass/consts/chained-constants-stackoverflow.rs similarity index 100% rename from src/test/run-pass/ctfe/chained-constants-stackoverflow.rs rename to src/test/run-pass/consts/chained-constants-stackoverflow.rs diff --git a/src/test/run-pass/ctfe/const-block-non-item-statement-3.rs b/src/test/run-pass/consts/const-block-non-item-statement-3.rs similarity index 100% rename from src/test/run-pass/ctfe/const-block-non-item-statement-3.rs rename to src/test/run-pass/consts/const-block-non-item-statement-3.rs diff --git a/src/test/run-pass/ctfe/const-block-non-item-statement.rs b/src/test/run-pass/consts/const-block-non-item-statement.rs similarity index 100% rename from src/test/run-pass/ctfe/const-block-non-item-statement.rs rename to src/test/run-pass/consts/const-block-non-item-statement.rs diff --git a/src/test/run-pass/ctfe/const-fn-type-name.rs b/src/test/run-pass/consts/const-fn-type-name.rs similarity index 100% rename from src/test/run-pass/ctfe/const-fn-type-name.rs rename to src/test/run-pass/consts/const-fn-type-name.rs diff --git a/src/test/run-pass/const-int-conversion.rs b/src/test/run-pass/consts/const-int-conversion.rs similarity index 100% rename from src/test/run-pass/const-int-conversion.rs rename to src/test/run-pass/consts/const-int-conversion.rs diff --git a/src/test/run-pass/const-int-overflowing.rs b/src/test/run-pass/consts/const-int-overflowing.rs similarity index 100% rename from src/test/run-pass/const-int-overflowing.rs rename to src/test/run-pass/consts/const-int-overflowing.rs diff --git a/src/test/run-pass/const-int-rotate.rs b/src/test/run-pass/consts/const-int-rotate.rs similarity index 100% rename from src/test/run-pass/const-int-rotate.rs rename to src/test/run-pass/consts/const-int-rotate.rs diff --git a/src/test/run-pass/const-int-saturating-arith.rs b/src/test/run-pass/consts/const-int-saturating-arith.rs similarity index 100% rename from src/test/run-pass/const-int-saturating-arith.rs rename to src/test/run-pass/consts/const-int-saturating-arith.rs diff --git a/src/test/run-pass/const-int-sign.rs b/src/test/run-pass/consts/const-int-sign.rs similarity index 100% rename from src/test/run-pass/const-int-sign.rs rename to src/test/run-pass/consts/const-int-sign.rs diff --git a/src/test/run-pass/const-int-wrapping.rs b/src/test/run-pass/consts/const-int-wrapping.rs similarity index 100% rename from src/test/run-pass/const-int-wrapping.rs rename to src/test/run-pass/consts/const-int-wrapping.rs diff --git a/src/test/run-pass/const-needs_drop.rs b/src/test/run-pass/consts/const-needs_drop.rs similarity index 100% rename from src/test/run-pass/const-needs_drop.rs rename to src/test/run-pass/consts/const-needs_drop.rs diff --git a/src/test/run-pass/ctfe/deref_in_pattern.rs b/src/test/run-pass/consts/deref_in_pattern.rs similarity index 100% rename from src/test/run-pass/ctfe/deref_in_pattern.rs rename to src/test/run-pass/consts/deref_in_pattern.rs diff --git a/src/test/run-pass/ctfe/ice-48279.rs b/src/test/run-pass/consts/ice-48279.rs similarity index 100% rename from src/test/run-pass/ctfe/ice-48279.rs rename to src/test/run-pass/consts/ice-48279.rs diff --git a/src/test/run-pass/ctfe/issue-37550.rs b/src/test/run-pass/consts/issue-37550.rs similarity index 100% rename from src/test/run-pass/ctfe/issue-37550.rs rename to src/test/run-pass/consts/issue-37550.rs diff --git a/src/test/run-pass/ctfe/issue-broken-mir.rs b/src/test/run-pass/consts/issue-broken-mir.rs similarity index 100% rename from src/test/run-pass/ctfe/issue-broken-mir.rs rename to src/test/run-pass/consts/issue-broken-mir.rs diff --git a/src/test/run-pass/ctfe/locals-in-const-fn.rs b/src/test/run-pass/consts/locals-in-const-fn.rs similarity index 100% rename from src/test/run-pass/ctfe/locals-in-const-fn.rs rename to src/test/run-pass/consts/locals-in-const-fn.rs diff --git a/src/test/run-pass/ctfe/match-const-fn-structs.rs b/src/test/run-pass/consts/match-const-fn-structs.rs similarity index 100% rename from src/test/run-pass/ctfe/match-const-fn-structs.rs rename to src/test/run-pass/consts/match-const-fn-structs.rs diff --git a/src/test/run-pass/ctfe/mozjs-error.rs b/src/test/run-pass/consts/mozjs-error.rs similarity index 100% rename from src/test/run-pass/ctfe/mozjs-error.rs rename to src/test/run-pass/consts/mozjs-error.rs diff --git a/src/test/run-pass/ctfe/non-scalar-cast.rs b/src/test/run-pass/consts/non-scalar-cast.rs similarity index 100% rename from src/test/run-pass/ctfe/non-scalar-cast.rs rename to src/test/run-pass/consts/non-scalar-cast.rs diff --git a/src/test/run-pass/ctfe/promotion.rs b/src/test/run-pass/consts/promotion.rs similarity index 100% rename from src/test/run-pass/ctfe/promotion.rs rename to src/test/run-pass/consts/promotion.rs diff --git a/src/test/run-pass/ctfe/references.rs b/src/test/run-pass/consts/references.rs similarity index 100% rename from src/test/run-pass/ctfe/references.rs rename to src/test/run-pass/consts/references.rs diff --git a/src/test/run-pass/ctfe/repeat_match.rs b/src/test/run-pass/consts/repeat_match.rs similarity index 100% rename from src/test/run-pass/ctfe/repeat_match.rs rename to src/test/run-pass/consts/repeat_match.rs diff --git a/src/test/run-pass/ctfe/return-in-const-fn.rs b/src/test/run-pass/consts/return-in-const-fn.rs similarity index 100% rename from src/test/run-pass/ctfe/return-in-const-fn.rs rename to src/test/run-pass/consts/return-in-const-fn.rs diff --git a/src/test/run-pass/ctfe/signed_enum_discr.rs b/src/test/run-pass/consts/signed_enum_discr.rs similarity index 100% rename from src/test/run-pass/ctfe/signed_enum_discr.rs rename to src/test/run-pass/consts/signed_enum_discr.rs diff --git a/src/test/run-pass/ctfe/transmute-const.rs b/src/test/run-pass/consts/transmute-const.rs similarity index 100% rename from src/test/run-pass/ctfe/transmute-const.rs rename to src/test/run-pass/consts/transmute-const.rs diff --git a/src/test/run-pass/ctfe/tuple-struct-constructors.rs b/src/test/run-pass/consts/tuple-struct-constructors.rs similarity index 100% rename from src/test/run-pass/ctfe/tuple-struct-constructors.rs rename to src/test/run-pass/consts/tuple-struct-constructors.rs From 2e9931f9333d74cbe10545978e58e38ee915998a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Jun 2019 00:08:50 +0200 Subject: [PATCH 019/109] test more variants of enum-int-casting --- src/test/run-pass/consts/const-enum-cast.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/run-pass/consts/const-enum-cast.rs b/src/test/run-pass/consts/const-enum-cast.rs index 3b140d147579..a3255c2f601b 100644 --- a/src/test/run-pass/consts/const-enum-cast.rs +++ b/src/test/run-pass/consts/const-enum-cast.rs @@ -1,9 +1,8 @@ // run-pass -#![allow(dead_code)] #![allow(non_upper_case_globals)] enum A { A1, A2 } -enum B { B1=0, B2=2 } +enum B { B1=4, B2=2 } pub fn main () { static c1: isize = A::A2 as isize; @@ -14,4 +13,14 @@ pub fn main () { assert_eq!(c2, 2); assert_eq!(a1, 1); assert_eq!(a2, 2); + + // Turns out that adding a let-binding generates totally different MIR. + static c1_2: isize = { let v = A::A1; v as isize }; + static c2_2: isize = { let v = B::B1; v as isize }; + let a1_2 = { let v = A::A1; v as isize }; + let a2_2 = { let v = B::B1; v as isize }; + assert_eq!(c1_2, 0); + assert_eq!(c2_2, 4); + assert_eq!(a1_2, 0); + assert_eq!(a2_2, 4); } From 047f9bc94d46339032296cd872430cd71031bbbf Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 14 Jun 2019 10:54:27 +0900 Subject: [PATCH 020/109] Add explanation for E0592 --- src/librustc_typeck/error_codes.rs | 23 ++++++++++++++++++- ...nce-overlapping-inherent-impl-trait.stderr | 1 + .../overlapping_inherent_impls.stderr | 1 + ...nce-overlap-downstream-inherent.old.stderr | 1 + ...ence-overlap-downstream-inherent.re.stderr | 1 + ...ce-overlap-issue-23516-inherent.old.stderr | 1 + ...nce-overlap-issue-23516-inherent.re.stderr | 1 + ...rence-overlap-upstream-inherent.old.stderr | 1 + ...erence-overlap-upstream-inherent.re.stderr | 1 + src/test/ui/issues/issue-33140.stderr | 3 ++- .../specialization-overlap-hygiene.stderr | 1 + .../trait-object-auto-dedup-in-impl.stderr | 1 + 12 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index 0b618cdf1dbb..c424388fb2eb 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -3793,6 +3793,28 @@ details. [issue #33685]: https://github.com/rust-lang/rust/issues/33685 "##, +E0592: r##" +This error occurs when you defined methods or associated functions with same +name. + +For example, in the following code: + +```compile_fail,E0592 +struct Foo; + +impl Foo { + fn bar() {} +} + +impl Foo { + fn bar() {} +} +``` + +A similar error is E0201. The difference is whether there is one declaration +block or not. To avoid this error, you have to give them one name each. +"##, + E0599: r##" This error occurs when a method is used on a type which doesn't implement it: @@ -4771,7 +4793,6 @@ register_diagnostics! { // but `{}` was found in the type `{}` E0587, // type has conflicting packed and align representation hints E0588, // packed type cannot transitively contain a `[repr(align)]` type - E0592, // duplicate definitions with name `{}` // E0611, // merged into E0616 // E0612, // merged into E0609 // E0613, // Removed (merged with E0609) diff --git a/src/test/ui/codemap_tests/coherence-overlapping-inherent-impl-trait.stderr b/src/test/ui/codemap_tests/coherence-overlapping-inherent-impl-trait.stderr index a97161b131d4..a60be6f23c41 100644 --- a/src/test/ui/codemap_tests/coherence-overlapping-inherent-impl-trait.stderr +++ b/src/test/ui/codemap_tests/coherence-overlapping-inherent-impl-trait.stderr @@ -8,3 +8,4 @@ LL | impl dyn C { fn f() {} } error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/codemap_tests/overlapping_inherent_impls.stderr b/src/test/ui/codemap_tests/overlapping_inherent_impls.stderr index b16d2849f196..70c1093e9ed4 100644 --- a/src/test/ui/codemap_tests/overlapping_inherent_impls.stderr +++ b/src/test/ui/codemap_tests/overlapping_inherent_impls.stderr @@ -29,3 +29,4 @@ LL | fn baz(&self) {} error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/coherence/coherence-overlap-downstream-inherent.old.stderr b/src/test/ui/coherence/coherence-overlap-downstream-inherent.old.stderr index 283d7a04d9bf..dcfc017f1b03 100644 --- a/src/test/ui/coherence/coherence-overlap-downstream-inherent.old.stderr +++ b/src/test/ui/coherence/coherence-overlap-downstream-inherent.old.stderr @@ -20,3 +20,4 @@ LL | impl A { fn f(&self) {} } error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/coherence/coherence-overlap-downstream-inherent.re.stderr b/src/test/ui/coherence/coherence-overlap-downstream-inherent.re.stderr index 283d7a04d9bf..dcfc017f1b03 100644 --- a/src/test/ui/coherence/coherence-overlap-downstream-inherent.re.stderr +++ b/src/test/ui/coherence/coherence-overlap-downstream-inherent.re.stderr @@ -20,3 +20,4 @@ LL | impl A { fn f(&self) {} } error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.old.stderr b/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.old.stderr index 38df106cc887..6fd930775403 100644 --- a/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.old.stderr +++ b/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.old.stderr @@ -11,3 +11,4 @@ LL | impl Cake> { fn dummy(&self) { } } error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.re.stderr b/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.re.stderr index 38df106cc887..6fd930775403 100644 --- a/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.re.stderr +++ b/src/test/ui/coherence/coherence-overlap-issue-23516-inherent.re.stderr @@ -11,3 +11,4 @@ LL | impl Cake> { fn dummy(&self) { } } error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/coherence/coherence-overlap-upstream-inherent.old.stderr b/src/test/ui/coherence/coherence-overlap-upstream-inherent.old.stderr index 6716b71b25b5..928b65e00391 100644 --- a/src/test/ui/coherence/coherence-overlap-upstream-inherent.old.stderr +++ b/src/test/ui/coherence/coherence-overlap-upstream-inherent.old.stderr @@ -11,3 +11,4 @@ LL | impl A { fn dummy(&self) { } } error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/coherence/coherence-overlap-upstream-inherent.re.stderr b/src/test/ui/coherence/coherence-overlap-upstream-inherent.re.stderr index 6716b71b25b5..928b65e00391 100644 --- a/src/test/ui/coherence/coherence-overlap-upstream-inherent.re.stderr +++ b/src/test/ui/coherence/coherence-overlap-upstream-inherent.re.stderr @@ -11,3 +11,4 @@ LL | impl A { fn dummy(&self) { } } error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/issues/issue-33140.stderr b/src/test/ui/issues/issue-33140.stderr index dae9e02633d0..6c3ba63e6f6f 100644 --- a/src/test/ui/issues/issue-33140.stderr +++ b/src/test/ui/issues/issue-33140.stderr @@ -31,4 +31,5 @@ LL | | } error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0119`. +Some errors have detailed explanations: E0119, E0592. +For more information about an error, try `rustc --explain E0119`. diff --git a/src/test/ui/specialization/specialization-overlap-hygiene.stderr b/src/test/ui/specialization/specialization-overlap-hygiene.stderr index ed99aa3102df..6adf16de4621 100644 --- a/src/test/ui/specialization/specialization-overlap-hygiene.stderr +++ b/src/test/ui/specialization/specialization-overlap-hygiene.stderr @@ -9,3 +9,4 @@ LL | fn f() {} error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. diff --git a/src/test/ui/traits/trait-object-auto-dedup-in-impl.stderr b/src/test/ui/traits/trait-object-auto-dedup-in-impl.stderr index 9cf39584a8c1..2570db0212aa 100644 --- a/src/test/ui/traits/trait-object-auto-dedup-in-impl.stderr +++ b/src/test/ui/traits/trait-object-auto-dedup-in-impl.stderr @@ -9,3 +9,4 @@ LL | fn test(&self) { println!("two"); } error: aborting due to previous error +For more information about this error, try `rustc --explain E0592`. From e252aaec709cab0e460a70f616f49c6e61d7577d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 14 Jun 2019 20:12:01 +0900 Subject: [PATCH 021/109] Fix examples --- src/librustc_typeck/error_codes.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index c424388fb2eb..9f8874f1ff6d 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -3797,22 +3797,34 @@ E0592: r##" This error occurs when you defined methods or associated functions with same name. -For example, in the following code: +Erroneous code example: ```compile_fail,E0592 struct Foo; +impl Foo { + fn bar() {} // previous definition here +} + +impl Foo { + fn bar() {} // duplicate definition here +} +``` + +A similar error is E0201. The difference is whether there is one declaration +block or not. To avoid this error, you have to give them one name each. + +``` +struct Foo; + impl Foo { fn bar() {} } impl Foo { - fn bar() {} + fn baz() {} // define with different name } ``` - -A similar error is E0201. The difference is whether there is one declaration -block or not. To avoid this error, you have to give them one name each. "##, E0599: r##" From ea1bec3a8afbc79c8c1a5b989e1c3d2425400040 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Jun 2019 09:53:59 -0700 Subject: [PATCH 022/109] Turn down the myriad-closures test This tests takes nearly 5 minutes to compile on CI where the CPUs we have aren't exactly the fastest. This test does actually require all closures to exist to exhibit the original bug, but it seems a little excessive to test a single bug on CI on all platforms which simply pegs a single CPU for 5 minutes with no parallelism opportunities, so this turns down the test to still exercise it somewhat at least. --- src/test/run-pass-fulldeps/myriad-closures.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/run-pass-fulldeps/myriad-closures.rs b/src/test/run-pass-fulldeps/myriad-closures.rs index a1ea0e685d65..a6d3530f1390 100644 --- a/src/test/run-pass-fulldeps/myriad-closures.rs +++ b/src/test/run-pass-fulldeps/myriad-closures.rs @@ -32,7 +32,7 @@ macro_rules! mk_fn { } fn main() { - // Make 2^12 functions, each containing 16 closures, - // resulting in 2^16 closures overall. - go_bacterial!(mk_fn 1 1 1 1 1 1 1 1 1 1 1 1); + // Make 2^8 functions, each containing 16 closures, + // resulting in 2^12 closures overall. + go_bacterial!(mk_fn 1 1 1 1 1 1 1 1); } From 007aabae930d753742f6916d91d3fc8838db08a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 14 Jun 2019 18:09:57 +0200 Subject: [PATCH 023/109] Remove unnecessary lift calls --- src/librustc/infer/canonical/canonicalizer.rs | 30 +++++-------------- src/librustc/infer/canonical/mod.rs | 4 +-- .../infer/canonical/query_response.rs | 16 +++++----- src/librustc/infer/opaque_types/mod.rs | 5 ---- src/librustc/middle/mem_categorization.rs | 5 +--- src/librustc/traits/codegen/mod.rs | 10 ++----- src/librustc/traits/project.rs | 1 - src/librustc/traits/query/normalize.rs | 1 - src/librustc/traits/query/type_op/mod.rs | 6 ++-- .../traits/query/type_op/normalize.rs | 2 +- src/librustc/traits/specialize/mod.rs | 7 +---- src/librustc/ty/error.rs | 9 ++++-- src/librustc/ty/sty.rs | 13 ++++---- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/nll/region_infer/mod.rs | 4 +-- .../borrow_check/nll/type_check/mod.rs | 4 +-- src/librustc_mir/build/expr/as_rvalue.rs | 4 +-- .../dataflow/drop_flag_effects.rs | 2 +- src/librustc_mir/hair/constant.rs | 2 +- src/librustc_mir/hair/cx/mod.rs | 7 +---- src/librustc_mir/hair/pattern/_match.rs | 2 +- .../normalize_erasing_regions.rs | 3 +- 22 files changed, 50 insertions(+), 89 deletions(-) diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index b4779eec65f4..a156075b8127 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -14,7 +14,7 @@ use crate::mir::interpret::ConstValue; use std::sync::atomic::Ordering; use crate::ty::fold::{TypeFoldable, TypeFolder}; use crate::ty::subst::Kind; -use crate::ty::{self, BoundVar, InferConst, Lift, List, Ty, TyCtxt, TypeFlags}; +use crate::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags}; use crate::ty::flags::FlagComputation; use rustc_data_structures::fx::FxHashMap; @@ -43,7 +43,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { query_state: &mut OriginalQueryValues<'tcx>, ) -> Canonicalized<'tcx, V> where - V: TypeFoldable<'tcx> + Lift<'tcx>, + V: TypeFoldable<'tcx>, { self.tcx .sess @@ -87,7 +87,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { /// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html#canonicalizing-the-query-result pub fn canonicalize_response(&self, value: &V) -> Canonicalized<'tcx, V> where - V: TypeFoldable<'tcx> + Lift<'tcx>, + V: TypeFoldable<'tcx>, { let mut query_state = OriginalQueryValues::default(); Canonicalizer::canonicalize( @@ -101,7 +101,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { pub fn canonicalize_user_type_annotation(&self, value: &V) -> Canonicalized<'tcx, V> where - V: TypeFoldable<'tcx> + Lift<'tcx>, + V: TypeFoldable<'tcx>, { let mut query_state = OriginalQueryValues::default(); Canonicalizer::canonicalize( @@ -132,7 +132,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { query_state: &mut OriginalQueryValues<'tcx>, ) -> Canonicalized<'tcx, V> where - V: TypeFoldable<'tcx> + Lift<'tcx>, + V: TypeFoldable<'tcx>, { self.tcx .sess @@ -506,7 +506,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { query_state: &mut OriginalQueryValues<'tcx>, ) -> Canonicalized<'tcx, V> where - V: TypeFoldable<'tcx> + Lift<'tcx>, + V: TypeFoldable<'tcx>, { let needs_canonical_flags = if canonicalize_region_mode.any() { TypeFlags::KEEP_IN_LOCAL_TCX | @@ -520,20 +520,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { TypeFlags::HAS_CT_PLACEHOLDER }; - let gcx = tcx.global_tcx(); - // Fast path: nothing that needs to be canonicalized. if !value.has_type_flags(needs_canonical_flags) { - let out_value = gcx.lift(value).unwrap_or_else(|| { - bug!( - "failed to lift `{:?}` (nothing to canonicalize)", - value - ) - }); let canon_value = Canonical { max_universe: ty::UniverseIndex::ROOT, variables: List::empty(), - value: out_value, + value: value.clone(), }; return canon_value; } @@ -553,13 +545,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { // Once we have canonicalized `out_value`, it should not // contain anything that ties it to this inference context // anymore, so it should live in the global arena. - let out_value = gcx.lift(&out_value).unwrap_or_else(|| { - bug!( - "failed to lift `{:?}`, canonicalized from `{:?}`", - out_value, - value - ) - }); + debug_assert!(!out_value.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)); let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables); diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs index 8b1c34a487f5..b2c7bd73b681 100644 --- a/src/librustc/infer/canonical/mod.rs +++ b/src/librustc/infer/canonical/mod.rs @@ -194,10 +194,10 @@ pub struct QueryResponse<'tcx, R> { pub value: R, } -pub type Canonicalized<'tcx, V> = Canonical<'tcx, >::Lifted>; +pub type Canonicalized<'tcx, V> = Canonical<'tcx, V>; pub type CanonicalizedQueryResponse<'tcx, T> = - &'tcx Canonical<'tcx, QueryResponse<'tcx, >::Lifted>>; + &'tcx Canonical<'tcx, QueryResponse<'tcx, T>>; /// Indicates whether or not we were able to prove the query to be /// true. diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs index 8b11ebf9b924..3e92fed005cd 100644 --- a/src/librustc/infer/canonical/query_response.rs +++ b/src/librustc/infer/canonical/query_response.rs @@ -26,7 +26,7 @@ use crate::traits::TraitEngine; use crate::traits::{Obligation, ObligationCause, PredicateObligation}; use crate::ty::fold::TypeFoldable; use crate::ty::subst::{Kind, UnpackedKind}; -use crate::ty::{self, BoundVar, InferConst, Lift, Ty, TyCtxt}; +use crate::ty::{self, BoundVar, InferConst, Ty, TyCtxt}; use crate::util::captures::Captures; impl<'tcx> InferCtxtBuilder<'tcx> { @@ -53,8 +53,8 @@ impl<'tcx> InferCtxtBuilder<'tcx> { ) -> Fallible> where K: TypeFoldable<'tcx>, - R: Debug + Lift<'tcx> + TypeFoldable<'tcx>, - Canonical<'tcx, as Lift<'tcx>>::Lifted>: ArenaAllocatable, + R: Debug + TypeFoldable<'tcx>, + Canonical<'tcx, QueryResponse<'tcx, R>>: ArenaAllocatable, { self.enter_with_canonical( DUMMY_SP, @@ -99,8 +99,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { fulfill_cx: &mut dyn TraitEngine<'tcx>, ) -> Fallible> where - T: Debug + Lift<'tcx> + TypeFoldable<'tcx>, - Canonical<'tcx, as Lift<'tcx>>::Lifted>: ArenaAllocatable, + T: Debug + TypeFoldable<'tcx>, + Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable, { let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?; let canonical_result = self.canonicalize_response(&query_response); @@ -126,9 +126,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { &self, inference_vars: CanonicalVarValues<'tcx>, answer: T, - ) -> Canonical<'tcx, QueryResponse<'tcx, >::Lifted>> + ) -> Canonical<'tcx, QueryResponse<'tcx, T>> where - T: Debug + Lift<'tcx> + TypeFoldable<'tcx>, + T: Debug + TypeFoldable<'tcx>, { self.canonicalize_response(&QueryResponse { var_values: inference_vars, @@ -147,7 +147,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { fulfill_cx: &mut dyn TraitEngine<'tcx>, ) -> Result, NoSolution> where - T: Debug + TypeFoldable<'tcx> + Lift<'tcx>, + T: Debug + TypeFoldable<'tcx>, { let tcx = self.tcx; diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 8e9af8b39385..7b7a9cba76e6 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -469,11 +469,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { definition_ty ); - // We can unwrap here because our reverse mapper always - // produces things with 'tcx lifetime, though the type folder - // obscures that. - let definition_ty = gcx.lift(&definition_ty).unwrap(); - definition_ty } } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3b21b81df7b4..0304f76ec96e 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -819,10 +819,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { .unwrap_or(ty::ClosureKind::LATTICE_BOTTOM), None => - self.tcx.global_tcx() - .lift(&closure_substs) - .expect("no inference cx, but inference variables in closure ty") - .closure_kind(closure_def_id, self.tcx.global_tcx()), + closure_substs.closure_kind(closure_def_id, self.tcx.global_tcx()), } } _ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty), diff --git a/src/librustc/traits/codegen/mod.rs b/src/librustc/traits/codegen/mod.rs index bb4095333f19..97fb430a3e05 100644 --- a/src/librustc/traits/codegen/mod.rs +++ b/src/librustc/traits/codegen/mod.rs @@ -141,9 +141,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, fulfill_cx: &mut FulfillmentContext<'tcx>, result: &T, - ) -> T::Lifted + ) -> T where - T: TypeFoldable<'tcx> + ty::Lift<'tcx>, + T: TypeFoldable<'tcx>, { debug!("drain_fulfillment_cx_or_panic()"); @@ -155,10 +155,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } let result = self.resolve_vars_if_possible(result); - let result = self.tcx.erase_regions(&result); - - self.tcx.lift_to_global(&result).unwrap_or_else(|| - bug!("Uninferred types/regions/consts in `{:?}`", result) - ) + self.tcx.erase_regions(&result) } } diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index d189bb231163..d6d0d12b2ba6 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -409,7 +409,6 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { promoted: None }; if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) { - let substs = tcx.lift_to_global(&substs).unwrap(); let evaluated = evaluated.subst(tcx, substs); return evaluated; } diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index 50476721e824..1b82c412e982 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -203,7 +203,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { promoted: None, }; if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) { - let substs = tcx.lift_to_global(&substs).unwrap(); let evaluated = evaluated.subst(tcx, substs); return evaluated; } diff --git a/src/librustc/traits/query/type_op/mod.rs b/src/librustc/traits/query/type_op/mod.rs index b298edfec594..4a07a3120f3e 100644 --- a/src/librustc/traits/query/type_op/mod.rs +++ b/src/librustc/traits/query/type_op/mod.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use crate::traits::query::Fallible; use crate::traits::ObligationCause; use crate::ty::fold::TypeFoldable; -use crate::ty::{Lift, ParamEnvAnd, TyCtxt}; +use crate::ty::{ParamEnvAnd, TyCtxt}; pub mod ascribe_user_type; pub mod custom; @@ -44,8 +44,8 @@ pub trait TypeOp<'tcx>: Sized + fmt::Debug { /// which produces the resulting query region constraints. /// /// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html -pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + Lift<'tcx> { - type QueryResponse: TypeFoldable<'tcx> + Lift<'tcx>; +pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx { + type QueryResponse: TypeFoldable<'tcx>; /// Give query the option for a simple fast path that never /// actually hits the tcx cache lookup etc. Return `Some(r)` with diff --git a/src/librustc/traits/query/type_op/normalize.rs b/src/librustc/traits/query/type_op/normalize.rs index 5a768d9d58fc..3fe85d8d83eb 100644 --- a/src/librustc/traits/query/type_op/normalize.rs +++ b/src/librustc/traits/query/type_op/normalize.rs @@ -20,7 +20,7 @@ where impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize where - T: Normalizable<'tcx>, + T: Normalizable<'tcx> + 'tcx, { type QueryResponse = T; diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 3d47e94fb007..43bb4edd9b27 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -132,12 +132,7 @@ pub fn find_associated_item<'tcx>( let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs); let substs = translate_substs(&infcx, param_env, impl_data.impl_def_id, substs, node_item.node); - let substs = infcx.tcx.erase_regions(&substs); - tcx.lift(&substs).unwrap_or_else(|| - bug!("find_method: translate_substs \ - returned {:?} which contains inference types/regions", - substs) - ) + infcx.tcx.erase_regions(&substs) }); (node_item.item.def_id, substs) } diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index d5e045003503..b8bdde4a7873 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -192,9 +192,12 @@ impl<'tcx> ty::TyS<'tcx> { ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(), ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(), - ty::Array(_, n) => match n.assert_usize(tcx) { - Some(n) => format!("array of {} elements", n).into(), - None => "array".into(), + ty::Array(_, n) => { + let n = tcx.lift_to_global(&n).unwrap(); + match n.assert_usize(tcx) { + Some(n) => format!("array of {} elements", n).into(), + None => "array".into(), + } } ty::Slice(_) => "slice".into(), ty::RawPtr(_) => "*-ptr".into(), diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 810a26d37364..8bfbd8b854b0 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -2262,7 +2262,6 @@ impl<'tcx> Const<'tcx> { #[inline] pub fn from_bits(tcx: TyCtxt<'tcx>, bits: u128, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> &'tcx Self { - let ty = tcx.lift_to_global(&ty).unwrap(); let size = tcx.layout_of(ty).unwrap_or_else(|e| { panic!("could not compute layout for {:?}: {:?}", ty, e) }).size; @@ -2289,7 +2288,6 @@ impl<'tcx> Const<'tcx> { if self.ty != ty.value { return None; } - let ty = tcx.lift_to_global(&ty).unwrap(); let size = tcx.layout_of(ty).ok()?.size; self.val.try_to_bits(size) } @@ -2300,15 +2298,14 @@ impl<'tcx> Const<'tcx> { } #[inline] - pub fn assert_bits(&self, tcx: TyCtxt<'_>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option { + pub fn assert_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option { assert_eq!(self.ty, ty.value); - let ty = tcx.lift_to_global(&ty).unwrap(); let size = tcx.layout_of(ty).ok()?.size; self.val.try_to_bits(size) } #[inline] - pub fn assert_bool(&self, tcx: TyCtxt<'_>) -> Option { + pub fn assert_bool(&self, tcx: TyCtxt<'tcx>) -> Option { self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.bool)).and_then(|v| match v { 0 => Some(false), 1 => Some(true), @@ -2317,18 +2314,18 @@ impl<'tcx> Const<'tcx> { } #[inline] - pub fn assert_usize(&self, tcx: TyCtxt<'_>) -> Option { + pub fn assert_usize(&self, tcx: TyCtxt<'tcx>) -> Option { self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.usize)).map(|v| v as u64) } #[inline] - pub fn unwrap_bits(&self, tcx: TyCtxt<'_>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 { + pub fn unwrap_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 { self.assert_bits(tcx, ty).unwrap_or_else(|| bug!("expected bits of {}, got {:#?}", ty.value, self)) } #[inline] - pub fn unwrap_usize(&self, tcx: TyCtxt<'_>) -> u64 { + pub fn unwrap_usize(&self, tcx: TyCtxt<'tcx>) -> u64 { self.assert_usize(tcx).unwrap_or_else(|| bug!("expected constant usize, got {:#?}", self)) } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 161a08c5773e..b05e291710a4 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -670,7 +670,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx // "Lift" into the gcx -- once regions are erased, this type should be in the // global arenas; this "lift" operation basically just asserts that is true, but // that is useful later. - let drop_place_ty = gcx.lift(&drop_place_ty).unwrap(); + gcx.lift_to_global(&drop_place_ty).unwrap(); debug!("visit_terminator_drop \ loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}", diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 2b38fcee4796..41ed564d0f0e 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -863,8 +863,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { }); debug!("try_promote_type_test_subject: folded ty = {:?}", ty); - // `lift` will only fail if we failed to promote some region. - let ty = gcx.lift(&ty)?; + // `lift_to_global` will only fail if we failed to promote some region. + gcx.lift_to_global(&ty)?; Some(ClosureOutlivesSubject::Ty(ty)) } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 77e0b54781c9..9d33b371d9b5 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1866,7 +1866,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // `Sized` bound in no way depends on precise regions, so this // shouldn't affect `is_sized`. let gcx = tcx.global_tcx(); - let erased_ty = gcx.lift(&tcx.erase_regions(&ty)).unwrap(); + let erased_ty = tcx.erase_regions(&ty); if !erased_ty.is_sized(gcx.at(span), self.param_env) { // in current MIR construction, all non-control-flow rvalue // expressions evaluate through `as_temp` or `into` a return @@ -2652,7 +2652,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn normalize(&mut self, value: T, location: impl NormalizeLocation) -> T where - T: type_op::normalize::Normalizable<'tcx> + Copy, + T: type_op::normalize::Normalizable<'tcx> + Copy + 'tcx, { debug!("normalize(value={:?}, location={:?})", value, location); let param_env = self.param_env; diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 6d6e5de4761a..243c13c2982d 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -569,7 +569,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Helper to get a `-1` value of the appropriate type fn neg_1_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> { - let param_ty = ty::ParamEnv::empty().and(self.hir.tcx().lift_to_global(&ty).unwrap()); + let param_ty = ty::ParamEnv::empty().and(ty); let bits = self.hir.tcx().layout_of(param_ty).unwrap().size.bits(); let n = (!0u128) >> (128 - bits); let literal = ty::Const::from_bits(self.hir.tcx(), n, param_ty); @@ -580,7 +580,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Helper to get the minimum value of the appropriate type fn minval_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> { assert!(ty.is_signed()); - let param_ty = ty::ParamEnv::empty().and(self.hir.tcx().lift_to_global(&ty).unwrap()); + let param_ty = ty::ParamEnv::empty().and(ty); let bits = self.hir.tcx().layout_of(param_ty).unwrap().size.bits(); let n = 1 << (bits - 1); let literal = ty::Const::from_bits(self.hir.tcx(), n, param_ty); diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index e8a32477f1c3..37f2a9157824 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -151,7 +151,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>( debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty); let gcx = tcx.global_tcx(); - let erased_ty = gcx.lift(&tcx.erase_regions(&ty)).unwrap(); + let erased_ty = tcx.erase_regions(&ty); if erased_ty.needs_drop(gcx, ctxt.param_env) { each_child(child); } else { diff --git a/src/librustc_mir/hair/constant.rs b/src/librustc_mir/hair/constant.rs index 2cd04631118d..bc01e3ee95b9 100644 --- a/src/librustc_mir/hair/constant.rs +++ b/src/librustc_mir/hair/constant.rs @@ -18,7 +18,7 @@ crate fn lit_to_const<'tcx>( use syntax::ast::*; let trunc = |n| { - let param_ty = ParamEnv::reveal_all().and(tcx.lift_to_global(&ty).unwrap()); + let param_ty = ParamEnv::reveal_all().and(ty); let width = tcx.layout_of(param_ty).map_err(|_| LitToConstError::Reported)?.size; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = truncate(n, width); diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index 7740042c783f..1eb5ab0776a3 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -191,12 +191,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { } pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool { - let (ty, param_env) = self.tcx.lift_to_global(&(ty, self.param_env)).unwrap_or_else(|| { - bug!("MIR: Cx::needs_drop({:?}, {:?}) got \ - type with inference types/regions", - ty, self.param_env); - }); - ty.needs_drop(self.tcx.global_tcx(), param_env) + ty.needs_drop(self.tcx.global_tcx(), self.param_env) } pub fn tcx(&self) -> TyCtxt<'tcx> { diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 1d7c450f6950..9349e08b7d04 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -1311,7 +1311,7 @@ fn is_useful_specialized<'p, 'a: 'p, 'tcx: 'a>( /// Returns `None` in case of a catch-all, which can't be specialized. fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>, pat: &Pattern<'tcx>, - pcx: PatternContext<'_>) + pcx: PatternContext<'tcx>) -> Option>> { match *pat.kind { diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index bfa1a80bb320..d138ce753b07 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -37,8 +37,7 @@ fn normalize_ty_after_erasing_regions<'tcx>( ); let normalized_value = infcx.resolve_vars_if_possible(&normalized_value); - let normalized_value = infcx.tcx.erase_regions(&normalized_value); - tcx.lift_to_global(&normalized_value).unwrap() + infcx.tcx.erase_regions(&normalized_value) } Err(NoSolution) => bug!("could not fully normalize `{:?}`", value), } From 56e30e1f3f953f3b8b88f46e32a2ec1f5573943c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 11 Jun 2019 13:28:22 -0700 Subject: [PATCH 024/109] Tweak transparent enums and unions diagnostic spans --- src/librustc_typeck/check/mod.rs | 68 +++++++++----- .../feature-gate-transparent_enums.stderr | 6 +- .../feature-gate-transparent_unions.stderr | 7 +- src/test/ui/repr/repr-transparent.stderr | 94 +++++++------------ 4 files changed, 83 insertions(+), 92 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c857eac5d3c1..5b51c02b812e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1794,25 +1794,39 @@ fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, def_id: DefId) { if !adt.repr.transparent() { return; } + let sp = tcx.sess.source_map().def_span(sp); if adt.is_enum() { if !tcx.features().transparent_enums { - emit_feature_err(&tcx.sess.parse_sess, - sym::transparent_enums, - sp, - GateIssue::Language, - "transparent enums are unstable"); + emit_feature_err( + &tcx.sess.parse_sess, + sym::transparent_enums, + sp, + GateIssue::Language, + "transparent enums are unstable", + ); } if adt.variants.len() != 1 { let variant_spans: Vec<_> = adt.variants.iter().map(|variant| { tcx.hir().span_if_local(variant.def_id).unwrap() }).collect(); - let mut err = struct_span_err!(tcx.sess, sp, E0731, - "transparent enum needs exactly one variant, but has {}", - adt.variants.len()); - if !variant_spans.is_empty() { - err.span_note(variant_spans, &format!("the following variants exist on `{}`", - tcx.def_path_str(def_id))); + let msg = format!( + "needs exactly one variant, but has {}", + adt.variants.len(), + ); + let mut err = struct_span_err!(tcx.sess, sp, E0731, "transparent enum {}", msg); + err.span_label(sp, &msg); + match &variant_spans[..] { + &[] => {}, + &[ref start.., ref end] => { + for variant_span in start { + err.span_label(*variant_span, ""); + } + err.span_label(*end, &format!( + "too many variants in `{}`", + tcx.def_path_str(def_id), + )); + }, } err.emit(); if adt.variants.is_empty() { @@ -1847,23 +1861,31 @@ fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, def_id: DefId) { if non_zst_count != 1 { let field_spans: Vec<_> = non_zst_fields.map(|(span, _zst, _align1)| span).collect(); - let mut err = struct_span_err!(tcx.sess, sp, E0690, - "{}transparent {} needs exactly one non-zero-sized field, but has {}", - if adt.is_enum() { "the variant of a " } else { "" }, - adt.descr(), - non_zst_count); - if !field_spans.is_empty() { - err.span_note(field_spans, - &format!("the following non-zero-sized fields exist on `{}`:", - tcx.def_path_str(def_id))); + let msg = format!("needs exactly one non-zero-sized field, but has {}", non_zst_count); + let mut err = struct_span_err!( + tcx.sess, + sp, + E0690, + "{}transparent {} {}", + if adt.is_enum() { "the variant of a " } else { "" }, + adt.descr(), + msg, + ); + err.span_label(sp, &msg); + for sp in &field_spans { + err.span_label(*sp, "this field is non-zero-sized"); } err.emit(); } for (span, zst, align1) in field_infos { if zst && !align1 { - span_err!(tcx.sess, span, E0691, - "zero-sized field in transparent {} has alignment larger than 1", - adt.descr()); + struct_span_err!( + tcx.sess, + span, + E0691, + "zero-sized field in transparent {} has alignment larger than 1", + adt.descr(), + ).span_label(span, "has alignment larger than 1").emit(); } } } diff --git a/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr b/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr index 4b22654e9e41..8ba079b89f50 100644 --- a/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr +++ b/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr @@ -1,10 +1,8 @@ error[E0658]: transparent enums are unstable --> $DIR/feature-gate-transparent_enums.rs:2:1 | -LL | / enum OkButUnstableEnum { -LL | | Foo((), String, ()), -LL | | } - | |_^ +LL | enum OkButUnstableEnum { + | ^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/60405 = help: add #![feature(transparent_enums)] to the crate attributes to enable diff --git a/src/test/ui/feature-gates/feature-gate-transparent_unions.stderr b/src/test/ui/feature-gates/feature-gate-transparent_unions.stderr index 933b227de63b..341324c3d676 100644 --- a/src/test/ui/feature-gates/feature-gate-transparent_unions.stderr +++ b/src/test/ui/feature-gates/feature-gate-transparent_unions.stderr @@ -1,11 +1,8 @@ error[E0658]: transparent unions are unstable --> $DIR/feature-gate-transparent_unions.rs:2:1 | -LL | / union OkButUnstableUnion { -LL | | field: u8, -LL | | zst: (), -LL | | } - | |_^ +LL | union OkButUnstableUnion { + | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/60405 = help: add #![feature(transparent_unions)] to the crate attributes to enable diff --git a/src/test/ui/repr/repr-transparent.stderr b/src/test/ui/repr/repr-transparent.stderr index ea16bdf53783..f0c1fbe8ac9e 100644 --- a/src/test/ui/repr/repr-transparent.stderr +++ b/src/test/ui/repr/repr-transparent.stderr @@ -2,61 +2,57 @@ error[E0690]: transparent struct needs exactly one non-zero-sized field, but has --> $DIR/repr-transparent.rs:11:1 | LL | struct NoFields; - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 --> $DIR/repr-transparent.rs:14:1 | LL | struct ContainsOnlyZst(()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 --> $DIR/repr-transparent.rs:17:1 | LL | struct ContainsOnlyZstArray([bool; 0]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0 --> $DIR/repr-transparent.rs:20:1 | LL | struct ContainsMultipleZst(PhantomData<*const i32>, NoFields); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 2 --> $DIR/repr-transparent.rs:24:1 | LL | struct MultipleNonZst(u8, u8); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the following non-zero-sized fields exist on `MultipleNonZst`: - --> $DIR/repr-transparent.rs:24:23 - | -LL | struct MultipleNonZst(u8, u8); - | ^^ ^^ + | ^^^^^^^^^^^^^^^^^^^^^^--^^--^^ + | | | | + | | | this field is non-zero-sized + | | this field is non-zero-sized + | needs exactly one non-zero-sized field, but has 2 error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 2 --> $DIR/repr-transparent.rs:30:1 | LL | pub struct StructWithProjection(f32, ::It); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the following non-zero-sized fields exist on `StructWithProjection`: - --> $DIR/repr-transparent.rs:30:33 - | -LL | pub struct StructWithProjection(f32, ::It); - | ^^^ ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^-------------------^^ + | | | | + | | | this field is non-zero-sized + | | this field is non-zero-sized + | needs exactly one non-zero-sized field, but has 2 error[E0691]: zero-sized field in transparent struct has alignment larger than 1 --> $DIR/repr-transparent.rs:34:32 | LL | struct NontrivialAlignZst(u32, [u16; 0]); - | ^^^^^^^^ + | ^^^^^^^^ has alignment larger than 1 error[E0691]: zero-sized field in transparent struct has alignment larger than 1 --> $DIR/repr-transparent.rs:40:24 | LL | struct GenericAlign(ZstAlign32, u32); - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ has alignment larger than 1 error[E0084]: unsupported representation for zero-variant enum --> $DIR/repr-transparent.rs:42:1 @@ -70,71 +66,49 @@ error[E0731]: transparent enum needs exactly one variant, but has 0 --> $DIR/repr-transparent.rs:43:1 | LL | enum Void {} - | ^^^^^^^^^^^^ + | ^^^^^^^^^ needs exactly one variant, but has 0 error[E0690]: the variant of a transparent enum needs exactly one non-zero-sized field, but has 0 --> $DIR/repr-transparent.rs:47:1 | -LL | / enum FieldlessEnum { -LL | | Foo, -LL | | } - | |_^ +LL | enum FieldlessEnum { + | ^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 error[E0690]: the variant of a transparent enum needs exactly one non-zero-sized field, but has 2 --> $DIR/repr-transparent.rs:52:1 | -LL | / enum TooManyFieldsEnum { -LL | | Foo(u32, String), -LL | | } - | |_^ - | -note: the following non-zero-sized fields exist on `TooManyFieldsEnum`: - --> $DIR/repr-transparent.rs:53:9 - | +LL | enum TooManyFieldsEnum { + | ^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 2 LL | Foo(u32, String), - | ^^^ ^^^^^^ + | --- ------ this field is non-zero-sized + | | + | this field is non-zero-sized error[E0731]: transparent enum needs exactly one variant, but has 2 --> $DIR/repr-transparent.rs:58:1 | -LL | / enum TooManyVariants { -LL | | Foo(String), -LL | | Bar, -LL | | } - | |_^ - | -note: the following variants exist on `TooManyVariants` - --> $DIR/repr-transparent.rs:59:5 - | +LL | enum TooManyVariants { + | ^^^^^^^^^^^^^^^^^^^^ needs exactly one variant, but has 2 LL | Foo(String), - | ^^^^^^^^^^^ + | ----------- LL | Bar, - | ^^^ + | --- too many variants in `TooManyVariants` error[E0690]: transparent union needs exactly one non-zero-sized field, but has 0 --> $DIR/repr-transparent.rs:64:1 | -LL | / union UnitUnion { -LL | | u: (), -LL | | } - | |_^ +LL | union UnitUnion { + | ^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0 error[E0690]: transparent union needs exactly one non-zero-sized field, but has 2 --> $DIR/repr-transparent.rs:69:1 | -LL | / union TooManyFields { -LL | | u: u32, -LL | | s: i32 -LL | | } - | |_^ - | -note: the following non-zero-sized fields exist on `TooManyFields`: - --> $DIR/repr-transparent.rs:70:5 - | +LL | union TooManyFields { + | ^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 2 LL | u: u32, - | ^^^^^^ + | ------ this field is non-zero-sized LL | s: i32 - | ^^^^^^ + | ------ this field is non-zero-sized error: aborting due to 15 previous errors From f06b76122cde7ddd4f6778d77952b63baa70bdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 11 Jun 2019 18:21:53 -0700 Subject: [PATCH 025/109] review comments: move diagnostic code out of happy path --- src/librustc_typeck/check/mod.rs | 93 ++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 5b51c02b812e..2cb955c7c2ef 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1789,6 +1789,52 @@ fn check_packed_inner<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, stack: &mut Vec(tcx: TyCtxt<'tcx>, adt: &'tcx ty::AdtDef, sp: Span, did: DefId) { + let variant_spans: Vec<_> = adt.variants.iter().map(|variant| { + tcx.hir().span_if_local(variant.def_id).unwrap() + }).collect(); + let msg = format!( + "needs exactly one variant, but has {}", + adt.variants.len(), + ); + let mut err = struct_span_err!(tcx.sess, sp, E0731, "transparent enum {}", msg); + err.span_label(sp, &msg); + if let &[ref start.., ref end] = &variant_spans[..] { + for variant_span in start { + err.span_label(*variant_span, ""); + } + err.span_label(*end, &format!("too many variants in `{}`", tcx.def_path_str(did))); + } + err.emit(); +} + +/// Emit an error when encountering more or less than one non-zero-sized field in a transparent +/// enum. +fn bad_non_zero_sized_fields<'tcx>( + tcx: TyCtxt<'tcx>, + adt: &'tcx ty::AdtDef, + field_count: usize, + field_spans: impl Iterator, + sp: Span, +) { + let msg = format!("needs exactly one non-zero-sized field, but has {}", field_count); + let mut err = struct_span_err!( + tcx.sess, + sp, + E0690, + "{}transparent {} {}", + if adt.is_enum() { "the variant of a " } else { "" }, + adt.descr(), + msg, + ); + err.span_label(sp, &msg); + for sp in field_spans { + err.span_label(sp, "this field is non-zero-sized"); + } + err.emit(); +} + fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, def_id: DefId) { let adt = tcx.adt_def(def_id); if !adt.repr.transparent() { @@ -1807,28 +1853,7 @@ fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, def_id: DefId) { ); } if adt.variants.len() != 1 { - let variant_spans: Vec<_> = adt.variants.iter().map(|variant| { - tcx.hir().span_if_local(variant.def_id).unwrap() - }).collect(); - let msg = format!( - "needs exactly one variant, but has {}", - adt.variants.len(), - ); - let mut err = struct_span_err!(tcx.sess, sp, E0731, "transparent enum {}", msg); - err.span_label(sp, &msg); - match &variant_spans[..] { - &[] => {}, - &[ref start.., ref end] => { - for variant_span in start { - err.span_label(*variant_span, ""); - } - err.span_label(*end, &format!( - "too many variants in `{}`", - tcx.def_path_str(def_id), - )); - }, - } - err.emit(); + bad_variant_count(tcx, adt, sp, def_id); if adt.variants.is_empty() { // Don't bother checking the fields. No variants (and thus no fields) exist. return; @@ -1856,26 +1881,14 @@ fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, def_id: DefId) { (span, zst, align1) }); - let non_zst_fields = field_infos.clone().filter(|(_span, zst, _align1)| !*zst); + let non_zst_fields = field_infos.clone().filter_map(|(span, zst, _align1)| if !zst { + Some(span) + } else { + None + }); let non_zst_count = non_zst_fields.clone().count(); if non_zst_count != 1 { - let field_spans: Vec<_> = non_zst_fields.map(|(span, _zst, _align1)| span).collect(); - - let msg = format!("needs exactly one non-zero-sized field, but has {}", non_zst_count); - let mut err = struct_span_err!( - tcx.sess, - sp, - E0690, - "{}transparent {} {}", - if adt.is_enum() { "the variant of a " } else { "" }, - adt.descr(), - msg, - ); - err.span_label(sp, &msg); - for sp in &field_spans { - err.span_label(*sp, "this field is non-zero-sized"); - } - err.emit(); + bad_non_zero_sized_fields(tcx, adt, non_zst_count, non_zst_fields, sp); } for (span, zst, align1) in field_infos { if zst && !align1 { From d6e410b3205b6734dbd8640c14841a41782e1d42 Mon Sep 17 00:00:00 2001 From: Pyry Kontio Date: Fri, 14 Jun 2019 17:17:28 +0900 Subject: [PATCH 026/109] Fix rust-lldb wrapper scripts. --- .azure-pipelines/steps/run.yml | 2 +- .travis.yml | 2 +- src/etc/rust-lldb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.azure-pipelines/steps/run.yml b/.azure-pipelines/steps/run.yml index 3f98aa495296..553ec88a6e18 100644 --- a/.azure-pipelines/steps/run.yml +++ b/.azure-pipelines/steps/run.yml @@ -37,7 +37,7 @@ steps: set -e brew update brew install xz - brew install swig + brew install swig@3 displayName: Install build dependencies (OSX) condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'), eq(variables['SCRIPT'],'./x.py dist')) diff --git a/.travis.yml b/.travis.yml index 49a8d5b66c35..549893d7fcc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -263,7 +263,7 @@ install: if [[ "$SCRIPT" == "./x.py dist" ]]; then travis_retry brew update && travis_retry brew install xz && - travis_retry brew install swig; + travis_retry brew install swig@3; fi && travis_retry curl -fo /usr/local/bin/sccache https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2018-04-02-sccache-x86_64-apple-darwin && chmod +x /usr/local/bin/sccache && diff --git a/src/etc/rust-lldb b/src/etc/rust-lldb index 424302d495f3..0eb99423df57 100755 --- a/src/etc/rust-lldb +++ b/src/etc/rust-lldb @@ -31,7 +31,7 @@ category_definition="type summary add --no-value --python-function lldb_rust_for category_enable="type category enable Rust" # Call LLDB with the commands added to the argument list -exec "$lldb" --one-line-before-file="$script_import" \ - --one-line-before-file="$category_definition" \ - --one-line-before-file="$category_enable" \ +exec "$lldb" --one-line-before-file "$script_import" \ + --one-line-before-file "$category_definition" \ + --one-line-before-file "$category_enable" \ "$@" From 9d99ae520b74a0ae734851b03bf658b766b4b408 Mon Sep 17 00:00:00 2001 From: Pyry Kontio Date: Sat, 15 Jun 2019 20:00:55 +0900 Subject: [PATCH 027/109] swig@3 is keg-only and not linked by default so add linking so that the build scripts can find it --- .azure-pipelines/steps/run.yml | 1 + .travis.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.azure-pipelines/steps/run.yml b/.azure-pipelines/steps/run.yml index 553ec88a6e18..271f9d382ff6 100644 --- a/.azure-pipelines/steps/run.yml +++ b/.azure-pipelines/steps/run.yml @@ -38,6 +38,7 @@ steps: brew update brew install xz brew install swig@3 + brew link --force swig@3 displayName: Install build dependencies (OSX) condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'), eq(variables['SCRIPT'],'./x.py dist')) diff --git a/.travis.yml b/.travis.yml index 549893d7fcc1..20e092e3f91c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -264,6 +264,7 @@ install: travis_retry brew update && travis_retry brew install xz && travis_retry brew install swig@3; + brew link --force swig@3 fi && travis_retry curl -fo /usr/local/bin/sccache https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2018-04-02-sccache-x86_64-apple-darwin && chmod +x /usr/local/bin/sccache && From 2d6e1df51c7a8ebbe642e2c763249f73eb8f4df6 Mon Sep 17 00:00:00 2001 From: Pyry Kontio Date: Sat, 15 Jun 2019 20:17:42 +0900 Subject: [PATCH 028/109] fix syntax --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20e092e3f91c..3d185b4f0c9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -263,8 +263,8 @@ install: if [[ "$SCRIPT" == "./x.py dist" ]]; then travis_retry brew update && travis_retry brew install xz && - travis_retry brew install swig@3; - brew link --force swig@3 + travis_retry brew install swig@3 && + brew link --force swig@3; fi && travis_retry curl -fo /usr/local/bin/sccache https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2018-04-02-sccache-x86_64-apple-darwin && chmod +x /usr/local/bin/sccache && From af0e35e6a6837aba121c873e6f91fff6df61d268 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 15 Jun 2019 20:54:04 -0700 Subject: [PATCH 029/109] Help LLVM better optimize slice::Iter(Mut)::len --- src/libcore/intrinsics.rs | 6 ++++++ src/libcore/slice/mod.rs | 21 +++++++++++++++++---- src/test/codegen/slice-iter-len-eq-zero.rs | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/test/codegen/slice-iter-len-eq-zero.rs diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 8d9a51742fd9..b30eff8baa9c 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1607,3 +1607,9 @@ pub fn maxnumf64(x: f64, y: f64) -> f64 { // Identical to the `f32` case. (if x < y || x != x { y } else { x }) * 1.0 } + +/// For bootstrapping, implement unchecked_sub as just wrapping_sub. +#[cfg(bootstrap)] +pub unsafe fn unchecked_sub(x: T, y: T) -> T { + sub_with_overflow(x, y).0 +} diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index d93e5a9ca2b6..b2376cdf9fa7 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -25,7 +25,7 @@ use crate::cmp::Ordering::{self, Less, Equal, Greater}; use crate::cmp; use crate::fmt; -use crate::intrinsics::assume; +use crate::intrinsics::{assume, exact_div, unchecked_sub}; use crate::isize; use crate::iter::*; use crate::ops::{FnMut, Try, self}; @@ -2998,14 +2998,27 @@ macro_rules! is_empty { // unexpected way. (Tested by `codegen/slice-position-bounds-check`.) macro_rules! len { ($self: ident) => {{ + #![allow(unused_unsafe)] // we're sometimes used within an unsafe block + let start = $self.ptr; - let diff = ($self.end as usize).wrapping_sub(start as usize); let size = size_from_ptr(start); if size == 0 { + // This _cannot_ use `unchecked_sub` because we depend on wrapping + // to represent the length of long ZST slice iterators. + let diff = ($self.end as usize).wrapping_sub(start as usize); diff } else { - // Using division instead of `offset_from` helps LLVM remove bounds checks - diff / size + // We know that `start <= end`, so can do better than `offset_from`, + // which needs to deal in signed. By setting appropriate flags here + // we can tell LLVM this, which helps it remove bounds checks. + // SAFETY: By the type invariant, `start <= end` + let diff = unsafe { unchecked_sub($self.end as usize, start as usize) }; + // By also telling LLVM that the pointers are apart by an exact + // multiple of the type size, it can optimize `len() == 0` down to + // `start == end` instead of `(end - start) < size`. + // SAFETY: By the type invariant, the pointers are aligned so the + // distance between them must be a multiple of pointee size + unsafe { exact_div(diff, size) } } }} } diff --git a/src/test/codegen/slice-iter-len-eq-zero.rs b/src/test/codegen/slice-iter-len-eq-zero.rs new file mode 100644 index 000000000000..a5516833900a --- /dev/null +++ b/src/test/codegen/slice-iter-len-eq-zero.rs @@ -0,0 +1,14 @@ +// no-system-llvm +// compile-flags: -O +#![crate_type = "lib"] + +type Demo = [u8; 3]; + +// CHECK-LABEL: @slice_iter_len_eq_zero +#[no_mangle] +pub fn slice_iter_len_eq_zero(y: std::slice::Iter<'_, Demo>) -> bool { + // CHECK-NOT: sub + // CHECK: %2 = icmp eq i8* %1, %0 + // CHECK: ret i1 %2 + y.len() == 0 +} From 387ac060d2044be63786571fcf7831879d2a2bfb Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Sun, 16 Jun 2019 13:57:07 +0200 Subject: [PATCH 030/109] make `Weak::ptr_eq`s into methods --- src/liballoc/rc.rs | 14 +++++++------- src/liballoc/sync.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 7cbb49633017..ee78839f7f00 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1515,18 +1515,18 @@ impl Weak { /// /// ``` /// #![feature(weak_ptr_eq)] - /// use std::rc::{Rc, Weak}; + /// use std::rc::Rc; /// /// let first_rc = Rc::new(5); /// let first = Rc::downgrade(&first_rc); /// let second = Rc::downgrade(&first_rc); /// - /// assert!(Weak::ptr_eq(&first, &second)); + /// assert!(first.ptr_eq(&second)); /// /// let third_rc = Rc::new(5); /// let third = Rc::downgrade(&third_rc); /// - /// assert!(!Weak::ptr_eq(&first, &third)); + /// assert!(!first.ptr_eq(&third)); /// ``` /// /// Comparing `Weak::new`. @@ -1537,16 +1537,16 @@ impl Weak { /// /// let first = Weak::new(); /// let second = Weak::new(); - /// assert!(Weak::ptr_eq(&first, &second)); + /// assert!(first.ptr_eq(&second)); /// /// let third_rc = Rc::new(()); /// let third = Rc::downgrade(&third_rc); - /// assert!(!Weak::ptr_eq(&first, &third)); + /// assert!(!first.ptr_eq(&third)); /// ``` #[inline] #[unstable(feature = "weak_ptr_eq", issue = "55981")] - pub fn ptr_eq(this: &Self, other: &Self) -> bool { - this.ptr.as_ptr() == other.ptr.as_ptr() + pub fn ptr_eq(&self, other: &Self) -> bool { + self.ptr.as_ptr() == other.ptr.as_ptr() } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 2503f696bf32..6c23b3179ed6 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1349,18 +1349,18 @@ impl Weak { /// /// ``` /// #![feature(weak_ptr_eq)] - /// use std::sync::{Arc, Weak}; + /// use std::sync::Arc; /// /// let first_rc = Arc::new(5); /// let first = Arc::downgrade(&first_rc); /// let second = Arc::downgrade(&first_rc); /// - /// assert!(Weak::ptr_eq(&first, &second)); + /// assert!(first.ptr_eq(&second)); /// /// let third_rc = Arc::new(5); /// let third = Arc::downgrade(&third_rc); /// - /// assert!(!Weak::ptr_eq(&first, &third)); + /// assert!(!first.ptr_eq(&third)); /// ``` /// /// Comparing `Weak::new`. @@ -1371,16 +1371,16 @@ impl Weak { /// /// let first = Weak::new(); /// let second = Weak::new(); - /// assert!(Weak::ptr_eq(&first, &second)); + /// assert!(first.ptr_eq(&second)); /// /// let third_rc = Arc::new(()); /// let third = Arc::downgrade(&third_rc); - /// assert!(!Weak::ptr_eq(&first, &third)); + /// assert!(!first.ptr_eq(&third)); /// ``` #[inline] #[unstable(feature = "weak_ptr_eq", issue = "55981")] - pub fn ptr_eq(this: &Self, other: &Self) -> bool { - this.ptr.as_ptr() == other.ptr.as_ptr() + pub fn ptr_eq(&self, other: &Self) -> bool { + self.ptr.as_ptr() == other.ptr.as_ptr() } } From 7d69d4ced23c446d6af341e3f9dc031a302150fc Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 17 Jun 2019 10:52:37 +0000 Subject: [PATCH 031/109] Make use of `ptr::null(_mut)` instead of casting zero --- src/bootstrap/job.rs | 9 +++++---- src/bootstrap/util.rs | 2 +- src/libarena/lib.rs | 8 ++++---- src/libpanic_unwind/dummy.rs | 2 +- src/libpanic_unwind/seh.rs | 6 +++--- src/librustc_errors/lock.rs | 2 +- src/librustc_metadata/dynamic_lib.rs | 2 +- src/librustc_typeck/error_codes.rs | 6 +++--- src/libstd/sys/wasi/args.rs | 2 +- src/libstd/sys/wasm/thread_local_atomics.rs | 2 +- .../run-make-fulldeps/alloc-extern-crates/fakealloc.rs | 6 ++++-- src/test/run-pass/cast.rs | 2 +- src/test/run-pass/cleanup-shortcircuit.rs | 2 +- src/test/run-pass/consts/const-block.rs | 4 ++-- .../run-pass/issues/issue-13259-windows-tcb-trash.rs | 4 ++-- src/test/run-pass/issues/issue-19001.rs | 2 +- src/test/run-pass/issues/issue-39367.rs | 2 +- src/test/run-pass/issues/issue-46069.rs | 2 +- src/test/run-pass/structs-enums/enum-null-pointer-opt.rs | 2 +- src/test/ui/casts-issue-46365.rs | 2 +- src/test/ui/consts/const-eval/ice-generic-assoc-const.rs | 2 +- src/test/ui/consts/min_const_fn/min_const_fn.rs | 4 ++-- src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs | 4 ++-- src/test/ui/derived-errors/issue-31997.rs | 2 +- src/test/ui/derived-errors/issue-31997.stderr | 2 +- src/test/ui/error-codes/E0605.rs | 2 +- src/test/ui/error-codes/E0607.rs | 2 +- src/test/ui/error-festival.rs | 2 +- src/test/ui/issues/issue-17458.rs | 2 +- src/test/ui/issues/issue-17458.stderr | 4 ++-- src/test/ui/issues/issue-20801.rs | 4 ++-- src/test/ui/issues/issue-22034.rs | 2 +- src/test/ui/mismatched_types/cast-rfc0401.rs | 6 +++--- 33 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index df492e0fdfd1..6867d62a480b 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -32,6 +32,7 @@ use std::env; use std::io; use std::mem; +use std::ptr; use crate::Build; type HANDLE = *mut u8; @@ -118,8 +119,8 @@ pub unsafe fn setup(build: &mut Build) { SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX); // Create a new job object for us to use - let job = CreateJobObjectW(0 as *mut _, 0 as *const _); - assert!(job != 0 as *mut _, "{}", io::Error::last_os_error()); + let job = CreateJobObjectW(ptr::null_mut(), ptr::null()); + assert!(!job.is_null(), "{}", io::Error::last_os_error()); // Indicate that when all handles to the job object are gone that all // process in the object should be killed. Note that this includes our @@ -166,8 +167,8 @@ pub unsafe fn setup(build: &mut Build) { }; let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap()); - assert!(parent != 0 as *mut _, "{}", io::Error::last_os_error()); - let mut parent_handle = 0 as *mut _; + assert!(!parent.is_null(), "{}", io::Error::last_os_error()); + let mut parent_handle = ptr::null_mut(); let r = DuplicateHandle(GetCurrentProcess(), job, parent, &mut parent_handle, 0, FALSE, DUPLICATE_SAME_ACCESS); diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index 9f684678bb06..47f5edd15631 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -209,7 +209,7 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { let h = CreateFileW(path.as_ptr(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - 0 as *mut _, + ptr::null_mut(), OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, ptr::null_mut()); diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index e2a249c8e61c..3d16e335cd8f 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -114,8 +114,8 @@ impl Default for TypedArena { TypedArena { // We set both `ptr` and `end` to 0 so that the first call to // alloc() will trigger a grow(). - ptr: Cell::new(0 as *mut T), - end: Cell::new(0 as *mut T), + ptr: Cell::new(ptr::null_mut()), + end: Cell::new(ptr::null_mut()), chunks: RefCell::new(vec![]), _own: PhantomData, } @@ -370,8 +370,8 @@ impl Default for DroplessArena { #[inline] fn default() -> DroplessArena { DroplessArena { - ptr: Cell::new(0 as *mut u8), - end: Cell::new(0 as *mut u8), + ptr: Cell::new(ptr::null_mut()), + end: Cell::new(ptr::null_mut()), chunks: Default::default(), } } diff --git a/src/libpanic_unwind/dummy.rs b/src/libpanic_unwind/dummy.rs index 3a00d6376658..867563263871 100644 --- a/src/libpanic_unwind/dummy.rs +++ b/src/libpanic_unwind/dummy.rs @@ -7,7 +7,7 @@ use core::any::Any; use core::intrinsics; pub fn payload() -> *mut u8 { - 0 as *mut u8 + core::ptr::null_mut() } pub unsafe fn cleanup(_ptr: *mut u8) -> Box { diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs index 996fdb931eff..809e4619812d 100644 --- a/src/libpanic_unwind/seh.rs +++ b/src/libpanic_unwind/seh.rs @@ -104,7 +104,7 @@ mod imp { pub const NAME2: [u8; 7] = [b'.', b'P', b'A', b'X', 0, 0, 0]; macro_rules! ptr { - (0) => (0 as *mut u8); + (0) => (core::ptr::null_mut()); ($e:expr) => ($e as *mut u8); } } @@ -223,13 +223,13 @@ extern "C" { #[cfg_attr(not(test), lang = "msvc_try_filter")] static mut TYPE_DESCRIPTOR1: _TypeDescriptor = _TypeDescriptor { pVFTable: unsafe { &TYPE_INFO_VTABLE } as *const _ as *const _, - spare: 0 as *mut _, + spare: core::ptr::null_mut(), name: imp::NAME1, }; static mut TYPE_DESCRIPTOR2: _TypeDescriptor = _TypeDescriptor { pVFTable: unsafe { &TYPE_INFO_VTABLE } as *const _ as *const _, - spare: 0 as *mut _, + spare: core::ptr::null_mut(), name: imp::NAME2, }; diff --git a/src/librustc_errors/lock.rs b/src/librustc_errors/lock.rs index f731791efe6e..25a27d2cbd88 100644 --- a/src/librustc_errors/lock.rs +++ b/src/librustc_errors/lock.rs @@ -64,7 +64,7 @@ pub fn acquire_global_lock(name: &str) -> Box { // // This will silently create one if it doesn't already exist, or it'll // open up a handle to one if it already exists. - let mutex = CreateMutexA(0 as *mut _, 0, cname.as_ptr() as *const u8); + let mutex = CreateMutexA(std::ptr::null_mut(), 0, cname.as_ptr() as *const u8); if mutex.is_null() { panic!("failed to create global mutex named `{}`: {}", name, diff --git a/src/librustc_metadata/dynamic_lib.rs b/src/librustc_metadata/dynamic_lib.rs index 76a9a3405bd8..4c279361ff5e 100644 --- a/src/librustc_metadata/dynamic_lib.rs +++ b/src/librustc_metadata/dynamic_lib.rs @@ -115,7 +115,7 @@ mod dl { { use std::sync::{Mutex, Once}; static INIT: Once = Once::new(); - static mut LOCK: *mut Mutex<()> = 0 as *mut _; + static mut LOCK: *mut Mutex<()> = ptr::null_mut(); unsafe { INIT.call_once(|| { LOCK = Box::into_raw(Box::new(Mutex::new(()))); diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index 0b618cdf1dbb..b5b214d4aff6 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -3904,7 +3904,7 @@ x as Vec; // error: non-primitive cast: `u8` as `std::vec::Vec` // Another example -let v = 0 as *const u8; // So here, `v` is a `*const u8`. +let v = core::ptr::null::(); // So here, `v` is a `*const u8`. v as &u8; // error: non-primitive cast: `*const u8` as `&u8` ``` @@ -3914,7 +3914,7 @@ Only primitive types can be cast into each other. Examples: let x = 0u8; x as u32; // ok! -let v = 0 as *const u8; +let v = core::ptr::null::(); v as *const i8; // ok! ``` @@ -3954,7 +3954,7 @@ A cast between a thin and a fat pointer was attempted. Erroneous code example: ```compile_fail,E0607 -let v = 0 as *const u8; +let v = core::ptr::null::(); v as *const [u8]; ``` diff --git a/src/libstd/sys/wasi/args.rs b/src/libstd/sys/wasi/args.rs index 9c8e59e4fb5e..8b4b354d9fc2 100644 --- a/src/libstd/sys/wasi/args.rs +++ b/src/libstd/sys/wasi/args.rs @@ -32,7 +32,7 @@ fn maybe_args() -> io::Result { let (mut argc, mut argv_buf_size) = (0, 0); cvt_wasi(libc::__wasi_args_sizes_get(&mut argc, &mut argv_buf_size))?; - let mut argc = vec![0 as *mut libc::c_char; argc]; + let mut argc = vec![core::ptr::null_mut::(); argc]; let mut argv_buf = vec![0; argv_buf_size]; cvt_wasi(libc::__wasi_args_get(argc.as_mut_ptr(), argv_buf.as_mut_ptr()))?; diff --git a/src/libstd/sys/wasm/thread_local_atomics.rs b/src/libstd/sys/wasm/thread_local_atomics.rs index b408ad0d5c1f..3dc0bb24553f 100644 --- a/src/libstd/sys/wasm/thread_local_atomics.rs +++ b/src/libstd/sys/wasm/thread_local_atomics.rs @@ -11,7 +11,7 @@ struct ThreadControlBlock { impl ThreadControlBlock { fn new() -> ThreadControlBlock { ThreadControlBlock { - keys: [0 as *mut u8; MAX_KEYS], + keys: [core::ptr::null_mut(); MAX_KEYS], } } diff --git a/src/test/run-make-fulldeps/alloc-extern-crates/fakealloc.rs b/src/test/run-make-fulldeps/alloc-extern-crates/fakealloc.rs index 625c3afab921..d4612c325d5a 100644 --- a/src/test/run-make-fulldeps/alloc-extern-crates/fakealloc.rs +++ b/src/test/run-make-fulldeps/alloc-extern-crates/fakealloc.rs @@ -2,14 +2,16 @@ #![no_std] #[inline] -pub unsafe fn allocate(_size: usize, _align: usize) -> *mut u8 { 0 as *mut u8 } +pub unsafe fn allocate(_size: usize, _align: usize) -> *mut u8 { + core::ptr::null_mut() +} #[inline] pub unsafe fn deallocate(_ptr: *mut u8, _old_size: usize, _align: usize) { } #[inline] pub unsafe fn reallocate(_ptr: *mut u8, _old_size: usize, _size: usize, _align: usize) -> *mut u8 { - 0 as *mut u8 + core::ptr::null_mut() } #[inline] diff --git a/src/test/run-pass/cast.rs b/src/test/run-pass/cast.rs index 37add8446f40..c7977f461dfc 100644 --- a/src/test/run-pass/cast.rs +++ b/src/test/run-pass/cast.rs @@ -15,5 +15,5 @@ pub fn main() { // Test that `_` is correctly inferred. let x = &"hello"; let mut y = x as *const _; - y = 0 as *const _; + y = core::ptr::null_mut(); } diff --git a/src/test/run-pass/cleanup-shortcircuit.rs b/src/test/run-pass/cleanup-shortcircuit.rs index 118fa0083ab4..6e67a276d4f1 100644 --- a/src/test/run-pass/cleanup-shortcircuit.rs +++ b/src/test/run-pass/cleanup-shortcircuit.rs @@ -16,6 +16,6 @@ pub fn main() { if args.len() >= 2 && args[1] == "signal" { // Raise a segfault. - unsafe { *(0 as *mut isize) = 0; } + unsafe { *std::ptr::null_mut::() = 0; } } } diff --git a/src/test/run-pass/consts/const-block.rs b/src/test/run-pass/consts/const-block.rs index 012523a61efc..7172a34c8cfe 100644 --- a/src/test/run-pass/consts/const-block.rs +++ b/src/test/run-pass/consts/const-block.rs @@ -21,7 +21,7 @@ static BLOCK_EXPLICIT_UNIT: () = { () }; static BLOCK_IMPLICIT_UNIT: () = { }; static BLOCK_FLOAT: f64 = { 1.0 }; static BLOCK_ENUM: Option = { Some(100) }; -static BLOCK_STRUCT: Foo = { Foo { a: 12, b: 0 as *const () } }; +static BLOCK_STRUCT: Foo = { Foo { a: 12, b: std::ptr::null::<()>() } }; static BLOCK_UNSAFE: usize = unsafe { 1000 }; static BLOCK_FN_INFERRED: fn(usize) -> usize = { foo }; @@ -36,7 +36,7 @@ pub fn main() { assert_eq!(BLOCK_IMPLICIT_UNIT, ()); assert_eq!(BLOCK_FLOAT, 1.0_f64); assert_eq!(BLOCK_STRUCT.a, 12); - assert_eq!(BLOCK_STRUCT.b, 0 as *const ()); + assert_eq!(BLOCK_STRUCT.b, std::ptr::null::<()>()); assert_eq!(BLOCK_ENUM, Some(100)); assert_eq!(BLOCK_UNSAFE, 1000); assert_eq!(BLOCK_FN_INFERRED(300), 300); diff --git a/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs b/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs index d79d34de571d..740e7780de67 100644 --- a/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs +++ b/src/test/run-pass/issues/issue-13259-windows-tcb-trash.rs @@ -23,8 +23,8 @@ mod imp { pub fn test() { let mut buf: [u16; 50] = [0; 50]; let ret = unsafe { - FormatMessageW(0x1000, 0 as *mut _, 1, 0x400, - buf.as_mut_ptr(), buf.len() as u32, 0 as *const _) + FormatMessageW(0x1000, core::ptr::null_mut(), 1, 0x400, + buf.as_mut_ptr(), buf.len() as u32, core::ptr::null()) }; // On some 32-bit Windowses (Win7-8 at least) this will panic with segmented // stacks taking control of pvArbitrary diff --git a/src/test/run-pass/issues/issue-19001.rs b/src/test/run-pass/issues/issue-19001.rs index 85f7a84ac295..76c380c2fc97 100644 --- a/src/test/run-pass/issues/issue-19001.rs +++ b/src/test/run-pass/issues/issue-19001.rs @@ -7,5 +7,5 @@ struct Loopy { } fn main() { - let _t = Loopy { ptr: 0 as *mut _ }; + let _t = Loopy { ptr: core::ptr::null_mut() }; } diff --git a/src/test/run-pass/issues/issue-39367.rs b/src/test/run-pass/issues/issue-39367.rs index 2e2b480e0660..8314be3d14cc 100644 --- a/src/test/run-pass/issues/issue-39367.rs +++ b/src/test/run-pass/issues/issue-39367.rs @@ -15,7 +15,7 @@ fn arena() -> &'static ArenaSet> { fn require_sync(_: &T) { } unsafe fn __stability() -> &'static ArenaSet> { use std::mem::transmute; - static mut DATA: *const ArenaSet> = 0 as *const ArenaSet>; + static mut DATA: *const ArenaSet> = std::ptr::null_mut(); static mut ONCE: Once = Once::new(); ONCE.call_once(|| { diff --git a/src/test/run-pass/issues/issue-46069.rs b/src/test/run-pass/issues/issue-46069.rs index fba2a2ebe3b0..1d4f789828d8 100644 --- a/src/test/run-pass/issues/issue-46069.rs +++ b/src/test/run-pass/issues/issue-46069.rs @@ -17,7 +17,7 @@ fn copy_ex() { } fn main() { - let _f = 0 as *mut >> as Iterator>::Item; + let _f: *mut >> as Iterator>::Item = std::ptr::null_mut(); copy_ex(); } diff --git a/src/test/run-pass/structs-enums/enum-null-pointer-opt.rs b/src/test/run-pass/structs-enums/enum-null-pointer-opt.rs index f871c2185586..32fdbf620a98 100644 --- a/src/test/run-pass/structs-enums/enum-null-pointer-opt.rs +++ b/src/test/run-pass/structs-enums/enum-null-pointer-opt.rs @@ -38,7 +38,7 @@ fn main() { // The optimization can't apply to raw pointers or unions with a ZST field. assert!(size_of::>() != size_of::<*const isize>()); - assert!(Some(0 as *const isize).is_some()); // Can't collapse None to null + assert!(Some(std::ptr::null::()).is_some()); // Can't collapse None to null assert_ne!(size_of::(), size_of::>>()); assert_ne!(size_of::<&str>(), size_of::>>()); assert_ne!(size_of::>(), size_of::>>>()); diff --git a/src/test/ui/casts-issue-46365.rs b/src/test/ui/casts-issue-46365.rs index 2e7c26b54e41..3d0fea245c0c 100644 --- a/src/test/ui/casts-issue-46365.rs +++ b/src/test/ui/casts-issue-46365.rs @@ -3,5 +3,5 @@ struct Lorem { } fn main() { - let _foo: *mut Lorem = 0 as *mut _; // no error here + let _foo: *mut Lorem = core::ptr::null_mut(); // no error here } diff --git a/src/test/ui/consts/const-eval/ice-generic-assoc-const.rs b/src/test/ui/consts/const-eval/ice-generic-assoc-const.rs index e92de84c2798..2ad1a633d125 100644 --- a/src/test/ui/consts/const-eval/ice-generic-assoc-const.rs +++ b/src/test/ui/consts/const-eval/ice-generic-assoc-const.rs @@ -7,7 +7,7 @@ pub trait Nullable { } impl Nullable for *const T { - const NULL: Self = 0 as *const T; + const NULL: Self = core::ptr::null::(); fn is_null(&self) -> bool { *self == Self::NULL diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs index 40e7107e4a15..9523fcbfc603 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn.rs @@ -69,8 +69,8 @@ const fn i32_ops3(c: i32, d: i32) -> bool { c != d } const fn i32_ops4(c: i32, d: i32) -> i32 { c + d } const fn char_cast(u: u8) -> char { u as char } const unsafe fn ret_i32_no_unsafe() -> i32 { 42 } -const unsafe fn ret_null_ptr_no_unsafe() -> *const T { 0 as *const T } -const unsafe fn ret_null_mut_ptr_no_unsafe() -> *mut T { 0 as *mut T } +const unsafe fn ret_null_ptr_no_unsafe() -> *const T { core::ptr::null() } +const unsafe fn ret_null_mut_ptr_no_unsafe() -> *mut T { core::ptr::null_mut() } // not ok const fn foo11(t: T) -> T { t } diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs index e25dafa74d7a..0152561aefcb 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs @@ -3,8 +3,8 @@ //------------------------------------------------------------------------------ const unsafe fn ret_i32_no_unsafe() -> i32 { 42 } -const unsafe fn ret_null_ptr_no_unsafe() -> *const T { 0 as *const T } -const unsafe fn ret_null_mut_ptr_no_unsafe() -> *mut T { 0 as *mut T } +const unsafe fn ret_null_ptr_no_unsafe() -> *const T { std::ptr::null() } +const unsafe fn ret_null_mut_ptr_no_unsafe() -> *mut T { std::ptr::null_mut() } const fn no_unsafe() { unsafe {} } const fn call_unsafe_const_fn() -> i32 { diff --git a/src/test/ui/derived-errors/issue-31997.rs b/src/test/ui/derived-errors/issue-31997.rs index 025e9100e236..cfdee26c5599 100644 --- a/src/test/ui/derived-errors/issue-31997.rs +++ b/src/test/ui/derived-errors/issue-31997.rs @@ -10,7 +10,7 @@ fn closure(x: F) -> Result } fn foo() -> Result<(), ()> { - try!(closure(|| bar(0 as *mut _))); //~ ERROR cannot find function `bar` in this scope + try!(closure(|| bar(core::ptr::null_mut()))); //~ ERROR cannot find function `bar` in this scope Ok(()) } diff --git a/src/test/ui/derived-errors/issue-31997.stderr b/src/test/ui/derived-errors/issue-31997.stderr index dbceba046e2a..e9fe0d3971ee 100644 --- a/src/test/ui/derived-errors/issue-31997.stderr +++ b/src/test/ui/derived-errors/issue-31997.stderr @@ -1,7 +1,7 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/issue-31997.rs:13:21 | -LL | try!(closure(|| bar(0 as *mut _))); +LL | try!(closure(|| bar(core::ptr::null_mut()))); | ^^^ not found in this scope error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0605.rs b/src/test/ui/error-codes/E0605.rs index 0e86e367e832..cfbf1aa2bd76 100644 --- a/src/test/ui/error-codes/E0605.rs +++ b/src/test/ui/error-codes/E0605.rs @@ -2,6 +2,6 @@ fn main() { let x = 0u8; x as Vec; //~ ERROR E0605 - let v = 0 as *const u8; + let v = std::ptr::null::(); v as &u8; //~ ERROR E0605 } diff --git a/src/test/ui/error-codes/E0607.rs b/src/test/ui/error-codes/E0607.rs index ad9f8709b07f..65001c471cb4 100644 --- a/src/test/ui/error-codes/E0607.rs +++ b/src/test/ui/error-codes/E0607.rs @@ -1,4 +1,4 @@ fn main() { - let v = 0 as *const u8; + let v = core::ptr::null::(); v as *const [u8]; //~ ERROR E0607 } diff --git a/src/test/ui/error-festival.rs b/src/test/ui/error-festival.rs index e462824cded4..356564e54077 100644 --- a/src/test/ui/error-festival.rs +++ b/src/test/ui/error-festival.rs @@ -37,7 +37,7 @@ fn main() { let y: u32 = x as u32; //~^ ERROR E0606 - let v = 0 as *const u8; + let v = core::ptr::null::(); v as *const [u8]; //~^ ERROR E0607 } diff --git a/src/test/ui/issues/issue-17458.rs b/src/test/ui/issues/issue-17458.rs index 444e94d829bf..d56ffebad7d5 100644 --- a/src/test/ui/issues/issue-17458.rs +++ b/src/test/ui/issues/issue-17458.rs @@ -1,4 +1,4 @@ -static X: usize = unsafe { 0 as *const usize as usize }; +static X: usize = unsafe { core::ptr::null::() as usize }; //~^ ERROR: casting pointers to integers in statics is unstable fn main() { diff --git a/src/test/ui/issues/issue-17458.stderr b/src/test/ui/issues/issue-17458.stderr index 69b6ab71e507..d51d2f50d6fa 100644 --- a/src/test/ui/issues/issue-17458.stderr +++ b/src/test/ui/issues/issue-17458.stderr @@ -1,8 +1,8 @@ error[E0658]: casting pointers to integers in statics is unstable --> $DIR/issue-17458.rs:1:28 | -LL | static X: usize = unsafe { 0 as *const usize as usize }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | static X: usize = unsafe { core::ptr::null::() as usize }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/51910 = help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable diff --git a/src/test/ui/issues/issue-20801.rs b/src/test/ui/issues/issue-20801.rs index 35d6f8c0fae1..c3f136f2876b 100644 --- a/src/test/ui/issues/issue-20801.rs +++ b/src/test/ui/issues/issue-20801.rs @@ -15,11 +15,11 @@ fn mut_ref() -> &'static mut T { } fn mut_ptr() -> *mut T { - unsafe { 0 as *mut T } + unsafe { core::ptr::null_mut() } } fn const_ptr() -> *const T { - unsafe { 0 as *const T } + unsafe { core::ptr::null() } } pub fn main() { diff --git a/src/test/ui/issues/issue-22034.rs b/src/test/ui/issues/issue-22034.rs index 508c9c91b04e..fab1cdadaf5e 100644 --- a/src/test/ui/issues/issue-22034.rs +++ b/src/test/ui/issues/issue-22034.rs @@ -3,7 +3,7 @@ extern crate libc; fn main() { - let ptr: *mut () = 0 as *mut _; + let ptr: *mut () = core::ptr::null_mut(); let _: &mut dyn Fn() = unsafe { &mut *(ptr as *mut dyn Fn()) //~^ ERROR expected a `std::ops::Fn<()>` closure, found `()` diff --git a/src/test/ui/mismatched_types/cast-rfc0401.rs b/src/test/ui/mismatched_types/cast-rfc0401.rs index 2f88c6496c42..b8d12fb9809c 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.rs +++ b/src/test/ui/mismatched_types/cast-rfc0401.rs @@ -21,9 +21,9 @@ enum E { fn main() { let f: f32 = 1.2; - let v = 0 as *const u8; - let fat_v : *const [u8] = unsafe { &*(0 as *const [u8; 1])}; - let fat_sv : *const [i8] = unsafe { &*(0 as *const [i8; 1])}; + let v = core::ptr::null::(); + let fat_v : *const [u8] = unsafe { &*core::ptr::null::<[u8; 1]>()}; + let fat_sv : *const [i8] = unsafe { &*core::ptr::null::<[i8; 1]>()}; let foo: &dyn Foo = &f; let _ = v as &u8; //~ ERROR non-primitive cast From ccb2dfbfec812d1502626992a8856df27c4fa950 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Jun 2019 11:35:26 +0300 Subject: [PATCH 032/109] don't ICE on large files This is an extremely marginal error, so the cost of properly threading `Handler` everywhere just not seemed justified. However, it's useful to panic when we create a file, and not when we slice strings with overflown indexes somewhere in the guts of the compiler. For this reason, while we provide safe `try_new_source_file`, we don't change the existing public interface and just panic more or less cleanly. --- src/libsyntax/source_map.rs | 19 ++++++++++++++++--- src/libsyntax_pos/lib.rs | 12 +++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index a21d2df41620..c0307263387e 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -191,6 +191,18 @@ impl SourceMap { /// If a file already exists in the source_map with the same id, that file is returned /// unmodified pub fn new_source_file(&self, filename: FileName, src: String) -> Lrc { + self.try_new_source_file(filename, src) + .unwrap_or_else(|OffsetOverflowError| { + eprintln!("fatal error: rustc does not support files larger than 4GB"); + errors::FatalError.raise() + }) + } + + fn try_new_source_file( + &self, + filename: FileName, + src: String + ) -> Result, OffsetOverflowError> { let start_pos = self.next_start_pos(); // The path is used to determine the directory for loading submodules and @@ -212,7 +224,7 @@ impl SourceMap { was_remapped, Some(&unmapped_path)); - return match self.source_file_by_stable_id(file_id) { + let lrc_sf = match self.source_file_by_stable_id(file_id) { Some(lrc_sf) => lrc_sf, None => { let source_file = Lrc::new(SourceFile::new( @@ -221,7 +233,7 @@ impl SourceMap { unmapped_path, src, Pos::from_usize(start_pos), - )); + )?); let mut files = self.files.borrow_mut(); @@ -230,7 +242,8 @@ impl SourceMap { source_file } - } + }; + Ok(lrc_sf) } /// Allocates a new SourceFile representing a source file from an external diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index e7158372762d..2dd409bf5bee 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -859,6 +859,9 @@ impl ExternalSource { } } +#[derive(Debug)] +pub struct OffsetOverflowError; + /// A single source in the `SourceMap`. #[derive(Clone)] pub struct SourceFile { @@ -1040,7 +1043,7 @@ impl SourceFile { name_was_remapped: bool, unmapped_path: FileName, mut src: String, - start_pos: BytePos) -> SourceFile { + start_pos: BytePos) -> Result { remove_bom(&mut src); let src_hash = { @@ -1054,11 +1057,14 @@ impl SourceFile { hasher.finish() }; let end_pos = start_pos.to_usize() + src.len(); + if end_pos > u32::max_value() as usize { + return Err(OffsetOverflowError); + } let (lines, multibyte_chars, non_narrow_chars) = analyze_source_file::analyze_source_file(&src[..], start_pos); - SourceFile { + Ok(SourceFile { name, name_was_remapped, unmapped_path: Some(unmapped_path), @@ -1072,7 +1078,7 @@ impl SourceFile { multibyte_chars, non_narrow_chars, name_hash, - } + }) } /// Returns the `BytePos` of the beginning of the current line. From 61964d9732847a3c208c48d07cb8c2ddae8ddb3c Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 14 Jun 2019 12:28:47 +0200 Subject: [PATCH 033/109] replace some uses of NodeId with HirId --- src/librustc/cfg/construct.rs | 3 +- src/librustc/cfg/graphviz.rs | 6 +- src/librustc/hir/map/hir_id_validator.rs | 3 +- src/librustc/hir/map/mod.rs | 98 ++----------------- src/librustc/hir/upvars.rs | 4 +- src/librustc/infer/error_reporting/mod.rs | 8 +- .../nice_region_error/find_anon_type.rs | 4 +- .../nice_region_error/outlives_closure.rs | 4 +- .../error_reporting/nice_region_error/util.rs | 8 +- src/librustc/middle/mem_categorization.rs | 21 ++-- src/librustc/middle/region.rs | 19 ++-- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc/traits/error_reporting.rs | 6 +- src/librustc/ty/context.rs | 4 +- src/librustc_borrowck/borrowck/mod.rs | 19 ++-- src/librustc_driver/pretty.rs | 3 +- .../borrow_check/mutability_errors.rs | 4 +- .../error_reporting/region_name.rs | 20 ++-- src/librustc_mir/build/mod.rs | 6 +- src/librustc_mir/hair/cx/expr.rs | 11 ++- src/librustc_mir/interpret/validity.rs | 4 +- src/librustc_passes/rvalue_promotion.rs | 4 +- src/librustc_typeck/astconv.rs | 10 +- src/librustc_typeck/check/mod.rs | 3 +- src/librustc_typeck/check/writeback.rs | 7 +- src/librustc_typeck/collect.rs | 2 +- 26 files changed, 95 insertions(+), 190 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 139c144fbcf4..8eea01cc4acc 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -42,7 +42,8 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG { let body_exit; // Find the tables for this body. - let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id())); + let owner_hir_id = tcx.hir().body_owner(body.id()); + let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_hir_id); let tables = tcx.typeck_tables_of(owner_def_id); let mut cfg_builder = CFGBuilder { diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index dbc462ee49b3..0bfb6b98e630 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -22,11 +22,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> { impl<'a, 'tcx> LabelledCFG<'a, 'tcx> { fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String { assert!(self.cfg.owner_def_id.is_local()); - let node_id = self.tcx.hir().hir_to_node_id(hir::HirId { + let hir_id = hir::HirId { owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner, local_id - }); - let s = self.tcx.hir().node_to_string(node_id); + }; + let s = self.tcx.hir().hir_to_string(hir_id); // Replacing newlines with \\l causes each line to be left-aligned, // improving presentation of (long) pretty-printed expressions. diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index fafe671b9eb8..08ec2aeed290 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -122,9 +122,10 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { .find(|&(_, &entry)| hir_id == entry) .expect("no node_to_hir_id entry"); let node_id = NodeId::from_usize(node_id); + let hir_id = self.hir_map.node_to_hir_id(node_id); missing_items.push(format!("[local_id: {}, node:{}]", local_id, - self.hir_map.node_to_string(node_id))); + self.hir_map.hir_to_string(hir_id))); } self.error(|| format!( "ItemLocalIds not assigned densely in {}. \ diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 978a5556d31b..680fe2866bce 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -286,21 +286,11 @@ impl<'hir> Map<'hir> { self.definitions.def_index_to_hir_id(def_index) } - #[inline] - pub fn def_index_to_node_id(&self, def_index: DefIndex) -> NodeId { - self.definitions.def_index_to_node_id(def_index) - } - #[inline] pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId { self.definitions.def_index_to_hir_id(def_id.to_def_id().index) } - #[inline] - pub fn local_def_id_to_node_id(&self, def_id: LocalDefId) -> NodeId { - self.definitions.as_local_node_id(def_id.to_def_id()).unwrap() - } - fn def_kind(&self, node_id: NodeId) -> Option { let node = if let Some(node) = self.find(node_id) { node @@ -422,12 +412,6 @@ impl<'hir> Map<'hir> { self.forest.krate.body(id) } - pub fn fn_decl(&self, node_id: ast::NodeId) -> Option { - let hir_id = self.node_to_hir_id(node_id); - self.fn_decl_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option { if let Some(entry) = self.find_entry(hir_id) { entry.fn_decl().cloned() @@ -439,24 +423,18 @@ impl<'hir> Map<'hir> { /// Returns the `NodeId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. - pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId { + pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.get_parent_node_by_hir_id(hir_id); assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id))); - self.hir_to_node_id(parent) + parent } pub fn body_owner_def_id(&self, id: BodyId) -> DefId { - self.local_def_id(self.body_owner(id)) + self.local_def_id_from_hir_id(self.body_owner(id)) } - /// Given a `NodeId`, returns the `BodyId` associated with it, + /// Given a `HirId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. - pub fn maybe_body_owned_by(&self, id: NodeId) -> Option { - let hir_id = self.node_to_hir_id(id); - self.maybe_body_owned_by_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn maybe_body_owned_by_by_hir_id(&self, hir_id: HirId) -> Option { if let Some(entry) = self.find_entry(hir_id) { if self.dep_graph.is_fully_enabled() { @@ -479,12 +457,6 @@ impl<'hir> Map<'hir> { }) } - pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind { - let hir_id = self.node_to_hir_id(id); - self.body_owner_kind_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind { match self.get_by_hir_id(id) { Node::Item(&Item { node: ItemKind::Const(..), .. }) | @@ -793,17 +765,10 @@ impl<'hir> Map<'hir> { self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok() } - /// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no + /// Retrieves the `HirId` for `id`'s parent item, or `id` itself if no /// parent item is in this map. The "parent item" is the closest parent node /// in the HIR which is recorded by the map and is an item, either an item /// in a module, trait, or impl. - pub fn get_parent(&self, id: NodeId) -> NodeId { - let hir_id = self.node_to_hir_id(id); - let parent_hir_id = self.get_parent_item(hir_id); - self.hir_to_node_id(parent_hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_parent_item(&self, hir_id: HirId) -> HirId { match self.walk_parent_nodes(hir_id, |node| match *node { Node::Item(_) | @@ -819,12 +784,6 @@ impl<'hir> Map<'hir> { /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. - pub fn get_module_parent(&self, id: NodeId) -> DefId { - let hir_id = self.node_to_hir_id(id); - self.get_module_parent_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_module_parent_node(id)) } @@ -901,22 +860,10 @@ impl<'hir> Map<'hir> { Some(scope) } - pub fn get_parent_did(&self, id: NodeId) -> DefId { - let hir_id = self.node_to_hir_id(id); - self.get_parent_did_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_parent_item(id)) } - pub fn get_foreign_abi(&self, id: NodeId) -> Abi { - let hir_id = self.node_to_hir_id(id); - self.get_foreign_abi_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_foreign_abi_by_hir_id(&self, hir_id: HirId) -> Abi { let parent = self.get_parent_item(hir_id); if let Some(entry) = self.find_entry(parent) { @@ -930,12 +877,6 @@ impl<'hir> Map<'hir> { bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) } - pub fn expect_item(&self, id: NodeId) -> &'hir Item { - let hir_id = self.node_to_hir_id(id); - self.expect_item_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { match self.find_by_hir_id(id) { // read recorded by `find` Some(Node::Item(item)) => item, @@ -1024,12 +965,6 @@ impl<'hir> Map<'hir> { /// Given a node ID, gets a list of attributes associated with the AST /// corresponding to the node-ID. - pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] { - let hir_id = self.node_to_hir_id(id); - self.attrs_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] { self.read(id); // reveals attributes on the node let attrs = match self.find_entry(id).map(|entry| entry.node) { @@ -1093,12 +1028,6 @@ impl<'hir> Map<'hir> { }) } - pub fn span(&self, id: NodeId) -> Span { - let hir_id = self.node_to_hir_id(id); - self.span_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn span_by_hir_id(&self, hir_id: HirId) -> Span { self.read(hir_id); // reveals span from node match self.find_entry(hir_id).map(|entry| entry.node) { @@ -1139,32 +1068,17 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - self.as_local_node_id(id).map(|id| self.span(id)) + self.as_local_hir_id(id).map(|id| self.span_by_hir_id(id)) } - pub fn node_to_string(&self, id: NodeId) -> String { - hir_id_to_string(self, self.node_to_hir_id(id), true) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn hir_to_string(&self, id: HirId) -> String { hir_id_to_string(self, id, true) } - pub fn node_to_user_string(&self, id: NodeId) -> String { - hir_id_to_string(self, self.node_to_hir_id(id), false) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn hir_to_user_string(&self, id: HirId) -> String { hir_id_to_string(self, id, false) } - pub fn node_to_pretty_string(&self, id: NodeId) -> String { - print::to_string(self, |s| s.print_node(self.get(id))) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn hir_to_pretty_string(&self, id: HirId) -> String { print::to_string(self, |s| s.print_node(self.get_by_hir_id(id))) } diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index 1a4fe35c530b..662bde43c569 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -14,8 +14,8 @@ pub fn provide(providers: &mut Providers<'_>) { return None; } - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(node_id)?); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let body = tcx.hir().body(tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)?); let mut local_collector = LocalCollector::default(); local_collector.visit_body(body); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 04d29a8db1c3..73bd37d53fe2 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> { ) }; let span = scope.span(self, region_scope_tree); - let tag = match self.hir().find(scope.node_id(self, region_scope_tree)) { + let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) { Some(Node::Block(_)) => "block", Some(Node::Expr(expr)) => match expr.node { hir::ExprKind::Call(..) => "call", @@ -1330,15 +1330,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if !param.is_self() { let type_param = generics.type_param(param, self.tcx); let hir = &self.tcx.hir(); - hir.as_local_node_id(type_param.def_id).map(|id| { + hir.as_local_hir_id(type_param.def_id).map(|id| { // Get the `hir::Param` to verify whether it already has any bounds. // We do this to avoid suggesting code that ends up as `T: 'a'b`, // instead we suggest `T: 'a + 'b` in that case. let mut has_bounds = false; - if let Node::GenericParam(ref param) = hir.get(id) { + if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) { has_bounds = !param.bounds.is_empty(); } - let sp = hir.span(id); + let sp = hir.span_by_hir_id(id); // `sp` only covers `T`, change it so that it covers // `T:` when appropriate let is_impl_trait = bound_kind.to_string().starts_with("impl "); diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index fa95ea101325..78d1d56993e0 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -28,8 +28,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { ) -> Option<(&hir::Ty, &hir::FnDecl)> { if let Some(anon_reg) = self.tcx().is_suitable_region(region) { let def_id = anon_reg.def_id; - if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) { - let fndecl = match self.tcx().hir().get(node_id) { + if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) { + let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(ref fndecl, ..), .. diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs index 0d98a024977d..6ed2b67556dd 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -48,11 +48,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span), &RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) { let hir = &self.tcx().hir(); - if let Some(node_id) = hir.as_local_node_id(free_region.scope) { + if let Some(hir_id) = hir.as_local_hir_id(free_region.scope) { if let Node::Expr(Expr { node: Closure(_, _, _, closure_span, None), .. - }) = hir.get(node_id) { + }) = hir.get_by_hir_id(hir_id) { let sup_sp = sup_origin.span(); let origin_sp = origin.span(); let mut err = self.tcx().sess.struct_span_err( diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 017f36b02098..061d74416c57 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -51,11 +51,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { }; let hir = &self.tcx().hir(); - if let Some(node_id) = hir.as_local_node_id(id) { - if let Some(body_id) = hir.maybe_body_owned_by(node_id) { + if let Some(hir_id) = hir.as_local_hir_id(id) { + if let Some(body_id) = hir.maybe_body_owned_by_by_hir_id(hir_id) { let body = hir.body(body_id); let owner_id = hir.body_owner(body_id); - let fn_decl = hir.fn_decl(owner_id).unwrap(); + let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); if let Some(tables) = self.tables { body.arguments .iter() @@ -63,7 +63,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { .filter_map(|(index, arg)| { // May return None; sometimes the tables are not yet populated. let ty_hir_id = fn_decl.inputs[index].hir_id; - let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id)); + let arg_ty_span = hir.span_by_hir_id(ty_hir_id); let ty = tables.node_type_opt(arg.hir_id)?; let mut found_anon_region = false; let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3b21b81df7b4..cf304ebf3cbf 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -342,9 +342,9 @@ impl MutabilityCategory { fn from_local( tcx: TyCtxt<'_>, tables: &ty::TypeckTables<'_>, - id: ast::NodeId, + id: hir::HirId, ) -> MutabilityCategory { - let ret = match tcx.hir().get(id) { + let ret = match tcx.hir().get_by_hir_id(id) { Node::Binding(p) => match p.node { PatKind::Binding(..) => { let bm = *tables.pat_binding_modes() @@ -358,7 +358,7 @@ impl MutabilityCategory { } _ => span_bug!(p.span, "expected identifier pattern") }, - _ => span_bug!(tcx.hir().span(id), "expected identifier pattern") + _ => span_bug!(tcx.hir().span_by_hir_id(id), "expected identifier pattern") }; debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}", "from_local", id, ret); @@ -500,9 +500,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { // FIXME None if self.is_tainted_by_errors() => Err(()), None => { - let id = self.tcx.hir().hir_to_node_id(id); bug!("no type for node {}: {} in mem_categorization", - id, self.tcx.hir().node_to_string(id)); + id, self.tcx.hir().hir_to_string(id)); } } } @@ -753,15 +752,14 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } Res::Local(var_id) => { - let var_nid = self.tcx.hir().hir_to_node_id(var_id); if self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) { - self.cat_upvar(hir_id, span, var_nid) + self.cat_upvar(hir_id, span, var_id) } else { Ok(cmt_ { hir_id, span, cat: Categorization::Local(var_id), - mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_nid), + mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_id), ty: expr_ty, note: NoteNone }) @@ -778,7 +776,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { &self, hir_id: hir::HirId, span: Span, - var_id: ast::NodeId, + var_id: hir::HirId, ) -> McResult> { // An upvar can have up to 3 components. We translate first to a // `Categorization::Upvar`, which is itself a fiction -- it represents the reference to the @@ -828,13 +826,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { _ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty), }; - let var_hir_id = self.tcx.hir().node_to_hir_id(var_id); let upvar_id = ty::UpvarId { - var_path: ty::UpvarPath { hir_id: var_hir_id }, + var_path: ty::UpvarPath { hir_id: var_id }, closure_expr_id: closure_expr_def_id.to_local(), }; - let var_ty = self.node_ty(var_hir_id)?; + let var_ty = self.node_ty(var_id)?; // Mutability of original variable itself let var_mutbl = MutabilityCategory::from_local(self.tcx, self.tables, var_id); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 8b1eeeb7f51b..708bd6f735d8 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -14,7 +14,6 @@ use std::mem; use std::fmt; use rustc_macros::HashStable; use syntax::source_map; -use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; use crate::ty::{DefIdTree, TyCtxt}; use crate::ty::query::Providers; @@ -169,15 +168,15 @@ impl Scope { self.id } - pub fn node_id(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> ast::NodeId { + pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId { match scope_tree.root_body { Some(hir_id) => { - tcx.hir().hir_to_node_id(hir::HirId { + hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() - }) + } } - None => ast::DUMMY_NODE_ID + None => hir::DUMMY_HIR_ID } } @@ -185,13 +184,13 @@ impl Scope { /// returned span may not correspond to the span of any `NodeId` in /// the AST. pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span { - let node_id = self.node_id(tcx, scope_tree); - if node_id == ast::DUMMY_NODE_ID { + let hir_id = self.hir_id(scope_tree); + if hir_id == hir::DUMMY_HIR_ID { return DUMMY_SP; } - let span = tcx.hir().span(node_id); + let span = tcx.hir().span_by_hir_id(hir_id); if let ScopeData::Remainder(first_statement_index) = self.data { - if let Node::Block(ref blk) = tcx.hir().get(node_id) { + if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) { // Want span for scope starting after the // indexed statement and ending at end of // `blk`; reuse span of `blk` and shift `lo` @@ -1278,7 +1277,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // The body of the every fn is a root scope. self.cx.parent = self.cx.var_parent; - if self.tcx.hir().body_owner_kind(owner_id).is_fn_or_closure() { + if self.tcx.hir().body_owner_kind_by_hir_id(owner_id).is_fn_or_closure() { self.visit_expr(&body.value) } else { // Only functions have an outer terminating (drop) scope, while diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 48d2a477a9af..b350f15664d4 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1823,7 +1823,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // Do not free early-bound regions, only late-bound ones. } else if let Some(body_id) = outermost_body { let fn_id = self.tcx.hir().body_owner(body_id); - match self.tcx.hir().get(fn_id) { + match self.tcx.hir().get_by_hir_id(fn_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(..), .. @@ -1836,7 +1836,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { node: hir::ImplItemKind::Method(..), .. }) => { - let scope = self.tcx.hir().local_def_id(fn_id); + let scope = self.tcx.hir().local_def_id_from_hir_id(fn_id); def = Region::Free(scope, def.id().unwrap()); } _ => {} diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 42bde3563492..f886794be628 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1013,10 +1013,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { trait_ref: &ty::Binder>, ) { let hir = self.tcx.hir(); - let parent_node = hir.get_parent_node( - hir.hir_to_node_id(obligation.cause.body_id), - ); - let node = hir.find(parent_node); + let parent_node = hir.get_parent_node_by_hir_id(obligation.cause.body_id); + let node = hir.find_by_hir_id(parent_node); if let Some(hir::Node::Item(hir::Item { node: hir::ItemKind::Fn(decl, _, _, body_id), .. diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index e5d06532b3a1..c32f62e88c42 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -250,11 +250,9 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option, if let Some(local_id_root) = local_id_root { if hir_id.owner != local_id_root.index { ty::tls::with(|tcx| { - let node_id = tcx.hir().hir_to_node_id(hir_id); - bug!("node {} with HirId::owner {:?} cannot be placed in \ TypeckTables with local_id_root {:?}", - tcx.hir().node_to_string(node_id), + tcx.hir().hir_to_string(hir_id), DefId::local(hir_id.owner), local_id_root) }); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 9b0dce50dd0c..9429fde27908 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -198,7 +198,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( cfg: &cfg::CFG, ) -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>) { let owner_id = tcx.hir().body_owner(body_id); - let owner_def_id = tcx.hir().local_def_id(owner_id); + let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_id); let tables = tcx.typeck_tables_of(owner_def_id); let region_scope_tree = tcx.region_scope_tree(owner_def_id); let body = tcx.hir().body(body_id); @@ -389,8 +389,8 @@ pub enum LoanPathElem<'tcx> { } fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_>) -> HirId { - let closure_id = tcx.hir().local_def_id_to_node_id(closure_id); - match tcx.hir().get(closure_id) { + let closure_id = tcx.hir().local_def_id_to_hir_id(closure_id); + match tcx.hir().get_by_hir_id(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { body_id.hir_id @@ -896,8 +896,7 @@ impl BorrowckCtxt<'_, 'tcx> { // to implement two traits for "one operator" is not very intuitive for // many programmers. if err.cmt.note == mc::NoteIndex { - let node_id = self.tcx.hir().hir_to_node_id(err.cmt.hir_id); - let node = self.tcx.hir().get(node_id); + let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); // This pattern probably always matches. if let Node::Expr( @@ -1022,8 +1021,8 @@ impl BorrowckCtxt<'_, 'tcx> { } if let ty::ReScope(scope) = *super_scope { - let node_id = scope.node_id(self.tcx, &self.region_scope_tree); - match self.tcx.hir().find(node_id) { + let hir_id = scope.hir_id(&self.region_scope_tree); + match self.tcx.hir().find_by_hir_id(hir_id) { Some(Node::Stmt(_)) => { if *sub_scope != ty::ReStatic { db.note("consider using a `let` binding to increase its lifetime"); @@ -1514,8 +1513,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> { LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => { let s = ty::tls::with(|tcx| { - let var_node_id = tcx.hir().hir_to_node_id(var_id); - tcx.hir().node_to_string(var_node_id) + tcx.hir().hir_to_string(var_id) }); write!(f, "$({} captured by id={:?})", s, closure_expr_id) } @@ -1549,8 +1547,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> { LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => { let s = ty::tls::with(|tcx| { - let var_node_id = tcx.hir().hir_to_node_id(hir_id); - tcx.hir().node_to_string(var_node_id) + tcx.hir().hir_to_string(hir_id) }); write!(f, "$({} captured by closure)", s) } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index e70c510b779c..ef416dbe62b8 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -922,7 +922,8 @@ fn print_with_analysis<'tcx>( got {:?}", node); - tcx.sess.span_fatal(tcx.hir().span(nodeid), &message) + let hir_id = tcx.hir().node_to_hir_id(nodeid); + tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &message) } } } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index d3c23cfd65a6..fc11cd82f8a9 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -304,8 +304,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err.span_label(span, format!("cannot {ACT}", ACT = act)); let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id; - let upvar_node_id = self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id); - if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_node_id) { + if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find_by_hir_id(upvar_hir_id) + { if let hir::PatKind::Binding( hir::BindingAnnotation::Unannotated, _, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 1ec30897e92d..61a13df47ffe 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -230,14 +230,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { }, ty::BoundRegion::BrEnv => { - let mir_node_id = tcx.hir() - .as_local_node_id(mir_def_id) - .expect("non-local mir"); + let mir_hir_id = tcx.hir() + .as_local_hir_id(mir_def_id) + .expect("non-local mir"); let def_ty = self.universal_regions.defining_ty; if let DefiningTy::Closure(def_id, substs) = def_ty { let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) = - tcx.hir().expect_expr(mir_node_id).node + tcx.hir().expect_expr_by_hir_id(mir_hir_id).node { span } else { @@ -367,8 +367,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { argument_index: usize, counter: &mut usize, ) -> Option { - let mir_node_id = infcx.tcx.hir().as_local_node_id(mir_def_id)?; - let fn_decl = infcx.tcx.hir().fn_decl(mir_node_id)?; + let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?; + let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?; let argument_hir_ty: &hir::Ty = &fn_decl.inputs[argument_index]; match argument_hir_ty.node { // This indicates a variable with no type annotation, like @@ -696,9 +696,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { highlight.highlighting_region_vid(fr, *counter); let type_name = infcx.extract_type_name(&return_ty, Some(highlight)); - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir"); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); - let (return_span, mir_description) = match tcx.hir().get(mir_node_id) { + let (return_span, mir_description) = match tcx.hir().get_by_hir_id(mir_hir_id) { hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, return_ty, _, span, gen_move), .. @@ -759,9 +759,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { highlight.highlighting_region_vid(fr, *counter); let type_name = infcx.extract_type_name(&yield_ty, Some(highlight)); - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir"); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); - let yield_span = match tcx.hir().get(mir_node_id) { + let yield_span = match tcx.hir().get_by_hir_id(mir_hir_id) { hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, span, _), .. diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 3a48f35ad0fe..280592e2b016 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -101,7 +101,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { let owner_id = tcx.hir().body_owner(body_id); let opt_ty_info; let self_arg; - if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) { + if let Some(ref fn_decl) = tcx.hir().fn_decl_by_hir_id(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; let ty_span = tcx.hir().span_by_hir_id(ty_hir_id); opt_ty_info = Some(ty_span); @@ -650,7 +650,7 @@ fn construct_const<'a, 'tcx>( ) -> Body<'tcx> { let tcx = hir.tcx(); let owner_id = tcx.hir().body_owner(body_id); - let span = tcx.hir().span(owner_id); + let span = tcx.hir().span_by_hir_id(owner_id); let mut builder = Builder::new( hir, span, @@ -689,7 +689,7 @@ fn construct_error<'a, 'tcx>( body_id: hir::BodyId ) -> Body<'tcx> { let owner_id = hir.tcx().hir().body_owner(body_id); - let span = hir.tcx().hir().span(owner_id); + let span = hir.tcx().hir().span_by_hir_id(owner_id); let ty = hir.tcx().types.err; let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![], false); let source_info = builder.source_info(span); diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 89452b23880c..9f05cf981f51 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -908,12 +908,13 @@ fn convert_path_expr<'a, 'tcx>( } Res::Def(DefKind::ConstParam, def_id) => { - let node_id = cx.tcx.hir().as_local_node_id(def_id).unwrap(); - let item_id = cx.tcx.hir().get_parent_node(node_id); - let item_def_id = cx.tcx.hir().local_def_id(item_id); + let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap(); + let item_id = cx.tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(item_id); let generics = cx.tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&cx.tcx.hir().local_def_id(node_id)]; - let name = cx.tcx.hir().name(node_id).as_interned_str(); + let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); + let index = generics.param_def_id_to_index[&local_def_id]; + let name = cx.tcx.hir().name_by_hir_id(hir_id).as_interned_str(); let val = ConstValue::Param(ty::ParamConst::new(index, name)); ExprKind::Literal { literal: cx.tcx.mk_const( diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 8a8cc0fe1d17..03ccbdb14b73 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -175,8 +175,8 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M // Sometimes the index is beyond the number of upvars (seen // for a generator). if let Some((&var_hir_id, _)) = upvars.get_index(field) { - let var_node_id = self.ecx.tcx.hir().hir_to_node_id(var_hir_id); - if let hir::Node::Binding(pat) = self.ecx.tcx.hir().get(var_node_id) { + let node = self.ecx.tcx.hir().get_by_hir_id(var_hir_id); + if let hir::Node::Binding(pat) = node { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { name = Some(ident.name); } diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 7230b6946812..3adee156eb17 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -165,7 +165,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability { let item_id = self.tcx.hir().body_owner(body_id); - let item_def_id = self.tcx.hir().local_def_id(item_id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); let outer_in_fn = self.in_fn; let outer_tables = self.tables; @@ -175,7 +175,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { self.in_fn = false; self.in_static = false; - match self.tcx.hir().body_owner_kind(item_id) { + match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => self.in_fn = true, hir::BodyOwnerKind::Static(_) => self.in_static = true, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 892a7b1f7301..97124e534771 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2196,12 +2196,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(def_id) = self.const_param_def_id(expr) { // Find the name and index of the const parameter by indexing the generics of the // parent item and construct a `ParamConst`. - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item_id = tcx.hir().get_parent_node(node_id); - let item_def_id = tcx.hir().local_def_id(item_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)]; - let name = tcx.hir().name(node_id).as_interned_str(); + let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)]; + let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str(); const_.val = ConstValue::Param(ty::ParamConst::new(index, name)); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ecf7860367be..c4a834dd600a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2517,9 +2517,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(&t) => t, None if self.is_tainted_by_errors() => self.tcx.types.err, None => { - let node_id = self.tcx.hir().hir_to_node_id(id); bug!("no type for node {}: {} in fcx {}", - node_id, self.tcx.hir().node_to_string(node_id), + id, self.tcx.hir().hir_to_string(id), self.tag()); } } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 5be822897407..1e33551b2560 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -34,7 +34,7 @@ use syntax_pos::Span; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body) -> &'tcx ty::TypeckTables<'tcx> { let item_id = self.tcx.hir().body_owner(body.id()); - let item_def_id = self.tcx.hir().local_def_id(item_id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); // This attribute causes us to dump some writeback information // in the form of errors, which is uSymbolfor unit tests. @@ -45,10 +45,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.visit_node_id(arg.pat.span, arg.hir_id); } // Type only exists for constants and statics, not functions. - match self.tcx.hir().body_owner_kind(item_id) { + match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => { - let item_hir_id = self.tcx.hir().node_to_hir_id(item_id); - wbcx.visit_node_id(body.value.span, item_hir_id); + wbcx.visit_node_id(body.value.span, item_id); } hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (), } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d4b2c200297d..1273fcfc2573 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -395,7 +395,7 @@ fn is_param<'tcx>(tcx: TyCtxt<'tcx>, ast_ty: &hir::Ty, param_id: hir::HirId) -> } fn convert_item<'tcx>(tcx: TyCtxt<'tcx>, item_id: hir::HirId) { - let it = tcx.hir().expect_item_by_hir_id(item_id); + let it = tcx.hir().expect_item(item_id); debug!("convert: item {} with id {}", it.ident, it.hir_id); let def_id = tcx.hir().local_def_id_from_hir_id(item_id); match it.node { From d996c4d5a383744ec7550b59943b5744f4bcd122 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 14 Jun 2019 18:58:55 +0200 Subject: [PATCH 034/109] remove _by_hir_id if there is no NodeId counterpart --- src/librustc/cfg/construct.rs | 2 +- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/map/mod.rs | 28 +++++++++---------- src/librustc/hir/upvars.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 10 +++---- .../error_reporting/nice_region_error/util.rs | 4 +-- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 2 +- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/liveness.rs | 4 +-- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/reachable.rs | 6 ++-- src/librustc/middle/region.rs | 8 +++--- src/librustc/middle/resolve_lifetime.rs | 14 +++++----- src/librustc/mir/mod.rs | 4 +-- src/librustc/mir/mono.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/util.rs | 2 +- src/librustc/ty/mod.rs | 14 +++++----- src/librustc/ty/print/pretty.rs | 4 +-- .../borrowck/gather_loans/move_error.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 16 +++++------ src/librustc_codegen_ssa/mono_item.rs | 2 +- src/librustc_driver/pretty.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_lint/types.rs | 2 +- src/librustc_lint/unused.rs | 2 +- src/librustc_metadata/encoder.rs | 6 ++-- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/borrow_check/move_errors.rs | 2 +- .../error_reporting/region_name.rs | 2 +- .../region_infer/error_reporting/var_name.rs | 2 +- .../borrow_check/nll/universal_regions.rs | 2 +- src/librustc_mir/build/mod.rs | 14 +++++----- src/librustc_mir/hair/cx/block.rs | 2 +- src/librustc_mir/hair/cx/mod.rs | 4 +-- src/librustc_mir/hair/pattern/check_match.rs | 6 ++-- src/librustc_mir/lints.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/monomorphize/item.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 8 +++--- src/librustc_mir/transform/inline.rs | 2 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/librustc_passes/rvalue_promotion.rs | 2 +- src/librustc_privacy/lib.rs | 16 +++++------ src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 2 +- src/librustc_typeck/check/dropck.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 8 +++--- src/librustc_typeck/check/mod.rs | 16 +++++------ src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/check/writeback.rs | 8 +++--- src/librustc_typeck/check_unused.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 14 +++++----- src/librustc_typeck/collect.rs | 18 ++++++------ src/librustc_typeck/variance/mod.rs | 2 +- src/librustdoc/clean/inline.rs | 4 +-- src/librustdoc/clean/mod.rs | 10 +++---- src/librustdoc/visit_ast.rs | 10 +++---- .../auxiliary/issue-40001-plugin.rs | 2 +- 62 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 8eea01cc4acc..8f0f832b6c41 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -358,7 +358,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { args: I) -> CFGIndex { let func_or_rcvr_exit = self.expr(func_or_rcvr, pred); let ret = self.straightline(call_expr, func_or_rcvr_exit, args); - let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id); + let m = self.tcx.hir().get_module_parent(call_expr.hir_id); if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) { self.add_unreachable_node() } else { diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index f4f9d6261de4..666cfc3f6dca 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -171,7 +171,7 @@ pub trait Visitor<'v> : Sized { /// but cannot supply a `Map`; see `nested_visit_map` for advice. #[allow(unused_variables)] fn visit_nested_item(&mut self, id: ItemId) { - let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item_by_hir_id(id.id)); + let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item(id.id)); if let Some(item) = opt_item { self.visit_item(item); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 680fe2866bce..5a45f04b6371 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -435,7 +435,7 @@ impl<'hir> Map<'hir> { /// Given a `HirId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. - pub fn maybe_body_owned_by_by_hir_id(&self, hir_id: HirId) -> Option { + pub fn maybe_body_owned_by(&self, hir_id: HirId) -> Option { if let Some(entry) = self.find_entry(hir_id) { if self.dep_graph.is_fully_enabled() { let hir_id_owner = hir_id.owner; @@ -451,13 +451,13 @@ impl<'hir> Map<'hir> { /// Given a body owner's id, returns the `BodyId` associated with it. pub fn body_owned_by(&self, id: HirId) -> BodyId { - self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| { - span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body", + self.maybe_body_owned_by(id).unwrap_or_else(|| { + span_bug!(self.span(id), "body_owned_by: {} has no associated body", self.hir_to_string(id)); }) } - pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind { + pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { match self.get_by_hir_id(id) { Node::Item(&Item { node: ItemKind::Const(..), .. }) | Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) | @@ -548,7 +548,7 @@ impl<'hir> Map<'hir> { let module = &self.forest.krate.modules[&node_id]; for id in &module.items { - visitor.visit_item(self.expect_item_by_hir_id(*id)); + visitor.visit_item(self.expect_item(*id)); } for id in &module.trait_items { @@ -784,7 +784,7 @@ impl<'hir> Map<'hir> { /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. - pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId { + pub fn get_module_parent(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_module_parent_node(id)) } @@ -860,11 +860,11 @@ impl<'hir> Map<'hir> { Some(scope) } - pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId { + pub fn get_parent_did(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_parent_item(id)) } - pub fn get_foreign_abi_by_hir_id(&self, hir_id: HirId) -> Abi { + pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi { let parent = self.get_parent_item(hir_id); if let Some(entry) = self.find_entry(parent) { if let Entry { @@ -877,7 +877,7 @@ impl<'hir> Map<'hir> { bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) } - pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { + pub fn expect_item(&self, id: HirId) -> &'hir Item { match self.find_by_hir_id(id) { // read recorded by `find` Some(Node::Item(item)) => item, _ => bug!("expected item, found {}", self.hir_to_string(id)) @@ -965,7 +965,7 @@ impl<'hir> Map<'hir> { /// Given a node ID, gets a list of attributes associated with the AST /// corresponding to the node-ID. - pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] { + pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] { self.read(id); // reveals attributes on the node let attrs = match self.find_entry(id).map(|entry| entry.node) { Some(Node::Local(l)) => Some(&l.attrs[..]), @@ -981,7 +981,7 @@ impl<'hir> Map<'hir> { Some(Node::GenericParam(param)) => Some(¶m.attrs[..]), // Unit/tuple structs/variants take the attributes straight from // the struct/variant definition. - Some(Node::Ctor(..)) => return self.attrs_by_hir_id(self.get_parent_item(id)), + Some(Node::Ctor(..)) => return self.attrs(self.get_parent_item(id)), Some(Node::Crate) => Some(&self.forest.krate.attrs[..]), _ => None }; @@ -1028,7 +1028,7 @@ impl<'hir> Map<'hir> { }) } - pub fn span_by_hir_id(&self, hir_id: HirId) -> Span { + pub fn span(&self, hir_id: HirId) -> Span { self.read(hir_id); // reveals span from node match self.find_entry(hir_id).map(|entry| entry.node) { Some(Node::Item(item)) => item.span, @@ -1068,7 +1068,7 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - self.as_local_hir_id(id).map(|id| self.span_by_hir_id(id)) + self.as_local_hir_id(id).map(|id| self.span(id)) } pub fn hir_to_string(&self, id: HirId) -> String { @@ -1221,7 +1221,7 @@ pub fn map_crate<'hir>(sess: &crate::session::Session, impl<'hir> print::PpAnn for Map<'hir> { fn nested(&self, state: &mut print::State<'_>, nested: print::Nested) -> io::Result<()> { match nested { - Nested::Item(id) => state.print_item(self.expect_item_by_hir_id(id.id)), + Nested::Item(id) => state.print_item(self.expect_item(id.id)), Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)), Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)), Nested::Body(id) => state.print_expr(&self.body(id).value), diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index 662bde43c569..54b4435573ba 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -15,7 +15,7 @@ pub fn provide(providers: &mut Providers<'_>) { } let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let body = tcx.hir().body(tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)?); + let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(hir_id)?); let mut local_collector = LocalCollector::default(); local_collector.visit_body(body); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 73bd37d53fe2..321c06897de1 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -191,7 +191,7 @@ impl<'tcx> TyCtxt<'tcx> { }; let (prefix, span) = match *region { ty::ReEarlyBound(ref br) => { - let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); + let mut sp = cm.def_span(self.hir().span(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(br.name)) @@ -204,7 +204,7 @@ impl<'tcx> TyCtxt<'tcx> { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => { - let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); + let mut sp = cm.def_span(self.hir().span(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(name)) @@ -216,11 +216,11 @@ impl<'tcx> TyCtxt<'tcx> { ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => ( format!("the anonymous lifetime #{} defined on", idx + 1), - self.hir().span_by_hir_id(node), + self.hir().span(node), ), _ => ( format!("the lifetime {} as defined on", region), - cm.def_span(self.hir().span_by_hir_id(node)), + cm.def_span(self.hir().span(node)), ), }, _ => bug!(), @@ -1338,7 +1338,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) { has_bounds = !param.bounds.is_empty(); } - let sp = hir.span_by_hir_id(id); + let sp = hir.span(id); // `sp` only covers `T`, change it so that it covers // `T:` when appropriate let is_impl_trait = bound_kind.to_string().starts_with("impl "); diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 061d74416c57..f33f91739265 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -52,7 +52,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let hir = &self.tcx().hir(); if let Some(hir_id) = hir.as_local_hir_id(id) { - if let Some(body_id) = hir.maybe_body_owned_by_by_hir_id(hir_id) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id) { let body = hir.body(body_id); let owner_id = hir.body_owner(body_id); let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); @@ -63,7 +63,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { .filter_map(|(index, arg)| { // May return None; sometimes the tables are not yet populated. let ty_hir_id = fn_decl.inputs[index].hir_id; - let arg_ty_span = hir.span_by_hir_id(ty_hir_id); + let arg_ty_span = hir.span(ty_hir_id); let ty = tables.node_type_opt(arg.hir_id)?; let mut found_anon_region = false; let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 468d909e5497..e90f4ca94c62 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1399,7 +1399,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( // Visit the crate attributes if hir_id == hir::CRATE_HIR_ID { - walk_list!(cx, visit_attribute, tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID)); + walk_list!(cx, visit_attribute, tcx.hir().attrs(hir::CRATE_HIR_ID)); } } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 70c0e83517af..041944d887bd 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -762,7 +762,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session, } pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool { - let attrs = tcx.hir().attrs_by_hir_id(id); + let attrs = tcx.hir().attrs(id); attrs.iter().any(|attr| Level::from_symbol(attr.name_or_empty()).is_some()) } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0356e7e10724..63503f58156b 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -292,7 +292,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { fn visit_ty(&mut self, ty: &'tcx hir::Ty) { match ty.node { TyKind::Def(item_id, _) => { - let item = self.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = self.tcx.hir().expect_item(item_id.id); intravisit::walk_item(self, item); } _ => () diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 29c624575c3c..3d2bc6c7bf88 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1171,7 +1171,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::Call(ref f, ref args) => { - let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id); + let m = self.ir.tcx.hir().get_module_parent(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { @@ -1182,7 +1182,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::MethodCall(.., ref args) => { - let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id); + let m = self.ir.tcx.hir().get_module_parent(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index cf304ebf3cbf..a856430e68a2 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -358,7 +358,7 @@ impl MutabilityCategory { } _ => span_bug!(p.span, "expected identifier pattern") }, - _ => span_bug!(tcx.hir().span_by_hir_id(id), "expected identifier pattern") + _ => span_bug!(tcx.hir().span(id), "expected identifier pattern") }; debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}", "from_local", id, ret); diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 363ccd74c08d..2285beb37585 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -174,12 +174,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } else { let impl_did = self.tcx .hir() - .get_parent_did_by_hir_id(hir_id); + .get_parent_did(hir_id); // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap(); - match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node { + match self.tcx.hir().expect_item(impl_hir_id).node { hir::ItemKind::Impl(..) => { let generics = self.tcx.generics_of(impl_did); generics.requires_monomorphization(self.tcx) @@ -296,7 +296,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { self.visit_nested_body(body); } hir::ImplItemKind::Method(_, body) => { - let did = self.tcx.hir().get_parent_did_by_hir_id(search_item); + let did = self.tcx.hir().get_parent_did(search_item); if method_might_be_inlined(self.tcx, impl_item, did) { self.visit_nested_body(body) } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 708bd6f735d8..dfab8e36bf9d 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -188,7 +188,7 @@ impl Scope { if hir_id == hir::DUMMY_HIR_ID { return DUMMY_SP; } - let span = tcx.hir().span_by_hir_id(hir_id); + let span = tcx.hir().span(hir_id); if let ScopeData::Remainder(first_statement_index) = self.data { if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) { // Want span for scope starting after the @@ -649,7 +649,7 @@ impl<'tcx> ScopeTree { let param_owner = tcx.parent(br.def_id).unwrap(); let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap(); - let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| { + let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| { tcx.hir().body(body_id).value.hir_id.local_id }).unwrap_or_else(|| { // The lifetime was defined on node that doesn't own a body, @@ -1277,7 +1277,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // The body of the every fn is a root scope. self.cx.parent = self.cx.var_parent; - if self.tcx.hir().body_owner_kind_by_hir_id(owner_id).is_fn_or_closure() { + if self.tcx.hir().body_owner_kind(owner_id).is_fn_or_closure() { self.visit_expr(&body.value) } else { // Only functions have an outer terminating (drop) scope, while @@ -1336,7 +1336,7 @@ fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ScopeTree } let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by_by_hir_id(id) { + let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) { let mut visitor = RegionResolutionVisitor { tcx, scope_tree: ScopeTree::default(), diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index b350f15664d4..6f2c4b66f5ec 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -625,7 +625,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { // `abstract type MyAnonTy<'b>: MyTrait<'b>;` // ^ ^ this gets resolved in the scope of // the exist_ty generics - let (generics, bounds) = match self.tcx.hir().expect_item_by_hir_id(item_id.id).node + let (generics, bounds) = match self.tcx.hir().expect_item(item_id.id).node { // named existential types are reached via TyKind::Path // this arm is for `impl Trait` in the types of statics, constants and locals @@ -1236,7 +1236,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { signal_shadowing_problem( tcx, label.name, - original_lifetime(tcx.hir().span_by_hir_id(hir_id)), + original_lifetime(tcx.hir().span(hir_id)), shadower_label(label.span), ); return; @@ -1590,7 +1590,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let Some(parent_hir_id) = self.tcx.hir() .as_local_hir_id(parent_def_id) { // lifetimes in `derive` expansions don't count (Issue #53738) - if self.tcx.hir().attrs_by_hir_id(parent_hir_id).iter() + if self.tcx.hir().attrs(parent_hir_id).iter() .any(|attr| attr.check_name(sym::automatically_derived)) { continue; } @@ -1690,7 +1690,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // Find the start of nested early scopes, e.g., in methods. let mut index = 0; if let Some(parent_id) = parent_id { - let parent = self.tcx.hir().expect_item_by_hir_id(parent_id); + let parent = self.tcx.hir().expect_item(parent_id); if sub_items_have_self_param(&parent.node) { index += 1; // Self comes before lifetimes } @@ -2065,7 +2065,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx .hir() - .expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent)) + .expect_item(self.tcx.hir().get_parent_item(parent)) .node { assoc_item_kind = trait_items @@ -2085,7 +2085,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx .hir() - .expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent)) + .expect_item(self.tcx.hir().get_parent_item(parent)) .node { impl_self = Some(self_ty); @@ -2629,7 +2629,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { signal_shadowing_problem( self.tcx, param.name.ident().name, - original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)), + original_lifetime(self.tcx.hir().span(hir_id)), shadower_lifetime(¶m), ); return; diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 3d96acbe7be9..1d5c1cb927d2 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2565,7 +2565,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { let name = if tcx.sess.opts.debugging_opts.span_free_formats { format!("[closure@{:?}]", hir_id) } else { - format!("[closure@{:?}]", tcx.hir().span_by_hir_id(hir_id)) + format!("[closure@{:?}]", tcx.hir().span(hir_id)) }; let mut struct_fmt = fmt.debug_struct(&name); @@ -2585,7 +2585,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { let name = format!("[generator@{:?}]", - tcx.hir().span_by_hir_id(hir_id)); + tcx.hir().span(hir_id)); let mut struct_fmt = fmt.debug_struct(&name); if let Some(upvars) = tcx.upvars(def_id) { diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 39ae48b303ab..432a61de6cb9 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -218,7 +218,7 @@ impl<'tcx> MonoItem<'tcx> { MonoItem::GlobalAsm(hir_id) => { Some(hir_id) } - }.map(|hir_id| tcx.hir().span_by_hir_id(hir_id)) + }.map(|hir_id| tcx.hir().span(hir_id)) } } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index f886794be628..dcf69fee0e16 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1096,7 +1096,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } Node::Ctor(ref variant_data) => { let span = variant_data.ctor_hir_id() - .map(|hir_id| self.tcx.hir().span_by_hir_id(hir_id)) + .map(|hir_id| self.tcx.hir().span(hir_id)) .unwrap_or(DUMMY_SP); let span = self.tcx.sess.source_map().def_span(span); diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index b6a1ab9fe709..2d295679be32 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -654,7 +654,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn impl_is_default(self, node_item_def_id: DefId) -> bool { match self.hir().as_local_hir_id(node_item_def_id) { Some(hir_id) => { - let item = self.hir().expect_item_by_hir_id(hir_id); + let item = self.hir().expect_item(hir_id); if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node { defaultness.is_default() } else { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index c932586c078b..361410380e8f 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -277,7 +277,7 @@ impl Visibility { def => Visibility::Restricted(def.def_id()), }, hir::VisibilityKind::Inherited => { - Visibility::Restricted(tcx.hir().get_module_parent_by_hir_id(id)) + Visibility::Restricted(tcx.hir().get_module_parent(id)) } } } @@ -3016,7 +3016,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Gets the attributes of a definition. pub fn get_attrs(self, did: DefId) -> Attributes<'tcx> { if let Some(id) = self.hir().as_local_hir_id(did) { - Attributes::Borrowed(self.hir().attrs_by_hir_id(id)) + Attributes::Borrowed(self.hir().attrs(id)) } else { Attributes::Owned(self.item_attrs(did)) } @@ -3068,7 +3068,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn span_of_impl(self, impl_did: DefId) -> Result { if impl_did.is_local() { let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); - Ok(self.hir().span_by_hir_id(hir_id)) + Ok(self.hir().span(hir_id)) } else { Err(self.crate_name(impl_did.krate)) } @@ -3103,7 +3103,7 @@ impl<'tcx> TyCtxt<'tcx> { let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) { Some(actual_expansion) => self.hir().definitions().parent_module_of_macro_def(actual_expansion), - None => self.hir().get_module_parent_by_hir_id(block), + None => self.hir().get_module_parent(block), }; (ident, scope) } @@ -3129,7 +3129,7 @@ fn associated_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AssocItem { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let parent_id = tcx.hir().get_parent_item(id); let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id); - let parent_item = tcx.hir().expect_item_by_hir_id(parent_id); + let parent_item = tcx.hir().expect_item(parent_id); match parent_item.node { hir::ItemKind::Impl(.., ref impl_item_refs) => { if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.hir_id == id) { @@ -3186,7 +3186,7 @@ fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AdtSizedConst fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [DefId] { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(id); + let item = tcx.hir().expect_item(id); match item.node { hir::ItemKind::Trait(.., ref trait_item_refs) => { tcx.arena.alloc_from_iter( @@ -3266,7 +3266,7 @@ fn param_env<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ParamEnv<'tcx> { ); let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| { - tcx.hir().maybe_body_owned_by_by_hir_id(id).map_or(id, |body| body.hir_id) + tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id) }); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index b79d7f06cd6a..d143cc3e6092 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -589,7 +589,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) { - p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id))); + p!(write("@{:?}", self.tcx().hir().span(hir_id))); let mut sep = " "; for (&var_id, upvar_ty) in self.tcx().upvars(did) .as_ref() @@ -631,7 +631,7 @@ pub trait PrettyPrinter<'tcx>: if self.tcx().sess.opts.debugging_opts.span_free_formats { p!(write("@{:?}", hir_id)); } else { - p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id))); + p!(write("@{:?}", self.tcx().hir().span(hir_id))); } let mut sep = " "; for (&var_id, upvar_ty) in self.tcx().upvars(did) diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index 9a00c43be3fb..58be2cf76c72 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -88,7 +88,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr } } if let NoteClosureEnv(upvar_id) = error.move_from.note { - err.span_label(bccx.tcx.hir().span_by_hir_id(upvar_id.var_path.hir_id), + err.span_label(bccx.tcx.hir().span(upvar_id.var_path.hir_id), "captured outer variable"); } err.emit(); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 9429fde27908..cc9c83de179c 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -699,7 +699,7 @@ impl BorrowckCtxt<'_, 'tcx> { } move_data::MoveExpr | - move_data::MovePat => (self.tcx.hir().span_by_hir_id(hir_id), ""), + move_data::MovePat => (self.tcx.hir().span(hir_id), ""), move_data::Captured => (match self.tcx.hir().expect_expr_by_hir_id(hir_id).node { @@ -828,7 +828,7 @@ impl BorrowckCtxt<'_, 'tcx> { let mut db = self.cannot_assign(error_span, &descr, Origin::Ast); if let mc::NoteClosureEnv(upvar_id) = err.cmt.note { let hir_id = upvar_id.var_path.hir_id; - let sp = self.tcx.hir().span_by_hir_id(hir_id); + let sp = self.tcx.hir().span(hir_id); let fn_closure_msg = "`Fn` closures cannot capture their enclosing \ environment for modifications"; match (self.tcx.sess.source_map().span_to_snippet(sp), &err.cmt.cat) { @@ -1117,7 +1117,7 @@ impl BorrowckCtxt<'_, 'tcx> { "consider changing this closure to take self by mutable reference" }; let hir_id = self.tcx.hir().local_def_id_to_hir_id(id); - let help_span = self.tcx.hir().span_by_hir_id(hir_id); + let help_span = self.tcx.hir().span(hir_id); self.cannot_act_on_capture_in_sharable_fn(span, prefix, (help_span, help_msg), @@ -1223,7 +1223,7 @@ impl BorrowckCtxt<'_, 'tcx> { Some(ImmutabilityBlame::LocalDeref(hir_id)) => { match self.local_binding_mode(hir_id) { ty::BindByReference(..) => { - let let_span = self.tcx.hir().span_by_hir_id(hir_id); + let let_span = self.tcx.hir().span(hir_id); let suggestion = suggest_ref_mut(self.tcx, let_span); if let Some(replace_str) = suggestion { db.span_suggestion( @@ -1271,7 +1271,7 @@ impl BorrowckCtxt<'_, 'tcx> { db: &mut DiagnosticBuilder<'_>, borrowed_hir_id: hir::HirId, binding_hir_id: hir::HirId) { - let let_span = self.tcx.hir().span_by_hir_id(binding_hir_id); + let let_span = self.tcx.hir().span(binding_hir_id); if let ty::BindByValue(..) = self.local_binding_mode(binding_hir_id) { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(let_span) { let (ty, is_implicit_self) = self.local_ty(binding_hir_id); @@ -1289,7 +1289,7 @@ impl BorrowckCtxt<'_, 'tcx> { { let borrow_expr_id = self.tcx.hir().get_parent_node_by_hir_id(borrowed_hir_id); db.span_suggestion( - self.tcx.hir().span_by_hir_id(borrow_expr_id), + self.tcx.hir().span(borrow_expr_id), "consider removing the `&mut`, as it is an \ immutable binding to a mutable reference", snippet, @@ -1360,7 +1360,7 @@ impl BorrowckCtxt<'_, 'tcx> { if *kind == ty::ClosureKind::Fn { let closure_hir_id = self.tcx.hir().local_def_id_to_hir_id(upvar_id.closure_expr_id); - db.span_help(self.tcx.hir().span_by_hir_id(closure_hir_id), + db.span_help(self.tcx.hir().span(closure_hir_id), "consider changing this closure to take \ self by mutable reference"); } @@ -1369,7 +1369,7 @@ impl BorrowckCtxt<'_, 'tcx> { if let Categorization::Deref(..) = err.cmt.cat { db.span_label(*error_span, "cannot borrow as mutable"); } else if let Categorization::Local(local_id) = err.cmt.cat { - let span = self.tcx.hir().span_by_hir_id(local_id); + let span = self.tcx.hir().span(local_id); if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { if snippet.starts_with("ref mut ") || snippet.starts_with("&mut ") { db.span_label(*error_span, "cannot reborrow mutably"); diff --git a/src/librustc_codegen_ssa/mono_item.rs b/src/librustc_codegen_ssa/mono_item.rs index 11e9a48133d9..dc50c0e19efb 100644 --- a/src/librustc_codegen_ssa/mono_item.rs +++ b/src/librustc_codegen_ssa/mono_item.rs @@ -29,7 +29,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id)); } MonoItem::GlobalAsm(hir_id) => { - let item = cx.tcx().hir().expect_item_by_hir_id(hir_id); + let item = cx.tcx().hir().expect_item(hir_id); if let hir::ItemKind::GlobalAsm(ref ga) = item.node { cx.codegen_global_asm(ga); } else { diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index ef416dbe62b8..683da5865cda 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -923,7 +923,7 @@ fn print_with_analysis<'tcx>( node); let hir_id = tcx.hir().node_to_hir_id(nodeid); - tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &message) + tcx.sess.span_fatal(tcx.hir().span(hir_id), &message) } } } diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 903a2d680123..b221b8ed30c5 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -254,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name { Some(Ident::from_str(name)) } else { - attr::find_by_name(&cx.tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID), sym::crate_name) + attr::find_by_name(&cx.tcx.hir().attrs(hir::CRATE_HIR_ID), sym::crate_name) .and_then(|attr| attr.meta()) .and_then(|meta| { meta.name_value_literal().and_then(|lit| { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index a843ee6d45d8..9fc23e45d203 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -921,7 +921,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) { let mut vis = ImproperCTypesVisitor { cx }; - let abi = cx.tcx.hir().get_foreign_abi_by_hir_id(it.hir_id); + let abi = cx.tcx.hir().get_foreign_abi(it.hir_id); if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic { match it.node { hir::ForeignItemKind::Fn(ref decl, _, _) => { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index d540b3f7e40a..f84ce2f015ed 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -136,7 +136,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { descr_post_path: &str, ) -> bool { if ty.is_unit() || cx.tcx.is_ty_uninhabited_from( - cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty) + cx.tcx.hir().get_module_parent(expr.hir_id), ty) { return true; } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index dbf140afda24..b52b6dfbb5e1 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -579,7 +579,7 @@ impl EncodeContext<'tcx> { }; let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap(); - let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis; + let enum_vis = &tcx.hir().expect_item(enum_id).vis; Entry { kind: EntryKind::Variant(self.lazy(&data)), @@ -632,7 +632,7 @@ impl EncodeContext<'tcx> { // Variant constructors have the same visibility as the parent enums, unless marked as // non-exhaustive, in which case they are lowered to `pub(crate)`. let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap(); - let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis; + let enum_vis = &tcx.hir().expect_item(enum_id).vis; let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx); if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); @@ -751,7 +751,7 @@ impl EncodeContext<'tcx> { }; let struct_id = tcx.hir().as_local_hir_id(adt_def_id).unwrap(); - let struct_vis = &tcx.hir().expect_item_by_hir_id(struct_id).vis; + let struct_vis = &tcx.hir().expect_item(struct_id).vis; let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx); for field in &variant.fields { if ctor_vis.is_at_least(field.vis, tcx) { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 9c2ab91fe2f8..c4a11efe5bce 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -177,7 +177,7 @@ fn do_mir_borrowck<'a, 'tcx>( |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), )); - let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure(); + let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure(); let borrow_set = Rc::new(BorrowSet::build( tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data)); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 402654c44ac1..d15229367251 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -422,7 +422,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let upvar = &self.upvars[upvar_field.unwrap().index()]; let upvar_hir_id = upvar.var_hir_id; let upvar_name = upvar.name; - let upvar_span = self.infcx.tcx.hir().span_by_hir_id(upvar_hir_id); + let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id); let place_name = self.describe_place(move_place).unwrap(); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 61a13df47ffe..46b690129ea2 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -310,7 +310,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let scope = error_region.free_region_binding_scope(tcx); let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); - let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(node)); + let span = tcx.sess.source_map().def_span(tcx.hir().span(node)); if let Some(param) = tcx.hir() .get_generics(scope) .and_then(|generics| generics.get_named(name)) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index 6ce925cc7d12..59fc4113794a 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -73,7 +73,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id); let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id); - let upvar_span = tcx.hir().span_by_hir_id(upvar_hir_id); + let upvar_span = tcx.hir().span(upvar_hir_id); debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}", upvar_name, upvar_span); diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index df0110ed3e39..a236359f1d43 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -471,7 +471,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let tcx = self.infcx.tcx; let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); - match tcx.hir().body_owner_kind_by_hir_id(self.mir_hir_id) { + match tcx.hir().body_owner_kind(self.mir_hir_id) { BodyOwnerKind::Closure | BodyOwnerKind::Fn => { let defining_ty = if self.mir_def_id == closure_base_def_id { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 280592e2b016..a0e45caeb6b3 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -55,10 +55,10 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { (*body_id, ty.span) } Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => { - (*body, tcx.hir().span_by_hir_id(*hir_id)) + (*body, tcx.hir().span(*hir_id)) } - _ => span_bug!(tcx.hir().span_by_hir_id(id), "can't build MIR for {:?}", def_id), + _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), }; tcx.infer_ctxt().enter(|infcx| { @@ -103,7 +103,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { let self_arg; if let Some(ref fn_decl) = tcx.hir().fn_decl_by_hir_id(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; - let ty_span = tcx.hir().span_by_hir_id(ty_hir_id); + let ty_span = tcx.hir().span(ty_hir_id); opt_ty_info = Some(ty_span); self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { match fn_decl.implicit_self { @@ -131,7 +131,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { ty::Generator(gen_def_id, gen_substs, ..) => gen_substs.sig(gen_def_id, tcx), _ => - span_bug!(tcx.hir().span_by_hir_id(id), + span_bug!(tcx.hir().span(id), "generator w/o generator type: {:?}", ty), }; (Some(gen_sig.yield_ty), gen_sig.return_ty) @@ -535,7 +535,7 @@ where let tcx = hir.tcx(); let tcx_hir = tcx.hir(); - let span = tcx_hir.span_by_hir_id(fn_id); + let span = tcx_hir.span(fn_id); let hir_tables = hir.tables(); let fn_def_id = tcx_hir.local_def_id_from_hir_id(fn_id); @@ -650,7 +650,7 @@ fn construct_const<'a, 'tcx>( ) -> Body<'tcx> { let tcx = hir.tcx(); let owner_id = tcx.hir().body_owner(body_id); - let span = tcx.hir().span_by_hir_id(owner_id); + let span = tcx.hir().span(owner_id); let mut builder = Builder::new( hir, span, @@ -689,7 +689,7 @@ fn construct_error<'a, 'tcx>( body_id: hir::BodyId ) -> Body<'tcx> { let owner_id = hir.tcx().hir().body_owner(body_id); - let span = hir.tcx().hir().span_by_hir_id(owner_id); + let span = hir.tcx().hir().span(owner_id); let ty = hir.tcx().types.err; let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![], false); let source_info = builder.source_info(span); diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 63239a36a175..d5932052d1aa 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -49,7 +49,7 @@ fn mirror_stmts<'a, 'tcx>( for (index, stmt) in stmts.iter().enumerate() { let hir_id = stmt.hir_id; let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id); - let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id)); + let stmt_span = StatementSpan(cx.tcx.hir().span(hir_id)); match stmt.node { hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => { diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index b6feac392f48..ff53cf02d8d1 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { let tcx = infcx.tcx; let src_def_id = tcx.hir().local_def_id_from_hir_id(src_id); let tables = tcx.typeck_tables_of(src_def_id); - let body_owner_kind = tcx.hir().body_owner_kind_by_hir_id(src_id); + let body_owner_kind = tcx.hir().body_owner_kind(src_id); let constness = match body_owner_kind { hir::BodyOwnerKind::Const | @@ -65,7 +65,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { hir::BodyOwnerKind::Fn => hir::Constness::NotConst, }; - let attrs = tcx.hir().attrs_by_hir_id(src_id); + let attrs = tcx.hir().attrs(src_id); // Some functions always have overflow checks enabled, // however, they may not get codegen'd, depending on diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index e7fd308070c9..159b526bdba6 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -161,7 +161,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } } - let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id); + let module = self.tcx.hir().get_module_parent(scrut.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut have_errors = false; @@ -193,7 +193,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { // Then, if the match has no arms, check whether the scrutinee // is uninhabited. let pat_ty = self.tables.node_type(scrut.hir_id); - let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id); + let module = self.tcx.hir().get_module_parent(scrut.hir_id); let mut def_span = None; let mut missing_variants = vec![]; if inlined_arms.is_empty() { @@ -261,7 +261,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) { - let module = self.tcx.hir().get_module_parent_by_hir_id(pat.hir_id); + let module = self.tcx.hir().get_module_parent(pat.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut patcx = PatternContext::new(self.tcx, self.param_env.and(self.identity_substs), diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 55151a9b33eb..a7120888742d 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -130,7 +130,7 @@ fn check_fn_for_unconditional_recursion( // recurs. if !reached_exit_without_self_call && !self_call_locations.is_empty() { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let sp = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(hir_id)); + let sp = tcx.sess.source_map().def_span(tcx.hir().span(hir_id)); let mut db = tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index e530c56ed6f3..2e74ebcf061e 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -455,7 +455,7 @@ fn check_recursion_limit<'tcx>( let error = format!("reached the recursion limit while instantiating `{}`", instance); if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { - tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &error); + tcx.sess.span_fatal(tcx.hir().span(hir_id), &error); } else { tcx.sess.fatal(&error); } diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 595e599c1150..2bcf058ad7c3 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -193,7 +193,7 @@ pub trait MonoItemExt<'tcx>: fmt::Debug { MonoItem::GlobalAsm(hir_id) => { Some(hir_id) } - }.map(|hir_id| tcx.hir().span_by_hir_id(hir_id)) + }.map(|hir_id| tcx.hir().span(hir_id)) } } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 80a31efd0d3f..32153f7bcd9c 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -488,7 +488,7 @@ fn check_unused_unsafe<'a, 'tcx>( ) { let body_id = tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| { - tcx.hir().maybe_body_owned_by_by_hir_id(hir_id) + tcx.hir().maybe_body_owned_by(hir_id) }); let body_id = match body_id { @@ -527,7 +527,7 @@ fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> UnsafetyChec let param_env = tcx.param_env(def_id); let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let (const_context, min_const_fn) = match tcx.hir().body_owner_kind_by_hir_id(id) { + let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Fn => (tcx.is_const_fn(def_id), tcx.is_min_const_fn(def_id)), hir::BodyOwnerKind::Const | @@ -591,12 +591,12 @@ fn is_enclosed( } fn report_unused_unsafe(tcx: TyCtxt<'_>, used_unsafe: &FxHashSet, id: hir::HirId) { - let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)); + let span = tcx.sess.source_map().def_span(tcx.hir().span(id)); let msg = "unnecessary `unsafe` block"; let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg); db.span_label(span, msg); if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) { - db.span_label(tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)), + db.span_label(tcx.sess.source_map().def_span(tcx.hir().span(id)), format!("because it's nested under this `unsafe` {}", kind)); } db.emit(); diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index f8e3fc2138d1..5e6f1bc15f02 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -70,7 +70,7 @@ impl Inliner<'tcx> { // Only do inlining into fn bodies. let id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap(); - if self.tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure() + if self.tcx.hir().body_owner_kind(id).is_fn_or_closure() && self.source.promoted.is_none() { for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated() { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 04dce326e69d..79bb2cfe08db 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -208,7 +208,7 @@ fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> fn mir_validated(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(hir_id) { + if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind(hir_id) { // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. let _ = tcx.mir_const_qualif(def_id); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 8a8cc5080a85..b6abfdb7425a 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1503,7 +1503,7 @@ impl MirPass for QualifyAndPromoteConstants { let def_id = src.def_id(); let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let mut const_promoted_temps = None; - let mode = match tcx.hir().body_owner_kind_by_hir_id(id) { + let mode = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => Mode::NonConstFn, hir::BodyOwnerKind::Fn => { if tcx.is_const_fn(def_id) { diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 3adee156eb17..5397a4af8fa8 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -175,7 +175,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { self.in_fn = false; self.in_static = false; - match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { + match self.tcx.hir().body_owner_kind(item_id) { hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => self.in_fn = true, hir::BodyOwnerKind::Static(_) => self.in_static = true, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index c2cb2f4d1745..9eaa6f920f08 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -233,7 +233,7 @@ fn def_id_visibility<'tcx>( Node::Item(item) => &item.vis, Node::ForeignItem(foreign_item) => &foreign_item.vis, Node::TraitItem(..) | Node::Variant(..) => { - return def_id_visibility(tcx, tcx.hir().get_parent_did_by_hir_id(hir_id)); + return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id)); } Node::ImplItem(impl_item) => { match tcx.hir().get_by_hir_id(tcx.hir().get_parent_item(hir_id)) { @@ -255,7 +255,7 @@ fn def_id_visibility<'tcx>( tcx, parent_did, ); - let adt_def = tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id)); + let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id)); let ctor_did = tcx.hir().local_def_id_from_hir_id( vdata.ctor_hir_id().unwrap()); let variant = adt_def.variant_with_ctor_id(ctor_did); @@ -294,7 +294,7 @@ fn def_id_visibility<'tcx>( // visibility to within the crate. if ctor_vis == ty::Visibility::Public { let adt_def = - tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id)); + tcx.adt_def(tcx.hir().get_parent_did(hir_id)); if adt_def.non_enum_variant().is_field_list_non_exhaustive() { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); @@ -311,7 +311,7 @@ fn def_id_visibility<'tcx>( } Node::Expr(expr) => { return (ty::Visibility::Restricted( - tcx.hir().get_module_parent_by_hir_id(expr.hir_id)), + tcx.hir().get_module_parent(expr.hir_id)), expr.span, "private") } node => bug!("unexpected node kind: {:?}", node) @@ -501,11 +501,11 @@ impl EmbargoVisitor<'tcx> { if let Some(item) = module.res .and_then(|res| res.mod_def_id()) .and_then(|def_id| self.tcx.hir().as_local_hir_id(def_id)) - .map(|module_hir_id| self.tcx.hir().expect_item_by_hir_id(module_hir_id)) + .map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id)) { if let hir::ItemKind::Mod(m) = &item.node { for item_id in m.item_ids.as_ref() { - let item = self.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = self.tcx.hir().expect_item(item_id.id); let def_id = self.tcx.hir().local_def_id_from_hir_id(item_id.id); if !self.tcx.hygienic_eq(segment.ident, item.ident, def_id) { continue; } if let hir::ItemKind::Use(..) = item.node { @@ -764,7 +764,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { let module = if module_id == hir::CRATE_HIR_ID { &self.tcx.hir().krate().module } else if let hir::ItemKind::Mod(ref module) = - self.tcx.hir().expect_item_by_hir_id(module_id).node { + self.tcx.hir().expect_item(module_id).node { module } else { unreachable!() @@ -1690,7 +1690,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { tcx: self.tcx, item_id, item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id), - span: self.tcx.hir().span_by_hir_id(item_id), + span: self.tcx.hir().span(item_id), required_visibility, has_pub_restricted: self.has_pub_restricted, has_old_errors, diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 0207f18ac81d..42c7ff607c55 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -354,7 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let def_span = match def { Res::Err => None, Res::Local(id) => { - Some(self.tcx.hir().span_by_hir_id(id)) + Some(self.tcx.hir().span(id)) }, _ => def .opt_def_id() diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 088ac0e8ba6c..946082746f46 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -813,7 +813,7 @@ fn compare_synthetic_generics<'tcx>( { if impl_synthetic != trait_synthetic { let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); - let impl_span = tcx.hir().span_by_hir_id(impl_hir_id); + let impl_span = tcx.hir().span(impl_hir_id); let trait_span = tcx.def_span(trait_def_id); let mut err = struct_span_err!(tcx.sess, impl_span, diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 2003782e7adc..a2621abf44d8 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -213,7 +213,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // repeated `contains` calls. if !assumptions_in_impl_context.contains(&predicate) { - let item_span = tcx.hir().span_by_hir_id(self_type_hir_id); + let item_span = tcx.hir().span(self_type_hir_id); struct_span_err!( tcx.sess, drop_impl_span, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 71bcf2bc0563..29b4fee138e8 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -264,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // local binding if let &QPath::Resolved(_, ref path) = &qpath { if let hir::def::Res::Local(hir_id) = path.res { - let span = tcx.hir().span_by_hir_id(hir_id); + let span = tcx.hir().span(hir_id); let snippet = tcx.sess.source_map().span_to_snippet(span); let filename = tcx.sess.source_map().span_to_filename(span); @@ -370,7 +370,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }); if let Some((field, field_ty)) = field_receiver { - let scope = self.tcx.hir().get_module_parent_by_hir_id(self.body_id); + let scope = self.tcx.hir().get_module_parent(self.body_id); let is_accessible = field.vis.is_accessible_from(scope, self.tcx); if is_accessible { @@ -564,7 +564,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'_>, mut msg: String, candidates: Vec) { - let module_did = self.tcx.hir().get_module_parent_by_hir_id(self.body_id); + let module_did = self.tcx.hir().get_module_parent(self.body_id); let module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap(); let krate = self.tcx.hir().krate(); let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id); @@ -897,7 +897,7 @@ impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> { } // Find a `use` statement. for item_id in &module.item_ids { - let item = self.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = self.tcx.hir().expect_item(item_id.id); match item.node { hir::ItemKind::Use(..) => { // Don't suggest placing a `use` before the prelude diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c4a834dd600a..d4dbb68778ed 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -622,7 +622,7 @@ impl Inherited<'a, 'tcx> { fn new(infcx: InferCtxt<'a, 'tcx>, def_id: DefId) -> Self { let tcx = infcx.tcx; let item_id = tcx.hir().as_local_hir_id(def_id); - let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by_by_hir_id(id)); + let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by(id)); let implicit_region_bound = body_id.map(|body_id| { let body = tcx.hir().body(body_id); tcx.mk_region(ty::ReScope(region::Scope { @@ -821,7 +821,7 @@ fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::TypeckT } let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let span = tcx.hir().span_by_hir_id(id); + let span = tcx.hir().span(id); // Figure out what primary body this item has. let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| { @@ -1193,7 +1193,7 @@ fn check_fn<'a, 'tcx>( } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span_by_hir_id(fn_id); + let span = fcx.tcx.hir().span(fn_id); if inputs.len() == 1 { let arg_is_panic_info = match inputs[0].sty { ty::Ref(region, ty, mutbl) => match ty.sty { @@ -1246,7 +1246,7 @@ fn check_fn<'a, 'tcx>( } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span_by_hir_id(fn_id); + let span = fcx.tcx.hir().span(fn_id); if inputs.len() == 1 { let arg_is_alloc_layout = match inputs[0].sty { ty::Adt(ref adt, _) => { @@ -1909,11 +1909,11 @@ pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant], i let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap(); let variant_i = tcx.hir().expect_variant(variant_i_hir_id); let i_span = match variant_i.node.disr_expr { - Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), - None => tcx.hir().span_by_hir_id(variant_i_hir_id) + Some(ref expr) => tcx.hir().span(expr.hir_id), + None => tcx.hir().span(variant_i_hir_id) }; let span = match v.node.disr_expr { - Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), + Some(ref expr) => tcx.hir().span(expr.hir_id), None => v.span }; struct_span_err!(tcx.sess, span, E0081, @@ -4363,7 +4363,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t for (&used, param) in types_used.iter().zip(types) { if !used { let id = tcx.hir().as_local_hir_id(param.def_id).unwrap(); - let span = tcx.hir().span_by_hir_id(id); + let span = tcx.hir().span(id); struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name) .span_label(span, "unused type parameter") .emit(); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index bf3381d206b5..5c710399446e 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -175,7 +175,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.err_count_since_creation() == 0 { // regionck assumes typeck succeeded - rcx.visit_fn_body(fn_id, body, self.tcx.hir().span_by_hir_id(fn_id)); + rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id)); } rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx)); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index bf64643e5a74..034ff5f83476 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -70,7 +70,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> { /// the types first. pub fn check_item_well_formed<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(hir_id); + let item = tcx.hir().expect_item(hir_id); debug!("check_item_well_formed(it.hir_id={:?}, it.name={})", item.hir_id, diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 1e33551b2560..ffc323f28b67 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.visit_node_id(arg.pat.span, arg.hir_id); } // Type only exists for constants and statics, not functions. - match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { + match self.tcx.hir().body_owner_kind(item_id) { hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => { wbcx.visit_node_id(body.value.span, item_id); } @@ -398,7 +398,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { if let ty::UserType::TypeOf(_, user_substs) = c_ty.value { if self.rustc_dump_user_substs { // This is a unit-testing mechanism. - let span = self.tcx().hir().span_by_hir_id(hir_id); + let span = self.tcx().hir().span(hir_id); // We need to buffer the errors in order to guarantee a consistent // order when emitting them. let err = self.tcx().sess.struct_span_err( @@ -773,13 +773,13 @@ impl Locatable for Span { impl Locatable for DefIndex { fn to_span(&self, tcx: TyCtxt<'_>) -> Span { let hir_id = tcx.hir().def_index_to_hir_id(*self); - tcx.hir().span_by_hir_id(hir_id) + tcx.hir().span(hir_id) } } impl Locatable for hir::HirId { fn to_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.hir().span_by_hir_id(*self) + tcx.hir().span(*self) } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index c724500b9ede..dda86778f272 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -121,7 +121,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'tcx>) { for extern_crate in &crates_to_lint { let id = tcx.hir().as_local_hir_id(extern_crate.def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(id); + let item = tcx.hir().expect_item(id); // If the crate is fully unused, we suggest removing it altogether. // We do this in any edition. diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index a690eefdf134..e392622060c9 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -88,7 +88,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); - let span = tcx.hir().span_by_hir_id(impl_hir_id); + let span = tcx.hir().span(impl_hir_id); let param_env = tcx.param_env(impl_did); assert!(!self_type.has_escaping_bound_vars()); @@ -98,7 +98,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { match param_env.can_type_implement_copy(tcx, self_type) { Ok(()) => {} Err(CopyImplementationError::InfrigingFields(fields)) => { - let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = tcx.hir().expect_item(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node { tr.path.span } else { @@ -115,7 +115,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { err.emit() } Err(CopyImplementationError::NotAnAdt) => { - let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = tcx.hir().expect_item(impl_hir_id); let span = if let ItemKind::Impl(.., ref ty, _) = item.node { ty.span } else { @@ -161,7 +161,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did: let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap(); let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap(); - let span = tcx.hir().span_by_hir_id(impl_hir_id); + let span = tcx.hir().span(impl_hir_id); let source = tcx.type_of(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -343,7 +343,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn source, target); - let span = gcx.hir().span_by_hir_id(impl_hir_id); + let span = gcx.hir().span(impl_hir_id); let param_env = gcx.param_env(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -480,11 +480,11 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn being coerced, none found"); return err_info; } else if diff_fields.len() > 1 { - let item = gcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = gcx.hir().expect_item(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.node { t.path.span } else { - gcx.hir().span_by_hir_id(impl_hir_id) + gcx.hir().span(impl_hir_id) }; let mut err = struct_span_err!(gcx.sess, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 1273fcfc2573..5606d9c0ce81 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -742,7 +742,7 @@ fn super_predicates_of<'tcx>( fn trait_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::TraitDef { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(hir_id); + let item = tcx.hir().expect_item(hir_id); let (is_auto, unsafety) = match item.node { hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety), @@ -1177,7 +1177,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op ImplItemKind::Const(ref ty, _) => icx.to_ty(ty), ImplItemKind::Existential(_) => { if tcx - .impl_trait_ref(tcx.hir().get_parent_did_by_hir_id(hir_id)) + .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1187,7 +1187,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op } ImplItemKind::Type(ref ty) => { if tcx - .impl_trait_ref(tcx.hir().get_parent_did_by_hir_id(hir_id)) + .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1272,7 +1272,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op .. }) => match *def { VariantData::Unit(..) | VariantData::Struct(..) => { - tcx.type_of(tcx.hir().get_parent_did_by_hir_id(hir_id)) + tcx.type_of(tcx.hir().get_parent_did(hir_id)) } VariantData::Tuple(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); @@ -1325,7 +1325,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op .. }) if e.hir_id == hir_id => { - tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id)) + tcx.adt_def(tcx.hir().get_parent_did(hir_id)) .repr .discr_type() .to_ty(tcx) @@ -1709,7 +1709,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { node: ForeignItemKind::Fn(ref fn_decl, _, _), .. }) => { - let abi = tcx.hir().get_foreign_abi_by_hir_id(hir_id); + let abi = tcx.hir().get_foreign_abi(hir_id); compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi) } @@ -1717,7 +1717,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { node: hir::VariantKind { data, .. }, .. }) if data.ctor_hir_id().is_some() => { - let ty = tcx.type_of(tcx.hir().get_parent_did_by_hir_id(hir_id)); + let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id)); let inputs = data.fields() .iter() .map(|f| tcx.type_of(tcx.hir().local_def_id_from_hir_id(f.hir_id))); @@ -1762,7 +1762,7 @@ fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option { opt_trait_ref.as_ref().map(|ast_trait_ref| { let selfty = tcx.type_of(def_id); @@ -1775,7 +1775,7 @@ fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option(tcx: TyCtxt<'tcx>, def_id: DefId) -> hir::ImplPolarity { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - match tcx.hir().expect_item_by_hir_id(hir_id).node { + match tcx.hir().expect_item(hir_id).node { hir::ItemKind::Impl(_, polarity, ..) => polarity, ref item => bug!("impl_polarity: {:?} not an impl", item), } diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index ea458842acce..5dbd667485e9 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -46,7 +46,7 @@ fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> &'tcx [ty::Varia let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. - span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item") + span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") }; match tcx.hir().get_by_hir_id(id) { Node::Item(item) => match item.node { diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 5a5540e7e385..c14ae5932af4 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -305,7 +305,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec) { } let for_ = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { - match tcx.hir().expect_item_by_hir_id(hir_id).node { + match tcx.hir().expect_item(hir_id).node { hir::ItemKind::Impl(.., ref t, _) => { t.clean(cx) } @@ -327,7 +327,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec) { let predicates = tcx.explicit_predicates_of(did); let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { - match tcx.hir().expect_item_by_hir_id(hir_id).node { + match tcx.hir().expect_item(hir_id).node { hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => { ( item_ids.iter() diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 43cb3dd7261c..4becb42d3055 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -276,7 +276,7 @@ impl Clean for CrateNum { }; let primitives = if root.is_local() { cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| { - let item = cx.tcx.hir().expect_item_by_hir_id(id.id); + let item = cx.tcx.hir().expect_item(id.id); match item.node { hir::ItemKind::Mod(_) => { as_primitive(Res::Def( @@ -320,7 +320,7 @@ impl Clean for CrateNum { }; let keywords = if root.is_local() { cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| { - let item = cx.tcx.hir().expect_item_by_hir_id(id.id); + let item = cx.tcx.hir().expect_item(id.id); match item.node { hir::ItemKind::Mod(_) => { as_keyword(Res::Def( @@ -2777,7 +2777,7 @@ impl Clean for hir::Ty { }, TyKind::Tup(ref tys) => Tuple(tys.clean(cx)), TyKind::Def(item_id, _) => { - let item = cx.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = cx.tcx.hir().expect_item(item_id.id); if let hir::ItemKind::Existential(ref ty) = item.node { ImplTrait(ty.bounds.clean(cx)) } else { @@ -2799,7 +2799,7 @@ impl Clean for hir::Ty { // Substitute private type aliases if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(def_id) { if !cx.renderinfo.borrow().access_levels.is_exported(def_id) { - alias = Some(&cx.tcx.hir().expect_item_by_hir_id(hir_id).node); + alias = Some(&cx.tcx.hir().expect_item(hir_id).node); } } }; @@ -4441,7 +4441,7 @@ pub fn path_to_def_local(tcx: TyCtxt<'_>, path: &[Symbol]) -> Option { let segment = path_it.next()?; for item_id in mem::replace(&mut items, HirVec::new()).iter() { - let item = tcx.hir().expect_item_by_hir_id(item_id.id); + let item = tcx.hir().expect_item(item_id.id); if item.ident.name == *segment { if path_it.peek().is_none() { return Some(tcx.hir().local_def_id_from_hir_id(item_id.id)) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index eb9de43e3886..ff76579d67d2 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -248,7 +248,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let orig_inside_public_path = self.inside_public_path; self.inside_public_path &= vis.node.is_pub(); for i in &m.item_ids { - let item = self.cx.tcx.hir().expect_item_by_hir_id(i.id); + let item = self.cx.tcx.hir().expect_item(i.id); self.visit_item(item, None, &mut om); } self.inside_public_path = orig_inside_public_path; @@ -275,7 +275,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool { while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) { node = id; - if cx.tcx.hir().attrs_by_hir_id(node) + if cx.tcx.hir().attrs(node) .lists(sym::doc).has_word(sym::hidden) { return true; } @@ -295,7 +295,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { return false; }; - let use_attrs = tcx.hir().attrs_by_hir_id(id); + let use_attrs = tcx.hir().attrs(id); // Don't inline `doc(hidden)` imports so they can be stripped at a later stage. let is_no_inline = use_attrs.lists(sym::doc).has_word(sym::no_inline) || use_attrs.lists(sym::doc).has_word(sym::hidden); @@ -346,7 +346,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => { let prev = mem::replace(&mut self.inlining, true); for i in &m.item_ids { - let i = self.cx.tcx.hir().expect_item_by_hir_id(i.id); + let i = self.cx.tcx.hir().expect_item(i.id); self.visit_item(i, None, om); } self.inlining = prev; @@ -361,7 +361,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { Node::ForeignItem(it) if !glob => { // Generate a fresh `extern {}` block if we want to inline a foreign item. om.foreigns.push(hir::ForeignMod { - abi: tcx.hir().get_foreign_abi_by_hir_id(it.hir_id), + abi: tcx.hir().get_foreign_abi(it.hir_id), items: vec![hir::ForeignItem { ident: renamed.unwrap_or(it.ident), .. it.clone() diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs index 40e0115c623e..76554eaba9c9 100644 --- a/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs +++ b/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass { let item = match cx.tcx.hir().get_by_hir_id(id) { Node::Item(item) => item, - _ => cx.tcx.hir().expect_item_by_hir_id(cx.tcx.hir().get_parent_item(id)), + _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)), }; if !attr::contains_name(&item.attrs, Symbol::intern("whitelisted_attr")) { From 1c8551b0ebb4efc72dd1d57035672e5b1c915ac2 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:30:02 +0200 Subject: [PATCH 035/109] renamve hir_to_string to node_to_string --- src/librustc/cfg/graphviz.rs | 2 +- src/librustc/hir/map/hir_id_validator.rs | 8 +++---- src/librustc/hir/map/mod.rs | 28 +++++++++++------------ src/librustc/infer/opaque_types/mod.rs | 2 +- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/reachable.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/ty/context.rs | 4 ++-- src/librustc_borrowck/borrowck/mod.rs | 6 ++--- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index 0bfb6b98e630..66963e5856ee 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -26,7 +26,7 @@ impl<'a, 'tcx> LabelledCFG<'a, 'tcx> { owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner, local_id }; - let s = self.tcx.hir().hir_to_string(hir_id); + let s = self.tcx.hir().node_to_string(hir_id); // Replacing newlines with \\l causes each line to be left-aligned, // improving presentation of (long) pretty-printed expressions. diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 08ec2aeed290..d6ac7ea2ed70 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -125,7 +125,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { let hir_id = self.hir_map.node_to_hir_id(node_id); missing_items.push(format!("[local_id: {}, node:{}]", local_id, - self.hir_map.hir_to_string(hir_id))); + self.hir_map.node_to_string(hir_id))); } self.error(|| format!( "ItemLocalIds not assigned densely in {}. \ @@ -139,7 +139,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { owner: owner_def_index, local_id, }) - .map(|h| format!("({:?} {})", h, self.hir_map.hir_to_string(h))) + .map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h))) .collect::>())); } } @@ -157,14 +157,14 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { if hir_id == hir::DUMMY_HIR_ID { self.error(|| format!("HirIdValidator: HirId {:?} is invalid", - self.hir_map.hir_to_string(hir_id))); + self.hir_map.node_to_string(hir_id))); return; } if owner != hir_id.owner { self.error(|| format!( "HirIdValidator: The recorded owner of {} is {} instead of {}", - self.hir_map.hir_to_string(hir_id), + self.hir_map.node_to_string(hir_id), self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(), self.hir_map.def_path(DefId::local(owner)).to_string_no_crate())); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5a45f04b6371..26c08154647e 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -453,7 +453,7 @@ impl<'hir> Map<'hir> { pub fn body_owned_by(&self, id: HirId) -> BodyId { self.maybe_body_owned_by(id).unwrap_or_else(|| { span_bug!(self.span(id), "body_owned_by: {} has no associated body", - self.hir_to_string(id)); + self.node_to_string(id)); }) } @@ -486,7 +486,7 @@ impl<'hir> Map<'hir> { Node::Item(&Item { node: ItemKind::Trait(..), .. }) | Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id, Node::GenericParam(_) => self.get_parent_node_by_hir_id(id), - _ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id)) + _ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id)) } } @@ -495,7 +495,7 @@ impl<'hir> Map<'hir> { Node::Item(&Item { node: ItemKind::Trait(..), .. }) | Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper, Node::GenericParam(param) => param.name.ident().name, - _ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)), + _ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)), } } @@ -874,27 +874,27 @@ impl<'hir> Map<'hir> { return nm.abi; } } - bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) + bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent)) } pub fn expect_item(&self, id: HirId) -> &'hir Item { match self.find_by_hir_id(id) { // read recorded by `find` Some(Node::Item(item)) => item, - _ => bug!("expected item, found {}", self.hir_to_string(id)) + _ => bug!("expected item, found {}", self.node_to_string(id)) } } pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem { match self.find_by_hir_id(id) { Some(Node::ImplItem(item)) => item, - _ => bug!("expected impl item, found {}", self.hir_to_string(id)) + _ => bug!("expected impl item, found {}", self.node_to_string(id)) } } pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem { match self.find_by_hir_id(id) { Some(Node::TraitItem(item)) => item, - _ => bug!("expected trait item, found {}", self.hir_to_string(id)) + _ => bug!("expected trait item, found {}", self.node_to_string(id)) } } @@ -904,26 +904,26 @@ impl<'hir> Map<'hir> { match i.node { ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => struct_def, - _ => bug!("struct ID bound to non-struct {}", self.hir_to_string(id)) + _ => bug!("struct ID bound to non-struct {}", self.node_to_string(id)) } } Some(Node::Variant(variant)) => &variant.node.data, Some(Node::Ctor(data)) => data, - _ => bug!("expected struct or variant, found {}", self.hir_to_string(id)) + _ => bug!("expected struct or variant, found {}", self.node_to_string(id)) } } pub fn expect_variant(&self, id: HirId) -> &'hir Variant { match self.find_by_hir_id(id) { Some(Node::Variant(variant)) => variant, - _ => bug!("expected variant, found {}", self.hir_to_string(id)), + _ => bug!("expected variant, found {}", self.node_to_string(id)), } } pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem { match self.find_by_hir_id(id) { Some(Node::ForeignItem(item)) => item, - _ => bug!("expected foreign item, found {}", self.hir_to_string(id)) + _ => bug!("expected foreign item, found {}", self.node_to_string(id)) } } @@ -936,7 +936,7 @@ impl<'hir> Map<'hir> { pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { match self.find_by_hir_id(id) { // read recorded by find Some(Node::Expr(expr)) => expr, - _ => bug!("expected expr, found {}", self.hir_to_string(id)) + _ => bug!("expected expr, found {}", self.node_to_string(id)) } } @@ -959,7 +959,7 @@ impl<'hir> Map<'hir> { Node::GenericParam(param) => param.name.ident().name, Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name, Node::Ctor(..) => self.name_by_hir_id(self.get_parent_item(id)), - _ => bug!("no name for {}", self.hir_to_string(id)) + _ => bug!("no name for {}", self.node_to_string(id)) } } @@ -1071,7 +1071,7 @@ impl<'hir> Map<'hir> { self.as_local_hir_id(id).map(|id| self.span(id)) } - pub fn hir_to_string(&self, id: HirId) -> String { + pub fn node_to_string(&self, id: HirId) -> String { hir_id_to_string(self, id, true) } diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 1c52b5775a0c..328ace51a582 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -819,7 +819,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { }, _ => bug!( "expected (impl) item, found {}", - tcx.hir().hir_to_string(opaque_hir_id), + tcx.hir().node_to_string(opaque_hir_id), ), }; if in_definition_scope { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index a856430e68a2..192e72383ace 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -501,7 +501,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { None if self.is_tainted_by_errors() => Err(()), None => { bug!("no type for node {}: {} in mem_categorization", - id, self.tcx.hir().hir_to_string(id)); + id, self.tcx.hir().node_to_string(id)); } } } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 2285beb37585..628a44cbfe01 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -318,7 +318,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { _ => { bug!( "found unexpected node kind in worklist: {} ({:?})", - self.tcx.hir().hir_to_string(search_item), + self.tcx.hir().node_to_string(search_item), node, ); } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 6f2c4b66f5ec..76bff500634a 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -2696,7 +2696,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!( "insert_lifetime: {} resolved to {:?} span={:?}", - self.tcx.hir().hir_to_string(lifetime_ref.hir_id), + self.tcx.hir().node_to_string(lifetime_ref.hir_id), def, self.tcx.sess.source_map().span_to_string(lifetime_ref.span) ); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index c32f62e88c42..b84ebd8afe88 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -252,7 +252,7 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option, ty::tls::with(|tcx| { bug!("node {} with HirId::owner {:?} cannot be placed in \ TypeckTables with local_id_root {:?}", - tcx.hir().hir_to_string(hir_id), + tcx.hir().node_to_string(hir_id), DefId::local(hir_id.owner), local_id_root) }); @@ -554,7 +554,7 @@ impl<'tcx> TypeckTables<'tcx> { pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> { self.node_type_opt(id).unwrap_or_else(|| bug!("node_type: no type for node `{}`", - tls::with(|tcx| tcx.hir().hir_to_string(id))) + tls::with(|tcx| tcx.hir().node_to_string(id))) ) } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index cc9c83de179c..23b28952935d 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1508,12 +1508,12 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.kind { LpVar(id) => { - write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().hir_to_string(id))) + write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_string(id))) } LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => { let s = ty::tls::with(|tcx| { - tcx.hir().hir_to_string(var_id) + tcx.hir().node_to_string(var_id) }); write!(f, "$({} captured by id={:?})", s, closure_expr_id) } @@ -1547,7 +1547,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> { LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => { let s = ty::tls::with(|tcx| { - tcx.hir().hir_to_string(hir_id) + tcx.hir().node_to_string(hir_id) }); write!(f, "$({} captured by closure)", s) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d4dbb68778ed..10bfe9e034d3 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2181,7 +2181,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn local_ty(&self, span: Span, nid: hir::HirId) -> LocalTy<'tcx> { self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| span_bug!(span, "no type for local variable {}", - self.tcx.hir().hir_to_string(nid)) + self.tcx.hir().node_to_string(nid)) ) } @@ -2518,7 +2518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None if self.is_tainted_by_errors() => self.tcx.types.err, None => { bug!("no type for node {}: {} in fcx {}", - id, self.tcx.hir().hir_to_string(id), + id, self.tcx.hir().node_to_string(id), self.tag()); } } diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 43063d7b8d12..4e6fcfe0593e 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -26,7 +26,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> { // "Trait" impl if let hir::ItemKind::Impl(.., Some(_), _, _) = item.node { debug!("coherence2::orphan check: trait impl {}", - self.tcx.hir().hir_to_string(item.hir_id)); + self.tcx.hir().node_to_string(item.hir_id)); let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap(); let trait_def_id = trait_ref.def_id; let cm = self.tcx.sess.source_map(); diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index b120f995ad3a..99f87ccb6f65 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -129,7 +129,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { debug!("add_inferreds for item {}", - self.tcx.hir().hir_to_string(item.hir_id)); + self.tcx.hir().node_to_string(item.hir_id)); match item.node { hir::ItemKind::Struct(ref struct_def, _) | From 21fbb59500ec50bab7e8a2b00af8a00c967f6b76 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:30:53 +0200 Subject: [PATCH 036/109] fix a HIR doc, simplify one HIR-related function call --- src/librustc/cfg/construct.rs | 3 +-- src/librustc/hir/map/mod.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 8f0f832b6c41..85602320f0b0 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -42,8 +42,7 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG { let body_exit; // Find the tables for this body. - let owner_hir_id = tcx.hir().body_owner(body.id()); - let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_hir_id); + let owner_def_id = tcx.hir().body_owner_def_id(body.id()); let tables = tcx.typeck_tables_of(owner_def_id); let mut cfg_builder = CFGBuilder { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 26c08154647e..18b8d23a455c 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -420,7 +420,7 @@ impl<'hir> Map<'hir> { } } - /// Returns the `NodeId` that corresponds to the definition of + /// Returns the `HirId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { From 88961b049ec2e8dec3f7b1c8166fb201c0632bbe Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:37:58 +0200 Subject: [PATCH 037/109] simplify ICE handling in HirIdValidator --- src/librustc/hir/map/hir_id_validator.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index d6ac7ea2ed70..32d0e069f72d 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -1,6 +1,5 @@ use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; use crate::hir::{self, intravisit, HirId, ItemLocalId}; -use syntax::ast::NodeId; use crate::hir::itemlikevisit::ItemLikeVisitor; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter}; @@ -112,17 +111,6 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { trace!("missing hir id {:#?}", hir_id); - // We are already in ICE mode here, so doing a linear search - // should be fine. - let (node_id, _) = self.hir_map - .definitions() - .node_to_hir_id - .iter() - .enumerate() - .find(|&(_, &entry)| hir_id == entry) - .expect("no node_to_hir_id entry"); - let node_id = NodeId::from_usize(node_id); - let hir_id = self.hir_map.node_to_hir_id(node_id); missing_items.push(format!("[local_id: {}, node:{}]", local_id, self.hir_map.node_to_string(hir_id))); From 72bb5c7067a12aa28a32c377135a1dd34bb73cb7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:44:19 +0200 Subject: [PATCH 038/109] change NodeId to HirId in some HIR docs --- src/librustc/hir/map/mod.rs | 10 +++++----- src/librustc/hir/mod.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 18b8d23a455c..85c86991f489 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -35,7 +35,7 @@ mod def_collector; pub mod definitions; mod hir_id_validator; -/// Represents an entry and its parent `NodeId`. +/// Represents an entry and its parent `HirId`. #[derive(Copy, Clone, Debug)] pub struct Entry<'hir> { parent: HirId, @@ -200,7 +200,7 @@ impl<'hir> Map<'hir> { /// "reveals" the content of a node to the caller (who might not /// otherwise have had access to those contents, and hence needs a /// read recorded). If the function just returns a DefId or - /// NodeId, no actual content was returned, so no read is needed. + /// HirId, no actual content was returned, so no read is needed. pub fn read(&self, hir_id: HirId) { if let Some(entry) = self.lookup(hir_id) { self.dep_graph.read_index(entry.dep_node); @@ -681,7 +681,7 @@ impl<'hir> Map<'hir> { /// If there is some error when walking the parents (e.g., a node does not /// have a parent in the map or a node can't be found), then we return the - /// last good `NodeId` we found. Note that reaching the crate root (`id == 0`), + /// last good `HirId` we found. Note that reaching the crate root (`id == 0`), /// is not an error, since items in the crate module have the crate root as /// parent. fn walk_parent_nodes(&self, @@ -717,7 +717,7 @@ impl<'hir> Map<'hir> { } } - /// Retrieves the `NodeId` for `id`'s enclosing method, unless there's a + /// Retrieves the `HirId` for `id`'s enclosing method, unless there's a /// `while` or `loop` before reaching it, as block tail returns are not /// available in them. /// @@ -725,7 +725,7 @@ impl<'hir> Map<'hir> { /// fn foo(x: usize) -> bool { /// if x == 1 { /// true // `get_return_block` gets passed the `id` corresponding - /// } else { // to this, it will return `foo`'s `NodeId`. + /// } else { // to this, it will return `foo`'s `HirId`. /// false /// } /// } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6ace4c4174b5..0884a726a27b 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2177,8 +2177,8 @@ pub enum UseKind { /// References to traits in impls. /// /// `resolve` maps each `TraitRef`'s `ref_id` to its defining trait; that's all -/// that the `ref_id` is for. Note that `ref_id`'s value is not the `NodeId` of the -/// trait being referred to but just a unique `NodeId` that serves as a key +/// that the `ref_id` is for. Note that `ref_id`'s value is not the `HirId` of the +/// trait being referred to but just a unique `HirId` that serves as a key /// within the resolution map. #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct TraitRef { From 61e004d68e916694c12fb9051826ed1779ac98d6 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 17 Jun 2019 19:01:41 +0200 Subject: [PATCH 039/109] fix rebase fallout --- src/librustc_typeck/check/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index fa9e0d8a8578..421688097b89 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -180,7 +180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.diverges.set(self.diverges.get() | old_diverges); self.has_errors.set(self.has_errors.get() | old_has_errors); - debug!("type of {} is...", self.tcx.hir().hir_to_string(expr.hir_id)); + debug!("type of {} is...", self.tcx.hir().node_to_string(expr.hir_id)); debug!("... {:?}, expected is {:?}", ty, expected); ty From f7ecf1c54806d0a2b614510b46d1b25c178450f0 Mon Sep 17 00:00:00 2001 From: Cedric Date: Mon, 17 Jun 2019 20:04:26 +0200 Subject: [PATCH 040/109] suggest tuple struct syntax --- src/librustc_typeck/check/expr.rs | 73 +++++++++++++---------- src/test/ui/issues/issue-4736.stderr | 5 +- src/test/ui/numeric/numeric-fields.stderr | 7 ++- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index fa9e0d8a8578..06d07d992427 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1215,38 +1215,49 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }, ty); - // prevent all specified fields from being suggested - let skip_fields = skip_fields.iter().map(|ref x| x.ident.as_str()); - if let Some(field_name) = Self::suggest_field_name(variant, - &field.ident.as_str(), - skip_fields.collect()) { - err.span_suggestion( - field.ident.span, - "a field with a similar name exists", - field_name.to_string(), - Applicability::MaybeIncorrect, - ); - } else { - match ty.sty { - ty::Adt(adt, ..) => { - if adt.is_enum() { - err.span_label(field.ident.span, - format!("`{}::{}` does not have this field", - ty, variant.ident)); - } else { - err.span_label(field.ident.span, - format!("`{}` does not have this field", ty)); - } - let available_field_names = self.available_field_names(variant); - if !available_field_names.is_empty() { - err.note(&format!("available fields are: {}", - self.name_series_display(available_field_names))); - } - } - _ => bug!("non-ADT passed to report_unknown_field") + match variant.ctor_kind { + CtorKind::Fn => { + err.span_label(field.ident.span, "field does not exist"); + err.span_label( + field.ident.span, + format!("`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`", adt=ty, kind_name=kind_name) + ); } - }; - err.emit(); + _ => { + // prevent all specified fields from being suggested + let skip_fields = skip_fields.iter().map(|ref x| x.ident.as_str()); + if let Some(field_name) = Self::suggest_field_name(variant, + &field.ident.as_str(), + skip_fields.collect()) { + err.span_suggestion( + field.ident.span, + "a field with a similar name exists", + field_name.to_string(), + Applicability::MaybeIncorrect, + ); + } else { + match ty.sty { + ty::Adt(adt, ..) => { + if adt.is_enum() { + err.span_label(field.ident.span, + format!("`{}::{}` does not have this field", + ty, variant.ident)); + } else { + err.span_label(field.ident.span, + format!("`{}` does not have this field", ty)); + } + let available_field_names = self.available_field_names(variant); + if !available_field_names.is_empty() { + err.note(&format!("available fields are: {}", + self.name_series_display(available_field_names))); + } + } + _ => bug!("non-ADT passed to report_unknown_field") + } + }; + } + } + err.emit(); } // Return an hint about the closest match in field names diff --git a/src/test/ui/issues/issue-4736.stderr b/src/test/ui/issues/issue-4736.stderr index b4ac12643bca..557ee5593f37 100644 --- a/src/test/ui/issues/issue-4736.stderr +++ b/src/test/ui/issues/issue-4736.stderr @@ -2,7 +2,10 @@ error[E0560]: struct `NonCopyable` has no field named `p` --> $DIR/issue-4736.rs:4:26 | LL | let z = NonCopyable{ p: () }; - | ^ help: a field with a similar name exists: `0` + | ^ + | | + | field does not exist + | `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)` error: aborting due to previous error diff --git a/src/test/ui/numeric/numeric-fields.stderr b/src/test/ui/numeric/numeric-fields.stderr index 13c18d740fc1..fef7486b8536 100644 --- a/src/test/ui/numeric/numeric-fields.stderr +++ b/src/test/ui/numeric/numeric-fields.stderr @@ -2,9 +2,10 @@ error[E0560]: struct `S` has no field named `0b1` --> $DIR/numeric-fields.rs:4:15 | LL | let s = S{0b1: 10, 0: 11}; - | ^^^ `S` does not have this field - | - = note: available fields are: `0`, `1` + | ^^^ + | | + | field does not exist + | `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)` error[E0026]: struct `S` does not have a field named `0x1` --> $DIR/numeric-fields.rs:7:17 From e1bf56de25a78b3883822f82aeba0010c4a2fad7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 17 Jun 2019 20:31:26 +0200 Subject: [PATCH 041/109] remove superfluous space --- src/librustc_borrowck/borrowck/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 23b28952935d..93cea6d2f019 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -896,7 +896,7 @@ impl BorrowckCtxt<'_, 'tcx> { // to implement two traits for "one operator" is not very intuitive for // many programmers. if err.cmt.note == mc::NoteIndex { - let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); + let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); // This pattern probably always matches. if let Node::Expr( From aedb74b8c38f965c5a27408050b3b04c83e514bb Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 12 Jun 2019 07:37:30 -0700 Subject: [PATCH 042/109] Update cargo --- Cargo.lock | 369 ++++++++++++++++++++++++++++++++---------------- src/tools/cargo | 2 +- 2 files changed, 250 insertions(+), 121 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3c6be59b75d..1919faf21ca0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,7 +70,7 @@ name = "arena" version = "0.0.0" dependencies = [ "rustc_data_structures 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -190,7 +190,7 @@ dependencies = [ "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -213,7 +213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "build-manifest" version = "0.1.0" dependencies = [ - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -266,6 +266,7 @@ dependencies = [ "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "bytesize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo-test-macro 0.1.0", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crates-io 0.26.0", @@ -279,8 +280,8 @@ dependencies = [ "flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "fwdansi 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "git2-curl 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "git2-curl 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "home 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -290,7 +291,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -303,7 +304,7 @@ dependencies = [ "rustfix 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -315,10 +316,19 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cargo-test-macro" +version = "0.1.0" +dependencies = [ + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cargo_metadata" version = "0.7.1" @@ -326,7 +336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -338,7 +348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -417,7 +427,7 @@ dependencies = [ "rustc-workspace-hack 1.0.0", "rustc_tools_util 0.2.0", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -437,8 +447,8 @@ dependencies = [ "quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -506,7 +516,7 @@ dependencies = [ "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustfix 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -525,7 +535,7 @@ dependencies = [ "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustfix 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -566,7 +576,7 @@ dependencies = [ "curl 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -594,7 +604,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -710,9 +720,9 @@ name = "derive-new" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -720,10 +730,10 @@ name = "derive_more" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -796,7 +806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -880,9 +890,9 @@ name = "failure_derive" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1034,12 +1044,12 @@ dependencies = [ [[package]] name = "git2" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1048,11 +1058,11 @@ dependencies = [ [[package]] name = "git2-curl" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "curl 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1089,7 +1099,7 @@ dependencies = [ "pest_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1104,11 +1114,16 @@ dependencies = [ "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hashbrown" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hashbrown" version = "0.4.0" @@ -1149,9 +1164,9 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "markup5ever 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1161,7 +1176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1266,7 +1281,7 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1301,7 +1316,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1330,6 +1345,11 @@ name = "lazycell" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "leb128" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.54" @@ -1340,11 +1360,10 @@ dependencies = [ [[package]] name = "libgit2-sys" -version = "0.7.11" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", - "curl-sys 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", "libssh2-sys 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1432,7 +1451,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "num-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1472,7 +1491,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1504,7 +1523,7 @@ dependencies = [ "open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1532,7 +1551,7 @@ dependencies = [ "open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1714,9 +1733,9 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1792,6 +1811,14 @@ dependencies = [ "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ordered-float" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ordermap" version = "0.3.5" @@ -1856,10 +1883,28 @@ dependencies = [ "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "partial_ref" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "partial_ref_derive 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "partial_ref_derive" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1904,9 +1949,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2003,7 +2048,7 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "0.4.24" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2083,10 +2128,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "quote" -version = "0.6.10" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2344,7 +2389,7 @@ dependencies = [ "rustc-workspace-hack 1.0.0", "rustc_tools_util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustfmt-nightly 1.2.2", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2369,7 +2414,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rls-data 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2384,7 +2429,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rls-span 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2396,7 +2441,7 @@ name = "rls-span" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2446,7 +2491,7 @@ dependencies = [ "rustc_target 0.0.0", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2492,7 +2537,7 @@ dependencies = [ "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2528,7 +2573,7 @@ name = "rustc-ap-serialize" version = "407.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2544,7 +2589,7 @@ dependencies = [ "rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-ap-syntax_pos 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2656,10 +2701,10 @@ dependencies = [ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2672,7 +2717,7 @@ dependencies = [ "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_target 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] @@ -2683,7 +2728,7 @@ version = "0.0.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2792,7 +2837,7 @@ dependencies = [ "rustc-rayon-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2826,7 +2871,7 @@ dependencies = [ "rustc_typeck 0.0.0", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_ext 0.0.0", "syntax_pos 0.0.0", @@ -2891,7 +2936,7 @@ dependencies = [ "rustc_typeck 0.0.0", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_ext 0.0.0", "syntax_pos 0.0.0", @@ -2934,9 +2979,9 @@ name = "rustc_macros" version = "0.1.0" dependencies = [ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2952,7 +2997,7 @@ dependencies = [ "rustc_errors 0.0.0", "rustc_target 0.0.0", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_ext 0.0.0", @@ -2976,7 +3021,7 @@ dependencies = [ "rustc_errors 0.0.0", "rustc_target 0.0.0", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] @@ -3041,7 +3086,7 @@ dependencies = [ "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_metadata 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] @@ -3095,7 +3140,7 @@ dependencies = [ "rustc 0.0.0", "rustc_data_structures 0.0.0", "rustc_target 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] @@ -3121,7 +3166,7 @@ dependencies = [ "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_target 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] @@ -3162,7 +3207,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3190,7 +3235,7 @@ dependencies = [ "rustc-ap-syntax 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-ap-syntax_pos 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3254,7 +3299,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3264,7 +3309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.82" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3275,9 +3320,9 @@ name = "serde_derive" version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3285,7 +3330,7 @@ name = "serde_ignored" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3293,9 +3338,9 @@ name = "serde_json" version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3303,7 +3348,7 @@ name = "serialize" version = "0.0.0" dependencies = [ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3356,11 +3401,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.7" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "socket2" @@ -3412,7 +3454,7 @@ dependencies = [ "new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3424,8 +3466,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3458,9 +3500,9 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3475,11 +3517,11 @@ dependencies = [ [[package]] name = "syn" -version = "0.15.22" +version = "0.15.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3496,9 +3538,9 @@ name = "synstructure" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3515,7 +3557,7 @@ dependencies = [ "rustc_target 0.0.0", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax_pos 0.0.0", ] @@ -3528,7 +3570,7 @@ dependencies = [ "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_target 0.0.0", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] @@ -3660,7 +3702,7 @@ name = "tidy" version = "0.1.0" dependencies = [ "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3867,7 +3909,7 @@ name = "toml" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3875,7 +3917,7 @@ name = "toml" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4005,7 +4047,7 @@ name = "url_serde" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4024,6 +4066,76 @@ name = "utf8parse" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "varisat" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "leb128 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "partial_ref 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-checker 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-dimacs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-formula 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-internal-macros 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-internal-proof 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_mut_scan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "varisat-checker" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-dimacs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-formula 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-internal-proof 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "varisat-dimacs" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-formula 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "varisat-formula" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "varisat-internal-macros" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "varisat-internal-proof" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "varisat-formula 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "vcpkg" version = "0.2.6" @@ -4034,6 +4146,11 @@ name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vec_mut_scan" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "vergen" version = "3.0.4" @@ -4254,12 +4371,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fwdansi 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34dd4c507af68d37ffef962063dfa1944ce0dd4d5b82043dbab1dabe088610c3" "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" "checksum getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)" = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450" -"checksum git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7339329bfa14a00223244311560d11f8f489b453fb90092af97f267a6090ab0" -"checksum git2-curl 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d58551e903ed7e2d6fe3a2f3c7efa3a784ec29b19d0fbb035aaf0497c183fbdd" +"checksum git2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "924b2e7d2986e625dcad89e8a429a7b3adee3c3d71e585f4a66c4f7e78715e31" +"checksum git2-curl 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f21f0550fd5d3f7c5adb94797fcd3d1002d7fc1fa349c82fe44f3c97ef80b62c" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum globset 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef4feaabe24a0a658fd9cf4a9acf6ed284f045c77df0f49020ba3245cfb7b454" "checksum handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d89ec99d1594f285d4590fc32bac5f75cdab383f1123d504d27862c644a807dd" "checksum handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d82e5750d8027a97b9640e3fefa66bbaf852a35228e1c90790efd13c4b09c166" +"checksum hashbrown 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "29fba9abe4742d586dfd0c06ae4f7e73a1c2d86b856933509b269d82cdf06e18" "checksum hashbrown 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9529213c67695ca2d146e6f263b7b72df8fa973368beadf767e8ed80c03f2f36" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" @@ -4276,7 +4394,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum is-match 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7e5b386aef33a1c677be65237cb9d32c3f3ef56bd035949710c4bb13083eb053" "checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum jemalloc-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bef0d4ce37578dfd80b466e3d8324bd9de788e249f1accebb0c472ea4b52bdc" "checksum jobserver 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b3d51e24009d966c8285d524dbaf6d60926636b2a89caee9ce0bd612494ddc16" "checksum json 0.11.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9ad0485404155f45cce53a40d4b2d6ac356418300daed05273d9e26f91c390be" @@ -4285,8 +4403,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" +"checksum leb128 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" "checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6" -"checksum libgit2-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "48441cb35dc255da8ae72825689a95368bf510659ae1ad55dc4aa88cb1789bf1" +"checksum libgit2-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3cdc869f847995243b84e2f10226fe70afdd9f989c6fc4500d1ff53dd21cf43b" "checksum libnghttp2-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d75d7966bda4730b722d1eab8e668df445368a24394bae9fc1e8dc0ab3dbe4f4" "checksum libssh2-sys 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "126a1f4078368b163bfdee65fbab072af08a1b374a5551b21e87ade27b1fbf9d" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" @@ -4329,12 +4448,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)" = "26bb632127731bf4ac49bf86a5dde12d2ca0918c2234fc39d79d4da2ccbc6da7" "checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d" +"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum ordslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd20eec3dbe4376829cb7d80ae6ac45e0a766831dca50202ff2d40db46a8a024" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum packed_simd 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "25d36de864f7218ec5633572a800109bbe5a1cc8d9d95a967f3daf93ea7e6ddc" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum partial_ref 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b85fa89a02abf59d36821c373b5ed38c8e075505f1a08618b000fce81229bc" +"checksum partial_ref_derive 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "759319b785d033e4279ec98fb2d1fb767a1af5b6a8996086c07168169cff079b" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pest 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0fce5d8b5cc33983fc74f78ad552b5522ab41442c4ca91606e4236eb4b5ceefc" "checksum pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "54f0c72a98d8ab3c99560bfd16df8059cc10e1f9a8e83e6e3b97718dd766e9c3" @@ -4352,7 +4474,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" "checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6" "checksum pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8b3f4e0475def7d9c2e5de8e5a1306949849761e107b360d03e98eafaffd61" -"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proptest 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24f5844db2f839e97e3021980975f6ebf8691d9b9b2ca67ed3feb38dc3edb52c" "checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32" "checksum pulldown-cmark 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "051e60ace841b3bfecd402fe5051c06cb3bec4a6e6fdd060a37aa8eb829a1db3" @@ -4360,7 +4482,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" +"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" "checksum racer 2.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4323343f25bc372dc9293ac6b5cd3034b32784af1e7de9366b4db71466d8c7" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a" @@ -4416,7 +4538,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)" = "6fa52f19aee12441d5ad11c9a00459122bd8f98707cadf9778c540674f1935b6" +"checksum serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be" "checksum serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)" = "477b13b646f5b5b56fc95bedfc3b550d12141ce84f466f6c44b9a17589923885" "checksum serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "190e9765dcedb56be63b6e0993a006c7e3b071a016a304736e4a315dc01fb142" "checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811" @@ -4427,7 +4549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537" "checksum sized-chunks 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2eb3fe454976eefb479f78f9b394d34d661b647c6326a3a6e66f68bb12c26" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" +"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7" "checksum stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffbc596e092fe5f598b12ef46cc03754085ac2f4d8c739ad61c4ae266cc3b3fa" "checksum string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25d70109977172b127fe834e5449e5ab1740b9ba49fa18a2020f509174f25423" @@ -4438,7 +4560,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum strum 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c3a2071519ab6a48f465808c4c1ffdd00dfc8e93111d02b4fc5abab177676e" "checksum strum_macros 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8baacebd7b7c9b864d83a6ba7a246232983e277b86fa5cdec77f565715a4b136" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)" = "ae8b29eb5210bc5cf63ed6149cbf9adfc82ac0be023d8735c176ee74a2db4da7" +"checksum syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)" = "641e117d55514d6d918490e47102f7e08d096fdde360247e4a10f7a91a8478d3" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum tar 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "a303ba60a099fcd2aaa646b14d2724591a96a75283e4b7ed3d1a1658909d9ae2" @@ -4487,8 +4609,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum utf-8 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1262dfab4c30d5cb7c07026be00ee343a6cf5027fdc0104a9160f354e5db75c" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" +"checksum varisat 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a2640f5949bcd945ffdb030f5f336d0a5da8fe8ddab8e8230e2e030ea0623cfa" +"checksum varisat-checker 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a44da8d5e25b089d66fb3d14ae87994e2f7ba7f86ff396b7c490083d8a9a0a7b" +"checksum varisat-dimacs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f992cf40560ad73983369414fcc5a42fb9c9e39ae7ff215c75725f9c6785f0b9" +"checksum varisat-formula 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "78d44ab5c6de769e855c77add5b0efa73ed3320b06485f04c8d3fad9b2eb9997" +"checksum varisat-internal-macros 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e76c43d9badf53d22b0edd25667d65b7b67167e2cce249c9d1e3ca0f02dc81c" +"checksum varisat-internal-proof 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5a7553f03a4a8581410fb1813add70ce54e481d0e3eb1ca2cc1754faf46ff9ad" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum vec_mut_scan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d5668931075a8dfe6eb3e9e585d06f0ab4d9b377663e94d135ef51933ff9f6" "checksum vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6aba5e34f93dc7051dfad05b98a18e9156f27e7b431fe1d2398cb6061c0a1dba" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/src/tools/cargo b/src/tools/cargo index 545f354259be..807429e1b6da 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 545f354259be4e9745ea00a524c0e4c51df01aa6 +Subproject commit 807429e1b6da4e2ec52488ef2f59e77068c31e1f From 6b25e535381bffe43359060cbbda2ee3df912686 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 13 Jun 2019 22:35:27 -0700 Subject: [PATCH 043/109] Add `syn` to workspace hack. Cargo's syn now has the `full` feature, so add it here to keep it in sync. --- src/tools/rustc-workspace-hack/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tools/rustc-workspace-hack/Cargo.toml b/src/tools/rustc-workspace-hack/Cargo.toml index 747200611224..26b447d2efe7 100644 --- a/src/tools/rustc-workspace-hack/Cargo.toml +++ b/src/tools/rustc-workspace-hack/Cargo.toml @@ -69,8 +69,9 @@ rand = { version = "0.6.1", features = ["i128_support"] } serde = { version = "1.0.82", features = ['derive'] } serde_json = { version = "1.0.31", features = ["raw_value"] } smallvec = { version = "0.6", features = ['union', 'may_dangle'] } -scopeguard = { version = "0.3.3", features = ["use_std", "default"]} -byteorder = { version = "1.2.7", features = ["i128"]} +scopeguard = { version = "0.3.3", features = ["use_std", "default"] } +byteorder = { version = "1.2.7", features = ["i128"] } +syn = { version = "0.15.35", features = ["extra-traits", "full"] } [target.'cfg(not(windows))'.dependencies] From afa4827e986f8f6e683e09c983767d68e05e6038 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 17 Jun 2019 14:34:24 -0700 Subject: [PATCH 044/109] Bump libgit2-sys to get it to compile on i686-pc-windows-gnu. --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1919faf21ca0..403fe4101eb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,7 +291,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1049,7 +1049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1360,7 +1360,7 @@ dependencies = [ [[package]] name = "libgit2-sys" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4405,7 +4405,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum leb128 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" "checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6" -"checksum libgit2-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3cdc869f847995243b84e2f10226fe70afdd9f989c6fc4500d1ff53dd21cf43b" +"checksum libgit2-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "941a41e23f77323b8c9d2ee118aec9ee39dfc176078c18b4757d3bad049d9ff7" "checksum libnghttp2-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d75d7966bda4730b722d1eab8e668df445368a24394bae9fc1e8dc0ab3dbe4f4" "checksum libssh2-sys 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "126a1f4078368b163bfdee65fbab072af08a1b374a5551b21e87ade27b1fbf9d" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" From 3d5ef11f1a64fe829e6e3306cdfc723eba1b0eab Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 18 Jun 2019 07:53:27 +0900 Subject: [PATCH 045/109] Improve wording --- src/librustc_typeck/error_codes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index 9f8874f1ff6d..8fb7049dea8d 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -3812,7 +3812,7 @@ impl Foo { ``` A similar error is E0201. The difference is whether there is one declaration -block or not. To avoid this error, you have to give them one name each. +block or not. To avoid this error, you must give each `fn` a unique name. ``` struct Foo; From b9ea653aee231114acbe6d4b3c7b1d692772d060 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Mon, 25 Mar 2019 14:28:03 -0700 Subject: [PATCH 046/109] Expose `VaListImpl` as the Rust equivalent of `__va_list_tag` and implement Clone for it. --- src/libcore/ffi.rs | 241 ++++++++++++++---- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/mod.rs | 2 +- src/librustc/ty/layout.rs | 4 +- src/librustc_codegen_llvm/intrinsic.rs | 38 +-- src/librustc_codegen_llvm/va_arg.rs | 12 +- src/librustc_codegen_ssa/mir/block.rs | 6 +- src/librustc_codegen_ssa/mir/mod.rs | 33 +-- src/librustc_codegen_ssa/traits/intrinsic.rs | 4 +- src/librustc_lint/types.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_typeck/check/intrinsic.rs | 40 +-- src/libstd/ffi/mod.rs | 2 +- src/test/auxiliary/rust_test_helpers.c | 17 +- src/test/codegen/c-variadic-copy.rs | 16 ++ src/test/codegen/c-variadic-opt.rs | 15 +- src/test/codegen/c-variadic.rs | 2 +- .../c-link-to-rust-va-list-fn/checkrust.rs | 2 +- src/test/run-pass/variadic-ffi.rs | 45 ++++ src/test/ui/c-variadic/variadic-ffi-1.stderr | 4 +- .../ui/c-variadic/variadic-ffi-4.nll.stderr | 52 ++-- src/test/ui/c-variadic/variadic-ffi-4.rs | 16 +- src/test/ui/c-variadic/variadic-ffi-4.stderr | 81 ++++-- src/test/ui/error-codes/E0617.rs | 4 +- src/test/ui/error-codes/E0617.stderr | 8 +- src/test/ui/symbol-names/impl1.rs | 2 +- 26 files changed, 424 insertions(+), 228 deletions(-) create mode 100644 src/test/codegen/c-variadic-copy.rs diff --git a/src/libcore/ffi.rs b/src/libcore/ffi.rs index 2906e5824ae7..49090fb8e437 100644 --- a/src/libcore/ffi.rs +++ b/src/libcore/ffi.rs @@ -5,6 +5,8 @@ //! Utilities related to FFI bindings. use crate::fmt; +use crate::marker::PhantomData; +use crate::ops::{Deref, DerefMut}; /// Equivalent to C's `void` type when used as a [pointer]. /// @@ -45,25 +47,33 @@ impl fmt::Debug for c_void { } /// Basic implementation of a `va_list`. +// The name is WIP, using `VaListImpl` for now. #[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), - not(target_arch = "x86_64")), + not(target_arch = "x86_64"), not(target_arch = "asmjs")), + all(target_arch = "aarch64", target_os = "ios"), + windows))] +#[repr(transparent)] +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +#[lang = "va_list"] +pub struct VaListImpl<'f> { + ptr: *mut c_void, + _marker: PhantomData<&'f c_void>, +} + +#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), + not(target_arch = "x86_64"), not(target_arch = "asmjs")), all(target_arch = "aarch64", target_os = "ios"), windows))] #[unstable(feature = "c_variadic", reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930")] -extern { - type VaListImpl; -} - -#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), - not(target_arch = "x86_64")), - all(target_arch = "aarch64", target_os = "ios"), - windows))] -impl fmt::Debug for VaListImpl { +impl<'f> fmt::Debug for VaListImpl<'f> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "va_list* {:p}", self) + write!(f, "va_list* {:p}", self.ptr) } } @@ -79,12 +89,14 @@ impl fmt::Debug for VaListImpl { reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930")] -struct VaListImpl { +#[lang = "va_list"] +pub struct VaListImpl<'f> { stack: *mut c_void, gr_top: *mut c_void, vr_top: *mut c_void, gr_offs: i32, vr_offs: i32, + _marker: PhantomData<&'f c_void>, } /// PowerPC ABI implementation of a `va_list`. @@ -95,12 +107,14 @@ struct VaListImpl { reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930")] -struct VaListImpl { +#[lang = "va_list"] +pub struct VaListImpl<'f> { gpr: u8, fpr: u8, reserved: u16, overflow_arg_area: *mut c_void, reg_save_area: *mut c_void, + _marker: PhantomData<&'f c_void>, } /// x86_64 ABI implementation of a `va_list`. @@ -111,22 +125,131 @@ struct VaListImpl { reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930")] -struct VaListImpl { +#[lang = "va_list"] +pub struct VaListImpl<'f> { gp_offset: i32, fp_offset: i32, overflow_arg_area: *mut c_void, reg_save_area: *mut c_void, + _marker: PhantomData<&'f c_void>, +} + +/// asm.js ABI implementation of a `va_list`. +// asm.js uses the PNaCl ABI, which specifies that a `va_list` is +// an array of 4 32-bit integers, according to the old PNaCl docs at +// https://web.archive.org/web/20130518054430/https://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Derived-Types +// and clang does the same in `CreatePNaClABIBuiltinVaListDecl` from `lib/AST/ASTContext.cpp` +#[cfg(all(target_arch = "asmjs", not(windows)))] +#[repr(C)] +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +#[lang = "va_list"] +pub struct VaListImpl<'f> { + inner: [crate::mem::MaybeUninit; 4], + _marker: PhantomData<&'f c_void>, +} + +#[cfg(all(target_arch = "asmjs", not(windows)))] +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +impl<'f> fmt::Debug for VaListImpl<'f> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + unsafe { + write!(f, "va_list* [{:#x}, {:#x}, {:#x}, {:#x}]", + self.inner[0].read(), self.inner[1].read(), + self.inner[2].read(), self.inner[3].read()) + } + } } /// A wrapper for a `va_list` -#[lang = "va_list"] +#[repr(transparent)] #[derive(Debug)] #[unstable(feature = "c_variadic", reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930")] -#[repr(transparent)] -pub struct VaList<'a>(&'a mut VaListImpl); +pub struct VaList<'a, 'f: 'a> { + #[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), + not(target_arch = "x86_64"), not(target_arch = "asmjs")), + all(target_arch = "aarch64", target_os = "ios"), + windows))] + inner: VaListImpl<'f>, + + #[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", + target_arch = "x86_64", target_arch = "asmjs"), + any(not(target_arch = "aarch64"), not(target_os = "ios")), + not(windows)))] + inner: &'a mut VaListImpl<'f>, + + _marker: PhantomData<&'a mut VaListImpl<'f>>, +} + +#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), + not(target_arch = "x86_64"), not(target_arch = "asmjs")), + all(target_arch = "aarch64", target_os = "ios"), + windows))] +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +impl<'f> VaListImpl<'f> { + /// Convert a `VaListImpl` into a `VaList` that is binary-compatible with C's `va_list`. + #[inline] + pub fn as_va_list<'a>(&'a mut self) -> VaList<'a, 'f> { + VaList { + inner: VaListImpl { ..*self }, + _marker: PhantomData, + } + } +} + +#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", + target_arch = "x86_64", target_arch = "asmjs"), + any(not(target_arch = "aarch64"), not(target_os = "ios")), + not(windows)))] +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +impl<'f> VaListImpl<'f> { + /// Convert a `VaListImpl` into a `VaList` that is binary-compatible with C's `va_list`. + #[inline] + pub fn as_va_list<'a>(&'a mut self) -> VaList<'a, 'f> { + VaList { + inner: self, + _marker: PhantomData, + } + } +} + +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +impl<'a, 'f: 'a> Deref for VaList<'a, 'f> { + type Target = VaListImpl<'f>; + + #[inline] + fn deref(&self) -> &VaListImpl<'f> { + &self.inner + } +} + +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> { + #[inline] + fn deref_mut(&mut self) -> &mut VaListImpl<'f> { + &mut self.inner + } +} // The VaArgSafe trait needs to be used in public interfaces, however, the trait // itself must not be allowed to be used outside this module. Allowing users to @@ -175,56 +298,76 @@ impl sealed_trait::VaArgSafe for *mut T {} issue = "44930")] impl sealed_trait::VaArgSafe for *const T {} -impl<'a> VaList<'a> { +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +#[cfg(not(bootstrap))] +impl<'f> VaListImpl<'f> { /// Advance to the next arg. - #[unstable(feature = "c_variadic", - reason = "the `c_variadic` feature has not been properly tested on \ - all supported platforms", - issue = "44930")] + #[inline] pub unsafe fn arg(&mut self) -> T { va_arg(self) } /// Copies the `va_list` at the current location. - #[unstable(feature = "c_variadic", - reason = "the `c_variadic` feature has not been properly tested on \ - all supported platforms", - issue = "44930")] pub unsafe fn with_copy(&self, f: F) -> R - where F: for<'copy> FnOnce(VaList<'copy>) -> R { - #[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), - not(target_arch = "x86_64")), - all(target_arch = "aarch64", target_os = "ios"), - windows))] - let mut ap = va_copy(self); - #[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"), - not(windows), not(all(target_arch = "aarch64", target_os = "ios"))))] - let mut ap_inner = va_copy(self); - #[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"), - not(windows), not(all(target_arch = "aarch64", target_os = "ios"))))] - let mut ap = VaList(&mut ap_inner); - let ret = f(VaList(ap.0)); + where F: for<'copy> FnOnce(VaList<'copy, 'f>) -> R { + let mut ap = self.clone(); + let ret = f(ap.as_va_list()); va_end(&mut ap); ret } } +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +#[cfg(not(bootstrap))] +impl<'f> Clone for VaListImpl<'f> { + #[inline] + fn clone(&self) -> Self { + let mut dest = crate::mem::MaybeUninit::uninit(); + unsafe { + va_copy(dest.as_mut_ptr(), self); + dest.assume_init() + } + } +} + +#[unstable(feature = "c_variadic", + reason = "the `c_variadic` feature has not been properly tested on \ + all supported platforms", + issue = "44930")] +#[cfg(not(bootstrap))] +impl<'f> Drop for VaListImpl<'f> { + fn drop(&mut self) { + // FIXME: this should call `va_end`, but there's no clean way to + // guarantee that `drop` always gets inlined into its caller, + // so the `va_end` would get directly called from the same function as + // the corresponding `va_copy`. `man va_end` states that C requires this, + // and LLVM basically follows the C semantics, so we need to make sure + // that `va_end` is always called from the same function as `va_copy`. + // For more details, see https://github.com/rust-lang/rust/pull/59625 + // and https://llvm.org/docs/LangRef.html#llvm-va-end-intrinsic. + // + // This works for now, since `va_end` is a no-op on all current LLVM targets. + } +} + extern "rust-intrinsic" { /// Destroy the arglist `ap` after initialization with `va_start` or /// `va_copy`. - fn va_end(ap: &mut VaList<'_>); + #[cfg(not(bootstrap))] + fn va_end(ap: &mut VaListImpl<'_>); /// Copies the current location of arglist `src` to the arglist `dst`. - #[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), - not(target_arch = "x86_64")), - all(target_arch = "aarch64", target_os = "ios"), - windows))] - fn va_copy<'a>(src: &VaList<'a>) -> VaList<'a>; - #[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"), - not(windows), not(all(target_arch = "aarch64", target_os = "ios"))))] - fn va_copy(src: &VaList<'_>) -> VaListImpl; + #[cfg(not(bootstrap))] + fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>); /// Loads an argument of type `T` from the `va_list` `ap` and increment the /// argument `ap` points to. - fn va_arg(ap: &mut VaList<'_>) -> T; + #[cfg(not(bootstrap))] + fn va_arg(ap: &mut VaListImpl<'_>) -> T; } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 5a548ce8d9ff..ae8fdaea2859 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1674,7 +1674,7 @@ impl<'a> LoweringContext<'a> { } TyKind::Mac(_) => bug!("`TyMac` should have been expanded by now."), TyKind::CVarArgs => { - // Create the implicit lifetime of the "spoofed" `VaList`. + // Create the implicit lifetime of the "spoofed" `VaListImpl`. let span = self.sess.source_map().next_point(t.span.shrink_to_lo()); let lt = self.new_implicit_lifetime(span); hir::TyKind::CVarArgs(lt) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6ace4c4174b5..49b6fd67cb74 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1930,7 +1930,7 @@ pub enum TyKind { Infer, /// Placeholder for a type that has failed to be defined. Err, - /// Placeholder for C-variadic arguments. We "spoof" the `VaList` created + /// Placeholder for C-variadic arguments. We "spoof" the `VaListImpl` created /// from the variadic arguments. This type is only valid up to typeck. CVarArgs(Lifetime), } diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 6cee2709b636..9ce1d2eec5d2 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -2711,7 +2711,7 @@ where } // If this is a C-variadic function, this is not the return value, - // and there is one or more fixed arguments; ensure that the `VaList` + // and there is one or more fixed arguments; ensure that the `VaListImpl` // is ignored as an argument. if sig.c_variadic { match (last_arg_idx, arg_idx) { @@ -2722,7 +2722,7 @@ where }; match ty.sty { ty::Adt(def, _) if def.did == va_list_did => { - // This is the "spoofed" `VaList`. Set the arguments mode + // This is the "spoofed" `VaListImpl`. Set the arguments mode // so that it will be ignored. arg.mode = PassMode::Ignore(IgnoreMode::CVarArgs); } diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index dc3631e2ee17..7831c200114a 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -146,15 +146,8 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { self.va_end(args[0].immediate()) } "va_copy" => { - let va_list = match (tcx.lang_items().va_list(), &result.layout.ty.sty) { - (Some(did), ty::Adt(def, _)) if def.did == did => args[0].immediate(), - (Some(_), _) => self.load(args[0].immediate(), - tcx.data_layout.pointer_align.abi), - (None, _) => bug!("`va_list` language item must be defined") - }; let intrinsic = self.cx().get_intrinsic(&("llvm.va_copy")); - self.call(intrinsic, &[llresult, va_list], None); - return; + self.call(intrinsic, &[args[0].immediate(), args[1].immediate()], None) } "va_arg" => { match fn_ty.ret.layout.abi { @@ -743,37 +736,12 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { self.call(expect, &[cond, self.const_bool(expected)], None) } - fn va_start(&mut self, list: &'ll Value) -> &'ll Value { - let target = &self.cx.tcx.sess.target.target; - let arch = &target.arch; - // A pointer to the architecture specific structure is passed to this - // function. For pointer variants (i686, RISC-V, Windows, etc), we - // should do do nothing, as the address to the pointer is needed. For - // architectures with a architecture specific structure (`Aarch64`, - // `X86_64`, etc), this function should load the structure from the - // address provided. - let va_list = match &**arch { - _ if target.options.is_like_windows => list, - "aarch64" if target.target_os == "ios" => list, - "aarch64" | "x86_64" | "powerpc" => - self.load(list, self.tcx().data_layout.pointer_align.abi), - _ => list, - }; + fn va_start(&mut self, va_list: &'ll Value) -> &'ll Value { let intrinsic = self.cx().get_intrinsic("llvm.va_start"); self.call(intrinsic, &[va_list], None) } - fn va_end(&mut self, list: &'ll Value) -> &'ll Value { - let target = &self.cx.tcx.sess.target.target; - let arch = &target.arch; - // See the comment in `va_start` for the purpose of the following. - let va_list = match &**arch { - _ if target.options.is_like_windows => list, - "aarch64" if target.target_os == "ios" => list, - "aarch64" | "x86_64" | "powerpc" => - self.load(list, self.tcx().data_layout.pointer_align.abi), - _ => list, - }; + fn va_end(&mut self, va_list: &'ll Value) -> &'ll Value { let intrinsic = self.cx().get_intrinsic("llvm.va_end"); self.call(intrinsic, &[va_list], None) } diff --git a/src/librustc_codegen_llvm/va_arg.rs b/src/librustc_codegen_llvm/va_arg.rs index 410e00fe0b88..86b0ad761af6 100644 --- a/src/librustc_codegen_llvm/va_arg.rs +++ b/src/librustc_codegen_llvm/va_arg.rs @@ -132,16 +132,6 @@ pub(super) fn emit_va_arg( // For all other architecture/OS combinations fall back to using // the LLVM va_arg instruction. // https://llvm.org/docs/LangRef.html#va-arg-instruction - _ => { - let va_list = if (target.arch == "aarch64" || - target.arch == "x86_64" || - target.arch == "powerpc") && - !target.options.is_like_windows { - bx.load(addr.immediate(), bx.tcx().data_layout.pointer_align.abi) - } else { - addr.immediate() - }; - bx.va_arg(va_list, bx.cx.layout_of(target_ty).llvm_type(bx.cx)) - } + _ => bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)) } } diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index e4b82d849666..cee9c9009a22 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -503,7 +503,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return; } - // The "spoofed" `VaList` added to a C-variadic functions signature + // The "spoofed" `VaListImpl` added to a C-variadic functions signature // should not be included in the `extra_args` calculation. let extra_args_start_idx = sig.inputs().len() - if sig.c_variadic { 1 } else { 0 }; let extra_args = &args[extra_args_start_idx..]; @@ -687,7 +687,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (&args[..], None) }; - // Useful determining if the current argument is the "spoofed" `VaList` + // Useful determining if the current argument is the "spoofed" `VaListImpl` let last_arg_idx = if sig.inputs().is_empty() { None } else { @@ -695,7 +695,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; 'make_args: for (i, arg) in first_args.iter().enumerate() { // If this is a C-variadic function the function signature contains - // an "spoofed" `VaList`. This argument is ignored, but we need to + // an "spoofed" `VaListImpl`. This argument is ignored, but we need to // populate it with a dummy operand so that the users real arguments // are not overwritten. let i = if sig.c_variadic && last_arg_idx.map(|x| i >= x).unwrap_or(false) { diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index dd69d3583131..df3823dd9ca2 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -83,7 +83,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> { scopes: IndexVec>, /// If this function is a C-variadic function, this contains the `PlaceRef` of the - /// "spoofed" `VaList`. + /// "spoofed" `VaListImpl`. va_list_ref: Option>, } @@ -561,35 +561,24 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( indirect_operand.store(bx, tmp); tmp } else { + let tmp = PlaceRef::alloca(bx, arg.layout, &name); if fx.fn_ty.c_variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) { - let va_list_impl = match arg_decl.ty.ty_adt_def() { - Some(adt) => adt.non_enum_variant(), - None => bug!("`va_list` language item improperly constructed") + let va_list_did = match tcx.lang_items().va_list() { + Some(did) => did, + None => bug!("`va_list` lang item required for C-variadic functions"), }; - match tcx.type_of(va_list_impl.fields[0].did).sty { - ty::Ref(_, ty, _) => { - // If the underlying structure the `VaList` contains is a structure, - // we need to allocate it (e.g., X86_64 on Linux). - let tmp = PlaceRef::alloca(bx, arg.layout, &name); - if let ty::Adt(..) = ty.sty { - let layout = bx.layout_of(ty); - // Create an unnamed allocation for the backing structure - // and store it in the the spoofed `VaList`. - let backing = PlaceRef::alloca(bx, layout, ""); - bx.store(backing.llval, tmp.llval, layout.align.abi); - } - // Call `va_start` on the spoofed `VaList`. + match arg_decl.ty.sty { + ty::Adt(def, _) if def.did == va_list_did => { + // Call `va_start` on the spoofed `VaListImpl`. bx.va_start(tmp.llval); *va_list_ref = Some(tmp); - tmp - } - _ => bug!("improperly constructed `va_list` lang item"), + }, + _ => bug!("last argument of variadic function is not a `va_list`") } } else { - let tmp = PlaceRef::alloca(bx, arg.layout, &name); bx.store_fn_arg(arg, &mut llarg_idx, tmp); - tmp } + tmp }; let upvar_debuginfo = &mir.__upvar_debuginfo_codegen_only_do_not_use; arg_scope.map(|scope| { diff --git a/src/librustc_codegen_ssa/traits/intrinsic.rs b/src/librustc_codegen_ssa/traits/intrinsic.rs index cd5278989778..ede30a0bed75 100644 --- a/src/librustc_codegen_ssa/traits/intrinsic.rs +++ b/src/librustc_codegen_ssa/traits/intrinsic.rs @@ -20,10 +20,10 @@ pub trait IntrinsicCallMethods<'tcx>: BackendTypes { fn abort(&mut self); fn assume(&mut self, val: Self::Value); fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value; - /// Trait method used to inject `va_start` on the "spoofed" `VaList` in + /// Trait method used to inject `va_start` on the "spoofed" `VaListImpl` in /// Rust defined C-variadic functions. fn va_start(&mut self, val: Self::Value) -> Self::Value; - /// Trait method used to inject `va_end` on the "spoofed" `VaList` before + /// Trait method used to inject `va_end` on the "spoofed" `VaListImpl` before /// Rust defined C-variadic functions return. fn va_end(&mut self, val: Self::Value) -> Self::Value; } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index a843ee6d45d8..3b159e5da27e 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -892,7 +892,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { let sig = self.cx.tcx.fn_sig(def_id); let sig = self.cx.tcx.erase_late_bound_regions(&sig); let inputs = if sig.c_variadic { - // Don't include the spoofed `VaList` in the functions list + // Don't include the spoofed `VaListImpl` in the functions list // of inputs. &sig.inputs()[..sig.inputs().len() - 1] } else { diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index ad79f2109207..6767a820e6fd 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1695,7 +1695,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { from_hir_call: bool, ) { debug!("check_call_inputs({:?}, {:?})", sig, args); - // Do not count the `VaList` argument as a "true" argument to + // Do not count the `VaListImpl` argument as a "true" argument to // a C-variadic function. let inputs = if sig.c_variadic { &sig.inputs()[..sig.inputs().len() - 1] diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 7f690b6e828a..8c2b8d1565f2 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -83,12 +83,15 @@ pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx>, it: &hir::ForeignItem) { let param = |n| tcx.mk_ty_param(n, InternedString::intern(&format!("P{}", n))); let name = it.ident.as_str(); - let mk_va_list_ty = || { + let mk_va_list_ty = |mutbl| { tcx.lang_items().va_list().map(|did| { let region = tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(0))); let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv); let va_list_ty = tcx.type_of(did).subst(tcx, &[region.into()]); - tcx.mk_mut_ref(tcx.mk_region(env_region), va_list_ty) + (tcx.mk_ref(tcx.mk_region(env_region), ty::TypeAndMut { + ty: va_list_ty, + mutbl + }), va_list_ty) }) }; @@ -340,42 +343,25 @@ pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx>, it: &hir::ForeignItem) { } "va_start" | "va_end" => { - match mk_va_list_ty() { - Some(va_list_ty) => (0, vec![va_list_ty], tcx.mk_unit()), + match mk_va_list_ty(hir::MutMutable) { + Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], tcx.mk_unit()), None => bug!("`va_list` language item needed for C-variadic intrinsics") } } "va_copy" => { - match tcx.lang_items().va_list() { - Some(did) => { - let region = tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(0))); - let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv); - let va_list_ty = tcx.type_of(did).subst(tcx, &[region.into()]); - let ret_ty = match va_list_ty.sty { - ty::Adt(def, _) if def.is_struct() => { - let fields = &def.non_enum_variant().fields; - match tcx.type_of(fields[0].did).subst(tcx, &[region.into()]).sty { - ty::Ref(_, element_ty, _) => match element_ty.sty { - ty::Adt(..) => element_ty, - _ => va_list_ty - } - _ => bug!("va_list structure is invalid") - } - } - _ => { - bug!("va_list structure is invalid") - } - }; - (0, vec![tcx.mk_imm_ref(tcx.mk_region(env_region), va_list_ty)], ret_ty) + match mk_va_list_ty(hir::MutImmutable) { + Some((va_list_ref_ty, va_list_ty)) => { + let va_list_ptr_ty = tcx.mk_mut_ptr(va_list_ty); + (0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.mk_unit()) } None => bug!("`va_list` language item needed for C-variadic intrinsics") } } "va_arg" => { - match mk_va_list_ty() { - Some(va_list_ty) => (1, vec![va_list_ty], param(0)), + match mk_va_list_ty(hir::MutMutable) { + Some((va_list_ref_ty, _)) => (1, vec![va_list_ref_ty], param(0)), None => bug!("`va_list` language item needed for C-variadic intrinsics") } } diff --git a/src/libstd/ffi/mod.rs b/src/libstd/ffi/mod.rs index 7a38f0ebd5a5..69fcfa8b39ca 100644 --- a/src/libstd/ffi/mod.rs +++ b/src/libstd/ffi/mod.rs @@ -170,7 +170,7 @@ pub use core::ffi::c_void; reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930")] -pub use core::ffi::VaList; +pub use core::ffi::{VaList, VaListImpl}; mod c_str; mod os_str; diff --git a/src/test/auxiliary/rust_test_helpers.c b/src/test/auxiliary/rust_test_helpers.c index 27a26d244c23..7f2afd9c5715 100644 --- a/src/test/auxiliary/rust_test_helpers.c +++ b/src/test/auxiliary/rust_test_helpers.c @@ -216,20 +216,27 @@ uint64_t get_c_many_params(void *a, void *b, void *c, void *d, struct quad f) { } // Calculates the average of `(x + y) / n` where x: i64, y: f64. There must be exactly n pairs -// passed as variadic arguments. -double rust_interesting_average(uint64_t n, ...) { - va_list pairs; +// passed as variadic arguments. There are two versions of this function: the +// variadic one, and the one that takes a `va_list`. +double rust_valist_interesting_average(uint64_t n, va_list pairs) { double sum = 0.0; int i; - va_start(pairs, n); for(i = 0; i < n; i += 1) { sum += (double)va_arg(pairs, int64_t); sum += va_arg(pairs, double); } - va_end(pairs); return sum / n; } +double rust_interesting_average(uint64_t n, ...) { + double sum; + va_list pairs; + va_start(pairs, n); + sum = rust_valist_interesting_average(n, pairs); + va_end(pairs); + return sum; +} + int32_t rust_int8_to_int32(int8_t x) { return (int32_t)x; } diff --git a/src/test/codegen/c-variadic-copy.rs b/src/test/codegen/c-variadic-copy.rs new file mode 100644 index 000000000000..4c61c4fcf68d --- /dev/null +++ b/src/test/codegen/c-variadic-copy.rs @@ -0,0 +1,16 @@ +// Tests that `VaListImpl::clone` gets inlined into a call to `llvm.va_copy` + +#![crate_type = "lib"] +#![feature(c_variadic)] +#![no_std] +use core::ffi::VaList; + +extern "C" { + fn foreign_c_variadic_1(_: VaList, ...); +} + +pub unsafe extern "C" fn clone_variadic(ap: VaList) { + let mut ap2 = ap.clone(); + // CHECK: call void @llvm.va_copy + foreign_c_variadic_1(ap2.as_va_list(), 42i32); +} diff --git a/src/test/codegen/c-variadic-opt.rs b/src/test/codegen/c-variadic-opt.rs index 8594d309b0a5..969dce80f587 100644 --- a/src/test/codegen/c-variadic-opt.rs +++ b/src/test/codegen/c-variadic-opt.rs @@ -10,10 +10,21 @@ extern "C" { } // Ensure that `va_start` and `va_end` are properly injected even -// when the "spoofed" `VaList` is not used. +// when the "spoofed" `VaListImpl` is not used. #[no_mangle] pub unsafe extern "C" fn c_variadic_no_use(fmt: *const i8, mut ap: ...) -> i32 { // CHECK: call void @llvm.va_start - vprintf(fmt, ap) + vprintf(fmt, ap.as_va_list()) + // CHECK: call void @llvm.va_end +} + +// Check that `VaListImpl::clone` gets inlined into a direct call to `llvm.va_copy` +#[no_mangle] +pub unsafe extern "C" fn c_variadic_clone(fmt: *const i8, mut ap: ...) -> i32 { + // CHECK: call void @llvm.va_start + let mut ap2 = ap.clone(); + // CHECK: call void @llvm.va_copy + let res = vprintf(fmt, ap2.as_va_list()); + res // CHECK: call void @llvm.va_end } diff --git a/src/test/codegen/c-variadic.rs b/src/test/codegen/c-variadic.rs index 09c18ed90b21..13be5ced27fa 100644 --- a/src/test/codegen/c-variadic.rs +++ b/src/test/codegen/c-variadic.rs @@ -23,7 +23,7 @@ pub unsafe extern "C" fn use_foreign_c_variadic_0() { } // Ensure that we do not remove the `va_list` passed to the foreign function when -// removing the "spoofed" `VaList` that is used by Rust defined C-variadics. +// removing the "spoofed" `VaListImpl` that is used by Rust defined C-variadics. pub unsafe extern "C" fn use_foreign_c_variadic_1_0(ap: VaList) { // CHECK: invoke void ({{.*}}*, ...) @foreign_c_variadic_1({{.*}} %ap) foreign_c_variadic_1(ap); diff --git a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs index 163d50c4e4b4..a0a5b141ec0e 100644 --- a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs +++ b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs @@ -88,6 +88,6 @@ pub unsafe extern "C" fn check_varargs_1(_: c_int, mut ap: ...) -> usize { } #[no_mangle] -pub unsafe extern "C" fn check_varargs_2(_: c_int, mut ap: ...) -> usize { +pub unsafe extern "C" fn check_varargs_2(_: c_int, _ap: ...) -> usize { 0 } diff --git a/src/test/run-pass/variadic-ffi.rs b/src/test/run-pass/variadic-ffi.rs index 3539c8d6b72a..d6fbb1773b29 100644 --- a/src/test/run-pass/variadic-ffi.rs +++ b/src/test/run-pass/variadic-ffi.rs @@ -1,8 +1,45 @@ // ignore-wasm32-bare no libc to test ffi with +#![feature(c_variadic)] + +use std::ffi::VaList; #[link(name = "rust_test_helpers", kind = "static")] extern { fn rust_interesting_average(_: u64, ...) -> f64; + + // FIXME: we need to disable this lint for `VaList`, + // since it contains a `MaybeUninit` on the asmjs target, + // and this type isn't FFI-safe. This is OK for now, + // since the type is layout-compatible with `i32`. + #[cfg_attr(target_arch = "asmjs", allow(improper_ctypes))] + fn rust_valist_interesting_average(_: u64, _: VaList) -> f64; +} + +pub unsafe extern "C" fn test_valist_forward(n: u64, mut ap: ...) -> f64 { + rust_valist_interesting_average(n, ap.as_va_list()) +} + +pub unsafe extern "C" fn test_va_copy(_: u64, mut ap: ...) { + let mut ap2 = ap.clone(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 30); + + // Advance one pair in the copy before checking + let mut ap2 = ap.clone(); + let _ = ap2.arg::(); + let _ = ap2.arg::(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 50); + + // Advance one pair in the original + let _ = ap.arg::(); + let _ = ap.arg::(); + + let mut ap2 = ap.clone(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 50); + + let mut ap2 = ap.clone(); + let _ = ap2.arg::(); + let _ = ap2.arg::(); + assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 70); } pub fn main() { @@ -35,4 +72,12 @@ pub fn main() { let x: unsafe extern fn(u64, ...) -> f64 = rust_interesting_average; call(x); } + + unsafe { + assert_eq!(test_valist_forward(2, 10i64, 10f64, 20i64, 20f64) as i64, 30); + } + + unsafe { + test_va_copy(4, 10i64, 10f64, 20i64, 20f64, 30i64, 30f64, 40i64, 40f64); + } } diff --git a/src/test/ui/c-variadic/variadic-ffi-1.stderr b/src/test/ui/c-variadic/variadic-ffi-1.stderr index e16d15a98bf9..695eba2a7ee4 100644 --- a/src/test/ui/c-variadic/variadic-ffi-1.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-1.stderr @@ -29,7 +29,7 @@ LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo; | ^^^ expected non-variadic fn, found variadic function | = note: expected type `unsafe extern "C" fn(isize, u8)` - found type `for<'r> unsafe extern "C" fn(isize, u8, std::ffi::VaList<'r>, ...) {foo}` + found type `for<'r> unsafe extern "C" fn(isize, u8, std::ffi::VaListImpl<'r>, ...) {foo}` error[E0308]: mismatched types --> $DIR/variadic-ffi-1.rs:20:54 @@ -37,7 +37,7 @@ error[E0308]: mismatched types LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar; | ^^^ expected variadic fn, found non-variadic function | - = note: expected type `for<'r> extern "C" fn(isize, u8, std::ffi::VaList<'r>, ...)` + = note: expected type `for<'r> extern "C" fn(isize, u8, std::ffi::VaListImpl<'r>, ...)` found type `extern "C" fn(isize, u8) {bar}` error[E0617]: can't pass `f32` to variadic function diff --git a/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr b/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr index a1afbb06390f..3c5131835b57 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr @@ -1,16 +1,16 @@ error[E0621]: explicit lifetime required in the type of `ap` --> $DIR/variadic-ffi-4.rs:8:5 | -LL | pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { - | --- help: add explicit lifetime `'a` to the type of `ap`: `core::ffi::VaList<'a>` +LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { + | --- help: add explicit lifetime `'f` to the type of `ap`: `core::ffi::VaListImpl<'f>` LL | ap - | ^^ lifetime `'a` required + | ^^ lifetime `'f` required error[E0621]: explicit lifetime required in the type of `ap` --> $DIR/variadic-ffi-4.rs:12:5 | -LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { - | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaList<'static>` +LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { + | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaListImpl<'static>` LL | ap | ^^ lifetime `'static` required @@ -20,43 +20,43 @@ error: lifetime may not live long enough LL | let _ = ap.with_copy(|ap| { ap }); | --- ^^ returning this value requires that `'1` must outlive `'2` | | | - | | return type of closure is core::ffi::VaList<'2> - | has type `core::ffi::VaList<'1>` + | | return type of closure is core::ffi::VaList<'2, '_> + | has type `core::ffi::VaList<'1, '_>` error: lifetime may not live long enough --> $DIR/variadic-ffi-4.rs:20:5 | -LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaList, mut ap1: ...) { - | ------- ------- has type `core::ffi::VaList<'1>` +LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { + | ------- ------- has type `core::ffi::VaListImpl<'1>` | | - | has type `&mut core::ffi::VaList<'2>` + | has type `&mut core::ffi::VaListImpl<'2>` LL | *ap0 = ap1; - | ^^^^^^^^^^ assignment requires that `'1` must outlive `'2` + | ^^^^ assignment requires that `'1` must outlive `'2` error: lifetime may not live long enough --> $DIR/variadic-ffi-4.rs:24:5 | -LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { - | --- ------- has type `core::ffi::VaList<'2>` +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { + | --- ------- has type `core::ffi::VaListImpl<'2>` | | - | has type `&mut core::ffi::VaList<'1>` + | has type `&mut core::ffi::VaListImpl<'1>` LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` error: lifetime may not live long enough --> $DIR/variadic-ffi-4.rs:24:5 | -LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { - | --- ------- has type `core::ffi::VaList<'1>` +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { + | --- ------- has type `core::ffi::VaListImpl<'1>` | | - | has type `&mut core::ffi::VaList<'2>` + | has type `&mut core::ffi::VaListImpl<'2>` LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` error[E0384]: cannot assign to immutable argument `ap0` --> $DIR/variadic-ffi-4.rs:24:5 | -LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { | --- help: make this binding mutable: `mut ap0` LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ cannot assign to immutable argument @@ -64,7 +64,7 @@ LL | ap0 = &mut ap1; error[E0597]: `ap1` does not live long enough --> $DIR/variadic-ffi-4.rs:24:11 | -LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { | - let's call the lifetime of this reference `'1` LL | ap0 = &mut ap1; | ------^^^^^^^^ @@ -73,9 +73,19 @@ LL | ap0 = &mut ap1; | assignment requires that `ap1` is borrowed for `'1` ... LL | } - | - `ap1` dropped here while still borrowed + | - `ap1` dropped here while still borrowed -error: aborting due to 8 previous errors +error: lifetime may not live long enough + --> $DIR/variadic-ffi-4.rs:32:5 + | +LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { + | ------- ------- has type `core::ffi::VaListImpl<'1>` + | | + | has type `&mut core::ffi::VaListImpl<'2>` +LL | *ap0 = ap1.clone(); + | ^^^^ assignment requires that `'1` must outlive `'2` + +error: aborting due to 9 previous errors Some errors have detailed explanations: E0384, E0597, E0621. For more information about an error, try `rustc --explain E0384`. diff --git a/src/test/ui/c-variadic/variadic-ffi-4.rs b/src/test/ui/c-variadic/variadic-ffi-4.rs index 1c77479d02f4..07c32ecbfc2d 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.rs +++ b/src/test/ui/c-variadic/variadic-ffi-4.rs @@ -2,13 +2,13 @@ #![no_std] #![feature(c_variadic)] -use core::ffi::VaList; +use core::ffi::{VaList, VaListImpl}; -pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { +pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { ap //~ ERROR: explicit lifetime required } -pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { +pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { ap //~ ERROR: explicit lifetime required } @@ -16,14 +16,18 @@ pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { let _ = ap.with_copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime } -pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaList, mut ap1: ...) { +pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { *ap0 = ap1; //~ ERROR: mismatched types } -pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { ap0 = &mut ap1; - //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long + //~^ ERROR: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long //~^^ ERROR: mismatched types //~^^^ ERROR: mismatched types //~^^^^ ERROR: cannot infer an appropriate lifetime } + +pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { + *ap0 = ap1.clone(); //~ ERROR: cannot infer an appropriate lifetime +} diff --git a/src/test/ui/c-variadic/variadic-ffi-4.stderr b/src/test/ui/c-variadic/variadic-ffi-4.stderr index 80b765671c5d..72d4d8b63445 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-4.stderr @@ -1,16 +1,16 @@ error[E0621]: explicit lifetime required in the type of `ap` --> $DIR/variadic-ffi-4.rs:8:5 | -LL | pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { - | --- help: add explicit lifetime `'a` to the type of `ap`: `core::ffi::VaList<'a>` +LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { + | --- help: add explicit lifetime `'f` to the type of `ap`: `core::ffi::VaListImpl<'f>` LL | ap - | ^^ lifetime `'a` required + | ^^ lifetime `'f` required error[E0621]: explicit lifetime required in the type of `ap` --> $DIR/variadic-ffi-4.rs:12:5 | -LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { - | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaList<'static>` +LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { + | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaListImpl<'static>` LL | ap | ^^ lifetime `'static` required @@ -26,14 +26,14 @@ note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on th LL | let _ = ap.with_copy(|ap| { ap }); | ^^^^^^^^^^^ = note: ...so that the expression is assignable: - expected core::ffi::VaList<'_> - found core::ffi::VaList<'_> + expected core::ffi::VaList<'_, '_> + found core::ffi::VaList<'_, '_> note: but, the lifetime must be valid for the method call at 16:13... --> $DIR/variadic-ffi-4.rs:16:13 | LL | let _ = ap.with_copy(|ap| { ap }); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...so type `core::ffi::VaList<'_>` of expression is valid during the expression +note: ...so type `core::ffi::VaList<'_, '_>` of expression is valid during the expression --> $DIR/variadic-ffi-4.rs:16:13 | LL | let _ = ap.with_copy(|ap| { ap }); @@ -45,24 +45,24 @@ error[E0308]: mismatched types LL | *ap0 = ap1; | ^^^ lifetime mismatch | - = note: expected type `core::ffi::VaList<'_>` - found type `core::ffi::VaList<'_>` + = note: expected type `core::ffi::VaListImpl<'_>` + found type `core::ffi::VaListImpl<'_>` note: the anonymous lifetime #3 defined on the function body at 19:1... --> $DIR/variadic-ffi-4.rs:19:1 | -LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1; LL | | } | |_^ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 19:1 --> $DIR/variadic-ffi-4.rs:19:1 | -LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1; LL | | } | |_^ -error[E0490]: a value of type `core::ffi::VaList<'_>` is borrowed for too long +error[E0490]: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; @@ -71,7 +71,7 @@ LL | ap0 = &mut ap1; note: the type is valid for the anonymous lifetime #1 defined on the function body at 23:1 --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -82,7 +82,7 @@ LL | | } note: but the borrow lasts for the anonymous lifetime #3 defined on the function body at 23:1 --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -97,12 +97,12 @@ error[E0308]: mismatched types LL | ap0 = &mut ap1; | ^^^^^^^^ lifetime mismatch | - = note: expected type `&mut core::ffi::VaList<'_>` - found type `&mut core::ffi::VaList<'_>` + = note: expected type `&mut core::ffi::VaListImpl<'_>` + found type `&mut core::ffi::VaListImpl<'_>` note: the anonymous lifetime #3 defined on the function body at 23:1... --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -113,7 +113,7 @@ LL | | } note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 23:1 --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -128,12 +128,12 @@ error[E0308]: mismatched types LL | ap0 = &mut ap1; | ^^^^^^^^ lifetime mismatch | - = note: expected type `&mut core::ffi::VaList<'_>` - found type `&mut core::ffi::VaList<'_>` + = note: expected type `&mut core::ffi::VaListImpl<'_>` + found type `&mut core::ffi::VaListImpl<'_>` note: the anonymous lifetime #2 defined on the function body at 23:1... --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -144,7 +144,7 @@ LL | | } note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 23:1 --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -162,7 +162,7 @@ LL | ap0 = &mut ap1; note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 23:1... --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -170,7 +170,7 @@ LL | | LL | | LL | | } | |_^ -note: ...so that the type `core::ffi::VaList<'_>` is not borrowed for too long +note: ...so that the type `core::ffi::VaListImpl<'_>` is not borrowed for too long --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; @@ -178,7 +178,7 @@ LL | ap0 = &mut ap1; note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the function body at 23:1... --> $DIR/variadic-ffi-4.rs:23:1 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | @@ -192,7 +192,34 @@ note: ...so that reference does not outlive borrowed content LL | ap0 = &mut ap1; | ^^^^^^^^ -error: aborting due to 8 previous errors +error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements + --> $DIR/variadic-ffi-4.rs:32:16 + | +LL | *ap0 = ap1.clone(); + | ^^^^^ + | +note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 31:1... + --> $DIR/variadic-ffi-4.rs:31:1 + | +LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | | *ap0 = ap1.clone(); +LL | | } + | |_^ + = note: ...so that the types are compatible: + expected &core::ffi::VaListImpl<'_> + found &core::ffi::VaListImpl<'_> +note: but, the lifetime must be valid for the anonymous lifetime #2 defined on the function body at 31:1... + --> $DIR/variadic-ffi-4.rs:31:1 + | +LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | | *ap0 = ap1.clone(); +LL | | } + | |_^ + = note: ...so that the expression is assignable: + expected core::ffi::VaListImpl<'_> + found core::ffi::VaListImpl<'_> + +error: aborting due to 9 previous errors Some errors have detailed explanations: E0308, E0621. For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/error-codes/E0617.rs b/src/test/ui/error-codes/E0617.rs index 51f13c7dbd54..439c3db57686 100644 --- a/src/test/ui/error-codes/E0617.rs +++ b/src/test/ui/error-codes/E0617.rs @@ -22,7 +22,7 @@ fn main() { //~^ ERROR can't pass `u16` to variadic function //~| HELP cast the value to `c_uint` printf(::std::ptr::null(), printf); - //~^ ERROR can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...) {printf}` to variadic function - //~| HELP cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...)` + //~^ ERROR can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...) {printf}` to variadic function + //~| HELP cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...)` } } diff --git a/src/test/ui/error-codes/E0617.stderr b/src/test/ui/error-codes/E0617.stderr index 8387d5c7e93a..d866320bbcdf 100644 --- a/src/test/ui/error-codes/E0617.stderr +++ b/src/test/ui/error-codes/E0617.stderr @@ -28,15 +28,15 @@ error[E0617]: can't pass `u16` to variadic function LL | printf(::std::ptr::null(), 0u16); | ^^^^ help: cast the value to `c_uint`: `0u16 as c_uint` -error[E0617]: can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...) {printf}` to variadic function +error[E0617]: can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...) {printf}` to variadic function --> $DIR/E0617.rs:24:36 | LL | printf(::std::ptr::null(), printf); | ^^^^^^ -help: cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...)` +help: cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...)` | -LL | printf(::std::ptr::null(), printf as for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | printf(::std::ptr::null(), printf as for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/symbol-names/impl1.rs b/src/test/ui/symbol-names/impl1.rs index 9ed93bb98185..52bb118fa23a 100644 --- a/src/test/ui/symbol-names/impl1.rs +++ b/src/test/ui/symbol-names/impl1.rs @@ -57,7 +57,7 @@ fn main() { } // Test type mangling, by putting them in an `impl` header. - // FIXME(eddyb) test C varargs when `core::ffi::VaList` stops leaking into the signature + // FIXME(eddyb) test C varargs when `core::ffi::VaListImpl` stops leaking into the signature // (which is a problem because `core` has an unpredictable hash) - see also #44930. impl Bar for [&'_ (dyn Foo + AutoTrait); 3] { #[rustc_symbol_name] From 298770406200600be3eedb753d262401b2d59678 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 18 Jun 2019 08:14:03 +0200 Subject: [PATCH 047/109] update miri --- src/tools/miri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri b/src/tools/miri index fd0dccd4b121..e4b298bc4f5a 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit fd0dccd4b12169e0aac42aff8addbb26b6d72197 +Subproject commit e4b298bc4f5a7e86eb78404e25de08f179091e03 From 961ba8f9efbb51d80e7e73a609f6587c0ffa0623 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 16 Jun 2019 18:58:39 +0300 Subject: [PATCH 048/109] syntax: Factor out common fields from `SyntaxExtension` variants --- .../src/language-features/plugin.md | 2 +- src/librustc_allocator/expand.rs | 2 +- src/librustc_metadata/creader.rs | 50 +++-- src/librustc_metadata/cstore_impl.rs | 13 +- src/librustc_metadata/decoder.rs | 7 +- src/librustc_plugin/registry.rs | 22 +-- src/librustc_resolve/build_reduced_graph.rs | 11 +- src/librustc_resolve/macros.rs | 32 ++-- src/librustdoc/clean/inline.rs | 12 +- .../passes/collect_intra_doc_links.rs | 4 +- src/libsyntax/ext/base.rs | 148 +++++++++------ src/libsyntax/ext/derive.rs | 2 +- src/libsyntax/ext/expand.rs | 178 +++++------------- src/libsyntax/ext/tt/macro_rules.rs | 12 +- src/libsyntax/std_inject.rs | 2 +- src/libsyntax/test.rs | 2 +- src/libsyntax_ext/deriving/mod.rs | 21 ++- src/libsyntax_ext/lib.rs | 69 +++---- src/libsyntax_ext/proc_macro_decls.rs | 7 +- src/libsyntax_ext/test.rs | 2 +- src/libsyntax_ext/test_case.rs | 2 +- .../auxiliary/plugin-args.rs | 18 +- 22 files changed, 269 insertions(+), 349 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 1994cf491889..0e38e2865d89 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -132,7 +132,7 @@ The advantages over a simple `fn(&str) -> u32` are: In addition to procedural macros, you can define new [`derive`](../../reference/attributes/derive.md)-like attributes and other kinds of extensions. See `Registry::register_syntax_extension` and the -`SyntaxExtension` enum. For a more involved macro example, see +`SyntaxExtension` struct. For a more involved macro example, see [`regex_macros`](https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs). diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 3ec06b17aff2..ecc165ca5ea9 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -91,7 +91,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> { call_site: item.span, // use the call site of the static def_site: None, format: MacroAttribute(Symbol::intern(name)), - allow_internal_unstable: Some(vec![sym::rustc_attrs].into()), + allow_internal_unstable: Some([sym::rustc_attrs][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: self.sess.edition, diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 5fef8e53e1d0..d3d00fa4adcf 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -26,7 +26,7 @@ use std::{cmp, fs}; use syntax::ast; use syntax::attr; -use syntax::ext::base::SyntaxExtension; +use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; use syntax::symbol::{Symbol, sym}; use syntax::visit; use syntax::{span_err, span_fatal}; @@ -611,33 +611,31 @@ impl<'a> CrateLoader<'a> { }; let extensions = decls.iter().map(|&decl| { - match decl { + let (name, kind, helper_attrs) = match decl { ProcMacro::CustomDerive { trait_name, attributes, client } => { - let attrs = attributes.iter().cloned().map(Symbol::intern).collect::>(); - (trait_name, SyntaxExtension::Derive( - Box::new(ProcMacroDerive { - client, - attrs: attrs.clone(), - }), - attrs, - root.edition, - )) + let helper_attrs = + attributes.iter().cloned().map(Symbol::intern).collect::>(); + ( + trait_name, + SyntaxExtensionKind::Derive(Box::new(ProcMacroDerive { + client, attrs: helper_attrs.clone() + })), + helper_attrs, + ) } - ProcMacro::Attr { name, client } => { - (name, SyntaxExtension::Attr( - Box::new(AttrProcMacro { client }), - root.edition, - )) - } - ProcMacro::Bang { name, client } => { - (name, SyntaxExtension::Bang { - expander: Box::new(BangProcMacro { client }), - allow_internal_unstable: None, - edition: root.edition, - }) - } - } - }).map(|(name, ext)| (Symbol::intern(name), Lrc::new(ext))).collect(); + ProcMacro::Attr { name, client } => ( + name, SyntaxExtensionKind::Attr(Box::new(AttrProcMacro { client })), Vec::new() + ), + ProcMacro::Bang { name, client } => ( + name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new() + ) + }; + + (Symbol::intern(name), Lrc::new(SyntaxExtension { + helper_attrs, + ..SyntaxExtension::default(kind, root.edition) + })) + }).collect(); // Intentionally leak the dynamic library. We can't ever unload it // since the library can make things that will live arbitrarily long. diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 86536b179f22..04a9c4e9a1a1 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -30,9 +30,11 @@ use syntax::ast; use syntax::attr; use syntax::source_map; use syntax::edition::Edition; +use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; use syntax::parse::source_file_to_stream; use syntax::parse::parser::emit_unclosed_delims; use syntax::symbol::{Symbol, sym}; +use syntax_ext::proc_macro_impl::BangProcMacro; use syntax_pos::{Span, NO_EXPANSION, FileName}; use rustc_data_structures::bit_set::BitSet; @@ -427,14 +429,11 @@ impl cstore::CStore { if let Some(ref proc_macros) = data.proc_macros { return LoadedMacro::ProcMacro(proc_macros[id.index.to_proc_macro_index()].1.clone()); } else if data.name == sym::proc_macro && data.item_name(id.index) == sym::quote { - use syntax::ext::base::SyntaxExtension; - use syntax_ext::proc_macro_impl::BangProcMacro; - let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote); - let ext = SyntaxExtension::Bang { - expander: Box::new(BangProcMacro { client }), - allow_internal_unstable: Some(vec![sym::proc_macro_def_site].into()), - edition: data.root.edition, + let kind = SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })); + let ext = SyntaxExtension { + allow_internal_unstable: Some([sym::proc_macro_def_site][..].into()), + ..SyntaxExtension::default(kind, data.root.edition) }; return LoadedMacro::ProcMacro(Lrc::new(ext)); } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 4bafe16b8e66..a776966bda48 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -511,8 +511,9 @@ impl<'a, 'tcx> CrateMetadata { if !self.is_proc_macro(index) { self.entry(index).kind.def_kind() } else { - let kind = self.proc_macros.as_ref().unwrap()[index.to_proc_macro_index()].1.kind(); - Some(DefKind::Macro(kind)) + Some(DefKind::Macro( + self.proc_macros.as_ref().unwrap()[index.to_proc_macro_index()].1.macro_kind() + )) } } @@ -739,7 +740,7 @@ impl<'a, 'tcx> CrateMetadata { if id == CRATE_DEF_INDEX { for (id, &(name, ref ext)) in proc_macros.iter().enumerate() { let res = Res::Def( - DefKind::Macro(ext.kind()), + DefKind::Macro(ext.macro_kind()), self.local_def_id(DefIndex::from_proc_macro_index(id)), ); let ident = Ident::with_empty_ctxt(name); diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs index dd5e42684c42..16d484e2a98f 100644 --- a/src/librustc_plugin/registry.rs +++ b/src/librustc_plugin/registry.rs @@ -4,9 +4,8 @@ use rustc::lint::{EarlyLintPassObject, LateLintPassObject, LintId, Lint}; use rustc::session::Session; use rustc::util::nodemap::FxHashMap; -use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension}; +use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, NamedSyntaxExtension}; use syntax::ext::base::MacroExpanderFn; -use syntax::ext::hygiene::Transparency; use syntax::symbol::{Symbol, sym}; use syntax::ast; use syntax::feature_gate::AttributeType; @@ -89,8 +88,8 @@ impl<'a> Registry<'a> { if name == sym::macro_rules { panic!("user-defined macros may not be named `macro_rules`"); } - if let SyntaxExtension::LegacyBang { def_info: ref mut def_info @ None, .. } = extension { - *def_info = Some((ast::CRATE_NODE_ID, self.krate_span)); + if extension.def_info.is_none() { + extension.def_info = Some((ast::CRATE_NODE_ID, self.krate_span)); } self.syntax_exts.push((name, extension)); } @@ -98,19 +97,12 @@ impl<'a> Registry<'a> { /// Register a macro of the usual kind. /// /// This is a convenience wrapper for `register_syntax_extension`. - /// It builds for you a `SyntaxExtension::LegacyBang` that calls `expander`, + /// It builds for you a `SyntaxExtensionKind::LegacyBang` that calls `expander`, /// and also takes care of interning the macro's name. pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) { - self.register_syntax_extension(Symbol::intern(name), SyntaxExtension::LegacyBang { - expander: Box::new(expander), - def_info: None, - transparency: Transparency::SemiTransparent, - allow_internal_unstable: None, - allow_internal_unsafe: false, - local_inner_macros: false, - unstable_feature: None, - edition: self.sess.edition(), - }); + let kind = SyntaxExtensionKind::LegacyBang(Box::new(expander)); + let ext = SyntaxExtension::default(kind, self.sess.edition()); + self.register_syntax_extension(Symbol::intern(name), ext); } /// Register a compiler lint pass. diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index e3cd2948d7af..bb4edf355f8b 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -29,7 +29,7 @@ use syntax::attr; use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId}; use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant}; -use syntax::ext::base::{MacroKind, SyntaxExtension}; +use syntax::ext::base::{MacroKind, SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::base::Determinacy::Undetermined; use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; @@ -772,9 +772,12 @@ impl<'a> Resolver<'a> { pub fn get_macro(&mut self, res: Res) -> Lrc { let def_id = match res { Res::Def(DefKind::Macro(..), def_id) => def_id, - Res::NonMacroAttr(attr_kind) => return Lrc::new(SyntaxExtension::NonMacroAttr { - mark_used: attr_kind == NonMacroAttrKind::Tool, - }), + Res::NonMacroAttr(attr_kind) => return Lrc::new(SyntaxExtension::default( + SyntaxExtensionKind::NonMacroAttr { + mark_used: attr_kind == NonMacroAttrKind::Tool + }, + self.session.edition(), + )), _ => panic!("expected `DefKind::Macro` or `Res::NonMacroAttr`"), }; if let Some(ext) = self.macro_map.get(&def_id) { diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 2369bddf4f75..89e28330be7e 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -15,7 +15,7 @@ use syntax::ast::{self, Ident}; use syntax::attr; use syntax::errors::DiagnosticBuilder; use syntax::ext::base::{self, Determinacy}; -use syntax::ext::base::{MacroKind, SyntaxExtension}; +use syntax::ext::base::{MacroKind, SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::expand::{AstFragment, Invocation, InvocationKind}; use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; @@ -174,7 +174,7 @@ impl<'a> base::Resolver for Resolver<'a> { krate: CrateNum::BuiltinMacros, index: DefIndex::from(self.macro_map.len()), }; - let kind = ext.kind(); + let kind = ext.macro_kind(); self.macro_map.insert(def_id, ext); let binding = self.arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Res(Res::Def(DefKind::Macro(kind), def_id), false), @@ -211,7 +211,8 @@ impl<'a> base::Resolver for Resolver<'a> { Ok((res, ext)) => (res, ext), Err(Determinacy::Determined) if kind == MacroKind::Attr => { // Replace unresolved attributes with used inert attributes for better recovery. - return Ok(Some(Lrc::new(SyntaxExtension::NonMacroAttr { mark_used: true }))); + let kind = SyntaxExtensionKind::NonMacroAttr { mark_used: true }; + return Ok(Some(Lrc::new(SyntaxExtension::default(kind, self.session.edition())))); } Err(determinacy) => return Err(determinacy), }; @@ -226,7 +227,7 @@ impl<'a> base::Resolver for Resolver<'a> { self.macro_def_scope(invoc.expansion_data.mark).normal_ancestor_id; self.definitions.add_parent_module_of_macro_def(invoc.expansion_data.mark, normal_module_def_id); - invoc.expansion_data.mark.set_default_transparency(ext.default_transparency()); + invoc.expansion_data.mark.set_default_transparency(ext.default_transparency); } Ok(Some(ext)) @@ -241,11 +242,7 @@ impl<'a> base::Resolver for Resolver<'a> { fn check_unused_macros(&self) { for did in self.unused_macros.iter() { - let id_span = match *self.macro_map[did] { - SyntaxExtension::LegacyBang { def_info, .. } => def_info, - _ => None, - }; - if let Some((id, span)) = id_span { + if let Some((id, span)) = self.macro_map[did].def_info { let lint = lint::builtin::UNUSED_MACROS; let msg = "unused macro definition"; self.session.buffer_lint(lint, id, span, msg); @@ -585,17 +582,12 @@ impl<'a> Resolver<'a> { let parent_scope = ParentScope { derives: Vec::new(), ..*parent_scope }; match self.resolve_macro_to_res(derive, MacroKind::Derive, &parent_scope, true, force) { - Ok((_, ext)) => { - if let SyntaxExtension::Derive(_, helpers, _) = &*ext { - if helpers.contains(&ident.name) { - let binding = - (Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper), - ty::Visibility::Public, derive.span, Mark::root()) - .to_name_binding(self.arenas); - result = Ok((binding, Flags::empty())); - break; - } - } + Ok((_, ext)) => if ext.helper_attrs.contains(&ident.name) { + let binding = (Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper), + ty::Visibility::Public, derive.span, Mark::root()) + .to_name_binding(self.arenas); + result = Ok((binding, Flags::empty())); + break; } Err(Determinacy::Determined) => {} Err(Determinacy::Undetermined) => diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index c14ae5932af4..9259b3b5d3ab 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -3,7 +3,7 @@ use std::iter::once; use syntax::ast; -use syntax::ext::base::{MacroKind, SyntaxExtension}; +use syntax::ext::base::MacroKind; use syntax::symbol::sym; use syntax_pos::Span; @@ -470,18 +470,12 @@ fn build_macro(cx: &DocContext<'_>, did: DefId, name: ast::Name) -> clean::ItemE }) } LoadedMacro::ProcMacro(ext) => { - let helpers = match &*ext { - &SyntaxExtension::Derive(_, ref syms, ..) => { syms.clean(cx) } - _ => Vec::new(), - }; - clean::ProcMacroItem(clean::ProcMacro { - kind: ext.kind(), - helpers, + kind: ext.macro_kind(), + helpers: ext.helper_attrs.clean(cx), }) } } - } /// A trait's generics clause actually contains all of the predicates for all of diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 7fbfc3e1fc0f..68b96a408294 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -423,7 +423,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { /// Resolves a string as a macro. fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option { - use syntax::ext::base::{MacroKind, SyntaxExtension}; + use syntax::ext::base::{MacroKind, SyntaxExtensionKind}; let segment = ast::PathSegment::from_ident(Ident::from_str(path_str)); let path = ast::Path { segments: vec![segment], span: DUMMY_SP }; cx.enter_resolver(|resolver| { @@ -433,7 +433,7 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option { if let Res::Def(DefKind::Macro(MacroKind::ProcMacroStub), _) = res { // skip proc-macro stubs, they'll cause `get_macro` to crash } else { - if let SyntaxExtension::LegacyBang { .. } = *resolver.get_macro(res) { + if let SyntaxExtensionKind::LegacyBang(..) = resolver.get_macro(res).kind { return Some(res.map_id(|_| panic!("unexpected id"))); } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 38b7dee40c44..04cef0bba24b 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -15,6 +15,7 @@ use crate::tokenstream::{self, TokenStream}; use errors::{DiagnosticBuilder, DiagnosticId}; use smallvec::{smallvec, SmallVec}; use syntax_pos::{Span, MultiSpan, DUMMY_SP}; +use syntax_pos::hygiene::{ExpnInfo, ExpnFormat}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::{self, Lrc}; @@ -548,37 +549,19 @@ impl MacroKind { } } -/// An enum representing the different kinds of syntax extensions. -pub enum SyntaxExtension { +/// A syntax extension kind. +pub enum SyntaxExtensionKind { /// A token-based function-like macro. - Bang { + Bang( /// An expander with signature TokenStream -> TokenStream. - expander: Box, - /// Whitelist of unstable features that are treated as stable inside this macro. - allow_internal_unstable: Option>, - /// Edition of the crate in which this macro is defined. - edition: Edition, - }, + Box, + ), /// An AST-based function-like macro. - LegacyBang { + LegacyBang( /// An expander with signature TokenStream -> AST. - expander: Box, - /// Some info about the macro's definition point. - def_info: Option<(ast::NodeId, Span)>, - /// Hygienic properties of identifiers produced by this macro. - transparency: Transparency, - /// Whitelist of unstable features that are treated as stable inside this macro. - allow_internal_unstable: Option>, - /// Suppresses the `unsafe_code` lint for code produced by this macro. - allow_internal_unsafe: bool, - /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro. - local_inner_macros: bool, - /// The macro's feature name and tracking issue number if it is unstable. - unstable_feature: Option<(Symbol, u32)>, - /// Edition of the crate in which this macro is defined. - edition: Edition, - }, + Box, + ), /// A token-based attribute macro. Attr( @@ -586,8 +569,6 @@ pub enum SyntaxExtension { /// The first TokenSteam is the attribute itself, the second is the annotated item. /// The produced TokenSteam replaces the input TokenSteam. Box, - /// Edition of the crate in which this macro is defined. - Edition, ), /// An AST-based attribute macro. @@ -599,7 +580,8 @@ pub enum SyntaxExtension { ), /// A trivial attribute "macro" that does nothing, - /// only keeps the attribute and marks it as known. + /// only keeps the attribute and marks it as inert, + /// thus making it ineligible for further expansion. NonMacroAttr { /// Suppresses the `unused_attributes` lint for this attribute. mark_used: bool, @@ -610,10 +592,6 @@ pub enum SyntaxExtension { /// An expander with signature TokenStream -> TokenStream (not yet). /// The produced TokenSteam is appended to the input TokenSteam. Box, - /// Names of helper attributes registered by this macro. - Vec, - /// Edition of the crate in which this macro is defined. - Edition, ), /// An AST-based derive macro. @@ -624,42 +602,90 @@ pub enum SyntaxExtension { ), } +/// A struct representing a macro definition in "lowered" form ready for expansion. +pub struct SyntaxExtension { + /// A syntax extension kind. + pub kind: SyntaxExtensionKind, + /// Some info about the macro's definition point. + pub def_info: Option<(ast::NodeId, Span)>, + /// Hygienic properties of spans produced by this macro by default. + pub default_transparency: Transparency, + /// Whitelist of unstable features that are treated as stable inside this macro. + pub allow_internal_unstable: Option>, + /// Suppresses the `unsafe_code` lint for code produced by this macro. + pub allow_internal_unsafe: bool, + /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro. + pub local_inner_macros: bool, + /// The macro's feature name and tracking issue number if it is unstable. + pub unstable_feature: Option<(Symbol, u32)>, + /// Names of helper attributes registered by this macro. + pub helper_attrs: Vec, + /// Edition of the crate in which this macro is defined. + pub edition: Edition, +} + +impl SyntaxExtensionKind { + /// When a syntax extension is constructed, + /// its transparency can often be inferred from its kind. + fn default_transparency(&self) -> Transparency { + match self { + SyntaxExtensionKind::Bang(..) | + SyntaxExtensionKind::Attr(..) | + SyntaxExtensionKind::Derive(..) | + SyntaxExtensionKind::NonMacroAttr { .. } => Transparency::Opaque, + SyntaxExtensionKind::LegacyBang(..) | + SyntaxExtensionKind::LegacyAttr(..) | + SyntaxExtensionKind::LegacyDerive(..) => Transparency::SemiTransparent, + } + } +} + impl SyntaxExtension { /// Returns which kind of macro calls this syntax extension. - pub fn kind(&self) -> MacroKind { - match *self { - SyntaxExtension::Bang { .. } | - SyntaxExtension::LegacyBang { .. } => MacroKind::Bang, - SyntaxExtension::Attr(..) | - SyntaxExtension::LegacyAttr(..) | - SyntaxExtension::NonMacroAttr { .. } => MacroKind::Attr, - SyntaxExtension::Derive(..) | - SyntaxExtension::LegacyDerive(..) => MacroKind::Derive, + pub fn macro_kind(&self) -> MacroKind { + match self.kind { + SyntaxExtensionKind::Bang(..) | + SyntaxExtensionKind::LegacyBang(..) => MacroKind::Bang, + SyntaxExtensionKind::Attr(..) | + SyntaxExtensionKind::LegacyAttr(..) | + SyntaxExtensionKind::NonMacroAttr { .. } => MacroKind::Attr, + SyntaxExtensionKind::Derive(..) | + SyntaxExtensionKind::LegacyDerive(..) => MacroKind::Derive, } } - pub fn default_transparency(&self) -> Transparency { - match *self { - SyntaxExtension::LegacyBang { transparency, .. } => transparency, - SyntaxExtension::Bang { .. } | - SyntaxExtension::Attr(..) | - SyntaxExtension::Derive(..) | - SyntaxExtension::NonMacroAttr { .. } => Transparency::Opaque, - SyntaxExtension::LegacyAttr(..) | - SyntaxExtension::LegacyDerive(..) => Transparency::SemiTransparent, + /// Constructs a syntax extension with default properties. + pub fn default(kind: SyntaxExtensionKind, edition: Edition) -> SyntaxExtension { + SyntaxExtension { + def_info: None, + default_transparency: kind.default_transparency(), + allow_internal_unstable: None, + allow_internal_unsafe: false, + local_inner_macros: false, + unstable_feature: None, + helper_attrs: Vec::new(), + edition, + kind, } } - pub fn edition(&self, default_edition: Edition) -> Edition { - match *self { - SyntaxExtension::Bang { edition, .. } | - SyntaxExtension::LegacyBang { edition, .. } | - SyntaxExtension::Attr(.., edition) | - SyntaxExtension::Derive(.., edition) => edition, - // Unstable legacy stuff - SyntaxExtension::NonMacroAttr { .. } | - SyntaxExtension::LegacyAttr(..) | - SyntaxExtension::LegacyDerive(..) => default_edition, + fn expn_format(&self, symbol: Symbol) -> ExpnFormat { + match self.kind { + SyntaxExtensionKind::Bang(..) | + SyntaxExtensionKind::LegacyBang(..) => ExpnFormat::MacroBang(symbol), + _ => ExpnFormat::MacroAttribute(symbol), + } + } + + crate fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo { + ExpnInfo { + call_site, + def_site: self.def_info.map(|(_, span)| span), + format: self.expn_format(Symbol::intern(format)), + allow_internal_unstable: self.allow_internal_unstable.clone(), + allow_internal_unsafe: self.allow_internal_unsafe, + local_inner_macros: self.local_inner_macros, + edition: self.edition, } } } diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index a2cf4a2a82d8..33620cb80f94 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -64,7 +64,7 @@ pub fn add_derived_markers(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P call_site: span, def_site: None, format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), - allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::structural_match].into()), + allow_internal_unstable: Some([sym::rustc_attrs, sym::structural_match][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: cx.parse_sess.edition, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 3fa96c60bff6..4e759c5e5286 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1,7 +1,7 @@ use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path}; use crate::ast::{MacStmtStyle, StmtKind, ItemKind}; use crate::attr::{self, HasAttrs}; -use crate::source_map::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan}; +use crate::source_map::{dummy_spanned, respan}; use crate::config::StripUnconfigured; use crate::ext::base::*; use crate::ext::derive::{add_derived_markers, collect_derives}; @@ -22,7 +22,6 @@ use crate::util::map_in_place::MapInPlace; use errors::{Applicability, FatalError}; use smallvec::{smallvec, SmallVec}; use syntax_pos::{Span, DUMMY_SP, FileName}; -use syntax_pos::hygiene::ExpnFormat; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -189,10 +188,10 @@ impl AstFragmentKind { } } -fn macro_bang_format(path: &ast::Path) -> ExpnFormat { - // We don't want to format a path using pretty-printing, - // `format!("{}", path)`, because that tries to insert - // line-breaks and is slow. +// We don't want to format a path using pretty-printing, +// `format!("{}", path)`, because that tries to insert +// line-breaks and is slow. +fn fast_print_path(path: &ast::Path) -> String { let mut path_str = String::with_capacity(64); for (i, segment) in path.segments.iter().enumerate() { if i != 0 { @@ -202,8 +201,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat { path_str.push_str(&segment.ident.as_str()) } } - - MacroBang(Symbol::intern(&path_str)) + path_str } pub struct Invocation { @@ -388,8 +386,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { derives.push(mark); let item = match self.cx.resolver.resolve_macro_path( path, MacroKind::Derive, Mark::root(), Vec::new(), false) { - Ok(ext) => match *ext { - SyntaxExtension::LegacyDerive(..) => item_with_markers.clone(), + Ok(ext) => match ext.kind { + SyntaxExtensionKind::LegacyDerive(..) => item_with_markers.clone(), _ => item.clone(), }, _ => item.clone(), @@ -509,7 +507,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtension) -> Option { if invoc.fragment_kind == AstFragmentKind::ForeignItems && !self.cx.ecfg.macros_in_extern_enabled() { - if let SyntaxExtension::NonMacroAttr { .. } = *ext {} else { + if let SyntaxExtensionKind::NonMacroAttr { .. } = ext.kind {} else { emit_feature_err(&self.cx.parse_sess, sym::macros_in_extern, invoc.span(), GateIssue::Language, "macro invocations in `extern {}` blocks are experimental"); @@ -548,34 +546,25 @@ impl<'a, 'b> MacroExpander<'a, 'b> { _ => unreachable!(), }; - if let SyntaxExtension::NonMacroAttr { mark_used: false } = *ext {} else { - // Macro attrs are always used when expanded, - // non-macro attrs are considered used when the field says so. - attr::mark_used(&attr); - } - invoc.expansion_data.mark.set_expn_info(ExpnInfo { - call_site: attr.span, - def_site: None, - format: MacroAttribute(Symbol::intern(&attr.path.to_string())), - allow_internal_unstable: None, - allow_internal_unsafe: false, - local_inner_macros: false, - edition: ext.edition(self.cx.parse_sess.edition), - }); + let expn_info = ext.expn_info(attr.span, &fast_print_path(&attr.path)); + invoc.expansion_data.mark.set_expn_info(expn_info); - match *ext { - SyntaxExtension::NonMacroAttr { .. } => { + match &ext.kind { + SyntaxExtensionKind::NonMacroAttr { mark_used } => { attr::mark_known(&attr); + if *mark_used { + attr::mark_used(&attr); + } item.visit_attrs(|attrs| attrs.push(attr)); Some(invoc.fragment_kind.expect_from_annotatables(iter::once(item))) } - SyntaxExtension::LegacyAttr(ref mac) => { + SyntaxExtensionKind::LegacyAttr(expander) => { let meta = attr.parse_meta(self.cx.parse_sess) .map_err(|mut e| { e.emit(); }).ok()?; - let item = mac.expand(self.cx, attr.span, &meta, item); + let item = expander.expand(self.cx, attr.span, &meta, item); Some(invoc.fragment_kind.expect_from_annotatables(item)) } - SyntaxExtension::Attr(ref mac, ..) => { + SyntaxExtensionKind::Attr(expander) => { self.gate_proc_macro_attr_item(attr.span, &item); let item_tok = TokenTree::token(token::Interpolated(Lrc::new(match item { Annotatable::Item(item) => token::NtItem(item), @@ -586,13 +575,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { Annotatable::Expr(expr) => token::NtExpr(expr), })), DUMMY_SP).into(); let input = self.extract_proc_macro_attr_input(attr.tokens, attr.span); - let tok_result = mac.expand(self.cx, attr.span, input, item_tok); + let tok_result = expander.expand(self.cx, attr.span, input, item_tok); let res = self.parse_ast_fragment(tok_result, invoc.fragment_kind, &attr.path, attr.span); self.gate_proc_macro_expansion(attr.span, &res); res } - SyntaxExtension::Derive(..) | SyntaxExtension::LegacyDerive(..) => { + SyntaxExtensionKind::Derive(..) | SyntaxExtensionKind::LegacyDerive(..) => { self.cx.span_err(attr.span, &format!("`{}` is a derive macro", attr.path)); self.cx.trace_macros_diag(); invoc.fragment_kind.dummy(attr.span) @@ -701,21 +690,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let path = &mac.node.path; let ident = ident.unwrap_or_else(|| Ident::invalid()); - let validate_and_set_expn_info = |this: &mut Self, // arg instead of capture - def_site_span: Option, - allow_internal_unstable, - allow_internal_unsafe, - local_inner_macros, - // can't infer this type - unstable_feature: Option<(Symbol, u32)>, - edition| { - + let validate_and_set_expn_info = |this: &mut Self| { // feature-gate the macro invocation - if let Some((feature, issue)) = unstable_feature { + if let Some((feature, issue)) = ext.unstable_feature { let crate_span = this.cx.current_expansion.crate_span.unwrap(); // don't stability-check macros in the same crate // (the only time this is null is for syntax extensions registered as macros) - if def_site_span.map_or(false, |def_span| !crate_span.contains(def_span)) + if ext.def_info.map_or(false, |(_, def_span)| !crate_span.contains(def_span)) && !span.allows_unstable(feature) && this.cx.ecfg.features.map_or(true, |feats| { // macro features will count as lib features @@ -734,62 +715,40 @@ impl<'a, 'b> MacroExpander<'a, 'b> { this.cx.trace_macros_diag(); return Err(kind.dummy(span)); } - mark.set_expn_info(ExpnInfo { - call_site: span, - def_site: def_site_span, - format: macro_bang_format(path), - allow_internal_unstable, - allow_internal_unsafe, - local_inner_macros, - edition, - }); + mark.set_expn_info(ext.expn_info(span, &fast_print_path(path))); Ok(()) }; - let opt_expanded = match *ext { - SyntaxExtension::LegacyBang { - ref expander, - def_info, - ref allow_internal_unstable, - allow_internal_unsafe, - local_inner_macros, - unstable_feature, - edition, - .. - } => { - if let Err(dummy_span) = validate_and_set_expn_info(self, def_info.map(|(_, s)| s), - allow_internal_unstable.clone(), - allow_internal_unsafe, - local_inner_macros, - unstable_feature, - edition) { + let opt_expanded = match &ext.kind { + SyntaxExtensionKind::LegacyBang(expander) => { + if let Err(dummy_span) = validate_and_set_expn_info(self) { dummy_span } else { kind.make_from(expander.expand( self.cx, span, mac.node.stream(), - def_info.map(|(_, s)| s), + ext.def_info.map(|(_, s)| s), )) } } - SyntaxExtension::Attr(..) | - SyntaxExtension::LegacyAttr(..) | - SyntaxExtension::NonMacroAttr { .. } => { + SyntaxExtensionKind::Attr(..) | + SyntaxExtensionKind::LegacyAttr(..) | + SyntaxExtensionKind::NonMacroAttr { .. } => { self.cx.span_err(path.span, &format!("`{}` can only be used in attributes", path)); self.cx.trace_macros_diag(); kind.dummy(span) } - SyntaxExtension::Derive(..) | SyntaxExtension::LegacyDerive(..) => { + SyntaxExtensionKind::Derive(..) | SyntaxExtensionKind::LegacyDerive(..) => { self.cx.span_err(path.span, &format!("`{}` is a derive macro", path)); self.cx.trace_macros_diag(); kind.dummy(span) } - SyntaxExtension::Bang { ref expander, ref allow_internal_unstable, edition } => { + SyntaxExtensionKind::Bang(expander) => { if ident.name != kw::Invalid { let msg = format!("macro {}! expects no ident argument, given '{}'", path, ident); @@ -798,19 +757,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { kind.dummy(span) } else { self.gate_proc_macro_expansion_kind(span, kind); - invoc.expansion_data.mark.set_expn_info(ExpnInfo { - call_site: span, - // FIXME procedural macros do not have proper span info - // yet, when they do, we should use it here. - def_site: None, - format: macro_bang_format(path), - // FIXME probably want to follow macro_rules macros here. - allow_internal_unstable: allow_internal_unstable.clone(), - allow_internal_unsafe: false, - local_inner_macros: false, - edition, - }); - + let expn_info = ext.expn_info(span, &fast_print_path(path)); + invoc.expansion_data.mark.set_expn_info(expn_info); let tok_result = expander.expand(self.cx, span, mac.node.stream()); let result = self.parse_ast_fragment(tok_result, kind, path, span); self.gate_proc_macro_expansion(span, &result); @@ -867,55 +815,23 @@ impl<'a, 'b> MacroExpander<'a, 'b> { return None; } - let pretty_name = Symbol::intern(&format!("derive({})", path)); - let span = path.span; - let attr = ast::Attribute { - path, span, - tokens: TokenStream::empty(), - // irrelevant: - id: ast::AttrId(0), style: ast::AttrStyle::Outer, is_sugared_doc: false, - }; - - let mut expn_info = ExpnInfo { - call_site: span, - def_site: None, - format: MacroAttribute(pretty_name), - allow_internal_unstable: None, - allow_internal_unsafe: false, - local_inner_macros: false, - edition: ext.edition(self.cx.parse_sess.edition), - }; - - match ext { - SyntaxExtension::Derive(expander, ..) | SyntaxExtension::LegacyDerive(expander) => { - let meta = match ext { - SyntaxExtension::Derive(..) => ast::MetaItem { // FIXME(jseyfried) avoid this - path: Path::from_ident(Ident::invalid()), - span: DUMMY_SP, - node: ast::MetaItemKind::Word, - }, - _ => { - expn_info.allow_internal_unstable = Some(vec![ - sym::rustc_attrs, - Symbol::intern("derive_clone_copy"), - Symbol::intern("derive_eq"), - // RustcDeserialize and RustcSerialize - Symbol::intern("libstd_sys_internals"), - ].into()); - attr.meta()? - } - }; - + match &ext.kind { + SyntaxExtensionKind::Derive(expander) | + SyntaxExtensionKind::LegacyDerive(expander) => { + let expn_info = + ext.expn_info(path.span, &format!("derive({})", fast_print_path(&path))); invoc.expansion_data.mark.set_expn_info(expn_info); - let span = span.with_ctxt(self.cx.backtrace()); + + let meta = ast::MetaItem { node: ast::MetaItemKind::Word, span: path.span, path }; + let span = meta.span.with_ctxt(self.cx.backtrace()); let items = expander.expand(self.cx, span, &meta, item); Some(invoc.fragment_kind.expect_from_annotatables(items)) } _ => { - let msg = &format!("macro `{}` may not be used for derive attributes", attr.path); - self.cx.span_err(span, msg); + let msg = &format!("macro `{}` may not be used for derive attributes", path); + self.cx.span_err(path.span, msg); self.cx.trace_macros_diag(); - invoc.fragment_kind.dummy(span) + invoc.fragment_kind.dummy(path.span) } } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 22745a1a76d5..7f051c260ec8 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -1,6 +1,7 @@ use crate::{ast, attr}; use crate::edition::Edition; -use crate::ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension, TTMacroExpander}; +use crate::ext::base::{SyntaxExtension, SyntaxExtensionKind}; +use crate::ext::base::{DummyResult, ExtCtxt, MacResult, TTMacroExpander}; use crate::ext::expand::{AstFragment, AstFragmentKind}; use crate::ext::hygiene::Transparency; use crate::ext::tt::macro_parser::{Success, Error, Failure}; @@ -376,7 +377,7 @@ pub fn compile( valid, }); - let transparency = if attr::contains_name(&def.attrs, sym::rustc_transparent_macro) { + let default_transparency = if attr::contains_name(&def.attrs, sym::rustc_transparent_macro) { Transparency::Transparent } else if body.legacy { Transparency::SemiTransparent @@ -426,14 +427,15 @@ pub fn compile( } }); - SyntaxExtension::LegacyBang { - expander, + SyntaxExtension { + kind: SyntaxExtensionKind::LegacyBang(expander), def_info: Some((def.id, def.span)), - transparency, + default_transparency, allow_internal_unstable, allow_internal_unsafe, local_inner_macros, unstable_feature, + helper_attrs: Vec::new(), edition, } } diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index eea94f0d1945..9072ad7b30fd 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -20,7 +20,7 @@ fn ignored_span(sp: Span, edition: Edition) -> Span { call_site: DUMMY_SP, def_site: None, format: MacroAttribute(Symbol::intern("std_inject")), - allow_internal_unstable: Some(vec![sym::prelude_import].into()), + allow_internal_unstable: Some([sym::prelude_import][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition, diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index cbaf12529c10..0e1b10c14f17 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -284,7 +284,7 @@ fn generate_test_harness(sess: &ParseSess, call_site: DUMMY_SP, def_site: None, format: MacroAttribute(sym::test_case), - allow_internal_unstable: Some(vec![sym::main, sym::test, sym::rustc_attrs].into()), + allow_internal_unstable: Some([sym::main, sym::test, sym::rustc_attrs][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: sess.edition, diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index cf54eacc3d46..e4a413dda09c 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -2,7 +2,9 @@ use rustc_data_structures::sync::Lrc; use syntax::ast::{self, MetaItem}; -use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxExtension, Resolver, MultiItemModifier}; +use syntax::edition::Edition; +use syntax::ext::base::{Annotatable, ExtCtxt, Resolver, MultiItemModifier}; +use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::build::AstBuilder; use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::ptr::P; @@ -67,11 +69,24 @@ macro_rules! derive_traits { } } - pub fn register_builtin_derives(resolver: &mut dyn Resolver) { + pub fn register_builtin_derives(resolver: &mut dyn Resolver, edition: Edition) { + let allow_internal_unstable = Some([ + sym::rustc_attrs, + Symbol::intern("derive_clone_copy"), + Symbol::intern("derive_eq"), + Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize + ][..].into()); + $( resolver.add_builtin( ast::Ident::with_empty_ctxt(Symbol::intern($name)), - Lrc::new(SyntaxExtension::LegacyDerive(Box::new(BuiltinDerive($func)))) + Lrc::new(SyntaxExtension { + allow_internal_unstable: allow_internal_unstable.clone(), + ..SyntaxExtension::default( + SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($func))), + edition, + ) + }), ); )* } diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 3dd17207cb8e..d29d93a8678f 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -43,32 +43,31 @@ pub mod proc_macro_impl; use rustc_data_structures::sync::Lrc; use syntax::ast; -use syntax::ext::base::{MacroExpanderFn, NamedSyntaxExtension, SyntaxExtension}; -use syntax::ext::hygiene::Transparency; +use syntax::ext::base::MacroExpanderFn; +use syntax::ext::base::{NamedSyntaxExtension, SyntaxExtension, SyntaxExtensionKind}; use syntax::edition::Edition; use syntax::symbol::{sym, Symbol}; pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, user_exts: Vec, edition: Edition) { - deriving::register_builtin_derives(resolver); + deriving::register_builtin_derives(resolver, edition); let mut register = |name, ext| { resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Lrc::new(ext)); }; macro_rules! register { ($( $name:ident: $f:expr, )*) => { $( - register(Symbol::intern(stringify!($name)), - SyntaxExtension::LegacyBang { - expander: Box::new($f as MacroExpanderFn), - def_info: None, - transparency: Transparency::SemiTransparent, - allow_internal_unstable: None, - allow_internal_unsafe: false, - local_inner_macros: false, - unstable_feature: None, - edition, - }); + register(Symbol::intern(stringify!($name)), SyntaxExtension::default( + SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)), edition + )); + )* } + } + macro_rules! register_attr { + ($( $name:ident: $f:expr, )*) => { $( + register(Symbol::intern(stringify!($name)), SyntaxExtension::default( + SyntaxExtensionKind::LegacyAttr(Box::new($f)), edition + )); )* } } @@ -97,33 +96,25 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, assert: assert::expand_assert, } - register(sym::test_case, SyntaxExtension::LegacyAttr(Box::new(test_case::expand))); - register(sym::test, SyntaxExtension::LegacyAttr(Box::new(test::expand_test))); - register(sym::bench, SyntaxExtension::LegacyAttr(Box::new(test::expand_bench))); + register_attr! { + test_case: test_case::expand, + test: test::expand_test, + bench: test::expand_bench, + } // format_args uses `unstable` things internally. - register(Symbol::intern("format_args"), - SyntaxExtension::LegacyBang { - expander: Box::new(format::expand_format_args), - def_info: None, - transparency: Transparency::SemiTransparent, - allow_internal_unstable: Some(vec![sym::fmt_internals].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - unstable_feature: None, - edition, - }); - register(sym::format_args_nl, - SyntaxExtension::LegacyBang { - expander: Box::new(format::expand_format_args_nl), - def_info: None, - transparency: Transparency::SemiTransparent, - allow_internal_unstable: Some(vec![sym::fmt_internals].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - unstable_feature: None, - edition, - }); + register(Symbol::intern("format_args"), SyntaxExtension { + allow_internal_unstable: Some([sym::fmt_internals][..].into()), + ..SyntaxExtension::default( + SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args)), edition + ) + }); + register(sym::format_args_nl, SyntaxExtension { + allow_internal_unstable: Some([sym::fmt_internals][..].into()), + ..SyntaxExtension::default( + SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args_nl)), edition + ) + }); for (name, ext) in user_exts { register(name, ext); diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index 29297aa913ed..cdef5c6a9f48 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -351,10 +351,9 @@ fn mk_decls( call_site: DUMMY_SP, def_site: None, format: MacroAttribute(sym::proc_macro), - allow_internal_unstable: Some(vec![ - sym::rustc_attrs, - Symbol::intern("proc_macro_internals"), - ].into()), + allow_internal_unstable: Some([ + sym::rustc_attrs, Symbol::intern("proc_macro_internals") + ][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: cx.parse_sess.edition, diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index c20dc6cb2d7c..a8c8456a3bcf 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -66,7 +66,7 @@ pub fn expand_test_or_bench( call_site: DUMMY_SP, def_site: None, format: MacroAttribute(sym::test), - allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::test].into()), + allow_internal_unstable: Some([sym::rustc_attrs, sym::test][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: cx.parse_sess.edition, diff --git a/src/libsyntax_ext/test_case.rs b/src/libsyntax_ext/test_case.rs index cffecdd0f18e..ce17cf2a6e78 100644 --- a/src/libsyntax_ext/test_case.rs +++ b/src/libsyntax_ext/test_case.rs @@ -41,7 +41,7 @@ pub fn expand( call_site: DUMMY_SP, def_site: None, format: MacroAttribute(sym::test_case), - allow_internal_unstable: Some(vec![sym::test, sym::rustc_attrs].into()), + allow_internal_unstable: Some([sym::test, sym::rustc_attrs][..].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: ecx.parse_sess.edition, diff --git a/src/test/run-pass-fulldeps/auxiliary/plugin-args.rs b/src/test/run-pass-fulldeps/auxiliary/plugin-args.rs index 330459fc08f5..4cf8a4e33c52 100644 --- a/src/test/run-pass-fulldeps/auxiliary/plugin-args.rs +++ b/src/test/run-pass-fulldeps/auxiliary/plugin-args.rs @@ -11,8 +11,8 @@ extern crate rustc_plugin; use std::borrow::ToOwned; use syntax::ast; use syntax::ext::build::AstBuilder; -use syntax::ext::base::{SyntaxExtension, TTMacroExpander, ExtCtxt, MacResult, MacEager}; -use syntax::ext::hygiene::Transparency; +use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; +use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager}; use syntax::print::pprust; use syntax::symbol::Symbol; use syntax_pos::Span; @@ -38,15 +38,7 @@ impl TTMacroExpander for Expander { #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { let args = reg.args().to_owned(); - reg.register_syntax_extension(Symbol::intern("plugin_args"), - SyntaxExtension::LegacyBang { - expander: Box::new(Expander { args: args, }), - def_info: None, - transparency: Transparency::SemiTransparent, - allow_internal_unstable: None, - allow_internal_unsafe: false, - local_inner_macros: false, - unstable_feature: None, - edition: reg.sess.edition(), - }); + reg.register_syntax_extension(Symbol::intern("plugin_args"), SyntaxExtension::default( + SyntaxExtensionKind::LegacyBang(Box::new(Expander { args })), reg.sess.edition() + )); } From 679000cc0e98b2810a2d1c76ae77ce2574a4ab91 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 17 Jun 2019 00:31:46 +0300 Subject: [PATCH 049/109] allow_internal_unstable: Avoid some more allocations --- src/librustc/hir/lowering.rs | 15 ++++++++++----- src/libsyntax_ext/deriving/mod.rs | 19 +++---------------- src/libsyntax_ext/lib.rs | 5 +++-- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 5a548ce8d9ff..a491b1a099b8 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -142,6 +142,9 @@ pub struct LoweringContext<'a> { current_hir_id_owner: Vec<(DefIndex, u32)>, item_local_id_counters: NodeMap, node_id_to_hir_id: IndexVec, + + allow_try_trait: Option>, + allow_gen_future: Option>, } pub trait Resolver { @@ -267,6 +270,8 @@ pub fn lower_crate( lifetimes_to_define: Vec::new(), is_collecting_in_band_lifetimes: false, in_scope_lifetimes: Vec::new(), + allow_try_trait: Some([sym::try_trait][..].into()), + allow_gen_future: Some([sym::gen_future][..].into()), }.lower_crate(krate) } @@ -1156,7 +1161,7 @@ impl<'a> LoweringContext<'a> { let unstable_span = self.mark_span_with_reason( CompilerDesugaringKind::Async, span, - Some(vec![sym::gen_future].into()), + self.allow_gen_future.clone(), ); let gen_future = self.expr_std_path( unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new()); @@ -4382,7 +4387,7 @@ impl<'a> LoweringContext<'a> { let unstable_span = this.mark_span_with_reason( CompilerDesugaringKind::TryBlock, body.span, - Some(vec![sym::try_trait].into()), + this.allow_try_trait.clone(), ); let mut block = this.lower_block(body, true).into_inner(); let tail = block.expr.take().map_or_else( @@ -4968,13 +4973,13 @@ impl<'a> LoweringContext<'a> { let unstable_span = self.mark_span_with_reason( CompilerDesugaringKind::QuestionMark, e.span, - Some(vec![sym::try_trait].into()), + self.allow_try_trait.clone(), ); let try_span = self.sess.source_map().end_point(e.span); let try_span = self.mark_span_with_reason( CompilerDesugaringKind::QuestionMark, try_span, - Some(vec![sym::try_trait].into()), + self.allow_try_trait.clone(), ); // `Try::into_result()` @@ -5776,7 +5781,7 @@ impl<'a> LoweringContext<'a> { let gen_future_span = self.mark_span_with_reason( CompilerDesugaringKind::Await, await_span, - Some(vec![sym::gen_future].into()), + self.allow_gen_future.clone(), ); // let mut pinned = ; diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index e4a413dda09c..1fe6094fca68 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -6,7 +6,6 @@ use syntax::edition::Edition; use syntax::ext::base::{Annotatable, ExtCtxt, Resolver, MultiItemModifier}; use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::build::AstBuilder; -use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::ptr::P; use syntax::symbol::{Symbol, sym}; use syntax_pos::Span; @@ -71,6 +70,7 @@ macro_rules! derive_traits { pub fn register_builtin_derives(resolver: &mut dyn Resolver, edition: Edition) { let allow_internal_unstable = Some([ + sym::core_intrinsics, sym::rustc_attrs, Symbol::intern("derive_clone_copy"), Symbol::intern("derive_eq"), @@ -163,24 +163,11 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String { /// Constructs an expression that calls an intrinsic fn call_intrinsic(cx: &ExtCtxt<'_>, - mut span: Span, + span: Span, intrinsic: &str, args: Vec>) -> P { - let intrinsic_allowed_via_allow_internal_unstable = cx - .current_expansion.mark.expn_info().unwrap() - .allow_internal_unstable.map_or(false, |features| features.iter().any(|&s| - s == sym::core_intrinsics - )); - if intrinsic_allowed_via_allow_internal_unstable { - span = span.with_ctxt(cx.backtrace()); - } else { // Avoid instability errors with user defined curstom derives, cc #36316 - let mut info = cx.current_expansion.mark.expn_info().unwrap(); - info.allow_internal_unstable = Some(vec![sym::core_intrinsics].into()); - let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(info); - span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark)); - } + let span = span.with_ctxt(cx.backtrace()); let path = cx.std_path(&[sym::intrinsics, Symbol::intern(intrinsic)]); let call = cx.expr_call_global(span, path, args); diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index d29d93a8678f..b868f5b273c4 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -103,14 +103,15 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, } // format_args uses `unstable` things internally. + let allow_internal_unstable = Some([sym::fmt_internals][..].into()); register(Symbol::intern("format_args"), SyntaxExtension { - allow_internal_unstable: Some([sym::fmt_internals][..].into()), + allow_internal_unstable: allow_internal_unstable.clone(), ..SyntaxExtension::default( SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args)), edition ) }); register(sym::format_args_nl, SyntaxExtension { - allow_internal_unstable: Some([sym::fmt_internals][..].into()), + allow_internal_unstable, ..SyntaxExtension::default( SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args_nl)), edition ) From 085a8d03750b524a34bf14adc0c9a36a2503e016 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 17 Jun 2019 11:10:48 +0300 Subject: [PATCH 050/109] syntax: Remove `DummyResolver` --- src/libsyntax/ext/base.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 04cef0bba24b..cc5a91465ae4 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -725,31 +725,6 @@ impl Determinacy { } } -pub struct DummyResolver; - -impl Resolver for DummyResolver { - fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID } - - fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() } - - fn resolve_dollar_crates(&mut self, _fragment: &AstFragment) {} - fn visit_ast_fragment_with_placeholders(&mut self, _invoc: Mark, _fragment: &AstFragment, - _derives: &[Mark]) {} - fn add_builtin(&mut self, _ident: ast::Ident, _ext: Lrc) {} - - fn resolve_imports(&mut self) {} - fn resolve_macro_invocation(&mut self, _invoc: &Invocation, _invoc_id: Mark, _force: bool) - -> Result>, Determinacy> { - Err(Determinacy::Determined) - } - fn resolve_macro_path(&mut self, _path: &ast::Path, _kind: MacroKind, _invoc_id: Mark, - _derives_in_scope: Vec, _force: bool) - -> Result, Determinacy> { - Err(Determinacy::Determined) - } - fn check_unused_macros(&self) {} -} - #[derive(Clone)] pub struct ModuleData { pub mod_path: Vec, From 68e1141c45c71c56cc4904b72f2212701b5912d4 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 17 Jun 2019 12:29:56 +0300 Subject: [PATCH 051/109] resolve: Avoid creating fresh syntax extensions for all non-macro attributes --- src/librustc_resolve/build_reduced_graph.rs | 10 +++------- src/librustc_resolve/lib.rs | 12 +++++++++++- src/librustc_resolve/macros.rs | 5 ++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index bb4edf355f8b..60ffb0782f00 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -29,7 +29,7 @@ use syntax::attr; use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId}; use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant}; -use syntax::ext::base::{MacroKind, SyntaxExtension, SyntaxExtensionKind}; +use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::base::Determinacy::Undetermined; use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; @@ -772,12 +772,8 @@ impl<'a> Resolver<'a> { pub fn get_macro(&mut self, res: Res) -> Lrc { let def_id = match res { Res::Def(DefKind::Macro(..), def_id) => def_id, - Res::NonMacroAttr(attr_kind) => return Lrc::new(SyntaxExtension::default( - SyntaxExtensionKind::NonMacroAttr { - mark_used: attr_kind == NonMacroAttrKind::Tool - }, - self.session.edition(), - )), + Res::NonMacroAttr(attr_kind) => + return self.non_macro_attr(attr_kind == NonMacroAttrKind::Tool), _ => panic!("expected `DefKind::Macro` or `Res::NonMacroAttr`"), }; if let Some(ext) = self.macro_map.get(&def_id) { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7f05e0f477c2..dcc2a228b4a7 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -41,7 +41,7 @@ use rustc_metadata::cstore::CStore; use syntax::source_map::SourceMap; use syntax::ext::hygiene::{Mark, Transparency, SyntaxContext}; use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy}; -use syntax::ext::base::SyntaxExtension; +use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::base::Determinacy::{self, Determined, Undetermined}; use syntax::ext::base::MacroKind; use syntax::symbol::{Symbol, kw, sym}; @@ -1668,6 +1668,7 @@ pub struct Resolver<'a> { macro_use_prelude: FxHashMap>, pub all_macros: FxHashMap, macro_map: FxHashMap>, + non_macro_attrs: [Lrc; 2], macro_defs: FxHashMap, local_macro_def_scopes: FxHashMap>, @@ -1941,6 +1942,10 @@ impl<'a> Resolver<'a> { let mut macro_defs = FxHashMap::default(); macro_defs.insert(Mark::root(), root_def_id); + let non_macro_attr = |mark_used| Lrc::new(SyntaxExtension::default( + SyntaxExtensionKind::NonMacroAttr { mark_used }, session.edition() + )); + Resolver { session, @@ -2014,6 +2019,7 @@ impl<'a> Resolver<'a> { macro_use_prelude: FxHashMap::default(), all_macros: FxHashMap::default(), macro_map: FxHashMap::default(), + non_macro_attrs: [non_macro_attr(false), non_macro_attr(true)], invocations, macro_defs, local_macro_def_scopes: FxHashMap::default(), @@ -2030,6 +2036,10 @@ impl<'a> Resolver<'a> { Default::default() } + fn non_macro_attr(&self, mark_used: bool) -> Lrc { + self.non_macro_attrs[mark_used as usize].clone() + } + /// Runs the function on each namespace. fn per_ns(&mut self, mut f: F) { f(self, TypeNS); diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 89e28330be7e..02342d212ebb 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -15,7 +15,7 @@ use syntax::ast::{self, Ident}; use syntax::attr; use syntax::errors::DiagnosticBuilder; use syntax::ext::base::{self, Determinacy}; -use syntax::ext::base::{MacroKind, SyntaxExtension, SyntaxExtensionKind}; +use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::expand::{AstFragment, Invocation, InvocationKind}; use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; @@ -211,8 +211,7 @@ impl<'a> base::Resolver for Resolver<'a> { Ok((res, ext)) => (res, ext), Err(Determinacy::Determined) if kind == MacroKind::Attr => { // Replace unresolved attributes with used inert attributes for better recovery. - let kind = SyntaxExtensionKind::NonMacroAttr { mark_used: true }; - return Ok(Some(Lrc::new(SyntaxExtension::default(kind, self.session.edition())))); + return Ok(Some(self.non_macro_attr(true))); } Err(determinacy) => return Err(determinacy), }; From 8ec502eecdccec643ae6631a323dc6f38b490269 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 17 Jun 2019 22:18:56 +0300 Subject: [PATCH 052/109] syntax: Introduce `default`/`with_unstable` constructors for `ExpnInfo` --- src/librustc/hir/lowering.rs | 12 ++++-------- src/librustc_allocator/expand.rs | 21 +++++++-------------- src/libsyntax/ext/derive.rs | 13 ++++--------- src/libsyntax/std_inject.rs | 12 +++--------- src/libsyntax/test.rs | 13 ++++--------- src/libsyntax_ext/proc_macro_decls.rs | 15 ++++----------- src/libsyntax_ext/test.rs | 15 +++++---------- src/libsyntax_ext/test_case.rs | 15 +++++---------- src/libsyntax_pos/hygiene.rs | 23 +++++++++++++++++++++++ 9 files changed, 59 insertions(+), 80 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a491b1a099b8..0edf407f7c9e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -62,14 +62,14 @@ use syntax::errors; use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned}; +use syntax::source_map::{self, respan, ExpnInfo, CompilerDesugaringKind, Spanned}; use syntax::source_map::CompilerDesugaringKind::IfTemporary; use syntax::std_inject; use syntax::symbol::{kw, sym, Symbol}; use syntax::tokenstream::{TokenStream, TokenTree}; use syntax::parse::token::{self, Token}; use syntax::visit::{self, Visitor}; -use syntax_pos::{DUMMY_SP, edition, Span}; +use syntax_pos::{DUMMY_SP, Span}; const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF; @@ -853,14 +853,10 @@ impl<'a> LoweringContext<'a> { allow_internal_unstable: Option>, ) -> Span { let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(source_map::ExpnInfo { - call_site: span, + mark.set_expn_info(ExpnInfo { def_site: Some(span), - format: source_map::CompilerDesugaring(reason), allow_internal_unstable, - allow_internal_unsafe: false, - local_inner_macros: false, - edition: edition::Edition::from_session(), + ..ExpnInfo::default(source_map::CompilerDesugaring(reason), span, self.sess.edition()) }); span.with_ctxt(SyntaxContext::empty().apply_mark(mark)) } diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index ecc165ca5ea9..d402b0ddf6e8 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -19,7 +19,7 @@ use syntax::{ mut_visit::{self, MutVisitor}, parse::ParseSess, ptr::P, - symbol::{kw, sym, Symbol} + symbol::{kw, sym} }; use syntax_pos::Span; @@ -58,11 +58,10 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { debug!("in submodule {}", self.in_submod); - let name = if attr::contains_name(&item.attrs, sym::global_allocator) { - "global_allocator" - } else { + if !attr::contains_name(&item.attrs, sym::global_allocator) { return mut_visit::noop_flat_map_item(item, self); - }; + } + match item.node { ItemKind::Static(..) => {} _ => { @@ -87,15 +86,9 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> { // Create a fresh Mark for the new macro expansion we are about to do let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(ExpnInfo { - call_site: item.span, // use the call site of the static - def_site: None, - format: MacroAttribute(Symbol::intern(name)), - allow_internal_unstable: Some([sym::rustc_attrs][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition: self.sess.edition, - }); + mark.set_expn_info(ExpnInfo::with_unstable( + MacroAttribute(sym::global_allocator), item.span, self.sess.edition, &[sym::rustc_attrs] + )); // Tie the span to the macro expansion info we just created let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)); diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 33620cb80f94..abc451c96ae0 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -60,15 +60,10 @@ pub fn add_derived_markers(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P } pretty_name.push(')'); - cx.current_expansion.mark.set_expn_info(ExpnInfo { - call_site: span, - def_site: None, - format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), - allow_internal_unstable: Some([sym::rustc_attrs, sym::structural_match][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition: cx.parse_sess.edition, - }); + cx.current_expansion.mark.set_expn_info(ExpnInfo::with_unstable( + ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), span, cx.parse_sess.edition, + &[sym::rustc_attrs, sym::structural_match], + )); let span = span.with_ctxt(cx.backtrace()); item.visit_attrs(|attrs| { diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 9072ad7b30fd..6630bf908154 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -16,15 +16,9 @@ use syntax_pos::{DUMMY_SP, Span}; /// The expanded code uses the unstable `#[prelude_import]` attribute. fn ignored_span(sp: Span, edition: Edition) -> Span { let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(ExpnInfo { - call_site: DUMMY_SP, - def_site: None, - format: MacroAttribute(Symbol::intern("std_inject")), - allow_internal_unstable: Some([sym::prelude_import][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition, - }); + mark.set_expn_info(ExpnInfo::with_unstable( + MacroAttribute(Symbol::intern("std_inject")), sp, edition, &[sym::prelude_import] + )); sp.with_ctxt(SyntaxContext::empty().apply_mark(mark)) } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 0e1b10c14f17..f90b76721ee1 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -280,15 +280,10 @@ fn generate_test_harness(sess: &ParseSess, test_runner }; - mark.set_expn_info(ExpnInfo { - call_site: DUMMY_SP, - def_site: None, - format: MacroAttribute(sym::test_case), - allow_internal_unstable: Some([sym::main, sym::test, sym::rustc_attrs][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition: sess.edition, - }); + mark.set_expn_info(ExpnInfo::with_unstable( + MacroAttribute(sym::test_case), DUMMY_SP, sess.edition, + &[sym::main, sym::test, sym::rustc_attrs], + )); TestHarnessGenerator { cx, diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index cdef5c6a9f48..45e65288a24e 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -347,17 +347,10 @@ fn mk_decls( custom_macros: &[ProcMacroDef], ) -> P { let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(ExpnInfo { - call_site: DUMMY_SP, - def_site: None, - format: MacroAttribute(sym::proc_macro), - allow_internal_unstable: Some([ - sym::rustc_attrs, Symbol::intern("proc_macro_internals") - ][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition: cx.parse_sess.edition, - }); + mark.set_expn_info(ExpnInfo::with_unstable( + MacroAttribute(sym::proc_macro), DUMMY_SP, cx.parse_sess.edition, + &[sym::rustc_attrs, Symbol::intern("proc_macro_internals")], + )); let span = DUMMY_SP.apply_mark(mark); let hidden = cx.meta_list_item_word(span, sym::hidden); diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index a8c8456a3bcf..24d3055e7114 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -8,7 +8,7 @@ use syntax::attr; use syntax::ast; use syntax::print::pprust; use syntax::symbol::{Symbol, sym}; -use syntax_pos::{DUMMY_SP, Span}; +use syntax_pos::Span; use syntax::source_map::{ExpnInfo, MacroAttribute}; use std::iter; @@ -62,15 +62,10 @@ pub fn expand_test_or_bench( let (sp, attr_sp) = { let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(ExpnInfo { - call_site: DUMMY_SP, - def_site: None, - format: MacroAttribute(sym::test), - allow_internal_unstable: Some([sym::rustc_attrs, sym::test][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition: cx.parse_sess.edition, - }); + mark.set_expn_info(ExpnInfo::with_unstable( + MacroAttribute(sym::test), attr_sp, cx.parse_sess.edition, + &[sym::rustc_attrs, sym::test], + )); (item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)), attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))) }; diff --git a/src/libsyntax_ext/test_case.rs b/src/libsyntax_ext/test_case.rs index ce17cf2a6e78..6e3bc05b65e4 100644 --- a/src/libsyntax_ext/test_case.rs +++ b/src/libsyntax_ext/test_case.rs @@ -15,7 +15,7 @@ use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::ast; use syntax::source_map::respan; use syntax::symbol::sym; -use syntax_pos::{DUMMY_SP, Span}; +use syntax_pos::Span; use syntax::source_map::{ExpnInfo, MacroAttribute}; use syntax::feature_gate; @@ -37,15 +37,10 @@ pub fn expand( let sp = { let mark = Mark::fresh(Mark::root()); - mark.set_expn_info(ExpnInfo { - call_site: DUMMY_SP, - def_site: None, - format: MacroAttribute(sym::test_case), - allow_internal_unstable: Some([sym::test, sym::rustc_attrs][..].into()), - allow_internal_unsafe: false, - local_inner_macros: false, - edition: ecx.parse_sess.edition, - }); + mark.set_expn_info(ExpnInfo::with_unstable( + MacroAttribute(sym::test_case), attr_sp, ecx.parse_sess.edition, + &[sym::test, sym::rustc_attrs], + )); attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark)) }; diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index b827416ab53c..e9a912ddbc23 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -682,6 +682,29 @@ pub struct ExpnInfo { pub edition: Edition, } +impl ExpnInfo { + /// Constructs an expansion info with default properties. + pub fn default(format: ExpnFormat, call_site: Span, edition: Edition) -> ExpnInfo { + ExpnInfo { + call_site, + def_site: None, + format, + allow_internal_unstable: None, + allow_internal_unsafe: false, + local_inner_macros: false, + edition, + } + } + + pub fn with_unstable(format: ExpnFormat, call_site: Span, edition: Edition, + allow_internal_unstable: &[Symbol]) -> ExpnInfo { + ExpnInfo { + allow_internal_unstable: Some(allow_internal_unstable.into()), + ..ExpnInfo::default(format, call_site, edition) + } + } +} + /// The source of expansion. #[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub enum ExpnFormat { From 2de2278f1a356cba63300cee0bca49ad8f4905ab Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 17 Jun 2019 23:55:22 +0300 Subject: [PATCH 053/109] syntax: Move `default_transparency` into `ExpnInfo` --- src/librustc/ich/impls_syntax.rs | 9 ++++++- src/librustc_resolve/macros.rs | 1 - src/libsyntax/ext/base.rs | 3 ++- src/libsyntax_pos/hygiene.rs | 42 +++++++++++++------------------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 4f618457d6c6..9430661f75ab 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -391,10 +391,17 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind { NameValue(lit) }); +impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency { + Transparent, + SemiTransparent, + Opaque, +}); + impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo { call_site, - def_site, format, + def_site, + default_transparency, allow_internal_unstable, allow_internal_unsafe, local_inner_macros, diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 02342d212ebb..a7c98842fa3e 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -226,7 +226,6 @@ impl<'a> base::Resolver for Resolver<'a> { self.macro_def_scope(invoc.expansion_data.mark).normal_ancestor_id; self.definitions.add_parent_module_of_macro_def(invoc.expansion_data.mark, normal_module_def_id); - invoc.expansion_data.mark.set_default_transparency(ext.default_transparency); } Ok(Some(ext)) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index cc5a91465ae4..e0fbdedd24bd 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -680,8 +680,9 @@ impl SyntaxExtension { crate fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo { ExpnInfo { call_site, - def_site: self.def_info.map(|(_, span)| span), format: self.expn_format(Symbol::intern(format)), + def_site: self.def_info.map(|(_, span)| span), + default_transparency: self.default_transparency, allow_internal_unstable: self.allow_internal_unstable.clone(), allow_internal_unsafe: self.allow_internal_unsafe, local_inner_macros: self.local_inner_macros, diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index e9a912ddbc23..67b6e9da477f 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -59,13 +59,12 @@ pub struct Mark(u32); #[derive(Clone, Debug)] struct MarkData { parent: Mark, - default_transparency: Transparency, expn_info: Option, } /// A property of a macro expansion that determines how identifiers /// produced by that expansion are resolved. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)] pub enum Transparency { /// Identifier produced by a transparent expansion is always resolved at call-site. /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this. @@ -85,12 +84,7 @@ pub enum Transparency { impl Mark { pub fn fresh(parent: Mark) -> Self { HygieneData::with(|data| { - data.marks.push(MarkData { - parent, - // By default expansions behave like `macro_rules`. - default_transparency: Transparency::SemiTransparent, - expn_info: None, - }); + data.marks.push(MarkData { parent, expn_info: None }); Mark(data.marks.len() as u32 - 1) }) } @@ -126,12 +120,6 @@ impl Mark { HygieneData::with(|data| data.marks[self.0 as usize].expn_info = Some(info)) } - #[inline] - pub fn set_default_transparency(self, transparency: Transparency) { - assert_ne!(self, Mark::root()); - HygieneData::with(|data| data.marks[self.0 as usize].default_transparency = transparency) - } - pub fn is_descendant_of(self, ancestor: Mark) -> bool { HygieneData::with(|data| data.is_descendant_of(self, ancestor)) } @@ -172,9 +160,8 @@ impl Mark { #[inline] pub fn looks_like_proc_macro_derive(self) -> bool { HygieneData::with(|data| { - let mark_data = &data.marks[self.0 as usize]; - if mark_data.default_transparency == Transparency::Opaque { - if let Some(expn_info) = &mark_data.expn_info { + if data.default_transparency(self) == Transparency::Opaque { + if let Some(expn_info) = &data.marks[self.0 as usize].expn_info { if let ExpnFormat::MacroAttribute(name) = expn_info.format { if name.as_str().starts_with("derive(") { return true; @@ -199,9 +186,6 @@ impl HygieneData { HygieneData { marks: vec![MarkData { parent: Mark::root(), - // If the root is opaque, then loops searching for an opaque mark - // will automatically stop after reaching it. - default_transparency: Transparency::Opaque, expn_info: None, }], syntax_contexts: vec![SyntaxContextData { @@ -235,7 +219,9 @@ impl HygieneData { } fn default_transparency(&self, mark: Mark) -> Transparency { - self.marks[mark.0 as usize].default_transparency + self.marks[mark.0 as usize].expn_info.as_ref().map_or( + Transparency::SemiTransparent, |einfo| einfo.default_transparency + ) } fn modern(&self, ctxt: SyntaxContext) -> SyntaxContext { @@ -427,7 +413,6 @@ impl SyntaxContext { HygieneData::with(|data| { data.marks.push(MarkData { parent: Mark::root(), - default_transparency: Transparency::SemiTransparent, expn_info: Some(expansion_info), }); @@ -651,6 +636,7 @@ impl fmt::Debug for SyntaxContext { /// Extra information for tracking spans of macro and syntax sugar expansion #[derive(Clone, Hash, Debug, RustcEncodable, RustcDecodable)] pub struct ExpnInfo { + // --- The part unique to each expansion. /// The location of the actual macro invocation or syntax sugar , e.g. /// `let x = foo!();` or `if let Some(y) = x {}` /// @@ -661,13 +647,18 @@ pub struct ExpnInfo { /// call_site span would have its own ExpnInfo, with the call_site /// pointing to the `foo!` invocation. pub call_site: Span, + /// The format with which the macro was invoked. + pub format: ExpnFormat, + + // --- The part specific to the macro/desugaring definition. + // --- FIXME: Share it between expansions with the same definition. /// The span of the macro definition itself. The macro may not /// have a sensible definition span (e.g., something defined /// completely inside libsyntax) in which case this is None. /// This span serves only informational purpose and is not used for resolution. pub def_site: Option, - /// The format with which the macro was invoked. - pub format: ExpnFormat, + /// Transparency used by `apply_mark` for mark with this expansion info by default. + pub default_transparency: Transparency, /// List of #[unstable]/feature-gated features that the macro is allowed to use /// internally without forcing the whole crate to opt-in /// to them. @@ -687,8 +678,9 @@ impl ExpnInfo { pub fn default(format: ExpnFormat, call_site: Span, edition: Edition) -> ExpnInfo { ExpnInfo { call_site, - def_site: None, format, + def_site: None, + default_transparency: Transparency::SemiTransparent, allow_internal_unstable: None, allow_internal_unsafe: false, local_inner_macros: false, From 1ff3bce5bbcf3f23ad90266f8f3de1ac13d23623 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 18 Jun 2019 01:36:44 +0300 Subject: [PATCH 054/109] hygiene: Avoid some unnecessary `ExpnInfo` clones --- src/libsyntax_pos/hygiene.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 67b6e9da477f..4dbd4ccda910 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -112,7 +112,7 @@ impl Mark { #[inline] pub fn expn_info(self) -> Option { - HygieneData::with(|data| data.expn_info(self)) + HygieneData::with(|data| data.expn_info(self).cloned()) } #[inline] @@ -204,8 +204,8 @@ impl HygieneData { GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut())) } - fn expn_info(&self, mark: Mark) -> Option { - self.marks[mark.0 as usize].expn_info.clone() + fn expn_info(&self, mark: Mark) -> Option<&ExpnInfo> { + self.marks[mark.0 as usize].expn_info.as_ref() } fn is_descendant_of(&self, mut mark: Mark, ancestor: Mark) -> bool { @@ -598,7 +598,7 @@ impl SyntaxContext { /// `ctxt.outer().expn_info()`. #[inline] pub fn outer_expn_info(self) -> Option { - HygieneData::with(|data| data.expn_info(data.outer(self))) + HygieneData::with(|data| data.expn_info(data.outer(self)).cloned()) } /// `ctxt.outer_and_expn_info()` is equivalent to but faster than @@ -607,7 +607,7 @@ impl SyntaxContext { pub fn outer_and_expn_info(self) -> (Mark, Option) { HygieneData::with(|data| { let outer = data.outer(self); - (outer, data.expn_info(outer)) + (outer, data.expn_info(outer).cloned()) }) } From e152554e11ff44b1a08e21a8416e1fc18504764e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 18 Jun 2019 10:48:44 +0300 Subject: [PATCH 055/109] resolve/expand: Move expansion info setting to a single earlier point --- src/librustc_resolve/macros.rs | 31 ++++++++++++++++++++++++++----- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/expand.rs | 32 +++----------------------------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index a7c98842fa3e..d2fec0ed622d 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -114,6 +114,22 @@ fn sub_namespace_match(candidate: Option, requirement: Option String { + let mut path_str = String::with_capacity(64); + for (i, segment) in path.segments.iter().enumerate() { + if i != 0 { + path_str.push_str("::"); + } + if segment.ident.name != kw::PathRoot { + path_str.push_str(&segment.ident.as_str()) + } + } + path_str +} + impl<'a> base::Resolver for Resolver<'a> { fn next_node_id(&mut self) -> ast::NodeId { self.session.next_node_id() @@ -209,14 +225,19 @@ impl<'a> base::Resolver for Resolver<'a> { let parent_scope = self.invoc_parent_scope(invoc_id, derives_in_scope); let (res, ext) = match self.resolve_macro_to_res(path, kind, &parent_scope, true, force) { Ok((res, ext)) => (res, ext), - Err(Determinacy::Determined) if kind == MacroKind::Attr => { - // Replace unresolved attributes with used inert attributes for better recovery. - return Ok(Some(self.non_macro_attr(true))); - } + // Replace unresolved attributes with used inert attributes for better recovery. + Err(Determinacy::Determined) if kind == MacroKind::Attr => + (Res::Err, self.non_macro_attr(true)), Err(determinacy) => return Err(determinacy), }; - if let Res::Def(DefKind::Macro(_), def_id) = res { + let format = match kind { + MacroKind::Derive => format!("derive({})", fast_print_path(path)), + _ => fast_print_path(path), + }; + invoc.expansion_data.mark.set_expn_info(ext.expn_info(invoc.span(), &format)); + + if let Res::Def(_, def_id) = res { if after_derive { self.session.span_err(invoc.span(), "macro attributes must be placed before `#[derive]`"); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index e0fbdedd24bd..318a5a3a82a2 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -677,7 +677,7 @@ impl SyntaxExtension { } } - crate fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo { + pub fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo { ExpnInfo { call_site, format: self.expn_format(Symbol::intern(format)), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4e759c5e5286..7154cc409f26 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -188,22 +188,6 @@ impl AstFragmentKind { } } -// We don't want to format a path using pretty-printing, -// `format!("{}", path)`, because that tries to insert -// line-breaks and is slow. -fn fast_print_path(path: &ast::Path) -> String { - let mut path_str = String::with_capacity(64); - for (i, segment) in path.segments.iter().enumerate() { - if i != 0 { - path_str.push_str("::"); - } - if segment.ident.name != kw::PathRoot { - path_str.push_str(&segment.ident.as_str()) - } - } - path_str -} - pub struct Invocation { pub kind: InvocationKind, fragment_kind: AstFragmentKind, @@ -546,9 +530,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { _ => unreachable!(), }; - let expn_info = ext.expn_info(attr.span, &fast_print_path(&attr.path)); - invoc.expansion_data.mark.set_expn_info(expn_info); - match &ext.kind { SyntaxExtensionKind::NonMacroAttr { mark_used } => { attr::mark_known(&attr); @@ -682,7 +663,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invoc: Invocation, ext: &SyntaxExtension) -> Option { - let (mark, kind) = (invoc.expansion_data.mark, invoc.fragment_kind); + let kind = invoc.fragment_kind; let (mac, ident, span) = match invoc.kind { InvocationKind::Bang { mac, ident, span } => (mac, ident, span), _ => unreachable!(), @@ -690,7 +671,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let path = &mac.node.path; let ident = ident.unwrap_or_else(|| Ident::invalid()); - let validate_and_set_expn_info = |this: &mut Self| { + let validate = |this: &mut Self| { // feature-gate the macro invocation if let Some((feature, issue)) = ext.unstable_feature { let crate_span = this.cx.current_expansion.crate_span.unwrap(); @@ -715,13 +696,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> { this.cx.trace_macros_diag(); return Err(kind.dummy(span)); } - mark.set_expn_info(ext.expn_info(span, &fast_print_path(path))); Ok(()) }; let opt_expanded = match &ext.kind { SyntaxExtensionKind::LegacyBang(expander) => { - if let Err(dummy_span) = validate_and_set_expn_info(self) { + if let Err(dummy_span) = validate(self) { dummy_span } else { kind.make_from(expander.expand( @@ -757,8 +737,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { kind.dummy(span) } else { self.gate_proc_macro_expansion_kind(span, kind); - let expn_info = ext.expn_info(span, &fast_print_path(path)); - invoc.expansion_data.mark.set_expn_info(expn_info); let tok_result = expander.expand(self.cx, span, mac.node.stream()); let result = self.parse_ast_fragment(tok_result, kind, path, span); self.gate_proc_macro_expansion(span, &result); @@ -818,10 +796,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { match &ext.kind { SyntaxExtensionKind::Derive(expander) | SyntaxExtensionKind::LegacyDerive(expander) => { - let expn_info = - ext.expn_info(path.span, &format!("derive({})", fast_print_path(&path))); - invoc.expansion_data.mark.set_expn_info(expn_info); - let meta = ast::MetaItem { node: ast::MetaItemKind::Word, span: path.span, path }; let span = meta.span.with_ctxt(self.cx.backtrace()); let items = expander.expand(self.cx, span, &meta, item); From 0f9dc6c48e51637a5d54fc791df94d104c1e0aee Mon Sep 17 00:00:00 2001 From: Michael Bradshaw Date: Tue, 11 Jun 2019 19:04:02 -0700 Subject: [PATCH 056/109] Make MaybeUninit #[repr(transparent)] Tracking issue: #60405 --- src/libcore/lib.rs | 1 + src/libcore/mem/maybe_uninit.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 030f4f1d12cc..1bfb852424d6 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -100,6 +100,7 @@ #![feature(staged_api)] #![feature(std_internals)] #![feature(stmt_expr_attributes)] +#![cfg_attr(not(bootstrap), feature(transparent_unions))] #![feature(unboxed_closures)] #![feature(unsized_locals)] #![feature(untagged_unions)] diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index eeff9d0303a3..28e1e22ba7ff 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -172,7 +172,7 @@ use crate::mem::ManuallyDrop; /// /// # Layout /// -/// `MaybeUninit` is guaranteed to have the same size and alignment as `T`: +/// `MaybeUninit` is guaranteed to have the same size, alignment, and ABI as `T`: /// /// ```rust /// use std::mem::{MaybeUninit, size_of, align_of}; @@ -191,9 +191,23 @@ use crate::mem::ManuallyDrop; /// assert_eq!(size_of::>(), 1); /// assert_eq!(size_of::>>(), 2); /// ``` +/// +/// If `T` is FFI-safe, then so is `MaybeUninit`. +/// +/// While `MaybeUninit` is `#[repr(transparent)]` (indicating it guarantees the same size, +/// alignment, and ABI as `T`), this does *not* change any of the previous caveats. `Option` and +/// `Option>` may still have different sizes, and types containing a field of type +/// `T` may be laid out (and sized) differently than if that field were `MaybeUninit`. +/// `MaybeUninit` is a union type, and `#[repr(transparent)]` on unions is unstable (see [the +/// tracking issue](https://github.com/rust-lang/rust/issues/60405)). Over time, the exact +/// guarantees of `#[repr(transparent)]` on unions may evolve, and `MaybeUninit` may or may not +/// remain `#[repr(transparent)]`. That said, `MaybeUninit` will *always* guarantee that it has +/// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that +/// guarantee may evolve. #[allow(missing_debug_implementations)] #[stable(feature = "maybe_uninit", since = "1.36.0")] #[derive(Copy)] +#[cfg_attr(not(bootstrap), repr(transparent))] pub union MaybeUninit { uninit: (), value: ManuallyDrop, From 6a084dc0e76253449b6ed85e4814aa7862c6b42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 18 Jun 2019 15:43:41 +0200 Subject: [PATCH 057/109] submodules: update clippy from be5d17fe to 868f168c Changes: ```` rustup https://github.com/rust-lang/rust/pull/61836/ fix suggestion for floating points inequality ```` --- src/tools/clippy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/clippy b/src/tools/clippy index be5d17feb205..868f168c1c5f 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit be5d17feb20534d503c49722beecf5501d5d9c3a +Subproject commit 868f168c1c5fa9f19c922f3b0ba5be3980f6b0a9 From dedf2eda8f6d062da91c80a8980b3b794f5c876e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 16 Jun 2019 17:23:41 +0300 Subject: [PATCH 058/109] rustc_typeck: correctly compute `Substs` for `Res::SelfCtor`. --- src/librustc_typeck/check/mod.rs | 96 +++++++++---------- .../{run-pass => ui}/issues/issue-57924.rs | 1 + src/test/ui/issues/issue-57924.stderr | 9 ++ src/test/ui/issues/issue-61882-2.rs | 11 +++ src/test/ui/issues/issue-61882-2.stderr | 15 +++ src/test/ui/issues/issue-61882.rs | 9 ++ src/test/ui/issues/issue-61882.stderr | 21 ++++ 7 files changed, 109 insertions(+), 53 deletions(-) rename src/test/{run-pass => ui}/issues/issue-57924.rs (64%) create mode 100644 src/test/ui/issues/issue-57924.stderr create mode 100644 src/test/ui/issues/issue-61882-2.rs create mode 100644 src/test/ui/issues/issue-61882-2.stderr create mode 100644 src/test/ui/issues/issue-61882.rs create mode 100644 src/test/ui/issues/issue-61882.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 22f17097fcbe..a5d9284a6fed 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5300,52 +5300,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(original_span.with_lo(original_span.hi() - BytePos(1))) } - // Rewrite `SelfCtor` to `Ctor` - pub fn rewrite_self_ctor( - &self, - res: Res, - span: Span, - ) -> Result { - let tcx = self.tcx; - if let Res::SelfCtor(impl_def_id) = res { - let ty = self.impl_self_ty(span, impl_def_id).ty; - let adt_def = ty.ty_adt_def(); - - match adt_def { - Some(adt_def) if adt_def.has_ctor() => { - let variant = adt_def.non_enum_variant(); - let ctor_def_id = variant.ctor_def_id.unwrap(); - Ok(Res::Def(DefKind::Ctor(CtorOf::Struct, variant.ctor_kind), ctor_def_id)) - } - _ => { - let mut err = tcx.sess.struct_span_err(span, - "the `Self` constructor can only be used with tuple or unit structs"); - if let Some(adt_def) = adt_def { - match adt_def.adt_kind() { - AdtKind::Enum => { - err.help("did you mean to use one of the enum's variants?"); - }, - AdtKind::Struct | - AdtKind::Union => { - err.span_suggestion( - span, - "use curly brackets", - String::from("Self { /* fields */ }"), - Applicability::HasPlaceholders, - ); - } - } - } - err.emit(); - - Err(ErrorReported) - } - } - } else { - Ok(res) - } - } - // Instantiates the given path, which must refer to an item with the given // number of type parameters and type. pub fn instantiate_value_path(&self, @@ -5365,12 +5319,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let tcx = self.tcx; - let res = match self.rewrite_self_ctor(res, span) { - Ok(res) => res, - Err(ErrorReported) => return (tcx.types.err, res), - }; let path_segs = match res { - Res::Local(_) => vec![], + Res::Local(_) | Res::SelfCtor(_) => vec![], Res::Def(kind, def_id) => AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id), _ => bug!("instantiate_value_path on {:?}", res), @@ -5475,13 +5425,53 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { tcx.generics_of(*def_id).has_self }).unwrap_or(false); + let (res, self_ctor_substs) = if let Res::SelfCtor(impl_def_id) = res { + let ty = self.impl_self_ty(span, impl_def_id).ty; + let adt_def = ty.ty_adt_def(); + + match ty.sty { + ty::Adt(adt_def, substs) if adt_def.has_ctor() => { + let variant = adt_def.non_enum_variant(); + let ctor_def_id = variant.ctor_def_id.unwrap(); + ( + Res::Def(DefKind::Ctor(CtorOf::Struct, variant.ctor_kind), ctor_def_id), + Some(substs), + ) + } + _ => { + let mut err = tcx.sess.struct_span_err(span, + "the `Self` constructor can only be used with tuple or unit structs"); + if let Some(adt_def) = adt_def { + match adt_def.adt_kind() { + AdtKind::Enum => { + err.help("did you mean to use one of the enum's variants?"); + }, + AdtKind::Struct | + AdtKind::Union => { + err.span_suggestion( + span, + "use curly brackets", + String::from("Self { /* fields */ }"), + Applicability::HasPlaceholders, + ); + } + } + } + err.emit(); + + return (tcx.types.err, res) + } + } + } else { + (res, None) + }; let def_id = res.def_id(); // The things we are substituting into the type should not contain // escaping late-bound regions, and nor should the base type scheme. let ty = tcx.type_of(def_id); - let substs = AstConv::create_substs_for_generic_args( + let substs = self_ctor_substs.unwrap_or_else(|| AstConv::create_substs_for_generic_args( tcx, def_id, &[][..], @@ -5551,7 +5541,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } }, - ); + )); assert!(!substs.has_escaping_bound_vars()); assert!(!ty.has_escaping_bound_vars()); diff --git a/src/test/run-pass/issues/issue-57924.rs b/src/test/ui/issues/issue-57924.rs similarity index 64% rename from src/test/run-pass/issues/issue-57924.rs rename to src/test/ui/issues/issue-57924.rs index 232596334b0e..dc2942225e3d 100644 --- a/src/test/run-pass/issues/issue-57924.rs +++ b/src/test/ui/issues/issue-57924.rs @@ -3,6 +3,7 @@ pub struct Gcm(E); impl Gcm { pub fn crash(e: E) -> Self { Self::(e) + //~^ ERROR type arguments are not allowed for this type } } diff --git a/src/test/ui/issues/issue-57924.stderr b/src/test/ui/issues/issue-57924.stderr new file mode 100644 index 000000000000..2f184b1aae17 --- /dev/null +++ b/src/test/ui/issues/issue-57924.stderr @@ -0,0 +1,9 @@ +error[E0109]: type arguments are not allowed for this type + --> $DIR/issue-57924.rs:5:16 + | +LL | Self::(e) + | ^ type argument not allowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0109`. diff --git a/src/test/ui/issues/issue-61882-2.rs b/src/test/ui/issues/issue-61882-2.rs new file mode 100644 index 000000000000..1209b54bc410 --- /dev/null +++ b/src/test/ui/issues/issue-61882-2.rs @@ -0,0 +1,11 @@ +struct A(T); + +impl A<&'static u8> { + fn f() { + let x = 0; + Self(&x); + //~^ ERROR `x` does not live long enough + } +} + +fn main() {} diff --git a/src/test/ui/issues/issue-61882-2.stderr b/src/test/ui/issues/issue-61882-2.stderr new file mode 100644 index 000000000000..03a65540ced0 --- /dev/null +++ b/src/test/ui/issues/issue-61882-2.stderr @@ -0,0 +1,15 @@ +error[E0597]: `x` does not live long enough + --> $DIR/issue-61882-2.rs:6:14 + | +LL | Self(&x); + | ^^ + | | + | borrowed value does not live long enough + | requires that `x` is borrowed for `'static` +LL | +LL | } + | - `x` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/issues/issue-61882.rs b/src/test/ui/issues/issue-61882.rs new file mode 100644 index 000000000000..013398b4598a --- /dev/null +++ b/src/test/ui/issues/issue-61882.rs @@ -0,0 +1,9 @@ +struct A(T); + +impl A { + const B: A = Self(0); + //~^ ERROR mismatched types + //~| ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/issues/issue-61882.stderr b/src/test/ui/issues/issue-61882.stderr new file mode 100644 index 000000000000..a14e1a4dd4d4 --- /dev/null +++ b/src/test/ui/issues/issue-61882.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/issue-61882.rs:4:27 + | +LL | const B: A = Self(0); + | ^ expected bool, found integer + | + = note: expected type `bool` + found type `{integer}` + +error[E0308]: mismatched types + --> $DIR/issue-61882.rs:4:22 + | +LL | const B: A = Self(0); + | ^^^^^^^ expected u8, found bool + | + = note: expected type `A` + found type `A` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. From b25b466a887d8ceaef533e542431fdec7e70f10f Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 14 Jun 2019 19:39:39 +0300 Subject: [PATCH 059/109] rustc: remove 'x: 'y bounds (except from comments/strings). --- src/librustc/cfg/construct.rs | 2 +- src/librustc/cfg/graphviz.rs | 2 +- src/librustc/dep_graph/dep_node.rs | 4 +-- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/lowering.rs | 8 +++--- src/librustc/hir/map/hir_id_validator.rs | 12 ++++----- src/librustc/infer/at.rs | 4 +-- src/librustc/infer/canonical/canonicalizer.rs | 2 +- src/librustc/infer/combine.rs | 4 +-- src/librustc/infer/equate.rs | 2 +- .../error_reporting/nice_region_error/mod.rs | 2 +- src/librustc/infer/freshen.rs | 2 +- src/librustc/infer/fudge.rs | 2 +- src/librustc/infer/glb.rs | 2 +- src/librustc/infer/lattice.rs | 4 +-- .../infer/lexical_region_resolve/graphviz.rs | 2 +- .../infer/lexical_region_resolve/mod.rs | 2 +- src/librustc/infer/lub.rs | 2 +- src/librustc/infer/mod.rs | 2 +- src/librustc/infer/nll_relate/mod.rs | 6 ++--- src/librustc/infer/opaque_types/mod.rs | 2 +- src/librustc/infer/outlives/env.rs | 2 +- src/librustc/infer/outlives/obligations.rs | 2 +- src/librustc/infer/outlives/verify.rs | 2 +- src/librustc/infer/resolve.rs | 8 +++--- src/librustc/infer/sub.rs | 2 +- src/librustc/lint/context.rs | 4 +-- src/librustc/middle/dead.rs | 4 +-- src/librustc/middle/entry.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/free_region.rs | 2 +- src/librustc/middle/liveness.rs | 4 +-- src/librustc/middle/reachable.rs | 6 ++--- src/librustc/middle/resolve_lifetime.rs | 4 +-- src/librustc/middle/stability.rs | 8 +++--- src/librustc/middle/weak_lang_items.rs | 2 +- src/librustc/mir/mod.rs | 4 +-- src/librustc/mir/traversal.rs | 6 ++--- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/fulfill.rs | 2 +- src/librustc/traits/project.rs | 2 +- src/librustc/traits/query/normalize.rs | 2 +- src/librustc/traits/select.rs | 10 +++---- src/librustc/ty/query/on_disk_cache.rs | 2 +- src/librustc/ty/query/plumbing.rs | 4 +-- src/librustc/ty/wf.rs | 2 +- src/librustc_borrowck/borrowck/check_loans.rs | 2 +- .../borrowck/gather_loans/gather_moves.rs | 6 ++--- .../borrowck/gather_loans/lifetime.rs | 2 +- .../borrowck/gather_loans/mod.rs | 2 +- .../borrowck/gather_loans/restrictions.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_borrowck/graphviz.rs | 2 +- src/librustc_codegen_llvm/builder.rs | 2 +- src/librustc_codegen_llvm/context.rs | 2 +- src/librustc_codegen_llvm/lib.rs | 2 +- src/librustc_codegen_ssa/README.md | 10 +++---- src/librustc_codegen_ssa/base.rs | 24 ++++++++--------- src/librustc_codegen_ssa/common.rs | 8 +++--- src/librustc_codegen_ssa/glue.rs | 2 +- src/librustc_codegen_ssa/meth.rs | 2 +- src/librustc_codegen_ssa/mir/analyze.rs | 6 ++--- src/librustc_codegen_ssa/mir/block.rs | 4 +-- src/librustc_codegen_ssa/mir/constant.rs | 2 +- src/librustc_codegen_ssa/mir/mod.rs | 12 ++++----- src/librustc_codegen_ssa/mir/operand.rs | 6 ++--- src/librustc_codegen_ssa/mir/place.rs | 6 ++--- src/librustc_codegen_ssa/mir/rvalue.rs | 8 +++--- src/librustc_codegen_ssa/mir/statement.rs | 2 +- src/librustc_codegen_ssa/mono_item.rs | 4 +-- src/librustc_codegen_ssa/traits/backend.rs | 2 +- src/librustc_codegen_ssa/traits/builder.rs | 2 +- src/librustc_driver/pretty.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/types.rs | 2 +- src/librustc_metadata/creader.rs | 2 +- src/librustc_metadata/decoder.rs | 6 ++--- src/librustc_mir/borrow_check/borrow_set.rs | 2 +- src/librustc_mir/borrow_check/flows.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 6 ++--- .../borrow_check/nll/constraint_generation.rs | 2 +- .../nll/explain_borrow/find_use.rs | 4 +-- .../borrow_check/nll/invalidation.rs | 2 +- .../borrow_check/nll/region_infer/graphviz.rs | 4 +-- .../nll/type_check/constraint_conversion.rs | 2 +- .../nll/type_check/free_region_relations.rs | 2 +- .../nll/type_check/liveness/trace.rs | 12 ++++----- .../borrow_check/nll/type_check/mod.rs | 6 ++--- .../borrow_check/nll/type_check/relate_tys.rs | 2 +- .../borrow_check/nll/universal_regions.rs | 2 +- src/librustc_mir/borrow_check/prefixes.rs | 2 +- src/librustc_mir/borrow_check/used_muts.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 6 ++--- src/librustc_mir/build/mod.rs | 2 +- .../dataflow/impls/borrowed_locals.rs | 6 ++--- src/librustc_mir/dataflow/impls/borrows.rs | 2 +- src/librustc_mir/dataflow/impls/mod.rs | 14 +++++----- .../dataflow/impls/storage_liveness.rs | 4 +-- src/librustc_mir/dataflow/mod.rs | 22 ++++++++-------- .../dataflow/move_paths/builder.rs | 4 +-- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/hair/cx/to_ref.rs | 12 ++++----- src/librustc_mir/hair/pattern/_match.rs | 26 +++++++++---------- src/librustc_mir/hair/pattern/check_match.rs | 8 +++--- src/librustc_mir/hair/pattern/mod.rs | 2 +- src/librustc_mir/interpret/eval_context.rs | 4 +-- src/librustc_mir/interpret/snapshot.rs | 2 +- src/librustc_mir/interpret/visitor.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 4 +-- src/librustc_mir/monomorphize/partitioning.rs | 4 +-- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/transform/elaborate_drops.rs | 4 +-- src/librustc_mir/transform/generator.rs | 6 ++--- src/librustc_mir/transform/inline.rs | 2 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_mir/transform/promote_consts.rs | 2 +- src/librustc_mir/transform/simplify.rs | 4 +-- .../transform/uniform_array_move_out.rs | 2 +- src/librustc_mir/util/elaborate_drops.rs | 4 +-- src/librustc_passes/loops.rs | 2 +- src/librustc_passes/rvalue_promotion.rs | 2 +- src/librustc_privacy/lib.rs | 10 +++---- src/librustc_resolve/build_reduced_graph.rs | 2 +- src/librustc_resolve/check_unused.rs | 2 +- src/librustc_resolve/diagnostics.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_resolve/macros.rs | 2 +- src/librustc_resolve/resolve_imports.rs | 10 +++---- src/librustc_save_analysis/dump_visitor.rs | 6 ++--- src/librustc_save_analysis/lib.rs | 6 ++--- src/librustc_traits/chalk_context/mod.rs | 2 +- .../chalk_context/resolvent_ops.rs | 2 +- src/librustc_traits/chalk_context/unify.rs | 2 +- src/librustc_traits/type_op.rs | 2 +- src/librustc_typeck/check/autoderef.rs | 2 +- .../check/generator_interior.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 8 +++--- src/librustc_typeck/check/writeback.rs | 4 +-- src/librustc_typeck/check_unused.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- .../outlives/implicit_infer.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/solve.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- .../passes/check_code_block_syntax.rs | 2 +- src/librustdoc/test.rs | 2 +- src/libserialize/json.rs | 2 +- src/libsyntax/ext/expand.rs | 4 +-- src/libsyntax/ext/placeholders.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 4 +-- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- src/libsyntax_ext/format.rs | 2 +- 154 files changed, 305 insertions(+), 305 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 85602320f0b0..213e57a3b37c 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -7,7 +7,7 @@ use crate::ty::{self, TyCtxt}; use crate::hir::{self, PatKind}; use crate::hir::def_id::DefId; -struct CFGBuilder<'a, 'tcx: 'a> { +struct CFGBuilder<'a, 'tcx> { tcx: TyCtxt<'tcx>, owner_def_id: DefId, tables: &'a ty::TypeckTables<'tcx>, diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index 66963e5856ee..918120057d4d 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -11,7 +11,7 @@ use crate::ty::TyCtxt; pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode); pub type Edge<'a> = &'a cfg::CFGEdge; -pub struct LabelledCFG<'a, 'tcx: 'a> { +pub struct LabelledCFG<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, pub cfg: &'a cfg::CFG, pub name: String, diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index f7647167a757..e8f83093bda1 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -207,8 +207,8 @@ macro_rules! define_dep_nodes { pub fn new<'a, 'tcx>(tcx: TyCtxt<'tcx>, dep: DepConstructor<'tcx>) -> DepNode - where 'tcx: 'a, - 'tcx: 'a + where 'tcx, + 'tcx { match dep { $( diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 666cfc3f6dca..e29a373ec3b7 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -74,7 +74,7 @@ impl<'a> FnKind<'a> { /// /// See the comments on `ItemLikeVisitor` for more details on the overall /// visit strategy. -pub enum NestedVisitorMap<'this, 'tcx: 'this> { +pub enum NestedVisitorMap<'this, 'tcx> { /// Do not visit any nested things. When you add a new /// "non-nested" thing, you will want to audit such uses to see if /// they remain valid. diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 5a548ce8d9ff..153397f11b5a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -415,7 +415,7 @@ impl<'a> LoweringContext<'a> { /// needed from arbitrary locations in the crate, /// e.g., the number of lifetime generic parameters /// declared for every type and trait definition. - struct MiscCollector<'tcx, 'interner: 'tcx> { + struct MiscCollector<'tcx, 'interner> { lctx: &'tcx mut LoweringContext<'interner>, hir_id_owner: Option, } @@ -561,7 +561,7 @@ impl<'a> LoweringContext<'a> { } } - struct ItemLowerer<'tcx, 'interner: 'tcx> { + struct ItemLowerer<'tcx, 'interner> { lctx: &'tcx mut LoweringContext<'interner>, } @@ -1788,7 +1788,7 @@ impl<'a> LoweringContext<'a> { // This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that // appear in the bounds, excluding lifetimes that are created within the bounds. // E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`. - struct ImplTraitLifetimeCollector<'r, 'a: 'r> { + struct ImplTraitLifetimeCollector<'r, 'a> { context: &'r mut LoweringContext<'a>, parent: DefIndex, exist_ty_id: NodeId, @@ -1799,7 +1799,7 @@ impl<'a> LoweringContext<'a> { output_lifetime_params: Vec, } - impl<'r, 'a: 'r, 'v> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a> { + impl<'r, 'a, 'v> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a> { fn nested_visit_map<'this>( &'this mut self, ) -> hir::intravisit::NestedVisitorMap<'this, 'v> { diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 32d0e069f72d..60465c04ec62 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -26,19 +26,19 @@ pub fn check_crate<'hir>(hir_map: &hir::map::Map<'hir>) { } } -struct HirIdValidator<'a, 'hir: 'a> { +struct HirIdValidator<'a, 'hir> { hir_map: &'a hir::map::Map<'hir>, owner_def_index: Option, hir_ids_seen: FxHashSet, errors: &'a Lock>, } -struct OuterVisitor<'a, 'hir: 'a> { +struct OuterVisitor<'a, 'hir> { hir_map: &'a hir::map::Map<'hir>, errors: &'a Lock>, } -impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> { +impl<'a, 'hir> OuterVisitor<'a, 'hir> { fn new_inner_visitor(&self, hir_map: &'a hir::map::Map<'hir>) -> HirIdValidator<'a, 'hir> { @@ -51,7 +51,7 @@ impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> { } } -impl<'a, 'hir: 'a> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { +impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { fn visit_item(&mut self, i: &'hir hir::Item) { let mut inner_visitor = self.new_inner_visitor(self.hir_map); inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i)); @@ -68,7 +68,7 @@ impl<'a, 'hir: 'a> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> { } } -impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { +impl<'a, 'hir> HirIdValidator<'a, 'hir> { #[cold] #[inline(never)] fn error(&self, f: impl FnOnce() -> String) { @@ -133,7 +133,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { } } -impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { +impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'hir> { diff --git a/src/librustc/infer/at.rs b/src/librustc/infer/at.rs index 0bb939889a89..e4aec59c1f64 100644 --- a/src/librustc/infer/at.rs +++ b/src/librustc/infer/at.rs @@ -30,13 +30,13 @@ use super::*; use crate::ty::Const; use crate::ty::relate::{Relate, TypeRelation}; -pub struct At<'a, 'tcx: 'a> { +pub struct At<'a, 'tcx> { pub infcx: &'a InferCtxt<'a, 'tcx>, pub cause: &'a ObligationCause<'tcx>, pub param_env: ty::ParamEnv<'tcx>, } -pub struct Trace<'a, 'tcx: 'a> { +pub struct Trace<'a, 'tcx> { at: At<'a, 'tcx>, a_is_expected: bool, trace: TypeTrace<'tcx>, diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index b4779eec65f4..383048b5fe72 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -275,7 +275,7 @@ impl CanonicalizeRegionMode for CanonicalizeFreeRegionsOtherThanStatic { } } -struct Canonicalizer<'cx, 'tcx: 'cx> { +struct Canonicalizer<'cx, 'tcx> { infcx: Option<&'cx InferCtxt<'cx, 'tcx>>, tcx: TyCtxt<'tcx>, variables: SmallVec<[CanonicalVarInfo; 8]>, diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs index 23550569f7cc..e20b53455f49 100644 --- a/src/librustc/infer/combine.rs +++ b/src/librustc/infer/combine.rs @@ -44,7 +44,7 @@ use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; #[derive(Clone)] -pub struct CombineFields<'infcx, 'tcx: 'infcx> { +pub struct CombineFields<'infcx, 'tcx> { pub infcx: &'infcx InferCtxt<'infcx, 'tcx>, pub trace: TypeTrace<'tcx>, pub cause: Option, @@ -355,7 +355,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { } } -struct Generalizer<'cx, 'tcx: 'cx> { +struct Generalizer<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, /// The span, used when creating new type variables and things. diff --git a/src/librustc/infer/equate.rs b/src/librustc/infer/equate.rs index 39d8241e6b42..5eebe9e78d35 100644 --- a/src/librustc/infer/equate.rs +++ b/src/librustc/infer/equate.rs @@ -11,7 +11,7 @@ use crate::mir::interpret::ConstValue; use crate::infer::unify_key::replace_if_possible; /// Ensures `a` is made equal to `b`. Returns `a` on success. -pub struct Equate<'combine, 'infcx: 'combine, 'tcx: 'infcx> { +pub struct Equate<'combine, 'infcx, 'tcx> { fields: &'combine mut CombineFields<'infcx, 'tcx>, a_is_expected: bool, } diff --git a/src/librustc/infer/error_reporting/nice_region_error/mod.rs b/src/librustc/infer/error_reporting/nice_region_error/mod.rs index 541d9a96dbe6..1edb1c601bf1 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/mod.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/mod.rs @@ -30,7 +30,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { } } -pub struct NiceRegionError<'cx, 'tcx: 'cx> { +pub struct NiceRegionError<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, error: Option>, regions: Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)>, diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index 645f2b023380..7f4a817faf18 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -41,7 +41,7 @@ use std::collections::hash_map::Entry; use super::InferCtxt; use super::unify_key::ToType; -pub struct TypeFreshener<'a, 'tcx: 'a> { +pub struct TypeFreshener<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, ty_freshen_count: u32, const_freshen_count: u32, diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs index 59364862c649..658a9c1d8880 100644 --- a/src/librustc/infer/fudge.rs +++ b/src/librustc/infer/fudge.rs @@ -133,7 +133,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } -pub struct InferenceFudger<'a, 'tcx: 'a> { +pub struct InferenceFudger<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, type_vars: (Range, Vec), int_vars: Range, diff --git a/src/librustc/infer/glb.rs b/src/librustc/infer/glb.rs index 7f184d3424f2..550213167470 100644 --- a/src/librustc/infer/glb.rs +++ b/src/librustc/infer/glb.rs @@ -8,7 +8,7 @@ use crate::ty::{self, Ty, TyCtxt}; use crate::ty::relate::{Relate, RelateResult, TypeRelation}; /// "Greatest lower bound" (common subtype) -pub struct Glb<'combine, 'infcx: 'combine, 'tcx: 'infcx> { +pub struct Glb<'combine, 'infcx, 'tcx> { fields: &'combine mut CombineFields<'infcx, 'tcx>, a_is_expected: bool, } diff --git a/src/librustc/infer/lattice.rs b/src/librustc/infer/lattice.rs index c7766636e04e..a3372f503791 100644 --- a/src/librustc/infer/lattice.rs +++ b/src/librustc/infer/lattice.rs @@ -27,7 +27,7 @@ use crate::ty::TyVar; use crate::ty::{self, Ty}; use crate::ty::relate::{RelateResult, TypeRelation}; -pub trait LatticeDir<'f, 'tcx: 'f>: TypeRelation<'tcx> { +pub trait LatticeDir<'f, 'tcx>: TypeRelation<'tcx> { fn infcx(&self) -> &'f InferCtxt<'f, 'tcx>; fn cause(&self) -> &ObligationCause<'tcx>; @@ -48,7 +48,7 @@ pub fn super_lattice_tys<'a, 'tcx, L>( ) -> RelateResult<'tcx, Ty<'tcx>> where L: LatticeDir<'a, 'tcx>, - 'tcx: 'a, + 'tcx, { debug!("{}.lattice_tys({:?}, {:?})", this.tag(), diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index aa4bbcad6d5b..ad481417d5e5 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -107,7 +107,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>( } } -struct ConstraintGraph<'a, 'tcx: 'a> { +struct ConstraintGraph<'a, 'tcx> { graph_name: String, region_rels: &'a RegionRelations<'a, 'tcx>, map: &'a BTreeMap, SubregionOrigin<'tcx>>, diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 16f5a9d3b36c..2613f4c7c2ae 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -93,7 +93,7 @@ struct RegionAndOrigin<'tcx> { type RegionGraph<'tcx> = Graph<(), Constraint<'tcx>>; -struct LexicalResolver<'cx, 'tcx: 'cx> { +struct LexicalResolver<'cx, 'tcx> { region_rels: &'cx RegionRelations<'cx, 'tcx>, var_infos: VarInfos, data: RegionConstraintData<'tcx>, diff --git a/src/librustc/infer/lub.rs b/src/librustc/infer/lub.rs index 2a9f5856eb85..156288b9e6af 100644 --- a/src/librustc/infer/lub.rs +++ b/src/librustc/infer/lub.rs @@ -8,7 +8,7 @@ use crate::ty::{self, Ty, TyCtxt}; use crate::ty::relate::{Relate, RelateResult, TypeRelation}; /// "Least upper bound" (common supertype) -pub struct Lub<'combine, 'infcx: 'combine, 'tcx: 'infcx> { +pub struct Lub<'combine, 'infcx, 'tcx> { fields: &'combine mut CombineFields<'infcx, 'tcx>, a_is_expected: bool, } diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 47a276b2bcc5..fc46fe383c97 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -585,7 +585,7 @@ impl<'tcx> InferOk<'tcx, ()> { } #[must_use = "once you start a snapshot, you should always consume it"] -pub struct CombinedSnapshot<'a, 'tcx: 'a> { +pub struct CombinedSnapshot<'a, 'tcx> { projection_cache_snapshot: traits::ProjectionCacheSnapshot, type_snapshot: type_variable::Snapshot<'tcx>, const_snapshot: ut::Snapshot>>, diff --git a/src/librustc/infer/nll_relate/mod.rs b/src/librustc/infer/nll_relate/mod.rs index 2c821d0ae15c..21489965b1bf 100644 --- a/src/librustc/infer/nll_relate/mod.rs +++ b/src/librustc/infer/nll_relate/mod.rs @@ -38,7 +38,7 @@ pub enum NormalizationStrategy { Eager, } -pub struct TypeRelating<'me, 'tcx: 'me, D> +pub struct TypeRelating<'me, 'tcx, D> where D: TypeRelatingDelegate<'tcx>, { @@ -741,7 +741,7 @@ where /// binder depth, and finds late-bound regions targeting the /// `for<..`>. For each of those, it creates an entry in /// `bound_region_scope`. -struct ScopeInstantiator<'me, 'tcx: 'me> { +struct ScopeInstantiator<'me, 'tcx> { next_region: &'me mut dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx>, // The debruijn index of the scope we are instantiating. target_index: ty::DebruijnIndex, @@ -798,7 +798,7 @@ impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> { /// scopes. /// /// [blog post]: https://is.gd/0hKvIr -struct TypeGeneralizer<'me, 'tcx: 'me, D> +struct TypeGeneralizer<'me, 'tcx, D> where D: TypeRelatingDelegate<'tcx> + 'me, { diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 328ace51a582..c164f5446fd8 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -723,7 +723,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { } } -struct Instantiator<'a, 'tcx: 'a> { +struct Instantiator<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, parent_def_id: DefId, body_id: hir::HirId, diff --git a/src/librustc/infer/outlives/env.rs b/src/librustc/infer/outlives/env.rs index 4b5df444148b..d55588612859 100644 --- a/src/librustc/infer/outlives/env.rs +++ b/src/librustc/infer/outlives/env.rs @@ -67,7 +67,7 @@ pub struct OutlivesEnvironment<'tcx> { /// because of implied bounds. pub type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>; -impl<'a, 'tcx: 'a> OutlivesEnvironment<'tcx> { +impl<'a, 'tcx> OutlivesEnvironment<'tcx> { pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self { let mut env = OutlivesEnvironment { param_env, diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index 671718b1008e..0ae4446ee63f 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -226,7 +226,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { /// via a "delegate" of type `D` -- this is usually the `infcx`, which /// accrues them into the `region_obligations` code, but for NLL we /// use something else. -pub struct TypeOutlives<'cx, 'tcx: 'cx, D> +pub struct TypeOutlives<'cx, 'tcx, D> where D: TypeOutlivesDelegate<'tcx>, { diff --git a/src/librustc/infer/outlives/verify.rs b/src/librustc/infer/outlives/verify.rs index 96335e1052ee..f23e52fcfe49 100644 --- a/src/librustc/infer/outlives/verify.rs +++ b/src/librustc/infer/outlives/verify.rs @@ -12,7 +12,7 @@ use crate::util::captures::Captures; /// via a "delegate" of type `D` -- this is usually the `infcx`, which /// accrues them into the `region_obligations` code, but for NLL we /// use something else. -pub struct VerifyBoundCx<'cx, 'tcx: 'cx> { +pub struct VerifyBoundCx<'cx, 'tcx> { tcx: TyCtxt<'tcx>, region_bound_pairs: &'cx RegionBoundPairs<'tcx>, implicit_region_bound: Option>, diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs index 810c64185a71..7e553d7666b2 100644 --- a/src/librustc/infer/resolve.rs +++ b/src/librustc/infer/resolve.rs @@ -12,7 +12,7 @@ use crate::ty::fold::{TypeFolder, TypeVisitor}; /// been unified with (similar to `shallow_resolve`, but deep). This is /// useful for printing messages etc but also required at various /// points for correctness. -pub struct OpportunisticVarResolver<'a, 'tcx: 'a> { +pub struct OpportunisticVarResolver<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, } @@ -50,7 +50,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> { /// The opportunistic type and region resolver is similar to the /// opportunistic type resolver, but also opportunistically resolves /// regions. It is useful for canonicalization. -pub struct OpportunisticTypeAndRegionResolver<'a, 'tcx: 'a> { +pub struct OpportunisticTypeAndRegionResolver<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, } @@ -101,7 +101,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticTypeAndRegionResolver<'a, 'tcx> /// type variables that don't yet have a value. The first unresolved type is stored. /// It does not construct the fully resolved type (which might /// involve some hashing and so forth). -pub struct UnresolvedTypeFinder<'a, 'tcx: 'a> { +pub struct UnresolvedTypeFinder<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, /// Used to find the type parameter name and location for error reporting. @@ -171,7 +171,7 @@ where // N.B. This type is not public because the protocol around checking the // `err` field is not enforcable otherwise. -struct FullTypeResolver<'a, 'tcx: 'a> { +struct FullTypeResolver<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, err: Option>, } diff --git a/src/librustc/infer/sub.rs b/src/librustc/infer/sub.rs index ed84e3f63ae1..1452a6dee5bc 100644 --- a/src/librustc/infer/sub.rs +++ b/src/librustc/infer/sub.rs @@ -11,7 +11,7 @@ use crate::mir::interpret::ConstValue; use std::mem; /// Ensures `a` is made a subtype of `b`. Returns `a` on success. -pub struct Sub<'combine, 'infcx: 'combine, 'tcx: 'infcx> { +pub struct Sub<'combine, 'infcx, 'tcx> { fields: &'combine mut CombineFields<'infcx, 'tcx>, a_is_expected: bool, } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index e90f4ca94c62..7f09120bbdd5 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -507,7 +507,7 @@ impl LintStore { } /// Context for lint checking after type checking. -pub struct LateContext<'a, 'tcx: 'a> { +pub struct LateContext<'a, 'tcx> { /// Type context we're checking in. pub tcx: TyCtxt<'tcx>, @@ -533,7 +533,7 @@ pub struct LateContext<'a, 'tcx: 'a> { only_module: bool, } -pub struct LateContextAndPass<'a, 'tcx: 'a, T: LateLintPass<'a, 'tcx>> { +pub struct LateContextAndPass<'a, 'tcx, T: LateLintPass<'a, 'tcx>> { context: LateContext<'a, 'tcx>, pass: T, } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 63503f58156b..9e2038fa89ed 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -38,7 +38,7 @@ fn should_explore<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> bool { } } -struct MarkSymbolVisitor<'a, 'tcx: 'a> { +struct MarkSymbolVisitor<'a, 'tcx> { worklist: Vec, tcx: TyCtxt<'tcx>, tables: &'a ty::TypeckTables<'tcx>, @@ -351,7 +351,7 @@ fn has_allow_dead_code_or_lang_attr( // or // 2) We are not sure to be live or not // * Implementation of a trait method -struct LifeSeeder<'k, 'tcx: 'k> { +struct LifeSeeder<'k, 'tcx> { worklist: Vec, krate: &'k hir::Crate, tcx: TyCtxt<'tcx>, diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index d9e7caebb982..d1867e8fa36b 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -11,7 +11,7 @@ use crate::hir::itemlikevisit::ItemLikeVisitor; use crate::ty::TyCtxt; use crate::ty::query::Providers; -struct EntryContext<'a, 'tcx: 'a> { +struct EntryContext<'a, 'tcx> { session: &'a Session, map: &'a hir_map::Map<'tcx>, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 61770e6f4870..1c3eead90fa9 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -229,7 +229,7 @@ impl OverloadedCallType { // The ExprUseVisitor type // // This is the code that actually walks the tree. -pub struct ExprUseVisitor<'a, 'tcx: 'a> { +pub struct ExprUseVisitor<'a, 'tcx> { mc: mc::MemCategorizationContext<'a, 'tcx>, delegate: &'a mut dyn Delegate<'tcx>, param_env: ty::ParamEnv<'tcx>, diff --git a/src/librustc/middle/free_region.rs b/src/librustc/middle/free_region.rs index a8a7df08469a..60e41f7eb0f7 100644 --- a/src/librustc/middle/free_region.rs +++ b/src/librustc/middle/free_region.rs @@ -15,7 +15,7 @@ use crate::ty::{self, TyCtxt, Region}; /// /// This stuff is a bit convoluted and should be refactored, but as we /// transition to NLL, it'll all go away anyhow. -pub struct RegionRelations<'a, 'tcx: 'a> { +pub struct RegionRelations<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, /// The context used to fetch the region maps. diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 3d2bc6c7bf88..36411f81f1a2 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -352,7 +352,7 @@ impl IrMaps<'tcx> { } } -fn visit_fn<'a, 'tcx: 'a>( +fn visit_fn<'a, 'tcx>( ir: &mut IrMaps<'tcx>, fk: FnKind<'tcx>, decl: &'tcx hir::FnDecl, @@ -682,7 +682,7 @@ const ACC_READ: u32 = 1; const ACC_WRITE: u32 = 2; const ACC_USE: u32 = 4; -struct Liveness<'a, 'tcx: 'a> { +struct Liveness<'a, 'tcx> { ir: &'a mut IrMaps<'tcx>, tables: &'a ty::TypeckTables<'tcx>, s: Specials, diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 628a44cbfe01..593c5e734216 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -65,7 +65,7 @@ fn method_might_be_inlined<'tcx>( } // Information needed while computing reachability. -struct ReachableContext<'a, 'tcx: 'a> { +struct ReachableContext<'a, 'tcx> { // The type context. tcx: TyCtxt<'tcx>, tables: &'a ty::TypeckTables<'tcx>, @@ -334,13 +334,13 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // items of non-exported traits (or maybe all local traits?) unless their respective // trait items are used from inlinable code through method call syntax or UFCS, or their // trait is a lang item. -struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> { +struct CollectPrivateImplItemsVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, access_levels: &'a privacy::AccessLevels, worklist: &'a mut Vec, } -impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> { +impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { // Anything which has custom linkage gets thrown on the worklist no // matter where it is in the crate, along with "special std symbols" diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 76bff500634a..f68e18c2bb85 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -217,7 +217,7 @@ impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes { object_lifetime_defaults }); -struct LifetimeContext<'a, 'tcx: 'a> { +struct LifetimeContext<'a, 'tcx> { tcx: TyCtxt<'tcx>, map: &'a mut NamedRegionMap, scope: ScopeRef<'a>, @@ -1160,7 +1160,7 @@ fn signal_shadowing_problem(tcx: TyCtxt<'_>, name: ast::Name, orig: Original, sh // Adds all labels in `b` to `ctxt.labels_in_fn`, signalling a warning // if one of the label shadows a lifetime or another label. fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { - struct GatherLabels<'a, 'tcx: 'a> { + struct GatherLabels<'a, 'tcx> { tcx: TyCtxt<'tcx>, scope: ScopeRef<'a>, labels_in_fn: &'a mut Vec, diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 19d127a565fc..5a1e5212f865 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -105,7 +105,7 @@ impl_stable_hash_for!(struct self::Index<'tcx> { }); // A private tree-walker for producing an Index. -struct Annotator<'a, 'tcx: 'a> { +struct Annotator<'a, 'tcx> { tcx: TyCtxt<'tcx>, index: &'a mut Index<'tcx>, parent_stab: Option<&'tcx Stability>, @@ -113,7 +113,7 @@ struct Annotator<'a, 'tcx: 'a> { in_trait_impl: bool, } -impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { +impl<'a, 'tcx> Annotator<'a, 'tcx> { // Determine the stability for a node based on its attributes and inherited // stability. The stability is recorded in the index and used as the parent. fn annotate(&mut self, hir_id: HirId, attrs: &[Attribute], @@ -316,12 +316,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } } -struct MissingStabilityAnnotations<'a, 'tcx: 'a> { +struct MissingStabilityAnnotations<'a, 'tcx> { tcx: TyCtxt<'tcx>, access_levels: &'a AccessLevels, } -impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> { +impl<'a, 'tcx> MissingStabilityAnnotations<'a, 'tcx> { fn check_missing_stability(&self, hir_id: HirId, span: Span, name: &str) { let stab = self.tcx.stability().local_stability(hir_id); let is_error = !self.tcx.sess.opts.test && diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 422ff3f2fd36..b6cd24c291ac 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -17,7 +17,7 @@ use crate::ty::TyCtxt; macro_rules! weak_lang_items { ($($name:ident, $item:ident, $sym:ident;)*) => ( -struct Context<'a, 'tcx: 'a> { +struct Context<'a, 'tcx> { tcx: TyCtxt<'tcx>, items: &'a mut lang_items::LanguageItems, } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 1d5c1cb927d2..9dfd8d959a3c 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2104,7 +2104,7 @@ impl<'tcx> Place<'tcx> { /// N.B., this particular impl strategy is not the most obvious. It was /// chosen because it makes a measurable difference to NLL /// performance, as this code (`borrow_conflicts_with_place`) is somewhat hot. -pub enum Projections<'p, 'tcx: 'p> { +pub enum Projections<'p, 'tcx> { Empty, List { @@ -2143,7 +2143,7 @@ impl<'p, 'tcx> IntoIterator for &'p Projections<'p, 'tcx> { /// N.B., this is not a *true* Rust iterator -- the code above just /// manually invokes `next`. This is because we (sometimes) want to /// keep executing even after `None` has been returned. -pub struct ProjectionsIter<'p, 'tcx: 'p> { +pub struct ProjectionsIter<'p, 'tcx> { pub value: &'p Projections<'p, 'tcx>, } diff --git a/src/librustc/mir/traversal.rs b/src/librustc/mir/traversal.rs index 77af0e6661b7..1416a5f0a6e9 100644 --- a/src/librustc/mir/traversal.rs +++ b/src/librustc/mir/traversal.rs @@ -20,7 +20,7 @@ use super::*; /// /// A preorder traversal of this graph is either `A B D C` or `A C D B` #[derive(Clone)] -pub struct Preorder<'a, 'tcx: 'a> { +pub struct Preorder<'a, 'tcx> { body: &'a Body<'tcx>, visited: BitSet, worklist: Vec, @@ -98,7 +98,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> { /// ``` /// /// A Postorder traversal of this graph is `D B C A` or `D C B A` -pub struct Postorder<'a, 'tcx: 'a> { +pub struct Postorder<'a, 'tcx> { body: &'a Body<'tcx>, visited: BitSet, visit_stack: Vec<(BasicBlock, Successors<'a>)>, @@ -251,7 +251,7 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> { /// constructed as few times as possible. Use the `reset` method to be able /// to re-use the traversal #[derive(Clone)] -pub struct ReversePostorder<'a, 'tcx: 'a> { +pub struct ReversePostorder<'a, 'tcx> { body: &'a Body<'tcx>, blocks: Vec, idx: usize diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index dcf69fee0e16..4b65d3b9d8e3 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1449,7 +1449,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { param_env: ty::ParamEnv<'tcx>, pred: ty::PolyTraitRef<'tcx>, ) -> bool { - struct ParamToVarFolder<'a, 'tcx: 'a> { + struct ParamToVarFolder<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, var_map: FxHashMap, Ty<'tcx>>, } diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 5e2c949c7d8d..f106458c7676 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -224,7 +224,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> { } } -struct FulfillProcessor<'a, 'b: 'a, 'tcx: 'b> { +struct FulfillProcessor<'a, 'b, 'tcx> { selcx: &'a mut SelectionContext<'b, 'tcx>, register_region_obligations: bool, } diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index d189bb231163..04364cd63119 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -285,7 +285,7 @@ where } } -struct AssocTypeNormalizer<'a, 'b: 'a, 'tcx: 'b> { +struct AssocTypeNormalizer<'a, 'b, 'tcx> { selcx: &'a mut SelectionContext<'b, 'tcx>, param_env: ty::ParamEnv<'tcx>, cause: ObligationCause<'tcx>, diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index 50476721e824..a45213b06d3a 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -73,7 +73,7 @@ pub struct NormalizationResult<'tcx> { pub normalized_ty: Ty<'tcx>, } -struct QueryNormalizer<'cx, 'tcx: 'cx> { +struct QueryNormalizer<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, cause: &'cx ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 5aa7a120957c..c698b0c29331 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -50,7 +50,7 @@ use std::iter; use std::rc::Rc; use crate::util::nodemap::{FxHashMap, FxHashSet}; -pub struct SelectionContext<'cx, 'tcx: 'cx> { +pub struct SelectionContext<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, /// Freshener used specifically for entries on the obligation @@ -144,7 +144,7 @@ impl IntercrateAmbiguityCause { } // A stack that walks back up the stack frame. -struct TraitObligationStack<'prev, 'tcx: 'prev> { +struct TraitObligationStack<'prev, 'tcx> { obligation: &'prev TraitObligation<'tcx>, /// Trait ref from `obligation` but "freshened" with the @@ -697,7 +697,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result where I: IntoIterator>, - 'tcx: 'a, + 'tcx, { let mut result = EvaluatedToOk; for obligation in predicates { @@ -3789,7 +3789,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { matcher.relate(previous, current).is_ok() } - fn push_stack<'o, 's: 'o>( + fn push_stack<'o, 's>( &mut self, previous_stack: TraitObligationStackList<'s, 'tcx>, obligation: &'o TraitObligation<'tcx>, @@ -4252,7 +4252,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> { } #[derive(Copy, Clone)] -struct TraitObligationStackList<'o, 'tcx: 'o> { +struct TraitObligationStackList<'o, 'tcx> { cache: &'o ProvisionalEvaluationCache<'tcx>, head: Option<&'o TraitObligationStack<'o, 'tcx>>, } diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 6f83991a2daa..5781f40b93ad 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -511,7 +511,7 @@ fn decode_tagged<'a, 'tcx, D, T, V>(decoder: &mut D, where T: Decodable + Eq + ::std::fmt::Debug, V: Decodable, D: DecoderWithPosition, - 'tcx: 'a, + 'tcx, { let start_pos = decoder.position(); diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 48e68167f824..0f158d2982a2 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -89,7 +89,7 @@ macro_rules! profq_query_msg { /// A type representing the responsibility to execute the job in the `job` field. /// This will poison the relevant query if dropped. -pub(super) struct JobOwner<'a, 'tcx: 'a, Q: QueryDescription<'tcx> + 'a> { +pub(super) struct JobOwner<'a, 'tcx, Q: QueryDescription<'tcx> + 'a> { cache: &'a Lock>, key: Q::Key, job: Lrc>, @@ -230,7 +230,7 @@ pub struct CycleError<'tcx> { } /// The result of `try_get_lock` -pub(super) enum TryGetJob<'a, 'tcx: 'a, D: QueryDescription<'tcx> + 'a> { +pub(super) enum TryGetJob<'a, 'tcx, D: QueryDescription<'tcx> + 'a> { /// The query is not yet started. Contains a guard to the cache eventually used to start it. NotYetStarted(JobOwner<'a, 'tcx, D>), diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 6b2f00e5f703..1979b4317a7a 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -101,7 +101,7 @@ pub fn predicate_obligations<'a, 'tcx>( wf.normalize() } -struct WfPredicates<'a, 'tcx: 'a> { +struct WfPredicates<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, param_env: ty::ParamEnv<'tcx>, body_id: hir::HirId, diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 54989db46c1c..ace44421d375 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -78,7 +78,7 @@ fn owned_ptr_base_path_rc<'tcx>(loan_path: &Rc>) -> Rc { +struct CheckLoanCtxt<'a, 'tcx> { bccx: &'a BorrowckCtxt<'a, 'tcx>, dfcx_loans: &'a LoanDataFlow<'tcx>, move_data: &'a move_data::FlowedMoveData<'tcx>, diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 4d03b58179db..cc1f7232e04c 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -16,7 +16,7 @@ use rustc::hir::*; use rustc::hir::Node; use log::debug; -struct GatherMoveInfo<'c, 'tcx: 'c> { +struct GatherMoveInfo<'c, 'tcx> { id: hir::ItemLocalId, kind: MoveKind, cmt: &'c mc::cmt_<'tcx>, @@ -91,7 +91,7 @@ pub fn gather_move_from_expr<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, gather_move(bccx, move_data, move_error_collector, move_info); } -pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>, +pub fn gather_move_from_pat<'a, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_data: &MoveData<'tcx>, move_error_collector: &mut MoveErrorCollector<'tcx>, move_pat: &hir::Pat, @@ -121,7 +121,7 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>, gather_move(bccx, move_data, move_error_collector, move_info); } -fn gather_move<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>, +fn gather_move<'a, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_data: &MoveData<'tcx>, move_error_collector: &mut MoveErrorCollector<'tcx>, move_info: GatherMoveInfo<'c, 'tcx>) { diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs index 1607a6292010..3122a6060fbd 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs @@ -38,7 +38,7 @@ pub fn guarantee_lifetime<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, /////////////////////////////////////////////////////////////////////////// // Private -struct GuaranteeLifetimeContext<'a, 'tcx: 'a> { +struct GuaranteeLifetimeContext<'a, 'tcx> { bccx: &'a BorrowckCtxt<'a, 'tcx>, // the scope of the function body for the enclosing item diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index b1854a06693c..887011d3476d 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -56,7 +56,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, (all_loans, move_data) } -struct GatherLoanCtxt<'a, 'tcx: 'a> { +struct GatherLoanCtxt<'a, 'tcx> { bccx: &'a BorrowckCtxt<'a, 'tcx>, move_data: move_data::MoveData<'tcx>, move_error_collector: move_error::MoveErrorCollector<'tcx>, diff --git a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs index 9f4c05a6b255..371e6c55a738 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs @@ -37,7 +37,7 @@ pub fn compute_restrictions<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, /////////////////////////////////////////////////////////////////////////// // Private -struct RestrictionsContext<'a, 'tcx: 'a> { +struct RestrictionsContext<'a, 'tcx> { bccx: &'a BorrowckCtxt<'a, 'tcx>, span: Span, loan_region: ty::Region<'tcx>, diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 93cea6d2f019..025d5adc2b3e 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -552,7 +552,7 @@ pub enum bckerr_code<'tcx> { // Combination of an error code and the categorization of the expression // that caused it #[derive(Debug, PartialEq)] -pub struct BckError<'c, 'tcx: 'c> { +pub struct BckError<'c, 'tcx> { span: Span, cause: AliasableViolationKind, cmt: &'c mc::cmt_<'tcx>, diff --git a/src/librustc_borrowck/graphviz.rs b/src/librustc_borrowck/graphviz.rs index 1f2480666959..7a8a23ca76af 100644 --- a/src/librustc_borrowck/graphviz.rs +++ b/src/librustc_borrowck/graphviz.rs @@ -30,7 +30,7 @@ impl Variant { } } -pub struct DataflowLabeller<'a, 'tcx: 'a> { +pub struct DataflowLabeller<'a, 'tcx> { pub inner: cfg_dot::LabelledCFG<'a, 'tcx>, pub variants: Vec, pub borrowck_ctxt: &'a BorrowckCtxt<'a, 'tcx>, diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index 9102ba91df81..e06b4d8b3063 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -27,7 +27,7 @@ use std::iter::TrustedLen; // All Builders must have an llfn associated with them #[must_use] -pub struct Builder<'a, 'll: 'a, 'tcx: 'll> { +pub struct Builder<'a, 'll, 'tcx> { pub llbuilder: &'ll mut llvm::Builder<'ll>, pub cx: &'a CodegenCx<'ll, 'tcx>, } diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 588f7481cc06..6a61b180de43 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -34,7 +34,7 @@ use crate::abi::Abi; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM /// `llvm::Context` so that several compilation units may be optimized in parallel. /// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`. -pub struct CodegenCx<'ll, 'tcx: 'll> { +pub struct CodegenCx<'ll, 'tcx> { pub tcx: TyCtxt<'tcx>, pub check_overflow: bool, pub use_dll_storage_attrs: bool, diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index a0dd767a3a8f..a8a998a4d956 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -125,7 +125,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend { ) { unsafe { allocator::codegen(tcx, mods, kind) } } - fn compile_codegen_unit<'a, 'tcx: 'a>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString) { + fn compile_codegen_unit<'a, 'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString) { base::compile_codegen_unit(tcx, cgu_name); } fn target_machine_factory( diff --git a/src/librustc_codegen_ssa/README.md b/src/librustc_codegen_ssa/README.md index 11fac239edf1..c8bb2e7ee996 100644 --- a/src/librustc_codegen_ssa/README.md +++ b/src/librustc_codegen_ssa/README.md @@ -29,11 +29,11 @@ While the LLVM-specific code will be left in `rustc_codegen_llvm`, all the new t The two most important structures for the LLVM codegen are `CodegenCx` and `Builder`. They are parametrized by multiple lifetime parameters and the type for `Value`. ```rust -struct CodegenCx<'ll, 'tcx: 'll> { +struct CodegenCx<'ll, 'tcx> { /* ... */ } -struct Builder<'a, 'll: 'a, 'tcx: 'll> { +struct Builder<'a, 'll, 'tcx> { cx: &'a CodegenCx<'ll, 'tcx>, /* ... */ } @@ -49,7 +49,7 @@ The code in `rustc_codegen_llvm` has to deal with multiple explicit lifetime par Although there are already many lifetime parameters in the code, making it generic uncovered situations where the borrow-checker was passing only due to the special nature of the LLVM objects manipulated (they are extern pointers). For instance, a additional lifetime parameter had to be added to `LocalAnalyser` in `analyse.rs`, leading to the definition: ```rust -struct LocalAnalyzer<'mir, 'a: 'mir, 'tcx: 'a> { +struct LocalAnalyzer<'mir, 'a, 'tcx> { /* ... */ } ``` @@ -61,7 +61,7 @@ However, the two most important structures `CodegenCx` and `Builder` are not def Because they have to be defined by the backend, `CodegenCx` and `Builder` will be the structures implementing all the traits defining the backend's interface. These traits are defined in the folder `rustc_codegen_ssa/traits` and all the backend-agnostic code is parametrized by them. For instance, let us explain how a function in `base.rs` is parametrized: ```rust -pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn codegen_instance<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, instance: Instance<'tcx> ) { @@ -74,7 +74,7 @@ In this signature, we have the two lifetime parameters explained earlier and the On the trait side, here is an example with part of the definition of `BuilderMethods` in `traits/builder.rs`: ```rust -pub trait BuilderMethods<'a, 'tcx: 'a>: +pub trait BuilderMethods<'a, 'tcx>: HasCodegen<'tcx> + DebugInfoBuilderMethods<'tcx> + ArgTypeMethods<'tcx> diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index ca686453b6d4..a06f324d3895 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -88,7 +88,7 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate { } } -pub fn compare_simd_types<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, lhs: Bx::Value, rhs: Bx::Value, @@ -152,7 +152,7 @@ pub fn unsized_info<'tcx, Cx: CodegenMethods<'tcx>>( } /// Coerce `src` to `dst_ty`. `src_ty` must be a thin pointer. -pub fn unsize_thin_ptr<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn unsize_thin_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, src: Bx::Value, src_ty: Ty<'tcx>, @@ -207,7 +207,7 @@ pub fn unsize_thin_ptr<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( /// Coerce `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty` and store the result in `dst` -pub fn coerce_unsized_into<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, src: PlaceRef<'tcx, Bx::Value>, dst: PlaceRef<'tcx, Bx::Value> @@ -266,7 +266,7 @@ pub fn coerce_unsized_into<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } } -pub fn cast_shift_expr_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn cast_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, op: hir::BinOpKind, lhs: Bx::Value, @@ -275,7 +275,7 @@ pub fn cast_shift_expr_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( cast_shift_rhs(bx, op, lhs, rhs) } -fn cast_shift_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +fn cast_shift_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, op: hir::BinOpKind, lhs: Bx::Value, @@ -316,7 +316,7 @@ pub fn wants_msvc_seh(sess: &Session) -> bool { sess.target.target.options.is_like_msvc } -pub fn from_immediate<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn from_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, val: Bx::Value ) -> Bx::Value { @@ -327,7 +327,7 @@ pub fn from_immediate<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } } -pub fn to_immediate<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn to_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, val: Bx::Value, layout: layout::TyLayout<'_>, @@ -338,7 +338,7 @@ pub fn to_immediate<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( val } -pub fn to_immediate_scalar<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn to_immediate_scalar<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, val: Bx::Value, scalar: &layout::Scalar, @@ -349,7 +349,7 @@ pub fn to_immediate_scalar<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( val } -pub fn memcpy_ty<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn memcpy_ty<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, dst: Bx::Value, dst_align: Align, @@ -366,7 +366,7 @@ pub fn memcpy_ty<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( bx.memcpy(dst, dst_align, src, src_align, bx.cx().const_usize(size), flags); } -pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn codegen_instance<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, instance: Instance<'tcx>, ) { @@ -387,7 +387,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( /// Creates the `main` function which will initialize the rust runtime and call /// users main function. -pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx ) { let (main_def_id, span) = match cx.tcx().entry_fn(LOCAL_CRATE) { @@ -412,7 +412,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( None => {} // Do nothing. } - fn create_entry_fn<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( + fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, sp: Span, rust_main: Bx::Value, diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index e22d4db6dcb9..d17edf2ec0a2 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -137,7 +137,7 @@ pub fn langcall(tcx: TyCtxt<'_>, span: Option, msg: &str, li: LangItem) -> // all shifts). For 32- and 64-bit types, this matches the semantics // of Java. (See related discussion on #1877 and #10183.) -pub fn build_unchecked_lshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn build_unchecked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, lhs: Bx::Value, rhs: Bx::Value @@ -148,7 +148,7 @@ pub fn build_unchecked_lshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( bx.shl(lhs, rhs) } -pub fn build_unchecked_rshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn build_unchecked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, lhs_t: Ty<'tcx>, lhs: Bx::Value, @@ -165,7 +165,7 @@ pub fn build_unchecked_rshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } } -fn shift_mask_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +fn shift_mask_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, rhs: Bx::Value ) -> Bx::Value { @@ -174,7 +174,7 @@ fn shift_mask_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( bx.and(rhs, shift_val) } -pub fn shift_mask_val<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn shift_mask_val<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, llty: Bx::Type, mask_llty: Bx::Type, diff --git a/src/librustc_codegen_ssa/glue.rs b/src/librustc_codegen_ssa/glue.rs index e2b49de05bd1..294e2e021d2a 100644 --- a/src/librustc_codegen_ssa/glue.rs +++ b/src/librustc_codegen_ssa/glue.rs @@ -7,7 +7,7 @@ use crate::common::IntPredicate; use crate::meth; use crate::traits::*; -pub fn size_and_align_of_dst<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, t: Ty<'tcx>, info: Option diff --git a/src/librustc_codegen_ssa/meth.rs b/src/librustc_codegen_ssa/meth.rs index d38e434d98ce..7fe9f5f25130 100644 --- a/src/librustc_codegen_ssa/meth.rs +++ b/src/librustc_codegen_ssa/meth.rs @@ -12,7 +12,7 @@ pub const DESTRUCTOR: VirtualIndex = VirtualIndex(0); pub const SIZE: VirtualIndex = VirtualIndex(1); pub const ALIGN: VirtualIndex = VirtualIndex(2); -impl<'a, 'tcx: 'a> VirtualIndex { +impl<'a, 'tcx> VirtualIndex { pub fn from_index(index: usize) -> Self { VirtualIndex(index as u64 + 3) } diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index e2fd1c2bc38e..3d41eddb8035 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -12,7 +12,7 @@ use rustc::ty::layout::{LayoutOf, HasTyCtxt}; use super::FunctionCx; use crate::traits::*; -pub fn non_ssa_locals<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( fx: &FunctionCx<'a, 'tcx, Bx> ) -> BitSet { let mir = fx.mir; @@ -43,7 +43,7 @@ pub fn non_ssa_locals<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( analyzer.non_ssa_locals } -struct LocalAnalyzer<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> { +struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { fx: &'mir FunctionCx<'a, 'tcx, Bx>, dominators: Dominators, non_ssa_locals: BitSet, @@ -94,7 +94,7 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { } } -impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> +impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx, Bx> { fn visit_assign(&mut self, place: &mir::Place<'tcx>, diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index e4b82d849666..b4acc4005464 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -151,7 +151,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> { } /// Codegen implementations for some terminator variants. -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { /// Generates code for a `Resume` terminator. fn codegen_resume_terminator<'b>( &mut self, @@ -788,7 +788,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn codegen_block( &mut self, bb: mir::BasicBlock, diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 78c22206ab7a..d6951b923bf7 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -8,7 +8,7 @@ use crate::traits::*; use super::FunctionCx; -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn eval_mir_constant( &mut self, constant: &mir::Constant<'tcx>, diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index dd69d3583131..78af71b5a498 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -23,7 +23,7 @@ use rustc::mir::traversal; use self::operand::{OperandRef, OperandValue}; /// Master context for codegenning from MIR. -pub struct FunctionCx<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> { +pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { instance: Instance<'tcx>, mir: &'a mir::Body<'tcx>, @@ -87,7 +87,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> { va_list_ref: Option>, } -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn monomorphize(&self, value: &T) -> T where T: TypeFoldable<'tcx> { @@ -167,7 +167,7 @@ enum LocalRef<'tcx, V> { Operand(Option>), } -impl<'a, 'tcx: 'a, V: CodegenObject> LocalRef<'tcx, V> { +impl<'a, 'tcx, V: CodegenObject> LocalRef<'tcx, V> { fn new_operand>( bx: &mut Bx, layout: TyLayout<'tcx>, @@ -185,7 +185,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> LocalRef<'tcx, V> { /////////////////////////////////////////////////////////////////////////// -pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, llfn: Bx::Value, mir: &'a Body<'tcx>, @@ -351,7 +351,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } } -fn create_funclets<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +fn create_funclets<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( mir: &'a Body<'tcx>, bx: &mut Bx, cleanup_kinds: &IndexVec, @@ -420,7 +420,7 @@ fn create_funclets<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( /// Produces, for each argument, a `Value` pointing at the /// argument's value. As arguments are places, these are always /// indirect. -fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, fx: &FunctionCx<'a, 'tcx, Bx>, memory_locals: &BitSet, diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs index b4303cf5c9b2..3305dfe1ffbb 100644 --- a/src/librustc_codegen_ssa/mir/operand.rs +++ b/src/librustc_codegen_ssa/mir/operand.rs @@ -53,7 +53,7 @@ impl fmt::Debug for OperandRef<'tcx, V> { } } -impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> { +impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { pub fn new_zst>( bx: &mut Bx, layout: TyLayout<'tcx> @@ -266,7 +266,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> { } } -impl<'a, 'tcx: 'a, V: CodegenObject> OperandValue { +impl<'a, 'tcx, V: CodegenObject> OperandValue { pub fn store>( self, bx: &mut Bx, @@ -376,7 +376,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandValue { } } -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { fn maybe_codegen_consume_direct( &mut self, bx: &mut Bx, diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index 27311d0a8fbf..81b17d0bee80 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -26,7 +26,7 @@ pub struct PlaceRef<'tcx, V> { pub align: Align, } -impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> { +impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { pub fn new_sized( llval: V, layout: TyLayout<'tcx>, @@ -98,7 +98,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> { } -impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> { +impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { /// Access a field, at a point when the value's case is known. pub fn project_field>( self, bx: &mut Bx, @@ -386,7 +386,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> { } } -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn codegen_place( &mut self, bx: &mut Bx, diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 87e15ba6aac5..4a1971e3e2ee 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -18,7 +18,7 @@ use super::{FunctionCx, LocalRef}; use super::operand::{OperandRef, OperandValue}; use super::place::PlaceRef; -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn codegen_rvalue( &mut self, mut bx: Bx, @@ -687,7 +687,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool { match *rvalue { mir::Rvalue::Ref(..) | @@ -712,7 +712,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } -fn cast_int_to_float<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +fn cast_int_to_float<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, signed: bool, x: Bx::Value, @@ -746,7 +746,7 @@ fn cast_int_to_float<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } } -fn cast_float_to_int<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( +fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, signed: bool, x: Bx::Value, diff --git a/src/librustc_codegen_ssa/mir/statement.rs b/src/librustc_codegen_ssa/mir/statement.rs index 618d05245d2c..750b2f5b1a50 100644 --- a/src/librustc_codegen_ssa/mir/statement.rs +++ b/src/librustc_codegen_ssa/mir/statement.rs @@ -6,7 +6,7 @@ use super::LocalRef; use super::OperandValue; use crate::traits::*; -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { +impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn codegen_statement( &mut self, mut bx: Bx, diff --git a/src/librustc_codegen_ssa/mono_item.rs b/src/librustc_codegen_ssa/mono_item.rs index dc50c0e19efb..57bd2f36dd7f 100644 --- a/src/librustc_codegen_ssa/mono_item.rs +++ b/src/librustc_codegen_ssa/mono_item.rs @@ -6,7 +6,7 @@ use crate::traits::*; use rustc::mir::mono::MonoItem; -pub trait MonoItemExt<'a, 'tcx: 'a> { +pub trait MonoItemExt<'a, 'tcx> { fn define>(&self, cx: &'a Bx::CodegenCx); fn predefine>( &self, @@ -17,7 +17,7 @@ pub trait MonoItemExt<'a, 'tcx: 'a> { fn to_raw_string(&self) -> String; } -impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { +impl<'a, 'tcx> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { fn define>(&self, cx: &'a Bx::CodegenCx) { debug!("BEGIN IMPLEMENTING '{} ({})' in cgu {}", self.to_string(cx.tcx(), true), diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs index 2f95c9a7d8bb..f2edff2faace 100644 --- a/src/librustc_codegen_ssa/traits/backend.rs +++ b/src/librustc_codegen_ssa/traits/backend.rs @@ -44,7 +44,7 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se mods: &mut Self::Module, kind: AllocatorKind, ); - fn compile_codegen_unit<'a, 'tcx: 'a>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString); + fn compile_codegen_unit<'a, 'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString); // If find_features is true this won't access `sess.crate_types` by assuming // that `is_pie_binary` is false. When we discover LLVM target features // `sess.crate_types` is uninitialized so we cannot access it. diff --git a/src/librustc_codegen_ssa/traits/builder.rs b/src/librustc_codegen_ssa/traits/builder.rs index 2af57bcb064b..1c80e614db8d 100644 --- a/src/librustc_codegen_ssa/traits/builder.rs +++ b/src/librustc_codegen_ssa/traits/builder.rs @@ -22,7 +22,7 @@ pub enum OverflowOp { Mul, } -pub trait BuilderMethods<'a, 'tcx: 'a>: +pub trait BuilderMethods<'a, 'tcx>: HasCodegen<'tcx> + DebugInfoBuilderMethods<'tcx> + ArgTypeMethods<'tcx> diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 683da5865cda..eb89b5c1e637 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -453,7 +453,7 @@ impl<'a> pprust::PpAnn for HygieneAnnotation<'a> { } } -struct TypedAnnotation<'a, 'tcx: 'a> { +struct TypedAnnotation<'a, 'tcx> { tcx: TyCtxt<'tcx>, tables: Cell<&'a ty::TypeckTables<'tcx>>, } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index f3b940856939..c6f361855c7d 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1088,7 +1088,7 @@ impl TypeAliasBounds { // We use a HIR visitor to walk the type. use rustc::hir::intravisit::{self, Visitor}; - struct WalkAssocTypes<'a, 'db> where 'db: 'a { + struct WalkAssocTypes<'a, 'db> where 'db { err: &'a mut DiagnosticBuilder<'db> } impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 9fc23e45d203..2b99e2d91445 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -505,7 +505,7 @@ declare_lint! { declare_lint_pass!(ImproperCTypes => [IMPROPER_CTYPES]); -struct ImproperCTypesVisitor<'a, 'tcx: 'a> { +struct ImproperCTypesVisitor<'a, 'tcx> { cx: &'a LateContext<'a, 'tcx>, } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 5fef8e53e1d0..ff523c7b68a9 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -295,7 +295,7 @@ impl<'a> CrateLoader<'a> { path_kind: PathKind, ) -> Option<(LoadResult, Option)> where - 'a: 'b + 'a { // Use a new locator Context so trying to load a proc macro doesn't affect the error // message we emit diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 4bafe16b8e66..98cdeb699687 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -35,7 +35,7 @@ use syntax::ext::hygiene::Mark; use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION}; use log::debug; -pub struct DecodeContext<'a, 'tcx: 'a> { +pub struct DecodeContext<'a, 'tcx> { opaque: opaque::Decoder<'a>, cdata: Option<&'a CrateMetadata>, sess: Option<&'a Session>, @@ -128,7 +128,7 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadata, TyCtxt<'tcx>) { } } -impl<'a, 'tcx: 'a, T: Decodable> Lazy { +impl<'a, 'tcx, T: Decodable> Lazy { pub fn decode>(self, meta: M) -> T { let mut dcx = meta.decoder(self.position); dcx.lazy_state = LazyState::NodeStart(self.position); @@ -136,7 +136,7 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy { } } -impl<'a, 'tcx: 'a, T: Decodable> LazySeq { +impl<'a, 'tcx, T: Decodable> LazySeq { pub fn decode>( self, meta: M, diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index f6f2cfbfc088..40d8173ce400 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -160,7 +160,7 @@ impl<'tcx> BorrowSet<'tcx> { } } -struct GatherBorrows<'a, 'tcx: 'a> { +struct GatherBorrows<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, idx_vec: IndexVec>, diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index 5a57db2a6724..9a9310fbe05f 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -22,7 +22,7 @@ use std::fmt; use std::rc::Rc; // (forced to be `pub` due to its use as an associated type below.) -crate struct Flows<'b, 'tcx: 'b> { +crate struct Flows<'b, 'tcx> { borrows: FlowAtLocation<'tcx, Borrows<'b, 'tcx>>, pub uninits: FlowAtLocation<'tcx, MaybeUninitializedPlaces<'b, 'tcx>>, pub ever_inits: FlowAtLocation<'tcx, EverInitializedPlaces<'b, 'tcx>>, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index c4a11efe5bce..a21d585a13ca 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -423,7 +423,7 @@ fn downgrade_if_error(diag: &mut Diagnostic) { } } -pub struct MirBorrowckCtxt<'cx, 'tcx: 'cx> { +pub struct MirBorrowckCtxt<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, body: &'cx Body<'tcx>, mir_def_id: DefId, @@ -891,7 +891,7 @@ enum InitializationRequiringAction { PartialAssignment, } -struct RootPlace<'d, 'tcx: 'd> { +struct RootPlace<'d, 'tcx> { place: &'d Place<'tcx>, is_local_mutation_allowed: LocalMutationIsAllowed, } @@ -1693,7 +1693,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn move_path_closest_to<'a>( &mut self, place: &'a Place<'tcx>, - ) -> Result<(&'a Place<'tcx>, MovePathIndex), NoMovePathFound> where 'cx: 'a { + ) -> Result<(&'a Place<'tcx>, MovePathIndex), NoMovePathFound> where 'cx { let mut last_prefix = place; for prefix in self.prefixes(place, PrefixSet::All) { if let Some(mpi) = self.move_path_for_place(prefix) { diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index 18c542de2726..058cdec5cea6 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -35,7 +35,7 @@ pub(super) fn generate_constraints<'cx, 'tcx>( } /// 'cg = the duration of the constraint generation process itself. -struct ConstraintGeneration<'cg, 'cx: 'cg, 'tcx: 'cx> { +struct ConstraintGeneration<'cg, 'cx, 'tcx> { infcx: &'cg InferCtxt<'cx, 'tcx>, all_facts: &'cg mut Option, location_table: &'cg LocationTable, diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs index 4d7ab90a4b3e..7ab069260f94 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs @@ -27,7 +27,7 @@ crate fn find<'tcx>( uf.find() } -struct UseFinder<'cx, 'tcx: 'cx> { +struct UseFinder<'cx, 'tcx> { body: &'cx Body<'tcx>, regioncx: &'cx Rc>, tcx: TyCtxt<'tcx>, @@ -99,7 +99,7 @@ impl<'cx, 'tcx> UseFinder<'cx, 'tcx> { } } -struct DefUseVisitor<'cx, 'tcx: 'cx> { +struct DefUseVisitor<'cx, 'tcx> { body: &'cx Body<'tcx>, tcx: TyCtxt<'tcx>, region_vid: RegionVid, diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index 286f3ac5ccda..c45c28c61465 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -43,7 +43,7 @@ pub(super) fn generate_invalidates<'tcx>( } } -struct InvalidationGenerator<'cx, 'tcx: 'cx> { +struct InvalidationGenerator<'cx, 'tcx> { tcx: TyCtxt<'tcx>, all_facts: &'cx mut AllFacts, location_table: &'cx LocationTable, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs b/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs index cffc66ac7ddf..0cf8a0d16f62 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs @@ -29,7 +29,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } } -struct RawConstraints<'a, 'tcx: 'a> { +struct RawConstraints<'a, 'tcx> { regioncx: &'a RegionInferenceContext<'tcx>, } @@ -78,7 +78,7 @@ impl<'a, 'this, 'tcx> dot::GraphWalk<'this> for RawConstraints<'a, 'tcx> { } } -struct SccConstraints<'a, 'tcx: 'a> { +struct SccConstraints<'a, 'tcx> { regioncx: &'a RegionInferenceContext<'tcx>, nodes_per_scc: IndexVec>, } diff --git a/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs b/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs index d86702773e3f..77a4d2699fff 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs @@ -13,7 +13,7 @@ use rustc::ty::subst::UnpackedKind; use rustc::ty::{self, TyCtxt}; use syntax_pos::DUMMY_SP; -crate struct ConstraintConversion<'a, 'tcx: 'a> { +crate struct ConstraintConversion<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, tcx: TyCtxt<'tcx>, universal_regions: &'a UniversalRegions<'tcx>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs index ca42f249dc19..1bb3acc28f0c 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs @@ -219,7 +219,7 @@ impl UniversalRegionRelations<'tcx> { } } -struct UniversalRegionRelationsBuilder<'this, 'tcx: 'this> { +struct UniversalRegionRelationsBuilder<'this, 'tcx> { infcx: &'this InferCtxt<'this, 'tcx>, param_env: ty::ParamEnv<'tcx>, universal_regions: Rc>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs index 48e45e945256..2d65eb021d38 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs @@ -60,9 +60,9 @@ pub(super) fn trace( /// Contextual state for the type-liveness generator. struct LivenessContext<'me, 'typeck, 'flow, 'tcx> where - 'typeck: 'me, - 'flow: 'me, - 'tcx: 'typeck + 'flow, + 'typeck, + 'flow, + 'tcx, { /// Current type-checker, giving us our inference context etc. typeck: &'me mut TypeChecker<'typeck, 'tcx>, @@ -98,9 +98,9 @@ struct DropData<'tcx> { struct LivenessResults<'me, 'typeck, 'flow, 'tcx> where - 'typeck: 'me, - 'flow: 'me, - 'tcx: 'typeck + 'flow, + 'typeck, + 'flow, + 'tcx, { cx: LivenessContext<'me, 'typeck, 'flow, 'tcx>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index ad79f2109207..ac5efa464066 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -251,7 +251,7 @@ enum FieldAccessError { /// The sanitize_XYZ methods here take an MIR object and compute its /// type, calling `span_mirbug` and returning an error type if there /// is a problem. -struct TypeVerifier<'a, 'b: 'a, 'tcx: 'b> { +struct TypeVerifier<'a, 'b, 'tcx> { cx: &'a mut TypeChecker<'b, 'tcx>, body: &'b Body<'tcx>, last_span: Span, @@ -830,7 +830,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { /// constraints needed for it to be valid and well-typed. Along the /// way, it accrues region constraints -- these can later be used by /// NLL region checking. -struct TypeChecker<'a, 'tcx: 'a> { +struct TypeChecker<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, param_env: ty::ParamEnv<'tcx>, last_span: Span, @@ -845,7 +845,7 @@ struct TypeChecker<'a, 'tcx: 'a> { universal_region_relations: &'a UniversalRegionRelations<'tcx>, } -struct BorrowCheckContext<'a, 'tcx: 'a> { +struct BorrowCheckContext<'a, 'tcx> { universal_regions: &'a UniversalRegions<'tcx>, location_table: &'a LocationTable, all_facts: &'a mut Option, diff --git a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs index 5ced356299fc..2549aa4fbff9 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs @@ -34,7 +34,7 @@ pub(super) fn relate_types<'tcx>( Ok(()) } -struct NllTypeRelatingDelegate<'me, 'bccx: 'me, 'tcx: 'bccx> { +struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> { infcx: &'me InferCtxt<'me, 'tcx>, borrowck_context: Option<&'me mut BorrowCheckContext<'bccx, 'tcx>>, diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index a236359f1d43..fa3c7b9613e1 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -363,7 +363,7 @@ impl<'tcx> UniversalRegions<'tcx> { } } -struct UniversalRegionsBuilder<'cx, 'tcx: 'cx> { +struct UniversalRegionsBuilder<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, mir_def_id: DefId, mir_hir_id: HirId, diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs index b35bcc09a235..0cc1dfd4def0 100644 --- a/src/librustc_mir/borrow_check/prefixes.rs +++ b/src/librustc_mir/borrow_check/prefixes.rs @@ -36,7 +36,7 @@ impl<'tcx> IsPrefixOf<'tcx> for Place<'tcx> { } } -pub(super) struct Prefixes<'cx, 'tcx: 'cx> { +pub(super) struct Prefixes<'cx, 'tcx> { body: &'cx Body<'tcx>, tcx: TyCtxt<'tcx>, kind: PrefixSet, diff --git a/src/librustc_mir/borrow_check/used_muts.rs b/src/librustc_mir/borrow_check/used_muts.rs index e609ddbbe95f..9c5569011df4 100644 --- a/src/librustc_mir/borrow_check/used_muts.rs +++ b/src/librustc_mir/borrow_check/used_muts.rs @@ -46,7 +46,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// MIR visitor for collecting used mutable variables. /// The 'visit lifetime represents the duration of the MIR walk. -struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'tcx: 'cx> { +struct GatherUsedMutsVisitor<'visit, 'cx, 'tcx> { temporary_used_locals: FxHashSet, never_initialized_mut_locals: &'visit mut FxHashSet, mbcx: &'visit mut MirBorrowckCtxt<'cx, 'tcx>, diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 134ff52efe1e..54f935231827 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -661,7 +661,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } #[derive(Debug)] -pub struct Candidate<'pat, 'tcx: 'pat> { +pub struct Candidate<'pat, 'tcx> { // span of the original pattern that gave rise to this candidate span: Span, @@ -705,7 +705,7 @@ struct Ascription<'tcx> { } #[derive(Clone, Debug)] -pub struct MatchPair<'pat, 'tcx: 'pat> { +pub struct MatchPair<'pat, 'tcx> { // this place... place: Place<'tcx>, @@ -1691,7 +1691,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, block: BasicBlock, bindings: impl IntoIterator>, - ) where 'tcx: 'b { + ) where 'tcx { debug!("bind_matched_candidate_for_arm_body(block={:?})", block); let re_erased = self.hir.tcx().lifetimes.re_erased; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index a0e45caeb6b3..001f377c0ee3 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -241,7 +241,7 @@ impl BlockFrame { #[derive(Debug)] struct BlockContext(Vec); -struct Builder<'a, 'tcx: 'a> { +struct Builder<'a, 'tcx> { hir: Cx<'a, 'tcx>, cfg: CFG<'tcx>, diff --git a/src/librustc_mir/dataflow/impls/borrowed_locals.rs b/src/librustc_mir/dataflow/impls/borrowed_locals.rs index a5e1b4ebaafe..069ce3a78c5f 100644 --- a/src/librustc_mir/dataflow/impls/borrowed_locals.rs +++ b/src/librustc_mir/dataflow/impls/borrowed_locals.rs @@ -11,11 +11,11 @@ use crate::dataflow::BitDenotation; /// This is used to compute which locals are live during a yield expression for /// immovable generators. #[derive(Copy, Clone)] -pub struct HaveBeenBorrowedLocals<'a, 'tcx: 'a> { +pub struct HaveBeenBorrowedLocals<'a, 'tcx> { body: &'a Body<'tcx>, } -impl<'a, 'tcx: 'a> HaveBeenBorrowedLocals<'a, 'tcx> { +impl<'a, 'tcx> HaveBeenBorrowedLocals<'a, 'tcx> { pub fn new(body: &'a Body<'tcx>) -> Self { HaveBeenBorrowedLocals { body } @@ -97,7 +97,7 @@ impl<'a, 'tcx> InitialFlow for HaveBeenBorrowedLocals<'a, 'tcx> { } } -struct BorrowedLocalsVisitor<'b, 'c: 'b> { +struct BorrowedLocalsVisitor<'b, 'c> { sets: &'b mut BlockSets<'c, Local>, } diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index ba1a22c8d42e..899765a1d2da 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -29,7 +29,7 @@ newtype_index! { /// `BorrowIndex`, and maps each such index to a `BorrowData` /// describing the borrow. These indexes are used for representing the /// borrows in compact bitvectors. -pub struct Borrows<'a, 'tcx: 'a> { +pub struct Borrows<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index 50d9bbf4cc32..0a572d209362 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -63,7 +63,7 @@ pub(super) mod borrows; /// Similarly, at a given `drop` statement, the set-intersection /// between this data and `MaybeUninitializedPlaces` yields the set of /// places that would require a dynamic drop-flag at that statement. -pub struct MaybeInitializedPlaces<'a, 'tcx: 'a> { +pub struct MaybeInitializedPlaces<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>, @@ -114,7 +114,7 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> { /// Similarly, at a given `drop` statement, the set-intersection /// between this data and `MaybeInitializedPlaces` yields the set of /// places that would require a dynamic drop-flag at that statement. -pub struct MaybeUninitializedPlaces<'a, 'tcx: 'a> { +pub struct MaybeUninitializedPlaces<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>, @@ -164,19 +164,19 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, 'tcx> { /// Similarly, at a given `drop` statement, the set-difference between /// this data and `MaybeInitializedPlaces` yields the set of places /// that would require a dynamic drop-flag at that statement. -pub struct DefinitelyInitializedPlaces<'a, 'tcx: 'a> { +pub struct DefinitelyInitializedPlaces<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>, } -impl<'a, 'tcx: 'a> DefinitelyInitializedPlaces<'a, 'tcx> { +impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> { pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self { DefinitelyInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe } } } -impl<'a, 'tcx: 'a> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { +impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { fn move_data(&self) -> &MoveData<'tcx> { &self.mdpe.move_data } } @@ -209,13 +209,13 @@ impl<'a, 'tcx: 'a> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { /// c = S; // {a, b, c, d } /// } /// ``` -pub struct EverInitializedPlaces<'a, 'tcx: 'a> { +pub struct EverInitializedPlaces<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>, } -impl<'a, 'tcx: 'a> EverInitializedPlaces<'a, 'tcx> { +impl<'a, 'tcx> EverInitializedPlaces<'a, 'tcx> { pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self { EverInitializedPlaces { tcx: tcx, body: body, mdpe: mdpe } } diff --git a/src/librustc_mir/dataflow/impls/storage_liveness.rs b/src/librustc_mir/dataflow/impls/storage_liveness.rs index fed56e987ef4..d7575b0f441e 100644 --- a/src/librustc_mir/dataflow/impls/storage_liveness.rs +++ b/src/librustc_mir/dataflow/impls/storage_liveness.rs @@ -4,11 +4,11 @@ use rustc::mir::*; use crate::dataflow::BitDenotation; #[derive(Copy, Clone)] -pub struct MaybeStorageLive<'a, 'tcx: 'a> { +pub struct MaybeStorageLive<'a, 'tcx> { body: &'a Body<'tcx>, } -impl<'a, 'tcx: 'a> MaybeStorageLive<'a, 'tcx> { +impl<'a, 'tcx> MaybeStorageLive<'a, 'tcx> { pub fn new(body: &'a Body<'tcx>) -> Self { MaybeStorageLive { body } diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 8c4acd70456b..1130e7e3f5d0 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -41,7 +41,7 @@ pub(crate) mod indexes { }; } -pub(crate) struct DataflowBuilder<'a, 'tcx: 'a, BD> +pub(crate) struct DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> { @@ -86,7 +86,7 @@ pub(crate) trait Dataflow<'tcx, BD: BitDenotation<'tcx>> { fn propagate(&mut self); } -impl<'a, 'tcx: 'a, BD> Dataflow<'tcx, BD> for DataflowBuilder<'a, 'tcx, BD> +impl<'a, 'tcx, BD> Dataflow<'tcx, BD> for DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> { @@ -138,7 +138,7 @@ where flow_state.run(tcx, def_id, attributes, p) } -impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> +impl<'a, 'tcx, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx>, { @@ -179,12 +179,12 @@ where } } -struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O> where O: 'b + BitDenotation<'tcx> +struct PropagationContext<'b, 'a, 'tcx, O> where O: 'b + BitDenotation<'tcx> { builder: &'b mut DataflowAnalysis<'a, 'tcx, O>, } -impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'a, 'tcx, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx> { fn propagate(&mut self) { let mut temp = BitSet::new_empty(self.flow_state.sets.bits_per_block); @@ -234,7 +234,7 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'t } } -impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'b, 'a, 'tcx, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: BitDenotation<'tcx> { fn walk_cfg(&mut self, in_out: &mut BitSet) { let mut dirty_queue: WorkQueue = @@ -265,7 +265,7 @@ fn dataflow_path(context: &str, path: &str) -> PathBuf { path } -impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'a, 'tcx, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> { fn pre_dataflow_instrumentation

(&self, p: P) -> io::Result<()> where P: Fn(&BD, BD::Idx) -> DebugFormatted @@ -297,7 +297,7 @@ impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tc /// underlying flow analysis results, because it needs to handle cases /// where we are combining the results of *multiple* flow analyses /// (e.g., borrows + inits + uninits). -pub(crate) trait DataflowResultsConsumer<'a, 'tcx: 'a> { +pub(crate) trait DataflowResultsConsumer<'a, 'tcx> { type FlowState: FlowsAtLocation; // Observation Hooks: override (at least one of) these to get analysis feedback. @@ -387,14 +387,14 @@ pub fn state_for_location<'tcx, T: BitDenotation<'tcx>>(loc: Location, gen_set.to_dense() } -pub struct DataflowAnalysis<'a, 'tcx: 'a, O> where O: BitDenotation<'tcx> +pub struct DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> { flow_state: DataflowState<'tcx, O>, dead_unwinds: &'a BitSet, body: &'a Body<'tcx>, } -impl<'a, 'tcx: 'a, O> DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> +impl<'a, 'tcx, O> DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> { pub fn results(self) -> DataflowResults<'tcx, O> { DataflowResults(self.flow_state) @@ -734,7 +734,7 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation<'tcx> } } -impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation<'tcx> { +impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation<'tcx> { /// Propagates the bits of `in_out` into all the successors of `bb`, /// using bitwise operator denoted by `self.operator`. /// diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 7c738b75e072..e8386e8fef11 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -12,7 +12,7 @@ use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, Move use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind}; use super::IllegalMoveOriginKind::*; -struct MoveDataBuilder<'a, 'tcx: 'a> { +struct MoveDataBuilder<'a, 'tcx> { body: &'a Body<'tcx>, tcx: TyCtxt<'tcx>, data: MoveData<'tcx>, @@ -253,7 +253,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { } } -struct Gatherer<'b, 'a: 'b, 'tcx: 'a> { +struct Gatherer<'b, 'a, 'tcx> { builder: &'b mut MoveDataBuilder<'a, 'tcx>, loc: Location, } diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index ff53cf02d8d1..fe54e2a0f183 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -21,7 +21,7 @@ use rustc::hir; use crate::hair::constant::{lit_to_const, LitToConstError}; #[derive(Clone)] -pub struct Cx<'a, 'tcx: 'a> { +pub struct Cx<'a, 'tcx> { tcx: TyCtxt<'tcx>, infcx: &'a InferCtxt<'a, 'tcx>, diff --git a/src/librustc_mir/hair/cx/to_ref.rs b/src/librustc_mir/hair/cx/to_ref.rs index a462c61c2acb..d044b1faedfa 100644 --- a/src/librustc_mir/hair/cx/to_ref.rs +++ b/src/librustc_mir/hair/cx/to_ref.rs @@ -8,7 +8,7 @@ pub trait ToRef { fn to_ref(self) -> Self::Output; } -impl<'a, 'tcx: 'a> ToRef for &'tcx hir::Expr { +impl<'a, 'tcx> ToRef for &'tcx hir::Expr { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -16,7 +16,7 @@ impl<'a, 'tcx: 'a> ToRef for &'tcx hir::Expr { } } -impl<'a, 'tcx: 'a> ToRef for &'tcx P { +impl<'a, 'tcx> ToRef for &'tcx P { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -24,7 +24,7 @@ impl<'a, 'tcx: 'a> ToRef for &'tcx P { } } -impl<'a, 'tcx: 'a> ToRef for Expr<'tcx> { +impl<'a, 'tcx> ToRef for Expr<'tcx> { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -32,7 +32,7 @@ impl<'a, 'tcx: 'a> ToRef for Expr<'tcx> { } } -impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Option +impl<'a, 'tcx, T, U> ToRef for &'tcx Option where &'tcx T: ToRef { type Output = Option; @@ -42,7 +42,7 @@ impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Option } } -impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Vec +impl<'a, 'tcx, T, U> ToRef for &'tcx Vec where &'tcx T: ToRef { type Output = Vec; @@ -52,7 +52,7 @@ impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Vec } } -impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx P<[T]> +impl<'a, 'tcx, T, U> ToRef for &'tcx P<[T]> where &'tcx T: ToRef { type Output = Vec; diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index bb1a67bcdaef..22bd802c1fab 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -285,7 +285,7 @@ impl<'tcx> Pattern<'tcx> { /// A 2D matrix. Nx1 matrices are very common, which is why `SmallVec[_; 2]` /// works well for each row. -pub struct Matrix<'p, 'tcx: 'p>(Vec; 2]>>); +pub struct Matrix<'p, 'tcx>(Vec; 2]>>); impl<'p, 'tcx> Matrix<'p, 'tcx> { pub fn empty() -> Self { @@ -349,7 +349,7 @@ impl<'p, 'tcx> FromIterator; 2]>> for Matrix<'p, 'tc } } -pub struct MatchCheckCtxt<'a, 'tcx: 'a> { +pub struct MatchCheckCtxt<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, /// The module in which the match occurs. This is necessary for /// checking inhabited-ness of types because whether a type is (visibly) @@ -393,7 +393,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { } fn is_non_exhaustive_variant<'p>(&self, pattern: &'p Pattern<'tcx>) -> bool - where 'a: 'p + where 'a { match *pattern.kind { PatternKind::Variant { adt_def, variant_index, .. } => { @@ -634,7 +634,7 @@ impl<'tcx> Witness<'tcx> { /// /// We make sure to omit constructors that are statically impossible. E.g., for /// `Option`, we do not include `Some(_)` in the returned list of constructors. -fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, +fn all_constructors<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, pcx: PatternContext<'tcx>) -> Vec> { @@ -708,7 +708,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, ctors } -fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>( +fn max_slice_length<'p, 'a, 'tcx, I>( cx: &mut MatchCheckCtxt<'a, 'tcx>, patterns: I) -> u64 where I: Iterator> @@ -985,7 +985,7 @@ enum MissingCtors<'tcx> { // (The split logic gives a performance win, because we always need to know if // the set is empty, but we rarely need the full set, and it can be expensive // to compute the full set.) -fn compute_missing_ctors<'a, 'tcx: 'a>( +fn compute_missing_ctors<'a, 'tcx>( info: MissingCtorsInfo, tcx: TyCtxt<'tcx>, all_ctors: &Vec>, @@ -1057,7 +1057,7 @@ fn compute_missing_ctors<'a, 'tcx: 'a>( /// relation to preceding patterns, it is not reachable) and exhaustiveness /// checking (if a wildcard pattern is useful in relation to a matrix, the /// matrix isn't exhaustive). -pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, +pub fn is_useful<'p, 'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, matrix: &Matrix<'p, 'tcx>, v: &[&Pattern<'tcx>], witness: WitnessPreference) @@ -1267,7 +1267,7 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, /// A shorthand for the `U(S(c, P), S(c, q))` operation from the paper. I.e., `is_useful` applied /// to the specialised version of both the pattern matrix `P` and the new pattern `q`. -fn is_useful_specialized<'p, 'a: 'p, 'tcx: 'a>( +fn is_useful_specialized<'p, 'a, 'tcx>( cx: &mut MatchCheckCtxt<'a, 'tcx>, &Matrix(ref m): &Matrix<'p, 'tcx>, v: &[&Pattern<'tcx>], @@ -1373,7 +1373,7 @@ fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty /// expanded to. /// /// For instance, a tuple pattern (43u32, 'a') has sub pattern types [u32, char]. -fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>, +fn constructor_sub_pattern_tys<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty: Ty<'tcx>) -> Vec> { @@ -1520,7 +1520,7 @@ fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx>, ctor: &Constructor<'tcx>) /// boundaries for each interval range, sort them, then create constructors for each new interval /// between every pair of boundary points. (This essentially sums up to performing the intuitive /// merging operation depicted above.) -fn split_grouped_constructors<'p, 'a: 'p, 'tcx: 'a>( +fn split_grouped_constructors<'p, 'a, 'tcx>( tcx: TyCtxt<'tcx>, ctors: Vec>, &Matrix(ref m): &Matrix<'p, 'tcx>, @@ -1598,7 +1598,7 @@ fn split_grouped_constructors<'p, 'a: 'p, 'tcx: 'a>( } /// Checks whether there exists any shared value in either `ctor` or `pat` by intersecting them. -fn constructor_intersects_pattern<'p, 'a: 'p, 'tcx: 'a>( +fn constructor_intersects_pattern<'p, 'a, 'tcx>( tcx: TyCtxt<'tcx>, ctor: &Constructor<'tcx>, pat: &'p Pattern<'tcx>, @@ -1688,7 +1688,7 @@ fn constructor_covered_by_range<'tcx>( } } -fn patterns_for_variant<'p, 'a: 'p, 'tcx: 'a>( +fn patterns_for_variant<'p, 'a, 'tcx>( subpatterns: &'p [FieldPattern<'tcx>], wild_patterns: &[&'p Pattern<'tcx>]) -> SmallVec<[&'p Pattern<'tcx>; 2]> @@ -1711,7 +1711,7 @@ fn patterns_for_variant<'p, 'a: 'p, 'tcx: 'a>( /// different patterns. /// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing /// fields filled with wild patterns. -fn specialize<'p, 'a: 'p, 'tcx: 'a>( +fn specialize<'p, 'a, 'tcx>( cx: &mut MatchCheckCtxt<'a, 'tcx>, r: &[&'p Pattern<'tcx>], constructor: &Constructor<'tcx>, diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 159b526bdba6..ed850379af60 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -47,7 +47,7 @@ fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> Diagn struct_span_err!(sess, sp, E0004, "{}", &error_message) } -struct MatchVisitor<'a, 'tcx: 'a> { +struct MatchVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, body_owner: DefId, tables: &'a ty::TypeckTables<'tcx>, @@ -439,7 +439,7 @@ fn check_arms<'a, 'tcx>( } } -fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>( +fn check_exhaustive<'p, 'a, 'tcx>( cx: &mut MatchCheckCtxt<'a, 'tcx>, scrut_ty: Ty<'tcx>, sp: Span, @@ -642,7 +642,7 @@ fn check_for_mutation_in_guard(cx: &MatchVisitor<'_, '_>, guard: &hir::Guard) { }; } -struct MutationChecker<'a, 'tcx: 'a> { +struct MutationChecker<'a, 'tcx> { cx: &'a MatchVisitor<'a, 'tcx>, } @@ -691,7 +691,7 @@ fn check_legality_of_bindings_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pa AtBindingPatternVisitor { cx: cx, bindings_allowed: true }.visit_pat(pat); } -struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> { +struct AtBindingPatternVisitor<'a, 'b, 'tcx> { cx: &'a MatchVisitor<'b, 'tcx>, bindings_allowed: bool } diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index e0e14852c577..cf597ce0b631 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -326,7 +326,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { } } -pub struct PatternContext<'a, 'tcx: 'a> { +pub struct PatternContext<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, pub param_env: ty::ParamEnv<'tcx>, pub tables: &'a ty::TypeckTables<'tcx>, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 28dc0d37b36f..b01826c98db0 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -49,7 +49,7 @@ pub struct InterpretCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// A stack frame. #[derive(Clone)] -pub struct Frame<'mir, 'tcx: 'mir, Tag=(), Extra=()> { +pub struct Frame<'mir, 'tcx, Tag=(), Extra=()> { //////////////////////////////////////////////////////////////////////////////// // Function and callsite information //////////////////////////////////////////////////////////////////////////////// @@ -195,7 +195,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpretCx<'mir, 'tcx, M> } } -impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { +impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { pub fn new(tcx: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self { InterpretCx { machine, diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index 0032e84b266c..ad631793a082 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -304,7 +304,7 @@ impl_stable_hash_for!(enum crate::interpret::eval_context::StackPopCleanup { }); #[derive(Eq, PartialEq)] -struct FrameSnapshot<'a, 'tcx: 'a> { +struct FrameSnapshot<'a, 'tcx> { instance: &'a ty::Instance<'tcx>, span: &'a Span, return_to_block: &'a StackPopCleanup, diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index 9150f16526ba..95a679b95ddc 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -122,7 +122,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx, macro_rules! make_value_visitor { ($visitor_trait_name:ident, $($mutability:ident)?) => { // How to traverse a value and what to do when we are at the leaves. - pub trait $visitor_trait_name<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { + pub trait $visitor_trait_name<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Sized { type V: Value<'mir, 'tcx, M>; /// The visitor must have an `InterpretCx` in it. diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 2e74ebcf061e..6dcb23da321a 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -345,7 +345,7 @@ fn collect_roots<'tcx>(tcx: TyCtxt<'tcx>, mode: MonoItemCollectionMode) -> Vec( +fn collect_items_rec<'a, 'tcx>( tcx: TyCtxt<'tcx>, starting_point: MonoItem<'tcx>, visited: MTRef<'_, MTLock>>>, @@ -515,7 +515,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { } } -struct MirNeighborCollector<'a, 'tcx: 'a> { +struct MirNeighborCollector<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, output: &'a mut Vec>, diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index a821cb2cfdad..59e95215df2a 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -769,7 +769,7 @@ fn numbered_codegen_unit_name( fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I) where I: Iterator>, - 'tcx: 'a + 'b, + 'tcx, { if cfg!(debug_assertions) { debug!("{}", label); @@ -794,7 +794,7 @@ where } #[inline(never)] // give this a place in the profiler -fn assert_symbols_are_distinct<'a, 'tcx: 'a, I>(tcx: TyCtxt<'tcx>, mono_items: I) +fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, mono_items: I) where I: Iterator>, { diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index f5a22ea09315..c04672f8331e 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -248,7 +248,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) body } -pub struct DropShimElaborator<'a, 'tcx: 'a> { +pub struct DropShimElaborator<'a, 'tcx> { pub body: &'a Body<'tcx>, pub patch: MirPatch<'tcx>, pub tcx: TyCtxt<'tcx>, diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 32153f7bcd9c..9c78d761cb2c 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -18,7 +18,7 @@ use std::ops::Bound; use crate::util; -pub struct UnsafetyChecker<'a, 'tcx: 'a> { +pub struct UnsafetyChecker<'a, 'tcx> { body: &'a Body<'tcx>, const_context: bool, min_const_fn: bool, diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 584a2fd1341d..d805c66e3c36 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -164,7 +164,7 @@ impl InitializationData { } } -struct Elaborator<'a, 'b: 'a, 'tcx: 'b> { +struct Elaborator<'a, 'b, 'tcx> { init_data: &'a InitializationData, ctxt: &'a mut ElaborateDropsCtxt<'b, 'tcx>, } @@ -285,7 +285,7 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> { } } -struct ElaborateDropsCtxt<'a, 'tcx: 'a> { +struct ElaborateDropsCtxt<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, env: &'a MoveDataParamEnv<'tcx>, diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 9c7aedc12a27..6be54aa629de 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -616,7 +616,7 @@ fn compute_storage_conflicts( storage_conflicts } -struct StorageConflictVisitor<'body, 'tcx: 'body, 's> { +struct StorageConflictVisitor<'body, 'tcx, 's> { body: &'body Body<'tcx>, stored_locals: &'s liveness::LiveVarSet, // FIXME(tmandry): Consider using sparse bitsets here once we have good @@ -624,7 +624,7 @@ struct StorageConflictVisitor<'body, 'tcx: 'body, 's> { local_conflicts: BitMatrix, } -impl<'body, 'tcx: 'body, 's> DataflowResultsConsumer<'body, 'tcx> +impl<'body, 'tcx, 's> DataflowResultsConsumer<'body, 'tcx> for StorageConflictVisitor<'body, 'tcx, 's> { type FlowState = FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>; @@ -654,7 +654,7 @@ for StorageConflictVisitor<'body, 'tcx, 's> { } } -impl<'body, 'tcx: 'body, 's> StorageConflictVisitor<'body, 'tcx, 's> { +impl<'body, 'tcx, 's> StorageConflictVisitor<'body, 'tcx, 's> { fn apply_state(&mut self, flow_state: &FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>, loc: Location) { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 5e6f1bc15f02..e2f98e46dba5 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -643,7 +643,7 @@ fn type_size_of<'tcx>( * Updates block indices, references to locals and other control flow * stuff. */ -struct Integrator<'a, 'tcx: 'a> { +struct Integrator<'a, 'tcx> { block_idx: usize, args: &'a [Local], local_map: IndexVec, diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 79bb2cfe08db..81d91dcd0a95 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -66,7 +66,7 @@ fn mir_keys<'tcx>(tcx: TyCtxt<'tcx>, krate: CrateNum) -> &'tcx DefIdSet { // Additionally, tuple struct/variant constructors have MIR, but // they don't have a BodyId, so we need to build them separately. - struct GatherCtors<'a, 'tcx: 'a> { + struct GatherCtors<'a, 'tcx> { tcx: TyCtxt<'tcx>, set: &'a mut DefIdSet, } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 84d3f8f4c462..d78adfe433c4 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -147,7 +147,7 @@ pub fn collect_temps(body: &Body<'_>, collector.temps } -struct Promoter<'a, 'tcx: 'a> { +struct Promoter<'a, 'tcx> { tcx: TyCtxt<'tcx>, source: &'a mut Body<'tcx>, promoted: Body<'tcx>, diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index ac15f52d9ec5..f226f15c0096 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -63,12 +63,12 @@ impl MirPass for SimplifyCfg { } } -pub struct CfgSimplifier<'a, 'tcx: 'a> { +pub struct CfgSimplifier<'a, 'tcx> { basic_blocks: &'a mut IndexVec>, pred_count: IndexVec } -impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> { +impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { pub fn new(body: &'a mut Body<'tcx>) -> Self { let mut pred_count = IndexVec::from_elem(0u32, body.basic_blocks()); diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index 90b52b76155d..812a024e1d91 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -47,7 +47,7 @@ impl MirPass for UniformArrayMoveOut { } } -struct UniformArrayMoveOutVisitor<'a, 'tcx: 'a> { +struct UniformArrayMoveOutVisitor<'a, 'tcx> { body: &'a Body<'tcx>, patch: &'a mut MirPatch<'tcx>, tcx: TyCtxt<'tcx>, diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 0d7d6b4094ad..6da181ef6680 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -70,7 +70,7 @@ impl Unwind { } } -pub trait DropElaborator<'a, 'tcx: 'a>: fmt::Debug { +pub trait DropElaborator<'a, 'tcx>: fmt::Debug { type Path : Copy + fmt::Debug; fn patch(&mut self) -> &mut MirPatch<'tcx>; @@ -90,7 +90,7 @@ pub trait DropElaborator<'a, 'tcx: 'a>: fmt::Debug { } #[derive(Debug)] -struct DropCtxt<'l, 'b: 'l, 'tcx: 'b, D> +struct DropCtxt<'l, 'b, 'tcx, D> where D : DropElaborator<'b, 'tcx> + 'l { elaborator: &'l mut D, diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index efa4bd65c0bc..e1e4195d6d51 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -39,7 +39,7 @@ enum Context { } #[derive(Copy, Clone)] -struct CheckLoopVisitor<'a, 'hir: 'a> { +struct CheckLoopVisitor<'a, 'hir> { sess: &'a Session, hir_map: &'a Map<'hir>, cx: Context, diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 5397a4af8fa8..1493d0290480 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -74,7 +74,7 @@ fn rvalue_promotable_map<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ItemLo tcx.arena.alloc(visitor.result) } -struct CheckCrateVisitor<'a, 'tcx: 'a> { +struct CheckCrateVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, in_fn: bool, in_static: bool, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 9eaa6f920f08..ba834bf09aa8 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -842,7 +842,7 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { /// This pass performs remaining checks for fields in struct expressions and patterns. ////////////////////////////////////////////////////////////////////////////////////// -struct NamePrivacyVisitor<'a, 'tcx: 'a> { +struct NamePrivacyVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, tables: &'a ty::TypeckTables<'tcx>, current_item: hir::HirId, @@ -969,7 +969,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { /// Checks are performed on "semantic" types regardless of names and their hygiene. //////////////////////////////////////////////////////////////////////////////////////////// -struct TypePrivacyVisitor<'a, 'tcx: 'a> { +struct TypePrivacyVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, tables: &'a ty::TypeckTables<'tcx>, current_item: DefId, @@ -1202,7 +1202,7 @@ impl DefIdVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { /// warnings instead of hard errors when the erroneous node is not in this old set. /////////////////////////////////////////////////////////////////////////////// -struct ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx: 'a> { +struct ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, access_levels: &'a AccessLevels, in_variant: bool, @@ -1210,7 +1210,7 @@ struct ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx: 'a> { old_error_set: HirIdSet, } -struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> { +struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> { inner: &'a ObsoleteVisiblePrivateTypesVisitor<'b, 'tcx>, /// Whether the type refers to private types. contains_private: bool, @@ -1651,7 +1651,7 @@ impl DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> { } } -struct PrivateItemsInPublicInterfacesVisitor<'a, 'tcx: 'a> { +struct PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, has_pub_restricted: bool, old_error_set: &'a HirIdSet, diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index e3cd2948d7af..18ed91689ec1 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -930,7 +930,7 @@ impl<'a> Resolver<'a> { } } -pub struct BuildReducedGraphVisitor<'a, 'b: 'a> { +pub struct BuildReducedGraphVisitor<'a, 'b> { pub resolver: &'a mut Resolver<'b>, pub current_legacy_scope: LegacyScope<'b>, pub expansion: Mark, diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 3b6179f78558..4fee15c59b33 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -48,7 +48,7 @@ impl<'a> UnusedImport<'a> { } } -struct UnusedImportCheckVisitor<'a, 'b: 'a> { +struct UnusedImportCheckVisitor<'a, 'b> { resolver: &'a mut Resolver<'b>, /// All the (so far) unused imports, grouped path list unused_imports: NodeMap>, diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index d8292eebce79..e93a2315ca32 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -441,7 +441,7 @@ impl<'a> Resolver<'a> { } } -impl<'a, 'b:'a> ImportResolver<'a, 'b> { +impl<'a, 'b> ImportResolver<'a, 'b> { /// Adds suggestions for a path that cannot be resolved. pub(crate) fn make_path_suggestion( &mut self, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7f05e0f477c2..a127c9606854 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1735,7 +1735,7 @@ impl<'a> ResolverArenas<'a> { } } -impl<'a, 'b: 'a> ty::DefIdTree for &'a Resolver<'b> { +impl<'a, 'b> ty::DefIdTree for &'a Resolver<'b> { fn parent(self, id: DefId) -> Option { match id.krate { LOCAL_CRATE => self.definitions.def_key(id.index).parent, diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 2369bddf4f75..47ed3d684b2b 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -132,7 +132,7 @@ impl<'a> base::Resolver for Resolver<'a> { } fn resolve_dollar_crates(&mut self, fragment: &AstFragment) { - struct ResolveDollarCrates<'a, 'b: 'a> { + struct ResolveDollarCrates<'a, 'b> { resolver: &'a mut Resolver<'b> } impl<'a> Visitor<'a> for ResolveDollarCrates<'a, '_> { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index d24d8f8c2b5b..f69849bb4a9e 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -644,30 +644,30 @@ struct UnresolvedImportError { suggestion: Option, } -pub struct ImportResolver<'a, 'b: 'a> { +pub struct ImportResolver<'a, 'b> { pub resolver: &'a mut Resolver<'b>, } -impl<'a, 'b: 'a> std::ops::Deref for ImportResolver<'a, 'b> { +impl<'a, 'b> std::ops::Deref for ImportResolver<'a, 'b> { type Target = Resolver<'b>; fn deref(&self) -> &Resolver<'b> { self.resolver } } -impl<'a, 'b: 'a> std::ops::DerefMut for ImportResolver<'a, 'b> { +impl<'a, 'b> std::ops::DerefMut for ImportResolver<'a, 'b> { fn deref_mut(&mut self) -> &mut Resolver<'b> { self.resolver } } -impl<'a, 'b: 'a> ty::DefIdTree for &'a ImportResolver<'a, 'b> { +impl<'a, 'b> ty::DefIdTree for &'a ImportResolver<'a, 'b> { fn parent(self, id: DefId) -> Option { self.resolver.parent(id) } } -impl<'a, 'b:'a> ImportResolver<'a, 'b> { +impl<'a, 'b> ImportResolver<'a, 'b> { // Import resolution // // This is a fixed-point algorithm. We resolve imports until our efforts diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index f9dd4436434f..a7f46e876830 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -75,7 +75,7 @@ macro_rules! access_from_vis { }; } -pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput> { +pub struct DumpVisitor<'l, 'tcx, 'll, O: DumpOutput> { save_ctxt: SaveContext<'l, 'tcx>, tcx: TyCtxt<'tcx>, dumper: &'ll mut JsonDumper, @@ -92,7 +92,7 @@ pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput> { // macro_calls: FxHashSet, } -impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { +impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { pub fn new( save_ctxt: SaveContext<'l, 'tcx>, dumper: &'ll mut JsonDumper, @@ -1311,7 +1311,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { } } -impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, O> { +impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, O> { fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, attrs: &[ast::Attribute], id: NodeId) { // Since we handle explicit modules ourselves in visit_item, this should // only get called for the root module of a crate. diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index fb9f872880ea..4882a4240c83 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -51,7 +51,7 @@ use rls_data::config::Config; use log::{debug, error, info}; -pub struct SaveContext<'l, 'tcx: 'l> { +pub struct SaveContext<'l, 'tcx> { tcx: TyCtxt<'tcx>, tables: &'l ty::TypeckTables<'tcx>, access_levels: &'l AccessLevels, @@ -67,7 +67,7 @@ pub enum Data { RelationData(Relation, Impl), } -impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { +impl<'l, 'tcx> SaveContext<'l, 'tcx> { fn span_from_span(&self, span: Span) -> SpanData { use rls_span::{Column, Row}; @@ -960,7 +960,7 @@ impl<'l> PathCollector<'l> { } } -impl<'l, 'a: 'l> Visitor<'a> for PathCollector<'l> { +impl<'l, 'a> Visitor<'a> for PathCollector<'l> { fn visit_pat(&mut self, p: &'a ast::Pat) { match p.node { PatKind::Struct(ref path, ..) => { diff --git a/src/librustc_traits/chalk_context/mod.rs b/src/librustc_traits/chalk_context/mod.rs index 2b678919ce41..bbb0825ee082 100644 --- a/src/librustc_traits/chalk_context/mod.rs +++ b/src/librustc_traits/chalk_context/mod.rs @@ -56,7 +56,7 @@ crate struct ChalkContext<'tcx> { } #[derive(Copy, Clone)] -crate struct ChalkInferenceContext<'cx, 'tcx: 'cx> { +crate struct ChalkInferenceContext<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, } diff --git a/src/librustc_traits/chalk_context/resolvent_ops.rs b/src/librustc_traits/chalk_context/resolvent_ops.rs index 1e8b02659dc6..59c01b8b1b7b 100644 --- a/src/librustc_traits/chalk_context/resolvent_ops.rs +++ b/src/librustc_traits/chalk_context/resolvent_ops.rs @@ -139,7 +139,7 @@ impl context::ResolventOps, ChalkArenas<'tcx>> } } -struct AnswerSubstitutor<'cx, 'tcx: 'cx> { +struct AnswerSubstitutor<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, environment: Environment<'tcx>, answer_subst: CanonicalVarValues<'tcx>, diff --git a/src/librustc_traits/chalk_context/unify.rs b/src/librustc_traits/chalk_context/unify.rs index d66faa92336f..1f9090324414 100644 --- a/src/librustc_traits/chalk_context/unify.rs +++ b/src/librustc_traits/chalk_context/unify.rs @@ -42,7 +42,7 @@ crate fn unify<'me, 'tcx, T: Relate<'tcx>>( }) } -struct ChalkTypeRelatingDelegate<'me, 'tcx: 'me> { +struct ChalkTypeRelatingDelegate<'me, 'tcx> { infcx: &'me InferCtxt<'me, 'tcx>, environment: Environment<'tcx>, goals: Vec>>, diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index dcbb0dffba8f..cb30eba5b050 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -56,7 +56,7 @@ fn type_op_ascribe_user_type<'tcx>( }) } -struct AscribeUserTypeCx<'me, 'tcx: 'me> { +struct AscribeUserTypeCx<'me, 'tcx> { infcx: &'me InferCtxt<'me, 'tcx>, param_env: ParamEnv<'tcx>, fulfill_cx: &'me mut dyn TraitEngine<'tcx>, diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index dc4969d7ad2d..ecdf28e5d7f0 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -20,7 +20,7 @@ enum AutoderefKind { Overloaded, } -pub struct Autoderef<'a, 'tcx: 'a> { +pub struct Autoderef<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 5f9aa5fbabe0..ac2dcbadad82 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -12,7 +12,7 @@ use syntax_pos::Span; use super::FnCtxt; use crate::util::nodemap::FxHashMap; -struct InteriorVisitor<'a, 'tcx: 'a> { +struct InteriorVisitor<'a, 'tcx> { fcx: &'a FnCtxt<'a, 'tcx>, types: FxHashMap, usize>, region_scope_tree: &'tcx region::ScopeTree, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 29b4fee138e8..5943302c7088 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -787,7 +787,7 @@ fn compute_all_traits<'tcx>(tcx: TyCtxt<'tcx>) -> Vec { // Crate-local: - struct Visitor<'a, 'tcx: 'a> { + struct Visitor<'a, 'tcx> { map: &'a hir_map::Map<'tcx>, traits: &'a mut Vec, } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 10bfe9e034d3..864f19933a5f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -160,7 +160,7 @@ pub struct LocalTy<'tcx> { /// A wrapper for `InferCtxt`'s `in_progress_tables` field. #[derive(Copy, Clone)] -struct MaybeInProgressTables<'a, 'tcx: 'a> { +struct MaybeInProgressTables<'a, 'tcx> { maybe_tables: Option<&'a RefCell>>, } @@ -193,7 +193,7 @@ impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> { /// Here, the function `foo()` and the closure passed to /// `bar()` will each have their own `FnCtxt`, but they will /// share the inherited fields. -pub struct Inherited<'a, 'tcx: 'a> { +pub struct Inherited<'a, 'tcx> { infcx: InferCtxt<'a, 'tcx>, tables: MaybeInProgressTables<'a, 'tcx>, @@ -512,7 +512,7 @@ impl<'tcx> EnclosingBreakables<'tcx> { } } -pub struct FnCtxt<'a, 'tcx: 'a> { +pub struct FnCtxt<'a, 'tcx> { body_id: hir::HirId, /// The parameter environment used for proving trait obligations @@ -919,7 +919,7 @@ fn check_abi<'tcx>(tcx: TyCtxt<'tcx>, span: Span, abi: Abi) { } } -struct GatherLocalsVisitor<'a, 'tcx: 'a> { +struct GatherLocalsVisitor<'a, 'tcx> { fcx: &'a FnCtxt<'a, 'tcx>, parent_id: hir::HirId, } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index ffc323f28b67..6a95dec1c81b 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -96,7 +96,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // there, it applies a few ad-hoc checks that were not convenient to // do elsewhere. -struct WritebackCx<'cx, 'tcx: 'cx> { +struct WritebackCx<'cx, 'tcx> { fcx: &'cx FnCtxt<'cx, 'tcx>, tables: ty::TypeckTables<'tcx>, @@ -787,7 +787,7 @@ impl Locatable for hir::HirId { // The Resolver. This is the type folding engine that detects // unresolved types and so forth. -struct Resolver<'cx, 'tcx: 'cx> { +struct Resolver<'cx, 'tcx> { tcx: TyCtxt<'tcx>, infcx: &'cx InferCtxt<'cx, 'tcx>, span: &'cx dyn Locatable, diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index dda86778f272..8f89a77bd1a3 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -194,7 +194,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'tcx>) { } } -struct CollectExternCrateVisitor<'a, 'tcx: 'a> { +struct CollectExternCrateVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, crates_to_lint: &'a mut Vec, } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5606d9c0ce81..70deca9623b4 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1786,7 +1786,7 @@ fn impl_polarity<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> hir::ImplPolarity { /// the lifetimes that are declared. For fns or methods, we have to /// screen out those that do not appear in any where-clauses etc using /// `resolve_lifetime::early_bound_lifetimes`. -fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>( +fn early_bound_lifetimes_from_generics<'a, 'tcx>( tcx: TyCtxt<'tcx>, generics: &'a hir::Generics, ) -> impl Iterator + Captures<'tcx> { diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index a2f9a2bb50a2..1c2bb8c2f0b2 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -43,7 +43,7 @@ pub fn infer_predicates<'tcx>( global_inferred_outlives } -pub struct InferVisitor<'cx, 'tcx: 'cx> { +pub struct InferVisitor<'cx, 'tcx> { tcx: TyCtxt<'tcx>, global_inferred_outlives: &'cx mut FxHashMap>, predicates_added: &'cx mut bool, diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 59213ac3c134..36f0dbcd2fcb 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -12,7 +12,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use super::terms::*; use super::terms::VarianceTerm::*; -pub struct ConstraintContext<'a, 'tcx: 'a> { +pub struct ConstraintContext<'a, 'tcx> { pub terms_cx: TermsContext<'a, 'tcx>, // These are pointers to common `ConstantTerm` instances diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index 8edf3c52ccc2..3851b918c485 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -14,7 +14,7 @@ use super::terms::*; use super::terms::VarianceTerm::*; use super::xform::*; -struct SolveContext<'a, 'tcx: 'a> { +struct SolveContext<'a, 'tcx> { terms_cx: TermsContext<'a, 'tcx>, constraints: Vec>, diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 99f87ccb6f65..3f6eadeac333 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -47,7 +47,7 @@ impl<'a> fmt::Debug for VarianceTerm<'a> { // The first pass over the crate simply builds up the set of inferreds. -pub struct TermsContext<'a, 'tcx: 'a> { +pub struct TermsContext<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, pub arena: &'a TypedArena>, diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 6d51278b4e5e..f6ab1290da37 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -20,7 +20,7 @@ pub fn check_code_block_syntax(krate: clean::Crate, cx: &DocContext<'_>) -> clea SyntaxChecker { cx }.fold_crate(krate) } -struct SyntaxChecker<'a, 'tcx: 'a> { +struct SyntaxChecker<'a, 'tcx> { cx: &'a DocContext<'tcx>, } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 9a9fd941240b..ddce5cab1ebc 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -878,7 +878,7 @@ impl Tester for Collector { } } -struct HirCollector<'a, 'hir: 'a> { +struct HirCollector<'a, 'hir> { sess: &'a session::Session, collector: &'a mut Collector, map: &'a hir::map::Map<'hir>, diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 8f926e6dd290..2c3bea80e349 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2502,7 +2502,7 @@ impl ToJson for Option { } } -struct FormatShim<'a, 'b: 'a> { +struct FormatShim<'a, 'b> { inner: &'a mut fmt::Formatter<'b>, } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 3fa96c60bff6..d433e6c5a896 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -242,7 +242,7 @@ impl Invocation { } } -pub struct MacroExpander<'a, 'b:'a> { +pub struct MacroExpander<'a, 'b> { pub cx: &'a mut ExtCtxt<'b>, monotonic: bool, // cf. `cx.monotonic_expander()` } @@ -1031,7 +1031,7 @@ impl<'a> Parser<'a> { } } -struct InvocationCollector<'a, 'b: 'a> { +struct InvocationCollector<'a, 'b> { cx: &'a mut ExtCtxt<'b>, cfg: StripUnconfigured<'a>, invocations: Vec, diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index c56c156182bd..b2b8bfb09b45 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -69,7 +69,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { } } -pub struct PlaceholderExpander<'a, 'b: 'a> { +pub struct PlaceholderExpander<'a, 'b> { expanded_fragments: FxHashMap, cx: &'a mut ExtCtxt<'b>, monotonic: bool, diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 4758b6a50e52..d5da4c920bc4 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -156,7 +156,7 @@ type NamedMatchVec = SmallVec<[NamedMatch; 4]>; /// all the elements in that `SmallVec` strictly outlive the root stack slot /// lifetime. By separating `'tt` from `'root`, we can show that. #[derive(Clone)] -struct MatcherPos<'root, 'tt: 'root> { +struct MatcherPos<'root, 'tt> { /// The token or sequence of tokens that make up the matcher top_elts: TokenTreeOrTokenTreeSlice<'tt>, @@ -233,7 +233,7 @@ impl<'root, 'tt> MatcherPos<'root, 'tt> { // Therefore, the initial MatcherPos is always allocated on the stack, // subsequent ones (of which there aren't that many) are allocated on the heap, // and this type is used to encapsulate both cases. -enum MatcherPosHandle<'root, 'tt: 'root> { +enum MatcherPosHandle<'root, 'tt> { Ref(&'root mut MatcherPos<'root, 'tt>), Box(Box>), } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 8b719b5477c6..3edf7726ec61 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -346,7 +346,7 @@ fn find_type_parameters(ty: &ast::Ty, -> Vec> { use syntax::visit; - struct Visitor<'a, 'b: 'a> { + struct Visitor<'a, 'b> { cx: &'a ExtCtxt<'b>, span: Span, ty_param_names: &'a [ast::Name], diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index f44a6e7efa4f..a5f96559ca8a 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -31,7 +31,7 @@ enum Position { Named(Symbol), } -struct Context<'a, 'b: 'a> { +struct Context<'a, 'b> { ecx: &'a mut ExtCtxt<'b>, /// The macro's call site. References to unstable formatting internals must /// use this span to pass the stability checker. From 1d0cb40908534beb9eb2b181f0210043e91caae4 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 14 Jun 2019 19:43:53 +0300 Subject: [PATCH 060/109] rustc: remove leftover lifetimes with no bounds from where clauses. --- src/librustc/dep_graph/dep_node.rs | 2 -- src/librustc/infer/lattice.rs | 1 - src/librustc/traits/select.rs | 1 - src/librustc/ty/query/on_disk_cache.rs | 1 - src/librustc_lint/builtin.rs | 2 +- src/librustc_metadata/creader.rs | 5 +---- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/nll/type_check/liveness/trace.rs | 14 ++------------ src/librustc_mir/build/matches/mod.rs | 2 +- src/librustc_mir/hair/pattern/_match.rs | 4 +--- src/librustc_mir/monomorphize/partitioning.rs | 1 - 11 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index e8f83093bda1..2de52e0cfc5c 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -207,8 +207,6 @@ macro_rules! define_dep_nodes { pub fn new<'a, 'tcx>(tcx: TyCtxt<'tcx>, dep: DepConstructor<'tcx>) -> DepNode - where 'tcx, - 'tcx { match dep { $( diff --git a/src/librustc/infer/lattice.rs b/src/librustc/infer/lattice.rs index a3372f503791..e55ce345bd9d 100644 --- a/src/librustc/infer/lattice.rs +++ b/src/librustc/infer/lattice.rs @@ -48,7 +48,6 @@ pub fn super_lattice_tys<'a, 'tcx, L>( ) -> RelateResult<'tcx, Ty<'tcx>> where L: LatticeDir<'a, 'tcx>, - 'tcx, { debug!("{}.lattice_tys({:?}, {:?})", this.tag(), diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index c698b0c29331..0e22db2b9f13 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -697,7 +697,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result where I: IntoIterator>, - 'tcx, { let mut result = EvaluatedToOk; for obligation in predicates { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 5781f40b93ad..1684dac490f3 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -511,7 +511,6 @@ fn decode_tagged<'a, 'tcx, D, T, V>(decoder: &mut D, where T: Decodable + Eq + ::std::fmt::Debug, V: Decodable, D: DecoderWithPosition, - 'tcx, { let start_pos = decoder.position(); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c6f361855c7d..8ed4a556ea97 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1088,7 +1088,7 @@ impl TypeAliasBounds { // We use a HIR visitor to walk the type. use rustc::hir::intravisit::{self, Visitor}; - struct WalkAssocTypes<'a, 'db> where 'db { + struct WalkAssocTypes<'a, 'db> { err: &'a mut DiagnosticBuilder<'db> } impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> { diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index ff523c7b68a9..4564f2202533 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -293,10 +293,7 @@ impl<'a> CrateLoader<'a> { &mut self, locate_ctxt: &mut locator::Context<'b>, path_kind: PathKind, - ) -> Option<(LoadResult, Option)> - where - 'a - { + ) -> Option<(LoadResult, Option)> { // Use a new locator Context so trying to load a proc macro doesn't affect the error // message we emit let mut proc_macro_locator = locate_ctxt.clone(); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a21d585a13ca..288d69f097d3 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1693,7 +1693,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn move_path_closest_to<'a>( &mut self, place: &'a Place<'tcx>, - ) -> Result<(&'a Place<'tcx>, MovePathIndex), NoMovePathFound> where 'cx { + ) -> Result<(&'a Place<'tcx>, MovePathIndex), NoMovePathFound> { let mut last_prefix = place; for prefix in self.prefixes(place, PrefixSet::All) { if let Some(mpi) = self.move_path_for_place(prefix) { diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs index 2d65eb021d38..f1d568f0cf24 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs @@ -58,12 +58,7 @@ pub(super) fn trace( } /// Contextual state for the type-liveness generator. -struct LivenessContext<'me, 'typeck, 'flow, 'tcx> -where - 'typeck, - 'flow, - 'tcx, -{ +struct LivenessContext<'me, 'typeck, 'flow, 'tcx> { /// Current type-checker, giving us our inference context etc. typeck: &'me mut TypeChecker<'typeck, 'tcx>, @@ -96,12 +91,7 @@ struct DropData<'tcx> { region_constraint_data: Option>>>, } -struct LivenessResults<'me, 'typeck, 'flow, 'tcx> -where - 'typeck, - 'flow, - 'tcx, -{ +struct LivenessResults<'me, 'typeck, 'flow, 'tcx> { cx: LivenessContext<'me, 'typeck, 'flow, 'tcx>, /// Set of points that define the current local. diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 54f935231827..aa576030ef1d 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -1691,7 +1691,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, block: BasicBlock, bindings: impl IntoIterator>, - ) where 'tcx { + ) { debug!("bind_matched_candidate_for_arm_body(block={:?})", block); let re_erased = self.hir.tcx().lifetimes.re_erased; diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 22bd802c1fab..84e23734be0e 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -392,9 +392,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { } } - fn is_non_exhaustive_variant<'p>(&self, pattern: &'p Pattern<'tcx>) -> bool - where 'a - { + fn is_non_exhaustive_variant<'p>(&self, pattern: &'p Pattern<'tcx>) -> bool { match *pattern.kind { PatternKind::Variant { adt_def, variant_index, .. } => { let ref variant = adt_def.variants[variant_index]; diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 59e95215df2a..0337f3f1da7b 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -769,7 +769,6 @@ fn numbered_codegen_unit_name( fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I) where I: Iterator>, - 'tcx, { if cfg!(debug_assertions) { debug!("{}", label); From 356a37d8d1e9c62481970c36ef45fe7f4f936549 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 16 Jun 2019 12:33:21 +0300 Subject: [PATCH 061/109] rustc: remove unused lifetimes. --- src/librustc/dep_graph/dep_node.rs | 2 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/traits/select.rs | 2 +- src/librustc/ty/query/on_disk_cache.rs | 2 +- src/librustc_codegen_llvm/lib.rs | 2 +- src/librustc_codegen_ssa/traits/backend.rs | 2 +- src/librustc_mir/hair/cx/to_ref.rs | 12 ++++++------ src/librustc_mir/hair/pattern/_match.rs | 8 ++++---- src/librustc_mir/monomorphize/collector.rs | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 2de52e0cfc5c..82b0e50b50c4 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -204,7 +204,7 @@ macro_rules! define_dep_nodes { impl DepNode { #[allow(unreachable_code, non_snake_case)] #[inline(always)] - pub fn new<'a, 'tcx>(tcx: TyCtxt<'tcx>, + pub fn new<'tcx>(tcx: TyCtxt<'tcx>, dep: DepConstructor<'tcx>) -> DepNode { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 36411f81f1a2..dc6fa066071a 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -352,7 +352,7 @@ impl IrMaps<'tcx> { } } -fn visit_fn<'a, 'tcx>( +fn visit_fn<'tcx>( ir: &mut IrMaps<'tcx>, fk: FnKind<'tcx>, decl: &'tcx hir::FnDecl, diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 0e22db2b9f13..645b6f418dcb 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -690,7 +690,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { /// Evaluates the predicates in `predicates` recursively. Note that /// this applies projections in the predicates, and therefore /// is run within an inference probe. - fn evaluate_predicates_recursively<'a, 'o, I>( + fn evaluate_predicates_recursively<'o, I>( &mut self, stack: TraitObligationStackList<'o, 'tcx>, predicates: I, diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 1684dac490f3..5349b7dbda59 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -505,7 +505,7 @@ impl<'a, 'tcx> DecoderWithPosition for CacheDecoder<'a, 'tcx> { // Decode something that was encoded with encode_tagged() and verify that the // tag matches and the correct amount of bytes was read. -fn decode_tagged<'a, 'tcx, D, T, V>(decoder: &mut D, +fn decode_tagged(decoder: &mut D, expected_tag: T) -> Result where T: Decodable + Eq + ::std::fmt::Debug, diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index a8a998a4d956..1eb6e9a5283b 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -125,7 +125,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend { ) { unsafe { allocator::codegen(tcx, mods, kind) } } - fn compile_codegen_unit<'a, 'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString) { + fn compile_codegen_unit<'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString) { base::compile_codegen_unit(tcx, cgu_name); } fn target_machine_factory( diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs index f2edff2faace..414871be6116 100644 --- a/src/librustc_codegen_ssa/traits/backend.rs +++ b/src/librustc_codegen_ssa/traits/backend.rs @@ -44,7 +44,7 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se mods: &mut Self::Module, kind: AllocatorKind, ); - fn compile_codegen_unit<'a, 'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString); + fn compile_codegen_unit<'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: InternedString); // If find_features is true this won't access `sess.crate_types` by assuming // that `is_pie_binary` is false. When we discover LLVM target features // `sess.crate_types` is uninitialized so we cannot access it. diff --git a/src/librustc_mir/hair/cx/to_ref.rs b/src/librustc_mir/hair/cx/to_ref.rs index d044b1faedfa..2daa8e3cb707 100644 --- a/src/librustc_mir/hair/cx/to_ref.rs +++ b/src/librustc_mir/hair/cx/to_ref.rs @@ -8,7 +8,7 @@ pub trait ToRef { fn to_ref(self) -> Self::Output; } -impl<'a, 'tcx> ToRef for &'tcx hir::Expr { +impl<'tcx> ToRef for &'tcx hir::Expr { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -16,7 +16,7 @@ impl<'a, 'tcx> ToRef for &'tcx hir::Expr { } } -impl<'a, 'tcx> ToRef for &'tcx P { +impl<'tcx> ToRef for &'tcx P { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -24,7 +24,7 @@ impl<'a, 'tcx> ToRef for &'tcx P { } } -impl<'a, 'tcx> ToRef for Expr<'tcx> { +impl<'tcx> ToRef for Expr<'tcx> { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -32,7 +32,7 @@ impl<'a, 'tcx> ToRef for Expr<'tcx> { } } -impl<'a, 'tcx, T, U> ToRef for &'tcx Option +impl<'tcx, T, U> ToRef for &'tcx Option where &'tcx T: ToRef { type Output = Option; @@ -42,7 +42,7 @@ impl<'a, 'tcx, T, U> ToRef for &'tcx Option } } -impl<'a, 'tcx, T, U> ToRef for &'tcx Vec +impl<'tcx, T, U> ToRef for &'tcx Vec where &'tcx T: ToRef { type Output = Vec; @@ -52,7 +52,7 @@ impl<'a, 'tcx, T, U> ToRef for &'tcx Vec } } -impl<'a, 'tcx, T, U> ToRef for &'tcx P<[T]> +impl<'tcx, T, U> ToRef for &'tcx P<[T]> where &'tcx T: ToRef { type Output = Vec; diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 84e23734be0e..e4cff5861ca5 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -983,7 +983,7 @@ enum MissingCtors<'tcx> { // (The split logic gives a performance win, because we always need to know if // the set is empty, but we rarely need the full set, and it can be expensive // to compute the full set.) -fn compute_missing_ctors<'a, 'tcx>( +fn compute_missing_ctors<'tcx>( info: MissingCtorsInfo, tcx: TyCtxt<'tcx>, all_ctors: &Vec>, @@ -1518,7 +1518,7 @@ fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx>, ctor: &Constructor<'tcx>) /// boundaries for each interval range, sort them, then create constructors for each new interval /// between every pair of boundary points. (This essentially sums up to performing the intuitive /// merging operation depicted above.) -fn split_grouped_constructors<'p, 'a, 'tcx>( +fn split_grouped_constructors<'p, 'tcx>( tcx: TyCtxt<'tcx>, ctors: Vec>, &Matrix(ref m): &Matrix<'p, 'tcx>, @@ -1596,7 +1596,7 @@ fn split_grouped_constructors<'p, 'a, 'tcx>( } /// Checks whether there exists any shared value in either `ctor` or `pat` by intersecting them. -fn constructor_intersects_pattern<'p, 'a, 'tcx>( +fn constructor_intersects_pattern<'p, 'tcx>( tcx: TyCtxt<'tcx>, ctor: &Constructor<'tcx>, pat: &'p Pattern<'tcx>, @@ -1686,7 +1686,7 @@ fn constructor_covered_by_range<'tcx>( } } -fn patterns_for_variant<'p, 'a, 'tcx>( +fn patterns_for_variant<'p, 'tcx>( subpatterns: &'p [FieldPattern<'tcx>], wild_patterns: &[&'p Pattern<'tcx>]) -> SmallVec<[&'p Pattern<'tcx>; 2]> diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 6dcb23da321a..acc786050a84 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -345,7 +345,7 @@ fn collect_roots<'tcx>(tcx: TyCtxt<'tcx>, mode: MonoItemCollectionMode) -> Vec( +fn collect_items_rec<'tcx>( tcx: TyCtxt<'tcx>, starting_point: MonoItem<'tcx>, visited: MTRef<'_, MTLock>>>, From 4c4fc7512eff62f5cc63a1a30f4474db003884c9 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 16 Jun 2019 12:33:47 +0300 Subject: [PATCH 062/109] rustc: reintroduce lifetime bounds where necessary. --- src/librustc/infer/lattice.rs | 2 +- src/librustc/traits/select.rs | 4 ++-- src/librustc_codegen_ssa/base.rs | 2 +- src/librustc_codegen_ssa/mono_item.rs | 2 +- src/librustc_metadata/creader.rs | 7 +++++-- src/librustc_metadata/decoder.rs | 20 +++++++++---------- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 2 +- src/librustc_mir/dataflow/mod.rs | 2 +- src/librustc_mir/hair/pattern/_match.rs | 5 +++-- src/librustc_mir/interpret/visitor.rs | 2 +- src/librustc_mir/monomorphize/partitioning.rs | 6 ++++-- src/librustc_mir/util/elaborate_drops.rs | 4 +++- src/librustc_save_analysis/lib.rs | 4 ++-- src/librustc_typeck/collect.rs | 2 +- 15 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/librustc/infer/lattice.rs b/src/librustc/infer/lattice.rs index e55ce345bd9d..68cbef440767 100644 --- a/src/librustc/infer/lattice.rs +++ b/src/librustc/infer/lattice.rs @@ -41,7 +41,7 @@ pub trait LatticeDir<'f, 'tcx>: TypeRelation<'tcx> { fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()>; } -pub fn super_lattice_tys<'a, 'tcx, L>( +pub fn super_lattice_tys<'a, 'tcx: 'a, L>( this: &mut L, a: Ty<'tcx>, b: Ty<'tcx>, diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 645b6f418dcb..7c4742259ac1 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -3788,9 +3788,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { matcher.relate(previous, current).is_ok() } - fn push_stack<'o, 's>( + fn push_stack<'o>( &mut self, - previous_stack: TraitObligationStackList<'s, 'tcx>, + previous_stack: TraitObligationStackList<'o, 'tcx>, obligation: &'o TraitObligation<'tcx>, ) -> TraitObligationStack<'o, 'tcx> { let fresh_trait_ref = obligation diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index a06f324d3895..ba96865d23bd 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -366,7 +366,7 @@ pub fn memcpy_ty<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx.memcpy(dst, dst_align, src, src_align, bx.cx().const_usize(size), flags); } -pub fn codegen_instance<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( +pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, instance: Instance<'tcx>, ) { diff --git a/src/librustc_codegen_ssa/mono_item.rs b/src/librustc_codegen_ssa/mono_item.rs index 57bd2f36dd7f..4446f1a3a5ce 100644 --- a/src/librustc_codegen_ssa/mono_item.rs +++ b/src/librustc_codegen_ssa/mono_item.rs @@ -17,7 +17,7 @@ pub trait MonoItemExt<'a, 'tcx> { fn to_raw_string(&self) -> String; } -impl<'a, 'tcx> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { +impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { fn define>(&self, cx: &'a Bx::CodegenCx) { debug!("BEGIN IMPLEMENTING '{} ({})' in cgu {}", self.to_string(cx.tcx(), true), diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 4564f2202533..6a01d7454bee 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -289,11 +289,14 @@ impl<'a> CrateLoader<'a> { (cnum, cmeta) } - fn load_proc_macro<'b> ( + fn load_proc_macro<'b>( &mut self, locate_ctxt: &mut locator::Context<'b>, path_kind: PathKind, - ) -> Option<(LoadResult, Option)> { + ) -> Option<(LoadResult, Option)> + where + 'a: 'b, + { // Use a new locator Context so trying to load a proc macro doesn't affect the error // message we emit let mut proc_macro_locator = locate_ctxt.clone(); diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 98cdeb699687..f78cc2f38a93 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -38,7 +38,7 @@ use log::debug; pub struct DecodeContext<'a, 'tcx> { opaque: opaque::Decoder<'a>, cdata: Option<&'a CrateMetadata>, - sess: Option<&'a Session>, + sess: Option<&'tcx Session>, tcx: Option>, // Cache the last used source_file for translating spans as an optimization. @@ -54,10 +54,8 @@ pub struct DecodeContext<'a, 'tcx> { pub trait Metadata<'a, 'tcx>: Copy { fn raw_bytes(self) -> &'a [u8]; fn cdata(self) -> Option<&'a CrateMetadata> { None } - fn sess(self) -> Option<&'a Session> { None } - fn tcx(self) -> Option> { - None - } + fn sess(self) -> Option<&'tcx Session> { None } + fn tcx(self) -> Option> { None } fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> { let tcx = self.tcx(); @@ -82,13 +80,13 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for &'a MetadataBlob { } -impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a MetadataBlob, &'a Session) { +impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a MetadataBlob, &'tcx Session) { fn raw_bytes(self) -> &'a [u8] { let (blob, _) = self; &blob.0 } - fn sess(self) -> Option<&'a Session> { + fn sess(self) -> Option<&'tcx Session> { let (_, sess) = self; Some(sess) } @@ -104,14 +102,14 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for &'a CrateMetadata { } } -impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadata, &'a Session) { +impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadata, &'tcx Session) { fn raw_bytes(self) -> &'a [u8] { self.0.raw_bytes() } fn cdata(self) -> Option<&'a CrateMetadata> { Some(self.0) } - fn sess(self) -> Option<&'a Session> { + fn sess(self) -> Option<&'tcx Session> { Some(&self.1) } } @@ -136,11 +134,11 @@ impl<'a, 'tcx, T: Decodable> Lazy { } } -impl<'a, 'tcx, T: Decodable> LazySeq { +impl<'a: 'x, 'tcx: 'x, 'x, T: Decodable> LazySeq { pub fn decode>( self, meta: M, - ) -> impl Iterator + Captures<'tcx> + 'a { + ) -> impl Iterator + Captures<'a> + Captures<'tcx> + 'x { let mut dcx = meta.decoder(self.position); dcx.lazy_state = LazyState::NodeStart(self.position); (0..self.len).map(move |_| T::decode(&mut dcx).unwrap()) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 288d69f097d3..afdc9f5c02ae 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1693,7 +1693,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn move_path_closest_to<'a>( &mut self, place: &'a Place<'tcx>, - ) -> Result<(&'a Place<'tcx>, MovePathIndex), NoMovePathFound> { + ) -> Result<(&'a Place<'tcx>, MovePathIndex), NoMovePathFound> where 'cx: 'a { let mut last_prefix = place; for prefix in self.prefixes(place, PrefixSet::All) { if let Some(mpi) = self.move_path_for_place(prefix) { diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index aa576030ef1d..55093f28a42e 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -1691,7 +1691,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, block: BasicBlock, bindings: impl IntoIterator>, - ) { + ) where 'tcx: 'b { debug!("bind_matched_candidate_for_arm_body(block={:?})", block); let re_erased = self.hir.tcx().lifetimes.re_erased; diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 1130e7e3f5d0..8f91ba23e23b 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -297,7 +297,7 @@ impl<'a, 'tcx, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> /// underlying flow analysis results, because it needs to handle cases /// where we are combining the results of *multiple* flow analyses /// (e.g., borrows + inits + uninits). -pub(crate) trait DataflowResultsConsumer<'a, 'tcx> { +pub(crate) trait DataflowResultsConsumer<'a, 'tcx: 'a> { type FlowState: FlowsAtLocation; // Observation Hooks: override (at least one of) these to get analysis feedback. diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index e4cff5861ca5..f5817694c50a 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -709,7 +709,8 @@ fn all_constructors<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, fn max_slice_length<'p, 'a, 'tcx, I>( cx: &mut MatchCheckCtxt<'a, 'tcx>, patterns: I) -> u64 - where I: Iterator> + where I: Iterator>, + 'tcx: 'p, { // The exhaustiveness-checking paper does not include any details on // checking variable-length slice patterns. However, they are matched @@ -1709,7 +1710,7 @@ fn patterns_for_variant<'p, 'tcx>( /// different patterns. /// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing /// fields filled with wild patterns. -fn specialize<'p, 'a, 'tcx>( +fn specialize<'p, 'a: 'p, 'tcx>( cx: &mut MatchCheckCtxt<'a, 'tcx>, r: &[&'p Pattern<'tcx>], constructor: &Constructor<'tcx>, diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index 95a679b95ddc..9150f16526ba 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -122,7 +122,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx, macro_rules! make_value_visitor { ($visitor_trait_name:ident, $($mutability:ident)?) => { // How to traverse a value and what to do when we are at the leaves. - pub trait $visitor_trait_name<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Sized { + pub trait $visitor_trait_name<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { type V: Value<'mir, 'tcx, M>; /// The visitor must have an `InterpretCx` in it. diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 0337f3f1da7b..32e4d4f437a7 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -766,9 +766,10 @@ fn numbered_codegen_unit_name( name_builder.build_cgu_name_no_mangle(LOCAL_CRATE, &["cgu"], Some(index)) } -fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I) +fn debug_dump<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I) where - I: Iterator>, + I: Iterator>, + 'tcx: 'a, { if cfg!(debug_assertions) { debug!("{}", label); @@ -796,6 +797,7 @@ where fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, mono_items: I) where I: Iterator>, + 'tcx: 'a, { let mut symbols: Vec<_> = mono_items.map(|mono_item| { (mono_item, mono_item.symbol_name(tcx)) diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 6da181ef6680..002ff4b0b089 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -111,7 +111,8 @@ pub fn elaborate_drop<'b, 'tcx, D>( succ: BasicBlock, unwind: Unwind, bb: BasicBlock) - where D: DropElaborator<'b, 'tcx> + where D: DropElaborator<'b, 'tcx>, + 'tcx: 'b, { DropCtxt { elaborator, source_info, place, path, succ, unwind @@ -121,6 +122,7 @@ pub fn elaborate_drop<'b, 'tcx, D>( impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> where D: DropElaborator<'b, 'tcx>, + 'tcx: 'b, { fn place_ty(&self, place: &Place<'tcx>) -> Ty<'tcx> { place.ty(self.elaborator.body(), self.tcx()).ty diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 4882a4240c83..bc813b3d5a2e 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -960,8 +960,8 @@ impl<'l> PathCollector<'l> { } } -impl<'l, 'a> Visitor<'a> for PathCollector<'l> { - fn visit_pat(&mut self, p: &'a ast::Pat) { +impl<'l> Visitor<'l> for PathCollector<'l> { + fn visit_pat(&mut self, p: &'l ast::Pat) { match p.node { PatKind::Struct(ref path, ..) => { self.collected_paths.push((p.id, path)); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 70deca9623b4..5606d9c0ce81 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1786,7 +1786,7 @@ fn impl_polarity<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> hir::ImplPolarity { /// the lifetimes that are declared. For fns or methods, we have to /// screen out those that do not appear in any where-clauses etc using /// `resolve_lifetime::early_bound_lifetimes`. -fn early_bound_lifetimes_from_generics<'a, 'tcx>( +fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>( tcx: TyCtxt<'tcx>, generics: &'a hir::Generics, ) -> impl Iterator + Captures<'tcx> { From ea78c3aa33c09f987c4ad0d87b9a39a0d065d67c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 16 Jun 2019 12:41:24 +0300 Subject: [PATCH 063/109] Run `rustfmt --file-lines ...` for changes from previous commits. --- src/librustc/ty/query/on_disk_cache.rs | 11 +++--- .../borrowck/gather_loans/gather_moves.rs | 24 +++++++----- src/librustc_codegen_ssa/base.rs | 16 ++++---- src/librustc_codegen_ssa/common.rs | 8 ++-- src/librustc_codegen_ssa/glue.rs | 2 +- src/librustc_codegen_ssa/mir/analyze.rs | 7 ++-- src/librustc_codegen_ssa/mir/mod.rs | 11 +++--- src/librustc_mir/dataflow/mod.rs | 33 ++++++++++++----- src/librustc_mir/hair/cx/to_ref.rs | 9 +++-- src/librustc_mir/hair/pattern/_match.rs | 37 ++++++++++--------- src/librustc_mir/transform/generator.rs | 3 +- src/librustc_mir/util/elaborate_drops.rs | 8 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 11 +++--- 13 files changed, 103 insertions(+), 77 deletions(-) diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 5349b7dbda59..982886f0f157 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -505,12 +505,11 @@ impl<'a, 'tcx> DecoderWithPosition for CacheDecoder<'a, 'tcx> { // Decode something that was encoded with encode_tagged() and verify that the // tag matches and the correct amount of bytes was read. -fn decode_tagged(decoder: &mut D, - expected_tag: T) - -> Result - where T: Decodable + Eq + ::std::fmt::Debug, - V: Decodable, - D: DecoderWithPosition, +fn decode_tagged(decoder: &mut D, expected_tag: T) -> Result +where + T: Decodable + Eq + ::std::fmt::Debug, + V: Decodable, + D: DecoderWithPosition, { let start_pos = decoder.position(); diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index cc1f7232e04c..05c0a22900a0 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -20,7 +20,7 @@ struct GatherMoveInfo<'c, 'tcx> { id: hir::ItemLocalId, kind: MoveKind, cmt: &'c mc::cmt_<'tcx>, - span_path_opt: Option> + span_path_opt: Option>, } /// Represents the kind of pattern @@ -91,11 +91,13 @@ pub fn gather_move_from_expr<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, gather_move(bccx, move_data, move_error_collector, move_info); } -pub fn gather_move_from_pat<'a, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, - move_data: &MoveData<'tcx>, - move_error_collector: &mut MoveErrorCollector<'tcx>, - move_pat: &hir::Pat, - cmt: &'c mc::cmt_<'tcx>) { +pub fn gather_move_from_pat<'a, 'c, 'tcx>( + bccx: &BorrowckCtxt<'a, 'tcx>, + move_data: &MoveData<'tcx>, + move_error_collector: &mut MoveErrorCollector<'tcx>, + move_pat: &hir::Pat, + cmt: &'c mc::cmt_<'tcx>, +) { let source = get_pattern_source(bccx.tcx,move_pat); let pat_span_path_opt = match move_pat.node { PatKind::Binding(_, _, ident, _) => { @@ -121,10 +123,12 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, gather_move(bccx, move_data, move_error_collector, move_info); } -fn gather_move<'a, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, - move_data: &MoveData<'tcx>, - move_error_collector: &mut MoveErrorCollector<'tcx>, - move_info: GatherMoveInfo<'c, 'tcx>) { +fn gather_move<'a, 'c, 'tcx>( + bccx: &BorrowckCtxt<'a, 'tcx>, + move_data: &MoveData<'tcx>, + move_error_collector: &mut MoveErrorCollector<'tcx>, + move_info: GatherMoveInfo<'c, 'tcx>, +) { debug!("gather_move(move_id={:?}, cmt={:?})", move_info.id, move_info.cmt); diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index ba96865d23bd..47b383fddbc3 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -94,7 +94,7 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( rhs: Bx::Value, t: Ty<'tcx>, ret_ty: Bx::Type, - op: hir::BinOpKind + op: hir::BinOpKind, ) -> Bx::Value { let signed = match t.sty { ty::Float(_) => { @@ -156,7 +156,7 @@ pub fn unsize_thin_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, src: Bx::Value, src_ty: Ty<'tcx>, - dst_ty: Ty<'tcx> + dst_ty: Ty<'tcx>, ) -> (Bx::Value, Bx::Value) { debug!("unsize_thin_ptr: {:?} => {:?}", src_ty, dst_ty); match (&src_ty.sty, &dst_ty.sty) { @@ -210,8 +210,8 @@ pub fn unsize_thin_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, src: PlaceRef<'tcx, Bx::Value>, - dst: PlaceRef<'tcx, Bx::Value> -) { + dst: PlaceRef<'tcx, Bx::Value>, +) { let src_ty = src.layout.ty; let dst_ty = dst.layout.ty; let mut coerce_ptr = || { @@ -270,7 +270,7 @@ pub fn cast_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, op: hir::BinOpKind, lhs: Bx::Value, - rhs: Bx::Value + rhs: Bx::Value, ) -> Bx::Value { cast_shift_rhs(bx, op, lhs, rhs) } @@ -318,7 +318,7 @@ pub fn wants_msvc_seh(sess: &Session) -> bool { pub fn from_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, - val: Bx::Value + val: Bx::Value, ) -> Bx::Value { if bx.cx().val_ty(val) == bx.cx().type_i1() { bx.zext(val, bx.cx().type_i8()) @@ -387,9 +387,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( /// Creates the `main` function which will initialize the rust runtime and call /// users main function. -pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( - cx: &'a Bx::CodegenCx -) { +pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'a Bx::CodegenCx) { let (main_def_id, span) = match cx.tcx().entry_fn(LOCAL_CRATE) { Some((def_id, _)) => { (def_id, cx.tcx().def_span(def_id)) }, None => return, diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index d17edf2ec0a2..6376512ca402 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -140,7 +140,7 @@ pub fn langcall(tcx: TyCtxt<'_>, span: Option, msg: &str, li: LangItem) -> pub fn build_unchecked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, lhs: Bx::Value, - rhs: Bx::Value + rhs: Bx::Value, ) -> Bx::Value { let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs); // #1877, #10183: Ensure that input is always valid @@ -152,7 +152,7 @@ pub fn build_unchecked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, lhs_t: Ty<'tcx>, lhs: Bx::Value, - rhs: Bx::Value + rhs: Bx::Value, ) -> Bx::Value { let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs); // #1877, #10183: Ensure that input is always valid @@ -167,7 +167,7 @@ pub fn build_unchecked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( fn shift_mask_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, - rhs: Bx::Value + rhs: Bx::Value, ) -> Bx::Value { let rhs_llty = bx.val_ty(rhs); let shift_val = shift_mask_val(bx, rhs_llty, rhs_llty, false); @@ -178,7 +178,7 @@ pub fn shift_mask_val<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, llty: Bx::Type, mask_llty: Bx::Type, - invert: bool + invert: bool, ) -> Bx::Value { let kind = bx.type_kind(llty); match kind { diff --git a/src/librustc_codegen_ssa/glue.rs b/src/librustc_codegen_ssa/glue.rs index 294e2e021d2a..7fd9f67e2f45 100644 --- a/src/librustc_codegen_ssa/glue.rs +++ b/src/librustc_codegen_ssa/glue.rs @@ -10,7 +10,7 @@ use crate::traits::*; pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, t: Ty<'tcx>, - info: Option + info: Option, ) -> (Bx::Value, Bx::Value) { let layout = bx.layout_of(t); debug!("size_and_align_of_dst(ty={}, info={:?}): layout: {:?}", diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 3d41eddb8035..0289150a5e42 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -13,7 +13,7 @@ use super::FunctionCx; use crate::traits::*; pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( - fx: &FunctionCx<'a, 'tcx, Bx> + fx: &FunctionCx<'a, 'tcx, Bx>, ) -> BitSet { let mir = fx.mir; let mut analyzer = LocalAnalyzer::new(fx); @@ -49,7 +49,7 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { non_ssa_locals: BitSet, // The location of the first visited direct assignment to each // local, or an invalid location (out of bounds `block` index). - first_assignment: IndexVec + first_assignment: IndexVec, } impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { @@ -95,7 +95,8 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { } impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> - for LocalAnalyzer<'mir, 'a, 'tcx, Bx> { + for LocalAnalyzer<'mir, 'a, 'tcx, Bx> +{ fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'tcx>, diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 78af71b5a498..c20be56ba0cf 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -43,7 +43,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { /// don't really care about it very much. Anyway, this value /// contains an alloca into which the personality is stored and /// then later loaded when generating the DIVERGE_BLOCK. - personality_slot: Option>, + personality_slot: Option>, /// A `Block` for each MIR `BasicBlock` blocks: IndexVec, @@ -355,10 +355,11 @@ fn create_funclets<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( mir: &'a Body<'tcx>, bx: &mut Bx, cleanup_kinds: &IndexVec, - block_bxs: &IndexVec) - -> (IndexVec>, - IndexVec>) -{ + block_bxs: &IndexVec, +) -> ( + IndexVec>, + IndexVec>, +) { block_bxs.iter_enumerated().zip(cleanup_kinds).map(|((bb, &llbb), cleanup_kind)| { match *cleanup_kind { CleanupKind::Funclet if base::wants_msvc_seh(bx.sess()) => {} diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 8f91ba23e23b..0728d5b21bbd 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -43,7 +43,7 @@ pub(crate) mod indexes { pub(crate) struct DataflowBuilder<'a, 'tcx, BD> where - BD: BitDenotation<'tcx> + BD: BitDenotation<'tcx>, { def_id: DefId, flow_state: DataflowAnalysis<'a, 'tcx, BD>, @@ -88,7 +88,7 @@ pub(crate) trait Dataflow<'tcx, BD: BitDenotation<'tcx>> { impl<'a, 'tcx, BD> Dataflow<'tcx, BD> for DataflowBuilder<'a, 'tcx, BD> where - BD: BitDenotation<'tcx> + BD: BitDenotation<'tcx>, { fn dataflow

(&mut self, p: P) where P: Fn(&BD, BD::Idx) -> DebugFormatted { self.flow_state.build_sets(); @@ -179,12 +179,16 @@ where } } -struct PropagationContext<'b, 'a, 'tcx, O> where O: 'b + BitDenotation<'tcx> +struct PropagationContext<'b, 'a, 'tcx, O> +where + O: 'b + BitDenotation<'tcx>, { builder: &'b mut DataflowAnalysis<'a, 'tcx, O>, } -impl<'a, 'tcx, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'a, 'tcx, BD> DataflowAnalysis<'a, 'tcx, BD> +where + BD: BitDenotation<'tcx>, { fn propagate(&mut self) { let mut temp = BitSet::new_empty(self.flow_state.sets.bits_per_block); @@ -234,7 +238,9 @@ impl<'a, 'tcx, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx> } } -impl<'b, 'a, 'tcx, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'b, 'a, 'tcx, BD> PropagationContext<'b, 'a, 'tcx, BD> +where + BD: BitDenotation<'tcx>, { fn walk_cfg(&mut self, in_out: &mut BitSet) { let mut dirty_queue: WorkQueue = @@ -265,7 +271,9 @@ fn dataflow_path(context: &str, path: &str) -> PathBuf { path } -impl<'a, 'tcx, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation<'tcx> +impl<'a, 'tcx, BD> DataflowBuilder<'a, 'tcx, BD> +where + BD: BitDenotation<'tcx>, { fn pre_dataflow_instrumentation

(&self, p: P) -> io::Result<()> where P: Fn(&BD, BD::Idx) -> DebugFormatted @@ -387,14 +395,18 @@ pub fn state_for_location<'tcx, T: BitDenotation<'tcx>>(loc: Location, gen_set.to_dense() } -pub struct DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> +pub struct DataflowAnalysis<'a, 'tcx, O> +where + O: BitDenotation<'tcx>, { flow_state: DataflowState<'tcx, O>, dead_unwinds: &'a BitSet, body: &'a Body<'tcx>, } -impl<'a, 'tcx, O> DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> +impl<'a, 'tcx, O> DataflowAnalysis<'a, 'tcx, O> +where + O: BitDenotation<'tcx>, { pub fn results(self) -> DataflowResults<'tcx, O> { DataflowResults(self.flow_state) @@ -734,7 +746,10 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation<'tcx> } } -impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation<'tcx> { +impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> +where + D: BitDenotation<'tcx>, +{ /// Propagates the bits of `in_out` into all the successors of `bb`, /// using bitwise operator denoted by `self.operator`. /// diff --git a/src/librustc_mir/hair/cx/to_ref.rs b/src/librustc_mir/hair/cx/to_ref.rs index 2daa8e3cb707..946d66fc91d7 100644 --- a/src/librustc_mir/hair/cx/to_ref.rs +++ b/src/librustc_mir/hair/cx/to_ref.rs @@ -33,7 +33,8 @@ impl<'tcx> ToRef for Expr<'tcx> { } impl<'tcx, T, U> ToRef for &'tcx Option - where &'tcx T: ToRef +where + &'tcx T: ToRef, { type Output = Option; @@ -43,7 +44,8 @@ impl<'tcx, T, U> ToRef for &'tcx Option } impl<'tcx, T, U> ToRef for &'tcx Vec - where &'tcx T: ToRef +where + &'tcx T: ToRef, { type Output = Vec; @@ -53,7 +55,8 @@ impl<'tcx, T, U> ToRef for &'tcx Vec } impl<'tcx, T, U> ToRef for &'tcx P<[T]> - where &'tcx T: ToRef +where + &'tcx T: ToRef, { type Output = Vec; diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index f5817694c50a..1fcdf7133725 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -632,10 +632,10 @@ impl<'tcx> Witness<'tcx> { /// /// We make sure to omit constructors that are statically impossible. E.g., for /// `Option`, we do not include `Some(_)` in the returned list of constructors. -fn all_constructors<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, - pcx: PatternContext<'tcx>) - -> Vec> -{ +fn all_constructors<'a, 'tcx>( + cx: &mut MatchCheckCtxt<'a, 'tcx>, + pcx: PatternContext<'tcx>, +) -> Vec> { debug!("all_constructors({:?})", pcx.ty); let ctors = match pcx.ty.sty { ty::Bool => { @@ -706,11 +706,10 @@ fn all_constructors<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, ctors } -fn max_slice_length<'p, 'a, 'tcx, I>( - cx: &mut MatchCheckCtxt<'a, 'tcx>, - patterns: I) -> u64 - where I: Iterator>, - 'tcx: 'p, +fn max_slice_length<'p, 'a, 'tcx, I>(cx: &mut MatchCheckCtxt<'a, 'tcx>, patterns: I) -> u64 +where + I: Iterator>, + 'tcx: 'p, { // The exhaustiveness-checking paper does not include any details on // checking variable-length slice patterns. However, they are matched @@ -1056,11 +1055,12 @@ fn compute_missing_ctors<'tcx>( /// relation to preceding patterns, it is not reachable) and exhaustiveness /// checking (if a wildcard pattern is useful in relation to a matrix, the /// matrix isn't exhaustive). -pub fn is_useful<'p, 'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, - matrix: &Matrix<'p, 'tcx>, - v: &[&Pattern<'tcx>], - witness: WitnessPreference) - -> Usefulness<'tcx> { +pub fn is_useful<'p, 'a, 'tcx>( + cx: &mut MatchCheckCtxt<'a, 'tcx>, + matrix: &Matrix<'p, 'tcx>, + v: &[&Pattern<'tcx>], + witness: WitnessPreference, +) -> Usefulness<'tcx> { let &Matrix(ref rows) = matrix; debug!("is_useful({:#?}, {:#?})", matrix, v); @@ -1372,10 +1372,11 @@ fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty /// expanded to. /// /// For instance, a tuple pattern (43u32, 'a') has sub pattern types [u32, char]. -fn constructor_sub_pattern_tys<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, - ctor: &Constructor<'tcx>, - ty: Ty<'tcx>) -> Vec> -{ +fn constructor_sub_pattern_tys<'a, 'tcx>( + cx: &MatchCheckCtxt<'a, 'tcx>, + ctor: &Constructor<'tcx>, + ty: Ty<'tcx>, +) -> Vec> { debug!("constructor_sub_pattern_tys({:#?}, {:?})", ctor, ty); match ty.sty { ty::Tuple(ref fs) => fs.into_iter().map(|t| t.expect_ty()).collect(), diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 6be54aa629de..ba8c47c665e0 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -625,7 +625,8 @@ struct StorageConflictVisitor<'body, 'tcx, 's> { } impl<'body, 'tcx, 's> DataflowResultsConsumer<'body, 'tcx> -for StorageConflictVisitor<'body, 'tcx, 's> { + for StorageConflictVisitor<'body, 'tcx, 's> +{ type FlowState = FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>; fn body(&self) -> &'body Body<'tcx> { diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 002ff4b0b089..815d210d36ea 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -91,7 +91,8 @@ pub trait DropElaborator<'a, 'tcx>: fmt::Debug { #[derive(Debug)] struct DropCtxt<'l, 'b, 'tcx, D> - where D : DropElaborator<'b, 'tcx> + 'l +where + D: DropElaborator<'b, 'tcx> + 'l, { elaborator: &'l mut D, @@ -110,8 +111,9 @@ pub fn elaborate_drop<'b, 'tcx, D>( path: D::Path, succ: BasicBlock, unwind: Unwind, - bb: BasicBlock) - where D: DropElaborator<'b, 'tcx>, + bb: BasicBlock, +) where + D: DropElaborator<'b, 'tcx>, 'tcx: 'b, { DropCtxt { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 3edf7726ec61..444cf1263ce2 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -339,11 +339,12 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) /// This method helps to extract all the type parameters referenced from a /// type. For a type parameter ``, it looks for either a `TyPath` that /// is not global and starts with `T`, or a `TyQPath`. -fn find_type_parameters(ty: &ast::Ty, - ty_param_names: &[ast::Name], - span: Span, - cx: &ExtCtxt<'_>) - -> Vec> { +fn find_type_parameters( + ty: &ast::Ty, + ty_param_names: &[ast::Name], + span: Span, + cx: &ExtCtxt<'_>, +) -> Vec> { use syntax::visit; struct Visitor<'a, 'b> { From 2be847b2f95414690538bea48138a6738b47b43a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 16 Jun 2019 14:11:20 +0300 Subject: [PATCH 064/109] test: normalize away the line/column info in ui/pattern/const-pat-ice. --- src/test/ui/pattern/const-pat-ice.rs | 1 + src/test/ui/pattern/const-pat-ice.stderr | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/ui/pattern/const-pat-ice.rs b/src/test/ui/pattern/const-pat-ice.rs index b866c7fa6cc9..065587678821 100644 --- a/src/test/ui/pattern/const-pat-ice.rs +++ b/src/test/ui/pattern/const-pat-ice.rs @@ -2,6 +2,7 @@ // rustc-env:RUST_BACKTRACE=0 // normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET" // normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS" +// normalize-stderr-test "/_match.rs:[0-9]+:[0-9]+" -> "/_match.rs:LL:CC" // This is a repro test for an ICE in our pattern handling of constants. diff --git a/src/test/ui/pattern/const-pat-ice.stderr b/src/test/ui/pattern/const-pat-ice.stderr index 7ddeac4abca1..7a0f14425b74 100644 --- a/src/test/ui/pattern/const-pat-ice.stderr +++ b/src/test/ui/pattern/const-pat-ice.stderr @@ -1,4 +1,4 @@ -thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1084:5 +thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:LL:CC note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. error: internal compiler error: unexpected panic From 831ddf700d91b50ac8e3beffe35d7ee5f5dd5218 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Jun 2019 08:31:43 -0700 Subject: [PATCH 065/109] ci: Add a script for generating CPU usage graphs This commit checks in a script which generates CPU usage graphs over time, expanding on the previous comment that was include in the collection file. --- src/ci/cpu-usage-over-time.py | 19 ++--------- src/etc/cpu-usage-over-time-plot.sh | 49 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 17 deletions(-) create mode 100755 src/etc/cpu-usage-over-time-plot.sh diff --git a/src/ci/cpu-usage-over-time.py b/src/ci/cpu-usage-over-time.py index 78427a6360a9..daf21670b333 100644 --- a/src/ci/cpu-usage-over-time.py +++ b/src/ci/cpu-usage-over-time.py @@ -30,23 +30,8 @@ # the second column is always zero. # # Once you've downloaded a file there's various ways to plot it and visualize -# it. For command line usage you can use a script like so: -# -# set timefmt '%Y-%m-%dT%H:%M:%S' -# set xdata time -# set ylabel "Idle CPU %" -# set xlabel "Time" -# set datafile sep ',' -# set term png -# set output "printme.png" -# set grid -# builder = "i686-apple" -# plot "cpu-".builder.".csv" using 1:2 with lines title builder -# -# Executed as `gnuplot < ./foo.plot` it will generate a graph called -# `printme.png` which you can then open up. If you know how to improve this -# script or the viewing process that would be much appreciated :) (or even if -# you know how to automate it!) +# it. For command line usage you use the `src/etc/cpu-usage-over-time-plot.sh` +# script in this repository. import datetime import sys diff --git a/src/etc/cpu-usage-over-time-plot.sh b/src/etc/cpu-usage-over-time-plot.sh new file mode 100755 index 000000000000..724a21c3fc26 --- /dev/null +++ b/src/etc/cpu-usage-over-time-plot.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# A small script to help visualizing CPU usage over time data collected on CI +# using `gnuplot`. +# +# This script is expected to be called with two arguments. The first is the full +# commit SHA of the build you're interested in, and the second is the name of +# the builder. For example: +# +# ./src/etc/cpu-usage-over-time-plot.sh e699ea096fcc2fc9ce8e8bcf884e11496a31cc9f i686-mingw-1 +# +# That will generate `$builder.png` in the current directory which you can open +# up to see a hopefully pretty graph. +# +# Improvements to this script are greatly appreciated! + +set -ex + +bucket=rust-lang-ci-evalazure +commit=$1 +builder=$2 + +curl -O https://$bucket.s3.amazonaws.com/rustc-builds/$commit/cpu-$builder.csv + +gnuplot <<-EOF +reset +set timefmt '%Y-%m-%dT%H:%M:%S' +set xdata time +set ylabel "CPU Usage %" +set xlabel "Time" +set datafile sep ',' +set term png size 3000,1000 +set output "$builder.png" +set grid + +f(x) = mean_y +fit f(x) 'cpu-$builder.csv' using 1:(100-\$2) via mean_y + +set label 1 gprintf("Average = %g%%", mean_y) center font ",18" +set label 1 at graph 0.50, 0.25 +set xtics rotate by 45 offset -2,-2.4 300 +set ytics 10 +set boxwidth 0.5 + +plot \\ + mean_y with lines linetype 1 linecolor rgb "#ff0000" title "average", \\ + "cpu-$builder.csv" using 1:(100-\$2) with points pointtype 7 pointsize 0.4 title "$builder", \\ + "" using 1:(100-\$2) smooth bezier linewidth 3 title "bezier" +EOF From d8eea9258acfad331226ddc746f220216bf5dde4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 18 Jun 2019 21:57:31 +0200 Subject: [PATCH 066/109] create an issue for miri even in status test-fail --- src/tools/publish_toolstate.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index a777279bd16c..9e7c18b7f566 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -64,6 +64,7 @@ def maybe_delink(message): def issue( tool, + status, maintainers, relevant_pr_number, relevant_pr_user, @@ -72,12 +73,16 @@ def issue( # Open an issue about the toolstate failure. assignees = [x.strip() for x in maintainers.split('@') if x != ''] assignees.append(relevant_pr_user) + if status == 'test-fail': + status_description = 'has failing tests' + else: + status_description = 'no longer builds' response = urllib2.urlopen(urllib2.Request( gh_url(), json.dumps({ 'body': maybe_delink(textwrap.dedent('''\ Hello, this is your friendly neighborhood mergebot. - After merging PR {}, I observed that the tool {} no longer builds. + After merging PR {}, I observed that the tool {} {}. A follow-up PR to the repository {} is needed to fix the fallout. cc @{}, do you think you would have time to do the follow-up work? @@ -85,7 +90,10 @@ def issue( cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization. - ''').format(relevant_pr_number, tool, REPOS.get(tool), relevant_pr_user, pr_reviewer)), + ''').format( + relevant_pr_number, tool, status_description, + REPOS.get(tool), relevant_pr_user, pr_reviewer + )), 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number), 'assignees': assignees, 'labels': ['T-compiler', 'I-nominated'], @@ -127,7 +135,7 @@ def update_latest( for status in latest: tool = status['tool'] changed = False - build_failed = False + create_issue = False for os, s in current_status.items(): old = status[os] @@ -145,14 +153,15 @@ def update_latest( .format(tool, os, old, new) message += '{} (cc {}, @rust-lang/infra).\n' \ .format(title, MAINTAINERS.get(tool)) - # only create issues for build failures. Other failures can be spurious - if new == 'build-fail': - build_failed = True + # Most tools only create issues for build failures. + # Other failures can be spurious. + if new == 'build-fail' or (tool == 'miri' and new == 'test-fail'): + create_issue = True - if build_failed: + if create_issue: try: issue( - tool, MAINTAINERS.get(tool, ''), + tool, new, MAINTAINERS.get(tool, ''), relevant_pr_number, relevant_pr_user, pr_reviewer, ) except IOError as e: From 2191c1db08d21aac4d3823a497e429de283e878b Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 18 Jun 2019 22:05:27 +0200 Subject: [PATCH 067/109] improve indentation --- src/librustc_typeck/check/expr.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 06d07d992427..8edda805592a 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1218,17 +1218,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match variant.ctor_kind { CtorKind::Fn => { err.span_label(field.ident.span, "field does not exist"); - err.span_label( - field.ident.span, - format!("`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`", adt=ty, kind_name=kind_name) - ); + err.span_label(field.ident.span, format!( + "`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`", + adt=ty, + kind_name=kind_name + )); } _ => { // prevent all specified fields from being suggested let skip_fields = skip_fields.iter().map(|ref x| x.ident.as_str()); - if let Some(field_name) = Self::suggest_field_name(variant, - &field.ident.as_str(), - skip_fields.collect()) { + if let Some(field_name) = Self::suggest_field_name( + variant, + &field.ident.as_str(), + skip_fields.collect() + ) { err.span_suggestion( field.ident.span, "a field with a similar name exists", @@ -1239,12 +1242,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match ty.sty { ty::Adt(adt, ..) => { if adt.is_enum() { - err.span_label(field.ident.span, - format!("`{}::{}` does not have this field", - ty, variant.ident)); + err.span_label(field.ident.span, format!( + "`{}::{}` does not have this field", + ty, + variant.ident + )); } else { - err.span_label(field.ident.span, - format!("`{}` does not have this field", ty)); + err.span_label(field.ident.span, format!( + "`{}` does not have this field", + ty + )); } let available_field_names = self.available_field_names(variant); if !available_field_names.is_empty() { From f4737d5607eabbfc07440b0ce64b852395948a68 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 18 Jun 2019 22:06:00 +0200 Subject: [PATCH 068/109] Make Place::ty iterate --- src/librustc/mir/tcx.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index afabcdfadd03..2079a2a34e7e 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -122,13 +122,25 @@ impl<'tcx> Place<'tcx> { where D: HasLocalDecls<'tcx>, { - match *self { - Place::Base(PlaceBase::Local(index)) => - PlaceTy::from_ty(local_decls.local_decls()[index].ty), - Place::Base(PlaceBase::Static(ref data)) => - PlaceTy::from_ty(data.ty), - Place::Projection(ref proj) => - proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem), + self.iterate(|place_base, place_projections| { + let mut place_ty = place_base.ty(local_decls); + + for proj in place_projections { + place_ty = place_ty.projection_ty(tcx, &proj.elem); + } + + place_ty + }) + } +} + +impl<'tcx> PlaceBase<'tcx> { + pub fn ty(&self, local_decls: &D) -> PlaceTy<'tcx> + where D: HasLocalDecls<'tcx> + { + match self { + PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty), + PlaceBase::Static(data) => PlaceTy::from_ty(data.ty), } } } From 63edd2c35892c81fe3f071e7e259437de9557845 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 25 May 2019 10:11:48 +0100 Subject: [PATCH 069/109] Remove the HirId/NodeId from where clauses Also give them a span in the HIR --- src/librustc/hir/intravisit.rs | 1 - src/librustc/hir/lowering.rs | 6 +++--- src/librustc/hir/mod.rs | 17 ++++++++--------- src/librustc/hir/print.rs | 2 +- src/libsyntax/ast.rs | 2 -- src/libsyntax/mut_visit.rs | 3 +-- src/libsyntax/parse/parser.rs | 2 -- src/libsyntax/print/pprust.rs | 1 - src/libsyntax_ext/deriving/generic/ty.rs | 1 - src/test/ui/error-codes/E0646.stderr | 4 ++-- src/test/ui/error-codes/E0647.stderr | 4 ++-- src/test/ui/issues/issue-50714-1.stderr | 4 ++-- src/test/ui/issues/issue-50714.stderr | 4 ++-- 13 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index e29a373ec3b7..96fa8fe1f269 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -773,7 +773,6 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { walk_list!(visitor, visit_generic_param, &generics.params); - visitor.visit_id(generics.where_clause.hir_id); walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 153397f11b5a..b764d1079293 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1727,8 +1727,8 @@ impl<'a> LoweringContext<'a> { generics: hir::Generics { params: lifetime_defs, where_clause: hir::WhereClause { - hir_id: lctx.next_id(), predicates: hir_vec![], + span, }, span, }, @@ -2619,8 +2619,8 @@ impl<'a> LoweringContext<'a> { generics: hir::Generics { params: generic_params, where_clause: hir::WhereClause { - hir_id: this.next_id(), predicates: hir_vec![], + span, }, span, }, @@ -2973,11 +2973,11 @@ impl<'a> LoweringContext<'a> { AnonymousLifetimeMode::ReportError, |this| { hir::WhereClause { - hir_id: this.lower_node_id(wc.id), predicates: wc.predicates .iter() .map(|predicate| this.lower_where_predicate(predicate)) .collect(), + span: wc.span, } }, ) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 0884a726a27b..2cb0e2fd8cef 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -592,8 +592,8 @@ impl Generics { Generics { params: HirVec::new(), where_clause: WhereClause { - hir_id: DUMMY_HIR_ID, predicates: HirVec::new(), + span: DUMMY_SP, }, span: DUMMY_SP, } @@ -644,19 +644,18 @@ pub enum SyntheticTyParamKind { /// A where-clause in a definition. #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct WhereClause { - pub hir_id: HirId, pub predicates: HirVec, + // Only valid if predicates isn't empty. + span: Span, } impl WhereClause { pub fn span(&self) -> Option { - self.predicates.iter().map(|predicate| predicate.span()) - .fold(None, |acc, i| match (acc, i) { - (None, i) => Some(i), - (Some(acc), i) => { - Some(acc.to(i)) - } - }) + if self.predicates.is_empty() { + None + } else { + Some(self.span) + } } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 7b0a499fa5c6..54ac5abd3219 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -2202,8 +2202,8 @@ impl<'a> State<'a> { let generics = hir::Generics { params: hir::HirVec::new(), where_clause: hir::WhereClause { - hir_id: hir::DUMMY_HIR_ID, predicates: hir::HirVec::new(), + span: syntax_pos::DUMMY_SP, }, span: syntax_pos::DUMMY_SP, }; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 54cd4035a7ba..b1a62ac81d03 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -362,7 +362,6 @@ impl Default for Generics { Generics { params: Vec::new(), where_clause: WhereClause { - id: DUMMY_NODE_ID, predicates: Vec::new(), span: DUMMY_SP, }, @@ -374,7 +373,6 @@ impl Default for Generics { /// A where-clause in a definition. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereClause { - pub id: NodeId, pub predicates: Vec, pub span: Span, } diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 02e2c96868dd..5a5b633e3151 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -750,8 +750,7 @@ pub fn noop_visit_generics(generics: &mut Generics, vis: &mut T) } pub fn noop_visit_where_clause(wc: &mut WhereClause, vis: &mut T) { - let WhereClause { id, predicates, span } = wc; - vis.visit_id(id); + let WhereClause { predicates, span } = wc; visit_vec(predicates, |predicate| vis.visit_where_predicate(predicate)); vis.visit_span(span); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 78eeb5122066..fa697e06d269 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5075,7 +5075,6 @@ impl<'a> Parser<'a> { Ok(ast::Generics { params, where_clause: WhereClause { - id: ast::DUMMY_NODE_ID, predicates: Vec::new(), span: DUMMY_SP, }, @@ -5334,7 +5333,6 @@ impl<'a> Parser<'a> { /// ``` fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> { let mut where_clause = WhereClause { - id: ast::DUMMY_NODE_ID, predicates: Vec::new(), span: self.prev_span.to(self.prev_span), }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4cbe590d44bf..0aac4f83658b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -3042,7 +3042,6 @@ impl<'a> State<'a> { let generics = ast::Generics { params: Vec::new(), where_clause: ast::WhereClause { - id: ast::DUMMY_NODE_ID, predicates: Vec::new(), span: syntax_pos::DUMMY_SP, }, diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 362ea9ed2291..90d826429da4 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -223,7 +223,6 @@ fn mk_generics(params: Vec, span: Span) -> Generics { Generics { params, where_clause: ast::WhereClause { - id: ast::DUMMY_NODE_ID, predicates: Vec::new(), span, }, diff --git a/src/test/ui/error-codes/E0646.stderr b/src/test/ui/error-codes/E0646.stderr index 976cdd45f576..069401b3f182 100644 --- a/src/test/ui/error-codes/E0646.stderr +++ b/src/test/ui/error-codes/E0646.stderr @@ -1,8 +1,8 @@ error[E0646]: `main` function is not allowed to have a `where` clause - --> $DIR/E0646.rs:1:17 + --> $DIR/E0646.rs:1:11 | LL | fn main() where (): Copy {} - | ^^^^^^^^ `main` cannot have a `where` clause + | ^^^^^^^^^^^^^^ `main` cannot have a `where` clause error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0647.stderr b/src/test/ui/error-codes/E0647.stderr index 465cc7702eef..08cedfaef04c 100644 --- a/src/test/ui/error-codes/E0647.stderr +++ b/src/test/ui/error-codes/E0647.stderr @@ -1,8 +1,8 @@ error[E0647]: start function is not allowed to have a `where` clause - --> $DIR/E0647.rs:7:56 + --> $DIR/E0647.rs:7:50 | LL | fn start(_: isize, _: *const *const u8) -> isize where (): Copy { - | ^^^^^^^^ start function cannot have a `where` clause + | ^^^^^^^^^^^^^^ start function cannot have a `where` clause error: aborting due to previous error diff --git a/src/test/ui/issues/issue-50714-1.stderr b/src/test/ui/issues/issue-50714-1.stderr index 427b200adf43..28469bee0171 100644 --- a/src/test/ui/issues/issue-50714-1.stderr +++ b/src/test/ui/issues/issue-50714-1.stderr @@ -1,8 +1,8 @@ error[E0647]: start function is not allowed to have a `where` clause - --> $DIR/issue-50714-1.rs:9:56 + --> $DIR/issue-50714-1.rs:9:50 | LL | fn start(_: isize, _: *const *const u8) -> isize where fn(&()): Eq { - | ^^^^^^^^^^^ start function cannot have a `where` clause + | ^^^^^^^^^^^^^^^^^ start function cannot have a `where` clause error: aborting due to previous error diff --git a/src/test/ui/issues/issue-50714.stderr b/src/test/ui/issues/issue-50714.stderr index e048f39260c5..a11aceb6211c 100644 --- a/src/test/ui/issues/issue-50714.stderr +++ b/src/test/ui/issues/issue-50714.stderr @@ -1,8 +1,8 @@ error[E0646]: `main` function is not allowed to have a `where` clause - --> $DIR/issue-50714.rs:3:17 + --> $DIR/issue-50714.rs:3:11 | LL | fn main() where fn(&()): Eq {} - | ^^^^^^^^^^^ `main` cannot have a `where` clause + | ^^^^^^^^^^^^^^^^^ `main` cannot have a `where` clause error: aborting due to previous error From 36960a5a6f0d5201e7d7f59a1809c3030ddef579 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 25 May 2019 10:12:30 +0100 Subject: [PATCH 070/109] Remove an unnecessary HirId to DefId convertion --- src/librustc_typeck/astconv.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 97124e534771..8236cd1f7385 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2001,16 +2001,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let PathSeg(def_id, index) = path_segs.last().unwrap(); self.ast_path_to_ty(span, *def_id, &path.segments[*index]) } - Res::Def(DefKind::TyParam, did) => { + Res::Def(DefKind::TyParam, def_id) => { assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - let hir_id = tcx.hir().as_local_hir_id(did).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[ - &tcx.hir().local_def_id_from_hir_id(hir_id)]; + let index = generics.param_def_id_to_index[&def_id]; tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str()) } Res::SelfTy(Some(_), None) => { From d5f80c8414989660d66d822f3e2391f4efda2c7b Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 25 May 2019 10:28:17 +0100 Subject: [PATCH 071/109] Improve the explicit_outlives_requirements lint * Don't use Strings to compare parameters * Extend the lint to lifetime bounds * Extend the lint to enums and unions * Use the correct span for where clauses in tuple structs * Try to early-out where possible --- src/librustc_lint/builtin.rs | 315 ++++-- .../edition-lint-infer-outlives-multispan.rs | 391 +++++++- ...ition-lint-infer-outlives-multispan.stderr | 682 +++++++++++-- .../edition-lint-infer-outlives.fixed | 871 +++++++++++++--- .../rust-2018/edition-lint-infer-outlives.rs | 871 +++++++++++++--- .../edition-lint-infer-outlives.stderr | 926 ++++++++++++++++-- 6 files changed, 3473 insertions(+), 583 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 8ed4a556ea97..353cd1f7d210 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -23,7 +23,7 @@ use rustc::hir::def::{Res, DefKind}; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; -use rustc::ty::{self, Ty}; +use rustc::ty::{self, Ty, TyCtxt}; use rustc::{lint, util}; use hir::Node; use util::nodemap::HirIdSet; @@ -1494,58 +1494,107 @@ impl EarlyLintPass for KeywordIdents { declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMENTS]); impl ExplicitOutlivesRequirements { - fn collect_outlives_bound_spans( - &self, - cx: &LateContext<'_, '_>, - item_def_id: DefId, - param_name: &str, - bounds: &hir::GenericBounds, - infer_static: bool - ) -> Vec<(usize, Span)> { - // For lack of a more elegant strategy for comparing the `ty::Predicate`s - // returned by this query with the params/bounds grabbed from the HIR—and - // with some regrets—we're going to covert the param/lifetime names to - // strings - let inferred_outlives = cx.tcx.inferred_outlives_of(item_def_id); - - let ty_lt_names = inferred_outlives.iter().filter_map(|pred| { - let binder = match pred { - ty::Predicate::TypeOutlives(binder) => binder, - _ => { return None; } - }; - let ty_outlives_pred = binder.skip_binder(); - let ty_name = match ty_outlives_pred.0.sty { - ty::Param(param) => param.name.to_string(), - _ => { return None; } - }; - let lt_name = match ty_outlives_pred.1 { - ty::RegionKind::ReEarlyBound(region) => { - region.name.to_string() - }, - _ => { return None; } - }; - Some((ty_name, lt_name)) - }).collect::>(); - - let mut bound_spans = Vec::new(); - for (i, bound) in bounds.iter().enumerate() { - if let hir::GenericBound::Outlives(lifetime) = bound { - let is_static = match lifetime.name { - hir::LifetimeName::Static => true, - _ => false - }; - if is_static && !infer_static { - // infer-outlives for 'static is still feature-gated (tracking issue #44493) - continue; - } - - let lt_name = &lifetime.name.ident().to_string(); - if ty_lt_names.contains(&(param_name.to_owned(), lt_name.to_owned())) { - bound_spans.push((i, bound.span())); + fn lifetimes_outliving_lifetime<'tcx>( + inferred_outlives: &'tcx [ty::Predicate<'tcx>], + index: u32, + ) -> Vec> { + inferred_outlives.iter().filter_map(|pred| { + match pred { + ty::Predicate::RegionOutlives(outlives) => { + let outlives = outlives.skip_binder(); + match outlives.0 { + ty::ReEarlyBound(ebr) if ebr.index == index => { + Some(outlives.1) + } + _ => None, + } } + _ => None } + }).collect() + } + + fn lifetimes_outliving_type<'tcx>( + inferred_outlives: &'tcx [ty::Predicate<'tcx>], + index: u32, + ) -> Vec> { + inferred_outlives.iter().filter_map(|pred| { + match pred { + ty::Predicate::TypeOutlives(outlives) => { + let outlives = outlives.skip_binder(); + if outlives.0.is_param(index) { + Some(outlives.1) + } else { + None + } + } + _ => None + } + }).collect() + } + + fn collect_outlived_lifetimes<'tcx>( + &self, + param: &'tcx hir::GenericParam, + tcx: TyCtxt<'tcx>, + inferred_outlives: &'tcx [ty::Predicate<'tcx>], + ty_generics: &'tcx ty::Generics, + ) -> Vec> { + let index = ty_generics.param_def_id_to_index[ + &tcx.hir().local_def_id_from_hir_id(param.hir_id)]; + + match param.kind { + hir::GenericParamKind::Lifetime { .. } => { + Self::lifetimes_outliving_lifetime(inferred_outlives, index) + } + hir::GenericParamKind::Type { .. } => { + Self::lifetimes_outliving_type(inferred_outlives, index) + } + hir::GenericParamKind::Const { .. } => Vec::new(), } - bound_spans + } + + + fn collect_outlives_bound_spans<'tcx>( + &self, + tcx: TyCtxt<'tcx>, + bounds: &hir::GenericBounds, + inferred_outlives: &[ty::Region<'tcx>], + infer_static: bool, + ) -> Vec<(usize, Span)> { + use rustc::middle::resolve_lifetime::Region; + + bounds + .iter() + .enumerate() + .filter_map(|(i, bound)| { + if let hir::GenericBound::Outlives(lifetime) = bound { + let is_inferred = match tcx.named_region(lifetime.hir_id) { + Some(Region::Static) if infer_static => { + inferred_outlives.iter() + .any(|r| if let ty::ReStatic = r { true } else { false }) + } + Some(Region::EarlyBound(index, ..)) => inferred_outlives + .iter() + .any(|r| { + if let ty::ReEarlyBound(ebr) = r { + ebr.index == index + } else { + false + } + }), + _ => false, + }; + if is_inferred { + Some((i, bound.span())) + } else { + None + } + } else { + None + } + }) + .collect() } fn consolidate_outlives_bound_spans( @@ -1569,7 +1618,7 @@ impl ExplicitOutlivesRequirements { let mut from_start = true; for (i, bound_span) in bound_spans { match last_merged_i { - // If the first bound is inferable, our span should also eat the trailing `+` + // If the first bound is inferable, our span should also eat the leading `+` None if i == 0 => { merged.push(bound_span.to(bounds[1].span().shrink_to_lo())); last_merged_i = Some(0); @@ -1607,26 +1656,48 @@ impl ExplicitOutlivesRequirements { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { + use rustc::middle::resolve_lifetime::Region; + let infer_static = cx.tcx.features().infer_static_outlives_requirements; let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); - if let hir::ItemKind::Struct(_, ref generics) = item.node { + if let hir::ItemKind::Struct(_, ref hir_generics) + | hir::ItemKind::Enum(_, ref hir_generics) + | hir::ItemKind::Union(_, ref hir_generics) = item.node + { + let inferred_outlives = cx.tcx.inferred_outlives_of(def_id); + if inferred_outlives.is_empty() { + return; + } + + let ty_generics = cx.tcx.generics_of(def_id); + let mut bound_count = 0; let mut lint_spans = Vec::new(); - for param in &generics.params { - let param_name = match param.kind { - hir::GenericParamKind::Lifetime { .. } => continue, - hir::GenericParamKind::Type { .. } => { - match param.name { - hir::ParamName::Fresh(_) => continue, - hir::ParamName::Error => continue, - hir::ParamName::Plain(name) => name.to_string(), - } + for param in &hir_generics.params { + let has_lifetime_bounds = param.bounds.iter().any(|bound| { + if let hir::GenericBound::Outlives(_) = bound { + true + } else { + false } - hir::GenericParamKind::Const { .. } => continue, - }; + }); + if !has_lifetime_bounds { + continue; + } + + let relevant_lifetimes = self.collect_outlived_lifetimes( + param, + cx.tcx, + inferred_outlives, + ty_generics, + ); + if relevant_lifetimes.is_empty() { + continue; + } + let bound_spans = self.collect_outlives_bound_spans( - cx, def_id, ¶m_name, ¶m.bounds, infer_static + cx.tcx, ¶m.bounds, &relevant_lifetimes, infer_static, ); bound_count += bound_spans.len(); lint_spans.extend( @@ -1638,54 +1709,92 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { let mut where_lint_spans = Vec::new(); let mut dropped_predicate_count = 0; - let num_predicates = generics.where_clause.predicates.len(); - for (i, where_predicate) in generics.where_clause.predicates.iter().enumerate() { - if let hir::WherePredicate::BoundPredicate(predicate) = where_predicate { - let param_name = match predicate.bounded_ty.node { - hir::TyKind::Path(ref qpath) => { - if let hir::QPath::Resolved(None, ty_param_path) = qpath { - ty_param_path.segments[0].ident.to_string() - } else { - continue; - } - }, - _ => { continue; } - }; - let bound_spans = self.collect_outlives_bound_spans( - cx, def_id, ¶m_name, &predicate.bounds, infer_static - ); - bound_count += bound_spans.len(); - - let drop_predicate = bound_spans.len() == predicate.bounds.len(); - if drop_predicate { - dropped_predicate_count += 1; - } - - // If all the bounds on a predicate were inferable and there are - // further predicates, we want to eat the trailing comma - if drop_predicate && i + 1 < num_predicates { - let next_predicate_span = generics.where_clause.predicates[i+1].span(); - where_lint_spans.push( - predicate.span.to(next_predicate_span.shrink_to_lo()) - ); - } else { - where_lint_spans.extend( - self.consolidate_outlives_bound_spans( - predicate.span.shrink_to_lo(), + let num_predicates = hir_generics.where_clause.predicates.len(); + for (i, where_predicate) in hir_generics.where_clause.predicates.iter().enumerate() { + let (relevant_lifetimes, bounds, span) = match where_predicate { + hir::WherePredicate::RegionPredicate(predicate) => { + if let Some(Region::EarlyBound(index, ..)) + = cx.tcx.named_region(predicate.lifetime.hir_id) + { + ( + Self::lifetimes_outliving_lifetime(inferred_outlives, index), &predicate.bounds, - bound_spans + predicate.span, ) - ); + } else { + continue; + } } + hir::WherePredicate::BoundPredicate(predicate) => { + // FIXME we can also infer bounds on associated types, + // and should check for them here. + match predicate.bounded_ty.node { + hir::TyKind::Path(hir::QPath::Resolved( + None, + ref path, + )) => if let Res::Def(DefKind::TyParam, def_id) = path.res { + let index = ty_generics.param_def_id_to_index[&def_id]; + ( + Self::lifetimes_outliving_type(inferred_outlives, index), + &predicate.bounds, + predicate.span, + ) + } else { + continue + }, + _ => { continue; } + } + } + _ => continue, + }; + if relevant_lifetimes.is_empty() { + continue; + } + + let bound_spans = self.collect_outlives_bound_spans( + cx.tcx, bounds, &relevant_lifetimes, infer_static, + ); + bound_count += bound_spans.len(); + + let drop_predicate = bound_spans.len() == bounds.len(); + if drop_predicate { + dropped_predicate_count += 1; + } + + // If all the bounds on a predicate were inferable and there are + // further predicates, we want to eat the trailing comma + if drop_predicate && i + 1 < num_predicates { + let next_predicate_span = hir_generics.where_clause.predicates[i+1].span(); + where_lint_spans.push( + span.to(next_predicate_span.shrink_to_lo()) + ); + } else { + where_lint_spans.extend( + self.consolidate_outlives_bound_spans( + span.shrink_to_lo(), + bounds, + bound_spans + ) + ); } } // If all predicates are inferable, drop the entire clause // (including the `where`) if num_predicates > 0 && dropped_predicate_count == num_predicates { - let full_where_span = generics.span.shrink_to_hi() - .to(generics.where_clause.span() - .expect("span of (nonempty) where clause should exist")); + let where_span = hir_generics.where_clause.span() + .expect("span of (nonempty) where clause should exist"); + // Extend the where clause back to the closing `>` of the + // generics, except for tuple struct, which have the `where` + // after the fields of the struct. + let full_where_span = match item.node { + hir::ItemKind::Struct(hir::VariantData::Tuple(..), _) => { + where_span + } + _ => { + hir_generics.span.shrink_to_hi().to(where_span) + } + }; lint_spans.push( full_where_span ); diff --git a/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.rs b/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.rs index ca6abdf5e700..0b3de0df2b88 100644 --- a/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.rs +++ b/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.rs @@ -1,75 +1,368 @@ #![allow(unused)] #![deny(explicit_outlives_requirements)] -use std::fmt::{Debug, Display}; // These examples should live in edition-lint-infer-outlives.rs, but are split // into this separate file because they can't be `rustfix`'d (and thus, can't // be part of a `run-rustfix` test file) until rust-lang-nursery/rustfix#141 // is solved -struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T +mod structs { + use std::fmt::Debug; + + struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + struct BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where 'b: 'a, T: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> + where U: 'a + Debug + 'b, 'b: 'a + //~^ ERROR outlives requirements can be inferred + { + tee: T, + yoo: &'a &'b U + } } -struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { +mod tuple_structs { + use std::fmt::Debug; + + struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T>(&'a &'b T) where T: 'a + Debug + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug>(&'a T, &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b>(&'a T, &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + Debug + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b + Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: Debug + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereAyYooWhereBeeIsDebug<'a, 'b, T, U>(&'a T, &'b U) where T: 'a, U: 'b + Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereAyYooWhereIsDebugBee<'a, 'b, T, U>(&'a T, &'b U) where T: 'a, U: Debug + 'b; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereAyTeeWhereAyIsDebugBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'a + Debug + 'b; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereAyTeeYooWhereAyIsDebugBee<'a, 'b, T, U>(T, &'a &'b U) + where U: 'a + Debug + 'b, 'b: 'a; //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T } -struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U +mod enums { + use std::fmt::Debug; + + enum TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, }, + W(&'a &'b U), + } + + enum TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T, yoo: &'b U }, + W, + } + + enum TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + V(&'a T, &'b U), + W, + } + + enum TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W(&'b U), + } + + enum TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a T, &'b U), + W, + } + + enum TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W(&'b U) + } + + enum TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T, yoo: &'b U }, + W, + } + + enum TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a T, &'b U), + W, + } + + enum BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W, + } + + enum BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where 'b: 'a, T: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a &'b U), + } + + enum BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b, 'b: 'a { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + } } -struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U -} +mod unions { + use std::fmt::Debug; -struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U -} + union TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U -} + union TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U -} + union TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } -struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U -} + union TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } -struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U -} + union TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } -struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: &'b U + union TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } + + union TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + union TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + union TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + union TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: &'b U + } + + union BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + union BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where 'b: 'a, T: 'a + Debug + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + union BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } + + union BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b, 'b: 'a { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } } fn main() {} diff --git a/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.stderr b/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.stderr index 3c65dde01624..e0e846422d3c 100644 --- a/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.stderr +++ b/src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.stderr @@ -1,8 +1,8 @@ error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:11:43 + --> $DIR/edition-lint-infer-outlives-multispan.rs:13:47 | -LL | struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { - | ^^^^^ ^^^^^ +LL | struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { + | ^^^^^ ^^^^^ | note: lint level defined here --> $DIR/edition-lint-infer-outlives-multispan.rs:2:9 @@ -11,108 +11,678 @@ LL | #![deny(explicit_outlives_requirements)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds | -LL | struct TeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { - | -- -- +LL | struct TeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:16:57 + --> $DIR/edition-lint-infer-outlives-multispan.rs:18:61 | -LL | struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { - | ^^^^^ ^^^^^ +LL | struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { + | ^^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { - | -- -- +LL | struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:21:49 + --> $DIR/edition-lint-infer-outlives-multispan.rs:23:53 | -LL | struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { - | ^^^^^ ^^^^^ +LL | struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { + | ^^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { - | -- -- +LL | struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:27:44 + --> $DIR/edition-lint-infer-outlives-multispan.rs:29:48 | -LL | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { - | ^^^^ ^^^^^ +LL | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { + | ^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> { - | -- -- +LL | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:33:44 + --> $DIR/edition-lint-infer-outlives-multispan.rs:35:48 | -LL | struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { - | ^^^^ ^^^^^ +LL | struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { + | ^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T, U: Debug> { - | -- -- +LL | struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:39:42 + --> $DIR/edition-lint-infer-outlives-multispan.rs:41:46 | -LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { - | ^^^^ ^^^^^^^^^^^^ +LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { + | ^^^^ ^^^^^^^^^^^^ help: remove these bounds | -LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U> { - | -- -- +LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U> { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:45:63 + --> $DIR/edition-lint-infer-outlives-multispan.rs:47:67 | -LL | struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { - | ^^^^^ ^^^^^ +LL | struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { + | ^^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug { - | -- -- +LL | struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:51:49 + --> $DIR/edition-lint-infer-outlives-multispan.rs:53:53 | -LL | struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { - | ^^^^ ^^^^^ +LL | struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { + | ^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { - | -- -- +LL | struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:57:49 + --> $DIR/edition-lint-infer-outlives-multispan.rs:59:53 | -LL | struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { - | ^^^^ ^^^^^ +LL | struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { + | ^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { - | -- -- +LL | struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:63:65 + --> $DIR/edition-lint-infer-outlives-multispan.rs:65:69 | -LL | struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { - | ^^^^^^^ ^^^^^ +LL | struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { + | ^^^^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { - | -- -- +LL | struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { + | -- -- error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:69:65 + --> $DIR/edition-lint-infer-outlives-multispan.rs:71:69 | -LL | struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { - | ^^^^^^^ ^^^^^ +LL | struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { + | ^^^^^^^ ^^^^^ help: remove these bounds | -LL | struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { - | -- -- +LL | struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- -error: aborting due to 11 previous errors +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:77:38 + | +LL | struct BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b> { + | ^^^^ ^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeBee<'a, 'b, T> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:82:40 + | +LL | struct BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b> { + | ^^^^ ^^^^^^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeAyBee<'a, 'b, T> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:87:55 + | +LL | struct BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b> { + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:92:68 + | +LL | struct BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where 'b: 'a, T: 'a + Debug + 'b { + | ^^^^^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:97:58 + | +LL | struct BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b> { + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:104:18 + | +LL | where U: 'a + Debug + 'b, 'b: 'a + | ^^^^^ ^^^^^ ^^^^^^ +help: remove these bounds + | +LL | where U: Debug, + | -- ---- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:115:47 + | +LL | struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b>(&'a &'b T); + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeOutlivesAyIsDebugBee<'a, 'b, T: Debug>(&'a &'b T); + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:118:72 + | +LL | struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T>(&'a &'b T) where T: 'a + Debug + 'b; + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T>(&'a &'b T) where T: Debug; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:121:53 + | +LL | struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b>(T, &'a &'b U); + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug>(T, &'a &'b U); + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:124:48 + | +LL | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug>(&'a T, &'b U); + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug>(&'a T, &'b U); + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:127:48 + | +LL | struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b>(&'a T, &'b U); + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T, U: Debug>(&'a T, &'b U); + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:130:46 + | +LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b; + | ^^^^ ^^^^^^^^^^^ +help: remove these bounds + | +LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U>(&'a T, &'b U) ; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:133:81 + | +LL | struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + Debug + 'b; + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U>(T, &'a &'b U) where U: Debug; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:136:53 + | +LL | struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b + Debug; + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U>(&'a T, &'b U) where U: Debug; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:139:53 + | +LL | struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: Debug + 'b; + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U>(&'a T, &'b U) where U: Debug; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:142:75 + | +LL | struct TeeWhereAyYooWhereBeeIsDebug<'a, 'b, T, U>(&'a T, &'b U) where T: 'a, U: 'b + Debug; + | ^^^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeWhereAyYooWhereBeeIsDebug<'a, 'b, T, U>(&'a T, &'b U) where U: Debug; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:145:75 + | +LL | struct TeeWhereAyYooWhereIsDebugBee<'a, 'b, T, U>(&'a T, &'b U) where T: 'a, U: Debug + 'b; + | ^^^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct TeeWhereAyYooWhereIsDebugBee<'a, 'b, T, U>(&'a T, &'b U) where U: Debug; + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:148:38 + | +LL | struct BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b>(&'a &'b T); + | ^^^^ ^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeBee<'a, 'b, T>(&'a &'b T); + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:151:40 + | +LL | struct BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b>(&'a &'b T); + | ^^^^ ^^^^^^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeAyBee<'a, 'b, T>(&'a &'b T); + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:154:55 + | +LL | struct BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b>(&'a &'b T); + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b, T: Debug>(&'a &'b T); + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:157:71 + | +LL | struct BeeWhereAyTeeWhereAyIsDebugBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'a + Debug + 'b; + | ^^^^^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct BeeWhereAyTeeWhereAyIsDebugBee<'a, 'b, T>(&'a &'b T) where T: Debug; + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:160:58 + | +LL | struct BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b>(T, &'a &'b U); + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | struct BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug>(T, &'a &'b U); + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:164:18 + | +LL | where U: 'a + Debug + 'b, 'b: 'a; + | ^^^^^ ^^^^^ ^^^^^^ +help: remove these bounds + | +LL | where U: Debug, ; + | -- ---- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:171:45 + | +LL | enum TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:176:59 + | +LL | enum TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:181:51 + | +LL | enum TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:187:46 + | +LL | enum TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:193:46 + | +LL | enum TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeOutlivesAyYooIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:199:44 + | +LL | enum TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { + | ^^^^ ^^^^^^^^^^^^ +help: remove these bounds + | +LL | enum TeeOutlivesAyYooWhereBee<'a, 'b, T, U> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:205:65 + | +LL | enum TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:211:51 + | +LL | enum TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:217:51 + | +LL | enum TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:223:67 + | +LL | enum TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { + | ^^^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:229:67 + | +LL | enum TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { + | ^^^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:235:36 + | +LL | enum BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b> { + | ^^^^ ^^^^ +help: remove these bounds + | +LL | enum BeeOutlivesAyTeeBee<'a, 'b, T> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:240:38 + | +LL | enum BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b> { + | ^^^^ ^^^^^^^^^ +help: remove these bounds + | +LL | enum BeeOutlivesAyTeeAyBee<'a, 'b, T> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:246:53 + | +LL | enum BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b> { + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:251:66 + | +LL | enum BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where 'b: 'a, T: 'a + Debug + 'b { + | ^^^^^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:256:56 + | +LL | enum BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b> { + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | enum BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:262:75 + | +LL | enum BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b, 'b: 'a { + | ^^^^^ ^^^^^ ^^^^^^ +help: remove these bounds + | +LL | enum BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug, { + | -- ---- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:271:46 + | +LL | union TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:276:60 + | +LL | union TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:281:52 + | +LL | union TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:287:47 + | +LL | union TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:293:47 + | +LL | union TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeOutlivesAyYooIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:299:45 + | +LL | union TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { + | ^^^^ ^^^^^^^^^^^^ +help: remove these bounds + | +LL | union TeeOutlivesAyYooWhereBee<'a, 'b, T, U> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:305:66 + | +LL | union TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { + | ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:311:52 + | +LL | union TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:317:52 + | +LL | union TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { + | ^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:323:68 + | +LL | union TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { + | ^^^^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:329:68 + | +LL | union TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { + | ^^^^^^^ ^^^^^ +help: remove these bounds + | +LL | union TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where U: Debug { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:335:37 + | +LL | union BeeOutlivesAyTeeBee<'a, 'b: 'a, T: 'b> { + | ^^^^ ^^^^ +help: remove these bounds + | +LL | union BeeOutlivesAyTeeBee<'a, 'b, T> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:340:39 + | +LL | union BeeOutlivesAyTeeAyBee<'a, 'b: 'a, T: 'a + 'b> { + | ^^^^ ^^^^^^^^^ +help: remove these bounds + | +LL | union BeeOutlivesAyTeeAyBee<'a, 'b, T> { + | -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:345:54 + | +LL | union BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b: 'a, T: 'a + Debug + 'b> { + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union BeeOutlivesAyTeeOutlivesAyIsDebugBee<'a, 'b, T: Debug> { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:350:67 + | +LL | union BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where 'b: 'a, T: 'a + Debug + 'b { + | ^^^^^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union BeeWhereAyTeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: Debug { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:355:57 + | +LL | union BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b: 'a, T, U: 'a + Debug + 'b> { + | ^^^^ ^^^^^ ^^^^^ +help: remove these bounds + | +LL | union BeeOutlivesAyTeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: Debug> { + | -- -- -- + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives-multispan.rs:361:76 + | +LL | union BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b, 'b: 'a { + | ^^^^^ ^^^^^ ^^^^^^ +help: remove these bounds + | +LL | union BeeWhereAyTeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: Debug, { + | -- ---- + +error: aborting due to 68 previous errors diff --git a/src/test/ui/rust-2018/edition-lint-infer-outlives.fixed b/src/test/ui/rust-2018/edition-lint-infer-outlives.fixed index eb48933dca53..13645244da06 100644 --- a/src/test/ui/rust-2018/edition-lint-infer-outlives.fixed +++ b/src/test/ui/rust-2018/edition-lint-infer-outlives.fixed @@ -3,9 +3,6 @@ #![allow(unused)] #![deny(explicit_outlives_requirements)] -use std::fmt::{Debug, Display}; - - // Programmatically generated examples! // // Exercise outlives bounds for each of the following parameter/position @@ -17,177 +14,773 @@ use std::fmt::{Debug, Display}; // • two parameters (T and U), one bound inline, one with a where clause // • two parameters (T and U), both with where clauses // -// —and for every permutation of 0, 1, or 2 lifetimes to outlive and 0 or 1 -// trait bounds distributed among said parameters (subject to no where clause -// being empty and the struct having at least one lifetime). +// —and for every permutation of 1 or 2 lifetimes to outlive and 0 or 1 trait +// bounds distributed among said parameters (subject to no where clause being +// empty and the struct having at least one lifetime). +// +// —and for each of tuple structs, enums and unions. +mod structs { + use std::fmt::Debug; -struct TeeOutlivesAy<'a, T> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T + struct TeeOutlivesAy<'a, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeOutlivesAyIsDebug<'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeIsDebugOutlivesAy<'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeOutlivesAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereOutlivesAy<'a, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeWhereOutlivesAyIsDebug<'a, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeWhereOutlivesAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeYooOutlivesAy<'a, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooOutlivesAyIsDebug<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeOutlivesAyYooIsDebug<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: U + } + + struct TeeYooOutlivesAyBee<'a, 'b, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: U + } + + struct TeeYooWhereOutlivesAy<'a, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: U + } + + struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: U + } + + struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: U + } + + struct TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: U + } + + struct BeeOutlivesAy<'a, 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + struct BeeWhereOutlivesAy<'a, 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + struct BeeOutlivesAyTee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeOutlivesAyTeeDebug<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } } -struct TeeOutlivesAyIsDebug<'a, T: Debug> { +mod tuple_structs { + use std::fmt::Debug; + + struct TeeOutlivesAy<'a, T>(&'a T); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyIsDebug<'a, T: Debug>(&'a T); + //~^ ERROR outlives requirements can be inferred + + struct TeeIsDebugOutlivesAy<'a, T: Debug>(&'a T); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBee<'a, 'b, T>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: Debug>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAy<'a, T>(&'a T) ; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyIsDebug<'a, T>(&'a T) where T: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) ; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T>(&'a &'b T) where T: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAy<'a, T, U>(T, &'a U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyIsDebug<'a, T, U: Debug>(T, &'a U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug>(T, &'a U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooIsDebug<'a, T, U: Debug>(&'a T, U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: Debug>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug>(&'a &'b T, U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) ; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyIsDebug<'a, T, U>(T, &'a U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereIsDebugOutlivesAy<'a, T, U>(T, &'a U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooWhereIsDebug<'a, T, U>(&'a T, U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) ; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U>(T, &'a &'b U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U>(&'a &'b T, U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U>(&'a T, U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereAyBeeYooWhereIsDebug<'a, 'b, T, U>(&'a &'b T, U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAy<'a, 'b>(&'a &'b ()); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) ; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTee<'a, 'b, T>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) ; + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) ; + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) ; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTeeDebug<'a, 'b, T: Debug>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T>(&'a &'b T) where T: Debug; //~^ ERROR outlives requirements can be inferred - tee: &'a T } -struct TeeIsDebugOutlivesAy<'a, T: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T +mod enums { + use std::fmt::Debug; + + enum TeeOutlivesAy<'a, T> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + } + + enum TeeOutlivesAyIsDebug<'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + V(&'a T), + } + + enum TeeIsDebugOutlivesAy<'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W, + } + + enum TeeOutlivesAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum TeeOutlivesAyBeeIsDebug<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum TeeWhereOutlivesAy<'a, T> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W, + } + + enum TeeWhereOutlivesAyIsDebug<'a, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a T), + W, + } + + enum TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + } + + enum TeeWhereOutlivesAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W, + } + + enum TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum TeeYooOutlivesAy<'a, T, U> { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a U), + } + + enum TeeYooOutlivesAyIsDebug<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a U }, + W, + } + + enum TeeYooIsDebugOutlivesAy<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V(T, &'a U), + W, + } + + enum TeeOutlivesAyYooIsDebug<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W(U), + } + + enum TeeYooOutlivesAyBee<'a, 'b, T, U> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V(T, &'a &'b U), + W, + } + + enum TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T, U), + W, + } + + enum TeeYooWhereOutlivesAy<'a, T, U> { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a U), + } + + enum TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a U }, + W, + } + + enum TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V(T, &'a U), + W, + } + + enum TeeOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W(U), + } + + enum TeeYooWhereOutlivesAyBee<'a, 'b, T, U> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V(T, &'a &'b U), + W, + } + + enum TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a &'b U), + } + + enum TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T, yoo: U }, + W, + } + + enum TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a T, U), + W, + } + + enum TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W(U), + } + + enum BeeOutlivesAy<'a, 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b () }, + } + + enum BeeWhereOutlivesAy<'a, 'b> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b ()), + } + + enum BeeOutlivesAyTee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W, + } + + enum BeeWhereOutlivesAyTee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum BeeOutlivesAyTeeDebug<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } } -struct TeeOutlivesAyBee<'a, 'b, T> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} +mod unions { + use std::fmt::Debug; -struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeOutlivesAy<'a, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeOutlivesAyIsDebug<'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeWhereOutlivesAy<'a, T> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T -} + union TeeIsDebugOutlivesAy<'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeWhereOutlivesAyIsDebug<'a, T> where T: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T -} + union TeeOutlivesAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T -} + union TeeOutlivesAyBeeIsDebug<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeWhereOutlivesAyBee<'a, 'b, T> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeWhereOutlivesAy<'a, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeWhereOutlivesAyIsDebug<'a, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeYooOutlivesAy<'a, T, U> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeYooOutlivesAyIsDebug<'a, T, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeWhereOutlivesAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeOutlivesAyYooIsDebug<'a, T, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: U -} + union TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeYooOutlivesAyBee<'a, 'b, T, U> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooOutlivesAy<'a, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooOutlivesAyIsDebug<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooIsDebugOutlivesAy<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T, - yoo: U -} + union TeeOutlivesAyYooIsDebug<'a, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: *const U + } -struct TeeYooWhereOutlivesAy<'a, T, U> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeYooOutlivesAyBee<'a, 'b, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: U -} + union TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: *const U + } -struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooWhereOutlivesAy<'a, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T, - yoo: U -} + union TeeOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: *const U + } -struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: U -} + union TeeYooWhereOutlivesAyBee<'a, 'b, T, U> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T, - yoo: U + union TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } + + union TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } + + union TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: *const U + } + + union TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: *const U + } + + union TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: *const U + } + + union BeeOutlivesAy<'a, 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + union BeeWhereOutlivesAy<'a, 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + union BeeOutlivesAyTee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeOutlivesAyTeeDebug<'a, 'b, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } } diff --git a/src/test/ui/rust-2018/edition-lint-infer-outlives.rs b/src/test/ui/rust-2018/edition-lint-infer-outlives.rs index fd31341365c6..d9486ba66f8a 100644 --- a/src/test/ui/rust-2018/edition-lint-infer-outlives.rs +++ b/src/test/ui/rust-2018/edition-lint-infer-outlives.rs @@ -3,9 +3,6 @@ #![allow(unused)] #![deny(explicit_outlives_requirements)] -use std::fmt::{Debug, Display}; - - // Programmatically generated examples! // // Exercise outlives bounds for each of the following parameter/position @@ -17,177 +14,773 @@ use std::fmt::{Debug, Display}; // • two parameters (T and U), one bound inline, one with a where clause // • two parameters (T and U), both with where clauses // -// —and for every permutation of 0, 1, or 2 lifetimes to outlive and 0 or 1 -// trait bounds distributed among said parameters (subject to no where clause -// being empty and the struct having at least one lifetime). +// —and for every permutation of 1 or 2 lifetimes to outlive and 0 or 1 trait +// bounds distributed among said parameters (subject to no where clause being +// empty and the struct having at least one lifetime). +// +// —and for each of tuple structs, enums and unions. +mod structs { + use std::fmt::Debug; -struct TeeOutlivesAy<'a, T: 'a> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T + struct TeeOutlivesAy<'a, T: 'a> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereOutlivesAy<'a, T> where T: 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } + + struct TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } + + struct TeeYooOutlivesAy<'a, T, U: 'a> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: U + } + + struct TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: U + } + + struct TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a U + } + + struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: U + } + + struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: T, + yoo: &'a &'b U + } + + struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: U + } + + struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: U + } + + struct TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: U + } + + struct BeeOutlivesAy<'a, 'b: 'a> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + struct BeeWhereOutlivesAy<'a, 'b> where 'b: 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + struct BeeOutlivesAyTee<'a, 'b: 'a, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTee<'a, 'b, T> where 'b: 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> where 'b: 'a, T: 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> where 'b: 'a, T: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + struct BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } } -struct TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { +mod tuple_structs { + use std::fmt::Debug; + + struct TeeOutlivesAy<'a, T: 'a>(&'a T); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyIsDebug<'a, T: 'a + Debug>(&'a T); + //~^ ERROR outlives requirements can be inferred + + struct TeeIsDebugOutlivesAy<'a, T: Debug + 'a>(&'a T); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBee<'a, 'b, T: 'a + 'b>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAy<'a, T>(&'a T) where T: 'a; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyIsDebug<'a, T>(&'a T) where T: 'a + Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug + 'a; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: 'a + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T>(&'a &'b T) where T: 'a + 'b + Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: Debug + 'a + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAy<'a, T, U: 'a>(T, &'a U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug>(T, &'a U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a>(T, &'a U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug>(&'a T, U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b>(T, &'a &'b U); + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug>(&'a &'b T, U); + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) where U: 'a; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyIsDebug<'a, T, U>(T, &'a U) where U: 'a + Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereIsDebugOutlivesAy<'a, T, U>(T, &'a U) where U: Debug + 'a; + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U>(&'a T, U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + 'b + Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: Debug + 'a + 'b; + //~^ ERROR outlives requirements can be inferred + + struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U>(&'a &'b T, U) where U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U>(&'a T, U) where T: 'a, U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct TeeWhereAyBeeYooWhereIsDebug<'a, 'b, T, U>(&'a &'b T, U) where T: 'a + 'b, U: Debug; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAy<'a, 'b: 'a>(&'a &'b ()); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) where 'b: 'a; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTee<'a, 'b: 'a, T>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) where 'b: 'a; + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'b; + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'a + 'b; + //~^ ERROR outlives requirements can be inferred + + struct BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug>(&'a &'b T); + //~^ ERROR outlives requirements can be inferred + + struct BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: Debug; //~^ ERROR outlives requirements can be inferred - tee: &'a T } -struct TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T +mod enums { + use std::fmt::Debug; + + enum TeeOutlivesAy<'a, T: 'a> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + } + + enum TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { + //~^ ERROR outlives requirements can be inferred + V(&'a T), + } + + enum TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W, + } + + enum TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum TeeWhereOutlivesAy<'a, T> where T: 'a { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W, + } + + enum TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a T), + W, + } + + enum TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + } + + enum TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W, + } + + enum TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum TeeYooOutlivesAy<'a, T, U: 'a> { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a U), + } + + enum TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a U }, + W, + } + + enum TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { + //~^ ERROR outlives requirements can be inferred + V(T, &'a U), + W, + } + + enum TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W(U), + } + + enum TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + V(T, &'a &'b U), + W, + } + + enum TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T, U), + W, + } + + enum TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a U), + } + + enum TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a U }, + W, + } + + enum TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { + //~^ ERROR outlives requirements can be inferred + V(T, &'a U), + W, + } + + enum TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a T }, + W(U), + } + + enum TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + V { tee: T, yoo: &'a &'b U }, + W, + } + + enum TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { + //~^ ERROR outlives requirements can be inferred + V(T, &'a &'b U), + W, + } + + enum TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { + //~^ ERROR outlives requirements can be inferred + V { tee: T }, + W(&'a &'b U), + } + + enum TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T, yoo: U }, + W, + } + + enum TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a T, U), + W, + } + + enum TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W(U), + } + + enum BeeOutlivesAy<'a, 'b: 'a> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b () }, + } + + enum BeeWhereOutlivesAy<'a, 'b> where 'b: 'a { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b ()), + } + + enum BeeOutlivesAyTee<'a, 'b: 'a, T> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + W, + } + + enum BeeWhereOutlivesAyTee<'a, 'b, T> where 'b: 'a { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> where 'b: 'a, T: 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } + + enum BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> where 'b: 'a, T: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + W, + } + + enum BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + V { tee: &'a &'b T }, + } + + enum BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { + //~^ ERROR outlives requirements can be inferred + V(&'a &'b T), + } } -struct TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} +mod unions { + use std::fmt::Debug; -struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeOutlivesAy<'a, T: 'a> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeWhereOutlivesAy<'a, T> where T: 'a { - //~^ ERROR outlives requirements can be inferred - tee: &'a T -} + union TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T -} + union TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { - //~^ ERROR outlives requirements can be inferred - tee: &'a T -} + union TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeWhereOutlivesAy<'a, T> where T: 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T -} + union TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeYooOutlivesAy<'a, T, U: 'a> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a T + } -struct TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: U -} + union TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T + } -struct TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooOutlivesAy<'a, T, U: 'a> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T, - yoo: U -} + union TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: *const U + } -struct TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a U -} + union TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: U -} + union TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: *const U + } -struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { - //~^ ERROR outlives requirements can be inferred - tee: T, - yoo: &'a &'b U -} + union TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a U + } -struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T, - yoo: U -} + union TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: *const U + } -struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a T, - yoo: U -} + union TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } -struct TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { - //~^ ERROR outlives requirements can be inferred - tee: &'a &'b T, - yoo: U + union TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } + + union TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: *const T, + yoo: &'a &'b U + } + + union TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: *const U + } + + union TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a T, + yoo: *const U + } + + union TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + yoo: *const U + } + + union BeeOutlivesAy<'a, 'b: 'a> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + union BeeWhereOutlivesAy<'a, 'b> where 'b: 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b (), + } + + union BeeOutlivesAyTee<'a, 'b: 'a, T> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTee<'a, 'b, T> where 'b: 'a { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> where 'b: 'a, T: 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> where 'b: 'a, T: 'a + 'b { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug> { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } + + union BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { + //~^ ERROR outlives requirements can be inferred + tee: &'a &'b T, + } } diff --git a/src/test/ui/rust-2018/edition-lint-infer-outlives.stderr b/src/test/ui/rust-2018/edition-lint-infer-outlives.stderr index 8b957984af58..cddce94254b4 100644 --- a/src/test/ui/rust-2018/edition-lint-infer-outlives.stderr +++ b/src/test/ui/rust-2018/edition-lint-infer-outlives.stderr @@ -1,8 +1,8 @@ error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:25:27 + --> $DIR/edition-lint-infer-outlives.rs:26:31 | -LL | struct TeeOutlivesAy<'a, T: 'a> { - | ^^^^ help: remove this bound +LL | struct TeeOutlivesAy<'a, T: 'a> { + | ^^^^ help: remove this bound | note: lint level defined here --> $DIR/edition-lint-infer-outlives.rs:4:9 @@ -11,178 +11,910 @@ LL | #![deny(explicit_outlives_requirements)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:30:36 + --> $DIR/edition-lint-infer-outlives.rs:31:40 | -LL | struct TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { - | ^^^^^ help: remove this bound +LL | struct TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:35:41 + --> $DIR/edition-lint-infer-outlives.rs:36:45 | -LL | struct TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { - | ^^^^^ help: remove this bound +LL | struct TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:40:34 + --> $DIR/edition-lint-infer-outlives.rs:41:38 | -LL | struct TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { - | ^^^^^^^^^ help: remove these bounds +LL | struct TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { + | ^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:45:43 + --> $DIR/edition-lint-infer-outlives.rs:46:47 | -LL | struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:50:48 + --> $DIR/edition-lint-infer-outlives.rs:51:52 | -LL | struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:55:33 + --> $DIR/edition-lint-infer-outlives.rs:56:37 | -LL | struct TeeWhereOutlivesAy<'a, T> where T: 'a { - | ^^^^^^^^^^^^ help: remove this bound +LL | struct TeeWhereOutlivesAy<'a, T> where T: 'a { + | ^^^^^^^^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:60:50 + --> $DIR/edition-lint-infer-outlives.rs:61:54 | -LL | struct TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { - | ^^^^^ help: remove this bound +LL | struct TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:65:55 + --> $DIR/edition-lint-infer-outlives.rs:66:59 | -LL | struct TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { - | ^^^^^ help: remove this bound +LL | struct TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:70:40 + --> $DIR/edition-lint-infer-outlives.rs:71:44 | -LL | struct TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { - | ^^^^^^^^^^^^^^^^^ help: remove these bounds +LL | struct TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { + | ^^^^^^^^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:75:57 + --> $DIR/edition-lint-infer-outlives.rs:76:61 | -LL | struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:80:62 + --> $DIR/edition-lint-infer-outlives.rs:81:66 | -LL | struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:85:33 + --> $DIR/edition-lint-infer-outlives.rs:86:37 | -LL | struct TeeYooOutlivesAy<'a, T, U: 'a> { - | ^^^^ help: remove this bound - -error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:91:42 - | -LL | struct TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { - | ^^^^^ help: remove this bound - -error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:97:47 - | -LL | struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { - | ^^^^^ help: remove this bound - -error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:103:37 - | -LL | struct TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { +LL | struct TeeYooOutlivesAy<'a, T, U: 'a> { | ^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:109:40 + --> $DIR/edition-lint-infer-outlives.rs:92:46 | -LL | struct TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { - | ^^^^^^^^^ help: remove these bounds +LL | struct TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:115:49 + --> $DIR/edition-lint-infer-outlives.rs:98:51 | -LL | struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:121:54 + --> $DIR/edition-lint-infer-outlives.rs:104:41 | -LL | struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { + | ^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:127:44 + --> $DIR/edition-lint-infer-outlives.rs:110:44 | -LL | struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { +LL | struct TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { | ^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:133:39 + --> $DIR/edition-lint-infer-outlives.rs:116:53 | -LL | struct TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { - | ^^^^^^^^^^^^ help: remove this bound +LL | struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:139:56 + --> $DIR/edition-lint-infer-outlives.rs:122:58 | -LL | struct TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { - | ^^^^^ help: remove this bound +LL | struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:145:61 + --> $DIR/edition-lint-infer-outlives.rs:128:48 | -LL | struct TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { +LL | struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:134:43 + | +LL | struct TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:140:60 + | +LL | struct TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:146:65 + | +LL | struct TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:152:46 + | +LL | struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:158:50 + | +LL | struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { + | ^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:164:67 + | +LL | struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:170:72 + | +LL | struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:176:53 + | +LL | struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:182:62 + | +LL | struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { + | ^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:188:69 + | +LL | struct TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { + | ^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:194:32 + | +LL | struct BeeOutlivesAy<'a, 'b: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:199:38 + | +LL | struct BeeWhereOutlivesAy<'a, 'b> where 'b: 'a { + | ^^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:204:35 + | +LL | struct BeeOutlivesAyTee<'a, 'b: 'a, T> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:209:44 + | +LL | struct BeeWhereOutlivesAyTee<'a, 'b, T> where 'b: 'a { + | ^^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:214:52 + | +LL | struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> where 'b: 'a, T: 'b { + | ^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:219:54 + | +LL | struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> where 'b: 'a, T: 'a + 'b { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:224:40 + | +LL | struct BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:229:61 + | +LL | struct BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { + | ^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:238:31 + | +LL | struct TeeOutlivesAy<'a, T: 'a>(&'a T); + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:241:40 + | +LL | struct TeeOutlivesAyIsDebug<'a, T: 'a + Debug>(&'a T); + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:244:45 + | +LL | struct TeeIsDebugOutlivesAy<'a, T: Debug + 'a>(&'a T); + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:247:38 + | +LL | struct TeeOutlivesAyBee<'a, 'b, T: 'a + 'b>(&'a &'b T); + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:250:47 + | +LL | struct TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug>(&'a &'b T); + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:253:52 + | +LL | struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b>(&'a &'b T); + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:256:45 + | +LL | struct TeeWhereOutlivesAy<'a, T>(&'a T) where T: 'a; + | ^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:259:61 + | +LL | struct TeeWhereOutlivesAyIsDebug<'a, T>(&'a T) where T: 'a + Debug; | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:151:42 + --> $DIR/edition-lint-infer-outlives.rs:262:66 | -LL | struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { - | ^^^^ help: remove this bound +LL | struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug + 'a; + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:157:46 + --> $DIR/edition-lint-infer-outlives.rs:265:56 | -LL | struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { - | ^^^^^^^^^^^^^^^^^ help: remove these bounds +LL | struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: 'a + 'b; + | ^^^^^^^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:163:63 + --> $DIR/edition-lint-infer-outlives.rs:268:72 | -LL | struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T>(&'a &'b T) where T: 'a + 'b + Debug; + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:169:68 + --> $DIR/edition-lint-infer-outlives.rs:271:77 | -LL | struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { - | ^^^^^^^^^^ help: remove these bounds +LL | struct TeeWhereIsDebugOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: Debug + 'a + 'b; + | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:175:49 + --> $DIR/edition-lint-infer-outlives.rs:274:37 | -LL | struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { - | ^^^^^^^^^ help: remove these bounds +LL | struct TeeYooOutlivesAy<'a, T, U: 'a>(T, &'a U); + | ^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:181:58 + --> $DIR/edition-lint-infer-outlives.rs:277:46 | -LL | struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { - | ^^^^^^^ help: remove this bound +LL | struct TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug>(T, &'a U); + | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:187:65 + --> $DIR/edition-lint-infer-outlives.rs:280:51 | -LL | struct TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { - | ^^^^^^^^^^^^ help: remove these bounds +LL | struct TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a>(T, &'a U); + | ^^^^^ help: remove this bound -error: aborting due to 30 previous errors +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:283:41 + | +LL | struct TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug>(&'a T, U); + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:286:44 + | +LL | struct TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b>(T, &'a &'b U); + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:289:53 + | +LL | struct TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug>(T, &'a &'b U); + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:292:58 + | +LL | struct TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b>(T, &'a &'b U); + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:295:48 + | +LL | struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug>(&'a &'b T, U); + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:298:54 + | +LL | struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) where U: 'a; + | ^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:301:70 + | +LL | struct TeeYooWhereOutlivesAyIsDebug<'a, T, U>(T, &'a U) where U: 'a + Debug; + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:304:75 + | +LL | struct TeeYooWhereIsDebugOutlivesAy<'a, T, U>(T, &'a U) where U: Debug + 'a; + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:307:46 + | +LL | struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U>(&'a T, U) where U: Debug; + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:310:65 + | +LL | struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + 'b; + | ^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:313:81 + | +LL | struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + 'b + Debug; + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:316:86 + | +LL | struct TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: Debug + 'a + 'b; + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:319:53 + | +LL | struct TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U>(&'a &'b T, U) where U: Debug; + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:322:72 + | +LL | struct TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U>(&'a T, U) where T: 'a, U: Debug; + | ^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:325:75 + | +LL | struct TeeWhereAyBeeYooWhereIsDebug<'a, 'b, T, U>(&'a &'b T, U) where T: 'a + 'b, U: Debug; + | ^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:328:32 + | +LL | struct BeeOutlivesAy<'a, 'b: 'a>(&'a &'b ()); + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:331:51 + | +LL | struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) where 'b: 'a; + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:334:35 + | +LL | struct BeeOutlivesAyTee<'a, 'b: 'a, T>(&'a &'b T); + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:337:56 + | +LL | struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) where 'b: 'a; + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:340:64 + | +LL | struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'b; + | ^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:343:66 + | +LL | struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'a + 'b; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:346:40 + | +LL | struct BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug>(&'a &'b T); + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:349:72 + | +LL | struct BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: Debug; + | ^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:356:29 + | +LL | enum TeeOutlivesAy<'a, T: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:361:38 + | +LL | enum TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:366:43 + | +LL | enum TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:372:36 + | +LL | enum TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:378:45 + | +LL | enum TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:383:50 + | +LL | enum TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:388:35 + | +LL | enum TeeWhereOutlivesAy<'a, T> where T: 'a { + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:394:52 + | +LL | enum TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:400:57 + | +LL | enum TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:405:42 + | +LL | enum TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { + | ^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:410:59 + | +LL | enum TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:416:64 + | +LL | enum TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:422:35 + | +LL | enum TeeYooOutlivesAy<'a, T, U: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:428:44 + | +LL | enum TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:434:49 + | +LL | enum TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:440:39 + | +LL | enum TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:446:42 + | +LL | enum TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:452:51 + | +LL | enum TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:458:56 + | +LL | enum TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:464:46 + | +LL | enum TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:470:41 + | +LL | enum TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:476:58 + | +LL | enum TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:482:63 + | +LL | enum TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:488:44 + | +LL | enum TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:494:48 + | +LL | enum TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { + | ^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:500:65 + | +LL | enum TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:506:70 + | +LL | enum TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:512:51 + | +LL | enum TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:518:60 + | +LL | enum TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { + | ^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:524:67 + | +LL | enum TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { + | ^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:530:30 + | +LL | enum BeeOutlivesAy<'a, 'b: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:535:36 + | +LL | enum BeeWhereOutlivesAy<'a, 'b> where 'b: 'a { + | ^^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:540:33 + | +LL | enum BeeOutlivesAyTee<'a, 'b: 'a, T> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:546:42 + | +LL | enum BeeWhereOutlivesAyTee<'a, 'b, T> where 'b: 'a { + | ^^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:552:50 + | +LL | enum BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> where 'b: 'a, T: 'b { + | ^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:557:52 + | +LL | enum BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> where 'b: 'a, T: 'a + 'b { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:563:38 + | +LL | enum BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:568:59 + | +LL | enum BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { + | ^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:577:30 + | +LL | union TeeOutlivesAy<'a, T: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:582:39 + | +LL | union TeeOutlivesAyIsDebug<'a, T: 'a + Debug> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:587:44 + | +LL | union TeeIsDebugOutlivesAy<'a, T: Debug + 'a> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:592:37 + | +LL | union TeeOutlivesAyBee<'a, 'b, T: 'a + 'b> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:597:46 + | +LL | union TeeOutlivesAyBeeIsDebug<'a, 'b, T: 'a + 'b + Debug> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:602:51 + | +LL | union TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:607:36 + | +LL | union TeeWhereOutlivesAy<'a, T> where T: 'a { + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:612:53 + | +LL | union TeeWhereOutlivesAyIsDebug<'a, T> where T: 'a + Debug { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:617:58 + | +LL | union TeeWhereIsDebugOutlivesAy<'a, T> where T: Debug + 'a { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:622:43 + | +LL | union TeeWhereOutlivesAyBee<'a, 'b, T> where T: 'a + 'b { + | ^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:627:60 + | +LL | union TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T> where T: 'a + 'b + Debug { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:632:65 + | +LL | union TeeWhereIsDebugOutlivesAyBee<'a, 'b, T> where T: Debug + 'a + 'b { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:637:36 + | +LL | union TeeYooOutlivesAy<'a, T, U: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:643:45 + | +LL | union TeeYooOutlivesAyIsDebug<'a, T, U: 'a + Debug> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:649:50 + | +LL | union TeeYooIsDebugOutlivesAy<'a, T, U: Debug + 'a> { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:655:40 + | +LL | union TeeOutlivesAyYooIsDebug<'a, T: 'a, U: Debug> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:661:43 + | +LL | union TeeYooOutlivesAyBee<'a, 'b, T, U: 'a + 'b> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:667:52 + | +LL | union TeeYooOutlivesAyBeeIsDebug<'a, 'b, T, U: 'a + 'b + Debug> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:673:57 + | +LL | union TeeYooIsDebugOutlivesAyBee<'a, 'b, T, U: Debug + 'a + 'b> { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:679:47 + | +LL | union TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug> { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:685:42 + | +LL | union TeeYooWhereOutlivesAy<'a, T, U> where U: 'a { + | ^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:691:59 + | +LL | union TeeYooWhereOutlivesAyIsDebug<'a, T, U> where U: 'a + Debug { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:697:64 + | +LL | union TeeYooWhereIsDebugOutlivesAy<'a, T, U> where U: Debug + 'a { + | ^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:703:45 + | +LL | union TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U> where U: Debug { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:709:49 + | +LL | union TeeYooWhereOutlivesAyBee<'a, 'b, T, U> where U: 'a + 'b { + | ^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:715:66 + | +LL | union TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U> where U: 'a + 'b + Debug { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:721:71 + | +LL | union TeeYooWhereIsDebugOutlivesAyBee<'a, 'b, T, U> where U: Debug + 'a + 'b { + | ^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:727:52 + | +LL | union TeeOutlivesAyBeeYooWhereIsDebug<'a, 'b, T: 'a + 'b, U> where U: Debug { + | ^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:733:61 + | +LL | union TeeWhereOutlivesAyYooWhereIsDebug<'a, T, U> where T: 'a, U: Debug { + | ^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:739:68 + | +LL | union TeeWhereOutlivesAyBeeYooWhereIsDebug<'a, 'b, T, U> where T: 'a + 'b, U: Debug { + | ^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:745:31 + | +LL | union BeeOutlivesAy<'a, 'b: 'a> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:750:37 + | +LL | union BeeWhereOutlivesAy<'a, 'b> where 'b: 'a { + | ^^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:755:34 + | +LL | union BeeOutlivesAyTee<'a, 'b: 'a, T> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:760:43 + | +LL | union BeeWhereOutlivesAyTee<'a, 'b, T> where 'b: 'a { + | ^^^^^^^^^^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:765:51 + | +LL | union BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T> where 'b: 'a, T: 'b { + | ^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:770:53 + | +LL | union BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T> where 'b: 'a, T: 'a + 'b { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:775:39 + | +LL | union BeeOutlivesAyTeeDebug<'a, 'b: 'a, T: Debug> { + | ^^^^ help: remove this bound + +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:780:60 + | +LL | union BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { + | ^^^^^^^^ help: remove this bound + +error: aborting due to 152 previous errors From fdeb58151370c1a65fa1ff23e7d4b304fca01d2a Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 31 May 2019 21:31:03 +0100 Subject: [PATCH 072/109] Address review comments --- src/librustc_lint/builtin.rs | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 353cd1f7d210..1a4b12b03d83 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1618,7 +1618,7 @@ impl ExplicitOutlivesRequirements { let mut from_start = true; for (i, bound_span) in bound_spans { match last_merged_i { - // If the first bound is inferable, our span should also eat the leading `+` + // If the first bound is inferable, our span should also eat the leading `+`. None if i == 0 => { merged.push(bound_span.to(bounds[1].span().shrink_to_lo())); last_merged_i = Some(0); @@ -1732,15 +1732,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { hir::TyKind::Path(hir::QPath::Resolved( None, ref path, - )) => if let Res::Def(DefKind::TyParam, def_id) = path.res { - let index = ty_generics.param_def_id_to_index[&def_id]; - ( - Self::lifetimes_outliving_type(inferred_outlives, index), - &predicate.bounds, - predicate.span, - ) - } else { - continue + )) => { + if let Res::Def(DefKind::TyParam, def_id) = path.res { + let index = ty_generics.param_def_id_to_index[&def_id]; + ( + Self::lifetimes_outliving_type(inferred_outlives, index), + &predicate.bounds, + predicate.span, + ) + } else { + continue; + } }, _ => { continue; } } @@ -1762,9 +1764,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { } // If all the bounds on a predicate were inferable and there are - // further predicates, we want to eat the trailing comma + // further predicates, we want to eat the trailing comma. if drop_predicate && i + 1 < num_predicates { - let next_predicate_span = hir_generics.where_clause.predicates[i+1].span(); + let next_predicate_span = hir_generics.where_clause.predicates[i + 1].span(); where_lint_spans.push( span.to(next_predicate_span.shrink_to_lo()) ); @@ -1787,13 +1789,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { // Extend the where clause back to the closing `>` of the // generics, except for tuple struct, which have the `where` // after the fields of the struct. - let full_where_span = match item.node { - hir::ItemKind::Struct(hir::VariantData::Tuple(..), _) => { - where_span - } - _ => { - hir_generics.span.shrink_to_hi().to(where_span) - } + let full_where_span = if let hir::ItemKind::Struct(hir::VariantData::Tuple(..), _) + = item.node + { + where_span + } else { + hir_generics.span.shrink_to_hi().to(where_span) }; lint_spans.push( full_where_span From d67db0042c1f4e163292ea59bdfac546c67f7001 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 18 Jun 2019 14:34:51 -0700 Subject: [PATCH 073/109] Preserve generator and yield source for error messages Previously, error messages after HIR lowering all referred to generators and yield, regardless of whether the original source was a generator or an async/await body. This change tracks the kind of each generator and yield source in order to provide appropriately tailored error messages. --- src/librustc/cfg/construct.rs | 2 +- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/lowering.rs | 148 ++++++++++-------- src/librustc/hir/mod.rs | 72 +++++++-- src/librustc/hir/print.rs | 2 +- src/librustc/ich/impls_hir.rs | 10 +- .../infer/error_reporting/need_type_info.rs | 9 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/region.rs | 29 +++- src/librustc_mir/build/mod.rs | 4 +- src/librustc_mir/hair/cx/expr.rs | 2 +- src/librustc_passes/rvalue_promotion.rs | 2 +- src/librustc_typeck/check/expr.rs | 2 +- .../check/generator_interior.rs | 41 +++-- src/librustc_typeck/check/mod.rs | 12 +- .../ui/async-await/unresolved_type_param.rs | 4 +- .../async-await/unresolved_type_param.stderr | 4 +- 18 files changed, 221 insertions(+), 128 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 139c144fbcf4..ffbdc0373f80 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -330,7 +330,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { hir::ExprKind::DropTemps(ref e) | hir::ExprKind::Unary(_, ref e) | hir::ExprKind::Field(ref e, _) | - hir::ExprKind::Yield(ref e) | + hir::ExprKind::Yield(ref e, _) | hir::ExprKind::Repeat(ref e, _) => { self.straightline(expr, pred, Some(&**e).into_iter()) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index f4f9d6261de4..0ab6f7bc46a8 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -1089,7 +1089,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_expr(expr) } } - ExprKind::Yield(ref subexpression) => { + ExprKind::Yield(ref subexpression, _) => { visitor.visit_expr(subexpression); } ExprKind::Lit(_) | ExprKind::Err => {} diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 5a548ce8d9ff..d25f3ed5c89a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -95,8 +95,7 @@ pub struct LoweringContext<'a> { modules: BTreeMap, - is_generator: bool, - is_async_body: bool, + generator_kind: Option, /// Used to get the current `fn`'s def span to point to when using `await` /// outside of an `async fn`. @@ -261,8 +260,7 @@ pub fn lower_crate( current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)], item_local_id_counters: Default::default(), node_id_to_hir_id: IndexVec::new(), - is_generator: false, - is_async_body: false, + generator_kind: None, current_item: None, lifetimes_to_define: Vec::new(), is_collecting_in_band_lifetimes: false, @@ -790,18 +788,49 @@ impl<'a> LoweringContext<'a> { }) } - fn record_body(&mut self, arguments: HirVec, value: hir::Expr) -> hir::BodyId { - if self.is_generator && self.is_async_body { - span_err!( - self.sess, - value.span, - E0727, - "`async` generators are not yet supported", - ); - self.sess.abort_if_errors(); + fn generator_movability_for_fn( + &mut self, + decl: &ast::FnDecl, + fn_decl_span: Span, + generator_kind: Option, + movability: Movability, + ) -> Option { + match generator_kind { + Some(hir::GeneratorKind::Gen) => { + if !decl.inputs.is_empty() { + span_err!( + self.sess, + fn_decl_span, + E0628, + "generators cannot have explicit arguments" + ); + self.sess.abort_if_errors(); + } + Some(match movability { + Movability::Movable => hir::GeneratorMovability::Movable, + Movability::Static => hir::GeneratorMovability::Static, + }) + }, + Some(hir::GeneratorKind::Async) => { + bug!("non-`async` closure body turned `async` during lowering"); + }, + None => { + if movability == Movability::Static { + span_err!( + self.sess, + fn_decl_span, + E0697, + "closures cannot be static" + ); + } + None + }, } + } + + fn record_body(&mut self, arguments: HirVec, value: hir::Expr) -> hir::BodyId { let body = hir::Body { - is_generator: self.is_generator || self.is_async_body, + generator_kind: self.generator_kind, arguments, value, }; @@ -1142,7 +1171,7 @@ impl<'a> LoweringContext<'a> { }; let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None); let body_id = self.lower_fn_body(&ast_decl, |this| { - this.is_async_body = true; + this.generator_kind = Some(hir::GeneratorKind::Async); body(this) }); let generator = hir::Expr { @@ -1167,12 +1196,10 @@ impl<'a> LoweringContext<'a> { &mut self, f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec, hir::Expr), ) -> hir::BodyId { - let prev_is_generator = mem::replace(&mut self.is_generator, false); - let prev_is_async_body = mem::replace(&mut self.is_async_body, false); + let prev_gen_kind = self.generator_kind.take(); let (arguments, result) = f(self); let body_id = self.record_body(arguments, result); - self.is_generator = prev_is_generator; - self.is_async_body = prev_is_async_body; + self.generator_kind = prev_gen_kind; body_id } @@ -4475,37 +4502,18 @@ impl<'a> LoweringContext<'a> { self.with_new_scopes(|this| { this.current_item = Some(fn_decl_span); - let mut is_generator = false; + let mut generator_kind = None; let body_id = this.lower_fn_body(decl, |this| { let e = this.lower_expr(body); - is_generator = this.is_generator; + generator_kind = this.generator_kind; e }); - let generator_option = if is_generator { - if !decl.inputs.is_empty() { - span_err!( - this.sess, - fn_decl_span, - E0628, - "generators cannot have explicit arguments" - ); - this.sess.abort_if_errors(); - } - Some(match movability { - Movability::Movable => hir::GeneratorMovability::Movable, - Movability::Static => hir::GeneratorMovability::Static, - }) - } else { - if movability == Movability::Static { - span_err!( - this.sess, - fn_decl_span, - E0697, - "closures cannot be static" - ); - } - None - }; + let generator_option = this.generator_movability_for_fn( + &decl, + fn_decl_span, + generator_kind, + movability, + ); hir::ExprKind::Closure( this.lower_capture_clause(capture_clause), fn_decl, @@ -4677,12 +4685,26 @@ impl<'a> LoweringContext<'a> { } ExprKind::Yield(ref opt_expr) => { - self.is_generator = true; + match self.generator_kind { + Some(hir::GeneratorKind::Gen) => {}, + Some(hir::GeneratorKind::Async) => { + span_err!( + self.sess, + e.span, + E0727, + "`async` generators are not yet supported", + ); + self.sess.abort_if_errors(); + }, + None => { + self.generator_kind = Some(hir::GeneratorKind::Gen); + } + } let expr = opt_expr .as_ref() .map(|x| self.lower_expr(x)) .unwrap_or_else(|| self.expr_unit(e.span)); - hir::ExprKind::Yield(P(expr)) + hir::ExprKind::Yield(P(expr), hir::YieldSource::Yield) } ExprKind::Err => hir::ExprKind::Err, @@ -5754,19 +5776,23 @@ impl<'a> LoweringContext<'a> { // yield (); // } // } - if !self.is_async_body { - let mut err = struct_span_err!( - self.sess, - await_span, - E0728, - "`await` is only allowed inside `async` functions and blocks" - ); - err.span_label(await_span, "only allowed inside `async` functions and blocks"); - if let Some(item_sp) = self.current_item { - err.span_label(item_sp, "this is not `async`"); + match self.generator_kind { + Some(hir::GeneratorKind::Async) => {}, + Some(hir::GeneratorKind::Gen) | + None => { + let mut err = struct_span_err!( + self.sess, + await_span, + E0728, + "`await` is only allowed inside `async` functions and blocks" + ); + err.span_label(await_span, "only allowed inside `async` functions and blocks"); + if let Some(item_sp) = self.current_item { + err.span_label(item_sp, "this is not `async`"); + } + err.emit(); + return hir::ExprKind::Err; } - err.emit(); - return hir::ExprKind::Err; } let span = self.mark_span_with_reason( CompilerDesugaringKind::Await, @@ -5864,7 +5890,7 @@ impl<'a> LoweringContext<'a> { let unit = self.expr_unit(span); let yield_expr = P(self.expr( span, - hir::ExprKind::Yield(P(unit)), + hir::ExprKind::Yield(P(unit), hir::YieldSource::Await), ThinVec::new(), )); self.stmt(span, hir::StmtKind::Expr(yield_expr)) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6ace4c4174b5..d570d34ec4e0 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1306,7 +1306,7 @@ pub struct BodyId { /// /// - an `arguments` array containing the `(x, y)` pattern /// - a `value` containing the `x + y` expression (maybe wrapped in a block) -/// - `is_generator` would be false +/// - `generator_kind` would be `None` /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. @@ -1314,7 +1314,7 @@ pub struct BodyId { pub struct Body { pub arguments: HirVec, pub value: Expr, - pub is_generator: bool, + pub generator_kind: Option, } impl Body { @@ -1325,6 +1325,26 @@ impl Body { } } +/// The type of source expression that caused this generator to be created. +// Not `IsAsync` because we want to eventually add support for `AsyncGen` +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, + RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +pub enum GeneratorKind { + /// An `async` block or function. + Async, + /// A generator literal created via a `yield` inside a closure. + Gen, +} + +impl fmt::Display for GeneratorKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + GeneratorKind::Async => "`async` object", + GeneratorKind::Gen => "generator", + }) + } +} + #[derive(Copy, Clone, Debug)] pub enum BodyOwnerKind { /// Functions and methods. @@ -1531,8 +1551,8 @@ pub enum ExprKind { /// /// The final span is the span of the argument block `|...|`. /// - /// This may also be a generator literal, indicated by the final boolean, - /// in that case there is an `GeneratorClause`. + /// This may also be a generator literal or an `async block` as indicated by the + /// `Option`. Closure(CaptureClause, P, BodyId, Span, Option), /// A block (e.g., `'label: { ... }`). Block(P, Option

(_: P, _: ()) {} + +fn f3<'a>(x: &'a ((), &'a mut ())) { + f2(|| x.0, f1(x.1)) +//~^ ERROR cannot borrow `*x.1` as mutable, as it is behind a `&` reference +//~| ERROR cannot borrow `*x.1` as mutable because it is also borrowed as immutable +} + +fn main() {} diff --git a/src/test/ui/issues/issue-61623.stderr b/src/test/ui/issues/issue-61623.stderr new file mode 100644 index 000000000000..883a1c441d6b --- /dev/null +++ b/src/test/ui/issues/issue-61623.stderr @@ -0,0 +1,22 @@ +error[E0596]: cannot borrow `*x.1` as mutable, as it is behind a `&` reference + --> $DIR/issue-61623.rs:6:19 + | +LL | fn f3<'a>(x: &'a ((), &'a mut ())) { + | -------------------- help: consider changing this to be a mutable reference: `&'a mut ((), &'a mut ())` +LL | f2(|| x.0, f1(x.1)) + | ^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + +error[E0502]: cannot borrow `*x.1` as mutable because it is also borrowed as immutable + --> $DIR/issue-61623.rs:6:19 + | +LL | f2(|| x.0, f1(x.1)) + | -- -- - ^^^ mutable borrow occurs here + | | | | + | | | first borrow occurs due to use of `x` in closure + | | immutable borrow occurs here + | immutable borrow later used by call + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0502, E0596. +For more information about an error, try `rustc --explain E0502`. From 8b21b075f73c629c25e8225c78a2992aa6e1d874 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 19 Jun 2019 09:21:44 +0200 Subject: [PATCH 075/109] Add functions to build raw slices --- src/libcore/ptr/mod.rs | 47 ++++++++++++++++++++++++++++++++++++++++ src/libcore/slice/mod.rs | 19 +++------------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 8f026a5b7d8d..ba88fde6ebc9 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -230,6 +230,53 @@ pub const fn null() -> *const T { 0 as *const T } #[rustc_promotable] pub const fn null_mut() -> *mut T { 0 as *mut T } +#[repr(C)] +pub(crate) union Repr { + pub(crate) rust: *const [T], + rust_mut: *mut [T], + pub(crate) raw: FatPtr, +} + +#[repr(C)] +pub(crate) struct FatPtr { + data: *const T, + pub(crate) len: usize, +} + +/// Forms a slice from a pointer and a length. +/// +/// The `len` argument is the number of **elements**, not the number of bytes. +/// +/// # Examples +/// +/// ```rust +/// #![feature(slice_from_raw_parts)] +/// use std::ptr; +/// +/// // create a slice pointer when starting out with a pointer to the first element +/// let mut x = [5, 6, 7]; +/// let ptr = &mut x[0] as *mut _; +/// let slice = ptr::slice_from_raw_parts_mut(ptr, 3); +/// assert_eq!(unsafe { &*slice }[2], 7); +/// ``` +#[inline] +#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")] +pub fn slice_from_raw_parts(data: *const T, len: usize) -> *const [T] { + unsafe { Repr { raw: FatPtr { data, len } }.rust } +} + +/// Performs the same functionality as [`from_raw_parts`], except that a +/// mutable slice is returned. +/// +/// See the documentation of [`from_raw_parts`] for more details. +/// +/// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html +#[inline] +#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")] +pub fn slice_from_raw_parts_mut(data: *mut T, len: usize) -> *mut [T] { + unsafe { Repr { raw: FatPtr { data, len } }.rust_mut } +} + /// Swaps the values at two mutable locations of the same type, without /// deinitializing either. /// diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index b2376cdf9fa7..af1b20a4c10c 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -45,19 +45,6 @@ pub mod memchr; mod rotate; mod sort; -#[repr(C)] -union Repr<'a, T: 'a> { - rust: &'a [T], - rust_mut: &'a mut [T], - raw: FatPtr, -} - -#[repr(C)] -struct FatPtr { - data: *const T, - len: usize, -} - // // Extension traits // @@ -78,7 +65,7 @@ impl [T] { #[rustc_const_unstable(feature = "const_slice_len")] pub const fn len(&self) -> usize { unsafe { - Repr { rust: self }.raw.len + crate::ptr::Repr { rust: self }.raw.len } } @@ -5195,7 +5182,7 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] { debug_assert!(data as usize % mem::align_of::() == 0, "attempt to create unaligned slice"); debug_assert!(mem::size_of::().saturating_mul(len) <= isize::MAX as usize, "attempt to create slice covering half the address space"); - Repr { raw: FatPtr { data, len } }.rust + &*ptr::slice_from_raw_parts(data, len) } /// Performs the same functionality as [`from_raw_parts`], except that a @@ -5216,7 +5203,7 @@ pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] debug_assert!(data as usize % mem::align_of::() == 0, "attempt to create unaligned slice"); debug_assert!(mem::size_of::().saturating_mul(len) <= isize::MAX as usize, "attempt to create slice covering half the address space"); - Repr { raw: FatPtr { data, len } }.rust_mut + &mut *ptr::slice_from_raw_parts_mut(data, len) } /// Converts a reference to T into a slice of length 1 (without copying). From 8d5728a7c8e77c01708ac6b829cd77ef62c32eaa Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 5 Feb 2019 20:44:59 +0100 Subject: [PATCH 076/109] Fixmes and style fixes --- src/librustc_mir/interpret/eval_context.rs | 3 +++ src/librustc_mir/interpret/validity.rs | 1 + src/librustc_mir/interpret/visitor.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index b01826c98db0..908906623cd9 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -641,6 +641,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { &self, gid: GlobalId<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { + // FIXME(oli-obk): make this check an assertion that it's not a static here + // FIXME(RalfJ, oli-obk): document that `Place::Static` can never be anything but a static + // and `ConstValue::Unevaluated` can never be a static let param_env = if self.tcx.is_static(gid.instance.def_id()) { ty::ParamEnv::reveal_all() } else { diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 3460c21b52d0..cad0b3e0012f 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -396,6 +396,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> if let Some(ref mut ref_tracking) = self.ref_tracking { assert!(self.const_mode, "We should only do recursie checking in const mode"); let place = self.ecx.ref_to_mplace(value)?; + // FIXME(RalfJ): check ZST for inbound pointers if size != Size::ZERO { // Non-ZST also have to be dereferencable let ptr = try_validation!(place.ptr.to_ptr(), diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index 9150f16526ba..d04dc3ab37ed 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -81,6 +81,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M:: ecx.operand_field(self, field) } } + impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx, M::PointerTag> { #[inline(always)] fn layout(&self) -> TyLayout<'tcx> { From 4b6f3868b3e1bdb5193cc240664f046bc18ca6a4 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sun, 10 Feb 2019 14:59:13 +0100 Subject: [PATCH 077/109] Make interning explicitly care about types and the mutability of memory --- src/librustc_mir/const_eval.rs | 97 +++--- src/librustc_mir/interpret/eval_context.rs | 1 - src/librustc_mir/interpret/intern.rs | 326 ++++++++++++++++++ src/librustc_mir/interpret/memory.rs | 78 +---- src/librustc_mir/interpret/mod.rs | 3 + src/librustc_mir/interpret/operand.rs | 27 +- src/librustc_mir/interpret/place.rs | 12 +- src/librustc_mir/interpret/validity.rs | 89 +++-- src/librustc_mir/transform/const_prop.rs | 7 +- src/librustc_mir/transform/qualify_consts.rs | 42 +-- .../miri_unleashed/mutable_references.rs | 35 ++ .../miri_unleashed/mutable_references.stderr | 26 ++ .../miri_unleashed/mutable_references_ice.rs | 28 ++ .../mutable_references_ice.stderr | 21 ++ src/test/ui/consts/packed_pattern.rs | 19 + .../ui/consts/static-raw-pointer-interning.rs | 15 + .../consts/static-raw-pointer-interning2.rs | 15 + src/test/ui/consts/union_constant.rs | 1 + 18 files changed, 669 insertions(+), 173 deletions(-) create mode 100644 src/librustc_mir/interpret/intern.rs create mode 100644 src/test/ui/consts/miri_unleashed/mutable_references.rs create mode 100644 src/test/ui/consts/miri_unleashed/mutable_references.stderr create mode 100644 src/test/ui/consts/miri_unleashed/mutable_references_ice.rs create mode 100644 src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr create mode 100644 src/test/ui/consts/packed_pattern.rs create mode 100644 src/test/ui/consts/static-raw-pointer-interning.rs create mode 100644 src/test/ui/consts/static-raw-pointer-interning2.rs diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 7d05e7be26eb..31541842e215 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -9,7 +9,7 @@ use std::convert::TryInto; use rustc::hir::def::DefKind; use rustc::hir::def_id::DefId; -use rustc::mir::interpret::{ConstEvalErr, ErrorHandled}; +use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef}; use rustc::mir; use rustc::ty::{self, TyCtxt, query::TyCtxtAt}; use rustc::ty::layout::{self, LayoutOf, VariantIdx}; @@ -18,15 +18,14 @@ use rustc::traits::Reveal; use rustc::util::common::ErrorReported; use rustc_data_structures::fx::FxHashMap; -use syntax::ast::Mutability; use syntax::source_map::{Span, DUMMY_SP}; use crate::interpret::{self, - PlaceTy, MPlaceTy, MemPlace, OpTy, ImmTy, Immediate, Scalar, + PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar, RawConst, ConstValue, InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpretCx, StackPopCleanup, Allocation, AllocId, MemoryKind, - snapshot, RefTracking, + snapshot, RefTracking, intern_const_alloc_recursive, }; /// Number of steps until the detector even starts doing anything. @@ -63,33 +62,19 @@ pub(crate) fn eval_promoted<'mir, 'tcx>( eval_body_using_ecx(&mut ecx, cid, body, param_env) } -fn mplace_to_const<'tcx>( - ecx: &CompileTimeEvalContext<'_, 'tcx>, - mplace: MPlaceTy<'tcx>, -) -> &'tcx ty::Const<'tcx> { - let MemPlace { ptr, align, meta } = *mplace; - // extract alloc-offset pair - assert!(meta.is_none()); - let ptr = ptr.to_ptr().unwrap(); - let alloc = ecx.memory.get(ptr.alloc_id).unwrap(); - assert!(alloc.align >= align); - assert!(alloc.bytes.len() as u64 - ptr.offset.bytes() >= mplace.layout.size.bytes()); - let mut alloc = alloc.clone(); - alloc.align = align; - // FIXME shouldn't it be the case that `mark_static_initialized` has already - // interned this? I thought that is the entire point of that `FinishStatic` stuff? - let alloc = ecx.tcx.intern_const_alloc(alloc); - let val = ConstValue::ByRef(ptr, alloc); - ecx.tcx.mk_const(ty::Const { val, ty: mplace.layout.ty }) -} - fn op_to_const<'tcx>( ecx: &CompileTimeEvalContext<'_, 'tcx>, op: OpTy<'tcx>, ) -> &'tcx ty::Const<'tcx> { - // We do not normalize just any data. Only non-union scalars and slices. - let normalize = match op.layout.abi { - layout::Abi::Scalar(..) => op.layout.ty.ty_adt_def().map_or(true, |adt| !adt.is_union()), + // We do not have value optmizations for everything. + // Only scalars and slices, since they are very common. + // Note that further down we turn scalars of undefined bits back to `ByRef`. These can result + // from scalar unions that are initialized with one of their zero sized variants. We could + // instead allow `ConstValue::Scalar` to store `ScalarMaybeUndef`, but that would affect all + // the usual cases of extracting e.g. a `usize`, without there being a real use case for the + // `Undef` situation. + let try_as_immediate = match op.layout.abi { + layout::Abi::Scalar(..) => true, layout::Abi::ScalarPair(..) => match op.layout.ty.sty { ty::Ref(_, inner, _) => match inner.sty { ty::Slice(elem) => elem == ecx.tcx.types.u8, @@ -100,16 +85,38 @@ fn op_to_const<'tcx>( }, _ => false, }; - let normalized_op = if normalize { - Err(*ecx.read_immediate(op).expect("normalization works on validated constants")) + let immediate = if try_as_immediate { + Err(ecx.read_immediate(op).expect("normalization works on validated constants")) } else { + // It is guaranteed that any non-slice scalar pair is actually ByRef here. + // When we come back from raw const eval, we are always by-ref. The only way our op here is + // by-val is if we are in const_field, i.e., if this is (a field of) something that we + // "tried to make immediate" before. We wouldn't do that for non-slice scalar pairs or + // structs containing such. op.try_as_mplace() }; - let val = match normalized_op { - Ok(mplace) => return mplace_to_const(ecx, mplace), - Err(Immediate::Scalar(x)) => - ConstValue::Scalar(x.not_undef().unwrap()), - Err(Immediate::ScalarPair(a, b)) => { + let val = match immediate { + Ok(mplace) => { + let ptr = mplace.ptr.to_ptr().unwrap(); + let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); + ConstValue::ByRef(ptr, alloc) + }, + // see comment on `let try_as_immediate` above + Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x { + ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s), + ScalarMaybeUndef::Undef => { + // When coming out of "normal CTFE", we'll always have an `Indirect` operand as + // argument and we will not need this. The only way we can already have an + // `Immediate` is when we are called from `const_field`, and that `Immediate` + // comes from a constant so it can happen have `Undef`, because the indirect + // memory that was read had undefined bytes. + let mplace = op.to_mem_place(); + let ptr = mplace.ptr.to_ptr().unwrap(); + let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); + ConstValue::ByRef(ptr, alloc) + }, + }, + Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => { let (data, start) = match a.not_undef().unwrap() { Scalar::Ptr(ptr) => ( ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id), @@ -164,13 +171,12 @@ fn eval_body_using_ecx<'mir, 'tcx>( ecx.run()?; // Intern the result - let mutability = if tcx.is_mutable_static(cid.instance.def_id()) || - !layout.ty.is_freeze(tcx, param_env, body.span) { - Mutability::Mutable - } else { - Mutability::Immutable - }; - ecx.memory.intern_static(ret.ptr.to_ptr()?.alloc_id, mutability)?; + intern_const_alloc_recursive( + ecx, + cid.instance.def_id(), + ret, + param_env, + )?; debug!("eval_body_using_ecx done: {:?}", *ret); Ok(ret) @@ -297,7 +303,7 @@ impl interpret::AllocMap for FxHashMap { } } -type CompileTimeEvalContext<'mir, 'tcx> = +crate type CompileTimeEvalContext<'mir, 'tcx> = InterpretCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>; impl interpret::MayLeak for ! { @@ -526,13 +532,16 @@ fn validate_and_turn_into_const<'tcx>( mplace.into(), path, Some(&mut ref_tracking), - true, // const mode )?; } // Now that we validated, turn this into a proper constant. let def_id = cid.instance.def.def_id(); if tcx.is_static(def_id) || cid.promoted.is_some() { - Ok(mplace_to_const(&ecx, mplace)) + let ptr = mplace.ptr.to_ptr()?; + Ok(tcx.mk_const(ty::Const { + val: ConstValue::ByRef(ptr, ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id)), + ty: mplace.layout.ty, + })) } else { Ok(op_to_const(&ecx, mplace.into())) } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 908906623cd9..4afa4a0cbb3d 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -576,7 +576,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { self.place_to_op(return_place)?, vec![], None, - /*const_mode*/false, )?; } } else { diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs new file mode 100644 index 000000000000..47dcde95ca55 --- /dev/null +++ b/src/librustc_mir/interpret/intern.rs @@ -0,0 +1,326 @@ +//! This module specifies the type based interner for constants. +//! +//! After a const evaluation has computed a value, before we destroy the const evaluator's session +//! memory, we need to extract all memory allocations to the global memory pool so they stay around. + +use rustc::ty::layout::LayoutOf; +use rustc::ty::{Ty, TyCtxt, ParamEnv, self}; +use rustc::mir::interpret::{ + EvalResult, ErrorHandled, +}; +use rustc::hir; +use rustc::hir::def_id::DefId; +use super::validity::RefTracking; +use rustc_data_structures::fx::FxHashSet; + +use syntax::ast::Mutability; +use syntax_pos::Span; + +use super::{ + ValueVisitor, MemoryKind, Pointer, AllocId, MPlaceTy, InterpError, Scalar, +}; +use crate::const_eval::{CompileTimeInterpreter, CompileTimeEvalContext}; + +struct InternVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir> { + /// previously encountered safe references + ref_tracking: &'rt mut RefTracking<(MPlaceTy<'tcx>, Mutability, InternMode)>, + ecx: &'rt mut CompileTimeEvalContext<'a, 'mir, 'tcx>, + param_env: ParamEnv<'tcx>, + /// The root node of the value that we're looking at. This field is never mutated and only used + /// for sanity assertions that will ICE when `const_qualif` screws up. + mode: InternMode, + /// This field stores the mutability of the value *currently* being checked. + /// It is set to mutable when an `UnsafeCell` is encountered + /// When recursing across a reference, we don't recurse but store the + /// value to be checked in `ref_tracking` together with the mutability at which we are checking + /// the value. + /// When encountering an immutable reference, we treat everything as immutable that is behind + /// it. + mutability: Mutability, + /// A list of all encountered relocations. After type-based interning, we traverse this list to + /// also intern allocations that are only referenced by a raw pointer or inside a union. + leftover_relocations: &'rt mut FxHashSet, +} + +#[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)] +enum InternMode { + /// Mutable references don't change the `mutability` field to `Immutable` + StaticMut, + /// Mutable references must in fact be immutable due to their surrounding immutability + Static, + /// UnsafeCell is OK in the value of a constant, but not behind references in a constant + ConstBase, + /// `UnsafeCell` ICEs + Const, +} + +/// Signalling data structure to ensure we don't recurse +/// into the memory of other constants or statics +struct IsStaticOrFn; + +impl<'rt, 'a, 'mir, 'tcx> InternVisitor<'rt, 'a, 'mir, 'tcx> { + fn intern( + &mut self, + ptr: Pointer, + mutability: Mutability, + ) -> EvalResult<'tcx, Option> { + trace!( + "InternVisitor::intern {:?} with {:?}", + ptr, mutability, + ); + // remove allocation + let tcx = self.ecx.tcx; + let memory = self.ecx.memory_mut(); + let (kind, mut alloc) = match memory.alloc_map.remove(&ptr.alloc_id) { + Some(entry) => entry, + None => { + // if the pointer is dangling (neither in local nor global memory), we leave it + // to validation to error. The `delay_span_bug` ensures that we don't forget such + // a check in validation. + if tcx.alloc_map.lock().get(ptr.alloc_id).is_none() { + tcx.sess.delay_span_bug(self.ecx.tcx.span, "tried to intern dangling pointer"); + } + // treat dangling pointers like other statics + // just to stop trying to recurse into them + return Ok(Some(IsStaticOrFn)); + }, + }; + // This match is just a canary for future changes to `MemoryKind`, which most likely need + // changes in this function. + match kind { + MemoryKind::Stack | MemoryKind::Vtable => {}, + } + // Ensure llvm knows to only put this into immutable memory if the value is immutable either + // by being behind a reference or by being part of a static or const without interior + // mutability + alloc.mutability = mutability; + // link the alloc id to the actual allocation + let alloc = tcx.intern_const_alloc(alloc); + self.leftover_relocations.extend(alloc.relocations.iter().map(|&(_, ((), reloc))| reloc)); + tcx.alloc_map.lock().set_alloc_id_memory(ptr.alloc_id, alloc); + Ok(None) + } +} + +impl<'rt, 'a, 'mir, 'tcx> + ValueVisitor<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>> +for + InternVisitor<'rt, 'a, 'mir, 'tcx> +{ + type V = MPlaceTy<'tcx>; + + #[inline(always)] + fn ecx(&self) -> &CompileTimeEvalContext<'a, 'mir, 'tcx> { + &self.ecx + } + + fn visit_aggregate( + &mut self, + mplace: MPlaceTy<'tcx>, + fields: impl Iterator>, + ) -> EvalResult<'tcx> { + if let Some(def) = mplace.layout.ty.ty_adt_def() { + if Some(def.did) == self.ecx.tcx.lang_items().unsafe_cell_type() { + // We are crossing over an `UnsafeCell`, we can mutate again + let old = std::mem::replace(&mut self.mutability, Mutability::Mutable); + assert_ne!( + self.mode, InternMode::Const, + "UnsafeCells are not allowed behind references in constants. This should have \ + been prevented statically by const qualification. If this were allowed one \ + would be able to change a constant at one use site and other use sites may \ + arbitrarily decide to change, too.", + ); + let walked = self.walk_aggregate(mplace, fields); + self.mutability = old; + return walked; + } + } + self.walk_aggregate(mplace, fields) + } + + fn visit_primitive(&mut self, mplace: MPlaceTy<'tcx>) -> EvalResult<'tcx> { + // Handle Reference types, as these are the only relocations supported by const eval. + // Raw pointers (and boxes) are handled by the `leftover_relocations` logic. + let ty = mplace.layout.ty; + if let ty::Ref(_, _, mutability) = ty.sty { + let value = self.ecx.read_immediate(mplace.into())?; + // Handle trait object vtables + if let Ok(meta) = value.to_meta() { + let layout = self.ecx.layout_of(ty.builtin_deref(true).unwrap().ty)?; + if layout.is_unsized() { + if let ty::Dynamic(..) = self.ecx.tcx.struct_tail(layout.ty).sty { + if let Ok(vtable) = meta.unwrap().to_ptr() { + // explitly choose `Immutable` here, since vtables are immutable, even + // if the reference of the fat pointer is mutable + self.intern(vtable, Mutability::Immutable)?; + } + } + } + } + let mplace = self.ecx.ref_to_mplace(value)?; + // Check if we have encountered this pointer+layout combination before. + // Only recurse for allocation-backed pointers. + if let Scalar::Ptr(ptr) = mplace.ptr { + // In the future we will probably allow `& &mut T`, and thus will want to merge + // `mutability` with `self.mutability` to only choose `Mutable` if both are + // `Mutable`. + + // We do not have any `frozen` logic here, because it's essentially equivalent to + // the mutability except for the outermost item. Only `UnsafeCell` can "unfreeze", + // and we check that in `visit_aggregate`. + match (self.mode, mutability) { + // all is "good and well" in the unsoundness of `static mut` + (InternMode::StaticMut, _) => {}, + // immutable references are fine everywhere + (_, hir::Mutability::MutImmutable) => {}, + // mutable references are ok in `static`. Either they are treated as immutable + // because they are behind an immutable one, or they are behind an `UnsafeCell` + // and thus ok. + (InternMode::Static, hir::Mutability::MutMutable) => {}, + // we statically prevent `&mut T` via `const_qualif` and double check this here + (InternMode::ConstBase, hir::Mutability::MutMutable) | + (InternMode::Const, hir::Mutability::MutMutable) => + bug!("const qualif failed to prevent mutable references"), + } + let mutability = match (self.mutability, mutability) { + // The only way a mutable reference actually works as a mutable reference is + // by being in a `static mut` directly or behind another mutable reference. + // If there's an immutable reference or we are inside a static, then our + // mutable reference is equivalent to an immutable one. As an example: + // `&&mut Foo` is semantically equivalent to `&&Foo` + (Mutability::Mutable, hir::Mutability::MutMutable) => Mutability::Mutable, + _ => Mutability::Immutable, + }; + let intern_mutability = intern_mutability( + self.ecx.tcx.tcx, + self.param_env, + mplace.layout.ty, + self.ecx.tcx.span, + mutability, + ); + // Recursing behind references changes the intern mode for constants in order to + // cause assertions to trigger if we encounter any `UnsafeCell`s. + let mode = match self.mode { + InternMode::ConstBase => InternMode::Const, + other => other, + }; + match self.intern(ptr, intern_mutability)? { + // No need to recurse, these are interned already and statics may have + // cycles, so we don't want to recurse there + Some(IsStaticOrFn) => {}, + // intern everything referenced by this value. The mutability is taken from the + // reference. It is checked above that mutable references only happen in + // `static mut` + None => self.ref_tracking.track((mplace, mutability, mode), || ()), + } + } + } + Ok(()) + } +} + +/// Figure out the mutability of the allocation. +/// Mutable if it has interior mutability *anywhere* in the type. +fn intern_mutability<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + param_env: ParamEnv<'tcx>, + ty: Ty<'tcx>, + span: Span, + mutability: Mutability, +) -> Mutability { + let has_interior_mutability = !ty.is_freeze(tcx, param_env, span); + if has_interior_mutability { + Mutability::Mutable + } else { + mutability + } +} + +pub fn intern_const_alloc_recursive( + ecx: &mut CompileTimeEvalContext<'a, 'mir, 'tcx>, + def_id: DefId, + ret: MPlaceTy<'tcx>, + // FIXME(oli-obk): can we scrap the param env? I think we can, the final value of a const eval + // must always be monomorphic, right? + param_env: ty::ParamEnv<'tcx>, +) -> EvalResult<'tcx> { + let tcx = ecx.tcx; + let (mutability, base_intern_mode) = match tcx.static_mutability(def_id) { + Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static), + None => (Mutability::Immutable, InternMode::ConstBase), + // `static mut` doesn't care about interior mutability, it's mutable anyway + Some(hir::Mutability::MutMutable) => (Mutability::Mutable, InternMode::StaticMut), + }; + + // type based interning + let mut ref_tracking = RefTracking::new((ret, mutability, base_intern_mode)); + let leftover_relocations = &mut FxHashSet::default(); + + let alloc_mutability = intern_mutability( + tcx.tcx, param_env, ret.layout.ty, tcx.span, mutability, + ); + + // start with the outermost allocation + InternVisitor { + ref_tracking: &mut ref_tracking, + ecx, + mode: base_intern_mode, + leftover_relocations, + param_env, + mutability, + }.intern(ret.ptr.to_ptr()?, alloc_mutability)?; + + while let Some(((mplace, mutability, mode), _)) = ref_tracking.todo.pop() { + let interned = InternVisitor { + ref_tracking: &mut ref_tracking, + ecx, + mode, + leftover_relocations, + param_env, + mutability, + }.visit_value(mplace); + if let Err(error) = interned { + // This can happen when e.g. the tag of an enum is not a valid discriminant. We do have + // to read enum discriminants in order to find references in enum variant fields. + if let InterpError::ValidationFailure(_) = error.kind { + let err = crate::const_eval::error_to_const_error(&ecx, error); + match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") { + Ok(mut diag) => { + diag.note("The rules on what exactly is undefined behavior aren't clear, \ + so this check might be overzealous. Please open an issue on the rust \ + compiler repository if you believe it should not be considered \ + undefined behavior", + ); + diag.emit(); + } + Err(ErrorHandled::TooGeneric) | + Err(ErrorHandled::Reported) => {}, + } + } + } + } + + // Intern the rest of the allocations as mutable. These might be inside unions, padding, raw + // pointers, ... So we can't intern them according to their type rules + + let mut todo: Vec<_> = leftover_relocations.iter().cloned().collect(); + while let Some(alloc_id) = todo.pop() { + if let Some((_, alloc)) = ecx.memory_mut().alloc_map.remove(&alloc_id) { + // We can't call the `intern` method here, as its logic is tailored to safe references. + // So we hand-roll the interning logic here again + let alloc = tcx.intern_const_alloc(alloc); + tcx.alloc_map.lock().set_alloc_id_memory(alloc_id, alloc); + for &(_, ((), reloc)) in alloc.relocations.iter() { + if leftover_relocations.insert(reloc) { + todo.push(reloc); + } + } + } else if ecx.memory().dead_alloc_map.contains_key(&alloc_id) { + // dangling pointer + return err!(ValidationFailure( + "encountered dangling pointer in final constant".into(), + )) + } + } + Ok(()) +} diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index a0a34df3a5ea..a78c5a64894b 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -20,6 +20,7 @@ use super::{ Pointer, AllocId, Allocation, GlobalId, AllocationExtra, InterpResult, Scalar, InterpError, GlobalAlloc, PointerArithmetic, Machine, AllocMap, MayLeak, ErrorHandled, CheckInAllocMsg, InboundsCheck, + InterpError::ValidationFailure, }; #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] @@ -55,12 +56,12 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// the wrong type), so we let the machine override this type. /// Either way, if the machine allows writing to a static, doing so will /// create a copy of the static allocation here. - alloc_map: M::MemoryMap, + pub(super) alloc_map: M::MemoryMap, /// To be able to compare pointers with NULL, and to check alignment for accesses /// to ZSTs (where pointers may dangle), we keep track of the size even for allocations /// that do not exist any more. - dead_alloc_map: FxHashMap, + pub(super) dead_alloc_map: FxHashMap, /// Extra data added by the machine. pub extra: M::MemoryExtra, @@ -455,6 +456,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // Could also be a fn ptr or extern static match self.tcx.alloc_map.lock().get(id) { Some(GlobalAlloc::Function(..)) => Ok((Size::ZERO, Align::from_bytes(1).unwrap())), + // `self.get` would also work, but can cause cycles if a static refers to itself Some(GlobalAlloc::Static(did)) => { // The only way `get` couldn't have worked here is if this is an extern static assert!(self.tcx.is_foreign_item(did)); @@ -463,14 +465,20 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap(); Ok((layout.size, layout.align.abi)) } - _ => match liveness { - InboundsCheck::MaybeDead => { - // Must be a deallocated pointer - Ok(*self.dead_alloc_map.get(&id).expect( - "allocation missing in dead_alloc_map" - )) - }, - InboundsCheck::Live => err!(DanglingPointerDeref), + _ => { + if let Ok(alloc) = self.get(id) { + return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)); + } + match liveness { + InboundsCheck::MaybeDead => { + // Must be a deallocated pointer + self.dead_alloc_map.get(&id).cloned().ok_or_else(|| + ValidationFailure("allocation missing in dead_alloc_map".to_string()) + .into() + ) + }, + InboundsCheck::Live => err!(DanglingPointerDeref), + } }, } } @@ -633,56 +641,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } } -/// Interning (for CTFE) -impl<'mir, 'tcx, M> Memory<'mir, 'tcx, M> -where - M: Machine<'mir, 'tcx, PointerTag = (), AllocExtra = (), MemoryExtra = ()>, - // FIXME: Working around https://github.com/rust-lang/rust/issues/24159 - M::MemoryMap: AllocMap, Allocation)>, -{ - /// mark an allocation as static and initialized, either mutable or not - pub fn intern_static( - &mut self, - alloc_id: AllocId, - mutability: Mutability, - ) -> InterpResult<'tcx> { - trace!( - "mark_static_initialized {:?}, mutability: {:?}", - alloc_id, - mutability - ); - // remove allocation - let (kind, mut alloc) = self.alloc_map.remove(&alloc_id).unwrap(); - match kind { - MemoryKind::Machine(_) => bug!("Static cannot refer to machine memory"), - MemoryKind::Stack | MemoryKind::Vtable => {}, - } - // ensure llvm knows not to put this into immutable memory - alloc.mutability = mutability; - let alloc = self.tcx.intern_const_alloc(alloc); - self.tcx.alloc_map.lock().set_alloc_id_memory(alloc_id, alloc); - // recurse into inner allocations - for &(_, alloc) in alloc.relocations.values() { - // FIXME: Reusing the mutability here is likely incorrect. It is originally - // determined via `is_freeze`, and data is considered frozen if there is no - // `UnsafeCell` *immediately* in that data -- however, this search stops - // at references. So whenever we follow a reference, we should likely - // assume immutability -- and we should make sure that the compiler - // does not permit code that would break this! - if self.alloc_map.contains_key(&alloc) { - // Not yet interned, so proceed recursively - self.intern_static(alloc, mutability)?; - } else if self.dead_alloc_map.contains_key(&alloc) { - // dangling pointer - return err!(ValidationFailure( - "encountered dangling pointer in final constant".into(), - )) - } - } - Ok(()) - } -} - /// Reading and writing. impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { pub fn copy( diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index d59bee6943a5..0293a8366d08 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -14,6 +14,7 @@ mod traits; mod validity; mod intrinsics; mod visitor; +mod intern; pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here @@ -34,3 +35,5 @@ pub use self::visitor::{ValueVisitor, MutValueVisitor}; pub use self::validity::RefTracking; pub(super) use self::intrinsics::type_name; + +pub use self::intern::intern_const_alloc_recursive; diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 4b1e782ba1a4..ad841a57e787 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -217,7 +217,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { fn try_read_immediate_from_mplace( &self, mplace: MPlaceTy<'tcx, M::PointerTag>, - ) -> InterpResult<'tcx, Option>> { + ) -> InterpResult<'tcx, Option>> { if mplace.layout.is_unsized() { // Don't touch unsized return Ok(None); @@ -228,7 +228,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { // Not all ZSTs have a layout we would handle below, so just short-circuit them // all here. self.memory.check_align(ptr, ptr_align)?; - return Ok(Some(Immediate::Scalar(Scalar::zst().into()))); + return Ok(Some(ImmTy { + imm: Immediate::Scalar(Scalar::zst().into()), + layout: mplace.layout, + })); } // check for integer pointers before alignment to report better errors @@ -239,7 +242,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { let scalar = self.memory .get(ptr.alloc_id)? .read_scalar(self, ptr, mplace.layout.size)?; - Ok(Some(Immediate::Scalar(scalar))) + Ok(Some(ImmTy { + imm: Immediate::Scalar(scalar), + layout: mplace.layout, + })) } layout::Abi::ScalarPair(ref a, ref b) => { let (a, b) = (&a.value, &b.value); @@ -256,7 +262,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { let b_val = self.memory .get(ptr.alloc_id)? .read_scalar(self, b_ptr, b_size)?; - Ok(Some(Immediate::ScalarPair(a_val, b_val))) + Ok(Some(ImmTy { + imm: Immediate::ScalarPair(a_val, b_val), + layout: mplace.layout, + })) } _ => Ok(None), } @@ -271,13 +280,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { pub(crate) fn try_read_immediate( &self, src: OpTy<'tcx, M::PointerTag>, - ) -> InterpResult<'tcx, Result, MemPlace>> { + ) -> InterpResult<'tcx, Result, MPlaceTy<'tcx, M::PointerTag>>> { Ok(match src.try_as_mplace() { Ok(mplace) => { if let Some(val) = self.try_read_immediate_from_mplace(mplace)? { Ok(val) } else { - Err(*mplace) + Err(mplace) } }, Err(val) => Ok(val), @@ -291,7 +300,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { op: OpTy<'tcx, M::PointerTag> ) -> InterpResult<'tcx, ImmTy<'tcx, M::PointerTag>> { if let Ok(imm) = self.try_read_immediate(op)? { - Ok(ImmTy { imm, layout: op.layout }) + Ok(imm) } else { bug!("primitive read failed for type: {:?}", op.layout.ty); } @@ -339,9 +348,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout }); } let offset = op.layout.fields.offset(field); - let immediate = match base { + let immediate = match *base { // the field covers the entire type - _ if offset.bytes() == 0 && field_layout.size == op.layout.size => base, + _ if offset.bytes() == 0 && field_layout.size == op.layout.size => *base, // extract fields from types with `ScalarPair` ABI Immediate::ScalarPair(a, b) => { let val = if offset.bytes() == 0 { a } else { b }; diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index a8f88af3f383..a721cea85a24 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -232,10 +232,10 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { impl<'tcx, Tag: ::std::fmt::Debug + Copy> OpTy<'tcx, Tag> { #[inline(always)] - pub fn try_as_mplace(self) -> Result, Immediate> { + pub fn try_as_mplace(self) -> Result, ImmTy<'tcx, Tag>> { match *self { Operand::Indirect(mplace) => Ok(MPlaceTy { mplace, layout: self.layout }), - Operand::Immediate(imm) => Err(imm), + Operand::Immediate(imm) => Err(ImmTy { imm, layout: self.layout }), } } @@ -660,7 +660,7 @@ where if M::enforce_validity(self) { // Data got changed, better make sure it matches the type! - self.validate_operand(self.place_to_op(dest)?, vec![], None, /*const_mode*/false)?; + self.validate_operand(self.place_to_op(dest)?, vec![], None)?; } Ok(()) @@ -809,7 +809,7 @@ where if M::enforce_validity(self) { // Data got changed, better make sure it matches the type! - self.validate_operand(self.place_to_op(dest)?, vec![], None, /*const_mode*/false)?; + self.validate_operand(self.place_to_op(dest)?, vec![], None)?; } Ok(()) @@ -836,7 +836,7 @@ where // Yay, we got a value that we can write directly. // FIXME: Add a check to make sure that if `src` is indirect, // it does not overlap with `dest`. - return self.write_immediate_no_validate(src_val, dest); + return self.write_immediate_no_validate(*src_val, dest); } Err(mplace) => mplace, }; @@ -897,7 +897,7 @@ where if M::enforce_validity(self) { // Data got changed, better make sure it matches the type! - self.validate_operand(dest.into(), vec![], None, /*const_mode*/false)?; + self.validate_operand(dest.into(), vec![], None)?; } Ok(()) diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index cad0b3e0012f..d747eddd8d7b 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -1,5 +1,4 @@ use std::fmt::Write; -use std::hash::Hash; use std::ops::RangeInclusive; use syntax_pos::symbol::{sym, Symbol}; @@ -11,6 +10,8 @@ use rustc::mir::interpret::{ Scalar, GlobalAlloc, InterpResult, InterpError, CheckInAllocMsg, }; +use std::hash::Hash; + use super::{ OpTy, Machine, InterpretCx, ValueVisitor, MPlaceTy, }; @@ -76,19 +77,34 @@ pub enum PathElem { } /// State for tracking recursive validation of references -pub struct RefTracking { +pub struct RefTracking { pub seen: FxHashSet, - pub todo: Vec<(T, Vec)>, + pub todo: Vec<(T, PATH)>, } -impl RefTracking { - pub fn new(op: T) -> Self { - let mut ref_tracking = RefTracking { +impl RefTracking { + pub fn empty() -> Self { + RefTracking { seen: FxHashSet::default(), - todo: vec![(op, Vec::new())], + todo: vec![], + } + } + pub fn new(op: T) -> Self { + let mut ref_tracking_for_consts = RefTracking { + seen: FxHashSet::default(), + todo: vec![(op, PATH::default())], }; - ref_tracking.seen.insert(op); - ref_tracking + ref_tracking_for_consts.seen.insert(op); + ref_tracking_for_consts + } + + pub fn track(&mut self, op: T, path: impl FnOnce() -> PATH) { + if self.seen.insert(op) { + trace!("Recursing below ptr {:#?}", op); + let path = path(); + // Remember to come back to this later. + self.todo.push((op, path)); + } } } @@ -154,8 +170,10 @@ struct ValidityVisitor<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// starts must not be changed! `visit_fields` and `visit_array` rely on /// this stack discipline. path: Vec, - ref_tracking: Option<&'rt mut RefTracking>>, - const_mode: bool, + ref_tracking_for_consts: Option<&'rt mut RefTracking< + MPlaceTy<'tcx, M::PointerTag>, + Vec, + >>, ecx: &'rt InterpretCx<'mir, 'tcx, M>, } @@ -314,7 +332,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> // types below! let size = value.layout.size; let value = value.to_scalar_or_undef(); - if self.const_mode { + if self.ref_tracking_for_consts.is_some() { // Integers/floats in CTFE: Must be scalar bits, pointers are dangerous try_validation!(value.to_bits(size), value, self.path, "initialized plain (non-pointer) bytes"); @@ -324,7 +342,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> } } ty::RawPtr(..) => { - if self.const_mode { + if self.ref_tracking_for_consts.is_some() { // Integers/floats in CTFE: For consistency with integers, we do not // accept undef. let _ptr = try_validation!(value.to_scalar_ptr(), @@ -393,8 +411,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> } } // Recursive checking - if let Some(ref mut ref_tracking) = self.ref_tracking { - assert!(self.const_mode, "We should only do recursie checking in const mode"); + if let Some(ref mut ref_tracking) = self.ref_tracking_for_consts { let place = self.ecx.ref_to_mplace(value)?; // FIXME(RalfJ): check ZST for inbound pointers if size != Size::ZERO { @@ -424,16 +441,15 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> // before. Proceed recursively even for integer pointers, no // reason to skip them! They are (recursively) valid for some ZST, // but not for others (e.g., `!` is a ZST). - if ref_tracking.seen.insert(place) { - trace!("Recursing below ptr {:#?}", *place); + let path = &self.path; + ref_tracking.track(place, || { // We need to clone the path anyway, make sure it gets created // with enough space for the additional `Deref`. - let mut new_path = Vec::with_capacity(self.path.len()+1); - new_path.clone_from(&self.path); + let mut new_path = Vec::with_capacity(path.len() + 1); + new_path.clone_from(path); new_path.push(PathElem::Deref); - // Remember to come back to this later. - ref_tracking.todo.push((place, new_path)); - } + new_path + }); } } ty::FnPtr(_sig) => { @@ -489,10 +505,17 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> let non_null = self.ecx.memory.check_align( Scalar::Ptr(ptr), Align::from_bytes(1).unwrap() - ).is_ok() || - self.ecx.memory.get_fn(ptr).is_ok(); + ).is_ok(); if !non_null { - // could be NULL + // These conditions are just here to improve the diagnostics so we can + // differentiate between null pointers and dangling pointers + if self.ref_tracking_for_consts.is_some() && + self.ecx.memory.get(ptr.alloc_id).is_err() && + self.ecx.memory.get_fn(ptr).is_err() { + return validation_failure!( + "encountered dangling pointer", self.path + ); + } return validation_failure!("a potentially NULL pointer", self.path); } return Ok(()); @@ -575,7 +598,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> self.ecx, ptr, size, - /*allow_ptr_and_undef*/!self.const_mode, + /*allow_ptr_and_undef*/ self.ref_tracking_for_consts.is_none(), ) { // In the happy case, we needn't check anything else. Ok(()) => {}, @@ -613,23 +636,25 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { /// is an indirect operand. /// It will error if the bits at the destination do not match the ones described by the layout. /// - /// `ref_tracking` can be `None` to avoid recursive checking below references. + /// `ref_tracking_for_consts` can be `None` to avoid recursive checking below references. /// This also toggles between "run-time" (no recursion) and "compile-time" (with recursion) - /// validation (e.g., pointer values are fine in integers at runtime). + /// validation (e.g., pointer values are fine in integers at runtime) and various other const + /// specific validation checks pub fn validate_operand( &self, op: OpTy<'tcx, M::PointerTag>, path: Vec, - ref_tracking: Option<&mut RefTracking>>, - const_mode: bool, + ref_tracking_for_consts: Option<&mut RefTracking< + MPlaceTy<'tcx, M::PointerTag>, + Vec, + >>, ) -> InterpResult<'tcx> { trace!("validate_operand: {:?}, {:?}", *op, op.layout.ty); // Construct a visitor let mut visitor = ValidityVisitor { path, - ref_tracking, - const_mode, + ref_tracking_for_consts, ecx: self, }; diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 2ec5c192726b..805f15e37472 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -551,7 +551,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { source_info: SourceInfo, ) { trace!("attepting to replace {:?} with {:?}", rval, value); - if let Err(e) = self.ecx.validate_operand(value, vec![], None, true) { + if let Err(e) = self.ecx.validate_operand( + value, + vec![], + // FIXME: is ref tracking too expensive? + Some(&mut interpret::RefTracking::empty()), + ) { trace!("validation error, attempt failed: {:?}", e); return; } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index b6abfdb7425a..f082b5e5a046 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -738,27 +738,29 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { qualifs[IsNotPromotable] = true; if self.mode.requires_const_checking() { - if let BorrowKind::Mut { .. } = kind { - let mut err = struct_span_err!(self.tcx.sess, self.span, E0017, - "references in {}s may only refer \ - to immutable values", self.mode); - err.span_label(self.span, format!("{}s require immutable values", - self.mode)); - if self.tcx.sess.teach(&err.get_code().unwrap()) { - err.note("References in statics and constants may only refer to \ - immutable values.\n\n\ - Statics are shared everywhere, and if they refer to \ - mutable data one might violate memory safety since \ - holding multiple mutable references to shared data is \ - not allowed.\n\n\ - If you really want global mutable state, try using \ - static mut or a global UnsafeCell."); + if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you { + if let BorrowKind::Mut { .. } = kind { + let mut err = struct_span_err!(self.tcx.sess, self.span, E0017, + "references in {}s may only refer \ + to immutable values", self.mode); + err.span_label(self.span, format!("{}s require immutable values", + self.mode)); + if self.tcx.sess.teach(&err.get_code().unwrap()) { + err.note("References in statics and constants may only refer to \ + immutable values.\n\n\ + Statics are shared everywhere, and if they refer to \ + mutable data one might violate memory safety since \ + holding multiple mutable references to shared data is \ + not allowed.\n\n\ + If you really want global mutable state, try using \ + static mut or a global UnsafeCell."); + } + err.emit(); + } else { + span_err!(self.tcx.sess, self.span, E0492, + "cannot borrow a constant which may contain \ + interior mutability, create a static instead"); } - err.emit(); - } else { - span_err!(self.tcx.sess, self.span, E0492, - "cannot borrow a constant which may contain \ - interior mutability, create a static instead"); } } } else if let BorrowKind::Mut { .. } | BorrowKind::Shared = kind { diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.rs b/src/test/ui/consts/miri_unleashed/mutable_references.rs new file mode 100644 index 000000000000..5f9888053a19 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/mutable_references.rs @@ -0,0 +1,35 @@ +// compile-flags: -Zunleash-the-miri-inside-of-you +#![allow(const_err)] + +use std::cell::UnsafeCell; + +// a test demonstrating what things we could allow with a smarter const qualification + +static FOO: &&mut u32 = &&mut 42; + +static BAR: &mut () = &mut (); + +struct Foo(T); + +static BOO: &mut Foo<()> = &mut Foo(()); + +struct Meh { + x: &'static UnsafeCell, +} + +unsafe impl Sync for Meh {} + +static MEH: Meh = Meh { + x: &UnsafeCell::new(42), +}; + +static OH_YES: &mut i32 = &mut 42; + +fn main() { + unsafe { + *MEH.x.get() = 99; //~ WARN skipping const checks + //~^ WARN skipping const checks + } + *OH_YES = 99; //~ ERROR cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item + //~^ WARN skipping const checks +} diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.stderr b/src/test/ui/consts/miri_unleashed/mutable_references.stderr new file mode 100644 index 000000000000..b870aca640a0 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/mutable_references.stderr @@ -0,0 +1,26 @@ +warning: skipping const checks + --> $DIR/mutable_references.rs:30:10 + | +LL | *MEH.x.get() = 99; + | ^^^^^ + +warning: skipping const checks + --> $DIR/mutable_references.rs:30:9 + | +LL | *MEH.x.get() = 99; + | ^^^^^^^^^^^^^^^^^ + +warning: skipping const checks + --> $DIR/mutable_references.rs:33:5 + | +LL | *OH_YES = 99; + | ^^^^^^^^^^^^ + +error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item + --> $DIR/mutable_references.rs:33:5 + | +LL | *OH_YES = 99; + | ^^^^^^^^^^^^ cannot assign + +error: aborting due to previous error + diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_ice.rs b/src/test/ui/consts/miri_unleashed/mutable_references_ice.rs new file mode 100644 index 000000000000..4a77534c6c70 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/mutable_references_ice.rs @@ -0,0 +1,28 @@ +// compile-flags: -Zunleash-the-miri-inside-of-you +// failure-status: 101 +// rustc-env:RUST_BACKTRACE=0 +// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET" +// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS" + +#![allow(const_err)] + +use std::cell::UnsafeCell; + +// this test ICEs to ensure that our mutability story is sound + +struct Meh { + x: &'static UnsafeCell, +} + +unsafe impl Sync for Meh {} + +// the following will never be ok! +const MUH: Meh = Meh { + x: &UnsafeCell::new(42), +}; + +fn main() { + unsafe { + *MUH.x.get() = 99; //~ WARN skipping const checks + } +} diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr new file mode 100644 index 000000000000..efb175f445d9 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr @@ -0,0 +1,21 @@ +warning: skipping const checks + --> $DIR/mutable_references_ice.rs:26:9 + | +LL | *MUH.x.get() = 99; + | ^^^^^^^^^^^^^^^^^ + +thread 'rustc' panicked at 'assertion failed: `(left != right)` + left: `Const`, + right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites may arbitrarily decide to change, too.', src/librustc_mir/interpret/intern.rs:126:17 +note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. + +error: internal compiler error: unexpected panic + +note: the compiler unexpectedly panicked. this is a bug. + +note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports + +note: rustc VERSION running on TARGET + +note: compiler flags: FLAGS + diff --git a/src/test/ui/consts/packed_pattern.rs b/src/test/ui/consts/packed_pattern.rs new file mode 100644 index 000000000000..37ae45b6df7e --- /dev/null +++ b/src/test/ui/consts/packed_pattern.rs @@ -0,0 +1,19 @@ +// run-pass + +#[derive(PartialEq, Eq, Copy, Clone)] +#[repr(packed)] +struct Foo { + field: (i64, u32, u32, u32), +} + +const FOO: Foo = Foo { + field: (5, 6, 7, 8), +}; + +fn main() { + match FOO { + Foo { field: (5, 6, 7, 8) } => {}, + FOO => unreachable!(), + _ => unreachable!(), + } +} diff --git a/src/test/ui/consts/static-raw-pointer-interning.rs b/src/test/ui/consts/static-raw-pointer-interning.rs new file mode 100644 index 000000000000..cab60c91e165 --- /dev/null +++ b/src/test/ui/consts/static-raw-pointer-interning.rs @@ -0,0 +1,15 @@ +// run-pass + +static FOO: Foo = Foo { + field: &42 as *const i32, +}; + +struct Foo { + field: *const i32, +} + +unsafe impl Sync for Foo {} + +fn main() { + assert_eq!(unsafe { *FOO.field }, 42); +} diff --git a/src/test/ui/consts/static-raw-pointer-interning2.rs b/src/test/ui/consts/static-raw-pointer-interning2.rs new file mode 100644 index 000000000000..2b915fd7cb32 --- /dev/null +++ b/src/test/ui/consts/static-raw-pointer-interning2.rs @@ -0,0 +1,15 @@ +// run-pass + +static mut FOO: Foo = Foo { + field: &mut [42] as *mut [i32] as *mut i32, +}; + +struct Foo { + field: *mut i32, +} + +unsafe impl Sync for Foo {} + +fn main() { + assert_eq!(unsafe { *FOO.field = 69; *FOO.field }, 69); +} diff --git a/src/test/ui/consts/union_constant.rs b/src/test/ui/consts/union_constant.rs index 6b6042194ba2..16b05310b9fc 100644 --- a/src/test/ui/consts/union_constant.rs +++ b/src/test/ui/consts/union_constant.rs @@ -6,5 +6,6 @@ union Uninit { } const UNINIT: Uninit = Uninit { uninit: () }; +const UNINIT2: (Uninit,) = (Uninit { uninit: () }, ); fn main() {} From 21b1bd69b0fcd4861aad98ed2fef37a71cb70850 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 3 Jun 2019 17:49:14 +0200 Subject: [PATCH 078/109] Prevent cyclic locks of `alloc_map` --- src/librustc_mir/interpret/memory.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index a78c5a64894b..ff33dccdfeaf 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -453,8 +453,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { if let Ok(alloc) = self.get(id) { return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)); } + // can't do this in the match argument, we may get cycle errors since the lock would get + // dropped after the match. + let alloc = self.tcx.alloc_map.lock().get(id); // Could also be a fn ptr or extern static - match self.tcx.alloc_map.lock().get(id) { + match alloc { Some(GlobalAlloc::Function(..)) => Ok((Size::ZERO, Align::from_bytes(1).unwrap())), // `self.get` would also work, but can cause cycles if a static refers to itself Some(GlobalAlloc::Static(did)) => { From 870a6dc230f14347fe71b7a27919607630cef033 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 3 Jun 2019 18:35:50 +0200 Subject: [PATCH 079/109] Don't ICE when pattern matching packed structs --- src/librustc_mir/const_eval.rs | 7 ++++++- src/librustc_mir/interpret/operand.rs | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 31541842e215..ef8d0bb1e277 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -482,7 +482,12 @@ pub fn const_field<'tcx>( trace!("const_field: {:?}, {:?}", field, value); let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env); // get the operand again - let op = ecx.eval_const_to_op(value, None).unwrap(); + let mut op = ecx.eval_const_to_op(value, None).unwrap(); + // adjust the alignment of `op` to the one of the allocation, since it may be a field of a + // packed struct and thus end up causing an alignment error if we read from it. + if let ConstValue::ByRef(_, alloc) = value.val { + op.force_alignment(alloc.align); + } // downcast let down = match variant { None => op, diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index ad841a57e787..8e0260988505 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -4,7 +4,9 @@ use std::convert::TryInto; use rustc::{mir, ty}; -use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx}; +use rustc::ty::layout::{ + self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx, Align, +}; use rustc::mir::interpret::{ GlobalId, AllocId, CheckInAllocMsg, @@ -177,6 +179,21 @@ impl<'tcx, Tag> From> for OpTy<'tcx, Tag> { } } +impl<'tcx, Tag> OpTy<'tcx, Tag> { + /// This function exists solely for pattern matching. If we pattern match a packed struct with + /// an ADT field, the constant representing that field will have lost the information about the + /// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful, + /// since the alignment is already encoded in the allocation. We know it is alright, because + /// validation checked everything before the initial constant entered match checking. + pub(crate) fn force_alignment(&mut self, align: Align) { + if let Operand::Indirect(mplace) = &mut self.op { + if align < mplace.align { + mplace.align = align; + } + } + } +} + impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { #[inline] From b52f6f4ca8a2d04abf2f6481530303c2eabaef18 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 3 Jun 2019 18:39:38 +0200 Subject: [PATCH 080/109] Elaborate on why we don't look at frozenness --- src/librustc_mir/interpret/intern.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index 47dcde95ca55..b55129bd4196 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -168,6 +168,8 @@ for // We do not have any `frozen` logic here, because it's essentially equivalent to // the mutability except for the outermost item. Only `UnsafeCell` can "unfreeze", // and we check that in `visit_aggregate`. + // This is not an inherent limitation, but one that we know to be true, because + // const qualification enforces it. We can lift it in the future. match (self.mode, mutability) { // all is "good and well" in the unsoundness of `static mut` (InternMode::StaticMut, _) => {}, From d6fa4070bea1cf94b6fbab5028057d5604c600ee Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 11 Jun 2019 13:23:08 +0200 Subject: [PATCH 081/109] Fix rebase fallout --- src/librustc_mir/interpret/intern.rs | 12 ++++++------ src/librustc_mir/interpret/place.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index b55129bd4196..a7aee9407a49 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -6,7 +6,7 @@ use rustc::ty::layout::LayoutOf; use rustc::ty::{Ty, TyCtxt, ParamEnv, self}; use rustc::mir::interpret::{ - EvalResult, ErrorHandled, + InterpResult, ErrorHandled, }; use rustc::hir; use rustc::hir::def_id::DefId; @@ -63,7 +63,7 @@ impl<'rt, 'a, 'mir, 'tcx> InternVisitor<'rt, 'a, 'mir, 'tcx> { &mut self, ptr: Pointer, mutability: Mutability, - ) -> EvalResult<'tcx, Option> { + ) -> InterpResult<'tcx, Option> { trace!( "InternVisitor::intern {:?} with {:?}", ptr, mutability, @@ -117,8 +117,8 @@ for fn visit_aggregate( &mut self, mplace: MPlaceTy<'tcx>, - fields: impl Iterator>, - ) -> EvalResult<'tcx> { + fields: impl Iterator>, + ) -> InterpResult<'tcx> { if let Some(def) = mplace.layout.ty.ty_adt_def() { if Some(def.did) == self.ecx.tcx.lang_items().unsafe_cell_type() { // We are crossing over an `UnsafeCell`, we can mutate again @@ -138,7 +138,7 @@ for self.walk_aggregate(mplace, fields) } - fn visit_primitive(&mut self, mplace: MPlaceTy<'tcx>) -> EvalResult<'tcx> { + fn visit_primitive(&mut self, mplace: MPlaceTy<'tcx>) -> InterpResult<'tcx> { // Handle Reference types, as these are the only relocations supported by const eval. // Raw pointers (and boxes) are handled by the `leftover_relocations` logic. let ty = mplace.layout.ty; @@ -245,7 +245,7 @@ pub fn intern_const_alloc_recursive( // FIXME(oli-obk): can we scrap the param env? I think we can, the final value of a const eval // must always be monomorphic, right? param_env: ty::ParamEnv<'tcx>, -) -> EvalResult<'tcx> { +) -> InterpResult<'tcx> { let tcx = ecx.tcx; let (mutability, base_intern_mode) = match tcx.static_mutability(def_id) { Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static), diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index a721cea85a24..1285549015cd 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -677,7 +677,7 @@ where if M::enforce_validity(self) { // Data got changed, better make sure it matches the type! - self.validate_operand(dest.into(), vec![], None, /*const_mode*/ false)?; + self.validate_operand(dest.into(), vec![], None)?; } Ok(()) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 805f15e37472..5b567512a7b6 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -567,7 +567,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { }); if let Some(Ok(imm)) = imm { - match imm { + match *imm { interpret::Immediate::Scalar(ScalarMaybeUndef::Scalar(scalar)) => { *rval = Rvalue::Use( self.operand_from_scalar(scalar, value.layout.ty, source_info.span)); From 9e3fbcfd571d3ed4c0729a1ae822377bc075fcd6 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 11 Jun 2019 16:17:08 +0200 Subject: [PATCH 082/109] Merge `StaticMut` and `Static` logic --- src/librustc_mir/interpret/intern.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index a7aee9407a49..c450e3be1dda 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -44,9 +44,9 @@ struct InternVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir> { #[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)] enum InternMode { - /// Mutable references don't change the `mutability` field to `Immutable` - StaticMut, - /// Mutable references must in fact be immutable due to their surrounding immutability + /// Mutable references must in fact be immutable due to their surrounding immutability in a + /// `static`. In a `static mut` we start out as mutable and thus can also contain further `&mtu` + /// that will actually be treated as mutable. Static, /// UnsafeCell is OK in the value of a constant, but not behind references in a constant ConstBase, @@ -171,10 +171,10 @@ for // This is not an inherent limitation, but one that we know to be true, because // const qualification enforces it. We can lift it in the future. match (self.mode, mutability) { - // all is "good and well" in the unsoundness of `static mut` - (InternMode::StaticMut, _) => {}, // immutable references are fine everywhere (_, hir::Mutability::MutImmutable) => {}, + // all is "good and well" in the unsoundness of `static mut` + // mutable references are ok in `static`. Either they are treated as immutable // because they are behind an immutable one, or they are behind an `UnsafeCell` // and thus ok. @@ -251,7 +251,7 @@ pub fn intern_const_alloc_recursive( Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static), None => (Mutability::Immutable, InternMode::ConstBase), // `static mut` doesn't care about interior mutability, it's mutable anyway - Some(hir::Mutability::MutMutable) => (Mutability::Mutable, InternMode::StaticMut), + Some(hir::Mutability::MutMutable) => (Mutability::Mutable, InternMode::Static), }; // type based interning From 13f35de19d586ae125ec2c99b51d3d4a9321ca3b Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 11 Jun 2019 16:17:17 +0200 Subject: [PATCH 083/109] Elaborate on a comment --- src/librustc_mir/const_eval.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index ef8d0bb1e277..d6c0744b4e8a 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -540,6 +540,8 @@ fn validate_and_turn_into_const<'tcx>( )?; } // Now that we validated, turn this into a proper constant. + // Statics/promoteds are always `ByRef`, for the rest `op_to_const` decides + // whether they become immediates. let def_id = cid.instance.def.def_id(); if tcx.is_static(def_id) || cid.promoted.is_some() { let ptr = mplace.ptr.to_ptr()?; From 104b108406ab01d4ed96fac87a405602dab91c87 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 11 Jun 2019 16:17:26 +0200 Subject: [PATCH 084/109] Add and update more tests --- .../mutable_references_ice.stderr | 2 +- src/test/ui/consts/packed_pattern2.rs | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/packed_pattern2.rs diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr index efb175f445d9..f695ce30f19f 100644 --- a/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr +++ b/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr @@ -7,7 +7,7 @@ LL | *MUH.x.get() = 99; thread 'rustc' panicked at 'assertion failed: `(left != right)` left: `Const`, right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites may arbitrarily decide to change, too.', src/librustc_mir/interpret/intern.rs:126:17 -note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. error: internal compiler error: unexpected panic diff --git a/src/test/ui/consts/packed_pattern2.rs b/src/test/ui/consts/packed_pattern2.rs new file mode 100644 index 000000000000..174161fbd946 --- /dev/null +++ b/src/test/ui/consts/packed_pattern2.rs @@ -0,0 +1,27 @@ +// run-pass + +#[derive(PartialEq, Eq, Copy, Clone)] +#[repr(packed)] +struct Foo { + field: (u8, u16), +} + +#[derive(PartialEq, Eq, Copy, Clone)] +#[repr(align(2))] +struct Bar { + a: Foo, +} + +const FOO: Bar = Bar { + a: Foo { + field: (5, 6), + } +}; + +fn main() { + match FOO { + Bar { a: Foo { field: (5, 6) } } => {}, + FOO => unreachable!(), + _ => unreachable!(), + } +} From 98bf7376142633a6674668365d4ea47b9c5be287 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:04:46 +0200 Subject: [PATCH 085/109] s/intern/intern_shallow/ --- src/librustc_mir/interpret/intern.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index c450e3be1dda..9bbcd306651e 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -59,7 +59,8 @@ enum InternMode { struct IsStaticOrFn; impl<'rt, 'a, 'mir, 'tcx> InternVisitor<'rt, 'a, 'mir, 'tcx> { - fn intern( + /// Intern an allocation without looking at its children + fn intern_shallow( &mut self, ptr: Pointer, mutability: Mutability, @@ -152,7 +153,7 @@ for if let Ok(vtable) = meta.unwrap().to_ptr() { // explitly choose `Immutable` here, since vtables are immutable, even // if the reference of the fat pointer is mutable - self.intern(vtable, Mutability::Immutable)?; + self.intern_shallow(vtable, Mutability::Immutable)?; } } } @@ -206,7 +207,7 @@ for InternMode::ConstBase => InternMode::Const, other => other, }; - match self.intern(ptr, intern_mutability)? { + match self.intern_shallow(ptr, intern_mutability)? { // No need to recurse, these are interned already and statics may have // cycles, so we don't want to recurse there Some(IsStaticOrFn) => {}, @@ -270,7 +271,7 @@ pub fn intern_const_alloc_recursive( leftover_relocations, param_env, mutability, - }.intern(ret.ptr.to_ptr()?, alloc_mutability)?; + }.intern_shallow(ret.ptr.to_ptr()?, alloc_mutability)?; while let Some(((mplace, mutability, mode), _)) = ref_tracking.todo.pop() { let interned = InternVisitor { From 5734558881353d5f95454f44c81d71c2293d047d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:05:32 +0200 Subject: [PATCH 086/109] The future is now --- src/librustc_mir/interpret/intern.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index 9bbcd306651e..e43ebbffe90a 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -162,10 +162,6 @@ for // Check if we have encountered this pointer+layout combination before. // Only recurse for allocation-backed pointers. if let Scalar::Ptr(ptr) = mplace.ptr { - // In the future we will probably allow `& &mut T`, and thus will want to merge - // `mutability` with `self.mutability` to only choose `Mutable` if both are - // `Mutable`. - // We do not have any `frozen` logic here, because it's essentially equivalent to // the mutability except for the outermost item. Only `UnsafeCell` can "unfreeze", // and we check that in `visit_aggregate`. From a18d99abaafed676a3bf6bb0ccab37fd76ce931d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:05:56 +0200 Subject: [PATCH 087/109] Fix typo --- src/librustc_mir/interpret/intern.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index e43ebbffe90a..c78b73ddfcec 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -45,7 +45,7 @@ struct InternVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir> { #[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)] enum InternMode { /// Mutable references must in fact be immutable due to their surrounding immutability in a - /// `static`. In a `static mut` we start out as mutable and thus can also contain further `&mtu` + /// `static`. In a `static mut` we start out as mutable and thus can also contain further `&mut` /// that will actually be treated as mutable. Static, /// UnsafeCell is OK in the value of a constant, but not behind references in a constant From 521d38adb5610ac0b8da63469630f44691827a3f Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:17:50 +0200 Subject: [PATCH 088/109] Update to `TyCtxt` lifetime changes --- src/librustc_mir/interpret/intern.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index c78b73ddfcec..98598f0ca306 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -21,10 +21,10 @@ use super::{ }; use crate::const_eval::{CompileTimeInterpreter, CompileTimeEvalContext}; -struct InternVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir> { +struct InternVisitor<'rt, 'mir: 'rt, 'tcx: 'rt + 'mir> { /// previously encountered safe references ref_tracking: &'rt mut RefTracking<(MPlaceTy<'tcx>, Mutability, InternMode)>, - ecx: &'rt mut CompileTimeEvalContext<'a, 'mir, 'tcx>, + ecx: &'rt mut CompileTimeEvalContext<'mir, 'tcx>, param_env: ParamEnv<'tcx>, /// The root node of the value that we're looking at. This field is never mutated and only used /// for sanity assertions that will ICE when `const_qualif` screws up. @@ -58,7 +58,7 @@ enum InternMode { /// into the memory of other constants or statics struct IsStaticOrFn; -impl<'rt, 'a, 'mir, 'tcx> InternVisitor<'rt, 'a, 'mir, 'tcx> { +impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> { /// Intern an allocation without looking at its children fn intern_shallow( &mut self, @@ -103,15 +103,15 @@ impl<'rt, 'a, 'mir, 'tcx> InternVisitor<'rt, 'a, 'mir, 'tcx> { } } -impl<'rt, 'a, 'mir, 'tcx> - ValueVisitor<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>> +impl<'rt, 'mir, 'tcx> + ValueVisitor<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> for - InternVisitor<'rt, 'a, 'mir, 'tcx> + InternVisitor<'rt, 'mir, 'tcx> { type V = MPlaceTy<'tcx>; #[inline(always)] - fn ecx(&self) -> &CompileTimeEvalContext<'a, 'mir, 'tcx> { + fn ecx(&self) -> &CompileTimeEvalContext<'mir, 'tcx> { &self.ecx } @@ -220,8 +220,8 @@ for /// Figure out the mutability of the allocation. /// Mutable if it has interior mutability *anywhere* in the type. -fn intern_mutability<'a, 'tcx>( - tcx: TyCtxt<'a, 'tcx, 'tcx>, +fn intern_mutability<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, span: Span, @@ -236,7 +236,7 @@ fn intern_mutability<'a, 'tcx>( } pub fn intern_const_alloc_recursive( - ecx: &mut CompileTimeEvalContext<'a, 'mir, 'tcx>, + ecx: &mut CompileTimeEvalContext<'mir, 'tcx>, def_id: DefId, ret: MPlaceTy<'tcx>, // FIXME(oli-obk): can we scrap the param env? I think we can, the final value of a const eval From 6229a8f1f6853491808e960a8a88d4396dc391d0 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:18:10 +0200 Subject: [PATCH 089/109] Elaborate some more on what mutability field means what --- src/librustc_mir/interpret/intern.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index 98598f0ca306..6ce97ed99ab7 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -181,6 +181,8 @@ for (InternMode::Const, hir::Mutability::MutMutable) => bug!("const qualif failed to prevent mutable references"), } + // Compute the mutability with which we'll start visiting the allocation. This is + // what gets changed when we encounter an `UnsafeCell` let mutability = match (self.mutability, mutability) { // The only way a mutable reference actually works as a mutable reference is // by being in a `static mut` directly or behind another mutable reference. @@ -190,6 +192,7 @@ for (Mutability::Mutable, hir::Mutability::MutMutable) => Mutability::Mutable, _ => Mutability::Immutable, }; + // Compute the mutability of the allocation let intern_mutability = intern_mutability( self.ecx.tcx.tcx, self.param_env, @@ -244,6 +247,7 @@ pub fn intern_const_alloc_recursive( param_env: ty::ParamEnv<'tcx>, ) -> InterpResult<'tcx> { let tcx = ecx.tcx; + // this `mutability` is the mutability of the place, ignoring the type let (mutability, base_intern_mode) = match tcx.static_mutability(def_id) { Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static), None => (Mutability::Immutable, InternMode::ConstBase), @@ -255,6 +259,10 @@ pub fn intern_const_alloc_recursive( let mut ref_tracking = RefTracking::new((ret, mutability, base_intern_mode)); let leftover_relocations = &mut FxHashSet::default(); + // This mutability is the combination of the place mutability and the type mutability. If either + // is mutable, `alloc_mutability` is mutable. This exists because the entire allocation needs + // to be mutable if it contains an `UnsafeCell` anywhere. The other `mutability` exists so that + // the visitor does not treat everything outside the `UnsafeCell` as mutable. let alloc_mutability = intern_mutability( tcx.tcx, param_env, ret.layout.ty, tcx.span, mutability, ); From 667f94cb247ae826563ad185170747dc0ac8d658 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:41:25 +0200 Subject: [PATCH 090/109] Update ui test output --- src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr index f695ce30f19f..ff2351e1fdc5 100644 --- a/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr +++ b/src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr @@ -6,7 +6,7 @@ LL | *MUH.x.get() = 99; thread 'rustc' panicked at 'assertion failed: `(left != right)` left: `Const`, - right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites may arbitrarily decide to change, too.', src/librustc_mir/interpret/intern.rs:126:17 + right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites may arbitrarily decide to change, too.', src/librustc_mir/interpret/intern.rs:127:17 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. error: internal compiler error: unexpected panic From 921f0d9ca919245dfce2e0e672601619e7b0bf58 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Jun 2019 17:54:54 +0200 Subject: [PATCH 091/109] Outright ignore any alignment in `const_field` --- src/librustc_mir/const_eval.rs | 6 ++---- src/librustc_mir/interpret/operand.rs | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index d6c0744b4e8a..2b1e56e97fc5 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -483,11 +483,9 @@ pub fn const_field<'tcx>( let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env); // get the operand again let mut op = ecx.eval_const_to_op(value, None).unwrap(); - // adjust the alignment of `op` to the one of the allocation, since it may be a field of a + // Ignore the alignment when accessing the field, since it may be a field of a // packed struct and thus end up causing an alignment error if we read from it. - if let ConstValue::ByRef(_, alloc) = value.val { - op.force_alignment(alloc.align); - } + op.force_unaligned_access(); // downcast let down = match variant { None => op, diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 8e0260988505..04473bcb8e14 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -185,11 +185,9 @@ impl<'tcx, Tag> OpTy<'tcx, Tag> { /// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful, /// since the alignment is already encoded in the allocation. We know it is alright, because /// validation checked everything before the initial constant entered match checking. - pub(crate) fn force_alignment(&mut self, align: Align) { + pub(crate) fn force_unaligned_access(&mut self) { if let Operand::Indirect(mplace) = &mut self.op { - if align < mplace.align { - mplace.align = align; - } + mplace.align = Align::from_bytes(1).unwrap(); } } } From fb37bf0037833026c3ffe6ec1fe3367fec5a5e0e Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 14 Jun 2019 11:29:52 +0200 Subject: [PATCH 092/109] Weave the alignment through `ByRef` --- src/librustc/mir/interpret/value.rs | 6 ++++-- src/librustc/ty/structural_impls.rs | 2 +- src/librustc_codegen_llvm/common.rs | 7 ++++--- src/librustc_codegen_llvm/consts.rs | 4 +++- src/librustc_codegen_ssa/mir/operand.rs | 4 ++-- src/librustc_codegen_ssa/mir/place.rs | 4 ++-- src/librustc_codegen_ssa/traits/consts.rs | 1 + src/librustc_mir/const_eval.rs | 15 ++++++++------- src/librustc_mir/hair/pattern/_match.rs | 17 +++++++++++------ src/librustc_mir/interpret/operand.rs | 19 +++---------------- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- 12 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index f7b3385668f7..904576a2c1d5 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -2,7 +2,7 @@ use std::fmt; use rustc_macros::HashStable; use rustc_apfloat::{Float, ieee::{Double, Single}}; -use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size}, subst::SubstsRef}; +use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size, Align}, subst::SubstsRef}; use crate::ty::PlaceholderConst; use crate::hir::def_id::DefId; @@ -45,7 +45,9 @@ pub enum ConstValue<'tcx> { /// An allocation together with a pointer into the allocation. /// Invariant: the pointer's `AllocId` resolves to the allocation. - ByRef(Pointer, &'tcx Allocation), + /// The alignment exists to allow `const_field` to have `ByRef` access to nonprimitive fields + /// of packed structs. + ByRef(Pointer, Align, &'tcx Allocation), /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other /// variants when the code is monomorphic enough for that. diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index a4efb566e13e..4cd0fd3e824f 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -1335,7 +1335,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> { fn super_fold_with>(&self, folder: &mut F) -> Self { match *self { - ConstValue::ByRef(ptr, alloc) => ConstValue::ByRef(ptr, alloc), + ConstValue::ByRef(ptr, align, alloc) => ConstValue::ByRef(ptr, align, alloc), ConstValue::Infer(ic) => ConstValue::Infer(ic.fold_with(folder)), ConstValue::Param(p) => ConstValue::Param(p.fold_with(folder)), ConstValue::Placeholder(p) => ConstValue::Placeholder(p), diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 0b23aac5224c..f21f203fcc99 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -11,7 +11,7 @@ use crate::value::Value; use rustc_codegen_ssa::traits::*; use crate::consts::const_alloc_to_llvm; -use rustc::ty::layout::{HasDataLayout, LayoutOf, self, TyLayout, Size}; +use rustc::ty::layout::{HasDataLayout, LayoutOf, self, TyLayout, Size, Align}; use rustc::mir::interpret::{Scalar, GlobalAlloc, Allocation}; use rustc_codegen_ssa::mir::place::PlaceRef; @@ -344,11 +344,12 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn from_const_alloc( &self, layout: TyLayout<'tcx>, + align: Align, alloc: &Allocation, offset: Size, ) -> PlaceRef<'tcx, &'ll Value> { let init = const_alloc_to_llvm(self, alloc); - let base_addr = self.static_addr_of(init, layout.align.abi, None); + let base_addr = self.static_addr_of(init, align, None); let llval = unsafe { llvm::LLVMConstInBoundsGEP( self.const_bitcast(base_addr, self.type_i8p()), @@ -356,7 +357,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { 1, )}; let llval = self.const_bitcast(llval, self.type_ptr_to(layout.llvm_type(self))); - PlaceRef::new_sized(llval, layout, alloc.align) + PlaceRef::new_sized(llval, layout, align) } fn const_ptrcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value { diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index eb059ac453c3..4bf91bbed60e 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -71,7 +71,9 @@ pub fn codegen_static_initializer( let static_ = cx.tcx.const_eval(param_env.and(cid))?; let alloc = match static_.val { - ConstValue::ByRef(ptr, alloc) if ptr.offset.bytes() == 0 => alloc, + ConstValue::ByRef(ptr, align, alloc) if ptr.offset.bytes() == 0 && align == alloc.align => { + alloc + }, _ => bug!("static const eval returned {:#?}", static_), }; Ok((const_alloc_to_llvm(cx, alloc), alloc)) diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs index 3305dfe1ffbb..c1626d31c780 100644 --- a/src/librustc_codegen_ssa/mir/operand.rs +++ b/src/librustc_codegen_ssa/mir/operand.rs @@ -109,8 +109,8 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { let b_llval = bx.const_usize((end - start) as u64); OperandValue::Pair(a_llval, b_llval) }, - ConstValue::ByRef(ptr, alloc) => { - return bx.load_operand(bx.from_const_alloc(layout, alloc, ptr.offset)); + ConstValue::ByRef(ptr, align, alloc) => { + return bx.load_operand(bx.from_const_alloc(layout, align, alloc, ptr.offset)); }, }; diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index 81b17d0bee80..72aedb4812a2 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -424,8 +424,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let layout = cx.layout_of(self.monomorphize(&ty)); match bx.tcx().const_eval(param_env.and(cid)) { Ok(val) => match val.val { - mir::interpret::ConstValue::ByRef(ptr, alloc) => { - bx.cx().from_const_alloc(layout, alloc, ptr.offset) + mir::interpret::ConstValue::ByRef(ptr, align, alloc) => { + bx.cx().from_const_alloc(layout, align, alloc, ptr.offset) } _ => bug!("promoteds should have an allocation: {:?}", val), }, diff --git a/src/librustc_codegen_ssa/traits/consts.rs b/src/librustc_codegen_ssa/traits/consts.rs index 32412f303c15..46286b5329e4 100644 --- a/src/librustc_codegen_ssa/traits/consts.rs +++ b/src/librustc_codegen_ssa/traits/consts.rs @@ -34,6 +34,7 @@ pub trait ConstMethods<'tcx>: BackendTypes { fn from_const_alloc( &self, layout: layout::TyLayout<'tcx>, + align: layout::Align, alloc: &Allocation, offset: layout::Size, ) -> PlaceRef<'tcx, Self::Value>; diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 2b1e56e97fc5..284a8f40e1f3 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -99,7 +99,7 @@ fn op_to_const<'tcx>( Ok(mplace) => { let ptr = mplace.ptr.to_ptr().unwrap(); let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); - ConstValue::ByRef(ptr, alloc) + ConstValue::ByRef(ptr, mplace.align, alloc) }, // see comment on `let try_as_immediate` above Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x { @@ -113,7 +113,7 @@ fn op_to_const<'tcx>( let mplace = op.to_mem_place(); let ptr = mplace.ptr.to_ptr().unwrap(); let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); - ConstValue::ByRef(ptr, alloc) + ConstValue::ByRef(ptr, mplace.align, alloc) }, }, Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => { @@ -482,10 +482,7 @@ pub fn const_field<'tcx>( trace!("const_field: {:?}, {:?}", field, value); let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env); // get the operand again - let mut op = ecx.eval_const_to_op(value, None).unwrap(); - // Ignore the alignment when accessing the field, since it may be a field of a - // packed struct and thus end up causing an alignment error if we read from it. - op.force_unaligned_access(); + let op = ecx.eval_const_to_op(value, None).unwrap(); // downcast let down = match variant { None => op, @@ -544,7 +541,11 @@ fn validate_and_turn_into_const<'tcx>( if tcx.is_static(def_id) || cid.promoted.is_some() { let ptr = mplace.ptr.to_ptr()?; Ok(tcx.mk_const(ty::Const { - val: ConstValue::ByRef(ptr, ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id)), + val: ConstValue::ByRef( + ptr, + mplace.align, + ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id), + ), ty: mplace.layout.ty, })) } else { diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 1fcdf7133725..71daae5a7096 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -215,10 +215,15 @@ impl LiteralExpander<'tcx> { debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty); match (val, &crty.sty, &rty.sty) { // the easy case, deref a reference - (ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => ConstValue::ByRef( - p, - self.tcx.alloc_map.lock().unwrap_memory(p.alloc_id), - ), + (ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => { + let alloc = self.tcx.alloc_map.lock().unwrap_memory(p.alloc_id); + ConstValue::ByRef( + p, + // FIXME(oli-obk): this should be the type's layout + alloc.align, + alloc, + ) + }, // unsize array to slice if pattern is array but match value or other patterns are slice (ConstValue::Scalar(Scalar::Ptr(p)), ty::Array(t, n), ty::Slice(u)) => { assert_eq!(t, u); @@ -1431,7 +1436,7 @@ fn slice_pat_covered_by_const<'tcx>( suffix: &[Pattern<'tcx>], ) -> Result { let data: &[u8] = match (const_val.val, &const_val.ty.sty) { - (ConstValue::ByRef(ptr, alloc), ty::Array(t, n)) => { + (ConstValue::ByRef(ptr, _, alloc), ty::Array(t, n)) => { assert_eq!(*t, tcx.types.u8); let n = n.assert_usize(tcx).unwrap(); alloc.get_bytes(&tcx, ptr, Size::from_bytes(n)).unwrap() @@ -1753,7 +1758,7 @@ fn specialize<'p, 'a: 'p, 'tcx>( let (alloc, offset, n, ty) = match value.ty.sty { ty::Array(t, n) => { match value.val { - ConstValue::ByRef(ptr, alloc) => ( + ConstValue::ByRef(ptr, _, alloc) => ( alloc, ptr.offset, n.unwrap_usize(cx.tcx), diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 04473bcb8e14..1b451e0b8f18 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -5,7 +5,7 @@ use std::convert::TryInto; use rustc::{mir, ty}; use rustc::ty::layout::{ - self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx, Align, + self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx, }; use rustc::mir::interpret::{ @@ -179,19 +179,6 @@ impl<'tcx, Tag> From> for OpTy<'tcx, Tag> { } } -impl<'tcx, Tag> OpTy<'tcx, Tag> { - /// This function exists solely for pattern matching. If we pattern match a packed struct with - /// an ADT field, the constant representing that field will have lost the information about the - /// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful, - /// since the alignment is already encoded in the allocation. We know it is alright, because - /// validation checked everything before the initial constant entered match checking. - pub(crate) fn force_unaligned_access(&mut self) { - if let Operand::Indirect(mplace) = &mut self.op { - mplace.align = Align::from_bytes(1).unwrap(); - } - } -} - impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { #[inline] @@ -551,11 +538,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { self.layout_of(self.monomorphize(val.ty)?) })?; let op = match val.val { - ConstValue::ByRef(ptr, _alloc) => { + ConstValue::ByRef(ptr, align, _alloc) => { // We rely on mutability being set correctly in that allocation to prevent writes // where none should happen. let ptr = self.tag_static_base_pointer(ptr); - Operand::Indirect(MemPlace::from_ptr(ptr, layout.align.abi)) + Operand::Indirect(MemPlace::from_ptr(ptr, align)) }, ConstValue::Scalar(x) => Operand::Immediate(Immediate::Scalar(tag_scalar(x).into())), diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index acc786050a84..c64bb73802dc 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -1262,7 +1262,7 @@ fn collect_const<'tcx>( ConstValue::Scalar(Scalar::Ptr(ptr)) => collect_miri(tcx, ptr.alloc_id, output), ConstValue::Slice { data: alloc, start: _, end: _ } | - ConstValue::ByRef(_, alloc) => { + ConstValue::ByRef(_, _, alloc) => { for &((), id) in alloc.relocations.values() { collect_miri(tcx, id, output); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 864f19933a5f..1c0b77b2778c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1448,7 +1448,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: DefId, span: Span) }; let param_env = ty::ParamEnv::reveal_all(); if let Ok(static_) = tcx.const_eval(param_env.and(cid)) { - let alloc = if let ConstValue::ByRef(_, allocation) = static_.val { + let alloc = if let ConstValue::ByRef(_, _, allocation) = static_.val { allocation } else { bug!("Matching on non-ByRef static") From fd426a6ae9b9470bcfee19c251d60b5a2c2c6048 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 19 Jun 2019 09:57:07 +0200 Subject: [PATCH 093/109] Explain existance of `Align` field --- src/librustc/mir/interpret/value.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 904576a2c1d5..7b26ebf57a12 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -46,7 +46,10 @@ pub enum ConstValue<'tcx> { /// An allocation together with a pointer into the allocation. /// Invariant: the pointer's `AllocId` resolves to the allocation. /// The alignment exists to allow `const_field` to have `ByRef` access to nonprimitive fields - /// of packed structs. + /// of packed structs. The alignment may be lower than the alignment of the `Allocation` and + /// allow reads with lower alignment than what the allocation would normally permit. + /// FIXME(RalfJ,oli-obk): The alignment checks are part of miri, but const eval doesn't really + /// need them. Disabling them may be too hard though. ByRef(Pointer, Align, &'tcx Allocation), /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other From 0b58bb32f66f4ec5f00683293093d94d8fb1aada Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 5 Jun 2019 17:59:37 +0300 Subject: [PATCH 094/109] Support `cfg` and `cfg_attr` on generic parameters --- src/libsyntax/config.rs | 20 ++---- src/libsyntax/ext/expand.rs | 6 +- .../cfg-generic-params.rs | 38 +++++++++++ .../cfg-generic-params.stderr | 66 +++++++++++++++++++ src/test/ui/issues/issue-51279.rs | 27 -------- src/test/ui/issues/issue-51279.stderr | 60 ----------------- 6 files changed, 111 insertions(+), 106 deletions(-) create mode 100644 src/test/ui/conditional-compilation/cfg-generic-params.rs create mode 100644 src/test/ui/conditional-compilation/cfg-generic-params.stderr delete mode 100644 src/test/ui/issues/issue-51279.rs delete mode 100644 src/test/ui/issues/issue-51279.stderr diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 1cc13ac7878b..3b42e1de6149 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -240,6 +240,10 @@ impl<'a> StripUnconfigured<'a> { items.flat_map_in_place(|item| self.configure(item)); } + pub fn configure_generic_params(&mut self, params: &mut Vec) { + params.flat_map_in_place(|param| self.configure(param)); + } + fn configure_variant_data(&mut self, vdata: &mut ast::VariantData) { match vdata { ast::VariantData::Struct(fields, ..) | ast::VariantData::Tuple(fields, _) => @@ -301,22 +305,6 @@ impl<'a> StripUnconfigured<'a> { pub fn configure_fn_decl(&mut self, fn_decl: &mut ast::FnDecl) { fn_decl.inputs.flat_map_in_place(|arg| self.configure(arg)); } - - /// Denies `#[cfg]` on generic parameters until we decide what to do with it. - /// See issue #51279. - pub fn disallow_cfg_on_generic_param(&mut self, param: &ast::GenericParam) { - for attr in param.attrs() { - let offending_attr = if attr.check_name(sym::cfg) { - "cfg" - } else if attr.check_name(sym::cfg_attr) { - "cfg_attr" - } else { - continue; - }; - let msg = format!("#[{}] cannot be applied on a generic parameter", offending_attr); - self.sess.span_diagnostic.span_err(attr.span, &msg); - } - } } impl<'a> MutVisitor for StripUnconfigured<'a> { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d433e6c5a896..a71d1d503cab 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1439,9 +1439,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } } - fn visit_generic_param(&mut self, param: &mut ast::GenericParam) { - self.cfg.disallow_cfg_on_generic_param(¶m); - noop_visit_generic_param(param, self) + fn visit_generic_params(&mut self, params: &mut Vec) { + self.cfg.configure_generic_params(params); + noop_visit_generic_params(params, self); } fn visit_attribute(&mut self, at: &mut ast::Attribute) { diff --git a/src/test/ui/conditional-compilation/cfg-generic-params.rs b/src/test/ui/conditional-compilation/cfg-generic-params.rs new file mode 100644 index 000000000000..d80d3ea7b7fe --- /dev/null +++ b/src/test/ui/conditional-compilation/cfg-generic-params.rs @@ -0,0 +1,38 @@ +// compile-flags:--cfg yes + +fn f_lt<#[cfg(yes)] 'a: 'a, #[cfg(no)] T>() {} +fn f_ty<#[cfg(no)] 'a: 'a, #[cfg(yes)] T>() {} + +type FnGood = for<#[cfg(yes)] 'a, #[cfg(no)] T> fn(); // OK +type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn(); +//~^ ERROR only lifetime parameters can be used in this context + +type PolyGood = dyn for<#[cfg(yes)] 'a, #[cfg(no)] T> Copy; // OK +type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy; +//~^ ERROR only lifetime parameters can be used in this context + +struct WhereGood where for<#[cfg(yes)] 'a, #[cfg(no)] T> u8: Copy; // OK +struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy; +//~^ ERROR only lifetime parameters can be used in this context + +fn f_lt_no<#[cfg_attr(no, unknown)] 'a>() {} // OK +fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {} //~ ERROR attribute `unknown` is currently unknown +fn f_ty_no<#[cfg_attr(no, unknown)] T>() {} // OK +fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {} //~ ERROR attribute `unknown` is currently unknown + +type FnNo = for<#[cfg_attr(no, unknown)] 'a> fn(); // OK +type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn(); +//~^ ERROR attribute `unknown` is currently unknown + +type PolyNo = dyn for<#[cfg_attr(no, unknown)] 'a> Copy; // OK +type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy; +//~^ ERROR attribute `unknown` is currently unknown + +struct WhereNo where for<#[cfg_attr(no, unknown)] 'a> u8: Copy; // OK +struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy; +//~^ ERROR attribute `unknown` is currently unknown + +fn main() { + f_lt::<'static>(); + f_ty::(); +} diff --git a/src/test/ui/conditional-compilation/cfg-generic-params.stderr b/src/test/ui/conditional-compilation/cfg-generic-params.stderr new file mode 100644 index 000000000000..40ca44d9db59 --- /dev/null +++ b/src/test/ui/conditional-compilation/cfg-generic-params.stderr @@ -0,0 +1,66 @@ +error: only lifetime parameters can be used in this context + --> $DIR/cfg-generic-params.rs:7:45 + | +LL | type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn(); + | ^ + +error: only lifetime parameters can be used in this context + --> $DIR/cfg-generic-params.rs:11:51 + | +LL | type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy; + | ^ + +error: only lifetime parameters can be used in this context + --> $DIR/cfg-generic-params.rs:15:54 + | +LL | struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy; + | ^ + +error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/cfg-generic-params.rs:19:29 + | +LL | fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {} + | ^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/cfg-generic-params.rs:21:29 + | +LL | fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {} + | ^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/cfg-generic-params.rs:24:34 + | +LL | type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn(); + | ^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/cfg-generic-params.rs:28:40 + | +LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy; + | ^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/cfg-generic-params.rs:32:43 + | +LL | struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy; + | ^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/issues/issue-51279.rs b/src/test/ui/issues/issue-51279.rs deleted file mode 100644 index f8f3626caabe..000000000000 --- a/src/test/ui/issues/issue-51279.rs +++ /dev/null @@ -1,27 +0,0 @@ -pub struct X<#[cfg(none)] 'a, #[cfg(none)] T>(&'a T); -//~^ ERROR #[cfg] cannot be applied on a generic parameter -//~^^ ERROR #[cfg] cannot be applied on a generic parameter - -impl<#[cfg(none)] 'a, #[cfg(none)] T> X<'a, T> {} -//~^ ERROR #[cfg] cannot be applied on a generic parameter -//~^^ ERROR #[cfg] cannot be applied on a generic parameter - -pub fn f<#[cfg(none)] 'a, #[cfg(none)] T>(_: &'a T) {} -//~^ ERROR #[cfg] cannot be applied on a generic parameter -//~^^ ERROR #[cfg] cannot be applied on a generic parameter - -#[cfg(none)] -pub struct Y<#[cfg(none)] T>(T); // shouldn't care when the entire item is stripped out - -struct M(*const T); - -impl<#[cfg_attr(none, may_dangle)] T> Drop for M { - //~^ ERROR #[cfg_attr] cannot be applied on a generic parameter - fn drop(&mut self) {} -} - -type Z<#[ignored] 'a, #[cfg(none)] T> = X<'a, T>; -//~^ ERROR #[cfg] cannot be applied on a generic parameter -//~| ERROR attribute `ignored` is currently unknown to the compiler - -fn main() {} diff --git a/src/test/ui/issues/issue-51279.stderr b/src/test/ui/issues/issue-51279.stderr deleted file mode 100644 index 9dd4a9f23814..000000000000 --- a/src/test/ui/issues/issue-51279.stderr +++ /dev/null @@ -1,60 +0,0 @@ -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:1:14 - | -LL | pub struct X<#[cfg(none)] 'a, #[cfg(none)] T>(&'a T); - | ^^^^^^^^^^^^ - -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:1:31 - | -LL | pub struct X<#[cfg(none)] 'a, #[cfg(none)] T>(&'a T); - | ^^^^^^^^^^^^ - -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:5:6 - | -LL | impl<#[cfg(none)] 'a, #[cfg(none)] T> X<'a, T> {} - | ^^^^^^^^^^^^ - -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:5:23 - | -LL | impl<#[cfg(none)] 'a, #[cfg(none)] T> X<'a, T> {} - | ^^^^^^^^^^^^ - -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:9:10 - | -LL | pub fn f<#[cfg(none)] 'a, #[cfg(none)] T>(_: &'a T) {} - | ^^^^^^^^^^^^ - -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:9:27 - | -LL | pub fn f<#[cfg(none)] 'a, #[cfg(none)] T>(_: &'a T) {} - | ^^^^^^^^^^^^ - -error: #[cfg_attr] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:18:6 - | -LL | impl<#[cfg_attr(none, may_dangle)] T> Drop for M { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: #[cfg] cannot be applied on a generic parameter - --> $DIR/issue-51279.rs:23:23 - | -LL | type Z<#[ignored] 'a, #[cfg(none)] T> = X<'a, T>; - | ^^^^^^^^^^^^ - -error[E0658]: The attribute `ignored` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/issue-51279.rs:23:8 - | -LL | type Z<#[ignored] 'a, #[cfg(none)] T> = X<'a, T>; - | ^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/29642 - = help: add #![feature(custom_attribute)] to the crate attributes to enable - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0658`. From 62af19b614267e949ed7a3da0be9ffa2a40de2fa Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 19 Jun 2019 10:03:53 +0200 Subject: [PATCH 095/109] More FIXMEs --- src/librustc_mir/interpret/memory.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index ff33dccdfeaf..f2a115f8f359 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -56,6 +56,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// the wrong type), so we let the machine override this type. /// Either way, if the machine allows writing to a static, doing so will /// create a copy of the static allocation here. + // FIXME: this should not be public, but interning currently needs access to it pub(super) alloc_map: M::MemoryMap, /// To be able to compare pointers with NULL, and to check alignment for accesses From c917ba325f3e7944eefb5e906ca0392c9b499541 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 19 Jun 2019 10:07:07 +0200 Subject: [PATCH 096/109] adt hint pointing to adt span --- src/librustc_typeck/check/expr.rs | 5 +++-- src/test/ui/issues/issue-4736.stderr | 7 +++---- src/test/ui/numeric/numeric-fields.stderr | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 8edda805592a..3c31e0124031 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1125,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit(); } else { - self.report_unknown_field(adt_ty, variant, field, ast_fields, kind_name); + self.report_unknown_field(adt_ty, variant, field, ast_fields, kind_name, span); } tcx.types.err @@ -1196,6 +1196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { field: &hir::Field, skip_fields: &[hir::Field], kind_name: &str, + ty_span: Span ) { if variant.recovered { return; @@ -1218,7 +1219,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match variant.ctor_kind { CtorKind::Fn => { err.span_label(field.ident.span, "field does not exist"); - err.span_label(field.ident.span, format!( + err.span_label(ty_span, format!( "`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`", adt=ty, kind_name=kind_name diff --git a/src/test/ui/issues/issue-4736.stderr b/src/test/ui/issues/issue-4736.stderr index 557ee5593f37..6786b592d985 100644 --- a/src/test/ui/issues/issue-4736.stderr +++ b/src/test/ui/issues/issue-4736.stderr @@ -2,10 +2,9 @@ error[E0560]: struct `NonCopyable` has no field named `p` --> $DIR/issue-4736.rs:4:26 | LL | let z = NonCopyable{ p: () }; - | ^ - | | - | field does not exist - | `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)` + | ----------- ^ field does not exist + | | + | `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)` error: aborting due to previous error diff --git a/src/test/ui/numeric/numeric-fields.stderr b/src/test/ui/numeric/numeric-fields.stderr index fef7486b8536..e71af0f33ee4 100644 --- a/src/test/ui/numeric/numeric-fields.stderr +++ b/src/test/ui/numeric/numeric-fields.stderr @@ -2,10 +2,9 @@ error[E0560]: struct `S` has no field named `0b1` --> $DIR/numeric-fields.rs:4:15 | LL | let s = S{0b1: 10, 0: 11}; - | ^^^ - | | - | field does not exist - | `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)` + | - ^^^ field does not exist + | | + | `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)` error[E0026]: struct `S` does not have a field named `0x1` --> $DIR/numeric-fields.rs:7:17 From 3977cc2b3760d786b6722f1b7f705e57a63fb96e Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 19 Jun 2019 10:34:32 +0200 Subject: [PATCH 097/109] Remove now-unnecessary lifetime --- src/librustc_mir/interpret/intern.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index 6ce97ed99ab7..d998f40c86ec 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -224,7 +224,7 @@ for /// Figure out the mutability of the allocation. /// Mutable if it has interior mutability *anywhere* in the type. fn intern_mutability<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, + tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, span: Span, From 70e52f84186ee017d19d26e081ab8688beee9b37 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 19 Jun 2019 11:09:17 +0200 Subject: [PATCH 098/109] provide variant definition on tuple struct unknow field error --- src/librustc_typeck/check/expr.rs | 4 +++- src/test/ui/issues/issue-4736.stderr | 5 ++++- src/test/ui/numeric/numeric-fields.stderr | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 3c31e0124031..d659169711f2 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1218,9 +1218,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty); match variant.ctor_kind { CtorKind::Fn => { + err.span_label(variant.ident.span, format!("`{adt}` defined here", adt=ty)); err.span_label(field.ident.span, "field does not exist"); err.span_label(ty_span, format!( - "`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`", + "`{adt}` is a tuple {kind_name},\ + use the appropriate syntax: `{adt}(/* fields */)`", adt=ty, kind_name=kind_name )); diff --git a/src/test/ui/issues/issue-4736.stderr b/src/test/ui/issues/issue-4736.stderr index 6786b592d985..557607503efa 100644 --- a/src/test/ui/issues/issue-4736.stderr +++ b/src/test/ui/issues/issue-4736.stderr @@ -1,10 +1,13 @@ error[E0560]: struct `NonCopyable` has no field named `p` --> $DIR/issue-4736.rs:4:26 | +LL | struct NonCopyable(()); + | ----------- `NonCopyable` defined here +... LL | let z = NonCopyable{ p: () }; | ----------- ^ field does not exist | | - | `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)` + | `NonCopyable` is a tuple struct,use the appropriate syntax: `NonCopyable(/* fields */)` error: aborting due to previous error diff --git a/src/test/ui/numeric/numeric-fields.stderr b/src/test/ui/numeric/numeric-fields.stderr index e71af0f33ee4..ad1f1177f7be 100644 --- a/src/test/ui/numeric/numeric-fields.stderr +++ b/src/test/ui/numeric/numeric-fields.stderr @@ -1,10 +1,13 @@ error[E0560]: struct `S` has no field named `0b1` --> $DIR/numeric-fields.rs:4:15 | +LL | struct S(u8, u16); + | - `S` defined here +... LL | let s = S{0b1: 10, 0: 11}; | - ^^^ field does not exist | | - | `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)` + | `S` is a tuple struct,use the appropriate syntax: `S(/* fields */)` error[E0026]: struct `S` does not have a field named `0x1` --> $DIR/numeric-fields.rs:7:17 From ce39fff66be0ef298927c75c69a36a841230129f Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 19 Jun 2019 11:15:29 +0200 Subject: [PATCH 099/109] Fix comment about alignments --- src/librustc/mir/interpret/value.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 7b26ebf57a12..7fc1344533e0 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -46,8 +46,8 @@ pub enum ConstValue<'tcx> { /// An allocation together with a pointer into the allocation. /// Invariant: the pointer's `AllocId` resolves to the allocation. /// The alignment exists to allow `const_field` to have `ByRef` access to nonprimitive fields - /// of packed structs. The alignment may be lower than the alignment of the `Allocation` and - /// allow reads with lower alignment than what the allocation would normally permit. + /// of packed structs. The alignment may be lower than the type of this constant. + /// This permits reads with lower alignment than what the type would normally require. /// FIXME(RalfJ,oli-obk): The alignment checks are part of miri, but const eval doesn't really /// need them. Disabling them may be too hard though. ByRef(Pointer, Align, &'tcx Allocation), From cd290c7ee9cc00413116f402823475ed5735293a Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 19 Jun 2019 11:20:38 +0200 Subject: [PATCH 100/109] packed -> repr(packed) --- src/librustc/mir/interpret/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 7fc1344533e0..40e811199736 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -46,7 +46,7 @@ pub enum ConstValue<'tcx> { /// An allocation together with a pointer into the allocation. /// Invariant: the pointer's `AllocId` resolves to the allocation. /// The alignment exists to allow `const_field` to have `ByRef` access to nonprimitive fields - /// of packed structs. The alignment may be lower than the type of this constant. + /// of `repr(packed)` structs. The alignment may be lower than the type of this constant. /// This permits reads with lower alignment than what the type would normally require. /// FIXME(RalfJ,oli-obk): The alignment checks are part of miri, but const eval doesn't really /// need them. Disabling them may be too hard though. From 5a411a65d0eb9cc19f4edd21b94fd76d7e39f705 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 18 Jun 2019 21:15:19 +0900 Subject: [PATCH 101/109] Update rustfmt and rls Update rustfmt to 1.3.0. --- Cargo.lock | 186 ++++++++++++++++++++++++++-------------------- src/tools/rls | 2 +- src/tools/rustfmt | 2 +- 3 files changed, 106 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 403fe4101eb7..9af1c28b3c2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -813,14 +813,6 @@ dependencies = [ "strum_macros 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ena" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ena" version = "0.13.0" @@ -2136,7 +2128,7 @@ dependencies = [ [[package]] name = "racer" -version = "2.1.22" +version = "2.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2147,7 +2139,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2375,7 +2367,7 @@ dependencies = [ "lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ordslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "racer 2.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "racer 2.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2388,7 +2380,7 @@ dependencies = [ "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0", "rustc_tools_util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfmt-nightly 1.2.2", + "rustfmt-nightly 1.3.0", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2499,20 +2491,21 @@ dependencies = [ [[package]] name = "rustc-ap-arena" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-graphviz" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc-ap-rustc_cratesio_shim" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2522,85 +2515,104 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_data_structures" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "jobserver 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-graphviz 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-graphviz 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-rayon 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-rayon-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-rustc_errors" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "annotate-snippets 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-ap-rustc_macros" +version = "491.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-ap-rustc_target" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-serialize" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-syntax" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_errors 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_errors 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_macros 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-syntax_pos" -version = "407.0.0" +version = "491.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-arena 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-arena 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_macros 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2632,16 +2644,6 @@ dependencies = [ "rustc_target 0.0.0", ] -[[package]] -name = "rustc-rayon" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-rayon" version = "0.2.0" @@ -2652,17 +2654,6 @@ dependencies = [ "rustc-rayon-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-rayon-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-rayon-core" version = "0.2.0" @@ -3212,9 +3203,19 @@ dependencies = [ "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustfmt-config_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustfmt-nightly" -version = "1.2.2" +version = "1.3.0" dependencies = [ "annotate-snippets 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3231,13 +3232,14 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0", + "rustfmt-config_proc_macro 0.1.0", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3489,6 +3491,26 @@ name = "strsim" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "structopt" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "structopt-derive" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "strum" version = "0.11.0" @@ -4344,7 +4366,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum dlmalloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f283302e035e61c23f2b86b3093e8c6273a4c3125742d6087e96ade001ca5e63" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum elasticlunr-rs 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a99a310cd1f9770e7bf8e48810c7bcbb0e078c8fb23a8c7bcf0da4c2bf61a455" -"checksum ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f56c93cc076508c549d9bb747f79aa9b4eb098be7b8cad8830c3137ef52d1e00" "checksum ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc01d68e08ca384955a3aeba9217102ca1aa85b6e168639bf27739f1d749d87" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e" @@ -4483,7 +4504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" -"checksum racer 2.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4323343f25bc372dc9293ac6b5cd3034b32784af1e7de9366b4db71466d8c7" +"checksum racer 2.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "94dbdea3d959d8f76a2e303b3eadf107fd76da886b231291e649168613d432fb" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a" "checksum rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "771b009e3a508cb67e8823dda454aaa5368c7bc1c16829fb77d3e980440dd34a" @@ -4510,20 +4531,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rls-data 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "76c72ea97e045be5f6290bb157ebdc5ee9f2b093831ff72adfaf59025cf5c491" "checksum rls-span 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f1cb4694410d8d2ce43ccff3682f1c782158a018d5a9a92185675677f7533eb3" "checksum rls-vfs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce4b57b25b4330ed5ec14028fc02141e083ddafda327e7eb598dc0569c8c83c9" -"checksum rustc-ap-arena 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5aab2fb5e5becf1c9183f6c63b8714817a3e780a20b4fe6b3920751c98a18225" -"checksum rustc-ap-graphviz 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0235ff613d4f96176ea56748010b5d8e978605cc47856ba9bb5372f4f38e9c03" -"checksum rustc-ap-rustc_cratesio_shim 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63e04a90b0dd8597da83633961698c61a2948f50c9d4b9a71e8afafc0ba0f158" -"checksum rustc-ap-rustc_data_structures 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c03988d65fc5130787df32e8ea91738f78a8ed62b7a5bdd77f10e5cceb531d8e" -"checksum rustc-ap-rustc_errors 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b33b9dc34f9fa50bf7e6fd14f2f3c1adc69833acf43c10f3e9795bd4d613712" -"checksum rustc-ap-rustc_target 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6de75caef2c7acba11994614266d60238653657677934817ab368d169333cba" -"checksum rustc-ap-serialize 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf09c60aaee892b0fd107544cfe607d8d463e7f33da34aa823566b8fd2b17f53" -"checksum rustc-ap-syntax 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69f38cc120ff317678bbda8c4f58c1bbc1de64b615383ab01480482dde5e95a1" -"checksum rustc-ap-syntax_pos 407.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "20a0a201141c5c416b1924b079eeefc7b013e34ece0740ce4997f358b3684a7f" +"checksum rustc-ap-arena 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc0ad4318f3425229ed7b117275368b83269bec75f9609d4965dcb9752483c86" +"checksum rustc-ap-graphviz 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b80b7ea7902919f397c4bb12d102abe896fced7893d09d84bcac233e555bb388" +"checksum rustc-ap-rustc_cratesio_shim 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "752463d2b80039d23e42e667a9f6fe08213bd865f6ea301fb35f8068d94955ac" +"checksum rustc-ap-rustc_data_structures 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c3d6a14181e11c132d0ef97a6c27e1bb1d4da09682d02222393875c10d1c364" +"checksum rustc-ap-rustc_errors 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "55caea8426565de362e8df0df737e43b9f22d632e0e52710cbfe316acc6ce2f0" +"checksum rustc-ap-rustc_macros 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "071420d762d2c779d1d4972356f37f5d049dcdd6c49e78f1b037e04c5a0f1a19" +"checksum rustc-ap-rustc_target 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5464696d0748e3019b9e5daca5fcadc53889dc2bca1dc26bf42001fd1c4194f" +"checksum rustc-ap-serialize 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9464445c11c15cf32ef27815b3ec89315b0ed73c6c771cbcf8543be59a3c1502" +"checksum rustc-ap-syntax 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff53245ae370d8e8073dc9cc13f8921e6110d0ccd208b64c388c5653fa6b9c83" +"checksum rustc-ap-syntax_pos 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41896f0eb2eb2f4ddba406939aa6b07386160fa38bee8cde3f7f0d85663e3d47" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" -"checksum rustc-rayon 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d98c51d9cbbe810c8b6693236d3412d8cd60513ff27a3e1b6af483dca0af544" "checksum rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d2e07e19601f21c59aad953c2632172ba70cb27e685771514ea66e4062b3363" -"checksum rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "526e7b6d2707a5b9bec3927d424ad70fa3cfc68e0ac1b75e46cdbbc95adc5108" "checksum rustc-rayon-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "79d38ca7cbc22fa59f09d8534ea4b27f67b0facf0cbe274433aceea227a02543" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_tools_util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b725dadae9fabc488df69a287f5a99c5eaf5d10853842a8a3dfac52476f544ee" @@ -4557,6 +4577,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" "checksum strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fa19a5a708e22bb5be31c1b6108a2a902f909c4b9ba85cba44c06632386bc0ff" +"checksum structopt-derive 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "c6d59d0ae8ef8de16e49e3ca7afa16024a3e0dfd974a75ef93fdc5464e34523f" "checksum strum 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c3a2071519ab6a48f465808c4c1ffdd00dfc8e93111d02b4fc5abab177676e" "checksum strum_macros 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8baacebd7b7c9b864d83a6ba7a246232983e277b86fa5cdec77f565715a4b136" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" diff --git a/src/tools/rls b/src/tools/rls index 483dcbc73f99..3e519650cea9 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 483dcbc73f9923e98c71ec9df11ee3d0d5cfb467 +Subproject commit 3e519650cea91a4b785cd773a3e5965553f74249 diff --git a/src/tools/rustfmt b/src/tools/rustfmt index 5274b49caa1a..d33450247b17 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit 5274b49caa1a7db6ac10c76bf1a3d5710ccef569 +Subproject commit d33450247b17d92a951d9663822c5a3635a37dde From 8a415d145a935959d7415c16ea660d4b9dceabf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 19 Jun 2019 09:25:20 -0700 Subject: [PATCH 102/109] review comment --- src/librustc_mir/borrow_check/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index bb089cb4952d..839eee5a91f8 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1070,7 +1070,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { (Reservation(WriteKind::MutableBorrow(bk)), BorrowKind::Shallow) | (Reservation(WriteKind::MutableBorrow(bk)), BorrowKind::Shared) if { - tcx.migrate_borrowck() && this.borrow_set.location_map.get(&location).is_some() + tcx.migrate_borrowck() && this.borrow_set.location_map.contains_key(&location) } => { let bi = this.borrow_set.location_map[&location]; debug!( From 405f65594264d53edb398557650851ee48702f0c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 19 Jun 2019 17:30:55 +0000 Subject: [PATCH 103/109] Update clippy from 868f168c to 149a988 --- src/tools/clippy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/clippy b/src/tools/clippy index 868f168c1c5f..149a988146e1 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit 868f168c1c5fa9f19c922f3b0ba5be3980f6b0a9 +Subproject commit 149a988146e1e23849338cefe8df7823e1ca3853 From b72b1ac062a66819cd06a3f147486678e99b4f40 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 19 Jun 2019 19:47:52 +0200 Subject: [PATCH 104/109] fix indentation --- src/librustc_typeck/check/expr.rs | 4 ++-- src/test/ui/issues/issue-4736.stderr | 2 +- src/test/ui/numeric/numeric-fields.stderr | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index d659169711f2..b6e17091c06f 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1221,7 +1221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.span_label(variant.ident.span, format!("`{adt}` defined here", adt=ty)); err.span_label(field.ident.span, "field does not exist"); err.span_label(ty_span, format!( - "`{adt}` is a tuple {kind_name},\ + "`{adt}` is a tuple {kind_name}, \ use the appropriate syntax: `{adt}(/* fields */)`", adt=ty, kind_name=kind_name @@ -1267,7 +1267,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; } } - err.emit(); + err.emit(); } // Return an hint about the closest match in field names diff --git a/src/test/ui/issues/issue-4736.stderr b/src/test/ui/issues/issue-4736.stderr index 557607503efa..257ec914a61c 100644 --- a/src/test/ui/issues/issue-4736.stderr +++ b/src/test/ui/issues/issue-4736.stderr @@ -7,7 +7,7 @@ LL | struct NonCopyable(()); LL | let z = NonCopyable{ p: () }; | ----------- ^ field does not exist | | - | `NonCopyable` is a tuple struct,use the appropriate syntax: `NonCopyable(/* fields */)` + | `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)` error: aborting due to previous error diff --git a/src/test/ui/numeric/numeric-fields.stderr b/src/test/ui/numeric/numeric-fields.stderr index ad1f1177f7be..5202393f559c 100644 --- a/src/test/ui/numeric/numeric-fields.stderr +++ b/src/test/ui/numeric/numeric-fields.stderr @@ -7,7 +7,7 @@ LL | struct S(u8, u16); LL | let s = S{0b1: 10, 0: 11}; | - ^^^ field does not exist | | - | `S` is a tuple struct,use the appropriate syntax: `S(/* fields */)` + | `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)` error[E0026]: struct `S` does not have a field named `0x1` --> $DIR/numeric-fields.rs:7:17 From 887feeeaf7d40c25caa9532f2d9121cb79fca899 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 12 Jun 2019 11:42:58 +0300 Subject: [PATCH 105/109] rustc: replace `GenericArgs::with_generic_args` hack with a plain getter. --- src/librustc/hir/mod.rs | 18 +++--- src/librustc/hir/print.rs | 49 ++++++--------- src/librustc_typeck/astconv.rs | 106 ++++++++++++++++----------------- src/librustdoc/clean/mod.rs | 7 ++- src/libsyntax/lib.rs | 2 + src/libsyntax/ptr.rs | 11 +++- 6 files changed, 91 insertions(+), 102 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 527f18f57dc2..de8c75345fee 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -383,17 +383,13 @@ impl PathSegment { } } - // FIXME: hack required because you can't create a static - // `GenericArgs`, so you can't just return a `&GenericArgs`. - pub fn with_generic_args(&self, f: F) -> R - where F: FnOnce(&GenericArgs) -> R - { - let dummy = GenericArgs::none(); - f(if let Some(ref args) = self.args { - &args + pub fn generic_args(&self) -> &GenericArgs { + if let Some(ref args) = self.args { + args } else { - &dummy - }) + const DUMMY: &GenericArgs = &GenericArgs::none(); + DUMMY + } } } @@ -449,7 +445,7 @@ pub struct GenericArgs { } impl GenericArgs { - pub fn none() -> Self { + pub const fn none() -> Self { Self { args: HirVec::new(), bindings: HirVec::new(), diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index e1c713b537c2..8111ac44a87e 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1194,12 +1194,11 @@ impl<'a> State<'a> { self.s.word(".")?; self.print_ident(segment.ident)?; - segment.with_generic_args(|generic_args| { - if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() { - return self.print_generic_args(&generic_args, segment.infer_args, true); - } - Ok(()) - })?; + let generic_args = segment.generic_args(); + if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() { + self.print_generic_args(generic_args, segment.infer_args, true)?; + } + self.print_call_post(base_args) } @@ -1559,11 +1558,9 @@ impl<'a> State<'a> { self.s.word("::")? } if segment.ident.name != kw::PathRoot { - self.print_ident(segment.ident)?; - segment.with_generic_args(|generic_args| { - self.print_generic_args(generic_args, segment.infer_args, - colons_before_params) - })?; + self.print_ident(segment.ident)?; + self.print_generic_args(segment.generic_args(), segment.infer_args, + colons_before_params)?; } } @@ -1572,10 +1569,8 @@ impl<'a> State<'a> { pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> { if segment.ident.name != kw::PathRoot { - self.print_ident(segment.ident)?; - segment.with_generic_args(|generic_args| { - self.print_generic_args(generic_args, segment.infer_args, false) - })?; + self.print_ident(segment.ident)?; + self.print_generic_args(segment.generic_args(), segment.infer_args, false)?; } Ok(()) } @@ -1600,11 +1595,9 @@ impl<'a> State<'a> { } if segment.ident.name != kw::PathRoot { self.print_ident(segment.ident)?; - segment.with_generic_args(|generic_args| { - self.print_generic_args(generic_args, - segment.infer_args, - colons_before_params) - })?; + self.print_generic_args(segment.generic_args(), + segment.infer_args, + colons_before_params)?; } } @@ -1612,11 +1605,9 @@ impl<'a> State<'a> { self.s.word("::")?; let item_segment = path.segments.last().unwrap(); self.print_ident(item_segment.ident)?; - item_segment.with_generic_args(|generic_args| { - self.print_generic_args(generic_args, - item_segment.infer_args, - colons_before_params) - }) + self.print_generic_args(item_segment.generic_args(), + item_segment.infer_args, + colons_before_params) } hir::QPath::TypeRelative(ref qself, ref item_segment) => { self.s.word("<")?; @@ -1624,11 +1615,9 @@ impl<'a> State<'a> { self.s.word(">")?; self.s.word("::")?; self.print_ident(item_segment.ident)?; - item_segment.with_generic_args(|generic_args| { - self.print_generic_args(generic_args, - item_segment.infer_args, - colons_before_params) - }) + self.print_generic_args(item_segment.generic_args(), + item_segment.infer_args, + colons_before_params) } } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8236cd1f7385..b6d123c72acd 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -191,15 +191,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { item_segment: &hir::PathSegment) -> SubstsRef<'tcx> { - let (substs, assoc_bindings, _) = item_segment.with_generic_args(|generic_args| { - self.create_substs_for_ast_path( - span, - def_id, - generic_args, - item_segment.infer_args, - None, - ) - }); + let (substs, assoc_bindings, _) = self.create_substs_for_ast_path( + span, + def_id, + item_segment.generic_args(), + item_segment.infer_args, + None, + ); assoc_bindings.first().map(|b| Self::prohibit_assoc_ty_binding(self.tcx(), b.span)); @@ -874,8 +872,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let trait_def = self.tcx().trait_def(trait_def_id); if !self.tcx().features().unboxed_closures && - trait_segment.with_generic_args(|generic_args| generic_args.parenthesized) - != trait_def.paren_sugar { + trait_segment.generic_args().parenthesized != trait_def.paren_sugar + { // For now, require that parenthetical notation be used only with `Fn()` etc. let msg = if trait_def.paren_sugar { "the precise format of `Fn`-family traits' type parameters is subject to change. \ @@ -887,13 +885,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { span, GateIssue::Language, msg); } - trait_segment.with_generic_args(|generic_args| { - self.create_substs_for_ast_path(span, - trait_def_id, - generic_args, - trait_segment.infer_args, - Some(self_ty)) - }) + self.create_substs_for_ast_path(span, + trait_def_id, + trait_segment.generic_args(), + trait_segment.infer_args, + Some(self_ty)) } fn trait_defines_associated_type_named(&self, @@ -1765,47 +1761,45 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { &self, segments: T) -> bool { let mut has_err = false; for segment in segments { - segment.with_generic_args(|generic_args| { - let (mut err_for_lt, mut err_for_ty, mut err_for_ct) = (false, false, false); - for arg in &generic_args.args { - let (span, kind) = match arg { - hir::GenericArg::Lifetime(lt) => { - if err_for_lt { continue } - err_for_lt = true; - has_err = true; - (lt.span, "lifetime") - } - hir::GenericArg::Type(ty) => { - if err_for_ty { continue } - err_for_ty = true; - has_err = true; - (ty.span, "type") - } - hir::GenericArg::Const(ct) => { - if err_for_ct { continue } - err_for_ct = true; - (ct.span, "const") - } - }; - let mut err = struct_span_err!( - self.tcx().sess, - span, - E0109, - "{} arguments are not allowed for this type", - kind, - ); - err.span_label(span, format!("{} argument not allowed", kind)); - err.emit(); - if err_for_lt && err_for_ty && err_for_ct { - break; + let (mut err_for_lt, mut err_for_ty, mut err_for_ct) = (false, false, false); + for arg in &segment.generic_args().args { + let (span, kind) = match arg { + hir::GenericArg::Lifetime(lt) => { + if err_for_lt { continue } + err_for_lt = true; + has_err = true; + (lt.span, "lifetime") } - } - for binding in &generic_args.bindings { - has_err = true; - Self::prohibit_assoc_ty_binding(self.tcx(), binding.span); + hir::GenericArg::Type(ty) => { + if err_for_ty { continue } + err_for_ty = true; + has_err = true; + (ty.span, "type") + } + hir::GenericArg::Const(ct) => { + if err_for_ct { continue } + err_for_ct = true; + (ct.span, "const") + } + }; + let mut err = struct_span_err!( + self.tcx().sess, + span, + E0109, + "{} arguments are not allowed for this type", + kind, + ); + err.span_label(span, format!("{} argument not allowed", kind)); + err.emit(); + if err_for_lt && err_for_ty && err_for_ct { break; } - }) + } + for binding in &segment.generic_args().bindings { + has_err = true; + Self::prohibit_assoc_ty_binding(self.tcx(), binding.span); + break; + } } has_err } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4becb42d3055..9968118d2ece 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2809,7 +2809,8 @@ impl Clean for hir::Ty { let mut ty_substs = FxHashMap::default(); let mut lt_substs = FxHashMap::default(); let mut ct_substs = FxHashMap::default(); - provided_params.with_generic_args(|generic_args| { + let generic_args = provided_params.generic_args(); + { let mut indices: GenericParamCount = Default::default(); for param in generics.params.iter() { match param.kind { @@ -2884,7 +2885,7 @@ impl Clean for hir::Ty { } } } - }); + } return cx.enter_alias(ty_substs, lt_substs, ct_substs, || ty.clean(cx)); } resolve_type(cx, path.clean(cx), self.hir_id) @@ -3537,7 +3538,7 @@ impl Clean for hir::PathSegment { fn clean(&self, cx: &DocContext<'_>) -> PathSegment { PathSegment { name: self.ident.name.clean(cx), - args: self.with_generic_args(|generic_args| generic_args.clean(cx)) + args: self.generic_args().clean(cx), } } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 55db8da32767..337b84247361 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -12,6 +12,8 @@ #![deny(unused_lifetimes)] #![feature(bind_by_move_pattern_guards)] +#![feature(const_fn)] +#![feature(const_transmute)] #![feature(crate_visibility_modifier)] #![feature(label_break_value)] #![feature(nll)] diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index d577243fb3dc..f0cfa5a84a82 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -133,8 +133,15 @@ impl Encodable for P { } impl P<[T]> { - pub fn new() -> P<[T]> { - P { ptr: Default::default() } + pub const fn new() -> P<[T]> { + // HACK(eddyb) bypass the lack of a `const fn` to create an empty `Box<[T]>` + // (as trait methods, `default` in this case, can't be `const fn` yet). + P { + ptr: unsafe { + use std::ptr::NonNull; + std::mem::transmute(NonNull::<[T; 0]>::dangling() as NonNull<[T]>) + }, + } } #[inline(never)] From 673c3fc23ad0c78fe26420b641957e4fdfea553b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 12 Jun 2019 11:43:15 +0300 Subject: [PATCH 106/109] rustc: disallow cloning HIR nodes. --- src/librustc/hir/lowering.rs | 103 ++++---- src/librustc/hir/map/mod.rs | 10 +- src/librustc/hir/mod.rs | 170 ++++++------ src/librustc/hir/print.rs | 61 ++--- src/librustc/traits/error_reporting.rs | 4 +- .../borrow_check/conflict_errors.rs | 4 +- src/librustc_typeck/astconv.rs | 26 +- src/librustc_typeck/check/mod.rs | 14 +- src/librustc_typeck/collect.rs | 20 +- src/librustdoc/clean/mod.rs | 93 +++---- src/librustdoc/doctree.rs | 202 ++++++++------- src/librustdoc/visit_ast.rs | 243 +++++++++--------- 12 files changed, 476 insertions(+), 474 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 996af3672e8b..c87ab6869372 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -608,15 +608,7 @@ impl<'a> LoweringContext<'a> { }); if let Some(hir_id) = item_hir_id { - let item_generics = match self.lctx.items.get(&hir_id).unwrap().node { - hir::ItemKind::Impl(_, _, _, ref generics, ..) - | hir::ItemKind::Trait(_, _, ref generics, ..) => { - generics.params.clone() - } - _ => HirVec::new(), - }; - - self.lctx.with_parent_impl_lifetime_defs(&item_generics, |this| { + self.lctx.with_parent_item_lifetime_defs(hir_id, |this| { let this = &mut ItemLowerer { lctx: this }; if let ItemKind::Impl(.., ref opt_trait_ref, _, _) = item.node { this.with_trait_impl_ref(opt_trait_ref, |this| { @@ -1054,14 +1046,22 @@ impl<'a> LoweringContext<'a> { // This should only be used with generics that have already had their // in-band lifetimes added. In practice, this means that this function is // only used when lowering a child item of a trait or impl. - fn with_parent_impl_lifetime_defs(&mut self, - params: &HirVec, + fn with_parent_item_lifetime_defs(&mut self, + parent_hir_id: hir::HirId, f: F ) -> T where F: FnOnce(&mut LoweringContext<'_>) -> T, { let old_len = self.in_scope_lifetimes.len(); - let lt_def_names = params.iter().filter_map(|param| match param.kind { + + let parent_generics = match self.items.get(&parent_hir_id).unwrap().node { + hir::ItemKind::Impl(_, _, _, ref generics, ..) + | hir::ItemKind::Trait(_, _, ref generics, ..) => { + &generics.params[..] + } + _ => &[], + }; + let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind { hir::GenericParamKind::Lifetime { .. } => Some(param.name.ident().modern()), _ => None, }); @@ -1113,8 +1113,7 @@ impl<'a> LoweringContext<'a> { lowered_generics.params = lowered_generics .params - .iter() - .cloned() + .into_iter() .chain(in_band_defs) .collect(); @@ -3114,8 +3113,8 @@ impl<'a> LoweringContext<'a> { &NodeMap::default(), itctx.reborrow(), ); - let trait_ref = self.with_parent_impl_lifetime_defs( - &bound_generic_params, + let trait_ref = self.with_in_scope_lifetime_defs( + &p.bound_generic_params, |this| this.lower_trait_ref(&p.trait_ref, itctx), ); @@ -3602,8 +3601,7 @@ impl<'a> LoweringContext<'a> { // Essentially a single `use` which imports two names is desugared into // two imports. for (res, &new_node_id) in resolutions.zip([id1, id2].iter()) { - let vis = vis.clone(); - let ident = ident.clone(); + let ident = *ident; let mut path = path.clone(); for seg in &mut path.segments { seg.id = self.sess.next_node_id(); @@ -3616,19 +3614,7 @@ impl<'a> LoweringContext<'a> { let path = this.lower_path_extra(res, &path, ParamMode::Explicit, None); let item = hir::ItemKind::Use(P(path), hir::UseKind::Single); - let vis_kind = match vis.node { - hir::VisibilityKind::Public => hir::VisibilityKind::Public, - hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), - hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, - hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { - let path = this.renumber_segment_ids(path); - hir::VisibilityKind::Restricted { - path, - hir_id: this.next_id(), - } - } - }; - let vis = respan(vis.span, vis_kind); + let vis = this.rebuild_vis(&vis); this.insert_item( hir::Item { @@ -3692,8 +3678,6 @@ impl<'a> LoweringContext<'a> { for &(ref use_tree, id) in trees { let new_hir_id = self.lower_node_id(id); - let mut vis = vis.clone(); - let mut ident = ident.clone(); let mut prefix = prefix.clone(); // Give the segments new node-ids since they are being cloned. @@ -3707,6 +3691,9 @@ impl<'a> LoweringContext<'a> { // own its own names, we have to adjust the owner before // lowering the rest of the import. self.with_hir_id_owner(id, |this| { + let mut vis = this.rebuild_vis(&vis); + let mut ident = *ident; + let item = this.lower_use_tree(use_tree, &prefix, id, @@ -3714,20 +3701,6 @@ impl<'a> LoweringContext<'a> { &mut ident, attrs); - let vis_kind = match vis.node { - hir::VisibilityKind::Public => hir::VisibilityKind::Public, - hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), - hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, - hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { - let path = this.renumber_segment_ids(path); - hir::VisibilityKind::Restricted { - path: path, - hir_id: this.next_id(), - } - } - }; - let vis = respan(vis.span, vis_kind); - this.insert_item( hir::Item { hir_id: new_hir_id, @@ -3773,15 +3746,35 @@ impl<'a> LoweringContext<'a> { /// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated /// many times in the HIR tree; for each occurrence, we need to assign distinct /// `NodeId`s. (See, e.g., #56128.) - fn renumber_segment_ids(&mut self, path: &P) -> P { - debug!("renumber_segment_ids(path = {:?})", path); - let mut path = path.clone(); - for seg in path.segments.iter_mut() { - if seg.hir_id.is_some() { - seg.hir_id = Some(self.next_id()); - } + fn rebuild_use_path(&mut self, path: &hir::Path) -> hir::Path { + debug!("rebuild_use_path(path = {:?})", path); + let segments = path.segments.iter().map(|seg| hir::PathSegment { + ident: seg.ident, + hir_id: seg.hir_id.map(|_| self.next_id()), + res: seg.res, + args: None, + infer_args: seg.infer_args, + }).collect(); + hir::Path { + span: path.span, + res: path.res, + segments, } - path + } + + fn rebuild_vis(&mut self, vis: &hir::Visibility) -> hir::Visibility { + let vis_kind = match vis.node { + hir::VisibilityKind::Public => hir::VisibilityKind::Public, + hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), + hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, + hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { + hir::VisibilityKind::Restricted { + path: P(self.rebuild_use_path(path)), + hir_id: self.next_id(), + } + } + }; + respan(vis.span, vis_kind) } fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 85c86991f489..87da3273bd22 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -51,11 +51,11 @@ impl<'hir> Entry<'hir> { } } - fn fn_decl(&self) -> Option<&FnDecl> { + fn fn_decl(&self) -> Option<&'hir FnDecl> { match self.node { Node::Item(ref item) => { match item.node { - ItemKind::Fn(ref fn_decl, _, _, _) => Some(&fn_decl), + ItemKind::Fn(ref fn_decl, _, _, _) => Some(fn_decl), _ => None, } } @@ -76,7 +76,7 @@ impl<'hir> Entry<'hir> { Node::Expr(ref expr) => { match expr.node { - ExprKind::Closure(_, ref fn_decl, ..) => Some(&fn_decl), + ExprKind::Closure(_, ref fn_decl, ..) => Some(fn_decl), _ => None, } } @@ -412,9 +412,9 @@ impl<'hir> Map<'hir> { self.forest.krate.body(id) } - pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option { + pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl> { if let Some(entry) = self.find_entry(hir_id) { - entry.fn_decl().cloned() + entry.fn_decl() } else { bug!("no entry for hir_id `{}`", hir_id) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index de8c75345fee..2b46170a6d23 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -155,7 +155,7 @@ pub const DUMMY_HIR_ID: HirId = HirId { pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX; -#[derive(Clone, RustcEncodable, RustcDecodable, Copy, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct Lifetime { pub hir_id: HirId, pub span: Span, @@ -295,7 +295,7 @@ impl Lifetime { /// A `Path` is essentially Rust's notion of a name; for instance, /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable)] pub struct Path { pub span: Span, /// The resolution for the path. @@ -324,7 +324,7 @@ impl fmt::Display for Path { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct PathSegment { /// The identifier portion of this path segment. #[stable_hasher(project(name))] @@ -393,13 +393,13 @@ impl PathSegment { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct ConstArg { pub value: AnonConst, pub span: Span, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum GenericArg { Lifetime(Lifetime), Type(Ty), @@ -431,7 +431,7 @@ impl GenericArg { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct GenericArgs { /// The generic arguments for this path segment. pub args: HirVec, @@ -505,7 +505,7 @@ pub enum TraitBoundModifier { /// `typeck::collect::compute_bounds` matches these against /// the "special" built-in traits (see `middle::lang_items`) and /// detects `Copy`, `Send` and `Sync`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime), @@ -541,7 +541,7 @@ pub enum LifetimeParamKind { Error, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum GenericParamKind { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime { @@ -556,7 +556,7 @@ pub enum GenericParamKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct GenericParam { pub hir_id: HirId, pub name: ParamName, @@ -576,7 +576,7 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Generics { pub params: HirVec, pub where_clause: WhereClause, @@ -584,7 +584,7 @@ pub struct Generics { } impl Generics { - pub fn empty() -> Generics { + pub const fn empty() -> Generics { Generics { params: HirVec::new(), where_clause: WhereClause { @@ -638,7 +638,7 @@ pub enum SyntheticTyParamKind { } /// A where-clause in a definition. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct WhereClause { pub predicates: HirVec, // Only valid if predicates isn't empty. @@ -656,7 +656,7 @@ impl WhereClause { } /// A single predicate in a where-clause. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum WherePredicate { /// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`). BoundPredicate(WhereBoundPredicate), @@ -677,7 +677,7 @@ impl WherePredicate { } /// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding. @@ -689,7 +689,7 @@ pub struct WhereBoundPredicate { } /// A lifetime predicate (e.g., `'a: 'b + 'c`). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, @@ -697,7 +697,7 @@ pub struct WhereRegionPredicate { } /// An equality predicate (e.g., `T = int`); currently unsupported. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct WhereEqPredicate { pub hir_id: HirId, pub span: Span, @@ -705,7 +705,7 @@ pub struct WhereEqPredicate { pub rhs_ty: P, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(RustcEncodable, RustcDecodable, Debug)] pub struct ModuleItems { // Use BTreeSets here so items are in the same order as in the // list of all items in Crate @@ -720,7 +720,7 @@ pub struct ModuleItems { /// For more details, see the [rustc guide]. /// /// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(RustcEncodable, RustcDecodable, Debug)] pub struct Crate { pub module: Mod, pub attrs: HirVec, @@ -815,7 +815,7 @@ impl Crate { /// A macro definition, in this crate or imported from another. /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct MacroDef { pub name: Name, pub vis: Visibility, @@ -829,7 +829,7 @@ pub struct MacroDef { /// A block of statements `{ .. }`, which may have a label (in this case the /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// the `rules` being anything but `DefaultBlock`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Block { /// Statements in a block. pub stmts: HirVec, @@ -847,7 +847,7 @@ pub struct Block { pub targeted_by_break: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable)] pub struct Pat { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -910,7 +910,7 @@ impl Pat { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except `is_shorthand` is true. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct FieldPat { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -925,7 +925,7 @@ pub struct FieldPat { /// Explicit binding annotations given in the HIR for a binding. Note /// that this is not the final binding *mode* that we infer after type /// inference. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum BindingAnnotation { /// No binding annotation given: this means that the final binding mode /// will depend on whether we have skipped through a `&` reference @@ -952,7 +952,7 @@ pub enum RangeEnd { Excluded, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum PatKind { /// Represents a wildcard pattern (i.e., `_`). Wild, @@ -997,8 +997,8 @@ pub enum PatKind { Slice(HirVec>, Option>, HirVec>), } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, - RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, + RustcEncodable, RustcDecodable, Hash, Debug)] pub enum Mutability { MutMutable, MutImmutable, @@ -1014,7 +1014,7 @@ impl Mutability { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Hash, HashStable)] pub enum BinOpKind { /// The `+` operator (addition). Add, @@ -1148,7 +1148,7 @@ impl Into for BinOpKind { pub type BinOp = Spanned; -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Hash, HashStable)] pub enum UnOp { /// The `*` operator (deferencing). UnDeref, @@ -1177,7 +1177,7 @@ impl UnOp { } /// A statement. -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(RustcEncodable, RustcDecodable)] pub struct Stmt { pub hir_id: HirId, pub node: StmtKind, @@ -1192,7 +1192,7 @@ impl fmt::Debug for Stmt { } /// The contents of a statement. -#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable)] pub enum StmtKind { /// A local (`let`) binding. Local(P), @@ -1219,7 +1219,7 @@ impl StmtKind { } /// Represents a `let` statement (i.e., `let : = ;`). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Local { pub pat: P, /// Type annotation, if any (otherwise the type will be inferred). @@ -1236,7 +1236,7 @@ pub struct Local { /// Represents a single arm of a `match` expression, e.g. /// ` (if ) => `. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Arm { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1250,12 +1250,12 @@ pub struct Arm { pub body: P, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Guard { If(P), } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Field { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1265,7 +1265,7 @@ pub struct Field { pub is_shorthand: bool, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), @@ -1273,7 +1273,7 @@ pub enum BlockCheckMode { PopUnsafeBlock(UnsafeSource), } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum UnsafeSource { CompilerGenerated, UserProvided, @@ -1305,7 +1305,7 @@ pub struct BodyId { /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(RustcEncodable, RustcDecodable, Debug)] pub struct Body { pub arguments: HirVec, pub value: Expr, @@ -1379,7 +1379,7 @@ pub struct AnonConst { } /// An expression -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(RustcEncodable, RustcDecodable)] pub struct Expr { pub span: Span, pub node: ExprKind, @@ -1490,7 +1490,7 @@ impl fmt::Debug for Expr { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum ExprKind { /// A `box x` expression. Box(P), @@ -1598,7 +1598,7 @@ pub enum ExprKind { } /// Represents an optionally `Self`-qualified value/type path or associated extension. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum QPath { /// Path to a definition, optionally "fully-qualified" with a `Self` /// type, if the path points to an associated item in a trait. @@ -1618,7 +1618,7 @@ pub enum QPath { } /// Hints at the original code for a let statement. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum LocalSource { /// A `match _ { .. }`. Normal, @@ -1640,7 +1640,7 @@ pub enum LocalSource { } /// Hints at the original code for a `match _ { .. }`. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] pub enum MatchSource { /// A `match _ { .. }`. Normal, @@ -1664,7 +1664,7 @@ pub enum MatchSource { } /// The loop type that yielded an `ExprKind::Loop`. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum LoopSource { /// A `loop { .. }` loop. Loop, @@ -1674,7 +1674,7 @@ pub enum LoopSource { ForLoop, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -1692,7 +1692,7 @@ impl fmt::Display for LoopIdError { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Destination { // This is `Some(_)` iff there is an explicit user-specified `label pub label: Option