Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Respect #[allow(unused_braces)] #15527

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ide-diagnostics/src/handlers/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) fn unused_mut(ctx: &DiagnosticsContext<'_>, d: &hir::UnusedMut) -> Di
"variable does not need to be mutable",
ast,
)
.experimental() // Not supporting `#[allow(unused_mut)]` leads to false positive.
.experimental() // Not supporting `#[allow(unused_mut)]` in proc macros leads to false positive.
.with_fixes(fixes)
}

Expand Down
21 changes: 21 additions & 0 deletions crates/ide-diagnostics/src/handlers/useless_braces.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hir::InFile;
use ide_db::{base_db::FileId, source_change::SourceChange};
use itertools::Itertools;
use syntax::{ast, AstNode, SyntaxNode};
Expand Down Expand Up @@ -39,6 +40,7 @@ pub(crate) fn useless_braces(
"Unnecessary braces in use statement".to_string(),
use_range,
)
.with_main_node(InFile::new(file_id.into(), node.clone()))
.with_fixes(Some(vec![fix(
"remove_braces",
"Remove unnecessary braces",
Expand Down Expand Up @@ -153,6 +155,25 @@ use a::{c, d::{e$0}};
r#"
mod a { pub mod c {} pub mod d { pub mod e {} } }
use a::{c, d::e};
"#,
);
}

#[test]
fn respect_lint_attributes_for_unused_braces() {
check_diagnostics(
r#"
mod b {}
#[allow(unused_braces)]
use {b};
"#,
);
check_diagnostics(
r#"
mod b {}
#[deny(unused_braces)]
use {b};
//^^^ 💡 error: Unnecessary braces in use statement
"#,
);
}
Expand Down