Auto merge of #15911 - Young-Flash:fix_missing_assoc_item, r=lnicola
fix: handle default constant values in `trait_impl_missing_assoc_item` diagnostic A patch of https://github.com/rust-lang/rust-analyzer/pull/15895, close https://github.com/rust-lang/rust-analyzer/issues/15909 cc `@Veykril`
This commit is contained in:
commit
1a5cee1731
@ -667,21 +667,21 @@ pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) {
|
||||
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(),
|
||||
},
|
||||
)
|
||||
))
|
||||
},
|
||||
));
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user