Skip to content

Commit

Permalink
Rollup merge of rust-lang#70777 - faern:use-assoc-int-consts2, r=dtolnay
Browse files Browse the repository at this point in the history
Don't import integer and float modules, use assoc consts

Stop importing the standard library integer and float modules to reach the `MIN`, `MAX` and other constants. They are available directly on the primitive types now.

This PR is a follow up of rust-lang#69860 which made sure we use the new constants in documentation.

This type of change touches a lot of files, and previously all my assoc int consts PRs had collisions and were accepted only after a long delay. So I'd prefer to do it in smaller steps now. Just removing these imports seem like a good next step.

r? @dtolnay
  • Loading branch information
Dylan-DPC authored Apr 5, 2020
2 parents 829154f + 101085a commit c259553
Show file tree
Hide file tree
Showing 42 changed files with 27 additions and 75 deletions.
1 change: 0 additions & 1 deletion src/etc/test-float-parse/u64-pow2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod _common;

use _common::validate;
use std::u64;

fn main() {
for exp in 19..64 {
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! ```
//! use std::cmp::Ordering;
//! use std::collections::BinaryHeap;
//! use std::usize;
//!
//! #[derive(Copy, Clone, Eq, PartialEq)]
//! struct State {
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/liballoc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/string.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::super::*;
use core::num::flt2dec::strategy::dragon::*;
use std::{f64, i16};
use test::Bencher;

#[bench]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::super::*;
use core::num::flt2dec::strategy::grisu::*;
use std::{f64, i16};
use test::Bencher;

pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
Expand Down
4 changes: 0 additions & 4 deletions src/libcore/tests/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)));
Expand Down Expand Up @@ -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");
Expand Down
50 changes: 22 additions & 28 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/tests/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(overflowing_literals)]

use std::{f32, f64, i64};

mod parse;
mod rawfp;

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/num/flt2dec/random.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use std::i16;
use std::str;

use core::num::flt2dec::strategy::grisu::format_exact_opt;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_ast/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_data_structures/graph/implementation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_data_structures/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_index/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/librustc_infer/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Delegate>,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir_build/build/matches/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir_build/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/librustc_span/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading

0 comments on commit c259553

Please sign in to comment.