@@ -5807,16 +5807,30 @@ impl<'a> Resolver<'a> {
5807
5807
// This is a local path in the value namespace. Walk through
5808
5808
// scopes looking for it.
5809
5809
5810
+ let path_name = self . path_names_to_string ( path) ;
5811
+
5810
5812
match self . resolve_path ( expr. id , path, ValueNS , true ) {
5813
+ // Check if struct variant
5814
+ Some ( ( DefVariant ( _, _, true ) , _) ) => {
5815
+ self . resolve_error ( expr. span ,
5816
+ format ! ( "`{}` is a struct variant name, but \
5817
+ this expression \
5818
+ uses it like a function name",
5819
+ path_name) . as_slice ( ) ) ;
5820
+
5821
+ self . session . span_help ( expr. span ,
5822
+ format ! ( "Did you mean to write: \
5823
+ `{} {{ /* fields */ }}`?",
5824
+ path_name) . as_slice ( ) ) ;
5825
+ }
5811
5826
Some ( def) => {
5812
5827
// Write the result into the def map.
5813
5828
debug ! ( "(resolving expr) resolved `{}`" ,
5814
- self . path_names_to_string ( path ) ) ;
5829
+ path_name ) ;
5815
5830
5816
5831
self . record_def ( expr. id , def) ;
5817
5832
}
5818
5833
None => {
5819
- let wrong_name = self . path_names_to_string ( path) ;
5820
5834
// Be helpful if the name refers to a struct
5821
5835
// (The pattern matching def_tys where the id is in self.structs
5822
5836
// matches on regular structs while excluding tuple- and enum-like
@@ -5829,12 +5843,12 @@ impl<'a> Resolver<'a> {
5829
5843
format ! ( "`{}` is a structure name, but \
5830
5844
this expression \
5831
5845
uses it like a function name",
5832
- wrong_name ) . as_slice ( ) ) ;
5846
+ path_name ) . as_slice ( ) ) ;
5833
5847
5834
5848
self . session . span_help ( expr. span ,
5835
5849
format ! ( "Did you mean to write: \
5836
5850
`{} {{ /* fields */ }}`?",
5837
- wrong_name ) . as_slice ( ) ) ;
5851
+ path_name ) . as_slice ( ) ) ;
5838
5852
5839
5853
}
5840
5854
_ => {
@@ -5851,7 +5865,7 @@ impl<'a> Resolver<'a> {
5851
5865
} ) ;
5852
5866
5853
5867
if method_scope && token:: get_name ( self . self_name ) . get ( )
5854
- == wrong_name {
5868
+ == path_name {
5855
5869
self . resolve_error (
5856
5870
expr. span ,
5857
5871
"`self` is not available \
@@ -5863,18 +5877,18 @@ impl<'a> Resolver<'a> {
5863
5877
NoSuggestion => {
5864
5878
// limit search to 5 to reduce the number
5865
5879
// of stupid suggestions
5866
- self . find_best_match_for_name ( wrong_name . as_slice ( ) , 5 )
5880
+ self . find_best_match_for_name ( path_name . as_slice ( ) , 5 )
5867
5881
. map_or ( "" . to_string ( ) ,
5868
5882
|x| format ! ( "`{}`" , x) )
5869
5883
}
5870
5884
Field =>
5871
- format ! ( "`self.{}`" , wrong_name ) ,
5885
+ format ! ( "`self.{}`" , path_name ) ,
5872
5886
Method
5873
5887
| TraitItem =>
5874
- format ! ( "to call `self.{}`" , wrong_name ) ,
5888
+ format ! ( "to call `self.{}`" , path_name ) ,
5875
5889
TraitMethod ( path_str)
5876
5890
| StaticMethod ( path_str) =>
5877
- format ! ( "to call `{}::{}`" , path_str, wrong_name )
5891
+ format ! ( "to call `{}::{}`" , path_str, path_name )
5878
5892
} ;
5879
5893
5880
5894
if msg. len ( ) > 0 {
@@ -5884,7 +5898,7 @@ impl<'a> Resolver<'a> {
5884
5898
self . resolve_error (
5885
5899
expr. span ,
5886
5900
format ! ( "unresolved name `{}`{}" ,
5887
- wrong_name ,
5901
+ path_name ,
5888
5902
msg) . as_slice ( ) ) ;
5889
5903
}
5890
5904
}
0 commit comments