Skip to content

Commit 8cf7401

Browse files
committed
WIP for rust-lang#57073 revamp
1 parent 4314dba commit 8cf7401

9 files changed

+49
-32
lines changed

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def update_submodule(self, module, checked_out, recorded_submodules):
674674
run(["git", "submodule", "-q", "sync", module],
675675
cwd=self.rust_root, verbose=self.verbose)
676676
run(["git", "submodule", "update",
677-
"--init", "--recursive", "--progress", module],
677+
"--init", "--recursive", module],
678678
cwd=self.rust_root, verbose=self.verbose)
679679
run(["git", "reset", "-q", "--hard"],
680680
cwd=module_path, verbose=self.verbose)

src/librustc/mir/mod.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -2676,22 +2676,38 @@ pub fn fmt_const_val(f: &mut impl Write, const_val: ty::Const<'_>) -> fmt::Resul
26762676
let ty = const_val.ty;
26772677
// print some primitives
26782678
if let ConstValue::Scalar(Scalar::Bits { bits, .. }) = value {
2679+
let bit_width = ty::tls::with(|tcx| {
2680+
let ty = tcx.lift_to_global(&ty).unwrap();
2681+
tcx.layout_of(ty::ParamEnv::empty().and(ty))
2682+
.unwrap()
2683+
.size
2684+
.bits()
2685+
});
26792686
match ty.sty {
26802687
Bool if bits == 0 => return write!(f, "false"),
26812688
Bool if bits == 1 => return write!(f, "true"),
26822689
Float(ast::FloatTy::F32) => return write!(f, "{}f32", Single::from_bits(bits)),
26832690
Float(ast::FloatTy::F64) => return write!(f, "{}f64", Double::from_bits(bits)),
2684-
Uint(ui) => return write!(f, "{:?}{}", bits, ui),
2691+
Uint(ui) => {
2692+
return match bits {
2693+
// writing `0` as `uX::MIN` wouldn't clarify the value, so only `MAX` is
2694+
// special-cased
2695+
_ if bits == !0u128 >> (128 - bit_width) => write!(f, "::std::{}::MAX", ui),
2696+
_ => write!(f, "{:?}{}", bits, ui)
2697+
}
2698+
}
26852699
Int(i) => {
2686-
let bit_width = ty::tls::with(|tcx| {
2687-
let ty = tcx.lift_to_global(&ty).unwrap();
2688-
tcx.layout_of(ty::ParamEnv::empty().and(ty))
2689-
.unwrap()
2690-
.size
2691-
.bits()
2692-
});
26932700
let shift = 128 - bit_width;
2694-
return write!(f, "{:?}{}", ((bits as i128) << shift) >> shift, i);
2701+
let n = ((bits as i128) << shift) >> shift;
2702+
return match n {
2703+
_ if n == (1u128 << (bit_width - 1)) as i128 => {
2704+
write!(f, "::std::{}::MIN", i)
2705+
},
2706+
_ if n == ((1u128 << (bit_width - 1)) - 1) as i128 => {
2707+
write!(f, "::std::{}::MAX", i)
2708+
},
2709+
_ => write!(f, "{:?}{}", n, i)
2710+
}
26952711
}
26962712
Char => return write!(f, "{:?}", ::std::char::from_u32(bits as u32).unwrap()),
26972713
_ => {}

src/llvm

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit caddcd9b9dc9479a20908d93c3e47c49b021379e

src/test/ui/exhaustive_integer_patterns.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ note: lint level defined here
1010
LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

13-
error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered
13+
error[E0004]: non-exhaustive patterns: `128u8..=::std::u8::MAX` not covered
1414
--> $DIR/exhaustive_integer_patterns.rs:28:11
1515
|
1616
LL | match x { //~ ERROR non-exhaustive patterns
17-
| ^ pattern `128u8..=255u8` not covered
17+
| ^ pattern `128u8..=::std::u8::MAX` not covered
1818

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

49-
error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered
49+
error[E0004]: non-exhaustive patterns: `128u8..=::std::u8::MAX` not covered
5050
--> $DIR/exhaustive_integer_patterns.rs:108:11
5151
|
5252
LL | match 0u8 { //~ ERROR non-exhaustive patterns
53-
| ^^^ pattern `128u8..=255u8` not covered
53+
| ^^^ pattern `128u8..=::std::u8::MAX` not covered
5454

55-
error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered
55+
error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=::std::u8::MAX, Some(_))` not covered
5656
--> $DIR/exhaustive_integer_patterns.rs:120:11
5757
|
5858
LL | match (0u8, Some(())) { //~ ERROR non-exhaustive patterns
59-
| ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered
59+
| ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=::std::u8::MAX, Some(_))` not covered
6060

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

67-
error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered
67+
error[E0004]: non-exhaustive patterns: `::std::u128::MAX` not covered
6868
--> $DIR/exhaustive_integer_patterns.rs:145:11
6969
|
7070
LL | match 0u128 { //~ ERROR non-exhaustive patterns
71-
| ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered
71+
| ^^^^^ pattern `::std::u128::MAX` not covered
7272

73-
error[E0004]: non-exhaustive patterns: `5u128..=340282366920938463463374607431768211455u128` not covered
73+
error[E0004]: non-exhaustive patterns: `5u128..=::std::u128::MAX` not covered
7474
--> $DIR/exhaustive_integer_patterns.rs:149:11
7575
|
7676
LL | match 0u128 { //~ ERROR non-exhaustive patterns
77-
| ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered
77+
| ^^^^^ pattern `5u128..=::std::u128::MAX` not covered
7878

7979
error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered
8080
--> $DIR/exhaustive_integer_patterns.rs:153:11

src/test/ui/match/match-non-exhaustive.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered
1+
error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=::std::i32::MAX` not covered
22
--> $DIR/match-non-exhaustive.rs:2:11
33
|
44
LL | match 0 { 1 => () } //~ ERROR non-exhaustive patterns
5-
| ^ patterns `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered
5+
| ^ patterns `-2147483648i32..=0i32` and `2i32..=::std::i32::MAX` not covered
66

77
error[E0004]: non-exhaustive patterns: `_` not covered
88
--> $DIR/match-non-exhaustive.rs:3:11

src/test/ui/non-exhaustive/non-exhaustive-match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn main() {
1212
match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
1313
None => {}
1414
}
15-
match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)`
16-
// and `(_, _, 5i32..=2147483647i32)` not covered
15+
match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, ::std::i32::MIN..=3i32)`
16+
// and `(_, _, 5i32..=::std::i32::MAX)` not covered
1717
(_, _, 4) => {}
1818
}
1919
match (T::A, T::A) { //~ ERROR non-exhaustive patterns: `(A, A)` not covered

src/test/ui/non-exhaustive/non-exhaustive-match.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ error[E0004]: non-exhaustive patterns: `Some(_)` not covered
1616
LL | match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
1717
| ^^^^^^^^ pattern `Some(_)` not covered
1818

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

2525
error[E0004]: non-exhaustive patterns: `(A, A)` not covered
2626
--> $DIR/non-exhaustive-match.rs:19:11

src/test/ui/precise_pointer_size_matching.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered
1+
error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=::std::isize::MAX` not covered
22
--> $DIR/precise_pointer_size_matching.rs:24:11
33
|
44
LL | match 0isize { //~ ERROR non-exhaustive patterns
5-
| ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered
5+
| ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=::std::isize::MAX` not covered
66

7-
error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=$USIZE_MAX` not covered
7+
error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=::std::usize::MAX` not covered
88
--> $DIR/precise_pointer_size_matching.rs:29:11
99
|
1010
LL | match 0usize { //~ ERROR non-exhaustive patterns
11-
| ^^^^^^ patterns `0usize` and `21usize..=$USIZE_MAX` not covered
11+
| ^^^^^^ patterns `0usize` and `21usize..=::std::usize::MAX` not covered
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/refutable-pattern-errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fn func((1, (Some(1), 2..=3)): (isize, (Option<isize>, isize))) { }
33

44
fn main() {
55
let (1, (Some(1), 2..=3)) = (1, (None, 2));
6-
//~^ ERROR refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered
6+
//~^ ERROR refutable pattern in local binding: `(::std::i32::MIN..=0i32, _)` not covered
77
}

0 commit comments

Comments
 (0)