@@ -175,33 +175,50 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
175175 let tcx = self . tcx ;
176176
177177 let actual = self . resolve_type_vars_if_possible ( & rcvr_ty) ;
178+ let ty_string = self . ty_to_string ( actual) ;
179+ let type_str = if mode == Mode :: MethodCall {
180+ "method"
181+ } else if actual. is_enum ( ) {
182+ "variant"
183+ } else {
184+ match ( item_name. as_str ( ) . chars ( ) . next ( ) , actual. is_fresh_ty ( ) ) {
185+ ( Some ( name) , false ) if name. is_lowercase ( ) => {
186+ "function or associated item"
187+ }
188+ ( Some ( _) , false ) => "associated item" ,
189+ ( Some ( _) , true ) | ( None , false ) => {
190+ "variant or associated item"
191+ }
192+ ( None , true ) => "variant" ,
193+ }
194+ } ;
178195 let mut err = if !actual. references_error ( ) {
179- struct_span_err ! ( tcx. sess, span, E0599 ,
180- "no {} named `{}` found for type `{}` in the \
181- current scope",
182- if mode == Mode :: MethodCall {
183- "method"
184- } else if actual. is_enum( ) {
185- "variant"
186- } else {
187- let fresh_ty = actual. is_fresh_ty( ) ;
188- match ( item_name. as_str( ) . chars( ) . next( ) , fresh_ty) {
189- ( Some ( name) , false ) if name. is_lowercase( ) => {
190- "function or associated item"
191- }
192- ( Some ( _) , false ) => "associated item" ,
193- ( Some ( _) , true ) | ( None , false ) => {
194- "variant or associated item"
195- }
196- ( None , true ) => "variant" ,
197- }
198- } ,
199- item_name,
200- self . ty_to_string( actual) )
196+ struct_span_err ! (
197+ tcx. sess,
198+ span,
199+ E0599 ,
200+ "no {} named `{}` found for type `{}` in the current scope" ,
201+ type_str,
202+ item_name,
203+ ty_string
204+ )
201205 } else {
202- self . tcx . sess . diagnostic ( ) . struct_dummy ( )
206+ tcx. sess . diagnostic ( ) . struct_dummy ( )
203207 } ;
204208
209+ if let Some ( def) = actual. ty_adt_def ( ) {
210+ let full_sp = tcx. def_span ( def. did ) ;
211+ let def_sp = tcx. sess . codemap ( ) . def_span ( full_sp) ;
212+ err. span_label ( def_sp, format ! ( "{} `{}` not found {}" ,
213+ type_str,
214+ item_name,
215+ if def. is_enum( ) {
216+ "here"
217+ } else {
218+ "for this"
219+ } ) ) ;
220+ }
221+
205222 // If the method name is the name of a field with a function or closure type,
206223 // give a helping note that it has to be called as (x.f)(...).
207224 if let Some ( expr) = rcvr_expr {
@@ -243,6 +260,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
243260 _ => { }
244261 }
245262 }
263+ } else {
264+ err. span_label ( span, format ! ( "{} not found in `{}`" , type_str, ty_string) ) ;
246265 }
247266
248267 if self . is_fn_ty ( & rcvr_ty, span) {
0 commit comments