@@ -898,7 +898,7 @@ impl<'a> LexicalScopeBinding<'a> {
898
898
}
899
899
}
900
900
901
- #[ derive( Clone ) ]
901
+ #[ derive( Clone , Debug ) ]
902
902
enum PathResult < ' a > {
903
903
Module ( Module < ' a > ) ,
904
904
NonModule ( PathResolution ) ,
@@ -2568,7 +2568,8 @@ impl<'a> Resolver<'a> {
2568
2568
let code = source. error_code ( def. is_some ( ) ) ;
2569
2569
let ( base_msg, fallback_label, base_span) = if let Some ( def) = def {
2570
2570
( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
2571
- format ! ( "not a {}" , expected) , span)
2571
+ format ! ( "not a {}" , expected) ,
2572
+ span)
2572
2573
} else {
2573
2574
let item_str = path[ path. len ( ) - 1 ] . node ;
2574
2575
let item_span = path[ path. len ( ) - 1 ] . span ;
@@ -2585,7 +2586,8 @@ impl<'a> Resolver<'a> {
2585
2586
( mod_prefix, format ! ( "`{}`" , names_to_string( mod_path) ) )
2586
2587
} ;
2587
2588
( 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)
2589
2591
} ;
2590
2592
let code = DiagnosticId :: Error ( code. into ( ) ) ;
2591
2593
let mut err = this. session . struct_span_err_with_code ( base_span, & base_msg, code) ;
@@ -2700,20 +2702,37 @@ impl<'a> Resolver<'a> {
2700
2702
}
2701
2703
return ( err, candidates) ;
2702
2704
} ,
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") ) ;
2711
2712
}
2713
+ } else {
2714
+ err. span_label ( span, format ! ( "did you mean `{} {{ /* fields */ }}`?" ,
2715
+ path_str) ) ;
2712
2716
}
2717
+ return ( err, candidates) ;
2718
+ }
2719
+ ( Def :: Union ( ..) , _) |
2720
+ ( Def :: Variant ( ..) , _) |
2721
+ ( Def :: VariantCtor ( _, CtorKind :: Fictive ) , _) if ns == ValueNS => {
2713
2722
err. span_label ( span, format ! ( "did you mean `{} {{ /* fields */ }}`?" ,
2714
2723
path_str) ) ;
2715
2724
return ( err, candidates) ;
2716
2725
}
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
+ }
2717
2736
_ => { }
2718
2737
}
2719
2738
}
@@ -3965,13 +3984,6 @@ impl<'a> Resolver<'a> {
3965
3984
}
3966
3985
}
3967
3986
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
-
3975
3987
fn is_self_type ( path : & [ SpannedIdent ] , namespace : Namespace ) -> bool {
3976
3988
namespace == TypeNS && path. len ( ) == 1 && path[ 0 ] . node . name == keywords:: SelfType . name ( )
3977
3989
}
0 commit comments