diff --git a/src/etc/test-float-parse/u64-pow2.rs b/src/etc/test-float-parse/u64-pow2.rs index 1c9bda948ffd3..7e67e2b1246ef 100644 --- a/src/etc/test-float-parse/u64-pow2.rs +++ b/src/etc/test-float-parse/u64-pow2.rs @@ -1,7 +1,6 @@ mod _common; use _common::validate; -use std::u64; fn main() { for exp in 19..64 { diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 66575e3ef5517..d31c73cc1bd8d 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -4,7 +4,6 @@ use core::intrinsics::{self, min_align_of_val, size_of_val}; use core::ptr::{NonNull, Unique}; -use core::usize; #[stable(feature = "alloc_module", since = "1.28.0")] #[doc(inline)] diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index 9908a3049763a..a01e9b25dd6c8 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -20,7 +20,6 @@ //! ``` //! use std::cmp::Ordering; //! use std::collections::BinaryHeap; -//! use std::usize; //! //! #[derive(Copy, Clone, Eq, PartialEq)] //! struct State { diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 36770ee416cb9..70968964f476e 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -1780,18 +1780,12 @@ where where F: FnMut(&K, &mut V) -> bool, { - while let Some(kv) = unsafe { self.next_kv() } { - let (k, v) = unsafe { ptr::read(&kv) }.into_kv_mut(); + while let Some(mut kv) = unsafe { self.next_kv() } { + let (k, v) = kv.kv_mut(); if pred(k, v) { *self.length -= 1; let (k, v, leaf_edge_location) = kv.remove_kv_tracking(); - // `remove_kv_tracking` has either preserved or invalidated `self.cur_leaf_edge` - if let Some(node) = leaf_edge_location { - match search::search_tree(node, &k) { - search::SearchResult::Found(_) => unreachable!(), - search::SearchResult::GoDown(leaf) => self.cur_leaf_edge = Some(leaf), - } - }; + self.cur_leaf_edge = Some(leaf_edge_location); return Some((k, v)); } self.cur_leaf_edge = Some(kv.next_leaf_edge()); @@ -2698,28 +2692,26 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> { impl<'a, K: 'a, V: 'a> Handle, K, V, marker::LeafOrInternal>, marker::KV> { /// Removes a key/value-pair from the map, and returns that pair, as well as - /// the whereabouts of the leaf edge corresponding to that former pair: - /// if None is returned, the leaf edge is still the left leaf edge of the KV handle; - /// if a node is returned, it heads the subtree where the leaf edge may be found. + /// the leaf edge corresponding to that former pair. fn remove_kv_tracking( self, - ) -> (K, V, Option, K, V, marker::LeafOrInternal>>) { - let mut levels_down_handled: isize; - let (small_leaf, old_key, old_val) = match self.force() { + ) -> (K, V, Handle, K, V, marker::Leaf>, marker::Edge>) { + let (mut pos, old_key, old_val, was_internal) = match self.force() { Leaf(leaf) => { - levels_down_handled = 1; // handled at same level, but affects only the right side let (hole, old_key, old_val) = leaf.remove(); - (hole.into_node(), old_key, old_val) + (hole, old_key, old_val, false) } Internal(mut internal) => { // Replace the location freed in the internal node with the next KV, // and remove that next KV from its leaf. - levels_down_handled = unsafe { ptr::read(&internal).into_node().height() } as isize; let key_loc = internal.kv_mut().0 as *mut K; let val_loc = internal.kv_mut().1 as *mut V; - let to_remove = internal.right_edge().descend().first_leaf_edge().right_kv().ok(); + // Deleting from the left side is typically faster since we can + // just pop an element from the end of the KV array without + // needing to shift the other values. + let to_remove = internal.left_edge().descend().last_leaf_edge().left_kv().ok(); let to_remove = unsafe { unwrap_unchecked(to_remove) }; let (hole, key, val) = to_remove.remove(); @@ -2727,50 +2719,69 @@ impl<'a, K: 'a, V: 'a> Handle, K, V, marker::LeafOrInter let old_key = unsafe { mem::replace(&mut *key_loc, key) }; let old_val = unsafe { mem::replace(&mut *val_loc, val) }; - (hole.into_node(), old_key, old_val) + (hole, old_key, old_val, true) } }; // Handle underflow - let mut cur_node = small_leaf.forget_type(); + let mut cur_node = unsafe { ptr::read(&pos).into_node().forget_type() }; + let mut at_leaf = true; while cur_node.len() < node::MIN_LEN { match handle_underfull_node(cur_node) { - AtRoot(root) => { - cur_node = root; - break; - } - EmptyParent(_) => unreachable!(), - Merged(parent) => { - levels_down_handled -= 1; + AtRoot => break, + Merged(edge, merged_with_left, offset) => { + // If we merged with our right sibling then our tracked + // position has not changed. However if we merged with our + // left sibling then our tracked position is now dangling. + if at_leaf && merged_with_left { + let idx = pos.idx() + offset; + let node = match unsafe { ptr::read(&edge).descend().force() } { + Leaf(leaf) => leaf, + Internal(_) => unreachable!(), + }; + pos = unsafe { Handle::new_edge(node, idx) }; + } + + let parent = edge.into_node(); if parent.len() == 0 { // We must be at the root - let root = parent.into_root_mut(); - root.pop_level(); - cur_node = root.as_mut(); + parent.into_root_mut().pop_level(); break; } else { cur_node = parent.forget_type(); + at_leaf = false; } } - Stole(internal_node) => { - levels_down_handled -= 1; - cur_node = internal_node.forget_type(); + Stole(stole_from_left) => { + // Adjust the tracked position if we stole from a left sibling + if stole_from_left && at_leaf { + // SAFETY: This is safe since we just added an element to our node. + unsafe { + pos.next_unchecked(); + } + } + // This internal node might be underfull, but only if it's the root. break; } } } - let leaf_edge_location = if levels_down_handled > 0 { None } else { Some(cur_node) }; - (old_key, old_val, leaf_edge_location) + // If we deleted from an internal node then we need to compensate for + // the earlier swap and adjust the tracked position to point to the + // next element. + if was_internal { + pos = unsafe { unwrap_unchecked(pos.next_kv().ok()).next_leaf_edge() }; + } + + (old_key, old_val, pos) } } enum UnderflowResult<'a, K, V> { - AtRoot(NodeRef, K, V, marker::LeafOrInternal>), - EmptyParent(NodeRef, K, V, marker::Internal>), - Merged(NodeRef, K, V, marker::Internal>), - Stole(NodeRef, K, V, marker::Internal>), + AtRoot, + Merged(Handle, K, V, marker::Internal>, marker::Edge>, bool, usize), + Stole(bool), } fn handle_underfull_node( @@ -2778,28 +2789,27 @@ fn handle_underfull_node( ) -> UnderflowResult<'_, K, V> { let parent = match node.ascend() { Ok(parent) => parent, - Err(root) => return AtRoot(root), + Err(_) => return AtRoot, }; let (is_left, mut handle) = match parent.left_kv() { Ok(left) => (true, left), - Err(parent) => match parent.right_kv() { - Ok(right) => (false, right), - Err(parent) => { - return EmptyParent(parent.into_node()); - } - }, + Err(parent) => { + let right = unsafe { unwrap_unchecked(parent.right_kv().ok()) }; + (false, right) + } }; if handle.can_merge() { - Merged(handle.merge().into_node()) + let offset = if is_left { handle.reborrow().left_edge().descend().len() + 1 } else { 0 }; + Merged(handle.merge(), is_left, offset) } else { if is_left { handle.steal_left(); } else { handle.steal_right(); } - Stole(handle.into_node()) + Stole(is_left) } } diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 11c1429957326..bc4e271167086 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -723,6 +723,11 @@ impl Handle { pub fn into_node(self) -> Node { self.node } + + /// Returns the position of this handle in the node. + pub fn idx(&self) -> usize { + self.idx + } } impl Handle, marker::KV> { diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 6a78a7398a692..9db997e864170 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -250,7 +250,6 @@ use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; use core::pin::Pin; use core::ptr::{self, NonNull}; use core::slice::{self, from_raw_parts_mut}; -use core::usize; use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global, Layout}; use crate::string::String; diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 2ce5bc8ed2f9d..a3d9c78b7f58c 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -90,7 +90,6 @@ use core::borrow::{Borrow, BorrowMut}; use core::cmp::Ordering::{self, Less}; use core::mem::{self, size_of}; use core::ptr; -use core::{u16, u32, u8}; use crate::borrow::ToOwned; use crate::boxed::Box; diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 111a7651b5e77..1cfb26eb35a11 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -23,7 +23,6 @@ use core::ptr::{self, NonNull}; use core::slice::{self, from_raw_parts_mut}; use core::sync::atomic; use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst}; -use core::{isize, usize}; use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global, Layout}; use crate::boxed::Box; diff --git a/src/liballoc/tests.rs b/src/liballoc/tests.rs index 1b6e0bb291c35..bddaab0c76188 100644 --- a/src/liballoc/tests.rs +++ b/src/liballoc/tests.rs @@ -3,8 +3,6 @@ use core::any::Any; use core::clone::Clone; use core::convert::TryInto; -use core::f64; -use core::i64; use core::ops::Deref; use core::result::Result::{Err, Ok}; diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index d2f09eb4a7568..6e2a5abe90d70 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -1,7 +1,6 @@ use std::borrow::Cow; use std::collections::TryReserveError::*; use std::mem::size_of; -use std::{isize, usize}; pub trait IntoCow<'a, B: ?Sized> where diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 6321e7154e7d0..b63d81796f9d2 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -3,7 +3,6 @@ use std::collections::TryReserveError::*; use std::mem::size_of; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::vec::{Drain, IntoIter}; -use std::{isize, usize}; struct DropCounter<'a> { count: &'a mut u32, diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index 101dd67d97a9a..c287d56fa5353 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -3,7 +3,6 @@ use std::collections::{vec_deque::Drain, VecDeque}; use std::fmt::Debug; use std::mem::size_of; use std::panic::{catch_unwind, AssertUnwindSafe}; -use std::{isize, usize}; use crate::hash; diff --git a/src/libcore/benches/num/flt2dec/strategy/dragon.rs b/src/libcore/benches/num/flt2dec/strategy/dragon.rs index 4052fec33813c..4e1fd8bf753ca 100644 --- a/src/libcore/benches/num/flt2dec/strategy/dragon.rs +++ b/src/libcore/benches/num/flt2dec/strategy/dragon.rs @@ -1,6 +1,5 @@ use super::super::*; use core::num::flt2dec::strategy::dragon::*; -use std::{f64, i16}; use test::Bencher; #[bench] diff --git a/src/libcore/benches/num/flt2dec/strategy/grisu.rs b/src/libcore/benches/num/flt2dec/strategy/grisu.rs index 495074747c283..77ca901a90af3 100644 --- a/src/libcore/benches/num/flt2dec/strategy/grisu.rs +++ b/src/libcore/benches/num/flt2dec/strategy/grisu.rs @@ -1,6 +1,5 @@ use super::super::*; use core::num::flt2dec::strategy::grisu::*; -use std::{f64, i16}; use test::Bencher; pub fn decode_finite(v: T) -> Decoded { diff --git a/src/libcore/tests/fmt/num.rs b/src/libcore/tests/fmt/num.rs index a50c2b46a919b..275a1d062cafb 100644 --- a/src/libcore/tests/fmt/num.rs +++ b/src/libcore/tests/fmt/num.rs @@ -104,7 +104,6 @@ fn test_format_int() { #[test] fn test_format_int_exp_limits() { - use core::{i128, i16, i32, i64, i8, u128, u16, u32, u64, u8}; assert_eq!(format!("{:e}", i8::MIN), "-1.28e2"); assert_eq!(format!("{:e}", i8::MAX), "1.27e2"); assert_eq!(format!("{:e}", i16::MIN), "-3.2768e4"); @@ -125,8 +124,6 @@ fn test_format_int_exp_limits() { #[test] fn test_format_int_exp_precision() { - use core::{i128, i16, i32, i64, i8}; - //test that float and integer match let big_int: u32 = 314_159_265; assert_eq!(format!("{:.1e}", big_int), format!("{:.1e}", f64::from(big_int))); @@ -214,7 +211,6 @@ fn test_format_int_sign_padding() { #[test] fn test_format_int_twos_complement() { - use core::{i16, i32, i64, i8}; assert_eq!(format!("{}", i8::MIN), "-128"); assert_eq!(format!("{}", i16::MIN), "-32768"); assert_eq!(format!("{}", i32::MIN), "-2147483648"); diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 98e3eeb982bde..e0954a661c8d9 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -3,8 +3,6 @@ use core::cell::Cell; use core::convert::TryFrom; use core::iter::*; -use core::usize; -use core::{i16, i8, isize}; #[test] fn test_lt() { @@ -2251,62 +2249,58 @@ fn test_range_inclusive_folds() { #[test] fn test_range_size_hint() { - use core::usize::MAX as UMAX; assert_eq!((0..0usize).size_hint(), (0, Some(0))); assert_eq!((0..100usize).size_hint(), (100, Some(100))); - assert_eq!((0..UMAX).size_hint(), (UMAX, Some(UMAX))); + assert_eq!((0..usize::MAX).size_hint(), (usize::MAX, Some(usize::MAX))); - let umax = u128::try_from(UMAX).unwrap(); + let umax = u128::try_from(usize::MAX).unwrap(); assert_eq!((0..0u128).size_hint(), (0, Some(0))); assert_eq!((0..100u128).size_hint(), (100, Some(100))); - assert_eq!((0..umax).size_hint(), (UMAX, Some(UMAX))); - assert_eq!((0..umax + 1).size_hint(), (UMAX, None)); + assert_eq!((0..umax).size_hint(), (usize::MAX, Some(usize::MAX))); + assert_eq!((0..umax + 1).size_hint(), (usize::MAX, None)); - use core::isize::{MAX as IMAX, MIN as IMIN}; assert_eq!((0..0isize).size_hint(), (0, Some(0))); assert_eq!((-100..100isize).size_hint(), (200, Some(200))); - assert_eq!((IMIN..IMAX).size_hint(), (UMAX, Some(UMAX))); + assert_eq!((isize::MIN..isize::MAX).size_hint(), (usize::MAX, Some(usize::MAX))); - let imin = i128::try_from(IMIN).unwrap(); - let imax = i128::try_from(IMAX).unwrap(); + let imin = i128::try_from(isize::MIN).unwrap(); + let imax = i128::try_from(isize::MAX).unwrap(); assert_eq!((0..0i128).size_hint(), (0, Some(0))); assert_eq!((-100..100i128).size_hint(), (200, Some(200))); - assert_eq!((imin..imax).size_hint(), (UMAX, Some(UMAX))); - assert_eq!((imin..imax + 1).size_hint(), (UMAX, None)); + assert_eq!((imin..imax).size_hint(), (usize::MAX, Some(usize::MAX))); + assert_eq!((imin..imax + 1).size_hint(), (usize::MAX, None)); } #[test] fn test_range_inclusive_size_hint() { - use core::usize::MAX as UMAX; assert_eq!((1..=0usize).size_hint(), (0, Some(0))); assert_eq!((0..=0usize).size_hint(), (1, Some(1))); assert_eq!((0..=100usize).size_hint(), (101, Some(101))); - assert_eq!((0..=UMAX - 1).size_hint(), (UMAX, Some(UMAX))); - assert_eq!((0..=UMAX).size_hint(), (UMAX, None)); + assert_eq!((0..=usize::MAX - 1).size_hint(), (usize::MAX, Some(usize::MAX))); + assert_eq!((0..=usize::MAX).size_hint(), (usize::MAX, None)); - let umax = u128::try_from(UMAX).unwrap(); + let umax = u128::try_from(usize::MAX).unwrap(); assert_eq!((1..=0u128).size_hint(), (0, Some(0))); assert_eq!((0..=0u128).size_hint(), (1, Some(1))); assert_eq!((0..=100u128).size_hint(), (101, Some(101))); - assert_eq!((0..=umax - 1).size_hint(), (UMAX, Some(UMAX))); - assert_eq!((0..=umax).size_hint(), (UMAX, None)); - assert_eq!((0..=umax + 1).size_hint(), (UMAX, None)); + assert_eq!((0..=umax - 1).size_hint(), (usize::MAX, Some(usize::MAX))); + assert_eq!((0..=umax).size_hint(), (usize::MAX, None)); + assert_eq!((0..=umax + 1).size_hint(), (usize::MAX, None)); - use core::isize::{MAX as IMAX, MIN as IMIN}; assert_eq!((0..=-1isize).size_hint(), (0, Some(0))); assert_eq!((0..=0isize).size_hint(), (1, Some(1))); assert_eq!((-100..=100isize).size_hint(), (201, Some(201))); - assert_eq!((IMIN..=IMAX - 1).size_hint(), (UMAX, Some(UMAX))); - assert_eq!((IMIN..=IMAX).size_hint(), (UMAX, None)); + assert_eq!((isize::MIN..=isize::MAX - 1).size_hint(), (usize::MAX, Some(usize::MAX))); + assert_eq!((isize::MIN..=isize::MAX).size_hint(), (usize::MAX, None)); - let imin = i128::try_from(IMIN).unwrap(); - let imax = i128::try_from(IMAX).unwrap(); + let imin = i128::try_from(isize::MIN).unwrap(); + let imax = i128::try_from(isize::MAX).unwrap(); assert_eq!((0..=-1i128).size_hint(), (0, Some(0))); assert_eq!((0..=0i128).size_hint(), (1, Some(1))); assert_eq!((-100..=100i128).size_hint(), (201, Some(201))); - assert_eq!((imin..=imax - 1).size_hint(), (UMAX, Some(UMAX))); - assert_eq!((imin..=imax).size_hint(), (UMAX, None)); - assert_eq!((imin..=imax + 1).size_hint(), (UMAX, None)); + assert_eq!((imin..=imax - 1).size_hint(), (usize::MAX, Some(usize::MAX))); + assert_eq!((imin..=imax).size_hint(), (usize::MAX, None)); + assert_eq!((imin..=imax + 1).size_hint(), (usize::MAX, None)); } #[test] diff --git a/src/libcore/tests/num/dec2flt/mod.rs b/src/libcore/tests/num/dec2flt/mod.rs index a1fa5556ae5db..1c172f49c279c 100644 --- a/src/libcore/tests/num/dec2flt/mod.rs +++ b/src/libcore/tests/num/dec2flt/mod.rs @@ -1,7 +1,5 @@ #![allow(overflowing_literals)] -use std::{f32, f64, i64}; - mod parse; mod rawfp; diff --git a/src/libcore/tests/num/flt2dec/mod.rs b/src/libcore/tests/num/flt2dec/mod.rs index e945d9c4a54ce..ae892e3b0bfbf 100644 --- a/src/libcore/tests/num/flt2dec/mod.rs +++ b/src/libcore/tests/num/flt2dec/mod.rs @@ -1,4 +1,4 @@ -use std::{f32, f64, fmt, i16, str}; +use std::{fmt, str}; use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded}; use core::num::flt2dec::{round_up, Formatted, Part, Sign, MAX_SIG_DIGITS}; diff --git a/src/libcore/tests/num/flt2dec/random.rs b/src/libcore/tests/num/flt2dec/random.rs index ecdfc4b30a59f..5b050a2c35631 100644 --- a/src/libcore/tests/num/flt2dec/random.rs +++ b/src/libcore/tests/num/flt2dec/random.rs @@ -1,6 +1,5 @@ #![cfg(not(target_arch = "wasm32"))] -use std::i16; use std::str; use core::num::flt2dec::strategy::grisu::format_exact_opt; diff --git a/src/libcore/tests/num/int_macros.rs b/src/libcore/tests/num/int_macros.rs index 48a49073b2cf5..8396a0dd62db9 100644 --- a/src/libcore/tests/num/int_macros.rs +++ b/src/libcore/tests/num/int_macros.rs @@ -2,7 +2,6 @@ macro_rules! int_module { ($T:ident, $T_i:ident) => { #[cfg(test)] mod tests { - use core::isize; use core::mem; use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr}; use core::$T_i::*; diff --git a/src/librustc_ast/util/comments.rs b/src/librustc_ast/util/comments.rs index 0e42ae11fa2fa..5f5d4810cb570 100644 --- a/src/librustc_ast/util/comments.rs +++ b/src/librustc_ast/util/comments.rs @@ -5,7 +5,6 @@ use rustc_span::source_map::SourceMap; use rustc_span::{BytePos, CharPos, FileName, Pos}; use log::debug; -use std::usize; #[cfg(test)] mod tests; diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 5734eae7d5946..63730c56f0ed2 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -25,7 +25,7 @@ use rustc_span::Span; use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive}; use std::cmp::Ordering; -use std::{i128, iter, u128}; +use std::iter; fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Value> { let llvm_name = match name { diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 33f449ed270be..57fe7b0da6ff2 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -17,8 +17,6 @@ use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::sym; use rustc_target::abi::{Abi, Int, LayoutOf, Variants}; -use std::{i128, u128}; - impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn codegen_rvalue( &mut self, diff --git a/src/librustc_data_structures/graph/implementation/mod.rs b/src/librustc_data_structures/graph/implementation/mod.rs index f705c2f0b75f3..1aa7ac024d94e 100644 --- a/src/librustc_data_structures/graph/implementation/mod.rs +++ b/src/librustc_data_structures/graph/implementation/mod.rs @@ -23,7 +23,6 @@ use crate::snapshot_vec::{SnapshotVec, SnapshotVecDelegate}; use rustc_index::bit_set::BitSet; use std::fmt::Debug; -use std::usize; #[cfg(test)] mod tests; diff --git a/src/librustc_data_structures/profiling.rs b/src/librustc_data_structures/profiling.rs index a7cdc48d60342..23f3558cbdfa3 100644 --- a/src/librustc_data_structures/profiling.rs +++ b/src/librustc_data_structures/profiling.rs @@ -93,7 +93,6 @@ use std::path::Path; use std::process; use std::sync::Arc; use std::time::{Duration, Instant}; -use std::u32; use measureme::{EventId, EventIdBuilder, SerializableString, StringId}; use parking_lot::RwLock; diff --git a/src/librustc_index/vec.rs b/src/librustc_index/vec.rs index d8c67f6210c75..a84f89c7cd950 100644 --- a/src/librustc_index/vec.rs +++ b/src/librustc_index/vec.rs @@ -7,7 +7,6 @@ use std::iter::{self, FromIterator}; use std::marker::PhantomData; use std::ops::{Index, IndexMut, Range, RangeBounds}; use std::slice; -use std::u32; use std::vec; /// Represents some newtyped `usize` wrapper. diff --git a/src/librustc_infer/infer/type_variable.rs b/src/librustc_infer/infer/type_variable.rs index 8e4199f0c263d..1de820cdb6209 100644 --- a/src/librustc_infer/infer/type_variable.rs +++ b/src/librustc_infer/infer/type_variable.rs @@ -8,7 +8,6 @@ use rustc_data_structures::unify as ut; use std::cmp; use std::marker::PhantomData; use std::ops::Range; -use std::u32; pub struct TypeVariableTable<'tcx> { values: sv::SnapshotVec, diff --git a/src/librustc_interface/callbacks.rs b/src/librustc_interface/callbacks.rs index 88c3d0ec56f68..913c67d045e59 100644 --- a/src/librustc_interface/callbacks.rs +++ b/src/librustc_interface/callbacks.rs @@ -58,5 +58,4 @@ pub fn setup_callbacks() { rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_))); - rustc_middle::ty::RESOLVE_INSTANCE.swap(&(rustc_ty::instance::resolve_instance as _)); } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index a6e1ed84c8708..aa805a2f2dbc0 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -21,7 +21,6 @@ use rustc_target::spec::abi::Abi; use log::debug; use std::cmp; -use std::{f32, f64, i16, i32, i64, i8, u16, u32, u64, u8}; declare_lint! { UNUSED_COMPARISONS, diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index c59b155d5dbbc..29a4254d9eec6 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -42,7 +42,6 @@ use std::io; use std::mem; use std::num::NonZeroUsize; use std::path::Path; -use std::u32; pub use cstore_impl::{provide, provide_extern}; diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index f2e9f4d7e0b89..d75298fae0032 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -39,7 +39,6 @@ use rustc_target::abi::VariantIdx; use std::hash::Hash; use std::num::NonZeroUsize; use std::path::Path; -use std::u32; struct EncodeContext<'tcx> { opaque: opaque::Encoder, diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 36e10f8759d17..b82008f429fa4 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -33,7 +33,7 @@ use std::borrow::Cow; use std::fmt::{self, Debug, Display, Formatter, Write}; use std::ops::Index; use std::slice; -use std::{iter, mem, option, u32}; +use std::{iter, mem, option}; pub use self::cache::{BodyAndCache, ReadOnlyBodyAndCache}; pub use self::query::*; diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 2ffbbfb1762d3..c26c043994f54 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -1257,5 +1257,9 @@ rustc_queries! { eval_always desc { "looking up enabled feature gates" } } + + query resolve_instance(key: (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>)) -> Option> { + desc { "resolving instance `{:?}` `{:?}` with {:?}", key.1, key.2, key.0 } + } } } diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 5d47a6e13f488..cf0222370f288 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -1,7 +1,6 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable}; -use rustc_data_structures::AtomicRef; use rustc_hir::def::Namespace; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::lang_items::DropInPlaceFnLangItem; @@ -289,7 +288,9 @@ impl<'tcx> Instance<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, ) -> Option> { - (*RESOLVE_INSTANCE)(tcx, param_env, def_id, substs) + // All regions in the result of this query are erased, so it's + // fine to erase all of the input regions. + tcx.resolve_instance((tcx.erase_regions(¶m_env), def_id, tcx.erase_regions(&substs))) } pub fn resolve_for_fn_ptr( @@ -440,21 +441,3 @@ fn needs_fn_once_adapter_shim( (ty::ClosureKind::FnMut, _) | (ty::ClosureKind::FnOnce, _) => Err(()), } } - -fn resolve_instance_default( - _tcx: TyCtxt<'tcx>, - _param_env: ty::ParamEnv<'tcx>, - _def_id: DefId, - _substs: SubstsRef<'tcx>, -) -> Option> { - unimplemented!() -} - -pub static RESOLVE_INSTANCE: AtomicRef< - for<'tcx> fn( - TyCtxt<'tcx>, - ty::ParamEnv<'tcx>, - DefId, - SubstsRef<'tcx>, - ) -> Option>, -> = AtomicRef::new(&(resolve_instance_default as _)); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 9b18233390797..0ebd55a6c024c 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -81,7 +81,6 @@ pub use self::context::{ CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckTables, }; -pub use self::instance::RESOLVE_INSTANCE; pub use self::instance::{Instance, InstanceDef}; pub use self::trait_def::TraitDef; diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index a261e484a85fa..438e7ed4331a3 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -296,3 +296,14 @@ impl Key for (Symbol, u32, u32) { DUMMY_SP } } + +impl<'tcx> Key for (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>) { + type CacheSelector = DefaultCacheSelector; + + fn query_crate(&self) -> CrateNum { + self.1.krate + } + fn default_span(&self, tcx: TyCtxt<'_>) -> Span { + tcx.def_span(self.1) + } +} diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 34fa12e1b5683..ec0b89ebb4d0a 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -27,7 +27,7 @@ use rustc_index::vec::{Idx, IndexVec}; use rustc_target::spec::abi::Abi; use std::cell::Cell; -use std::{cmp, iter, mem, usize}; +use std::{cmp, iter, mem}; use crate::const_eval::{is_const_fn, is_unstable_const_fn}; use crate::transform::check_consts::{is_lang_panic_fn, qualifs, ConstKind, Item}; diff --git a/src/librustc_mir_build/build/matches/util.rs b/src/librustc_mir_build/build/matches/util.rs index 967a44b9b96e4..393af108a6e46 100644 --- a/src/librustc_mir_build/build/matches/util.rs +++ b/src/librustc_mir_build/build/matches/util.rs @@ -5,7 +5,6 @@ use rustc_middle::mir::*; use rustc_middle::ty; use smallvec::SmallVec; use std::convert::TryInto; -use std::u32; impl<'a, 'tcx> Builder<'a, 'tcx> { crate fn field_match_pairs<'pat>( diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index 2439570202053..04cb509d44e4b 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -17,7 +17,6 @@ use rustc_span::symbol::kw; use rustc_span::Span; use rustc_target::spec::abi::Abi; use rustc_target::spec::PanicStrategy; -use std::u32; use super::lints; diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 8c0843124f4f1..51ba84416d64d 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -256,7 +256,6 @@ use std::convert::TryInto; use std::fmt; use std::iter::{FromIterator, IntoIterator}; use std::ops::RangeInclusive; -use std::u128; crate fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pat<'tcx>) -> Pat<'tcx> { LiteralExpander { tcx: cx.tcx, param_env: cx.param_env }.fold_pattern(&pat) diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index da8ab727ed3aa..22ce909083d91 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -27,7 +27,8 @@ impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> { ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) - | ItemKind::Union(..) => { + | ItemKind::Union(..) + | ItemKind::OpaqueTy(..) => { for attr in self.tcx.get_attrs(item_def_id).iter() { if attr.check_name(sym::rustc_layout) { self.dump_layout_of(item_def_id, item, attr); @@ -84,7 +85,7 @@ impl LayoutTest<'tcx> { sym::debug => { self.tcx.sess.span_err( item.span, - &format!("layout debugging: {:#?}", *ty_layout), + &format!("layout debugging for type {:?}: {:#?}", ty, *ty_layout), ); } diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index c9060334a9a41..ee71d09cb21e9 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -112,10 +112,10 @@ use rustc_span::symbol::sym; use rustc_span::Span; use std::collections::VecDeque; +use std::fmt; use std::io; use std::io::prelude::*; use std::rc::Rc; -use std::{fmt, u32}; #[derive(Copy, Clone, PartialEq)] struct Variable(u32); diff --git a/src/librustc_span/def_id.rs b/src/librustc_span/def_id.rs index 3551220c5c54a..73b46d753d787 100644 --- a/src/librustc_span/def_id.rs +++ b/src/librustc_span/def_id.rs @@ -7,7 +7,6 @@ use rustc_macros::HashStable_Generic; use rustc_serialize::{Decoder, Encoder}; use std::borrow::Borrow; use std::fmt; -use std::{u32, u64}; rustc_index::newtype_index! { pub struct CrateId { diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 677e373f2f489..955e2e3615909 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -11,9 +11,7 @@ use log::debug; pub fn resolve_instance<'tcx>( tcx: TyCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, - def_id: DefId, - substs: SubstsRef<'tcx>, + (param_env, def_id, substs): (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>), ) -> Option> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { @@ -199,3 +197,7 @@ fn resolve_associated_item<'tcx>( traits::VtableAutoImpl(..) | traits::VtableParam(..) | traits::VtableTraitAlias(..) => None, } } + +pub fn provide(providers: &mut ty::query::Providers<'_>) { + *providers = ty::query::Providers { resolve_instance, ..*providers }; +} diff --git a/src/librustc_ty/lib.rs b/src/librustc_ty/lib.rs index 04909b8b0c1b4..75e62e796408a 100644 --- a/src/librustc_ty/lib.rs +++ b/src/librustc_ty/lib.rs @@ -25,4 +25,5 @@ pub fn provide(providers: &mut Providers<'_>) { common_traits::provide(providers); needs_drop::provide(providers); ty::provide(providers); + instance::provide(providers); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e027db8b56c00..f41114839020e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -32,7 +32,6 @@ use std::collections::hash_map::Entry; use std::default::Default; use std::hash::Hash; use std::rc::Rc; -use std::u32; use std::{mem, vec}; use crate::core::{self, DocContext, ImplTraitParam}; diff --git a/src/librustdoc/passes/unindent_comments.rs b/src/librustdoc/passes/unindent_comments.rs index d4e09ce47a3c1..5604a9c2dc163 100644 --- a/src/librustdoc/passes/unindent_comments.rs +++ b/src/librustdoc/passes/unindent_comments.rs @@ -1,6 +1,5 @@ use std::cmp; use std::string::String; -use std::usize; use crate::clean::{self, DocFragment, Item}; use crate::core::DocContext; diff --git a/src/libserialize/tests/json.rs b/src/libserialize/tests/json.rs index c16426b5919c9..688bddc2baf46 100644 --- a/src/libserialize/tests/json.rs +++ b/src/libserialize/tests/json.rs @@ -17,7 +17,6 @@ use rustc_serialize::{Decodable, Encodable}; use std::collections::BTreeMap; use std::io::prelude::*; use std::string; -use std::{f32, f64, i64, u64}; use Animal::*; #[derive(RustcDecodable, Eq, PartialEq, Debug)] diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index adad90f56d1cf..e0ceb9f3f3810 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -320,7 +320,7 @@ mod prim_char {} #[doc(primitive = "unit")] // -/// The `()` type, sometimes called "unit" or "nil". +/// The `()` type, also called "unit". /// /// The `()` type has exactly one value `()`, and is used when there /// is no other meaningful value that could be returned. `()` is most diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index 2b0393573fdc4..c4e929624d7a4 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -12,7 +12,6 @@ use self::StartResult::*; use core::cmp; use core::intrinsics::abort; -use core::isize; use crate::cell::UnsafeCell; use crate::ptr; diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index 2e3270e81fcd0..f33493ee0c9c9 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -11,7 +11,6 @@ use self::Message::*; pub use self::UpgradeResult::*; use core::cmp; -use core::isize; use crate::cell::UnsafeCell; use crate::ptr; diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 79e868171546b..3e2050799ccb4 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -26,7 +26,6 @@ use self::Blocker::*; pub use self::Failure::*; use core::intrinsics::abort; -use core::isize; use core::mem; use core::ptr; diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs index c7bea168f34d8..34f88eea0d7c3 100644 --- a/src/libstd/sys/hermit/thread.rs +++ b/src/libstd/sys/hermit/thread.rs @@ -6,7 +6,6 @@ use crate::io; use crate::mem; use crate::sys::hermit::abi; use crate::time::Duration; -use core::u32; pub type Tid = abi::Tid; diff --git a/src/test/ui/layout/debug.rs b/src/test/ui/layout/debug.rs index 70ae200e3e5aa..034ed3190c13f 100644 --- a/src/test/ui/layout/debug.rs +++ b/src/test/ui/layout/debug.rs @@ -1,5 +1,5 @@ // normalize-stderr-test "pref: Align \{\n *pow2: [1-3],\n *\}" -> "pref: $$PREF_ALIGN" -#![feature(never_type, rustc_attrs)] +#![feature(never_type, rustc_attrs, type_alias_impl_trait)] #![crate_type = "lib"] #[rustc_layout(debug)] @@ -13,3 +13,10 @@ union U { f1: (i32, i32), f3: i32 } //~ ERROR: layout debugging #[rustc_layout(debug)] type Test = Result; //~ ERROR: layout debugging + +#[rustc_layout(debug)] +type T = impl std::fmt::Debug; //~ ERROR: layout debugging + +fn f() -> T { + 0i32 +} diff --git a/src/test/ui/layout/debug.stderr b/src/test/ui/layout/debug.stderr index ef88cf1e4c13a..3539cea5ea318 100644 --- a/src/test/ui/layout/debug.stderr +++ b/src/test/ui/layout/debug.stderr @@ -1,4 +1,4 @@ -error: layout debugging: Layout { +error: layout debugging for type E: Layout { fields: Arbitrary { offsets: [ Size { @@ -110,7 +110,7 @@ error: layout debugging: Layout { LL | enum E { Foo, Bar(!, i32, i32) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: layout debugging: Layout { +error: layout debugging for type S: Layout { fields: Arbitrary { offsets: [ Size { @@ -164,7 +164,7 @@ error: layout debugging: Layout { LL | struct S { f1: i32, f2: (), f3: i32 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: layout debugging: Layout { +error: layout debugging for type U: Layout { fields: Union( 2, ), @@ -190,7 +190,7 @@ error: layout debugging: Layout { LL | union U { f1: (i32, i32), f3: i32 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: layout debugging: Layout { +error: layout debugging for type std::result::Result: Layout { fields: Arbitrary { offsets: [ Size { @@ -315,5 +315,37 @@ error: layout debugging: Layout { LL | type Test = Result; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: layout debugging for type i32: Layout { + fields: Union( + 0, + ), + variants: Single { + index: 0, + }, + abi: Scalar( + Scalar { + value: Int( + I32, + true, + ), + valid_range: 0..=4294967295, + }, + ), + largest_niche: None, + align: AbiAndPrefAlign { + abi: Align { + pow2: 2, + }, + pref: $PREF_ALIGN, + }, + size: Size { + raw: 4, + }, +} + --> $DIR/debug.rs:18:1 + | +LL | type T = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors