Skip to content

Commit 38bd3c2

Browse files
committed
Fix cfg_attr invalidating derive identifier IDE functionality
1 parent cc04cfc commit 38bd3c2

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

crates/hir/src/semantics.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
364364
self.imp.resolve_derive_ident(derive, ident)
365365
}
366366

367-
// FIXME: use this instead?
368-
// pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
369-
370367
pub fn record_literal_missing_fields(&self, literal: &ast::RecordExpr) -> Vec<(Field, Type)> {
371368
self.imp.record_literal_missing_fields(literal)
372369
}
@@ -931,7 +928,6 @@ impl<'db> SemanticsImpl<'db> {
931928
file.with_value(derive.clone()),
932929
)?;
933930
let attrs = adt_def.attrs(self.db);
934-
// FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/11298
935931
let mut derive_paths = attrs.get(attr_id)?.parse_path_comma_token_tree()?;
936932

937933
let derive_idx = tt

crates/hir_def/src/attr.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl ops::Deref for RawAttrs {
7373
}
7474
}
7575
impl Attrs {
76-
pub fn get(&self, AttrId { ast_index, .. }: AttrId) -> Option<&Attr> {
77-
(**self).get(ast_index as usize)
76+
pub fn get(&self, id: AttrId) -> Option<&Attr> {
77+
(**self).iter().find(|attr| attr.id == id)
7878
}
7979
}
8080

@@ -89,14 +89,6 @@ impl ops::Deref for Attrs {
8989
}
9090
}
9191

92-
impl ops::Index<AttrId> for Attrs {
93-
type Output = Attr;
94-
95-
fn index(&self, AttrId { ast_index, .. }: AttrId) -> &Self::Output {
96-
&(**self)[ast_index as usize]
97-
}
98-
}
99-
10092
impl ops::Deref for AttrsWithOwner {
10193
type Target = Attrs;
10294

@@ -110,7 +102,7 @@ impl RawAttrs {
110102

111103
pub(crate) fn new(db: &dyn DefDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self {
112104
let entries = collect_attrs(owner)
113-
.flat_map(|(id, attr)| match attr {
105+
.filter_map(|(id, attr)| match attr {
114106
Either::Left(attr) => {
115107
attr.meta().and_then(|meta| Attr::from_src(db, meta, hygiene, id))
116108
}

crates/ide/src/goto_definition.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,12 +1362,23 @@ impl Twait for Stwuct {
13621362

13631363
#[test]
13641364
fn goto_def_derive_input() {
1365+
// check(
1366+
// r#"
1367+
// //- minicore:derive
1368+
// #[rustc_builtin_macro]
1369+
// pub macro Copy {}
1370+
// // ^^^^
1371+
// #[derive(Copy$0)]
1372+
// struct Foo;
1373+
// "#,
1374+
// );
13651375
check(
13661376
r#"
13671377
//- minicore:derive
13681378
#[rustc_builtin_macro]
13691379
pub macro Copy {}
13701380
// ^^^^
1381+
#[cfg_attr(feature = "false", derive)]
13711382
#[derive(Copy$0)]
13721383
struct Foo;
13731384
"#,

0 commit comments

Comments
 (0)