diff options
| author | bors <bors@rust-lang.org> | 2023-12-10 22:24:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-10 22:24:32 +0000 |
| commit | 457b966b171b09a7e57acb710fbca29a4b3526f0 (patch) | |
| tree | 12b1cd0e758b69efc35dce8d39d0944daedcdb85 | |
| parent | 4e814e3f246994e235e8efb042a8c6ca74e814f6 (diff) | |
| parent | 1630477985097fcc9457dbd5f11b75ddb52bfe5b (diff) | |
| download | rust-457b966b171b09a7e57acb710fbca29a4b3526f0.tar.gz rust-457b966b171b09a7e57acb710fbca29a4b3526f0.zip | |
Auto merge of #16039 - WaffleLapkin:don't-emit-missing-assoc-items-diagnostic-for-negative-impls, r=Veykril
fix: Don't emit "missing items" diagnostic for negative impls Negative impls can't have items, so there is no reason for this diagnostic. LMK if I should add a test somewhere. Also LMK if that's not how we usually check multiple things in an if in r-a.
| -rw-r--r-- | crates/hir/src/lib.rs | 3 | ||||
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index eff98b21d2c..e0230fa3761 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -671,7 +671,8 @@ impl Module { _ => (), }; - if let Some(trait_) = trait_ { + // Negative impls can't have items, don't emit missing items diagnostic for them + if let (false, Some(trait_)) = (impl_is_negative, trait_) { let items = &db.trait_data(trait_.into()).items; let required_items = items.iter().filter(|&(_, assoc)| match *assoc { AssocItemId::FunctionId(it) => !db.function_data(it).has_body(), diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs b/crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs index 51923797ac9..56188cddf0b 100644 --- a/crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs +++ b/crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs @@ -112,4 +112,18 @@ impl Trait for () { "#, ); } + + #[test] + fn negative_impl() { + check_diagnostics( + r#" +trait Trait { + fn item(); +} + +// Negative impls don't require any items (in fact, the forbid providing any) +impl !Trait for () {} +"#, + ) + } } |
