Skip to content

Commit f738423

Browse files
authored
Rollup merge of #73194 - lzutao:INT-patterns, r=dtolnay
Prefer the associated constants for pattern matching error Resolved this comment: #68490 (comment)
2 parents 6ad8cbd + c755292 commit f738423

23 files changed

+139
-139
lines changed

src/librustc_middle/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ pub trait PrettyPrinter<'tcx>:
986986

987987
let ui_str = ui.name_str();
988988
if data == max {
989-
p!(write("std::{}::MAX", ui_str))
989+
p!(write("{}::MAX", ui_str))
990990
} else {
991991
if print_ty { p!(write("{}{}", data, ui_str)) } else { p!(write("{}", data)) }
992992
};
@@ -999,8 +999,8 @@ pub trait PrettyPrinter<'tcx>:
999999

10001000
let i_str = i.name_str();
10011001
match data {
1002-
d if d == min => p!(write("std::{}::MIN", i_str)),
1003-
d if d == max => p!(write("std::{}::MAX", i_str)),
1002+
d if d == min => p!(write("{}::MIN", i_str)),
1003+
d if d == max => p!(write("{}::MAX", i_str)),
10041004
_ => {
10051005
let data = sign_extend(data, size) as i128;
10061006
if print_ty {

src/test/mir-opt/const_prop/bad_op_div_by_zero/rustc.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
// mir::Constant
6060
// + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:19
6161
- // + literal: Const { ty: i32, val: Value(Scalar(0xffffffff)) }
62-
- _6 = Eq(const 1i32, const std::i32::MIN); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19
62+
- _6 = Eq(const 1i32, const i32::MIN); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19
6363
+ // + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
6464
+ _6 = const false; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19
6565
// ty::Const

src/test/mir-opt/const_prop/bad_op_mod_by_zero/rustc.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
// mir::Constant
6060
// + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:19
6161
- // + literal: Const { ty: i32, val: Value(Scalar(0xffffffff)) }
62-
- _6 = Eq(const 1i32, const std::i32::MIN); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19
62+
- _6 = Eq(const 1i32, const i32::MIN); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19
6363
+ // + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
6464
+ _6 = const false; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19
6565
// ty::Const

src/test/ui/consts/const-match-check.eval1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
1+
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
22
--> $DIR/const-match-check.rs:25:15
33
|
44
LL | A = { let 0 = 0; 0 },
5-
| ^ patterns `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
5+
| ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
66
|
77
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html

src/test/ui/consts/const-match-check.eval2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
1+
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
22
--> $DIR/const-match-check.rs:31:24
33
|
44
LL | let x: [i32; { let 0 = 0; 0 }] = [];
5-
| ^ patterns `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
5+
| ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
66
|
77
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html

src/test/ui/consts/const-match-check.matchck.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
1+
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
22
--> $DIR/const-match-check.rs:4:22
33
|
44
LL | const X: i32 = { let 0 = 0; 0 };
5-
| ^ patterns `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
5+
| ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
66
|
77
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
@@ -12,11 +12,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched
1212
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
1313
| ^^^^^^^^^^^^^^^^^^^^^^
1414

15-
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
15+
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
1616
--> $DIR/const-match-check.rs:8:23
1717
|
1818
LL | static Y: i32 = { let 0 = 0; 0 };
19-
| ^ patterns `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
19+
| ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
2020
|
2121
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
2222
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
@@ -26,11 +26,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched
2626
LL | static Y: i32 = { if let 0 = 0 { /* */ } 0 };
2727
| ^^^^^^^^^^^^^^^^^^^^^^
2828

29-
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
29+
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
3030
--> $DIR/const-match-check.rs:13:26
3131
|
3232
LL | const X: i32 = { let 0 = 0; 0 };
33-
| ^ patterns `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
33+
| ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
3434
|
3535
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
3636
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
@@ -40,11 +40,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched
4040
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
4141
| ^^^^^^^^^^^^^^^^^^^^^^
4242

43-
error[E0005]: refutable pattern in local binding: `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
43+
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
4444
--> $DIR/const-match-check.rs:19:26
4545
|
4646
LL | const X: i32 = { let 0 = 0; 0 };
47-
| ^ patterns `std::i32::MIN..=-1i32` and `1i32..=std::i32::MAX` not covered
47+
| ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered
4848
|
4949
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
5050
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html

src/test/ui/consts/const-pattern-irrefutable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use foo::d;
99
const a: u8 = 2;
1010

1111
fn main() {
12-
let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX
13-
let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX
14-
let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX
12+
let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX
13+
let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX
14+
let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX
1515
fn f() {} // Check that the `NOTE`s still work with an item here (cf. issue #35115).
1616
}

src/test/ui/consts/const-pattern-irrefutable.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX` not covered
1+
error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX` not covered
22
--> $DIR/const-pattern-irrefutable.rs:12:9
33
|
44
LL | const a: u8 = 2;
@@ -12,7 +12,7 @@ LL | let a = 4;
1212
|
1313
= note: the matched value is of type `u8`
1414

15-
error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX` not covered
15+
error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX` not covered
1616
--> $DIR/const-pattern-irrefutable.rs:13:9
1717
|
1818
LL | pub const b: u8 = 2;
@@ -26,7 +26,7 @@ LL | let c = 4;
2626
|
2727
= note: the matched value is of type `u8`
2828

29-
error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX` not covered
29+
error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX` not covered
3030
--> $DIR/const-pattern-irrefutable.rs:14:9
3131
|
3232
LL | pub const d: u8 = 2;

src/test/ui/for/for-loop-refutable-pattern-error-message.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0005]: refutable pattern in `for` loop binding: `&std::i32::MIN..=0i32` and `&2i32..=std::i32::MAX` not covered
1+
error[E0005]: refutable pattern in `for` loop binding: `&i32::MIN..=0i32` and `&2i32..=i32::MAX` not covered
22
--> $DIR/for-loop-refutable-pattern-error-message.rs:2:9
33
|
44
LL | for &1 in [1].iter() {}
5-
| ^^ patterns `&std::i32::MIN..=0i32` and `&2i32..=std::i32::MAX` not covered
5+
| ^^ patterns `&i32::MIN..=0i32` and `&2i32..=i32::MAX` not covered
66
|
77
= note: the matched value is of type `&i32`
88

0 commit comments

Comments
 (0)