]> git.lizzy.rs Git - rust.git/commitdiff
Resolve vars before emitting coerce suggestions too
authorJack Huey <31162821+jackh726@users.noreply.github.com>
Sun, 17 Apr 2022 19:27:03 +0000 (15:27 -0400)
committerJack Huey <31162821+jackh726@users.noreply.github.com>
Sat, 7 May 2022 03:35:44 +0000 (23:35 -0400)
compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
src/test/ui/indexing-requires-a-uint.stderr
src/test/ui/issues/issue-13359.stderr
src/test/ui/mismatched_types/issue-26480.stderr

index 166bd451199bb5c98b0b1cbc09b3cc9e48ea263a..fb0fcf5d7967265dac98e6837904a6218da92d3a 100644 (file)
@@ -504,6 +504,8 @@ pub(in super::super) fn check_argument_types(
                 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 @@ pub(in super::super) fn check_argument_types(
                 {
                     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 @@ enum SuggestionText {
                             .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),
index a9adff4faded9e5f4913e204002ae3e218202ab4..0a24855a6a79c96e648876a955934215533451bb 100644 (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
 
index db6283ea11f506577305f91eabc5d5f56bec2423..fef63680a86767e913c91cf8b787c018067eb193 100644 (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
 
index 579a5b7ecb98ceec6f58c6b28aa1e726b38a7532..ae10a00671e61e3ce921204abacb22c701adb28f 100644 (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