@@ -16,7 +16,7 @@ use ra_ap_ide_db::RootDatabase;
16
16
use ra_ap_ide_db:: line_index:: { LineCol , LineIndex } ;
17
17
use ra_ap_parser:: SyntaxKind ;
18
18
use ra_ap_span:: TextSize ;
19
- use ra_ap_syntax:: ast:: { Const , Fn , HasName , Param , Static } ;
19
+ use ra_ap_syntax:: ast:: { Const , Fn , HasName , HasVisibility , Param , Static } ;
20
20
use ra_ap_syntax:: {
21
21
AstNode , NodeOrToken , SyntaxElementChildren , SyntaxError , SyntaxNode , SyntaxToken , TextRange ,
22
22
ast,
@@ -672,6 +672,61 @@ impl<'a> Translator<'a> {
672
672
{
673
673
return true ;
674
674
}
675
+
676
+ if ast:: AnyHasVisibility :: cast ( syntax. clone ( ) )
677
+ . and_then ( |x| x. visibility ( ) )
678
+ . is_none ( )
679
+ {
680
+ match syntax. kind ( ) {
681
+ SyntaxKind :: ENUM
682
+ | SyntaxKind :: STATIC
683
+ | SyntaxKind :: STRUCT
684
+ | SyntaxKind :: TRAIT
685
+ | SyntaxKind :: TRAIT_ALIAS
686
+ | SyntaxKind :: UNION => return true ,
687
+ SyntaxKind :: CONST | SyntaxKind :: FN | SyntaxKind :: TYPE_ALIAS => {
688
+ // check for enclosing source file
689
+ if syntax. parent ( ) . and_then ( ast:: SourceFile :: cast) . is_some ( ) {
690
+ return true ;
691
+ }
692
+ // check for enclosing module
693
+ if syntax
694
+ . parent ( )
695
+ . and_then ( ast:: ItemList :: cast)
696
+ . and_then ( |x| x. syntax ( ) . parent ( ) )
697
+ . and_then ( ast:: Module :: cast)
698
+ . is_some ( )
699
+ {
700
+ return true ;
701
+ }
702
+ // check for enclosing extern block
703
+ if syntax
704
+ . parent ( )
705
+ . and_then ( ast:: ExternItemList :: cast)
706
+ . and_then ( |x| x. syntax ( ) . parent ( ) )
707
+ . and_then ( ast:: ExternBlock :: cast)
708
+ . is_some ( )
709
+ {
710
+ return true ;
711
+ }
712
+ // check for enclosing block expr
713
+ if syntax. parent ( ) . and_then ( ast:: BlockExpr :: cast) . is_some ( ) {
714
+ return true ;
715
+ }
716
+ // check for enclosing non-trait impl
717
+ if syntax
718
+ . parent ( )
719
+ . and_then ( ast:: AssocItemList :: cast)
720
+ . and_then ( |x| x. syntax ( ) . parent ( ) )
721
+ . and_then ( ast:: Impl :: cast)
722
+ . is_some_and ( |imp| imp. trait_ ( ) . is_none ( ) )
723
+ {
724
+ return true ;
725
+ }
726
+ }
727
+ _ => { }
728
+ }
729
+ }
675
730
}
676
731
false
677
732
}
0 commit comments