use rustc_ast as ast;
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
use rustc_hir as hir;
-use rustc_hir::def::{DefKind, Res};
+use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{ExprKind, Node, QPath};
use rustc_middle::ty::adjustment::AllowTwoPhase;
error_code: &str,
c_variadic: bool,
sugg_unit: bool| {
- let (span, start_span, args) = match &expr.kind {
- hir::ExprKind::Call(hir::Expr { span, .. }, args) => (*span, *span, &args[..]),
+ let (span, start_span, args, ctor_of) = match &expr.kind {
+ hir::ExprKind::Call(
+ hir::Expr {
+ span,
+ kind:
+ hir::ExprKind::Path(hir::QPath::Resolved(
+ _,
+ hir::Path { res: Res::Def(DefKind::Ctor(of, _), _), .. },
+ )),
+ ..
+ },
+ args,
+ ) => (*span, *span, &args[..], Some(of)),
+ hir::ExprKind::Call(hir::Expr { span, .. }, args) => {
+ (*span, *span, &args[..], None)
+ }
hir::ExprKind::MethodCall(path_segment, span, args, _) => (
*span,
// `sp` doesn't point at the whole `foo.bar()`, only at `bar`.
})
.unwrap_or(*span),
&args[1..], // Skip the receiver.
+ None, // methods are never ctors
),
k => span_bug!(sp, "checking argument types on a non-call: `{:?}`", k),
};
let mut err = tcx.sess.struct_span_err_with_code(
span,
&format!(
- "this function takes {}{} but {} {} supplied",
+ "this {} takes {}{} but {} {} supplied",
+ match ctor_of {
+ Some(CtorOf::Struct) => "struct",
+ Some(CtorOf::Variant) => "enum variant",
+ None => "function",
+ },
if c_variadic { "at least " } else { "" },
potentially_plural_count(expected_count, "argument"),
potentially_plural_count(arg_count, "argument"),
// that are not closures, then we type-check the closures. This is so
// that we have more information about the types of arguments when we
// type-check the functions. This isn't really the right way to do this.
- for &check_closures in &[false, true] {
+ for check_closures in [false, true] {
debug!("check_closures={}", check_closures);
// More awful hacks: before we check argument types, try to do