Fix cfg_attr invalidating derive identifier IDE functionality

This commit is contained in:
Lukas Wirth 2022-01-30 22:46:05 +01:00
parent cc04cfc982
commit ddf7b70a0f
3 changed files with 14 additions and 15 deletions

View File

@ -364,9 +364,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
self.imp.resolve_derive_ident(derive, ident)
}
// FIXME: use this instead?
// pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
pub fn record_literal_missing_fields(&self, literal: &ast::RecordExpr) -> Vec<(Field, Type)> {
self.imp.record_literal_missing_fields(literal)
}
@ -931,7 +928,6 @@ impl<'db> SemanticsImpl<'db> {
file.with_value(derive.clone()),
)?;
let attrs = adt_def.attrs(self.db);
// FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/11298
let mut derive_paths = attrs.get(attr_id)?.parse_path_comma_token_tree()?;
let derive_idx = tt

View File

@ -73,8 +73,8 @@ impl ops::Deref for RawAttrs {
}
}
impl Attrs {
pub fn get(&self, AttrId { ast_index, .. }: AttrId) -> Option<&Attr> {
(**self).get(ast_index as usize)
pub fn get(&self, id: AttrId) -> Option<&Attr> {
(**self).iter().find(|attr| attr.id == id)
}
}
@ -89,14 +89,6 @@ impl ops::Deref for Attrs {
}
}
impl ops::Index<AttrId> for Attrs {
type Output = Attr;
fn index(&self, AttrId { ast_index, .. }: AttrId) -> &Self::Output {
&(**self)[ast_index as usize]
}
}
impl ops::Deref for AttrsWithOwner {
type Target = Attrs;
@ -110,7 +102,7 @@ impl RawAttrs {
pub(crate) fn new(db: &dyn DefDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self {
let entries = collect_attrs(owner)
.flat_map(|(id, attr)| match attr {
.filter_map(|(id, attr)| match attr {
Either::Left(attr) => {
attr.meta().and_then(|meta| Attr::from_src(db, meta, hygiene, id))
}

View File

@ -1364,10 +1364,21 @@ impl Twait for Stwuct {
fn goto_def_derive_input() {
check(
r#"
//- minicore:derive
#[rustc_builtin_macro]
pub macro Copy {}
// ^^^^
#[derive(Copy$0)]
struct Foo;
"#,
);
check(
r#"
//- minicore:derive
#[rustc_builtin_macro]
pub macro Copy {}
// ^^^^
#[cfg_attr(feature = "false", derive)]
#[derive(Copy$0)]
struct Foo;
"#,