@@ -898,7 +898,7 @@ impl<'a> LexicalScopeBinding<'a> {
898898 }
899899}
900900
901- #[ derive( Clone ) ]
901+ #[ derive( Clone , Debug ) ]
902902enum PathResult < ' a > {
903903 Module ( Module < ' a > ) ,
904904 NonModule ( PathResolution ) ,
@@ -2568,7 +2568,8 @@ impl<'a> Resolver<'a> {
25682568 let code = source. error_code ( def. is_some ( ) ) ;
25692569 let ( base_msg, fallback_label, base_span) = if let Some ( def) = def {
25702570 ( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
2571- format ! ( "not a {}" , expected) , span)
2571+ format ! ( "not a {}" , expected) ,
2572+ span)
25722573 } else {
25732574 let item_str = path[ path. len ( ) - 1 ] . node ;
25742575 let item_span = path[ path. len ( ) - 1 ] . span ;
@@ -2585,7 +2586,8 @@ impl<'a> Resolver<'a> {
25852586 ( mod_prefix, format ! ( "`{}`" , names_to_string( mod_path) ) )
25862587 } ;
25872588 ( format ! ( "cannot find {} `{}` in {}{}" , expected, item_str, mod_prefix, mod_str) ,
2588- format ! ( "not found in {}" , mod_str) , item_span)
2589+ format ! ( "not found in {}" , mod_str) ,
2590+ item_span)
25892591 } ;
25902592 let code = DiagnosticId :: Error ( code. into ( ) ) ;
25912593 let mut err = this. session . struct_span_err_with_code ( base_span, & base_msg, code) ;
@@ -2700,20 +2702,37 @@ impl<'a> Resolver<'a> {
27002702 }
27012703 return ( err, candidates) ;
27022704 } ,
2703- _ if ns == ValueNS && is_struct_like ( def) => {
2704- if let Def :: Struct ( def_id) = def {
2705- if let Some ( ( ctor_def, ctor_vis) )
2706- = this. struct_constructors . get ( & def_id) . cloned ( ) {
2707- if is_expected ( ctor_def) && !this. is_accessible ( ctor_vis) {
2708- err. span_label ( span, format ! ( "constructor is not visible \
2709- here due to private fields") ) ;
2710- }
2705+ ( Def :: Struct ( def_id) , _) if ns == ValueNS => {
2706+ if let Some ( ( ctor_def, ctor_vis) )
2707+ = this. struct_constructors . get ( & def_id) . cloned ( ) {
2708+ let accessible_ctor = this. is_accessible ( ctor_vis) ;
2709+ if is_expected ( ctor_def) && !accessible_ctor {
2710+ err. span_label ( span, format ! ( "constructor is not visible \
2711+ here due to private fields") ) ;
27112712 }
2713+ } else {
2714+ err. span_label ( span, format ! ( "did you mean `{} {{ /* fields */ }}`?" ,
2715+ path_str) ) ;
27122716 }
2717+ return ( err, candidates) ;
2718+ }
2719+ ( Def :: Union ( ..) , _) |
2720+ ( Def :: Variant ( ..) , _) |
2721+ ( Def :: VariantCtor ( _, CtorKind :: Fictive ) , _) if ns == ValueNS => {
27132722 err. span_label ( span, format ! ( "did you mean `{} {{ /* fields */ }}`?" ,
27142723 path_str) ) ;
27152724 return ( err, candidates) ;
27162725 }
2726+ ( Def :: SelfTy ( ..) , _) if ns == ValueNS => {
2727+ err. span_label ( span, fallback_label) ;
2728+ err. note ( "can't use `Self` as a constructor, you must use the \
2729+ implemented struct") ;
2730+ return ( err, candidates) ;
2731+ }
2732+ ( Def :: TyAlias ( _) , _) | ( Def :: AssociatedTy ( ..) , _) if ns == ValueNS => {
2733+ err. note ( "can't use a type alias as a constructor" ) ;
2734+ return ( err, candidates) ;
2735+ }
27172736 _ => { }
27182737 }
27192738 }
@@ -3965,13 +3984,6 @@ impl<'a> Resolver<'a> {
39653984 }
39663985}
39673986
3968- fn is_struct_like ( def : Def ) -> bool {
3969- match def {
3970- Def :: VariantCtor ( _, CtorKind :: Fictive ) => true ,
3971- _ => PathSource :: Struct . is_expected ( def) ,
3972- }
3973- }
3974-
39753987fn is_self_type ( path : & [ SpannedIdent ] , namespace : Namespace ) -> bool {
39763988 namespace == TypeNS && path. len ( ) == 1 && path[ 0 ] . node . name == keywords:: SelfType . name ( )
39773989}
0 commit comments