Skip to content

Commit

Permalink
WIP for rust-lang#57073 revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
zackmdavis committed Feb 5, 2019
1 parent 4314dba commit 8cf7401
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def update_submodule(self, module, checked_out, recorded_submodules):
run(["git", "submodule", "-q", "sync", module],
cwd=self.rust_root, verbose=self.verbose)
run(["git", "submodule", "update",
"--init", "--recursive", "--progress", module],
"--init", "--recursive", module],
cwd=self.rust_root, verbose=self.verbose)
run(["git", "reset", "-q", "--hard"],
cwd=module_path, verbose=self.verbose)
Expand Down
34 changes: 25 additions & 9 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2676,22 +2676,38 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: ty::Const<'_>) -> fmt::Resul
let ty = const_val.ty;
// print some primitives
if let ConstValue::Scalar(Scalar::Bits { bits, .. }) = value {
let bit_width = ty::tls::with(|tcx| {
let ty = tcx.lift_to_global(&ty).unwrap();
tcx.layout_of(ty::ParamEnv::empty().and(ty))
.unwrap()
.size
.bits()
});
match ty.sty {
Bool if bits == 0 => return write!(f, "false"),
Bool if bits == 1 => return write!(f, "true"),
Float(ast::FloatTy::F32) => return write!(f, "{}f32", Single::from_bits(bits)),
Float(ast::FloatTy::F64) => return write!(f, "{}f64", Double::from_bits(bits)),
Uint(ui) => return write!(f, "{:?}{}", bits, ui),
Uint(ui) => {
return match bits {
// writing `0` as `uX::MIN` wouldn't clarify the value, so only `MAX` is
// special-cased
_ if bits == !0u128 >> (128 - bit_width) => write!(f, "::std::{}::MAX", ui),
_ => write!(f, "{:?}{}", bits, ui)
}
}
Int(i) => {
let bit_width = ty::tls::with(|tcx| {
let ty = tcx.lift_to_global(&ty).unwrap();
tcx.layout_of(ty::ParamEnv::empty().and(ty))
.unwrap()
.size
.bits()
});
let shift = 128 - bit_width;
return write!(f, "{:?}{}", ((bits as i128) << shift) >> shift, i);
let n = ((bits as i128) << shift) >> shift;
return match n {
_ if n == (1u128 << (bit_width - 1)) as i128 => {
write!(f, "::std::{}::MIN", i)
},
_ if n == ((1u128 << (bit_width - 1)) - 1) as i128 => {
write!(f, "::std::{}::MAX", i)
},
_ => write!(f, "{:?}{}", n, i)
}
}
Char => return write!(f, "{:?}", ::std::char::from_u32(bits as u32).unwrap()),
_ => {}
Expand Down
1 change: 1 addition & 0 deletions src/llvm
Submodule llvm added at caddcd
20 changes: 10 additions & 10 deletions src/test/ui/exhaustive_integer_patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 { //~ ERROR non-exhaustive patterns
| ^ pattern `128u8..=255u8` not covered
| ^ pattern `128u8..=::std::u8::MAX` not covered

error[E0004]: non-exhaustive patterns: `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered
--> $DIR/exhaustive_integer_patterns.rs:33:11
Expand Down Expand Up @@ -46,35 +46,35 @@ error[E0004]: non-exhaustive patterns: `0i16` not covered
LL | match 0i16 { //~ ERROR non-exhaustive patterns
| ^^^^ pattern `0i16` not covered

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 { //~ ERROR non-exhaustive patterns
| ^^^ pattern `128u8..=255u8` not covered
| ^^^ pattern `128u8..=::std::u8::MAX` not covered

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(())) { //~ ERROR non-exhaustive patterns
| ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered
| ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=::std::u8::MAX, Some(_))` not covered

error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered
--> $DIR/exhaustive_integer_patterns.rs:125:11
|
LL | match (0u8, true) { //~ ERROR non-exhaustive patterns
| ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered

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 { //~ ERROR non-exhaustive patterns
| ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered
| ^^^^^ pattern `::std::u128::MAX` not covered

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 { //~ ERROR non-exhaustive patterns
| ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered
| ^^^^^ pattern `5u128..=::std::u128::MAX` not covered

error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered
--> $DIR/exhaustive_integer_patterns.rs:153:11
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/match/match-non-exhaustive.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered
error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=::std::i32::MAX` not covered
--> $DIR/match-non-exhaustive.rs:2:11
|
LL | match 0 { 1 => () } //~ ERROR non-exhaustive patterns
| ^ patterns `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered
| ^ patterns `-2147483648i32..=0i32` and `2i32..=::std::i32::MAX` not covered

error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-non-exhaustive.rs:3:11
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/non-exhaustive/non-exhaustive-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/non-exhaustive/non-exhaustive-match.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ error[E0004]: non-exhaustive patterns: `Some(_)` not covered
LL | match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
| ^^^^^^^^ pattern `Some(_)` not covered

error[E0004]: non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered
error[E0004]: non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=::std::i32::MAX)` not covered
--> $DIR/non-exhaustive-match.rs:15:11
|
LL | match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)`
| ^^^^^^^^^ patterns `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered
LL | match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, ::std::i32::MIN..=3i32)`
| ^^^^^^^^^ patterns `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=::std::i32::MAX)` not covered

error[E0004]: non-exhaustive patterns: `(A, A)` not covered
--> $DIR/non-exhaustive-match.rs:19:11
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/precise_pointer_size_matching.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered
error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=::std::isize::MAX` not covered
--> $DIR/precise_pointer_size_matching.rs:24:11
|
LL | match 0isize { //~ ERROR non-exhaustive patterns
| ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered
| ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=::std::isize::MAX` not covered

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 { //~ ERROR non-exhaustive patterns
| ^^^^^^ patterns `0usize` and `21usize..=$USIZE_MAX` not covered
| ^^^^^^ patterns `0usize` and `21usize..=::std::usize::MAX` not covered

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/refutable-pattern-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ fn func((1, (Some(1), 2..=3)): (isize, (Option<isize>, 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
}

0 comments on commit 8cf7401

Please sign in to comment.