@@ -376,19 +376,6 @@ struct DiagnosticMetadata<'ast> {
376376 current_let_binding : Option < ( Span , Option < Span > , Option < Span > ) > ,
377377}
378378
379- /// Keeps track of whether errors should be reported.
380- ///
381- /// Used by rustdoc to ignore errors in function bodies.
382- /// This is just a fancy boolean so it can have doc-comments.
383- #[ derive( Copy , Clone , Debug ) ]
384- pub enum IgnoreState {
385- /// We are at global scope or in a trait implementation, so all errors should be reported.
386- Report ,
387- /// We are in a function body, so errors shouldn't be reported.
388- Ignore ,
389- // Note that we don't need to worry about macros, which must always be resolved (or we wouldn't have gotten to the late pass).
390- }
391-
392379struct LateResolutionVisitor < ' a , ' b , ' ast > {
393380 r : & ' b mut Resolver < ' a > ,
394381
@@ -408,12 +395,12 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
408395 /// Fields used to add information to diagnostic errors.
409396 diagnostic_metadata : DiagnosticMetadata < ' ast > ,
410397
411- /// State used to know whether to ignore resolution errors for item bodies.
398+ /// State used to know whether to ignore resolution errors for function bodies.
412399 ///
413400 /// In particular, rustdoc uses this to avoid giving errors for `cfg()` items.
414401 /// In most cases this will be `None`, in which case errors will always be reported.
415402 /// If it is `Some(_)`, then it will be updated when entering a nested function or trait body.
416- ignore_bodies : Option < IgnoreState > ,
403+ in_func_body : bool ,
417404}
418405
419406/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -517,18 +504,18 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
517504
518505 visit:: walk_fn_ret_ty ( this, & declaration. output ) ;
519506
520- let previous_ignore = this. ignore_bodies . take ( ) ;
521- // Ignore errors in function bodies if originally passed `ignore_state: true`
507+ let previous_state = this. in_func_body ;
508+ // Ignore errors in function bodies if this is rustdoc
522509 // Be sure not to set this until the function signature has been resolved.
523- this. ignore_bodies = previous_ignore . and ( Some ( IgnoreState :: Ignore ) ) ;
510+ this. in_func_body = true ;
524511 // Resolve the function body, potentially inside the body of an async closure
525512 match fn_kind {
526513 FnKind :: Fn ( .., body) => walk_list ! ( this, visit_block, body) ,
527514 FnKind :: Closure ( _, body) => this. visit_expr ( body) ,
528515 } ;
529516
530517 debug ! ( "(resolving function) leaving function" ) ;
531- this. ignore_bodies = previous_ignore ;
518+ this. in_func_body = previous_state ;
532519 } )
533520 } ) ;
534521 self . diagnostic_metadata . current_function = previous_value;
@@ -652,10 +639,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
652639}
653640
654641impl < ' a , ' b , ' ast > LateResolutionVisitor < ' a , ' b , ' ast > {
655- fn new (
656- resolver : & ' b mut Resolver < ' a > ,
657- ignore_bodies : IgnoreState ,
658- ) -> LateResolutionVisitor < ' a , ' b , ' ast > {
642+ fn new ( resolver : & ' b mut Resolver < ' a > ) -> LateResolutionVisitor < ' a , ' b , ' ast > {
659643 // During late resolution we only track the module component of the parent scope,
660644 // although it may be useful to track other components as well for diagnostics.
661645 let graph_root = resolver. graph_root ;
@@ -672,11 +656,8 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
672656 label_ribs : Vec :: new ( ) ,
673657 current_trait_ref : None ,
674658 diagnostic_metadata : DiagnosticMetadata :: default ( ) ,
675- ignore_bodies : match ignore_bodies {
676- // errors at module scope should always be reported
677- IgnoreState :: Ignore => Some ( IgnoreState :: Report ) ,
678- IgnoreState :: Report => None ,
679- } ,
659+ // errors at module scope should always be reported
660+ in_func_body : false ,
680661 }
681662 }
682663
@@ -1194,9 +1175,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11941175 impl_items : & ' ast [ P < AssocItem > ] ,
11951176 ) {
11961177 debug ! ( "resolve_implementation" ) ;
1197- let old_ignore = self . ignore_bodies . take ( ) ;
1178+ let old_ignore = self . in_func_body ;
11981179 // Never ignore errors in trait implementations.
1199- self . ignore_bodies = old_ignore . and ( Some ( IgnoreState :: Report ) ) ;
1180+ self . in_func_body = false ;
12001181 // If applicable, create a rib for the type parameters.
12011182 self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
12021183 // Dummy self type for better errors if `Self` is used in the trait path.
@@ -1292,7 +1273,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12921273 } ) ;
12931274 } ) ;
12941275 } ) ;
1295- self . ignore_bodies = old_ignore;
1276+ self . in_func_body = old_ignore;
12961277 }
12971278
12981279 fn check_trait_item < F > ( & mut self , ident : Ident , ns : Namespace , span : Span , err : F )
@@ -1900,20 +1881,17 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19001881
19011882 /// A wrapper around [`Resolver::report_error`].
19021883 ///
1903- /// This doesn't emit errors for function bodies if `ignore_bodies` is set.
1884+ /// This doesn't emit errors for function bodies if this is r
19041885 fn report_error ( & self , span : Span , resolution_error : ResolutionError < ' _ > ) {
19051886 if self . should_report_errs ( ) {
19061887 self . r . report_error ( span, resolution_error) ;
19071888 }
19081889 }
19091890
19101891 #[ inline]
1892+ /// If we're actually rustdoc then avoid giving a name resolution error for `cfg()` items.
19111893 fn should_report_errs ( & self ) -> bool {
1912- debug ! ( "should_report_errs(state={:?})" , self . ignore_bodies) ;
1913- match self . ignore_bodies {
1914- None | Some ( IgnoreState :: Report ) => true ,
1915- Some ( IgnoreState :: Ignore ) => false ,
1916- }
1894+ !( self . r . session . opts . actually_rustdoc && self . in_func_body )
19171895 }
19181896
19191897 // Resolve in alternative namespaces if resolution in the primary namespace fails.
@@ -2412,8 +2390,8 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
24122390}
24132391
24142392impl < ' a > Resolver < ' a > {
2415- pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate , ignore_bodies : IgnoreState ) {
2416- let mut late_resolution_visitor = LateResolutionVisitor :: new ( self , ignore_bodies ) ;
2393+ pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
2394+ let mut late_resolution_visitor = LateResolutionVisitor :: new ( self ) ;
24172395 visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
24182396 for ( id, span) in late_resolution_visitor. diagnostic_metadata . unused_labels . iter ( ) {
24192397 self . lint_buffer . buffer_lint ( lint:: builtin:: UNUSED_LABELS , * id, * span, "unused label" ) ;
0 commit comments