Use shorter span for float literal suggestion

This commit is contained in:
Esteban Küber 2024-07-03 23:23:38 +00:00
parent a06a18a47f
commit 2699d8108c
6 changed files with 91 additions and 59 deletions

View File

@ -52,10 +52,10 @@ pub fn note_and_explain_type_err(
) = tcx.sess.source_map().span_to_snippet(sp) =>
{
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
diag.span_suggestion(
sp,
diag.span_suggestion_verbose(
sp.shrink_to_hi(),
"use a float literal",
format!("{snippet}.0"),
".0",
MachineApplicable,
);
}

View File

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/issue-39974.rs:1:21
|
LL | const LENGTH: f64 = 2;
| ^
| |
| expected `f64`, found integer
| help: use a float literal: `2.0`
| ^ expected `f64`, found integer
|
help: use a float literal
|
LL | const LENGTH: f64 = 2.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-39974.rs:5:19

View File

@ -2,31 +2,40 @@ error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:2:24
|
LL | let sixteen: f32 = 16;
| --- ^^
| | |
| | expected `f32`, found integer
| | help: use a float literal: `16.0`
| --- ^^ expected `f32`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let sixteen: f32 = 16.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:5:38
|
LL | let a_million_and_seventy: f64 = 1_000_070;
| --- ^^^^^^^^^
| | |
| | expected `f64`, found integer
| | help: use a float literal: `1_000_070.0`
| --- ^^^^^^^^^ expected `f64`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let a_million_and_seventy: f64 = 1_000_070.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:8:30
|
LL | let negative_nine: f32 = -9;
| --- ^^
| | |
| | expected `f32`, found integer
| | help: use a float literal: `-9.0`
| --- ^^ expected `f32`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let negative_nine: f32 = -9.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:15:30

View File

@ -2,11 +2,14 @@ error[E0308]: mismatched types
--> $DIR/float-literal-inference-restrictions.rs:2:18
|
LL | let x: f32 = 1;
| --- ^
| | |
| | expected `f32`, found integer
| | help: use a float literal: `1.0`
| --- ^ expected `f32`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let x: f32 = 1.0;
| ++
error[E0308]: mismatched types
--> $DIR/float-literal-inference-restrictions.rs:3:18

View File

@ -2,55 +2,67 @@ error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:17:12
|
LL | x: 1,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `1.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | x: 1.0,
| ++
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:20:12
|
LL | y: 2,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `2.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | y: 2.0,
| ++
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:26:12
|
LL | x: 3,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `3.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | x: 3.0,
| ++
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:29:12
|
LL | y: 4,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `4.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | y: 4.0,
| ++
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:35:12
|
LL | x: 5,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `5.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | x: 5.0,
| ++
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:42:12
|
LL | x: 7,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `7.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | x: 7.0,
| ++
error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/structure-constructor-type-mismatch.rs:48:15
@ -70,19 +82,23 @@ error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:49:12
|
LL | x: 9,
| ^
| |
| expected `f32`, found integer
| help: use a float literal: `9.0`
| ^ expected `f32`, found integer
|
help: use a float literal
|
LL | x: 9.0,
| ++
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:50:12
|
LL | y: 10,
| ^^
| |
| expected `f32`, found integer
| help: use a float literal: `10.0`
| ^^ expected `f32`, found integer
|
help: use a float literal
|
LL | y: 10.0,
| ++
error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/structure-constructor-type-mismatch.rs:54:9

View File

@ -2,10 +2,12 @@ error[E0271]: type mismatch resolving `<Option<f32> as Try>::Output == {integer}
--> $DIR/try-block-type-error.rs:10:9
|
LL | 42
| ^^
| |
| expected `f32`, found integer
| help: use a float literal: `42.0`
| ^^ expected `f32`, found integer
|
help: use a float literal
|
LL | 42.0
| ++
error[E0271]: type mismatch resolving `<Option<i32> as Try>::Output == ()`
--> $DIR/try-block-type-error.rs:16:5