Skip to content

Commit

Permalink
diagnostic descriptor: redundant_assignment
Browse files Browse the repository at this point in the history
Summary:
As title.

This also fully removes the now-empty `semantic_diagnostics` function

Reviewed By: robertoaloi

Differential Revision: D55740827

fbshipit-source-id: c207bcc6de2f33becccc341ac1c8112792344c1e
  • Loading branch information
alanz authored and facebook-github-bot committed Apr 5, 2024
1 parent dbb6602 commit e3c1add
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 1 addition & 16 deletions crates/ide/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ pub fn native_diagnostics(
config
.lints_from_config
.get_diagnostics(&mut res, &sema, file_id);
semantic_diagnostics(&mut res, &sema, file_id, file_kind, config);
// @fb-only: meta_only::diagnostics(&mut res, &sema, file_id);
syntax_diagnostics(&sema, &parse, &mut res, file_id);
diagnostics_from_descriptors(
Expand Down Expand Up @@ -564,6 +563,7 @@ pub fn diagnostics_descriptors<'a>() -> Vec<&'a DiagnosticDescriptor<'a>> {
vec![
&unused_function_args::DESCRIPTOR,
&trivial_match::DESCRIPTOR,
&redundant_assignment::DESCRIPTOR,
&unused_macro::DESCRIPTOR,
&unused_record_field::DESCRIPTOR,
&mutable_variable::DESCRIPTOR,
Expand Down Expand Up @@ -655,21 +655,6 @@ fn widen_range(range: TextRange) -> TextRange {
}
}

pub fn semantic_diagnostics(
res: &mut Vec<Diagnostic>,
sema: &Semantic,
file_id: FileId,
_file_kind: FileKind,
config: &DiagnosticsConfig,
) {
if config.include_generated || !sema.db.is_generated(file_id) {
// TODO: disable this check when T151727890 and T151605845 are resolved
if config.experimental {
redundant_assignment::redundant_assignment(res, sema, file_id);
}
}
}

pub fn syntax_diagnostics(
sema: &Semantic,
parse: &Parse<ast::SourceFile>,
Expand Down
16 changes: 15 additions & 1 deletion crates/ide/src/diagnostics/redundant_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,28 @@ use hir::Semantic;
use hir::Strategy;

use super::Diagnostic;
use super::DiagnosticConditions;
use super::DiagnosticDescriptor;
use super::Severity;
use crate::codemod_helpers::check_is_only_place_where_var_is_defined_ast;
use crate::codemod_helpers::check_var_has_references;
use crate::diagnostics::Category;
use crate::diagnostics::DiagnosticCode;
use crate::fix;

pub(crate) fn redundant_assignment(diags: &mut Vec<Diagnostic>, sema: &Semantic, file_id: FileId) {
pub(crate) static DESCRIPTOR: DiagnosticDescriptor = DiagnosticDescriptor {
conditions: DiagnosticConditions {
// TODO: disable this check when T151727890 and T151605845 are resolved
experimental: true,
include_generated: false,
include_tests: true,
},
checker: &|diags, sema, file_id, _ext| {
redundant_assignment(diags, sema, file_id);
},
};

fn redundant_assignment(diags: &mut Vec<Diagnostic>, sema: &Semantic, file_id: FileId) {
if sema.db.is_generated(file_id) {
// No point asking for changes to generated files
return;
Expand Down

0 comments on commit e3c1add

Please sign in to comment.