fix: Don't emit "missing items" diagnostic for negative impls

This commit is contained in:
Maybe Waffle 2023-12-06 22:11:16 +00:00
parent 6557151dca
commit 1630477985
2 changed files with 16 additions and 1 deletions

View file

@ -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(),

View file

@ -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 () {}
"#,
)
}
}