Resolve vars before emitting coerce suggestions too

This commit is contained in:
Jack Huey 2022-04-17 15:27:03 -04:00
parent 62d0e4cba9
commit 7d8e10d3c2
4 changed files with 22 additions and 0 deletions

View file

@ -504,6 +504,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
TupleMatchFound::Single => {
let expected_ty = expected_input_tys[0];
let provided_ty = final_arg_types[0].map(|ty| ty.0).unwrap();
let expected_ty = self.resolve_vars_if_possible(expected_ty);
let provided_ty = self.resolve_vars_if_possible(provided_ty);
let cause = &self.misc(provided_args[0].span);
let compatibility = demand_compatible(0, &mut final_arg_types);
let type_error = match compatibility {
@ -565,6 +567,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
let expected_ty = expected_input_tys[*input_idx];
let provided_ty = final_arg_types[*input_idx].map(|ty| ty.0).unwrap();
let expected_ty = self.resolve_vars_if_possible(expected_ty);
let provided_ty = self.resolve_vars_if_possible(provided_ty);
let cause = &self.misc(provided_args[*input_idx].span);
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
let mut err = self.report_and_explain_type_error(trace, error);
@ -634,6 +638,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.and_then(|x| x.as_ref())
.map(|ty| ty.0)
.unwrap_or(tcx.ty_error());
let expected_ty = self.resolve_vars_if_possible(expected_ty);
let provided_ty = self.resolve_vars_if_possible(provided_ty);
if let Compatibility::Incompatible(error) = &compatibility {
let cause = &self.misc(
provided_args.get(input_idx).map(|i| i.span).unwrap_or(call_span),

View file

@ -21,6 +21,10 @@ note: function defined here
|
LL | fn bar<T>(_: T) {}
| ^^^ ----
help: you can convert a `usize` to an `isize` and panic if the converted value doesn'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

View file

@ -11,6 +11,10 @@ note: function defined here
|
LL | fn foo(_s: i16) { }
| ^^^ -------
help: you can convert an `isize` to an `i16` and panic if the converted value doesn't fit
|
LL | foo((1*(1 as isize)).try_into().unwrap());
| + +++++++++++++++++++++
error[E0308]: mismatched types
--> $DIR/issue-13359.rs:10:9
@ -25,6 +29,10 @@ note: function defined here
|
LL | fn bar(_s: u32) { }
| ^^^ -------
help: you can convert a `usize` to a `u32` and panic if the converted value doesn't fit
|
LL | bar((1*(1 as usize)).try_into().unwrap());
| + +++++++++++++++++++++
error: aborting due to 2 previous errors

View file

@ -15,6 +15,10 @@ note: function defined here
LL | fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64;
| ^^^^^
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can convert a `usize` to a `u64` and panic if the converted value doesn'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