@@ -164,41 +164,63 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
164164 } ;
165165
166166 match error {
167- MethodError :: NoMatch ( NoMatchData { static_candidates : static_sources,
168- unsatisfied_predicates,
169- out_of_scope_traits,
170- lev_candidate,
171- mode,
172- .. } ) => {
167+ MethodError :: NoMatch ( NoMatchData {
168+ static_candidates : static_sources,
169+ unsatisfied_predicates,
170+ out_of_scope_traits,
171+ lev_candidate,
172+ mode,
173+ ..
174+ } ) => {
173175 let tcx = self . tcx ;
174176
175177 let actual = self . resolve_type_vars_if_possible ( & rcvr_ty) ;
178+ let ty_string = self . ty_to_string ( actual) ;
179+ let is_method = mode == Mode :: MethodCall ;
180+ let type_str = if is_method {
181+ "method"
182+ } else if actual. is_enum ( ) {
183+ "variant"
184+ } else {
185+ match ( item_name. as_str ( ) . chars ( ) . next ( ) , actual. is_fresh_ty ( ) ) {
186+ ( Some ( name) , false ) if name. is_lowercase ( ) => {
187+ "function or associated item"
188+ }
189+ ( Some ( _) , false ) => "associated item" ,
190+ ( Some ( _) , true ) | ( None , false ) => {
191+ "variant or associated item"
192+ }
193+ ( None , true ) => "variant" ,
194+ }
195+ } ;
176196 let mut err = if !actual. references_error ( ) {
177- struct_span_err ! ( tcx. sess, span, E0599 ,
178- "no {} named `{}` found for type `{}` in the \
179- current scope",
180- if mode == Mode :: MethodCall {
181- "method"
182- } else {
183- match item_name. as_str( ) . chars( ) . next( ) {
184- Some ( name) => {
185- if name. is_lowercase( ) {
186- "function or associated item"
187- } else {
188- "associated item"
189- }
190- } ,
191- None => {
192- ""
193- } ,
194- }
195- } ,
196- item_name,
197- self . ty_to_string( actual) )
197+ struct_span_err ! (
198+ tcx. sess,
199+ span,
200+ E0599 ,
201+ "no {} named `{}` found for type `{}` in the current scope" ,
202+ type_str,
203+ item_name,
204+ ty_string
205+ )
198206 } else {
199- self . tcx . sess . diagnostic ( ) . struct_dummy ( )
207+ tcx. sess . diagnostic ( ) . struct_dummy ( )
200208 } ;
201209
210+ if let Some ( def) = actual. ty_adt_def ( ) {
211+ if let Some ( full_sp) = tcx. hir . span_if_local ( def. did ) {
212+ let def_sp = tcx. sess . codemap ( ) . def_span ( full_sp) ;
213+ err. span_label ( def_sp, format ! ( "{} `{}` not found {}" ,
214+ type_str,
215+ item_name,
216+ if def. is_enum( ) && !is_method {
217+ "here"
218+ } else {
219+ "for this"
220+ } ) ) ;
221+ }
222+ }
223+
202224 // If the method name is the name of a field with a function or closure type,
203225 // give a helping note that it has to be called as (x.f)(...).
204226 if let Some ( expr) = rcvr_expr {
@@ -240,6 +262,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
240262 _ => { }
241263 }
242264 }
265+ } else {
266+ err. span_label ( span, format ! ( "{} not found in `{}`" , type_str, ty_string) ) ;
243267 }
244268
245269 if self . is_fn_ty ( & rcvr_ty, span) {
0 commit comments