[option_option]: Fix duplicate diagnostics

This commit is contained in:
kcz 2024-03-09 18:08:40 -05:00
parent 7ee75f896f
commit a92037fce8
No known key found for this signature in database
GPG key ID: 4D8C63ADDD1637A0
3 changed files with 18 additions and 16 deletions

View file

@ -15,7 +15,7 @@ use rustc_hir::{
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem,
TraitItemKind, TyKind, TraitItemKind, TyKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::Span; use rustc_span::Span;
@ -392,6 +392,10 @@ impl<'tcx> LateLintPass<'tcx> for Types {
} }
fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &hir::FieldDef<'tcx>) { fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &hir::FieldDef<'tcx>) {
if rustc_middle::lint::in_external_macro(cx.sess(), field.span) {
return;
}
let is_exported = cx.effective_visibilities.is_exported(field.def_id); let is_exported = cx.effective_visibilities.is_exported(field.def_id);
self.check_ty( self.check_ty(

View file

@ -1,5 +1,3 @@
//@compile-flags: -Zdeduplicate-diagnostics=yes
#![deny(clippy::option_option)] #![deny(clippy::option_option)]
#![allow(clippy::unnecessary_wraps)] #![allow(clippy::unnecessary_wraps)]

View file

@ -1,77 +1,77 @@
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:6:10 --> tests/ui/option_option.rs:4:10
| |
LL | const C: Option<Option<i32>> = None; LL | const C: Option<Option<i32>> = None;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
note: the lint level is defined here note: the lint level is defined here
--> tests/ui/option_option.rs:3:9 --> tests/ui/option_option.rs:1:9
| |
LL | #![deny(clippy::option_option)] LL | #![deny(clippy::option_option)]
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:8:11 --> tests/ui/option_option.rs:6:11
| |
LL | static S: Option<Option<i32>> = None; LL | static S: Option<Option<i32>> = None;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:11:13 --> tests/ui/option_option.rs:9:13
| |
LL | fn input(_: Option<Option<u8>>) {} LL | fn input(_: Option<Option<u8>>) {}
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:14:16 --> tests/ui/option_option.rs:12:16
| |
LL | fn output() -> Option<Option<u8>> { LL | fn output() -> Option<Option<u8>> {
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:19:27 --> tests/ui/option_option.rs:17:27
| |
LL | fn output_nested() -> Vec<Option<Option<u8>>> { LL | fn output_nested() -> Vec<Option<Option<u8>>> {
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:25:30 --> tests/ui/option_option.rs:23:30
| |
LL | fn output_nested_nested() -> Option<Option<Option<u8>>> { LL | fn output_nested_nested() -> Option<Option<Option<u8>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:31:8 --> tests/ui/option_option.rs:29:8
| |
LL | x: Option<Option<u8>>, LL | x: Option<Option<u8>>,
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:36:23 --> tests/ui/option_option.rs:34:23
| |
LL | fn struct_fn() -> Option<Option<u8>> { LL | fn struct_fn() -> Option<Option<u8>> {
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:43:22 --> tests/ui/option_option.rs:41:22
| |
LL | fn trait_fn() -> Option<Option<u8>>; LL | fn trait_fn() -> Option<Option<u8>>;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:48:11 --> tests/ui/option_option.rs:46:11
| |
LL | Tuple(Option<Option<u8>>), LL | Tuple(Option<Option<u8>>),
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:50:17 --> tests/ui/option_option.rs:48:17
| |
LL | Struct { x: Option<Option<u8>> }, LL | Struct { x: Option<Option<u8>> },
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> tests/ui/option_option.rs:92:14 --> tests/ui/option_option.rs:90:14
| |
LL | foo: Option<Option<Cow<'a, str>>>, LL | foo: Option<Option<Cow<'a, str>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^