mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
fix: Put style lints behind disabled-by-default config
This commit is contained in:
parent
ce3216e0ae
commit
8844640c6f
7 changed files with 66 additions and 20 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue