@@ -11,7 +11,7 @@ use crate::check::{
1111use rustc_ast as ast;
1212use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticId } ;
1313use rustc_hir as hir;
14- use rustc_hir:: def:: { DefKind , Res } ;
14+ use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
1515use rustc_hir:: def_id:: DefId ;
1616use rustc_hir:: { ExprKind , Node , QPath } ;
1717use rustc_middle:: ty:: adjustment:: AllowTwoPhase ;
@@ -120,8 +120,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
120120 error_code : & str ,
121121 c_variadic : bool ,
122122 sugg_unit : bool | {
123- let ( span, start_span, args) = match & expr. kind {
124- hir:: ExprKind :: Call ( hir:: Expr { span, .. } , args) => ( * span, * span, & args[ ..] ) ,
123+ let ( span, start_span, args, ctor_of) = match & expr. kind {
124+ hir:: ExprKind :: Call (
125+ hir:: Expr {
126+ span,
127+ kind :
128+ hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
129+ _,
130+ hir:: Path { res : Res :: Def ( DefKind :: Ctor ( of, _) , _) , .. } ,
131+ ) ) ,
132+ ..
133+ } ,
134+ args,
135+ ) => ( * span, * span, & args[ ..] , Some ( of) ) ,
136+ hir:: ExprKind :: Call ( hir:: Expr { span, .. } , args) => {
137+ ( * span, * span, & args[ ..] , None )
138+ }
125139 hir:: ExprKind :: MethodCall ( path_segment, span, args, _) => (
126140 * span,
127141 // `sp` doesn't point at the whole `foo.bar()`, only at `bar`.
@@ -137,6 +151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137151 } )
138152 . unwrap_or ( * span) ,
139153 & args[ 1 ..] , // Skip the receiver.
154+ None , // methods are never ctors
140155 ) ,
141156 k => span_bug ! ( sp, "checking argument types on a non-call: `{:?}`" , k) ,
142157 } ;
@@ -157,7 +172,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
157172 let mut err = tcx. sess . struct_span_err_with_code (
158173 span,
159174 & format ! (
160- "this function takes {}{} but {} {} supplied" ,
175+ "this {} takes {}{} but {} {} supplied" ,
176+ match ctor_of {
177+ Some ( CtorOf :: Struct ) => "struct" ,
178+ Some ( CtorOf :: Variant ) => "enum variant" ,
179+ None => "function" ,
180+ } ,
161181 if c_variadic { "at least " } else { "" } ,
162182 potentially_plural_count( expected_count, "argument" ) ,
163183 potentially_plural_count( arg_count, "argument" ) ,
0 commit comments