This commit is contained in:
Hong Jiarong 2025-11-16 19:18:57 +08:00
parent ef347944ad
commit eac319bb97
2 changed files with 14 additions and 18 deletions

View file

@ -16,6 +16,12 @@ use crate::DiagnosticVec;
use collector::{DefInfo, DefScope, collect_definitions};
use diagnostic::generate_diagnostic;
type ImportUsageResult = (
HashSet<Interned<Decl>>,
HashSet<Interned<Decl>>,
HashMap<Interned<Decl>, HashSet<Interned<Decl>>>,
);
/// Configuration for dead code detection.
#[derive(Debug, Clone)]
pub struct DeadCodeConfig {
@ -89,14 +95,7 @@ pub fn check_dead_code(
diagnostics
}
fn compute_import_usage(
definitions: &[DefInfo],
ei: &ExprInfo,
) -> (
HashSet<Interned<Decl>>,
HashSet<Interned<Decl>>,
HashMap<Interned<Decl>, HashSet<Interned<Decl>>>,
) {
fn compute_import_usage(definitions: &[DefInfo], ei: &ExprInfo) -> ImportUsageResult {
let mut alias_links: HashMap<Interned<Decl>, Interned<Decl>> = HashMap::new();
let mut shadowed = HashSet::new();
let mut module_children: HashMap<Interned<Decl>, HashSet<Interned<Decl>>> = HashMap::new();

View file

@ -79,17 +79,14 @@ pub fn generate_diagnostic(
}
// Add kind-specific hints
match def_info.kind {
DefKind::Function => {
// Check if there's a docstring - documented functions might be intentional API
if matches!(def_info.scope, DefScope::Exported)
&& ei.docstrings.contains_key(&def_info.decl)
{
// Reduce severity for documented functions (they might be public API)
return None;
}
if let DefKind::Function = def_info.kind {
// Check if there's a docstring - documented functions might be intentional API
if matches!(def_info.scope, DefScope::Exported)
&& ei.docstrings.contains_key(&def_info.decl)
{
// Reduce severity for documented functions (they might be public API)
return None;
}
_ => {}
}
if is_module_like {