Skip to content

Commit 7d8e10d

Browse files
committed
Resolve vars before emitting coerce suggestions too
1 parent 62d0e4c commit 7d8e10d

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+6
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
504504
TupleMatchFound::Single => {
505505
let expected_ty = expected_input_tys[0];
506506
let provided_ty = final_arg_types[0].map(|ty| ty.0).unwrap();
507+
let expected_ty = self.resolve_vars_if_possible(expected_ty);
508+
let provided_ty = self.resolve_vars_if_possible(provided_ty);
507509
let cause = &self.misc(provided_args[0].span);
508510
let compatibility = demand_compatible(0, &mut final_arg_types);
509511
let type_error = match compatibility {
@@ -565,6 +567,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
565567
{
566568
let expected_ty = expected_input_tys[*input_idx];
567569
let provided_ty = final_arg_types[*input_idx].map(|ty| ty.0).unwrap();
570+
let expected_ty = self.resolve_vars_if_possible(expected_ty);
571+
let provided_ty = self.resolve_vars_if_possible(provided_ty);
568572
let cause = &self.misc(provided_args[*input_idx].span);
569573
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
570574
let mut err = self.report_and_explain_type_error(trace, error);
@@ -634,6 +638,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
634638
.and_then(|x| x.as_ref())
635639
.map(|ty| ty.0)
636640
.unwrap_or(tcx.ty_error());
641+
let expected_ty = self.resolve_vars_if_possible(expected_ty);
642+
let provided_ty = self.resolve_vars_if_possible(provided_ty);
637643
if let Compatibility::Incompatible(error) = &compatibility {
638644
let cause = &self.misc(
639645
provided_args.get(input_idx).map(|i| i.span).unwrap_or(call_span),

src/test/ui/indexing-requires-a-uint.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ note: function defined here
2121
|
2222
LL | fn bar<T>(_: T) {}
2323
| ^^^ ----
24+
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
25+
|
26+
LL | bar::<isize>(i.try_into().unwrap()); // i should not be re-coerced back to an isize
27+
| ++++++++++++++++++++
2428

2529
error: aborting due to 2 previous errors
2630

src/test/ui/issues/issue-13359.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ note: function defined here
1111
|
1212
LL | fn foo(_s: i16) { }
1313
| ^^^ -------
14+
help: you can convert an `isize` to an `i16` and panic if the converted value doesn't fit
15+
|
16+
LL | foo((1*(1 as isize)).try_into().unwrap());
17+
| + +++++++++++++++++++++
1418

1519
error[E0308]: mismatched types
1620
--> $DIR/issue-13359.rs:10:9
@@ -25,6 +29,10 @@ note: function defined here
2529
|
2630
LL | fn bar(_s: u32) { }
2731
| ^^^ -------
32+
help: you can convert a `usize` to a `u32` and panic if the converted value doesn't fit
33+
|
34+
LL | bar((1*(1 as usize)).try_into().unwrap());
35+
| + +++++++++++++++++++++
2836

2937
error: aborting due to 2 previous errors
3038

src/test/ui/mismatched_types/issue-26480.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ note: function defined here
1515
LL | fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64;
1616
| ^^^^^
1717
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
18+
help: you can convert a `usize` to a `u64` and panic if the converted value doesn't fit
19+
|
20+
LL | ($arr.len() * size_of($arr[0])).try_into().unwrap());
21+
| + +++++++++++++++++++++
1822

1923
error[E0605]: non-primitive cast: `{integer}` as `()`
2024
--> $DIR/issue-26480.rs:22:19

0 commit comments

Comments
 (0)