(expected, Some(err))
}
- fn point_at_expr_source_of_inferred_type(
+ pub fn point_at_expr_source_of_inferred_type(
&self,
err: &mut Diagnostic,
expr: &hir::Expr<'_>,
)),
);
break;
+ } else if !param_args.is_empty() {
+ break;
}
prev = ty;
} else {
full_call_span,
format!("arguments to this {} are incorrect", call_name),
);
+ if let (Some(callee_ty), hir::ExprKind::MethodCall(_, rcvr, _, _)) =
+ (callee_ty, &call_expr.kind)
+ {
+ // Type that would have accepted this argument if it hadn't been inferred earlier.
+ // FIXME: We leave an inference variable for now, but it'd be nice to get a more
+ // specific type to increase the accuracy of the diagnostic.
+ let expected = self.infcx.next_ty_var(TypeVariableOrigin {
+ kind: TypeVariableOriginKind::MiscVariable,
+ span: full_call_span,
+ });
+ self.point_at_expr_source_of_inferred_type(&mut err, rcvr, expected, callee_ty);
+ }
// Call out where the function is defined
self.label_fn_like(
&mut err,
--- /dev/null
+fn main() {
+ let v = Vec::new();
+ v.push(0);
+ //~^ NOTE this is of type `{integer}`, which makes `v` to be inferred as `Vec<{integer}>`
+ v.push(0);
+ v.push(""); //~ ERROR mismatched types
+ //~^ NOTE expected integer, found `&str`
+ //~| NOTE arguments to this function are incorrect
+ //~| NOTE associated function defined here
+}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/point-at-inference-3.rs:6:12
+ |
+LL | v.push(0);
+ | - this is of type `{integer}`, which makes `v` to be inferred as `Vec<{integer}>`
+...
+LL | v.push("");
+ | ---- ^^ expected integer, found `&str`
+ | |
+ | arguments to this function are incorrect
+ |
+note: associated function defined here
+ --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.