Skip to content

Commit

Permalink
Auto merge of #15911 - Young-Flash:fix_missing_assoc_item, r=lnicola
Browse files Browse the repository at this point in the history
fix: handle default constant values in `trait_impl_missing_assoc_item` diagnostic

A patch of #15895, close #15909

cc `@Veykril`
  • Loading branch information
bors committed Nov 20, 2023
2 parents 3751429 + cfc881a commit 1a5cee1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,21 +667,21 @@ impl Module {
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(),
AssocItemId::ConstId(_) => true,
AssocItemId::ConstId(id) => Const::from(id).value(db).is_none(),
AssocItemId::TypeAliasId(it) => db.type_alias_data(it).type_ref.is_none(),
});
impl_assoc_items_scratch.extend(db.impl_data(impl_def.id).items.iter().map(
impl_assoc_items_scratch.extend(db.impl_data(impl_def.id).items.iter().filter_map(
|&item| {
(
Some((
item,
match item {
AssocItemId::FunctionId(it) => db.function_data(it).name.clone(),
AssocItemId::ConstId(it) => {
db.const_data(it).name.as_ref().unwrap().clone()
db.const_data(it).name.as_ref()?.clone()
}
AssocItemId::TypeAliasId(it) => db.type_alias_data(it).name.clone(),
},
)
))
},
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ pub(crate) fn trait_impl_missing_assoc_item(
mod tests {
use crate::tests::check_diagnostics;

#[test]
fn trait_with_default_value() {
check_diagnostics(
r#"
trait Marker {
const FLAG: bool = false;
}
struct Foo;
impl Marker for Foo {}
"#,
)
}

#[test]
fn simple() {
check_diagnostics(
Expand Down

0 comments on commit 1a5cee1

Please sign in to comment.