Skip to content

Commit

Permalink
Replace doc_comments_and_attrs with collect_attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Dec 9, 2023
1 parent 19387d3 commit 9337519
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use hir_def::{
Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId,
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
};
use hir_expand::{name::name, MacroCallKind};
use hir_expand::{attrs::collect_attrs, name::name, MacroCallKind};
use hir_ty::{
all_super_traits, autoderef, check_orphan_rules,
consteval::{try_const_usize, unknown_const_as_generic, ConstEvalError, ConstExt},
Expand All @@ -81,7 +81,7 @@ use once_cell::unsync::Lazy;
use rustc_hash::FxHashSet;
use stdx::{impl_from, never};
use syntax::{
ast::{self, HasAttrs as _, HasDocComments, HasName},
ast::{self, HasAttrs as _, HasName},
AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, T,
};
use triomphe::Arc;
Expand Down Expand Up @@ -974,10 +974,9 @@ fn precise_macro_call_location(
// Compute the precise location of the macro name's token in the derive
// list.
let token = (|| {
let derive_attr = node
.doc_comments_and_attrs()
let derive_attr = collect_attrs(&node)
.nth(derive_attr_index.ast_index())
.and_then(Either::left)?;
.and_then(|x| Either::left(x.1))?;
let token_tree = derive_attr.meta()?.token_tree()?;
let group_by = token_tree
.syntax()
Expand All @@ -1002,10 +1001,9 @@ fn precise_macro_call_location(
}
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
let node = ast_id.to_node(db.upcast());
let attr = node
.doc_comments_and_attrs()
let attr = collect_attrs(&node)
.nth(invoc_attr_index.ast_index())
.and_then(Either::left)
.and_then(|x| Either::left(x.1))
.unwrap_or_else(|| {
panic!("cannot find attribute #{}", invoc_attr_index.ast_index())
});
Expand Down
15 changes: 15 additions & 0 deletions crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ extern crate core;
extern crate self as foo;
struct Foo;
use foo::Foo as Bar;
"#,
);
}

#[test]
fn regression_panic_with_inner_attribute_in_presence_of_unresolved_crate() {
check_diagnostics(
r#"
//- /lib.rs
#[macro_use] extern crate doesnotexist;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved extern crate
mod _test_inner {
#![empty_attr]
//^^^^^^^^^^^^^^ error: unresolved macro `empty_attr`
}
"#,
);
}
Expand Down

0 comments on commit 9337519

Please sign in to comment.