diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 017f67463c3..bf6741dde43 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -6,12 +6,13 @@ use crate::middle::cstore::{ExternCrate, ExternCrateSource}; use crate::middle::region; use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable}; use crate::ty::subst::{Kind, Subst, UnpackedKind}; -use crate::ty::layout::Size; -use crate::mir::interpret::{ConstValue, sign_extend, Scalar}; +use crate::ty::layout::{Integer, IntegerExt, Size}; +use crate::mir::interpret::{ConstValue, sign_extend, Scalar, truncate}; use syntax::ast; use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::Float; use rustc_target::spec::abi::Abi; +use syntax::attr::{SignedInt, UnsignedInt}; use syntax::symbol::{kw, InternedString}; use std::cell::Cell; @@ -899,15 +900,31 @@ pub trait PrettyPrinter<'tcx>: return Ok(self); }, ty::Uint(ui) => { - p!(write("{}{}", data, ui)); + let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(ui)).size(); + let max = truncate(u128::max_value(), bit_size); + + if data == max { + p!(write("std::{}::MAX", ui)) + } else { + p!(write("{}{}", data, ui)) + }; return Ok(self); }, ty::Int(i) =>{ + let bit_size = Integer::from_attr(&self.tcx(), SignedInt(i)) + .size().bits() as u128; + let min = 1u128 << (bit_size - 1); + let max = min - 1; + let ty = self.tcx().lift_to_global(&ct.ty).unwrap(); let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty)) .unwrap() .size; - p!(write("{}{}", sign_extend(data, size) as i128, i)); + match data { + d if d == min => p!(write("std::{}::MIN", i)), + d if d == max => p!(write("std::{}::MAX", i)), + _ => p!(write("{}{}", sign_extend(data, size) as i128, i)) + } return Ok(self); }, ty::Char => { diff --git a/src/test/ui/consts/const-match-check.eval1.stderr b/src/test/ui/consts/const-match-check.eval1.stderr index 4c6499cf99c..3bcb50c6dcf 100644 --- a/src/test/ui/consts/const-match-check.eval1.stderr +++ b/src/test/ui/consts/const-match-check.eval1.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered +error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` not covered --> $DIR/const-match-check.rs:25:15 | LL | A = { let 0 = 0; 0 }, - | ^ pattern `-2147483648i32..=-1i32` not covered + | ^ pattern `std::i32::MIN..=-1i32` not covered error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.eval2.stderr b/src/test/ui/consts/const-match-check.eval2.stderr index 854f8f3a7b9..e292e1cc165 100644 --- a/src/test/ui/consts/const-match-check.eval2.stderr +++ b/src/test/ui/consts/const-match-check.eval2.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered +error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` not covered --> $DIR/const-match-check.rs:31:24 | LL | let x: [i32; { let 0 = 0; 0 }] = []; - | ^ pattern `-2147483648i32..=-1i32` not covered + | ^ pattern `std::i32::MIN..=-1i32` not covered error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.matchck.stderr b/src/test/ui/consts/const-match-check.matchck.stderr index c9028b1c2a2..8a9fbde8537 100644 --- a/src/test/ui/consts/const-match-check.matchck.stderr +++ b/src/test/ui/consts/const-match-check.matchck.stderr @@ -1,26 +1,26 @@ -error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered +error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` not covered --> $DIR/const-match-check.rs:4:22 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `-2147483648i32..=-1i32` not covered + | ^ pattern `std::i32::MIN..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered +error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` not covered --> $DIR/const-match-check.rs:8:23 | LL | static Y: i32 = { let 0 = 0; 0 }; - | ^ pattern `-2147483648i32..=-1i32` not covered + | ^ pattern `std::i32::MIN..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered +error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` not covered --> $DIR/const-match-check.rs:13:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `-2147483648i32..=-1i32` not covered + | ^ pattern `std::i32::MIN..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered +error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` not covered --> $DIR/const-match-check.rs:19:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `-2147483648i32..=-1i32` not covered + | ^ pattern `std::i32::MIN..=-1i32` not covered error: aborting due to 4 previous errors diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index 82b0b484144..6c4b7b0cc03 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -10,11 +10,11 @@ note: lint level defined here LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ -error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered +error[E0004]: non-exhaustive patterns: `128u8..=std::u8::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:28:11 | LL | match x { - | ^ pattern `128u8..=255u8` not covered + | ^ pattern `128u8..=std::u8::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms @@ -32,19 +32,19 @@ error: unreachable pattern LL | -2..=20 => {} | ^^^^^^^ -error[E0004]: non-exhaustive patterns: `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered +error[E0004]: non-exhaustive patterns: `std::i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered --> $DIR/exhaustive_integer_patterns.rs:41:11 | LL | match x { - | ^ patterns `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered + | ^ patterns `std::i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `-128i8` not covered +error[E0004]: non-exhaustive patterns: `std::i8::MIN` not covered --> $DIR/exhaustive_integer_patterns.rs:82:11 | LL | match 0i8 { - | ^^^ pattern `-128i8` not covered + | ^^^ pattern `std::i8::MIN` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms @@ -56,19 +56,19 @@ LL | match 0i16 { | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered +error[E0004]: non-exhaustive patterns: `128u8..=std::u8::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:108:11 | LL | match 0u8 { - | ^^^ pattern `128u8..=255u8` not covered + | ^^^ pattern `128u8..=std::u8::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered +error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered --> $DIR/exhaustive_integer_patterns.rs:120:11 | LL | match (0u8, Some(())) { - | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered + | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms @@ -80,19 +80,19 @@ LL | match (0u8, true) { | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered +error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:145:11 | LL | match 0u128 { - | ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered + | ^^^^^ pattern `std::u128::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `5u128..=340282366920938463463374607431768211455u128` not covered +error[E0004]: non-exhaustive patterns: `5u128..=std::u128::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:149:11 | LL | match 0u128 { - | ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered + | ^^^^^ pattern `5u128..=std::u128::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr index da2b0dc234f..0d77fd4efdb 100644 --- a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr +++ b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in `for` loop binding: `&-2147483648i32..=0i32` not covered +error[E0005]: refutable pattern in `for` loop binding: `&std::i32::MIN..=0i32` not covered --> $DIR/for-loop-refutable-pattern-error-message.rs:2:9 | LL | for &1 in [1].iter() {} - | ^^ pattern `&-2147483648i32..=0i32` not covered + | ^^ pattern `&std::i32::MIN..=0i32` not covered error: aborting due to previous error diff --git a/src/test/ui/match/match-non-exhaustive.stderr b/src/test/ui/match/match-non-exhaustive.stderr index 00c2bfff7eb..211f333882b 100644 --- a/src/test/ui/match/match-non-exhaustive.stderr +++ b/src/test/ui/match/match-non-exhaustive.stderr @@ -1,8 +1,8 @@ -error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered +error[E0004]: non-exhaustive patterns: `std::i32::MIN..=0i32` and `2i32..=std::i32::MAX` not covered --> $DIR/match-non-exhaustive.rs:2:11 | LL | match 0 { 1 => () } - | ^ patterns `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered + | ^ patterns `std::i32::MIN..=0i32` and `2i32..=std::i32::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/non-exhaustive/non-exhaustive-match.rs b/src/test/ui/non-exhaustive/non-exhaustive-match.rs index 8cc5f4042cc..0e5a9203c5f 100644 --- a/src/test/ui/non-exhaustive/non-exhaustive-match.rs +++ b/src/test/ui/non-exhaustive/non-exhaustive-match.rs @@ -12,8 +12,8 @@ fn main() { match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered None => {} } - match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` - // and `(_, _, 5i32..=2147483647i32)` not covered + match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, std::i32::MIN..=3i32)` + // and `(_, _, 5i32..=std::i32::MAX)` not covered (_, _, 4) => {} } match (T::A, T::A) { //~ ERROR non-exhaustive patterns: `(A, A)` not covered diff --git a/src/test/ui/non-exhaustive/non-exhaustive-match.stderr b/src/test/ui/non-exhaustive/non-exhaustive-match.stderr index 58e3309fd26..5dba05e1642 100644 --- a/src/test/ui/non-exhaustive/non-exhaustive-match.stderr +++ b/src/test/ui/non-exhaustive/non-exhaustive-match.stderr @@ -28,11 +28,11 @@ LL | match Some(10) { | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered +error[E0004]: non-exhaustive patterns: `(_, _, std::i32::MIN..=3i32)` and `(_, _, 5i32..=std::i32::MAX)` not covered --> $DIR/non-exhaustive-match.rs:15:11 | LL | match (2, 3, 4) { - | ^^^^^^^^^ patterns `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered + | ^^^^^^^^^ patterns `(_, _, std::i32::MIN..=3i32)` and `(_, _, 5i32..=std::i32::MAX)` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr index 6f0322fd9b9..2c2c2aa04c2 100644 --- a/src/test/ui/precise_pointer_size_matching.stderr +++ b/src/test/ui/precise_pointer_size_matching.stderr @@ -1,16 +1,16 @@ -error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered +error[E0004]: non-exhaustive patterns: `std::isize::MIN..=-6isize` and `21isize..=std::isize::MAX` not covered --> $DIR/precise_pointer_size_matching.rs:24:11 | LL | match 0isize { - | ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered + | ^^^^^^ patterns `std::isize::MIN..=-6isize` and `21isize..=std::isize::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=$USIZE_MAX` not covered +error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=std::usize::MAX` not covered --> $DIR/precise_pointer_size_matching.rs:29:11 | LL | match 0usize { - | ^^^^^^ patterns `0usize` and `21usize..=$USIZE_MAX` not covered + | ^^^^^^ patterns `0usize` and `21usize..=std::usize::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/refutable-pattern-errors.rs b/src/test/ui/refutable-pattern-errors.rs index 05db247288b..aa5fa76bb8c 100644 --- a/src/test/ui/refutable-pattern-errors.rs +++ b/src/test/ui/refutable-pattern-errors.rs @@ -3,5 +3,5 @@ fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } fn main() { let (1, (Some(1), 2..=3)) = (1, (None, 2)); - //~^ ERROR refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered + //~^ ERROR refutable pattern in local binding: `(std::i32::MIN..=0i32, _)` not covered } diff --git a/src/test/ui/refutable-pattern-errors.stderr b/src/test/ui/refutable-pattern-errors.stderr index b7001e34d54..c67ae7c6d48 100644 --- a/src/test/ui/refutable-pattern-errors.stderr +++ b/src/test/ui/refutable-pattern-errors.stderr @@ -4,11 +4,11 @@ error[E0005]: refutable pattern in function argument: `(_, _)` not covered LL | fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } | ^^^^^^^^^^^^^^^^^^^^^ pattern `(_, _)` not covered -error[E0005]: refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered +error[E0005]: refutable pattern in local binding: `(std::i32::MIN..=0i32, _)` not covered --> $DIR/refutable-pattern-errors.rs:5:9 | LL | let (1, (Some(1), 2..=3)) = (1, (None, 2)); - | ^^^^^^^^^^^^^^^^^^^^^ pattern `(-2147483648i32..=0i32, _)` not covered + | ^^^^^^^^^^^^^^^^^^^^^ pattern `(std::i32::MIN..=0i32, _)` not covered error: aborting due to 2 previous errors