mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: skip private items when extracting library files
This commit is contained in:
@@ -16,7 +16,7 @@ use ra_ap_ide_db::RootDatabase;
|
||||
use ra_ap_ide_db::line_index::{LineCol, LineIndex};
|
||||
use ra_ap_parser::SyntaxKind;
|
||||
use ra_ap_span::TextSize;
|
||||
use ra_ap_syntax::ast::{Const, Fn, HasName, Param, Static};
|
||||
use ra_ap_syntax::ast::{Const, Fn, HasName, HasVisibility, Param, Static};
|
||||
use ra_ap_syntax::{
|
||||
AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken, TextRange,
|
||||
ast,
|
||||
@@ -687,6 +687,59 @@ impl<'a> Translator<'a> {
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ast::AnyHasVisibility::cast(syntax.clone())
|
||||
.and_then(|x| x.visibility())
|
||||
.is_none()
|
||||
{
|
||||
match syntax.kind() {
|
||||
SyntaxKind::ENUM
|
||||
| SyntaxKind::STATIC
|
||||
| SyntaxKind::STRUCT
|
||||
| SyntaxKind::TRAIT
|
||||
| SyntaxKind::TRAIT_ALIAS
|
||||
| SyntaxKind::UNION => return true,
|
||||
SyntaxKind::CONST | SyntaxKind::FN | SyntaxKind::TYPE_ALIAS => {
|
||||
// check for enclosing source file
|
||||
if syntax.parent().and_then(ast::SourceFile::cast).is_some() {
|
||||
return true;
|
||||
}
|
||||
// check for enclosing module
|
||||
if syntax
|
||||
.parent()
|
||||
.and_then(ast::ItemList::cast)
|
||||
.and_then(|x| x.syntax().parent())
|
||||
.and_then(ast::Module::cast)
|
||||
.is_some()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// check for enclosing extern block
|
||||
if syntax
|
||||
.parent()
|
||||
.and_then(ast::ExternItemList::cast)
|
||||
.is_some()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// check for enclosing block expr
|
||||
if syntax.parent().and_then(ast::BlockExpr::cast).is_some() {
|
||||
return true;
|
||||
}
|
||||
// check for enclosing non-trait impl
|
||||
if syntax
|
||||
.parent()
|
||||
.and_then(ast::AssocItemList::cast)
|
||||
.and_then(|x| x.syntax().parent())
|
||||
.and_then(ast::Impl::cast)
|
||||
.is_some_and(|imp| imp.trait_().is_none())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user