Fix #[expect] for clippy::manual_non_exhaustive

This commit is contained in:
xFrednet 2022-06-25 14:16:33 +02:00
parent 525f5ee7ac
commit 6427ba4855
No known key found for this signature in database
GPG key ID: F5C59D0E669E5302
3 changed files with 18 additions and 8 deletions

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
use clippy_utils::source::snippet_opt;
use clippy_utils::{is_doc_hidden, is_lint_allowed, meets_msrv, msrvs};
use clippy_utils::{is_doc_hidden, meets_msrv, msrvs};
use rustc_ast::ast::{self, VisibilityKind};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
@ -190,12 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
!self
.constructed_enum_variants
.contains(&(enum_id.to_def_id(), variant_id.to_def_id()))
&& !is_lint_allowed(cx, MANUAL_NON_EXHAUSTIVE, cx.tcx.hir().local_def_id_to_hir_id(enum_id))
})
{
span_lint_and_then(
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(enum_id);
span_lint_hir_and_then(
cx,
MANUAL_NON_EXHAUSTIVE,
hir_id,
enum_span,
"this seems like a manual implementation of the non-exhaustive pattern",
|diag| {

View file

@ -1,3 +1,4 @@
#![feature(lint_reasons)]
#![warn(clippy::manual_non_exhaustive)]
#![allow(unused)]
@ -75,4 +76,12 @@ fn foo(x: &mut UsedHidden) {
}
}
#[expect(clippy::manual_non_exhaustive)]
enum ExpectLint {
A,
B,
#[doc(hidden)]
_C,
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: this seems like a manual implementation of the non-exhaustive pattern
--> $DIR/manual_non_exhaustive_enum.rs:4:1
--> $DIR/manual_non_exhaustive_enum.rs:5:1
|
LL | enum E {
| ^-----
@ -15,13 +15,13 @@ LL | | }
|
= note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
help: remove this variant
--> $DIR/manual_non_exhaustive_enum.rs:8:5
--> $DIR/manual_non_exhaustive_enum.rs:9:5
|
LL | _C,
| ^^
error: this seems like a manual implementation of the non-exhaustive pattern
--> $DIR/manual_non_exhaustive_enum.rs:13:1
--> $DIR/manual_non_exhaustive_enum.rs:14:1
|
LL | / enum Ep {
LL | | A,
@ -32,7 +32,7 @@ LL | | }
| |_^
|
help: remove this variant
--> $DIR/manual_non_exhaustive_enum.rs:17:5
--> $DIR/manual_non_exhaustive_enum.rs:18:5
|
LL | _C,
| ^^