5682: Add an option to disable diagnostics r=matklad a=popzxc

As far as I know, currently it's not possible to disable a selected type of diagnostics provided by `rust-analyzer`.

This causes an inconvenient situation with a false-positive warnings: you either have to disable all the diagnostics, or you have to ignore these warnings.

There are some open issues related to this problem, e.g.: https://github.com/rust-analyzer/rust-analyzer/issues/5412, https://github.com/rust-analyzer/rust-analyzer/issues/5502

This PR attempts to make it possible to selectively disable some diagnostics on per-project basis.

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
This commit is contained in:
bors[bot] 2020-08-18 12:04:49 +00:00 committed by GitHub
commit b8dfc331ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 155 additions and 15 deletions

View file

@ -32,6 +32,10 @@ pub struct NoSuchField {
}
impl Diagnostic for NoSuchField {
fn name(&self) -> &'static str {
"no-such-field"
}
fn message(&self) -> String {
"no such field".to_string()
}
@ -54,6 +58,9 @@ pub struct MissingFields {
}
impl Diagnostic for MissingFields {
fn name(&self) -> &'static str {
"missing-structure-fields"
}
fn message(&self) -> String {
let mut buf = String::from("Missing structure fields:\n");
for field in &self.missed_fields {
@ -87,6 +94,9 @@ pub struct MissingPatFields {
}
impl Diagnostic for MissingPatFields {
fn name(&self) -> &'static str {
"missing-pat-fields"
}
fn message(&self) -> String {
let mut buf = String::from("Missing structure fields:\n");
for field in &self.missed_fields {
@ -117,6 +127,9 @@ pub struct MissingMatchArms {
}
impl Diagnostic for MissingMatchArms {
fn name(&self) -> &'static str {
"missing-match-arm"
}
fn message(&self) -> String {
String::from("Missing match arm")
}
@ -135,6 +148,9 @@ pub struct MissingOkInTailExpr {
}
impl Diagnostic for MissingOkInTailExpr {
fn name(&self) -> &'static str {
"missing-ok-in-tail-expr"
}
fn message(&self) -> String {
"wrap return expression in Ok".to_string()
}
@ -153,6 +169,9 @@ pub struct BreakOutsideOfLoop {
}
impl Diagnostic for BreakOutsideOfLoop {
fn name(&self) -> &'static str {
"break-outside-of-loop"
}
fn message(&self) -> String {
"break outside of loop".to_string()
}
@ -171,6 +190,9 @@ pub struct MissingUnsafe {
}
impl Diagnostic for MissingUnsafe {
fn name(&self) -> &'static str {
"missing-unsafe"
}
fn message(&self) -> String {
format!("This operation is unsafe and requires an unsafe function or block")
}
@ -191,6 +213,9 @@ pub struct MismatchedArgCount {
}
impl Diagnostic for MismatchedArgCount {
fn name(&self) -> &'static str {
"mismatched-arg-count"
}
fn message(&self) -> String {
let s = if self.expected == 1 { "" } else { "s" };
format!("Expected {} argument{}, found {}", self.expected, s, self.found)