Skip to content

Commit

Permalink
fix missing assoc item
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Nov 16, 2023
1 parent 58de0b1 commit cfc881a
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 cfc881a

Please sign in to comment.