Skip to content

Commit

Permalink
fix: Don't emit "missing items" diagnostic for negative impls
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Dec 10, 2023
1 parent 6557151 commit 1630477
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {}
"#,
)
}
}

0 comments on commit 1630477

Please sign in to comment.