Suggest try_into when possible
This commit is contained in:
parent
a55c2eb325
commit
4b1297baf7
@ -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,
|
||||
&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",
|
||||
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
|
||||
);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -12,6 +12,10 @@ error[E0308]: mismatched types
|
||||
|
|
||||
LL | bar::<isize>(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::<isize>(i.try_into().unwrap()); // i should not be re-coerced back to an isize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
38
src/test/ui/numeric/numeric-cast-without-suggestion.rs
Normal file
38
src/test/ui/numeric/numeric-cast-without-suggestion.rs
Normal file
@ -0,0 +1,38 @@
|
||||
fn foo<N>(_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::<usize>(x_f64); //~ ERROR mismatched types
|
||||
foo::<usize>(x_f32); //~ ERROR mismatched types
|
||||
foo::<isize>(x_f64); //~ ERROR mismatched types
|
||||
foo::<isize>(x_f32); //~ ERROR mismatched types
|
||||
foo::<u64>(x_f64); //~ ERROR mismatched types
|
||||
foo::<u64>(x_f32); //~ ERROR mismatched types
|
||||
foo::<i64>(x_f64); //~ ERROR mismatched types
|
||||
foo::<i64>(x_f32); //~ ERROR mismatched types
|
||||
foo::<u32>(x_f64); //~ ERROR mismatched types
|
||||
foo::<u32>(x_f32); //~ ERROR mismatched types
|
||||
foo::<i32>(x_f64); //~ ERROR mismatched types
|
||||
foo::<i32>(x_f32); //~ ERROR mismatched types
|
||||
foo::<u16>(x_f64); //~ ERROR mismatched types
|
||||
foo::<u16>(x_f32); //~ ERROR mismatched types
|
||||
foo::<i16>(x_f64); //~ ERROR mismatched types
|
||||
foo::<i16>(x_f32); //~ ERROR mismatched types
|
||||
foo::<u8>(x_f64); //~ ERROR mismatched types
|
||||
foo::<u8>(x_f32); //~ ERROR mismatched types
|
||||
foo::<i8>(x_f64); //~ ERROR mismatched types
|
||||
foo::<i8>(x_f32); //~ ERROR mismatched types
|
||||
foo::<f32>(x_f64); //~ ERROR mismatched types
|
||||
}
|
129
src/test/ui/numeric/numeric-cast-without-suggestion.stderr
Normal file
129
src/test/ui/numeric/numeric-cast-without-suggestion.stderr
Normal file
@ -0,0 +1,129 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:17:18
|
||||
|
|
||||
LL | foo::<usize>(x_f64);
|
||||
| ^^^^^ expected usize, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:18:18
|
||||
|
|
||||
LL | foo::<usize>(x_f32);
|
||||
| ^^^^^ expected usize, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:19:18
|
||||
|
|
||||
LL | foo::<isize>(x_f64);
|
||||
| ^^^^^ expected isize, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:20:18
|
||||
|
|
||||
LL | foo::<isize>(x_f32);
|
||||
| ^^^^^ expected isize, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:21:16
|
||||
|
|
||||
LL | foo::<u64>(x_f64);
|
||||
| ^^^^^ expected u64, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:22:16
|
||||
|
|
||||
LL | foo::<u64>(x_f32);
|
||||
| ^^^^^ expected u64, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:23:16
|
||||
|
|
||||
LL | foo::<i64>(x_f64);
|
||||
| ^^^^^ expected i64, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:24:16
|
||||
|
|
||||
LL | foo::<i64>(x_f32);
|
||||
| ^^^^^ expected i64, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:25:16
|
||||
|
|
||||
LL | foo::<u32>(x_f64);
|
||||
| ^^^^^ expected u32, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:26:16
|
||||
|
|
||||
LL | foo::<u32>(x_f32);
|
||||
| ^^^^^ expected u32, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:27:16
|
||||
|
|
||||
LL | foo::<i32>(x_f64);
|
||||
| ^^^^^ expected i32, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:28:16
|
||||
|
|
||||
LL | foo::<i32>(x_f32);
|
||||
| ^^^^^ expected i32, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:29:16
|
||||
|
|
||||
LL | foo::<u16>(x_f64);
|
||||
| ^^^^^ expected u16, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:30:16
|
||||
|
|
||||
LL | foo::<u16>(x_f32);
|
||||
| ^^^^^ expected u16, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:31:16
|
||||
|
|
||||
LL | foo::<i16>(x_f64);
|
||||
| ^^^^^ expected i16, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:32:16
|
||||
|
|
||||
LL | foo::<i16>(x_f32);
|
||||
| ^^^^^ expected i16, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:33:15
|
||||
|
|
||||
LL | foo::<u8>(x_f64);
|
||||
| ^^^^^ expected u8, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:34:15
|
||||
|
|
||||
LL | foo::<u8>(x_f32);
|
||||
| ^^^^^ expected u8, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:35:15
|
||||
|
|
||||
LL | foo::<i8>(x_f64);
|
||||
| ^^^^^ expected i8, found f64
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:36:15
|
||||
|
|
||||
LL | foo::<i8>(x_f32);
|
||||
| ^^^^^ expected i8, found f32
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/numeric-cast-without-suggestion.rs:37:16
|
||||
|
|
||||
LL | foo::<f32>(x_f64);
|
||||
| ^^^^^ expected f32, found f64
|
||||
|
||||
error: aborting due to 21 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
293
src/test/ui/numeric/numeric-cast.fixed
Normal file
293
src/test/ui/numeric/numeric-cast.fixed
Normal file
@ -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<N>(_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::<usize>(x_usize);
|
||||
foo::<usize>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_u8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_i8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<usize>(x_f64);
|
||||
// foo::<usize>(x_f32);
|
||||
|
||||
foo::<isize>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_u8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_isize);
|
||||
foo::<isize>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_i8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<isize>(x_f64);
|
||||
// foo::<isize>(x_f32);
|
||||
|
||||
foo::<u64>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_u64);
|
||||
foo::<u64>(x_u32.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_u16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_i8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u64>(x_f64);
|
||||
// foo::<u64>(x_f32);
|
||||
|
||||
foo::<i64>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_u8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_i64);
|
||||
foo::<i64>(x_i32.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_i16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i64>(x_f64);
|
||||
// foo::<i64>(x_f32);
|
||||
|
||||
foo::<u32>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_u32);
|
||||
foo::<u32>(x_u16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_i8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u32>(x_f64);
|
||||
// foo::<u32>(x_f32);
|
||||
|
||||
foo::<i32>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_u8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_i32);
|
||||
foo::<i32>(x_i16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i32>(x_f64);
|
||||
// foo::<i32>(x_f32);
|
||||
|
||||
foo::<u16>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_u16);
|
||||
foo::<u16>(x_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_i8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u16>(x_f64);
|
||||
// foo::<u16>(x_f32);
|
||||
|
||||
foo::<i16>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_u8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_i16);
|
||||
foo::<i16>(x_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i16>(x_f64);
|
||||
// foo::<i16>(x_f32);
|
||||
|
||||
foo::<u8>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_u8);
|
||||
foo::<u8>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_i8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u8>(x_f64);
|
||||
// foo::<u8>(x_f32);
|
||||
|
||||
foo::<i8>(x_usize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_u64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_u32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_u16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_u8.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_isize.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_i64.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_i32.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_i16.try_into().unwrap());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_i8);
|
||||
// foo::<i8>(x_f64);
|
||||
// foo::<i8>(x_f32);
|
||||
|
||||
foo::<f64>(x_usize as f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_u64 as f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_u32.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_u16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_isize as f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_i64 as f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_i32.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_i16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(x_f64);
|
||||
foo::<f64>(x_f32.into());
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<f32>(x_usize as f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_u64 as f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_u32 as f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_u16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_isize as f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_i64 as f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_i32 as f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_i16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<f32>(x_f64);
|
||||
foo::<f32>(x_f32);
|
||||
|
||||
foo::<u32>((x_u8 as u16).into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>((-x_i8).into());
|
||||
//~^ ERROR mismatched types
|
||||
}
|
@ -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<N>(_x: N) {}
|
||||
|
||||
fn main() {
|
||||
@ -33,10 +38,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<usize>(x_f64);
|
||||
// foo::<usize>(x_f32);
|
||||
|
||||
foo::<isize>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -57,10 +60,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<isize>(x_f64);
|
||||
// foo::<isize>(x_f32);
|
||||
|
||||
foo::<u64>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -81,10 +82,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u64>(x_f64);
|
||||
// foo::<u64>(x_f32);
|
||||
|
||||
foo::<i64>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -105,10 +104,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i64>(x_f64);
|
||||
// foo::<i64>(x_f32);
|
||||
|
||||
foo::<u32>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -129,10 +126,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u32>(x_f64);
|
||||
// foo::<u32>(x_f32);
|
||||
|
||||
foo::<i32>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -153,10 +148,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i32>(x_f64);
|
||||
// foo::<i32>(x_f32);
|
||||
|
||||
foo::<u16>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -177,10 +170,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u16>(x_f64);
|
||||
// foo::<u16>(x_f32);
|
||||
|
||||
foo::<i16>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -201,10 +192,8 @@ fn main() {
|
||||
foo::<i16>(x_i16);
|
||||
foo::<i16>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i16>(x_f64);
|
||||
// foo::<i16>(x_f32);
|
||||
|
||||
foo::<u8>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -225,10 +214,8 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<u8>(x_f64);
|
||||
// foo::<u8>(x_f32);
|
||||
|
||||
foo::<i8>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -249,10 +236,8 @@ fn main() {
|
||||
foo::<i8>(x_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_i8);
|
||||
foo::<i8>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(x_f32);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<i8>(x_f64);
|
||||
// foo::<i8>(x_f32);
|
||||
|
||||
foo::<f64>(x_usize);
|
||||
//~^ ERROR mismatched types
|
||||
@ -298,8 +283,7 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(x_f64);
|
||||
//~^ ERROR mismatched types
|
||||
// foo::<f32>(x_f64);
|
||||
foo::<f32>(x_f32);
|
||||
|
||||
foo::<u32>(x_u8 as u16);
|
||||
|
File diff suppressed because it is too large
Load Diff
298
src/test/ui/numeric/numeric-suffix.fixed
Normal file
298
src/test/ui/numeric/numeric-suffix.fixed
Normal file
@ -0,0 +1,298 @@
|
||||
// run-rustfix
|
||||
|
||||
fn foo<N>(_x: N) {}
|
||||
|
||||
fn main() {
|
||||
foo::<usize>(42_usize);
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42usize);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42isize);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42u64);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42i64);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42u32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42i32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42u16);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
foo::<i16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42i16);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42u8);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
foo::<i8>(42i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42i8);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<f64>(42_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u32.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i32.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42.0_f64);
|
||||
foo::<f64>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<f32>(42_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_u16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_u8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_i16.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_i8.into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42.0_f32);
|
||||
|
||||
foo::<u32>((42_u8 as u16).into());
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>((-42_i8).into());
|
||||
//~^ ERROR mismatched types
|
||||
}
|
298
src/test/ui/numeric/numeric-suffix.rs
Normal file
298
src/test/ui/numeric/numeric-suffix.rs
Normal file
@ -0,0 +1,298 @@
|
||||
// run-rustfix
|
||||
|
||||
fn foo<N>(_x: N) {}
|
||||
|
||||
fn main() {
|
||||
foo::<usize>(42_usize);
|
||||
foo::<usize>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<usize>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<isize>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_isize);
|
||||
foo::<isize>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<isize>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u64>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u64);
|
||||
foo::<u64>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u64>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i64>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i64);
|
||||
foo::<i64>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i64>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u32>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u32);
|
||||
foo::<u32>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u32>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i32>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i32);
|
||||
foo::<i32>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u16>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_u16);
|
||||
foo::<u16>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u16>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i16>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42_i16);
|
||||
foo::<i16>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i16>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<u8>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_u8);
|
||||
foo::<u8>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<u8>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<i8>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42_i8);
|
||||
foo::<i8>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i8>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<f64>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f64>(42.0_f64);
|
||||
foo::<f64>(42.0_f32);
|
||||
//~^ ERROR mismatched types
|
||||
|
||||
foo::<f32>(42_usize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_u64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_u32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_u8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_isize);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_i64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_i32);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_i16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42.0_f64);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<f32>(42.0_f32);
|
||||
|
||||
foo::<u32>(42_u8 as u16);
|
||||
//~^ ERROR mismatched types
|
||||
foo::<i32>(-42_i8);
|
||||
//~^ ERROR mismatched types
|
||||
}
|
1341
src/test/ui/numeric/numeric-suffix.stderr
Normal file
1341
src/test/ui/numeric/numeric-suffix.stderr
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
10
src/test/ui/suggestions/recover-invalid-float.fixed
Normal file
10
src/test/ui/suggestions/recover-invalid-float.fixed
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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: aborting due to 3 previous errors
|
||||
|
||||
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
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -11,12 +11,20 @@ error[E0308]: mismatched types
|
||||
|
|
||||
LL | <i32 as Add<i32>>::add(1u32, 2);
|
||||
| ^^^^ expected i32, found u32
|
||||
help: change the type of the numeric literal from `u32` to `i32`
|
||||
|
|
||||
LL | <i32 as Add<i32>>::add(1i32, 2);
|
||||
| ^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/ufcs-qpath-self-mismatch.rs:8:31
|
||||
|
|
||||
LL | <i32 as Add<i32>>::add(1, 2u32);
|
||||
| ^^^^ expected i32, found u32
|
||||
help: change the type of the numeric literal from `u32` to `i32`
|
||||
|
|
||||
LL | <i32 as Add<i32>>::add(1, 2i32);
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user