Skip to content

Commit 6ee6673

Browse files
authored
Rollup merge of #98677 - lyming2007:issue-98492-fix, r=lcnr
For diagnostic information of Boolean, remind it as use the type: 'bool' Fixes #98492. It helps programmers coming from other languages modified: compiler/rustc_resolve/src/late/diagnostics.rs
2 parents b1403d6 + 15d3ea5 commit 6ee6673

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
15031503
Some(match name {
15041504
"byte" => sym::u8, // In Java, bytes are signed, but in practice one almost always wants unsigned bytes.
15051505
"short" => sym::i16,
1506+
"Bool" => sym::bool,
1507+
"Boolean" => sym::bool,
15061508
"boolean" => sym::bool,
15071509
"int" => sym::i32,
15081510
"long" => sym::i64,

src/test/ui/lint/recommend-literal.rs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ fn main() {
77
let y: long = 74802374902374923;
88
//~^ ERROR cannot find type `long` in this scope
99
//~| HELP perhaps you intended to use this type
10+
let v1: Boolean = true;
11+
//~^ ERROR: cannot find type `Boolean` in this scope [E0412]
12+
//~| HELP perhaps you intended to use this type
13+
let v2: Bool = true;
14+
//~^ ERROR: cannot find type `Bool` in this scope [E0412]
15+
//~| HELP a builtin type with a similar name exists
16+
//~| HELP perhaps you intended to use this type
1017
}
1118

1219
fn z(a: boolean) {

src/test/ui/lint/recommend-literal.stderr

+30-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,32 @@ LL | let y: long = 74802374902374923;
1616
| not found in this scope
1717
| help: perhaps you intended to use this type: `i64`
1818

19+
error[E0412]: cannot find type `Boolean` in this scope
20+
--> $DIR/recommend-literal.rs:10:13
21+
|
22+
LL | let v1: Boolean = true;
23+
| ^^^^^^^
24+
| |
25+
| not found in this scope
26+
| help: perhaps you intended to use this type: `bool`
27+
28+
error[E0412]: cannot find type `Bool` in this scope
29+
--> $DIR/recommend-literal.rs:13:13
30+
|
31+
LL | let v2: Bool = true;
32+
| ^^^^
33+
|
34+
help: a builtin type with a similar name exists
35+
|
36+
LL | let v2: bool = true;
37+
| ~~~~
38+
help: perhaps you intended to use this type
39+
|
40+
LL | let v2: bool = true;
41+
| ~~~~
42+
1943
error[E0412]: cannot find type `boolean` in this scope
20-
--> $DIR/recommend-literal.rs:12:9
44+
--> $DIR/recommend-literal.rs:19:9
2145
|
2246
LL | fn z(a: boolean) {
2347
| ^^^^^^^
@@ -26,7 +50,7 @@ LL | fn z(a: boolean) {
2650
| help: perhaps you intended to use this type: `bool`
2751

2852
error[E0412]: cannot find type `byte` in this scope
29-
--> $DIR/recommend-literal.rs:17:11
53+
--> $DIR/recommend-literal.rs:24:11
3054
|
3155
LL | fn a() -> byte {
3256
| ^^^^
@@ -35,7 +59,7 @@ LL | fn a() -> byte {
3559
| help: perhaps you intended to use this type: `u8`
3660

3761
error[E0412]: cannot find type `float` in this scope
38-
--> $DIR/recommend-literal.rs:24:12
62+
--> $DIR/recommend-literal.rs:31:12
3963
|
4064
LL | width: float,
4165
| ^^^^^
@@ -44,7 +68,7 @@ LL | width: float,
4468
| help: perhaps you intended to use this type: `f32`
4569

4670
error[E0412]: cannot find type `int` in this scope
47-
--> $DIR/recommend-literal.rs:27:19
71+
--> $DIR/recommend-literal.rs:34:19
4872
|
4973
LL | depth: Option<int>,
5074
| ^^^ not found in this scope
@@ -59,14 +83,14 @@ LL | struct Data<int> {
5983
| +++++
6084

6185
error[E0412]: cannot find type `short` in this scope
62-
--> $DIR/recommend-literal.rs:33:16
86+
--> $DIR/recommend-literal.rs:40:16
6387
|
6488
LL | impl Stuff for short {}
6589
| ^^^^^
6690
| |
6791
| not found in this scope
6892
| help: perhaps you intended to use this type: `i16`
6993

70-
error: aborting due to 7 previous errors
94+
error: aborting due to 9 previous errors
7195

7296
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)