@@ -48,10 +48,10 @@ use crate::imports::{Import, ImportKind};
4848use crate :: late:: { DiagMetadata , PatternSource , Rib } ;
4949use crate :: {
5050 AmbiguityError , AmbiguityKind , AmbiguityWarning , BindingError , BindingKey , Decl , DeclKind ,
51- Finalize , ForwardGenericParamBanReason , HasGenericParams , IdentKey , LateDecl , MacroRulesScope ,
52- Module , ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult , PrivacyError , Res ,
53- ResolutionError , Resolver , Scope , ScopeSet , Segment , UseError , Used , VisResolutionError ,
54- errors as errs, path_names_to_string,
51+ DelayedVisResolutionError , Finalize , ForwardGenericParamBanReason , HasGenericParams , IdentKey ,
52+ LateDecl , MacroRulesScope , Module , ModuleKind , ModuleOrUniformRoot , ParentScope , PathResult ,
53+ PrivacyError , Res , ResolutionError , Resolver , Scope , ScopeSet , Segment , UseError , Used ,
54+ VisResolutionError , errors as errs, path_names_to_string,
5555} ;
5656
5757/// A vector of spans and replacements, a message and applicability.
@@ -137,6 +137,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
137137 }
138138
139139 pub ( crate ) fn report_errors ( & mut self , krate : & Crate ) {
140+ self . report_delayed_vis_resolution_errors ( ) ;
140141 self . report_with_use_injections ( krate) ;
141142
142143 for & ( span_use, span_def) in & self . macro_expanded_macro_export_errors {
@@ -178,6 +179,65 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
178179 }
179180 }
180181
182+ fn report_delayed_vis_resolution_errors ( & mut self ) {
183+ for DelayedVisResolutionError { path, parent_scope, id, span } in
184+ std:: mem:: take ( & mut self . delayed_vis_resolution_errors )
185+ {
186+ let path_result = self . cm ( ) . resolve_path (
187+ & path,
188+ None ,
189+ & parent_scope,
190+ Some ( Finalize :: new ( id, span) ) ,
191+ None ,
192+ None ,
193+ ) ;
194+ match path_result {
195+ PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) => {
196+ let res = module. res ( ) . expect ( "visibility resolved to unnamed block" ) ;
197+ if module. is_normal ( ) {
198+ match res {
199+ Res :: Err => { }
200+ _ => {
201+ let vis = Visibility :: Restricted ( res. def_id ( ) ) ;
202+ if !self . is_accessible_from ( vis, parent_scope. module ) {
203+ self . report_vis_error ( VisResolutionError :: AncestorOnly ( span) ) ;
204+ }
205+ }
206+ }
207+ } else {
208+ self . report_vis_error ( VisResolutionError :: ExpectedFound (
209+ span,
210+ Segment :: names_to_string ( & path) ,
211+ res,
212+ ) ) ;
213+ }
214+ }
215+ PathResult :: Module ( ..) => {
216+ self . report_vis_error ( VisResolutionError :: ModuleOnly ( span) ) ;
217+ }
218+ PathResult :: NonModule ( partial_res) => {
219+ self . report_vis_error ( VisResolutionError :: ExpectedFound (
220+ span,
221+ Segment :: names_to_string ( & path) ,
222+ partial_res. expect_full_res ( ) ,
223+ ) ) ;
224+ }
225+ PathResult :: Failed { span, segment_name, label, suggestion, message, .. } => {
226+ self . report_vis_error ( VisResolutionError :: FailedToResolve (
227+ span,
228+ segment_name,
229+ label,
230+ suggestion,
231+ message,
232+ ) ) ;
233+ }
234+ PathResult :: Indeterminate => {
235+ self . report_vis_error ( VisResolutionError :: Indeterminate ( span) ) ;
236+ }
237+ }
238+ }
239+ }
240+
181241 fn report_with_use_injections ( & mut self , krate : & Crate ) {
182242 for UseError { mut err, candidates, def_id, instead, suggestion, path, is_call } in
183243 std:: mem:: take ( & mut self . use_injections )
0 commit comments