@@ -4981,20 +4981,37 @@ impl Resolver {
4981
4981
wrong_name) ) ;
4982
4982
}
4983
4983
else {
4984
- // limit search to 5 to reduce the number
4985
- // of stupid suggestions
4986
- match self . find_best_match_for_name ( wrong_name, 5 ) {
4987
- Some ( m) => {
4984
+ // Be helpful if the name refers to a struct
4985
+ // (The pattern matching def_tys where the id is in self.structs
4986
+ // matches on regular structs while excluding tuple- and
4987
+ // enum-like structs, which wouldn't result in this error.)
4988
+ match self . resolve_path ( expr. id , path, TypeNS , false , visitor) {
4989
+ Some ( def_ty( struct_id) )
4990
+ if self . structs . contains ( & struct_id) => {
4988
4991
self . session . span_err ( expr. span ,
4989
- fmt ! ( "unresolved name `%s`. \
4990
- Did you mean `%s`?",
4991
- wrong_name, m) ) ;
4992
- }
4993
- None => {
4994
- self . session . span_err ( expr. span ,
4995
- fmt ! ( "unresolved name `%s`." ,
4996
- wrong_name) ) ;
4992
+ fmt ! ( "`%s` is a structure name, but this expression \
4993
+ uses it like a function name", wrong_name) ) ;
4994
+
4995
+ self . session . span_note ( expr. span , fmt ! ( "Did you mean to write: \
4996
+ `%s { /* fields */ }`?", wrong_name) ) ;
4997
+
4997
4998
}
4999
+ _ =>
5000
+ // limit search to 5 to reduce the number
5001
+ // of stupid suggestions
5002
+ match self . find_best_match_for_name ( wrong_name, 5 ) {
5003
+ Some ( m) => {
5004
+ self . session . span_err ( expr. span ,
5005
+ fmt ! ( "unresolved name `%s`. \
5006
+ Did you mean `%s`?",
5007
+ wrong_name, m) ) ;
5008
+ }
5009
+ None => {
5010
+ self . session . span_err ( expr. span ,
5011
+ fmt ! ( "unresolved name `%s`." ,
5012
+ wrong_name) ) ;
5013
+ }
5014
+ }
4998
5015
}
4999
5016
}
5000
5017
}
0 commit comments