about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJack Huey <31162821+jackh726@users.noreply.github.com>2022-04-17 15:27:03 -0400
committerJack Huey <31162821+jackh726@users.noreply.github.com>2022-05-06 23:35:44 -0400
commit7d8e10d3c242c2741d7190db8a9bbc4c919b53c7 (patch)
tree072ee6126725cbf7656b10500c05cea0adba5eec
parent62d0e4cba94713cd7e4149da73875654bedf75b7 (diff)
downloadrust-7d8e10d3c242c2741d7190db8a9bbc4c919b53c7.tar.gz
rust-7d8e10d3c242c2741d7190db8a9bbc4c919b53c7.zip
Resolve vars before emitting coerce suggestions too
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/checks.rs6
-rw-r--r--src/test/ui/indexing-requires-a-uint.stderr4
-rw-r--r--src/test/ui/issues/issue-13359.stderr8
-rw-r--r--src/test/ui/mismatched_types/issue-26480.stderr4
4 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
index 166bd451199..fb0fcf5d796 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
@@ -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),
diff --git a/src/test/ui/indexing-requires-a-uint.stderr b/src/test/ui/indexing-requires-a-uint.stderr
index a9adff4fade..0a24855a6a7 100644
--- a/src/test/ui/indexing-requires-a-uint.stderr
+++ b/src/test/ui/indexing-requires-a-uint.stderr
@@ -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
 
diff --git a/src/test/ui/issues/issue-13359.stderr b/src/test/ui/issues/issue-13359.stderr
index db6283ea11f..fef63680a86 100644
--- a/src/test/ui/issues/issue-13359.stderr
+++ b/src/test/ui/issues/issue-13359.stderr
@@ -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
 
diff --git a/src/test/ui/mismatched_types/issue-26480.stderr b/src/test/ui/mismatched_types/issue-26480.stderr
index 579a5b7ecb9..ae10a00671e 100644
--- a/src/test/ui/mismatched_types/issue-26480.stderr
+++ b/src/test/ui/mismatched_types/issue-26480.stderr
@@ -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