Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/diagnostics/expr.rs')
-rw-r--r--crates/hir-ty/src/diagnostics/expr.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs
index 1a134e6d78..dfc0a25bf4 100644
--- a/crates/hir-ty/src/diagnostics/expr.rs
+++ b/crates/hir-ty/src/diagnostics/expr.rs
@@ -60,12 +60,17 @@ pub enum BodyValidationDiagnostic {
}
impl BodyValidationDiagnostic {
- pub fn collect(db: &dyn HirDatabase, owner: DefWithBodyId) -> Vec<BodyValidationDiagnostic> {
+ pub fn collect(
+ db: &dyn HirDatabase,
+ owner: DefWithBodyId,
+ validate_lints: bool,
+ ) -> Vec<BodyValidationDiagnostic> {
let _p =
tracing::span!(tracing::Level::INFO, "BodyValidationDiagnostic::collect").entered();
let infer = db.infer(owner);
let body = db.body(owner);
- let mut validator = ExprValidator { owner, body, infer, diagnostics: Vec::new() };
+ let mut validator =
+ ExprValidator { owner, body, infer, diagnostics: Vec::new(), validate_lints };
validator.validate_body(db);
validator.diagnostics
}
@@ -76,6 +81,7 @@ struct ExprValidator {
body: Arc<Body>,
infer: Arc<InferenceResult>,
diagnostics: Vec<BodyValidationDiagnostic>,
+ validate_lints: bool,
}
impl ExprValidator {
@@ -139,6 +145,9 @@ impl ExprValidator {
expr: &Expr,
filter_map_next_checker: &mut Option<FilterMapNextChecker>,
) {
+ if !self.validate_lints {
+ return;
+ }
// Check that the number of arguments matches the number of parameters.
if self.infer.expr_type_mismatches().next().is_some() {
@@ -308,6 +317,9 @@ impl ExprValidator {
}
fn check_for_trailing_return(&mut self, body_expr: ExprId, body: &Body) {
+ if !self.validate_lints {
+ return;
+ }
match &body.exprs[body_expr] {
Expr::Block { statements, tail, .. } => {
let last_stmt = tail.or_else(|| match statements.last()? {
@@ -340,6 +352,9 @@ impl ExprValidator {
}
fn check_for_unnecessary_else(&mut self, id: ExprId, expr: &Expr, db: &dyn HirDatabase) {
+ if !self.validate_lints {
+ return;
+ }
if let Expr::If { condition: _, then_branch, else_branch } = expr {
if else_branch.is_none() {
return;