Skip to content

Commit 457b966

Browse files
committed
Auto merge of rust-lang#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.
2 parents 4e814e3 + 1630477 commit 457b966

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/hir/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ impl Module {
671671
_ => (),
672672
};
673673

674-
if let Some(trait_) = trait_ {
674+
// Negative impls can't have items, don't emit missing items diagnostic for them
675+
if let (false, Some(trait_)) = (impl_is_negative, trait_) {
675676
let items = &db.trait_data(trait_.into()).items;
676677
let required_items = items.iter().filter(|&(_, assoc)| match *assoc {
677678
AssocItemId::FunctionId(it) => !db.function_data(it).has_body(),

crates/ide-diagnostics/src/handlers/trait_impl_missing_assoc_item.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,18 @@ impl Trait for () {
112112
"#,
113113
);
114114
}
115+
116+
#[test]
117+
fn negative_impl() {
118+
check_diagnostics(
119+
r#"
120+
trait Trait {
121+
fn item();
122+
}
123+
124+
// Negative impls don't require any items (in fact, the forbid providing any)
125+
impl !Trait for () {}
126+
"#,
127+
)
128+
}
115129
}

0 commit comments

Comments
 (0)