From 4b1297baf7b6e9cd4cac83748c483a2f100a59e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 21 Apr 2019 15:44:23 -0700 Subject: [PATCH 1/3] Suggest try_into when possible --- src/librustc_typeck/check/demand.rs | 329 ++-- .../associated-types-path-2.stderr | 8 + src/test/ui/discrim/discrim-ill-typed.stderr | 32 + ...loat-literal-inference-restrictions.stderr | 4 + src/test/ui/indexing-requires-a-uint.stderr | 4 + .../integer-literal-suffix-inference.stderr | 234 +-- src/test/ui/issues/issue-13359.stderr | 8 + src/test/ui/issues/issue-1362.stderr | 4 + src/test/ui/issues/issue-1448-2.stderr | 4 + src/test/ui/issues/issue-31910.stderr | 4 + src/test/ui/issues/issue-8761.stderr | 8 + .../meta-expected-error-correct-rev.a.stderr | 4 + ...od-ambig-one-trait-unknown-int-type.stderr | 4 + .../ui/mismatched_types/issue-26480.stderr | 4 + src/test/ui/numeric/numeric-cast-2.stderr | 12 + .../numeric-cast-without-suggestion.rs | 38 + .../numeric-cast-without-suggestion.stderr | 129 ++ src/test/ui/numeric/numeric-cast.fixed | 293 ++++ src/test/ui/numeric/numeric-cast.rs | 68 +- src/test/ui/numeric/numeric-cast.stderr | 845 +++++++---- src/test/ui/numeric/numeric-suffix.fixed | 298 ++++ src/test/ui/numeric/numeric-suffix.rs | 298 ++++ src/test/ui/numeric/numeric-suffix.stderr | 1341 +++++++++++++++++ src/test/ui/pptypedef.stderr | 8 + src/test/ui/repeat_count.stderr | 8 + src/test/ui/shift-various-bad-types.stderr | 4 + .../suggestions/recover-invalid-float.fixed | 10 + .../ui/suggestions/recover-invalid-float.rs | 11 +- .../suggestions/recover-invalid-float.stderr | 42 +- ...e-mismatch-struct-field-shorthand-2.stderr | 18 +- ...ype-mismatch-struct-field-shorthand.stderr | 27 +- .../ui/traits/traits-multidispatch-bad.stderr | 4 + ...ounds-inconsistent-projection-error.stderr | 4 + .../ui/tutorial-suffix-inference-test.stderr | 17 +- .../ui/ufcs/ufcs-qpath-self-mismatch.stderr | 8 + .../unboxed-closures-type-mismatch.stderr | 4 + 36 files changed, 3413 insertions(+), 725 deletions(-) create mode 100644 src/test/ui/numeric/numeric-cast-without-suggestion.rs create mode 100644 src/test/ui/numeric/numeric-cast-without-suggestion.stderr create mode 100644 src/test/ui/numeric/numeric-cast.fixed create mode 100644 src/test/ui/numeric/numeric-suffix.fixed create mode 100644 src/test/ui/numeric/numeric-suffix.rs create mode 100644 src/test/ui/numeric/numeric-suffix.stderr create mode 100644 src/test/ui/suggestions/recover-invalid-float.fixed diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 6ce03025bf23c..6249d6e56af68 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -559,14 +559,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } }; - let will_truncate = "will truncate the source value"; - let depending_on_isize = "will truncate or zero-extend depending on the bit width of \ - `isize`"; - let depending_on_usize = "will truncate or zero-extend depending on the bit width of \ - `usize`"; - let will_sign_extend = "will sign-extend the source value"; - let will_zero_extend = "will zero-extend the source value"; - // If casting this expression to a given numeric type would be appropriate in case of a type // mismatch. // @@ -596,10 +588,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } + let msg = format!("you can convert an `{}` to `{}`", checked_ty, expected_ty); + let cast_msg = format!("you can cast an `{} to `{}`", checked_ty, expected_ty); + let try_msg = format!("{} or panic if it the converted value wouldn't fit", msg); + let lit_msg = format!( + "change the type of the numeric literal from `{}` to `{}`", + checked_ty, + expected_ty, + ); + let needs_paren = expr.precedence().order() < (PREC_POSTFIX as i8); if let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) { - let msg = format!("you can cast an `{}` to `{}`", checked_ty, expected_ty); let cast_suggestion = format!( "{}{}{}{} as {}", prefix, @@ -608,6 +608,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if needs_paren { ")" } else { "" }, expected_ty, ); + let try_into_suggestion = format!( + "{}{}{}{}.try_into().unwrap()", + prefix, + if needs_paren { "(" } else { "" }, + src, + if needs_paren { ")" } else { "" }, + ); let into_suggestion = format!( "{}{}{}{}.into()", prefix, @@ -615,6 +622,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { src, if needs_paren { ")" } else { "" }, ); + let suffix_suggestion = format!( + "{}{}{}{}", + if needs_paren { "(" } else { "" }, + if let (ty::Int(_), ty::Float(_)) | (ty::Uint(_), ty::Float(_)) = ( + &expected_ty.sty, + &checked_ty.sty, + ) { + // Remove fractional part from literal, for example `42.0f32` into `42` + let src = src.trim_end_matches(&checked_ty.to_string()); + src.split(".").next().unwrap() + } else { + src.trim_end_matches(&checked_ty.to_string()) + }, + expected_ty, + if needs_paren { ")" } else { "" }, + ); let literal_is_ty_suffixed = |expr: &hir::Expr| { if let hir::ExprKind::Lit(lit) = &expr.node { lit.node.is_suffixed() @@ -623,35 +646,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } }; - let into_sugg = into_suggestion.clone(); - let suggest_to_change_suffix_or_into = |err: &mut DiagnosticBuilder<'_>, - note: Option<&str>| { - let suggest_msg = if literal_is_ty_suffixed(expr) { - format!( - "change the type of the numeric literal from `{}` to `{}`", - checked_ty, - expected_ty, - ) - } else { - match note { - Some(note) => format!("{}, which {}", msg, note), - _ => format!("{} in a lossless way", msg), - } - }; - - let suffix_suggestion = format!( - "{}{}{}{}", - if needs_paren { "(" } else { "" }, - src.trim_end_matches(&checked_ty.to_string()), - expected_ty, - if needs_paren { ")" } else { "" }, - ); - + let suggest_to_change_suffix_or_into = | + err: &mut DiagnosticBuilder<'_>, + is_fallible: bool, + | { + let into_sugg = into_suggestion.clone(); err.span_suggestion( expr.span, - &suggest_msg, if literal_is_ty_suffixed(expr) { - suffix_suggestion + &lit_msg + } else if is_fallible { + &try_msg + } else { + &msg + }, + if literal_is_ty_suffixed(expr) { + suffix_suggestion.clone() + } else if is_fallible { + try_into_suggestion } else { into_sugg }, @@ -661,188 +673,67 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match (&expected_ty.sty, &checked_ty.sty) { (&ty::Int(ref exp), &ty::Int(ref found)) => { - match (found.bit_width(), exp.bit_width()) { - (Some(found), Some(exp)) if found > exp => { - if can_cast { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_truncate), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - } - (None, _) | (_, None) => { - if can_cast { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, depending_on_isize), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - } - _ => { - suggest_to_change_suffix_or_into( - err, - Some(will_sign_extend), - ); - } - } + let is_fallible = match (found.bit_width(), exp.bit_width()) { + (Some(found), Some(exp)) if found > exp => true, + (None, _) | (_, None) => true, + _ => false, + }; + suggest_to_change_suffix_or_into(err, is_fallible); true } (&ty::Uint(ref exp), &ty::Uint(ref found)) => { - match (found.bit_width(), exp.bit_width()) { - (Some(found), Some(exp)) if found > exp => { - if can_cast { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_truncate), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - } - (None, _) | (_, None) => { - if can_cast { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, depending_on_usize), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - } - _ => { - suggest_to_change_suffix_or_into( - err, - Some(will_zero_extend), - ); - } - } + let is_fallible = match (found.bit_width(), exp.bit_width()) { + (Some(found), Some(exp)) if found > exp => true, + (None, _) | (_, None) => true, + _ => false, + }; + suggest_to_change_suffix_or_into(err, is_fallible); true } - (&ty::Int(ref exp), &ty::Uint(ref found)) => { - if can_cast { - match (found.bit_width(), exp.bit_width()) { - (Some(found), Some(exp)) if found > exp - 1 => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_truncate), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - (None, None) => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_truncate), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - (None, _) => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, depending_on_isize), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - (_, None) => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, depending_on_usize), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - _ => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_zero_extend), - cast_suggestion, - Applicability::MachineApplicable - ); - } - } - } - true - } - (&ty::Uint(ref exp), &ty::Int(ref found)) => { - if can_cast { - match (found.bit_width(), exp.bit_width()) { - (Some(found), Some(exp)) if found - 1 > exp => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_truncate), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - (None, None) => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_sign_extend), - cast_suggestion, - Applicability::MachineApplicable // lossy conversion - ); - } - (None, _) => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, depending_on_usize), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - (_, None) => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, depending_on_isize), - cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion - ); - } - _ => { - err.span_suggestion( - expr.span, - &format!("{}, which {}", msg, will_sign_extend), - cast_suggestion, - Applicability::MachineApplicable - ); - } - } - } + (&ty::Int(_), &ty::Uint(_)) | (&ty::Uint(_), &ty::Int(_)) => { + suggest_to_change_suffix_or_into(err, true); true } (&ty::Float(ref exp), &ty::Float(ref found)) => { if found.bit_width() < exp.bit_width() { - suggest_to_change_suffix_or_into( - err, - None, - ); - } else if can_cast { + suggest_to_change_suffix_or_into(err, false); + } else if literal_is_ty_suffixed(expr) { err.span_suggestion( expr.span, - &format!("{}, producing the closest possible value", msg), + &lit_msg, + suffix_suggestion, + Applicability::MachineApplicable, + ); + } else if can_cast { // Missing try_into implementation for `f64` to `f32` + err.span_suggestion( + expr.span, + &format!("{}, producing the closest possible value", cast_msg), cast_suggestion, - Applicability::MaybeIncorrect // lossy conversion + Applicability::MaybeIncorrect, // lossy conversion ); } true } (&ty::Uint(_), &ty::Float(_)) | (&ty::Int(_), &ty::Float(_)) => { - if can_cast { + if literal_is_ty_suffixed(expr) { + err.span_suggestion( + expr.span, + &lit_msg, + suffix_suggestion, + Applicability::MachineApplicable, + ); + } else if can_cast { + // Missing try_into implementation for `{float}` to `{integer}` err.span_suggestion( expr.span, &format!("{}, rounding the float towards zero", msg), cast_suggestion, Applicability::MaybeIncorrect // lossy conversion ); - err.warn("casting here will cause undefined behavior if the rounded value \ - cannot be represented by the target integer type, including \ - `Inf` and `NaN` (this is a bug and will be fixed)"); + err.warn("if the rounded value cannot be represented by the target \ + integer type, including `Inf` and `NaN`, casting will cause \ + undefined behavior \ + (https://github.com/rust-lang/rust/issues/10184)"); } true } @@ -851,18 +742,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if exp.bit_width() > found.bit_width().unwrap_or(256) { err.span_suggestion( expr.span, - &format!("{}, producing the floating point representation of the \ - integer", - msg), + &format!( + "{}, producing the floating point representation of the integer", + msg, + ), into_suggestion, Applicability::MachineApplicable ); - } else if can_cast { + } else if literal_is_ty_suffixed(expr) { + err.span_suggestion( + expr.span, + &lit_msg, + suffix_suggestion, + Applicability::MachineApplicable, + ); + } else { + // Missing try_into implementation for `{integer}` to `{float}` err.span_suggestion( expr.span, - &format!("{}, producing the floating point representation of the \ - integer, rounded if necessary", - msg), + &format!( + "{}, producing the floating point representation of the integer, + rounded if necessary", + cast_msg, + ), cast_suggestion, Applicability::MaybeIncorrect // lossy conversion ); @@ -874,18 +776,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if exp.bit_width() > found.bit_width().unwrap_or(256) { err.span_suggestion( expr.span, - &format!("{}, producing the floating point representation of the \ - integer", - msg), + &format!( + "{}, producing the floating point representation of the integer", + &msg, + ), into_suggestion, Applicability::MachineApplicable ); - } else if can_cast { + } else if literal_is_ty_suffixed(expr) { err.span_suggestion( expr.span, - &format!("{}, producing the floating point representation of the \ - integer, rounded if necessary", - msg), + &lit_msg, + suffix_suggestion, + Applicability::MachineApplicable, + ); + } else { + // Missing try_into implementation for `{integer}` to `{float}` + err.span_suggestion( + expr.span, + &format!( + "{}, producing the floating point representation of the integer, \ + rounded if necessary", + &msg, + ), cast_suggestion, Applicability::MaybeIncorrect // lossy conversion ); diff --git a/src/test/ui/associated-types/associated-types-path-2.stderr b/src/test/ui/associated-types/associated-types-path-2.stderr index 13d874bdb574d..c25f12d008703 100644 --- a/src/test/ui/associated-types/associated-types-path-2.stderr +++ b/src/test/ui/associated-types/associated-types-path-2.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | f1(2i32, 4i32); | ^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | f1(2i32, 4u32); + | ^^^^ error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:5 @@ -45,6 +49,10 @@ error[E0308]: mismatched types | LL | let _: i32 = f2(2i32); | ^^^^^^^^ expected i32, found u32 +help: you can convert an `u32` to `i32` or panic if it the converted value wouldn't fit + | +LL | let _: i32 = f2(2i32).try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/discrim/discrim-ill-typed.stderr b/src/test/ui/discrim/discrim-ill-typed.stderr index 14cdb9e07f902..543fecb249f98 100644 --- a/src/test/ui/discrim/discrim-ill-typed.stderr +++ b/src/test/ui/discrim/discrim-ill-typed.stderr @@ -3,48 +3,80 @@ error[E0308]: mismatched types | LL | OhNo = 0_u8, | ^^^^ expected i8, found u8 +help: change the type of the numeric literal from `u8` to `i8` + | +LL | OhNo = 0_i8, + | ^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:30:16 | LL | OhNo = 0_i8, | ^^^^ expected u8, found i8 +help: change the type of the numeric literal from `i8` to `u8` + | +LL | OhNo = 0_u8, + | ^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:43:16 | LL | OhNo = 0_u16, | ^^^^^ expected i16, found u16 +help: change the type of the numeric literal from `u16` to `i16` + | +LL | OhNo = 0_i16, + | ^^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:56:16 | LL | OhNo = 0_i16, | ^^^^^ expected u16, found i16 +help: change the type of the numeric literal from `i16` to `u16` + | +LL | OhNo = 0_u16, + | ^^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:69:16 | LL | OhNo = 0_u32, | ^^^^^ expected i32, found u32 +help: change the type of the numeric literal from `u32` to `i32` + | +LL | OhNo = 0_i32, + | ^^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:82:16 | LL | OhNo = 0_i32, | ^^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | OhNo = 0_u32, + | ^^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:95:16 | LL | OhNo = 0_u64, | ^^^^^ expected i64, found u64 +help: change the type of the numeric literal from `u64` to `i64` + | +LL | OhNo = 0_i64, + | ^^^^^ error[E0308]: mismatched types --> $DIR/discrim-ill-typed.rs:108:16 | LL | OhNo = 0_i64, | ^^^^^ expected u64, found i64 +help: change the type of the numeric literal from `i64` to `u64` + | +LL | OhNo = 0_u64, + | ^^^^^ error: aborting due to 8 previous errors diff --git a/src/test/ui/float-literal-inference-restrictions.stderr b/src/test/ui/float-literal-inference-restrictions.stderr index 6ac49b7ccd13a..839ca57ce5562 100644 --- a/src/test/ui/float-literal-inference-restrictions.stderr +++ b/src/test/ui/float-literal-inference-restrictions.stderr @@ -15,6 +15,10 @@ error[E0308]: mismatched types | LL | let y: f32 = 1f64; | ^^^^ expected f32, found f64 +help: change the type of the numeric literal from `f64` to `f32` + | +LL | let y: f32 = 1f32; + | ^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/indexing-requires-a-uint.stderr b/src/test/ui/indexing-requires-a-uint.stderr index a2f8a7cf2a68f..9dafe1c24f1c2 100644 --- a/src/test/ui/indexing-requires-a-uint.stderr +++ b/src/test/ui/indexing-requires-a-uint.stderr @@ -12,6 +12,10 @@ error[E0308]: mismatched types | LL | bar::(i); // i should not be re-coerced back to an isize | ^ expected isize, found usize +help: you can convert an `usize` to `isize` or panic if it the converted value wouldn't fit + | +LL | bar::(i.try_into().unwrap()); // i should not be re-coerced back to an isize + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/integer-literal-suffix-inference.stderr b/src/test/ui/integer-literal-suffix-inference.stderr index 04c8633c8b5d8..b5b3f27f0e6cd 100644 --- a/src/test/ui/integer-literal-suffix-inference.stderr +++ b/src/test/ui/integer-literal-suffix-inference.stderr @@ -3,288 +3,342 @@ error[E0308]: mismatched types | LL | id_i8(a16); | ^^^ expected i8, found i16 +help: you can convert an `i16` to `i8` or panic if it the converted value wouldn't fit + | +LL | id_i8(a16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:35:11 | LL | id_i8(a32); | ^^^ expected i8, found i32 +help: you can convert an `i32` to `i8` or panic if it the converted value wouldn't fit + | +LL | id_i8(a32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:38:11 | LL | id_i8(a64); | ^^^ expected i8, found i64 +help: you can convert an `i64` to `i8` or panic if it the converted value wouldn't fit + | +LL | id_i8(a64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:42:12 | LL | id_i16(a8); - | ^^ expected i16, found i8 -help: you can cast an `i8` to `i16`, which will sign-extend the source value - | -LL | id_i16(a8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected i16, found i8 + | help: you can convert an `i8` to `i16`: `a8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:46:12 | LL | id_i16(a32); | ^^^ expected i16, found i32 +help: you can convert an `i32` to `i16` or panic if it the converted value wouldn't fit + | +LL | id_i16(a32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:49:12 | LL | id_i16(a64); | ^^^ expected i16, found i64 +help: you can convert an `i64` to `i16` or panic if it the converted value wouldn't fit + | +LL | id_i16(a64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:53:12 | LL | id_i32(a8); - | ^^ expected i32, found i8 -help: you can cast an `i8` to `i32`, which will sign-extend the source value - | -LL | id_i32(a8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected i32, found i8 + | help: you can convert an `i8` to `i32`: `a8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:56:12 | LL | id_i32(a16); - | ^^^ expected i32, found i16 -help: you can cast an `i16` to `i32`, which will sign-extend the source value - | -LL | id_i32(a16.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected i32, found i16 + | help: you can convert an `i16` to `i32`: `a16.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:60:12 | LL | id_i32(a64); | ^^^ expected i32, found i64 +help: you can convert an `i64` to `i32` or panic if it the converted value wouldn't fit + | +LL | id_i32(a64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:64:12 | LL | id_i64(a8); - | ^^ expected i64, found i8 -help: you can cast an `i8` to `i64`, which will sign-extend the source value - | -LL | id_i64(a8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected i64, found i8 + | help: you can convert an `i8` to `i64`: `a8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:67:12 | LL | id_i64(a16); - | ^^^ expected i64, found i16 -help: you can cast an `i16` to `i64`, which will sign-extend the source value - | -LL | id_i64(a16.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected i64, found i16 + | help: you can convert an `i16` to `i64`: `a16.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:70:12 | LL | id_i64(a32); - | ^^^ expected i64, found i32 -help: you can cast an `i32` to `i64`, which will sign-extend the source value - | -LL | id_i64(a32.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected i64, found i32 + | help: you can convert an `i32` to `i64`: `a32.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:76:11 | LL | id_i8(c16); | ^^^ expected i8, found i16 +help: you can convert an `i16` to `i8` or panic if it the converted value wouldn't fit + | +LL | id_i8(c16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:79:11 | LL | id_i8(c32); | ^^^ expected i8, found i32 +help: you can convert an `i32` to `i8` or panic if it the converted value wouldn't fit + | +LL | id_i8(c32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:82:11 | LL | id_i8(c64); | ^^^ expected i8, found i64 +help: you can convert an `i64` to `i8` or panic if it the converted value wouldn't fit + | +LL | id_i8(c64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:86:12 | LL | id_i16(c8); - | ^^ expected i16, found i8 -help: you can cast an `i8` to `i16`, which will sign-extend the source value - | -LL | id_i16(c8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected i16, found i8 + | help: you can convert an `i8` to `i16`: `c8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:90:12 | LL | id_i16(c32); | ^^^ expected i16, found i32 +help: you can convert an `i32` to `i16` or panic if it the converted value wouldn't fit + | +LL | id_i16(c32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:93:12 | LL | id_i16(c64); | ^^^ expected i16, found i64 +help: you can convert an `i64` to `i16` or panic if it the converted value wouldn't fit + | +LL | id_i16(c64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:97:12 | LL | id_i32(c8); - | ^^ expected i32, found i8 -help: you can cast an `i8` to `i32`, which will sign-extend the source value - | -LL | id_i32(c8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected i32, found i8 + | help: you can convert an `i8` to `i32`: `c8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:100:12 | LL | id_i32(c16); - | ^^^ expected i32, found i16 -help: you can cast an `i16` to `i32`, which will sign-extend the source value - | -LL | id_i32(c16.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected i32, found i16 + | help: you can convert an `i16` to `i32`: `c16.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:104:12 | LL | id_i32(c64); | ^^^ expected i32, found i64 +help: you can convert an `i64` to `i32` or panic if it the converted value wouldn't fit + | +LL | id_i32(c64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:108:12 | LL | id_i64(a8); - | ^^ expected i64, found i8 -help: you can cast an `i8` to `i64`, which will sign-extend the source value - | -LL | id_i64(a8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected i64, found i8 + | help: you can convert an `i8` to `i64`: `a8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:111:12 | LL | id_i64(a16); - | ^^^ expected i64, found i16 -help: you can cast an `i16` to `i64`, which will sign-extend the source value - | -LL | id_i64(a16.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected i64, found i16 + | help: you can convert an `i16` to `i64`: `a16.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:114:12 | LL | id_i64(a32); - | ^^^ expected i64, found i32 -help: you can cast an `i32` to `i64`, which will sign-extend the source value - | -LL | id_i64(a32.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected i64, found i32 + | help: you can convert an `i32` to `i64`: `a32.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:120:11 | LL | id_u8(b16); | ^^^ expected u8, found u16 +help: you can convert an `u16` to `u8` or panic if it the converted value wouldn't fit + | +LL | id_u8(b16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:123:11 | LL | id_u8(b32); | ^^^ expected u8, found u32 +help: you can convert an `u32` to `u8` or panic if it the converted value wouldn't fit + | +LL | id_u8(b32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:126:11 | LL | id_u8(b64); | ^^^ expected u8, found u64 +help: you can convert an `u64` to `u8` or panic if it the converted value wouldn't fit + | +LL | id_u8(b64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:130:12 | LL | id_u16(b8); - | ^^ expected u16, found u8 -help: you can cast an `u8` to `u16`, which will zero-extend the source value - | -LL | id_u16(b8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected u16, found u8 + | help: you can convert an `u8` to `u16`: `b8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:134:12 | LL | id_u16(b32); | ^^^ expected u16, found u32 +help: you can convert an `u32` to `u16` or panic if it the converted value wouldn't fit + | +LL | id_u16(b32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:137:12 | LL | id_u16(b64); | ^^^ expected u16, found u64 +help: you can convert an `u64` to `u16` or panic if it the converted value wouldn't fit + | +LL | id_u16(b64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:141:12 | LL | id_u32(b8); - | ^^ expected u32, found u8 -help: you can cast an `u8` to `u32`, which will zero-extend the source value - | -LL | id_u32(b8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected u32, found u8 + | help: you can convert an `u8` to `u32`: `b8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:144:12 | LL | id_u32(b16); - | ^^^ expected u32, found u16 -help: you can cast an `u16` to `u32`, which will zero-extend the source value - | -LL | id_u32(b16.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected u32, found u16 + | help: you can convert an `u16` to `u32`: `b16.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:148:12 | LL | id_u32(b64); | ^^^ expected u32, found u64 +help: you can convert an `u64` to `u32` or panic if it the converted value wouldn't fit + | +LL | id_u32(b64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:152:12 | LL | id_u64(b8); - | ^^ expected u64, found u8 -help: you can cast an `u8` to `u64`, which will zero-extend the source value - | -LL | id_u64(b8.into()); - | ^^^^^^^^^ + | ^^ + | | + | expected u64, found u8 + | help: you can convert an `u8` to `u64`: `b8.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:155:12 | LL | id_u64(b16); - | ^^^ expected u64, found u16 -help: you can cast an `u16` to `u64`, which will zero-extend the source value - | -LL | id_u64(b16.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected u64, found u16 + | help: you can convert an `u16` to `u64`: `b16.into()` error[E0308]: mismatched types --> $DIR/integer-literal-suffix-inference.rs:158:12 | LL | id_u64(b32); - | ^^^ expected u64, found u32 -help: you can cast an `u32` to `u64`, which will zero-extend the source value - | -LL | id_u64(b32.into()); - | ^^^^^^^^^^ + | ^^^ + | | + | expected u64, found u32 + | help: you can convert an `u32` to `u64`: `b32.into()` error: aborting due to 36 previous errors diff --git a/src/test/ui/issues/issue-13359.stderr b/src/test/ui/issues/issue-13359.stderr index 00b7fbd456490..b16b7a5b2cf04 100644 --- a/src/test/ui/issues/issue-13359.stderr +++ b/src/test/ui/issues/issue-13359.stderr @@ -3,12 +3,20 @@ error[E0308]: mismatched types | LL | foo(1*(1 as isize)); | ^^^^^^^^^^^^^^ expected i16, found isize +help: you can convert an `isize` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo((1*(1 as isize)).try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/issue-13359.rs:10:9 | LL | bar(1*(1 as usize)); | ^^^^^^^^^^^^^^ expected u32, found usize +help: you can convert an `usize` to `u32` or panic if it the converted value wouldn't fit + | +LL | bar((1*(1 as usize)).try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-1362.stderr b/src/test/ui/issues/issue-1362.stderr index 5fef8497cde54..3f4fdee50fdde 100644 --- a/src/test/ui/issues/issue-1362.stderr +++ b/src/test/ui/issues/issue-1362.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | let x: u32 = 20i32; | ^^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | let x: u32 = 20u32; + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-1448-2.stderr b/src/test/ui/issues/issue-1448-2.stderr index 487b061eba133..a9fabca50a683 100644 --- a/src/test/ui/issues/issue-1448-2.stderr +++ b/src/test/ui/issues/issue-1448-2.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | println!("{}", foo(10i32)); | ^^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | println!("{}", foo(10u32)); + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-31910.stderr b/src/test/ui/issues/issue-31910.stderr index c58702da97bc6..8dd9287ffec79 100644 --- a/src/test/ui/issues/issue-31910.stderr +++ b/src/test/ui/issues/issue-31910.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | X = Trait::Number, | ^^^^^^^^^^^^^ expected isize, found i32 +help: you can convert an `i32` to `isize` or panic if it the converted value wouldn't fit + | +LL | X = Trait::Number.try_into().unwrap(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-8761.stderr b/src/test/ui/issues/issue-8761.stderr index fc0c14076019f..28847c5a82a07 100644 --- a/src/test/ui/issues/issue-8761.stderr +++ b/src/test/ui/issues/issue-8761.stderr @@ -3,12 +3,20 @@ error[E0308]: mismatched types | LL | A = 1i64, | ^^^^ expected isize, found i64 +help: change the type of the numeric literal from `i64` to `isize` + | +LL | A = 1isize, + | ^^^^^^ error[E0308]: mismatched types --> $DIR/issue-8761.rs:5:9 | LL | B = 2u8 | ^^^ expected isize, found u8 +help: change the type of the numeric literal from `u8` to `isize` + | +LL | B = 2isize + | ^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/meta-expected-error-correct-rev.a.stderr b/src/test/ui/meta-expected-error-correct-rev.a.stderr index 901bdcd8e4a7e..db1d5070e7fa1 100644 --- a/src/test/ui/meta-expected-error-correct-rev.a.stderr +++ b/src/test/ui/meta-expected-error-correct-rev.a.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | let x: u32 = 22_usize; | ^^^^^^^^ expected u32, found usize +help: change the type of the numeric literal from `usize` to `u32` + | +LL | let x: u32 = 22_u32; + | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index 8a63aed60d58d..be701b2bb3973 100644 --- a/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -11,6 +11,10 @@ error[E0308]: mismatched types | LL | let y: usize = x.foo(); | ^^^^^^^ expected usize, found isize +help: you can convert an `isize` to `usize` or panic if it the converted value wouldn't fit + | +LL | let y: usize = x.foo().try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/mismatched_types/issue-26480.stderr b/src/test/ui/mismatched_types/issue-26480.stderr index 59326fc1dd26a..1a81df8e2c464 100644 --- a/src/test/ui/mismatched_types/issue-26480.stderr +++ b/src/test/ui/mismatched_types/issue-26480.stderr @@ -6,6 +6,10 @@ LL | $arr.len() * size_of($arr[0])); ... LL | write!(hello); | -------------- in this macro invocation +help: you can convert an `usize` to `u64` or panic if it the converted value wouldn't fit + | +LL | ($arr.len() * size_of($arr[0])).try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0605]: non-primitive cast: `{integer}` as `()` --> $DIR/issue-26480.rs:22:19 diff --git a/src/test/ui/numeric/numeric-cast-2.stderr b/src/test/ui/numeric/numeric-cast-2.stderr index 79088f0e2ca2f..be4411e630bec 100644 --- a/src/test/ui/numeric/numeric-cast-2.stderr +++ b/src/test/ui/numeric/numeric-cast-2.stderr @@ -3,18 +3,30 @@ error[E0308]: mismatched types | LL | let x: u16 = foo(); | ^^^^^ expected u16, found i32 +help: you can convert an `i32` to `u16` or panic if it the converted value wouldn't fit + | +LL | let x: u16 = foo().try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/numeric-cast-2.rs:7:18 | LL | let y: i64 = x + x; | ^^^^^ expected i64, found u16 +help: you can convert an `u16` to `i64` or panic if it the converted value wouldn't fit + | +LL | let y: i64 = (x + x).try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/numeric-cast-2.rs:9:18 | LL | let z: i32 = x + x; | ^^^^^ expected i32, found u16 +help: you can convert an `u16` to `i32` or panic if it the converted value wouldn't fit + | +LL | let z: i32 = (x + x).try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/numeric/numeric-cast-without-suggestion.rs b/src/test/ui/numeric/numeric-cast-without-suggestion.rs new file mode 100644 index 0000000000000..faf24a8c18efd --- /dev/null +++ b/src/test/ui/numeric/numeric-cast-without-suggestion.rs @@ -0,0 +1,38 @@ +fn foo(_x: N) {} + +fn main() { + let x_usize: usize = 1; + let x_u64: u64 = 2; + let x_u32: u32 = 3; + let x_u16: u16 = 4; + let x_u8: u8 = 5; + let x_isize: isize = 6; + let x_i64: i64 = 7; + let x_i32: i32 = 8; + let x_i16: i16 = 9; + let x_i8: i8 = 10; + let x_f64: f64 = 11.0; + let x_f32: f32 = 12.0; + + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types + foo::(x_f32); //~ ERROR mismatched types + foo::(x_f64); //~ ERROR mismatched types +} diff --git a/src/test/ui/numeric/numeric-cast-without-suggestion.stderr b/src/test/ui/numeric/numeric-cast-without-suggestion.stderr new file mode 100644 index 0000000000000..a79eaea16ebb0 --- /dev/null +++ b/src/test/ui/numeric/numeric-cast-without-suggestion.stderr @@ -0,0 +1,129 @@ +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:17:18 + | +LL | foo::(x_f64); + | ^^^^^ expected usize, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:18:18 + | +LL | foo::(x_f32); + | ^^^^^ expected usize, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:19:18 + | +LL | foo::(x_f64); + | ^^^^^ expected isize, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:20:18 + | +LL | foo::(x_f32); + | ^^^^^ expected isize, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:21:16 + | +LL | foo::(x_f64); + | ^^^^^ expected u64, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:22:16 + | +LL | foo::(x_f32); + | ^^^^^ expected u64, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:23:16 + | +LL | foo::(x_f64); + | ^^^^^ expected i64, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:24:16 + | +LL | foo::(x_f32); + | ^^^^^ expected i64, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:25:16 + | +LL | foo::(x_f64); + | ^^^^^ expected u32, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:26:16 + | +LL | foo::(x_f32); + | ^^^^^ expected u32, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:27:16 + | +LL | foo::(x_f64); + | ^^^^^ expected i32, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:28:16 + | +LL | foo::(x_f32); + | ^^^^^ expected i32, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:29:16 + | +LL | foo::(x_f64); + | ^^^^^ expected u16, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:30:16 + | +LL | foo::(x_f32); + | ^^^^^ expected u16, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:31:16 + | +LL | foo::(x_f64); + | ^^^^^ expected i16, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:32:16 + | +LL | foo::(x_f32); + | ^^^^^ expected i16, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:33:15 + | +LL | foo::(x_f64); + | ^^^^^ expected u8, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:34:15 + | +LL | foo::(x_f32); + | ^^^^^ expected u8, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:35:15 + | +LL | foo::(x_f64); + | ^^^^^ expected i8, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:36:15 + | +LL | foo::(x_f32); + | ^^^^^ expected i8, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-without-suggestion.rs:37:16 + | +LL | foo::(x_f64); + | ^^^^^ expected f32, found f64 + +error: aborting due to 21 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/numeric/numeric-cast.fixed b/src/test/ui/numeric/numeric-cast.fixed new file mode 100644 index 0000000000000..6f78228a85d44 --- /dev/null +++ b/src/test/ui/numeric/numeric-cast.fixed @@ -0,0 +1,293 @@ +// run-rustfix + +// The `try_into` suggestion doesn't include this, but we do suggest it after applying it +use std::convert::TryInto; + +fn foo(_x: N) {} + +fn main() { + let x_usize: usize = 1; + let x_u64: u64 = 2; + let x_u32: u32 = 3; + let x_u16: u16 = 4; + let x_u8: u8 = 5; + let x_isize: isize = 6; + let x_i64: i64 = 7; + let x_i32: i32 = 8; + let x_i16: i16 = 9; + let x_i8: i8 = 10; + let x_f64: f64 = 11.0; + let x_f32: f32 = 12.0; + + foo::(x_usize); + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8.try_into().unwrap()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_isize); + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8.try_into().unwrap()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64); + foo::(x_u32.into()); + //~^ ERROR mismatched types + foo::(x_u16.into()); + //~^ ERROR mismatched types + foo::(x_u8.into()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8.try_into().unwrap()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64); + foo::(x_i32.into()); + //~^ ERROR mismatched types + foo::(x_i16.into()); + //~^ ERROR mismatched types + foo::(x_i8.into()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32); + foo::(x_u16.into()); + //~^ ERROR mismatched types + foo::(x_u8.into()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8.try_into().unwrap()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32); + foo::(x_i16.into()); + //~^ ERROR mismatched types + foo::(x_i8.into()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16); + foo::(x_u8.into()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8.try_into().unwrap()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16); + foo::(x_i8.into()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8); + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8.try_into().unwrap()); + //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_u8.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_isize.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i64.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i32.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i16.try_into().unwrap()); + //~^ ERROR mismatched types + foo::(x_i8); + // foo::(x_f64); + // foo::(x_f32); + + foo::(x_usize as f64); + //~^ ERROR mismatched types + foo::(x_u64 as f64); + //~^ ERROR mismatched types + foo::(x_u32.into()); + //~^ ERROR mismatched types + foo::(x_u16.into()); + //~^ ERROR mismatched types + foo::(x_u8.into()); + //~^ ERROR mismatched types + foo::(x_isize as f64); + //~^ ERROR mismatched types + foo::(x_i64 as f64); + //~^ ERROR mismatched types + foo::(x_i32.into()); + //~^ ERROR mismatched types + foo::(x_i16.into()); + //~^ ERROR mismatched types + foo::(x_i8.into()); + //~^ ERROR mismatched types + foo::(x_f64); + foo::(x_f32.into()); + //~^ ERROR mismatched types + + foo::(x_usize as f32); + //~^ ERROR mismatched types + foo::(x_u64 as f32); + //~^ ERROR mismatched types + foo::(x_u32 as f32); + //~^ ERROR mismatched types + foo::(x_u16.into()); + //~^ ERROR mismatched types + foo::(x_u8.into()); + //~^ ERROR mismatched types + foo::(x_isize as f32); + //~^ ERROR mismatched types + foo::(x_i64 as f32); + //~^ ERROR mismatched types + foo::(x_i32 as f32); + //~^ ERROR mismatched types + foo::(x_i16.into()); + //~^ ERROR mismatched types + foo::(x_i8.into()); + //~^ ERROR mismatched types + // foo::(x_f64); + foo::(x_f32); + + foo::((x_u8 as u16).into()); + //~^ ERROR mismatched types + foo::((-x_i8).into()); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/numeric/numeric-cast.rs b/src/test/ui/numeric/numeric-cast.rs index 39378c288fe56..7bddfc5090535 100644 --- a/src/test/ui/numeric/numeric-cast.rs +++ b/src/test/ui/numeric/numeric-cast.rs @@ -1,3 +1,8 @@ +// run-rustfix + +// The `try_into` suggestion doesn't include this, but we do suggest it after applying it +use std::convert::TryInto; + fn foo(_x: N) {} fn main() { @@ -33,10 +38,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -57,10 +60,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -81,10 +82,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -105,10 +104,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -129,10 +126,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -153,10 +148,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -177,10 +170,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -201,10 +192,8 @@ fn main() { foo::(x_i16); foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -225,10 +214,8 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -249,10 +236,8 @@ fn main() { foo::(x_i16); //~^ ERROR mismatched types foo::(x_i8); - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types + // foo::(x_f64); + // foo::(x_f32); foo::(x_usize); //~^ ERROR mismatched types @@ -298,8 +283,7 @@ fn main() { //~^ ERROR mismatched types foo::(x_i8); //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types + // foo::(x_f64); foo::(x_f32); foo::(x_u8 as u16); diff --git a/src/test/ui/numeric/numeric-cast.stderr b/src/test/ui/numeric/numeric-cast.stderr index 2c4f6e20f1f0a..9e7dcf7e41b55 100644 --- a/src/test/ui/numeric/numeric-cast.stderr +++ b/src/test/ui/numeric/numeric-cast.stderr @@ -1,907 +1,1118 @@ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:18:18 + --> $DIR/numeric-cast.rs:23:18 | LL | foo::(x_u64); | ^^^^^ expected usize, found u64 +help: you can convert an `u64` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:20:18 + --> $DIR/numeric-cast.rs:25:18 | LL | foo::(x_u32); | ^^^^^ expected usize, found u32 +help: you can convert an `u32` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:22:18 + --> $DIR/numeric-cast.rs:27:18 | LL | foo::(x_u16); | ^^^^^ expected usize, found u16 +help: you can convert an `u16` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:24:18 + --> $DIR/numeric-cast.rs:29:18 | LL | foo::(x_u8); | ^^^^ expected usize, found u8 +help: you can convert an `u8` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:26:18 + --> $DIR/numeric-cast.rs:31:18 | LL | foo::(x_isize); | ^^^^^^^ expected usize, found isize +help: you can convert an `isize` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:28:18 + --> $DIR/numeric-cast.rs:33:18 | LL | foo::(x_i64); | ^^^^^ expected usize, found i64 +help: you can convert an `i64` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:30:18 + --> $DIR/numeric-cast.rs:35:18 | LL | foo::(x_i32); | ^^^^^ expected usize, found i32 +help: you can convert an `i32` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:32:18 + --> $DIR/numeric-cast.rs:37:18 | LL | foo::(x_i16); | ^^^^^ expected usize, found i16 +help: you can convert an `i16` to `usize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:34:18 + --> $DIR/numeric-cast.rs:39:18 | LL | foo::(x_i8); | ^^^^ expected usize, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:36:18 +help: you can convert an `i8` to `usize` or panic if it the converted value wouldn't fit | -LL | foo::(x_f64); - | ^^^^^ expected usize, found f64 +LL | foo::(x_i8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:38:18 - | -LL | foo::(x_f32); - | ^^^^^ expected usize, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:41:18 + --> $DIR/numeric-cast.rs:44:18 | LL | foo::(x_usize); | ^^^^^^^ expected isize, found usize +help: you can convert an `usize` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:43:18 + --> $DIR/numeric-cast.rs:46:18 | LL | foo::(x_u64); | ^^^^^ expected isize, found u64 +help: you can convert an `u64` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:45:18 + --> $DIR/numeric-cast.rs:48:18 | LL | foo::(x_u32); | ^^^^^ expected isize, found u32 +help: you can convert an `u32` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:47:18 + --> $DIR/numeric-cast.rs:50:18 | LL | foo::(x_u16); | ^^^^^ expected isize, found u16 +help: you can convert an `u16` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:49:18 + --> $DIR/numeric-cast.rs:52:18 | LL | foo::(x_u8); | ^^^^ expected isize, found u8 +help: you can convert an `u8` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:52:18 + --> $DIR/numeric-cast.rs:55:18 | LL | foo::(x_i64); | ^^^^^ expected isize, found i64 +help: you can convert an `i64` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:54:18 + --> $DIR/numeric-cast.rs:57:18 | LL | foo::(x_i32); | ^^^^^ expected isize, found i32 +help: you can convert an `i32` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:56:18 + --> $DIR/numeric-cast.rs:59:18 | LL | foo::(x_i16); | ^^^^^ expected isize, found i16 +help: you can convert an `i16` to `isize` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:58:18 + --> $DIR/numeric-cast.rs:61:18 | LL | foo::(x_i8); | ^^^^ expected isize, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:60:18 +help: you can convert an `i8` to `isize` or panic if it the converted value wouldn't fit | -LL | foo::(x_f64); - | ^^^^^ expected isize, found f64 +LL | foo::(x_i8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:62:18 - | -LL | foo::(x_f32); - | ^^^^^ expected isize, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:65:16 + --> $DIR/numeric-cast.rs:66:16 | LL | foo::(x_usize); | ^^^^^^^ expected u64, found usize +help: you can convert an `usize` to `u64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:68:16 + --> $DIR/numeric-cast.rs:69:16 | LL | foo::(x_u32); - | ^^^^^ expected u64, found u32 -help: you can cast an `u32` to `u64`, which will zero-extend the source value - | -LL | foo::(x_u32.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected u64, found u32 + | help: you can convert an `u32` to `u64`: `x_u32.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:70:16 + --> $DIR/numeric-cast.rs:71:16 | LL | foo::(x_u16); - | ^^^^^ expected u64, found u16 -help: you can cast an `u16` to `u64`, which will zero-extend the source value - | -LL | foo::(x_u16.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected u64, found u16 + | help: you can convert an `u16` to `u64`: `x_u16.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:72:16 + --> $DIR/numeric-cast.rs:73:16 | LL | foo::(x_u8); - | ^^^^ expected u64, found u8 -help: you can cast an `u8` to `u64`, which will zero-extend the source value - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ + | ^^^^ + | | + | expected u64, found u8 + | help: you can convert an `u8` to `u64`: `x_u8.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:74:16 + --> $DIR/numeric-cast.rs:75:16 | LL | foo::(x_isize); | ^^^^^^^ expected u64, found isize +help: you can convert an `isize` to `u64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:76:16 + --> $DIR/numeric-cast.rs:77:16 | LL | foo::(x_i64); | ^^^^^ expected u64, found i64 +help: you can convert an `i64` to `u64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:78:16 + --> $DIR/numeric-cast.rs:79:16 | LL | foo::(x_i32); | ^^^^^ expected u64, found i32 +help: you can convert an `i32` to `u64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:80:16 + --> $DIR/numeric-cast.rs:81:16 | LL | foo::(x_i16); | ^^^^^ expected u64, found i16 +help: you can convert an `i16` to `u64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:82:16 + --> $DIR/numeric-cast.rs:83:16 | LL | foo::(x_i8); | ^^^^ expected u64, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:84:16 +help: you can convert an `i8` to `u64` or panic if it the converted value wouldn't fit | -LL | foo::(x_f64); - | ^^^^^ expected u64, found f64 +LL | foo::(x_i8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:86:16 - | -LL | foo::(x_f32); - | ^^^^^ expected u64, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:89:16 + --> $DIR/numeric-cast.rs:88:16 | LL | foo::(x_usize); | ^^^^^^^ expected i64, found usize +help: you can convert an `usize` to `i64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:91:16 + --> $DIR/numeric-cast.rs:90:16 | LL | foo::(x_u64); | ^^^^^ expected i64, found u64 +help: you can convert an `u64` to `i64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:93:16 + --> $DIR/numeric-cast.rs:92:16 | LL | foo::(x_u32); | ^^^^^ expected i64, found u32 +help: you can convert an `u32` to `i64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:95:16 + --> $DIR/numeric-cast.rs:94:16 | LL | foo::(x_u16); | ^^^^^ expected i64, found u16 +help: you can convert an `u16` to `i64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:97:16 + --> $DIR/numeric-cast.rs:96:16 | LL | foo::(x_u8); | ^^^^ expected i64, found u8 +help: you can convert an `u8` to `i64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:99:16 + --> $DIR/numeric-cast.rs:98:16 | LL | foo::(x_isize); | ^^^^^^^ expected i64, found isize +help: you can convert an `isize` to `i64` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:102:16 + --> $DIR/numeric-cast.rs:101:16 | LL | foo::(x_i32); - | ^^^^^ expected i64, found i32 -help: you can cast an `i32` to `i64`, which will sign-extend the source value - | -LL | foo::(x_i32.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected i64, found i32 + | help: you can convert an `i32` to `i64`: `x_i32.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:104:16 + --> $DIR/numeric-cast.rs:103:16 | LL | foo::(x_i16); - | ^^^^^ expected i64, found i16 -help: you can cast an `i16` to `i64`, which will sign-extend the source value - | -LL | foo::(x_i16.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected i64, found i16 + | help: you can convert an `i16` to `i64`: `x_i16.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:106:16 + --> $DIR/numeric-cast.rs:105:16 | LL | foo::(x_i8); - | ^^^^ expected i64, found i8 -help: you can cast an `i8` to `i64`, which will sign-extend the source value - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:108:16 - | -LL | foo::(x_f64); - | ^^^^^ expected i64, found f64 + | ^^^^ + | | + | expected i64, found i8 + | help: you can convert an `i8` to `i64`: `x_i8.into()` error[E0308]: mismatched types --> $DIR/numeric-cast.rs:110:16 | -LL | foo::(x_f32); - | ^^^^^ expected i64, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:113:16 - | LL | foo::(x_usize); | ^^^^^^^ expected u32, found usize +help: you can convert an `usize` to `u32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:115:16 + --> $DIR/numeric-cast.rs:112:16 | LL | foo::(x_u64); | ^^^^^ expected u32, found u64 +help: you can convert an `u64` to `u32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:118:16 + --> $DIR/numeric-cast.rs:115:16 | LL | foo::(x_u16); - | ^^^^^ expected u32, found u16 -help: you can cast an `u16` to `u32`, which will zero-extend the source value - | -LL | foo::(x_u16.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected u32, found u16 + | help: you can convert an `u16` to `u32`: `x_u16.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:120:16 + --> $DIR/numeric-cast.rs:117:16 | LL | foo::(x_u8); - | ^^^^ expected u32, found u8 -help: you can cast an `u8` to `u32`, which will zero-extend the source value - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ + | ^^^^ + | | + | expected u32, found u8 + | help: you can convert an `u8` to `u32`: `x_u8.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:122:16 + --> $DIR/numeric-cast.rs:119:16 | LL | foo::(x_isize); | ^^^^^^^ expected u32, found isize +help: you can convert an `isize` to `u32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:124:16 + --> $DIR/numeric-cast.rs:121:16 | LL | foo::(x_i64); | ^^^^^ expected u32, found i64 +help: you can convert an `i64` to `u32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:126:16 + --> $DIR/numeric-cast.rs:123:16 | LL | foo::(x_i32); | ^^^^^ expected u32, found i32 +help: you can convert an `i32` to `u32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:128:16 + --> $DIR/numeric-cast.rs:125:16 | LL | foo::(x_i16); | ^^^^^ expected u32, found i16 +help: you can convert an `i16` to `u32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:130:16 + --> $DIR/numeric-cast.rs:127:16 | LL | foo::(x_i8); | ^^^^ expected u32, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:132:16 - | -LL | foo::(x_f64); - | ^^^^^ expected u32, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:134:16 +help: you can convert an `i8` to `u32` or panic if it the converted value wouldn't fit | -LL | foo::(x_f32); - | ^^^^^ expected u32, found f32 +LL | foo::(x_i8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:137:16 + --> $DIR/numeric-cast.rs:132:16 | LL | foo::(x_usize); | ^^^^^^^ expected i32, found usize +help: you can convert an `usize` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:139:16 + --> $DIR/numeric-cast.rs:134:16 | LL | foo::(x_u64); | ^^^^^ expected i32, found u64 +help: you can convert an `u64` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:141:16 + --> $DIR/numeric-cast.rs:136:16 | LL | foo::(x_u32); | ^^^^^ expected i32, found u32 +help: you can convert an `u32` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:143:16 + --> $DIR/numeric-cast.rs:138:16 | LL | foo::(x_u16); | ^^^^^ expected i32, found u16 +help: you can convert an `u16` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:145:16 + --> $DIR/numeric-cast.rs:140:16 | LL | foo::(x_u8); | ^^^^ expected i32, found u8 +help: you can convert an `u8` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:147:16 + --> $DIR/numeric-cast.rs:142:16 | LL | foo::(x_isize); | ^^^^^^^ expected i32, found isize +help: you can convert an `isize` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:149:16 + --> $DIR/numeric-cast.rs:144:16 | LL | foo::(x_i64); | ^^^^^ expected i32, found i64 +help: you can convert an `i64` to `i32` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:152:16 + --> $DIR/numeric-cast.rs:147:16 | LL | foo::(x_i16); - | ^^^^^ expected i32, found i16 -help: you can cast an `i16` to `i32`, which will sign-extend the source value - | -LL | foo::(x_i16.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected i32, found i16 + | help: you can convert an `i16` to `i32`: `x_i16.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:154:16 + --> $DIR/numeric-cast.rs:149:16 | LL | foo::(x_i8); - | ^^^^ expected i32, found i8 -help: you can cast an `i8` to `i32`, which will sign-extend the source value - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:156:16 - | -LL | foo::(x_f64); - | ^^^^^ expected i32, found f64 + | ^^^^ + | | + | expected i32, found i8 + | help: you can convert an `i8` to `i32`: `x_i8.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:158:16 - | -LL | foo::(x_f32); - | ^^^^^ expected i32, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:161:16 + --> $DIR/numeric-cast.rs:154:16 | LL | foo::(x_usize); | ^^^^^^^ expected u16, found usize +help: you can convert an `usize` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:163:16 + --> $DIR/numeric-cast.rs:156:16 | LL | foo::(x_u64); | ^^^^^ expected u16, found u64 +help: you can convert an `u64` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:165:16 + --> $DIR/numeric-cast.rs:158:16 | LL | foo::(x_u32); | ^^^^^ expected u16, found u32 +help: you can convert an `u32` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:168:16 + --> $DIR/numeric-cast.rs:161:16 | LL | foo::(x_u8); - | ^^^^ expected u16, found u8 -help: you can cast an `u8` to `u16`, which will zero-extend the source value - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ + | ^^^^ + | | + | expected u16, found u8 + | help: you can convert an `u8` to `u16`: `x_u8.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:170:16 + --> $DIR/numeric-cast.rs:163:16 | LL | foo::(x_isize); | ^^^^^^^ expected u16, found isize +help: you can convert an `isize` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:172:16 + --> $DIR/numeric-cast.rs:165:16 | LL | foo::(x_i64); | ^^^^^ expected u16, found i64 +help: you can convert an `i64` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:174:16 + --> $DIR/numeric-cast.rs:167:16 | LL | foo::(x_i32); | ^^^^^ expected u16, found i32 +help: you can convert an `i32` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:176:16 + --> $DIR/numeric-cast.rs:169:16 | LL | foo::(x_i16); | ^^^^^ expected u16, found i16 +help: you can convert an `i16` to `u16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:178:16 + --> $DIR/numeric-cast.rs:171:16 | LL | foo::(x_i8); | ^^^^ expected u16, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:180:16 - | -LL | foo::(x_f64); - | ^^^^^ expected u16, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:182:16 +help: you can convert an `i8` to `u16` or panic if it the converted value wouldn't fit | -LL | foo::(x_f32); - | ^^^^^ expected u16, found f32 +LL | foo::(x_i8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:185:16 + --> $DIR/numeric-cast.rs:176:16 | LL | foo::(x_usize); | ^^^^^^^ expected i16, found usize +help: you can convert an `usize` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:187:16 + --> $DIR/numeric-cast.rs:178:16 | LL | foo::(x_u64); | ^^^^^ expected i16, found u64 +help: you can convert an `u64` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:189:16 + --> $DIR/numeric-cast.rs:180:16 | LL | foo::(x_u32); | ^^^^^ expected i16, found u32 +help: you can convert an `u32` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:191:16 + --> $DIR/numeric-cast.rs:182:16 | LL | foo::(x_u16); | ^^^^^ expected i16, found u16 +help: you can convert an `u16` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:193:16 + --> $DIR/numeric-cast.rs:184:16 | LL | foo::(x_u8); | ^^^^ expected i16, found u8 +help: you can convert an `u8` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:195:16 + --> $DIR/numeric-cast.rs:186:16 | LL | foo::(x_isize); | ^^^^^^^ expected i16, found isize +help: you can convert an `isize` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:197:16 + --> $DIR/numeric-cast.rs:188:16 | LL | foo::(x_i64); | ^^^^^ expected i16, found i64 +help: you can convert an `i64` to `i16` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:199:16 + --> $DIR/numeric-cast.rs:190:16 | LL | foo::(x_i32); | ^^^^^ expected i16, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:202:16 - | -LL | foo::(x_i8); - | ^^^^ expected i16, found i8 -help: you can cast an `i8` to `i16`, which will sign-extend the source value - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:204:16 +help: you can convert an `i32` to `i16` or panic if it the converted value wouldn't fit | -LL | foo::(x_f64); - | ^^^^^ expected i16, found f64 +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:206:16 + --> $DIR/numeric-cast.rs:193:16 | -LL | foo::(x_f32); - | ^^^^^ expected i16, found f32 +LL | foo::(x_i8); + | ^^^^ + | | + | expected i16, found i8 + | help: you can convert an `i8` to `i16`: `x_i8.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:209:15 + --> $DIR/numeric-cast.rs:198:15 | LL | foo::(x_usize); | ^^^^^^^ expected u8, found usize +help: you can convert an `usize` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:211:15 + --> $DIR/numeric-cast.rs:200:15 | LL | foo::(x_u64); | ^^^^^ expected u8, found u64 +help: you can convert an `u64` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:213:15 + --> $DIR/numeric-cast.rs:202:15 | LL | foo::(x_u32); | ^^^^^ expected u8, found u32 +help: you can convert an `u32` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:215:15 + --> $DIR/numeric-cast.rs:204:15 | LL | foo::(x_u16); | ^^^^^ expected u8, found u16 +help: you can convert an `u16` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:218:15 + --> $DIR/numeric-cast.rs:207:15 | LL | foo::(x_isize); | ^^^^^^^ expected u8, found isize +help: you can convert an `isize` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:220:15 + --> $DIR/numeric-cast.rs:209:15 | LL | foo::(x_i64); | ^^^^^ expected u8, found i64 +help: you can convert an `i64` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:222:15 + --> $DIR/numeric-cast.rs:211:15 | LL | foo::(x_i32); | ^^^^^ expected u8, found i32 +help: you can convert an `i32` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:224:15 + --> $DIR/numeric-cast.rs:213:15 | LL | foo::(x_i16); | ^^^^^ expected u8, found i16 +help: you can convert an `i16` to `u8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:226:15 + --> $DIR/numeric-cast.rs:215:15 | LL | foo::(x_i8); | ^^^^ expected u8, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:228:15 - | -LL | foo::(x_f64); - | ^^^^^ expected u8, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:230:15 +help: you can convert an `i8` to `u8` or panic if it the converted value wouldn't fit | -LL | foo::(x_f32); - | ^^^^^ expected u8, found f32 +LL | foo::(x_i8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:233:15 + --> $DIR/numeric-cast.rs:220:15 | LL | foo::(x_usize); | ^^^^^^^ expected i8, found usize +help: you can convert an `usize` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_usize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:235:15 + --> $DIR/numeric-cast.rs:222:15 | LL | foo::(x_u64); | ^^^^^ expected i8, found u64 +help: you can convert an `u64` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:237:15 + --> $DIR/numeric-cast.rs:224:15 | LL | foo::(x_u32); | ^^^^^ expected i8, found u32 +help: you can convert an `u32` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:239:15 + --> $DIR/numeric-cast.rs:226:15 | LL | foo::(x_u16); | ^^^^^ expected i8, found u16 +help: you can convert an `u16` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:241:15 + --> $DIR/numeric-cast.rs:228:15 | LL | foo::(x_u8); | ^^^^ expected i8, found u8 +help: you can convert an `u8` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_u8.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:243:15 + --> $DIR/numeric-cast.rs:230:15 | LL | foo::(x_isize); | ^^^^^^^ expected i8, found isize +help: you can convert an `isize` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_isize.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:245:15 + --> $DIR/numeric-cast.rs:232:15 | LL | foo::(x_i64); | ^^^^^ expected i8, found i64 +help: you can convert an `i64` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i64.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:247:15 + --> $DIR/numeric-cast.rs:234:15 | LL | foo::(x_i32); | ^^^^^ expected i8, found i32 +help: you can convert an `i32` to `i8` or panic if it the converted value wouldn't fit + | +LL | foo::(x_i32.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:249:15 + --> $DIR/numeric-cast.rs:236:15 | LL | foo::(x_i16); | ^^^^^ expected i8, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:252:15 - | -LL | foo::(x_f64); - | ^^^^^ expected i8, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:254:15 +help: you can convert an `i16` to `i8` or panic if it the converted value wouldn't fit | -LL | foo::(x_f32); - | ^^^^^ expected i8, found f32 +LL | foo::(x_i16.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:257:16 + --> $DIR/numeric-cast.rs:242:16 | LL | foo::(x_usize); | ^^^^^^^ expected f64, found usize +help: you can cast an `usize to `f64`, producing the floating point representation of the integer, + | rounded if necessary +LL | foo::(x_usize as f64); + | ^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:259:16 + --> $DIR/numeric-cast.rs:244:16 | LL | foo::(x_u64); | ^^^^^ expected f64, found u64 +help: you can cast an `u64 to `f64`, producing the floating point representation of the integer, + | rounded if necessary +LL | foo::(x_u64 as f64); + | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:261:16 + --> $DIR/numeric-cast.rs:246:16 | LL | foo::(x_u32); | ^^^^^ expected f64, found u32 -help: you can cast an `u32` to `f64`, producing the floating point representation of the integer +help: you can convert an `u32` to `f64`, producing the floating point representation of the integer | LL | foo::(x_u32.into()); | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:263:16 + --> $DIR/numeric-cast.rs:248:16 | LL | foo::(x_u16); | ^^^^^ expected f64, found u16 -help: you can cast an `u16` to `f64`, producing the floating point representation of the integer +help: you can convert an `u16` to `f64`, producing the floating point representation of the integer | LL | foo::(x_u16.into()); | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:265:16 + --> $DIR/numeric-cast.rs:250:16 | LL | foo::(x_u8); | ^^^^ expected f64, found u8 -help: you can cast an `u8` to `f64`, producing the floating point representation of the integer +help: you can convert an `u8` to `f64`, producing the floating point representation of the integer | LL | foo::(x_u8.into()); | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:267:16 + --> $DIR/numeric-cast.rs:252:16 | LL | foo::(x_isize); | ^^^^^^^ expected f64, found isize +help: you can convert an `isize` to `f64`, producing the floating point representation of the integer, rounded if necessary + | +LL | foo::(x_isize as f64); + | ^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:269:16 + --> $DIR/numeric-cast.rs:254:16 | LL | foo::(x_i64); | ^^^^^ expected f64, found i64 +help: you can convert an `i64` to `f64`, producing the floating point representation of the integer, rounded if necessary + | +LL | foo::(x_i64 as f64); + | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:271:16 + --> $DIR/numeric-cast.rs:256:16 | LL | foo::(x_i32); | ^^^^^ expected f64, found i32 -help: you can cast an `i32` to `f64`, producing the floating point representation of the integer +help: you can convert an `i32` to `f64`, producing the floating point representation of the integer | LL | foo::(x_i32.into()); | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:273:16 + --> $DIR/numeric-cast.rs:258:16 | LL | foo::(x_i16); | ^^^^^ expected f64, found i16 -help: you can cast an `i16` to `f64`, producing the floating point representation of the integer +help: you can convert an `i16` to `f64`, producing the floating point representation of the integer | LL | foo::(x_i16.into()); | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:275:16 + --> $DIR/numeric-cast.rs:260:16 | LL | foo::(x_i8); | ^^^^ expected f64, found i8 -help: you can cast an `i8` to `f64`, producing the floating point representation of the integer +help: you can convert an `i8` to `f64`, producing the floating point representation of the integer | LL | foo::(x_i8.into()); | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:278:16 + --> $DIR/numeric-cast.rs:263:16 | LL | foo::(x_f32); - | ^^^^^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | foo::(x_f32.into()); - | ^^^^^^^^^^^^ + | ^^^^^ + | | + | expected f64, found f32 + | help: you can convert an `f32` to `f64`: `x_f32.into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:281:16 + --> $DIR/numeric-cast.rs:266:16 | LL | foo::(x_usize); | ^^^^^^^ expected f32, found usize +help: you can cast an `usize to `f32`, producing the floating point representation of the integer, + | rounded if necessary +LL | foo::(x_usize as f32); + | ^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:283:16 + --> $DIR/numeric-cast.rs:268:16 | LL | foo::(x_u64); | ^^^^^ expected f32, found u64 +help: you can cast an `u64 to `f32`, producing the floating point representation of the integer, + | rounded if necessary +LL | foo::(x_u64 as f32); + | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:285:16 + --> $DIR/numeric-cast.rs:270:16 | LL | foo::(x_u32); | ^^^^^ expected f32, found u32 +help: you can cast an `u32 to `f32`, producing the floating point representation of the integer, + | rounded if necessary +LL | foo::(x_u32 as f32); + | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:287:16 + --> $DIR/numeric-cast.rs:272:16 | LL | foo::(x_u16); | ^^^^^ expected f32, found u16 -help: you can cast an `u16` to `f32`, producing the floating point representation of the integer +help: you can convert an `u16` to `f32`, producing the floating point representation of the integer | LL | foo::(x_u16.into()); | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:289:16 + --> $DIR/numeric-cast.rs:274:16 | LL | foo::(x_u8); | ^^^^ expected f32, found u8 -help: you can cast an `u8` to `f32`, producing the floating point representation of the integer +help: you can convert an `u8` to `f32`, producing the floating point representation of the integer | LL | foo::(x_u8.into()); | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:291:16 + --> $DIR/numeric-cast.rs:276:16 | LL | foo::(x_isize); | ^^^^^^^ expected f32, found isize +help: you can convert an `isize` to `f32`, producing the floating point representation of the integer, rounded if necessary + | +LL | foo::(x_isize as f32); + | ^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:293:16 + --> $DIR/numeric-cast.rs:278:16 | LL | foo::(x_i64); | ^^^^^ expected f32, found i64 +help: you can convert an `i64` to `f32`, producing the floating point representation of the integer, rounded if necessary + | +LL | foo::(x_i64 as f32); + | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:295:16 + --> $DIR/numeric-cast.rs:280:16 | LL | foo::(x_i32); | ^^^^^ expected f32, found i32 +help: you can convert an `i32` to `f32`, producing the floating point representation of the integer, rounded if necessary + | +LL | foo::(x_i32 as f32); + | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:297:16 + --> $DIR/numeric-cast.rs:282:16 | LL | foo::(x_i16); | ^^^^^ expected f32, found i16 -help: you can cast an `i16` to `f32`, producing the floating point representation of the integer +help: you can convert an `i16` to `f32`, producing the floating point representation of the integer | LL | foo::(x_i16.into()); | ^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:299:16 + --> $DIR/numeric-cast.rs:284:16 | LL | foo::(x_i8); | ^^^^ expected f32, found i8 -help: you can cast an `i8` to `f32`, producing the floating point representation of the integer +help: you can convert an `i8` to `f32`, producing the floating point representation of the integer | LL | foo::(x_i8.into()); | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:301:16 - | -LL | foo::(x_f64); - | ^^^^^ expected f32, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:305:16 + --> $DIR/numeric-cast.rs:289:16 | LL | foo::(x_u8 as u16); - | ^^^^^^^^^^^ expected u32, found u16 -help: you can cast an `u16` to `u32`, which will zero-extend the source value - | -LL | foo::((x_u8 as u16).into()); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^ + | | + | expected u32, found u16 + | help: you can convert an `u16` to `u32`: `(x_u8 as u16).into()` error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:307:16 + --> $DIR/numeric-cast.rs:291:16 | LL | foo::(-x_i8); - | ^^^^^ expected i32, found i8 -help: you can cast an `i8` to `i32`, which will sign-extend the source value - | -LL | foo::((-x_i8).into()); - | ^^^^^^^^^^^^^^ + | ^^^^^ + | | + | expected i32, found i8 + | help: you can convert an `i8` to `i32`: `(-x_i8).into()` -error: aborting due to 134 previous errors +error: aborting due to 113 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/numeric/numeric-suffix.fixed b/src/test/ui/numeric/numeric-suffix.fixed new file mode 100644 index 0000000000000..53c5fe0f435f9 --- /dev/null +++ b/src/test/ui/numeric/numeric-suffix.fixed @@ -0,0 +1,298 @@ +// run-rustfix + +fn foo(_x: N) {} + +fn main() { + foo::(42_usize); + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42usize); + //~^ ERROR mismatched types + foo::(42usize); + //~^ ERROR mismatched types + + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42isize); + //~^ ERROR mismatched types + foo::(42isize); + //~^ ERROR mismatched types + + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42u64); + //~^ ERROR mismatched types + foo::(42u64); + //~^ ERROR mismatched types + + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42i64); + //~^ ERROR mismatched types + foo::(42i64); + //~^ ERROR mismatched types + + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42u32); + //~^ ERROR mismatched types + foo::(42u32); + //~^ ERROR mismatched types + + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42i32); + //~^ ERROR mismatched types + foo::(42i32); + //~^ ERROR mismatched types + + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42u16); + //~^ ERROR mismatched types + foo::(42u16); + //~^ ERROR mismatched types + + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i16); + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42i16); + //~^ ERROR mismatched types + foo::(42i16); + //~^ ERROR mismatched types + + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42u8); + //~^ ERROR mismatched types + foo::(42u8); + //~^ ERROR mismatched types + + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42_i8); + foo::(42i8); + //~^ ERROR mismatched types + foo::(42i8); + //~^ ERROR mismatched types + + foo::(42_f64); + //~^ ERROR mismatched types + foo::(42_f64); + //~^ ERROR mismatched types + foo::(42_u32.into()); + //~^ ERROR mismatched types + foo::(42_u16.into()); + //~^ ERROR mismatched types + foo::(42_u8.into()); + //~^ ERROR mismatched types + foo::(42_f64); + //~^ ERROR mismatched types + foo::(42_f64); + //~^ ERROR mismatched types + foo::(42_i32.into()); + //~^ ERROR mismatched types + foo::(42_i16.into()); + //~^ ERROR mismatched types + foo::(42_i8.into()); + //~^ ERROR mismatched types + foo::(42.0_f64); + foo::(42.0_f64); + //~^ ERROR mismatched types + + foo::(42_f32); + //~^ ERROR mismatched types + foo::(42_f32); + //~^ ERROR mismatched types + foo::(42_f32); + //~^ ERROR mismatched types + foo::(42_u16.into()); + //~^ ERROR mismatched types + foo::(42_u8.into()); + //~^ ERROR mismatched types + foo::(42_f32); + //~^ ERROR mismatched types + foo::(42_f32); + //~^ ERROR mismatched types + foo::(42_f32); + //~^ ERROR mismatched types + foo::(42_i16.into()); + //~^ ERROR mismatched types + foo::(42_i8.into()); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + foo::(42.0_f32); + + foo::((42_u8 as u16).into()); + //~^ ERROR mismatched types + foo::((-42_i8).into()); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/numeric/numeric-suffix.rs b/src/test/ui/numeric/numeric-suffix.rs new file mode 100644 index 0000000000000..ca38ed82220b2 --- /dev/null +++ b/src/test/ui/numeric/numeric-suffix.rs @@ -0,0 +1,298 @@ +// run-rustfix + +fn foo(_x: N) {} + +fn main() { + foo::(42_usize); + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + foo::(42.0_f32); + //~^ ERROR mismatched types + + foo::(42_usize); + //~^ ERROR mismatched types + foo::(42_u64); + //~^ ERROR mismatched types + foo::(42_u32); + //~^ ERROR mismatched types + foo::(42_u16); + //~^ ERROR mismatched types + foo::(42_u8); + //~^ ERROR mismatched types + foo::(42_isize); + //~^ ERROR mismatched types + foo::(42_i64); + //~^ ERROR mismatched types + foo::(42_i32); + //~^ ERROR mismatched types + foo::(42_i16); + //~^ ERROR mismatched types + foo::(42_i8); + //~^ ERROR mismatched types + foo::(42.0_f64); + //~^ ERROR mismatched types + foo::(42.0_f32); + + foo::(42_u8 as u16); + //~^ ERROR mismatched types + foo::(-42_i8); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/numeric/numeric-suffix.stderr b/src/test/ui/numeric/numeric-suffix.stderr new file mode 100644 index 0000000000000..c88eeeb9f70b2 --- /dev/null +++ b/src/test/ui/numeric/numeric-suffix.stderr @@ -0,0 +1,1341 @@ +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:7:18 + | +LL | foo::(42_u64); + | ^^^^^^ expected usize, found u64 +help: change the type of the numeric literal from `u64` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:9:18 + | +LL | foo::(42_u32); + | ^^^^^^ expected usize, found u32 +help: change the type of the numeric literal from `u32` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:11:18 + | +LL | foo::(42_u16); + | ^^^^^^ expected usize, found u16 +help: change the type of the numeric literal from `u16` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:13:18 + | +LL | foo::(42_u8); + | ^^^^^ expected usize, found u8 +help: change the type of the numeric literal from `u8` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:15:18 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected usize, found isize +help: change the type of the numeric literal from `isize` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:17:18 + | +LL | foo::(42_i64); + | ^^^^^^ expected usize, found i64 +help: change the type of the numeric literal from `i64` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:19:18 + | +LL | foo::(42_i32); + | ^^^^^^ expected usize, found i32 +help: change the type of the numeric literal from `i32` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:21:18 + | +LL | foo::(42_i16); + | ^^^^^^ expected usize, found i16 +help: change the type of the numeric literal from `i16` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:23:18 + | +LL | foo::(42_i8); + | ^^^^^ expected usize, found i8 +help: change the type of the numeric literal from `i8` to `usize` + | +LL | foo::(42_usize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:25:18 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected usize, found f64 +help: change the type of the numeric literal from `f64` to `usize` + | +LL | foo::(42usize); + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:27:18 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected usize, found f32 +help: change the type of the numeric literal from `f32` to `usize` + | +LL | foo::(42usize); + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:30:18 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected isize, found usize +help: change the type of the numeric literal from `usize` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:32:18 + | +LL | foo::(42_u64); + | ^^^^^^ expected isize, found u64 +help: change the type of the numeric literal from `u64` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:34:18 + | +LL | foo::(42_u32); + | ^^^^^^ expected isize, found u32 +help: change the type of the numeric literal from `u32` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:36:18 + | +LL | foo::(42_u16); + | ^^^^^^ expected isize, found u16 +help: change the type of the numeric literal from `u16` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:38:18 + | +LL | foo::(42_u8); + | ^^^^^ expected isize, found u8 +help: change the type of the numeric literal from `u8` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:41:18 + | +LL | foo::(42_i64); + | ^^^^^^ expected isize, found i64 +help: change the type of the numeric literal from `i64` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:43:18 + | +LL | foo::(42_i32); + | ^^^^^^ expected isize, found i32 +help: change the type of the numeric literal from `i32` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:45:18 + | +LL | foo::(42_i16); + | ^^^^^^ expected isize, found i16 +help: change the type of the numeric literal from `i16` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:47:18 + | +LL | foo::(42_i8); + | ^^^^^ expected isize, found i8 +help: change the type of the numeric literal from `i8` to `isize` + | +LL | foo::(42_isize); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:49:18 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected isize, found f64 +help: change the type of the numeric literal from `f64` to `isize` + | +LL | foo::(42isize); + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:51:18 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected isize, found f32 +help: change the type of the numeric literal from `f32` to `isize` + | +LL | foo::(42isize); + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:54:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected u64, found usize +help: change the type of the numeric literal from `usize` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:57:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected u64, found u32 +help: change the type of the numeric literal from `u32` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:59:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected u64, found u16 +help: change the type of the numeric literal from `u16` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:61:16 + | +LL | foo::(42_u8); + | ^^^^^ expected u64, found u8 +help: change the type of the numeric literal from `u8` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:63:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected u64, found isize +help: change the type of the numeric literal from `isize` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:65:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected u64, found i64 +help: change the type of the numeric literal from `i64` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:67:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected u64, found i32 +help: change the type of the numeric literal from `i32` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:69:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected u64, found i16 +help: change the type of the numeric literal from `i16` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:71:16 + | +LL | foo::(42_i8); + | ^^^^^ expected u64, found i8 +help: change the type of the numeric literal from `i8` to `u64` + | +LL | foo::(42_u64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:73:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected u64, found f64 +help: change the type of the numeric literal from `f64` to `u64` + | +LL | foo::(42u64); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:75:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected u64, found f32 +help: change the type of the numeric literal from `f32` to `u64` + | +LL | foo::(42u64); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:78:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected i64, found usize +help: change the type of the numeric literal from `usize` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:80:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected i64, found u64 +help: change the type of the numeric literal from `u64` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:82:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected i64, found u32 +help: change the type of the numeric literal from `u32` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:84:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected i64, found u16 +help: change the type of the numeric literal from `u16` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:86:16 + | +LL | foo::(42_u8); + | ^^^^^ expected i64, found u8 +help: change the type of the numeric literal from `u8` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:88:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected i64, found isize +help: change the type of the numeric literal from `isize` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:91:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected i64, found i32 +help: change the type of the numeric literal from `i32` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:93:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected i64, found i16 +help: change the type of the numeric literal from `i16` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:95:16 + | +LL | foo::(42_i8); + | ^^^^^ expected i64, found i8 +help: change the type of the numeric literal from `i8` to `i64` + | +LL | foo::(42_i64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:97:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected i64, found f64 +help: change the type of the numeric literal from `f64` to `i64` + | +LL | foo::(42i64); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:99:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected i64, found f32 +help: change the type of the numeric literal from `f32` to `i64` + | +LL | foo::(42i64); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:102:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected u32, found usize +help: change the type of the numeric literal from `usize` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:104:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected u32, found u64 +help: change the type of the numeric literal from `u64` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:107:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected u32, found u16 +help: change the type of the numeric literal from `u16` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:109:16 + | +LL | foo::(42_u8); + | ^^^^^ expected u32, found u8 +help: change the type of the numeric literal from `u8` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:111:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected u32, found isize +help: change the type of the numeric literal from `isize` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:113:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected u32, found i64 +help: change the type of the numeric literal from `i64` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:115:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:117:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected u32, found i16 +help: change the type of the numeric literal from `i16` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:119:16 + | +LL | foo::(42_i8); + | ^^^^^ expected u32, found i8 +help: change the type of the numeric literal from `i8` to `u32` + | +LL | foo::(42_u32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:121:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected u32, found f64 +help: change the type of the numeric literal from `f64` to `u32` + | +LL | foo::(42u32); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:123:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected u32, found f32 +help: change the type of the numeric literal from `f32` to `u32` + | +LL | foo::(42u32); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:126:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected i32, found usize +help: change the type of the numeric literal from `usize` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:128:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected i32, found u64 +help: change the type of the numeric literal from `u64` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:130:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected i32, found u32 +help: change the type of the numeric literal from `u32` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:132:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected i32, found u16 +help: change the type of the numeric literal from `u16` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:134:16 + | +LL | foo::(42_u8); + | ^^^^^ expected i32, found u8 +help: change the type of the numeric literal from `u8` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:136:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected i32, found isize +help: change the type of the numeric literal from `isize` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:138:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected i32, found i64 +help: change the type of the numeric literal from `i64` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:141:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected i32, found i16 +help: change the type of the numeric literal from `i16` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:143:16 + | +LL | foo::(42_i8); + | ^^^^^ expected i32, found i8 +help: change the type of the numeric literal from `i8` to `i32` + | +LL | foo::(42_i32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:145:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected i32, found f64 +help: change the type of the numeric literal from `f64` to `i32` + | +LL | foo::(42i32); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:147:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected i32, found f32 +help: change the type of the numeric literal from `f32` to `i32` + | +LL | foo::(42i32); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:150:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected u16, found usize +help: change the type of the numeric literal from `usize` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:152:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected u16, found u64 +help: change the type of the numeric literal from `u64` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:154:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected u16, found u32 +help: change the type of the numeric literal from `u32` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:157:16 + | +LL | foo::(42_u8); + | ^^^^^ expected u16, found u8 +help: change the type of the numeric literal from `u8` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:159:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected u16, found isize +help: change the type of the numeric literal from `isize` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:161:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected u16, found i64 +help: change the type of the numeric literal from `i64` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:163:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected u16, found i32 +help: change the type of the numeric literal from `i32` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:165:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected u16, found i16 +help: change the type of the numeric literal from `i16` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:167:16 + | +LL | foo::(42_i8); + | ^^^^^ expected u16, found i8 +help: change the type of the numeric literal from `i8` to `u16` + | +LL | foo::(42_u16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:169:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected u16, found f64 +help: change the type of the numeric literal from `f64` to `u16` + | +LL | foo::(42u16); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:171:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected u16, found f32 +help: change the type of the numeric literal from `f32` to `u16` + | +LL | foo::(42u16); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:174:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected i16, found usize +help: change the type of the numeric literal from `usize` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:176:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected i16, found u64 +help: change the type of the numeric literal from `u64` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:178:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected i16, found u32 +help: change the type of the numeric literal from `u32` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:180:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected i16, found u16 +help: change the type of the numeric literal from `u16` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:182:16 + | +LL | foo::(42_u8); + | ^^^^^ expected i16, found u8 +help: change the type of the numeric literal from `u8` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:184:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected i16, found isize +help: change the type of the numeric literal from `isize` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:186:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected i16, found i64 +help: change the type of the numeric literal from `i64` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:188:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected i16, found i32 +help: change the type of the numeric literal from `i32` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:191:16 + | +LL | foo::(42_i8); + | ^^^^^ expected i16, found i8 +help: change the type of the numeric literal from `i8` to `i16` + | +LL | foo::(42_i16); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:193:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected i16, found f64 +help: change the type of the numeric literal from `f64` to `i16` + | +LL | foo::(42i16); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:195:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected i16, found f32 +help: change the type of the numeric literal from `f32` to `i16` + | +LL | foo::(42i16); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:198:15 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected u8, found usize +help: change the type of the numeric literal from `usize` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:200:15 + | +LL | foo::(42_u64); + | ^^^^^^ expected u8, found u64 +help: change the type of the numeric literal from `u64` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:202:15 + | +LL | foo::(42_u32); + | ^^^^^^ expected u8, found u32 +help: change the type of the numeric literal from `u32` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:204:15 + | +LL | foo::(42_u16); + | ^^^^^^ expected u8, found u16 +help: change the type of the numeric literal from `u16` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:207:15 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected u8, found isize +help: change the type of the numeric literal from `isize` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:209:15 + | +LL | foo::(42_i64); + | ^^^^^^ expected u8, found i64 +help: change the type of the numeric literal from `i64` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:211:15 + | +LL | foo::(42_i32); + | ^^^^^^ expected u8, found i32 +help: change the type of the numeric literal from `i32` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:213:15 + | +LL | foo::(42_i16); + | ^^^^^^ expected u8, found i16 +help: change the type of the numeric literal from `i16` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:215:15 + | +LL | foo::(42_i8); + | ^^^^^ expected u8, found i8 +help: change the type of the numeric literal from `i8` to `u8` + | +LL | foo::(42_u8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:217:15 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected u8, found f64 +help: change the type of the numeric literal from `f64` to `u8` + | +LL | foo::(42u8); + | ^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:219:15 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected u8, found f32 +help: change the type of the numeric literal from `f32` to `u8` + | +LL | foo::(42u8); + | ^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:222:15 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected i8, found usize +help: change the type of the numeric literal from `usize` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:224:15 + | +LL | foo::(42_u64); + | ^^^^^^ expected i8, found u64 +help: change the type of the numeric literal from `u64` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:226:15 + | +LL | foo::(42_u32); + | ^^^^^^ expected i8, found u32 +help: change the type of the numeric literal from `u32` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:228:15 + | +LL | foo::(42_u16); + | ^^^^^^ expected i8, found u16 +help: change the type of the numeric literal from `u16` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:230:15 + | +LL | foo::(42_u8); + | ^^^^^ expected i8, found u8 +help: change the type of the numeric literal from `u8` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:232:15 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected i8, found isize +help: change the type of the numeric literal from `isize` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:234:15 + | +LL | foo::(42_i64); + | ^^^^^^ expected i8, found i64 +help: change the type of the numeric literal from `i64` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:236:15 + | +LL | foo::(42_i32); + | ^^^^^^ expected i8, found i32 +help: change the type of the numeric literal from `i32` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:238:15 + | +LL | foo::(42_i16); + | ^^^^^^ expected i8, found i16 +help: change the type of the numeric literal from `i16` to `i8` + | +LL | foo::(42_i8); + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:241:15 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected i8, found f64 +help: change the type of the numeric literal from `f64` to `i8` + | +LL | foo::(42i8); + | ^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:243:15 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected i8, found f32 +help: change the type of the numeric literal from `f32` to `i8` + | +LL | foo::(42i8); + | ^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:246:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected f64, found usize +help: change the type of the numeric literal from `usize` to `f64` + | +LL | foo::(42_f64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:248:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected f64, found u64 +help: change the type of the numeric literal from `u64` to `f64` + | +LL | foo::(42_f64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:250:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected f64, found u32 +help: you can convert an `u32` to `f64`, producing the floating point representation of the integer + | +LL | foo::(42_u32.into()); + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:252:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected f64, found u16 +help: you can convert an `u16` to `f64`, producing the floating point representation of the integer + | +LL | foo::(42_u16.into()); + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:254:16 + | +LL | foo::(42_u8); + | ^^^^^ expected f64, found u8 +help: you can convert an `u8` to `f64`, producing the floating point representation of the integer + | +LL | foo::(42_u8.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:256:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected f64, found isize +help: change the type of the numeric literal from `isize` to `f64` + | +LL | foo::(42_f64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:258:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected f64, found i64 +help: change the type of the numeric literal from `i64` to `f64` + | +LL | foo::(42_f64); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:260:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected f64, found i32 +help: you can convert an `i32` to `f64`, producing the floating point representation of the integer + | +LL | foo::(42_i32.into()); + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:262:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected f64, found i16 +help: you can convert an `i16` to `f64`, producing the floating point representation of the integer + | +LL | foo::(42_i16.into()); + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:264:16 + | +LL | foo::(42_i8); + | ^^^^^ expected f64, found i8 +help: you can convert an `i8` to `f64`, producing the floating point representation of the integer + | +LL | foo::(42_i8.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:267:16 + | +LL | foo::(42.0_f32); + | ^^^^^^^^ expected f64, found f32 +help: change the type of the numeric literal from `f32` to `f64` + | +LL | foo::(42.0_f64); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:270:16 + | +LL | foo::(42_usize); + | ^^^^^^^^ expected f32, found usize +help: change the type of the numeric literal from `usize` to `f32` + | +LL | foo::(42_f32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:272:16 + | +LL | foo::(42_u64); + | ^^^^^^ expected f32, found u64 +help: change the type of the numeric literal from `u64` to `f32` + | +LL | foo::(42_f32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:274:16 + | +LL | foo::(42_u32); + | ^^^^^^ expected f32, found u32 +help: change the type of the numeric literal from `u32` to `f32` + | +LL | foo::(42_f32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:276:16 + | +LL | foo::(42_u16); + | ^^^^^^ expected f32, found u16 +help: you can convert an `u16` to `f32`, producing the floating point representation of the integer + | +LL | foo::(42_u16.into()); + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:278:16 + | +LL | foo::(42_u8); + | ^^^^^ expected f32, found u8 +help: you can convert an `u8` to `f32`, producing the floating point representation of the integer + | +LL | foo::(42_u8.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:280:16 + | +LL | foo::(42_isize); + | ^^^^^^^^ expected f32, found isize +help: change the type of the numeric literal from `isize` to `f32` + | +LL | foo::(42_f32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:282:16 + | +LL | foo::(42_i64); + | ^^^^^^ expected f32, found i64 +help: change the type of the numeric literal from `i64` to `f32` + | +LL | foo::(42_f32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:284:16 + | +LL | foo::(42_i32); + | ^^^^^^ expected f32, found i32 +help: change the type of the numeric literal from `i32` to `f32` + | +LL | foo::(42_f32); + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:286:16 + | +LL | foo::(42_i16); + | ^^^^^^ expected f32, found i16 +help: you can convert an `i16` to `f32`, producing the floating point representation of the integer + | +LL | foo::(42_i16.into()); + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:288:16 + | +LL | foo::(42_i8); + | ^^^^^ expected f32, found i8 +help: you can convert an `i8` to `f32`, producing the floating point representation of the integer + | +LL | foo::(42_i8.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:290:16 + | +LL | foo::(42.0_f64); + | ^^^^^^^^ expected f32, found f64 +help: change the type of the numeric literal from `f64` to `f32` + | +LL | foo::(42.0_f32); + | ^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:294:16 + | +LL | foo::(42_u8 as u16); + | ^^^^^^^^^^^^ + | | + | expected u32, found u16 + | help: you can convert an `u16` to `u32`: `(42_u8 as u16).into()` + +error[E0308]: mismatched types + --> $DIR/numeric-suffix.rs:296:16 + | +LL | foo::(-42_i8); + | ^^^^^^ + | | + | expected i32, found i8 + | help: you can convert an `i8` to `i32`: `(-42_i8).into()` + +error: aborting due to 134 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/pptypedef.stderr b/src/test/ui/pptypedef.stderr index 32ee1a6aae99d..dc4b3ce370cb1 100644 --- a/src/test/ui/pptypedef.stderr +++ b/src/test/ui/pptypedef.stderr @@ -3,12 +3,20 @@ error[E0308]: mismatched types | LL | let_in(3u32, |i| { assert!(i == 3i32); }); | ^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | let_in(3u32, |i| { assert!(i == 3u32); }); + | ^^^^ error[E0308]: mismatched types --> $DIR/pptypedef.rs:8:37 | LL | let_in(3i32, |i| { assert!(i == 3u32); }); | ^^^^ expected i32, found u32 +help: change the type of the numeric literal from `u32` to `i32` + | +LL | let_in(3i32, |i| { assert!(i == 3i32); }); + | ^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/repeat_count.stderr b/src/test/ui/repeat_count.stderr index d4c2edf993ed4..6772aa1c38d2c 100644 --- a/src/test/ui/repeat_count.stderr +++ b/src/test/ui/repeat_count.stderr @@ -42,12 +42,20 @@ error[E0308]: mismatched types | LL | let f = [0; -4_isize]; | ^^^^^^^^ expected usize, found isize +help: you can convert an `isize` to `usize` or panic if it the converted value wouldn't fit + | +LL | let f = [0; (-4_isize).try_into().unwrap()]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/repeat_count.rs:28:23 | LL | let f = [0_usize; -1_isize]; | ^^^^^^^^ expected usize, found isize +help: you can convert an `isize` to `usize` or panic if it the converted value wouldn't fit + | +LL | let f = [0_usize; (-1_isize).try_into().unwrap()]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/repeat_count.rs:34:17 diff --git a/src/test/ui/shift-various-bad-types.stderr b/src/test/ui/shift-various-bad-types.stderr index 8ffc0f1ea08cc..97523fe82cd4e 100644 --- a/src/test/ui/shift-various-bad-types.stderr +++ b/src/test/ui/shift-various-bad-types.stderr @@ -27,6 +27,10 @@ error[E0308]: mismatched types | LL | let _: i32 = 22_i64 >> 1_i32; | ^^^^^^^^^^^^^^^ expected i32, found i64 +help: you can convert an `i64` to `i32` or panic if it the converted value wouldn't fit + | +LL | let _: i32 = (22_i64 >> 1_i32).try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/suggestions/recover-invalid-float.fixed b/src/test/ui/suggestions/recover-invalid-float.fixed new file mode 100644 index 0000000000000..62389ba612083 --- /dev/null +++ b/src/test/ui/suggestions/recover-invalid-float.fixed @@ -0,0 +1,10 @@ +// run-rustfix + +fn main() { + let _: f32 = 0.3; + //~^ ERROR float literals must have an integer part + let _: f32 = 0.42f32; + //~^ ERROR float literals must have an integer part + let _: f64 = 0.5f64; + //~^ ERROR float literals must have an integer part +} diff --git a/src/test/ui/suggestions/recover-invalid-float.rs b/src/test/ui/suggestions/recover-invalid-float.rs index 506ef8900b881..a5a7efe5e76e8 100644 --- a/src/test/ui/suggestions/recover-invalid-float.rs +++ b/src/test/ui/suggestions/recover-invalid-float.rs @@ -1,11 +1,10 @@ +// run-rustfix + fn main() { - let _: usize = .3; + let _: f32 = .3; //~^ ERROR float literals must have an integer part - //~| ERROR mismatched types - let _: usize = .42f32; + let _: f32 = .42f32; //~^ ERROR float literals must have an integer part - //~| ERROR mismatched types - let _: usize = .5f64; + let _: f64 = .5f64; //~^ ERROR float literals must have an integer part - //~| ERROR mismatched types } diff --git a/src/test/ui/suggestions/recover-invalid-float.stderr b/src/test/ui/suggestions/recover-invalid-float.stderr index c464676b444cc..dd24746eab80f 100644 --- a/src/test/ui/suggestions/recover-invalid-float.stderr +++ b/src/test/ui/suggestions/recover-invalid-float.stderr @@ -1,42 +1,20 @@ error: float literals must have an integer part - --> $DIR/recover-invalid-float.rs:2:20 + --> $DIR/recover-invalid-float.rs:4:18 | -LL | let _: usize = .3; - | ^^ help: must have an integer part: `0.3` +LL | let _: f32 = .3; + | ^^ help: must have an integer part: `0.3` error: float literals must have an integer part - --> $DIR/recover-invalid-float.rs:5:20 + --> $DIR/recover-invalid-float.rs:6:18 | -LL | let _: usize = .42f32; - | ^^^^^^ help: must have an integer part: `0.42f32` +LL | let _: f32 = .42f32; + | ^^^^^^ help: must have an integer part: `0.42f32` error: float literals must have an integer part - --> $DIR/recover-invalid-float.rs:8:20 + --> $DIR/recover-invalid-float.rs:8:18 | -LL | let _: usize = .5f64; - | ^^^^^ help: must have an integer part: `0.5f64` +LL | let _: f64 = .5f64; + | ^^^^^ help: must have an integer part: `0.5f64` -error[E0308]: mismatched types - --> $DIR/recover-invalid-float.rs:2:20 - | -LL | let _: usize = .3; - | ^^ expected usize, found floating-point number - | - = note: expected type `usize` - found type `{float}` - -error[E0308]: mismatched types - --> $DIR/recover-invalid-float.rs:5:20 - | -LL | let _: usize = .42f32; - | ^^^^^^ expected usize, found f32 - -error[E0308]: mismatched types - --> $DIR/recover-invalid-float.rs:8:20 - | -LL | let _: usize = .5f64; - | ^^^^^ expected usize, found f64 - -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/type-mismatch-struct-field-shorthand-2.stderr b/src/test/ui/suggestions/type-mismatch-struct-field-shorthand-2.stderr index f86351c19922c..a25c644680ee0 100644 --- a/src/test/ui/suggestions/type-mismatch-struct-field-shorthand-2.stderr +++ b/src/test/ui/suggestions/type-mismatch-struct-field-shorthand-2.stderr @@ -2,21 +2,19 @@ error[E0308]: mismatched types --> $DIR/type-mismatch-struct-field-shorthand-2.rs:5:19 | LL | let _ = RGB { r, g, c }; - | ^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | let _ = RGB { r: r.into(), g, c }; - | ^^^^^^^^^^^ + | ^ + | | + | expected f64, found f32 + | help: you can convert an `f32` to `f64`: `r: r.into()` error[E0308]: mismatched types --> $DIR/type-mismatch-struct-field-shorthand-2.rs:5:22 | LL | let _ = RGB { r, g, c }; - | ^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | let _ = RGB { r, g: g.into(), c }; - | ^^^^^^^^^^^ + | ^ + | | + | expected f64, found f32 + | help: you can convert an `f32` to `f64`: `g: g.into()` error[E0560]: struct `RGB` has no field named `c` --> $DIR/type-mismatch-struct-field-shorthand-2.rs:5:25 diff --git a/src/test/ui/suggestions/type-mismatch-struct-field-shorthand.stderr b/src/test/ui/suggestions/type-mismatch-struct-field-shorthand.stderr index 6bc16ba8b70fa..ed8013d5997e4 100644 --- a/src/test/ui/suggestions/type-mismatch-struct-field-shorthand.stderr +++ b/src/test/ui/suggestions/type-mismatch-struct-field-shorthand.stderr @@ -2,31 +2,28 @@ error[E0308]: mismatched types --> $DIR/type-mismatch-struct-field-shorthand.rs:8:19 | LL | let _ = RGB { r, g, b }; - | ^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | let _ = RGB { r: r.into(), g, b }; - | ^^^^^^^^^^^ + | ^ + | | + | expected f64, found f32 + | help: you can convert an `f32` to `f64`: `r: r.into()` error[E0308]: mismatched types --> $DIR/type-mismatch-struct-field-shorthand.rs:8:22 | LL | let _ = RGB { r, g, b }; - | ^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | let _ = RGB { r, g: g.into(), b }; - | ^^^^^^^^^^^ + | ^ + | | + | expected f64, found f32 + | help: you can convert an `f32` to `f64`: `g: g.into()` error[E0308]: mismatched types --> $DIR/type-mismatch-struct-field-shorthand.rs:8:25 | LL | let _ = RGB { r, g, b }; - | ^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | let _ = RGB { r, g, b: b.into() }; - | ^^^^^^^^^^^ + | ^ + | | + | expected f64, found f32 + | help: you can convert an `f32` to `f64`: `b: b.into()` error: aborting due to 3 previous errors diff --git a/src/test/ui/traits/traits-multidispatch-bad.stderr b/src/test/ui/traits/traits-multidispatch-bad.stderr index 5b800114aa8d1..9e6c38ced0d26 100644 --- a/src/test/ui/traits/traits-multidispatch-bad.stderr +++ b/src/test/ui/traits/traits-multidispatch-bad.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | test(22i32, 44i32); | ^^^^^ expected u32, found i32 +help: change the type of the numeric literal from `i32` to `u32` + | +LL | test(22i32, 44u32); + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-projection-error.stderr b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-projection-error.stderr index 7c1a833442748..9acd63c2c25f1 100644 --- a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-projection-error.stderr +++ b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-projection-error.stderr @@ -6,6 +6,10 @@ LL | fn global_bound_is_hidden() -> u8 ... LL | B::get_x() | ^^^^^^^^^^ expected u8, found i32 +help: you can convert an `i32` to `u8` or panic if it the converted value wouldn't fit + | +LL | B::get_x().try_into().unwrap() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/tutorial-suffix-inference-test.stderr b/src/test/ui/tutorial-suffix-inference-test.stderr index 6ba1b098d19b7..f51f2defd4759 100644 --- a/src/test/ui/tutorial-suffix-inference-test.stderr +++ b/src/test/ui/tutorial-suffix-inference-test.stderr @@ -2,23 +2,30 @@ error[E0308]: mismatched types --> $DIR/tutorial-suffix-inference-test.rs:9:18 | LL | identity_u16(x); - | ^ expected u16, found u8 -help: you can cast an `u8` to `u16`, which will zero-extend the source value - | -LL | identity_u16(x.into()); - | ^^^^^^^^ + | ^ + | | + | expected u16, found u8 + | help: you can convert an `u8` to `u16`: `x.into()` error[E0308]: mismatched types --> $DIR/tutorial-suffix-inference-test.rs:12:18 | LL | identity_u16(y); | ^ expected u16, found i32 +help: you can convert an `i32` to `u16` or panic if it the converted value wouldn't fit + | +LL | identity_u16(y.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/tutorial-suffix-inference-test.rs:21:18 | LL | identity_u16(a); | ^ expected u16, found isize +help: you can convert an `isize` to `u16` or panic if it the converted value wouldn't fit + | +LL | identity_u16(a.try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr index 610146954c985..f749ed3f9d865 100644 --- a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr +++ b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr @@ -11,12 +11,20 @@ error[E0308]: mismatched types | LL | >::add(1u32, 2); | ^^^^ expected i32, found u32 +help: change the type of the numeric literal from `u32` to `i32` + | +LL | >::add(1i32, 2); + | ^^^^ error[E0308]: mismatched types --> $DIR/ufcs-qpath-self-mismatch.rs:8:31 | LL | >::add(1, 2u32); | ^^^^ expected i32, found u32 +help: change the type of the numeric literal from `u32` to `i32` + | +LL | >::add(1, 2i32); + | ^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/unboxed-closures/unboxed-closures-type-mismatch.stderr b/src/test/ui/unboxed-closures/unboxed-closures-type-mismatch.stderr index df31a8d6104e3..758762fd5fde3 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-type-mismatch.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-type-mismatch.stderr @@ -3,6 +3,10 @@ error[E0308]: mismatched types | LL | let z = f(1_usize, 2); | ^^^^^^^ expected isize, found usize +help: change the type of the numeric literal from `usize` to `isize` + | +LL | let z = f(1_isize, 2); + | ^^^^^^^ error: aborting due to previous error From 4e84b619f4618a11e9be62379a60aebc7455a547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 21 Apr 2019 15:57:00 -0700 Subject: [PATCH 2/3] Add test --- src/test/ui/numeric/len.rs | 8 ++++++++ src/test/ui/numeric/len.stderr | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/numeric/len.rs create mode 100644 src/test/ui/numeric/len.stderr diff --git a/src/test/ui/numeric/len.rs b/src/test/ui/numeric/len.rs new file mode 100644 index 0000000000000..a725409882059 --- /dev/null +++ b/src/test/ui/numeric/len.rs @@ -0,0 +1,8 @@ +fn main() { + let array = [1, 2, 3]; + test(array.len()); //~ ERROR mismatched types +} + +fn test(length: u32) { + println!("{}", length); +} diff --git a/src/test/ui/numeric/len.stderr b/src/test/ui/numeric/len.stderr new file mode 100644 index 0000000000000..5a9349b4c0f29 --- /dev/null +++ b/src/test/ui/numeric/len.stderr @@ -0,0 +1,13 @@ +error[E0308]: mismatched types + --> $DIR/len.rs:3:10 + | +LL | test(array.len()); + | ^^^^^^^^^^^ expected u32, found usize +help: you can convert an `usize` to `u32` or panic if it the converted value wouldn't fit + | +LL | test(array.len().try_into().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 31eb5cc7305f8967efd449f7067178c980ab27ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 29 Apr 2019 17:14:31 -0700 Subject: [PATCH 3/3] Account for const fns to avoid incorrect suggestions --- src/librustc/hir/map/mod.rs | 8 +++++ src/librustc/hir/mod.rs | 9 +++++ src/librustc_typeck/check/demand.rs | 13 +++---- src/test/ui/numeric/const-scope.rs | 12 +++++++ src/test/ui/numeric/const-scope.stderr | 47 ++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/numeric/const-scope.rs create mode 100644 src/test/ui/numeric/const-scope.stderr diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 9e95f0acfeb79..826ae836a906e 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -734,6 +734,14 @@ impl<'hir> Map<'hir> { } } + pub fn is_const_scope(&self, hir_id: HirId) -> bool { + self.walk_parent_nodes(hir_id, |node| match *node { + Node::Item(Item { node: ItemKind::Const(_, _), .. }) => true, + Node::Item(Item { node: ItemKind::Fn(_, header, _, _), .. }) => header.is_const(), + _ => false, + }, |_| false).map(|id| id != CRATE_HIR_ID).unwrap_or(false) + } + /// If there is some error when walking the parents (e.g., a node does not /// have a parent in the map or a node can't be found), then we return the /// last good `NodeId` we found. Note that reaching the crate root (`id == 0`), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 2e10300dced0e..8418658ab6878 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2288,6 +2288,15 @@ pub struct FnHeader { pub abi: Abi, } +impl FnHeader { + pub fn is_const(&self) -> bool { + match &self.constness { + Constness::Const => true, + _ => false, + } + } +} + #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum ItemKind { /// An `extern crate` item, with optional *original* crate name if the crate was renamed. diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 6249d6e56af68..689996ccb25a9 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -7,7 +7,7 @@ use syntax_pos::Span; use rustc::hir; use rustc::hir::def::Def; use rustc::hir::Node; -use rustc::hir::{Item, ItemKind, print}; +use rustc::hir::print; use rustc::ty::{self, Ty, AssociatedItem}; use rustc::ty::adjustment::AllowTwoPhase; use errors::{Applicability, DiagnosticBuilder}; @@ -550,14 +550,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, ) -> bool { - let parent_id = self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id); - if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) { + if self.tcx.hir().is_const_scope(expr.hir_id) { // Shouldn't suggest `.into()` on `const`s. - if let Node::Item(Item { node: ItemKind::Const(_, _), .. }) = parent { - // FIXME(estebank): modify once we decide to suggest `as` casts - return false; - } - }; + // FIXME(estebank): modify once we decide to suggest `as` casts + return false; + } // If casting this expression to a given numeric type would be appropriate in case of a type // mismatch. diff --git a/src/test/ui/numeric/const-scope.rs b/src/test/ui/numeric/const-scope.rs new file mode 100644 index 0000000000000..053599a9bb9f1 --- /dev/null +++ b/src/test/ui/numeric/const-scope.rs @@ -0,0 +1,12 @@ +const C: i32 = 1i8; //~ ERROR mismatched types +const D: i8 = C; //~ ERROR mismatched types + +const fn foo() { + let c: i32 = 1i8; //~ ERROR mismatched types + let d: i8 = c; //~ ERROR mismatched types +} + +fn main() { + let c: i32 = 1i8; //~ ERROR mismatched types + let d: i8 = c; //~ ERROR mismatched types +} diff --git a/src/test/ui/numeric/const-scope.stderr b/src/test/ui/numeric/const-scope.stderr new file mode 100644 index 0000000000000..ead3a79da0270 --- /dev/null +++ b/src/test/ui/numeric/const-scope.stderr @@ -0,0 +1,47 @@ +error[E0308]: mismatched types + --> $DIR/const-scope.rs:1:16 + | +LL | const C: i32 = 1i8; + | ^^^ expected i32, found i8 + +error[E0308]: mismatched types + --> $DIR/const-scope.rs:2:15 + | +LL | const D: i8 = C; + | ^ expected i8, found i32 + +error[E0308]: mismatched types + --> $DIR/const-scope.rs:5:18 + | +LL | let c: i32 = 1i8; + | ^^^ expected i32, found i8 + +error[E0308]: mismatched types + --> $DIR/const-scope.rs:6:17 + | +LL | let d: i8 = c; + | ^ expected i8, found i32 + +error[E0308]: mismatched types + --> $DIR/const-scope.rs:10:18 + | +LL | let c: i32 = 1i8; + | ^^^ expected i32, found i8 +help: change the type of the numeric literal from `i8` to `i32` + | +LL | let c: i32 = 1i32; + | ^^^^ + +error[E0308]: mismatched types + --> $DIR/const-scope.rs:11:17 + | +LL | let d: i8 = c; + | ^ expected i8, found i32 +help: you can convert an `i32` to `i8` or panic if it the converted value wouldn't fit + | +LL | let d: i8 = c.try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`.