Skip to content

Commit

Permalink
BE: make atoms_exhaustion config completely static
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: robertoaloi

Differential Revision: D56629217

fbshipit-source-id: 77ba4febf1f9c76ae73a47b83a2f9086aac9c814
  • Loading branch information
alanz authored and facebook-github-bot committed Apr 29, 2024
1 parent bf8e8bf commit 076deb2
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions crates/ide/src/diagnostics/atoms_exhaustion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use elp_ide_db::elp_base_db::FileId;
use hir::FunctionDef;
use hir::Semantic;
use lazy_static::lazy_static;
use text_edit::TextRange;

use super::DiagnosticConditions;
Expand All @@ -35,19 +36,23 @@ pub(crate) static DESCRIPTOR: DiagnosticDescriptor = DiagnosticDescriptor {
};

fn atoms_exhaustion(diagnostics: &mut Vec<Diagnostic>, sema: &Semantic, file_id: FileId) {
let mut mfas = vec![
FunctionMatch::mfa("erlang", "binary_to_atom", 1),
FunctionMatch::mfa("erlang", "binary_to_atom", 2),
FunctionMatch::mfa("erlang", "list_to_atom", 1),
FunctionMatch::mfa("erlang", "binary_to_term", 1),
FunctionMatch::mfa("erlang", "binary_to_term", 2),
];

// @fb-only: let extra_mfas = diagnostics::meta_only::atoms_exhaustion_matches();
let extra_mfas = vec![]; // @oss-only
mfas.extend(extra_mfas);

let mfas = mfas.iter().map(|matcher| (matcher, ())).collect::<Vec<_>>();
lazy_static! {
static ref BAD_CALLS: Vec<FunctionMatch> = vec![
FunctionMatch::mfa("erlang", "binary_to_atom", 1),
FunctionMatch::mfa("erlang", "binary_to_atom", 2),
FunctionMatch::mfa("erlang", "list_to_atom", 1),
FunctionMatch::mfa("erlang", "binary_to_term", 1),
FunctionMatch::mfa("erlang", "binary_to_term", 2),
]
.into_iter()
// @fb-only: .chain(diagnostics::meta_only::atoms_exhaustion_matches().into_iter())
.collect();

static ref BAD_CALLS_MFAS: Vec<(&'static FunctionMatch, ())> = BAD_CALLS
.iter()
.map(|matcher| (matcher, ()))
.collect::<Vec<_>>();
}

sema.def_map(file_id)
.get_functions()
Expand All @@ -57,7 +62,7 @@ fn atoms_exhaustion(diagnostics: &mut Vec<Diagnostic>, sema: &Semantic, file_id:
// @fb-only: is_relevant = diagnostics::meta_only::is_relevant_file(sema.db.upcast(), file_id);
is_relevant = true; // @oss-only
if is_relevant {
check_function(diagnostics, sema, def, &mfas);
check_function(diagnostics, sema, def, &BAD_CALLS_MFAS);
}
}
});
Expand Down

0 comments on commit 076deb2

Please sign in to comment.