diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index bc59b5e033b..fd50d1eb438 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -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, ); } diff --git a/tests/ui/consts/issue-39974.stderr b/tests/ui/consts/issue-39974.stderr index 114c4cfeaf7..a371ea5709e 100644 --- a/tests/ui/consts/issue-39974.stderr +++ b/tests/ui/consts/issue-39974.stderr @@ -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 diff --git a/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr b/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr index 6f853ccab37..6e32483aee4 100644 --- a/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr +++ b/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr @@ -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 diff --git a/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr b/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr index 454373c322e..6b3e0cb505f 100644 --- a/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr +++ b/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr @@ -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 diff --git a/tests/ui/structs/structure-constructor-type-mismatch.stderr b/tests/ui/structs/structure-constructor-type-mismatch.stderr index 63dda459396..cb957487347 100644 --- a/tests/ui/structs/structure-constructor-type-mismatch.stderr +++ b/tests/ui/structs/structure-constructor-type-mismatch.stderr @@ -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 diff --git a/tests/ui/try-block/try-block-type-error.stderr b/tests/ui/try-block/try-block-type-error.stderr index 3e9a584a551..2cdb5fdee79 100644 --- a/tests/ui/try-block/try-block-type-error.stderr +++ b/tests/ui/try-block/try-block-type-error.stderr @@ -2,10 +2,12 @@ error[E0271]: type mismatch resolving ` 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 ` as Try>::Output == ()` --> $DIR/try-block-type-error.rs:16:5