@@ -17,11 +17,11 @@ use rustc_errors::{
1717use rustc_feature:: BUILTIN_ATTRIBUTES ;
1818use rustc_hir:: attrs:: { CfgEntry , StrippedCfgItem } ;
1919use rustc_hir:: def:: Namespace :: { self , * } ;
20- use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind , MacroKinds , NonMacroAttrKind , PerNS } ;
20+ use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , MacroKinds , NonMacroAttrKind , PerNS } ;
2121use rustc_hir:: def_id:: { CRATE_DEF_ID , DefId } ;
2222use rustc_hir:: { PrimTy , Stability , StabilityLevel , find_attr} ;
2323use rustc_middle:: bug;
24- use rustc_middle:: ty:: TyCtxt ;
24+ use rustc_middle:: ty:: { TyCtxt , Visibility } ;
2525use rustc_session:: Session ;
2626use rustc_session:: lint:: builtin:: {
2727 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE , AMBIGUOUS_GLOB_IMPORTS , AMBIGUOUS_IMPORT_VISIBILITIES ,
@@ -49,20 +49,31 @@ use crate::late::{DiagMetadata, PatternSource, Rib};
4949use crate :: {
5050 AmbiguityError , AmbiguityKind , AmbiguityWarning , BindingError , BindingKey , Decl , DeclKind ,
5151 Finalize , ForwardGenericParamBanReason , HasGenericParams , IdentKey , LateDecl , MacroRulesScope ,
52- Module , ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , PrivacyError ,
52+ Module , ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , PrivacyError , Res ,
5353 ResolutionError , Resolver , Scope , ScopeSet , Segment , UseError , Used , VisResolutionError ,
5454 errors as errs, path_names_to_string,
5555} ;
5656
57- type Res = def:: Res < ast:: NodeId > ;
58-
5957/// A vector of spans and replacements, a message and applicability.
6058pub ( crate ) type Suggestion = ( Vec < ( Span , String ) > , String , Applicability ) ;
6159
6260/// Potential candidate for an undeclared or out-of-scope label - contains the ident of a
6361/// similarly named label and whether or not it is reachable.
6462pub ( crate ) type LabelSuggestion = ( Ident , bool ) ;
6563
64+ #[ derive( Clone ) ]
65+ pub ( crate ) struct StructCtor {
66+ pub res : Res ,
67+ pub vis : Visibility < DefId > ,
68+ pub field_visibilities : Vec < Visibility < DefId > > ,
69+ }
70+
71+ impl StructCtor {
72+ pub ( crate ) fn has_private_fields < ' ra > ( & self , m : Module < ' ra > , r : & Resolver < ' ra , ' _ > ) -> bool {
73+ self . field_visibilities . iter ( ) . any ( |& vis| !r. is_accessible_from ( vis, m) )
74+ }
75+ }
76+
6677#[ derive( Debug ) ]
6778pub ( crate ) enum SuggestionTarget {
6879 /// The target has a similar name as the name used by the programmer (probably a typo)
@@ -3176,6 +3187,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
31763187 err. subdiagnostic ( note) ;
31773188 }
31783189 }
3190+
3191+ pub ( crate ) fn struct_ctor ( & self , def_id : DefId ) -> Option < StructCtor > {
3192+ match def_id. as_local ( ) {
3193+ Some ( def_id) => self . struct_ctors . get ( & def_id) . cloned ( ) ,
3194+ None => {
3195+ self . cstore ( ) . ctor_untracked ( self . tcx , def_id) . map ( |( ctor_kind, ctor_def_id) | {
3196+ let res = Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
3197+ let vis = self . tcx . visibility ( ctor_def_id) ;
3198+ let field_visibilities = self
3199+ . tcx
3200+ . associated_item_def_ids ( def_id)
3201+ . iter ( )
3202+ . map ( |& field_id| self . tcx . visibility ( field_id) )
3203+ . collect ( ) ;
3204+ StructCtor { res, vis, field_visibilities }
3205+ } )
3206+ }
3207+ }
3208+ }
31793209}
31803210
31813211/// Given a `binding_span` of a binding within a use statement:
0 commit comments