Skip to content

Commit 2699d81

Browse files
committed
Use shorter span for float literal suggestion
1 parent a06a18a commit 2699d81

File tree

6 files changed

+91
-59
lines changed

6 files changed

+91
-59
lines changed

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
5252
) = tcx.sess.source_map().span_to_snippet(sp) =>
5353
{
5454
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
55-
diag.span_suggestion(
56-
sp,
55+
diag.span_suggestion_verbose(
56+
sp.shrink_to_hi(),
5757
"use a float literal",
58-
format!("{snippet}.0"),
58+
".0",
5959
MachineApplicable,
6060
);
6161
}

tests/ui/consts/issue-39974.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0308]: mismatched types
22
--> $DIR/issue-39974.rs:1:21
33
|
44
LL | const LENGTH: f64 = 2;
5-
| ^
6-
| |
7-
| expected `f64`, found integer
8-
| help: use a float literal: `2.0`
5+
| ^ expected `f64`, found integer
6+
|
7+
help: use a float literal
8+
|
9+
LL | const LENGTH: f64 = 2.0;
10+
| ++
911

1012
error[E0308]: mismatched types
1113
--> $DIR/issue-39974.rs:5:19

tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr

+21-12
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@ error[E0308]: mismatched types
22
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:2:24
33
|
44
LL | let sixteen: f32 = 16;
5-
| --- ^^
6-
| | |
7-
| | expected `f32`, found integer
8-
| | help: use a float literal: `16.0`
5+
| --- ^^ expected `f32`, found integer
6+
| |
97
| expected due to this
8+
|
9+
help: use a float literal
10+
|
11+
LL | let sixteen: f32 = 16.0;
12+
| ++
1013

1114
error[E0308]: mismatched types
1215
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:5:38
1316
|
1417
LL | let a_million_and_seventy: f64 = 1_000_070;
15-
| --- ^^^^^^^^^
16-
| | |
17-
| | expected `f64`, found integer
18-
| | help: use a float literal: `1_000_070.0`
18+
| --- ^^^^^^^^^ expected `f64`, found integer
19+
| |
1920
| expected due to this
21+
|
22+
help: use a float literal
23+
|
24+
LL | let a_million_and_seventy: f64 = 1_000_070.0;
25+
| ++
2026

2127
error[E0308]: mismatched types
2228
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:8:30
2329
|
2430
LL | let negative_nine: f32 = -9;
25-
| --- ^^
26-
| | |
27-
| | expected `f32`, found integer
28-
| | help: use a float literal: `-9.0`
31+
| --- ^^ expected `f32`, found integer
32+
| |
2933
| expected due to this
34+
|
35+
help: use a float literal
36+
|
37+
LL | let negative_nine: f32 = -9.0;
38+
| ++
3039

3140
error[E0308]: mismatched types
3241
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:15:30

tests/ui/mismatched_types/float-literal-inference-restrictions.stderr

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ error[E0308]: mismatched types
22
--> $DIR/float-literal-inference-restrictions.rs:2:18
33
|
44
LL | let x: f32 = 1;
5-
| --- ^
6-
| | |
7-
| | expected `f32`, found integer
8-
| | help: use a float literal: `1.0`
5+
| --- ^ expected `f32`, found integer
6+
| |
97
| expected due to this
8+
|
9+
help: use a float literal
10+
|
11+
LL | let x: f32 = 1.0;
12+
| ++
1013

1114
error[E0308]: mismatched types
1215
--> $DIR/float-literal-inference-restrictions.rs:3:18

tests/ui/structs/structure-constructor-type-mismatch.stderr

+48-32
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,67 @@ error[E0308]: mismatched types
22
--> $DIR/structure-constructor-type-mismatch.rs:17:12
33
|
44
LL | x: 1,
5-
| ^
6-
| |
7-
| expected `f32`, found integer
8-
| help: use a float literal: `1.0`
5+
| ^ expected `f32`, found integer
6+
|
7+
help: use a float literal
8+
|
9+
LL | x: 1.0,
10+
| ++
911

1012
error[E0308]: mismatched types
1113
--> $DIR/structure-constructor-type-mismatch.rs:20:12
1214
|
1315
LL | y: 2,
14-
| ^
15-
| |
16-
| expected `f32`, found integer
17-
| help: use a float literal: `2.0`
16+
| ^ expected `f32`, found integer
17+
|
18+
help: use a float literal
19+
|
20+
LL | y: 2.0,
21+
| ++
1822

1923
error[E0308]: mismatched types
2024
--> $DIR/structure-constructor-type-mismatch.rs:26:12
2125
|
2226
LL | x: 3,
23-
| ^
24-
| |
25-
| expected `f32`, found integer
26-
| help: use a float literal: `3.0`
27+
| ^ expected `f32`, found integer
28+
|
29+
help: use a float literal
30+
|
31+
LL | x: 3.0,
32+
| ++
2733

2834
error[E0308]: mismatched types
2935
--> $DIR/structure-constructor-type-mismatch.rs:29:12
3036
|
3137
LL | y: 4,
32-
| ^
33-
| |
34-
| expected `f32`, found integer
35-
| help: use a float literal: `4.0`
38+
| ^ expected `f32`, found integer
39+
|
40+
help: use a float literal
41+
|
42+
LL | y: 4.0,
43+
| ++
3644

3745
error[E0308]: mismatched types
3846
--> $DIR/structure-constructor-type-mismatch.rs:35:12
3947
|
4048
LL | x: 5,
41-
| ^
42-
| |
43-
| expected `f32`, found integer
44-
| help: use a float literal: `5.0`
49+
| ^ expected `f32`, found integer
50+
|
51+
help: use a float literal
52+
|
53+
LL | x: 5.0,
54+
| ++
4555

4656
error[E0308]: mismatched types
4757
--> $DIR/structure-constructor-type-mismatch.rs:42:12
4858
|
4959
LL | x: 7,
50-
| ^
51-
| |
52-
| expected `f32`, found integer
53-
| help: use a float literal: `7.0`
60+
| ^ expected `f32`, found integer
61+
|
62+
help: use a float literal
63+
|
64+
LL | x: 7.0,
65+
| ++
5466

5567
error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied
5668
--> $DIR/structure-constructor-type-mismatch.rs:48:15
@@ -70,19 +82,23 @@ error[E0308]: mismatched types
7082
--> $DIR/structure-constructor-type-mismatch.rs:49:12
7183
|
7284
LL | x: 9,
73-
| ^
74-
| |
75-
| expected `f32`, found integer
76-
| help: use a float literal: `9.0`
85+
| ^ expected `f32`, found integer
86+
|
87+
help: use a float literal
88+
|
89+
LL | x: 9.0,
90+
| ++
7791

7892
error[E0308]: mismatched types
7993
--> $DIR/structure-constructor-type-mismatch.rs:50:12
8094
|
8195
LL | y: 10,
82-
| ^^
83-
| |
84-
| expected `f32`, found integer
85-
| help: use a float literal: `10.0`
96+
| ^^ expected `f32`, found integer
97+
|
98+
help: use a float literal
99+
|
100+
LL | y: 10.0,
101+
| ++
86102

87103
error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied
88104
--> $DIR/structure-constructor-type-mismatch.rs:54:9

tests/ui/try-block/try-block-type-error.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0271]: type mismatch resolving `<Option<f32> as Try>::Output == {integer}
22
--> $DIR/try-block-type-error.rs:10:9
33
|
44
LL | 42
5-
| ^^
6-
| |
7-
| expected `f32`, found integer
8-
| help: use a float literal: `42.0`
5+
| ^^ expected `f32`, found integer
6+
|
7+
help: use a float literal
8+
|
9+
LL | 42.0
10+
| ++
911

1012
error[E0271]: type mismatch resolving `<Option<i32> as Try>::Output == ()`
1113
--> $DIR/try-block-type-error.rs:16:5

0 commit comments

Comments
 (0)