Skip to content

Commit 9d87a23

Browse files
committed
Auto merge of rust-lang#16073 - HKalbasi:rustc-tests-fixup, r=HKalbasi
Replace `doc_comments_and_attrs` with `collect_attrs` fix rust-lang#16063 I looked at the other usages of `doc_comments_and_attrs` and it seems all of them are prone to ignoring inner attributes. `@Veykril` should I replace all of those with `collect_attrs` and remove `doc_comments_and_attrs` (or even `HasDocComments`) entirely?
2 parents 19387d3 + 9337519 commit 9d87a23

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

crates/hir/src/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use hir_def::{
5959
Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId,
6060
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
6161
};
62-
use hir_expand::{name::name, MacroCallKind};
62+
use hir_expand::{attrs::collect_attrs, name::name, MacroCallKind};
6363
use hir_ty::{
6464
all_super_traits, autoderef, check_orphan_rules,
6565
consteval::{try_const_usize, unknown_const_as_generic, ConstEvalError, ConstExt},
@@ -81,7 +81,7 @@ use once_cell::unsync::Lazy;
8181
use rustc_hash::FxHashSet;
8282
use stdx::{impl_from, never};
8383
use syntax::{
84-
ast::{self, HasAttrs as _, HasDocComments, HasName},
84+
ast::{self, HasAttrs as _, HasName},
8585
AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, T,
8686
};
8787
use triomphe::Arc;
@@ -974,10 +974,9 @@ fn precise_macro_call_location(
974974
// Compute the precise location of the macro name's token in the derive
975975
// list.
976976
let token = (|| {
977-
let derive_attr = node
978-
.doc_comments_and_attrs()
977+
let derive_attr = collect_attrs(&node)
979978
.nth(derive_attr_index.ast_index())
980-
.and_then(Either::left)?;
979+
.and_then(|x| Either::left(x.1))?;
981980
let token_tree = derive_attr.meta()?.token_tree()?;
982981
let group_by = token_tree
983982
.syntax()
@@ -1002,10 +1001,9 @@ fn precise_macro_call_location(
10021001
}
10031002
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
10041003
let node = ast_id.to_node(db.upcast());
1005-
let attr = node
1006-
.doc_comments_and_attrs()
1004+
let attr = collect_attrs(&node)
10071005
.nth(invoc_attr_index.ast_index())
1008-
.and_then(Either::left)
1006+
.and_then(|x| Either::left(x.1))
10091007
.unwrap_or_else(|| {
10101008
panic!("cannot find attribute #{}", invoc_attr_index.ast_index())
10111009
});

crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ extern crate core;
4444
extern crate self as foo;
4545
struct Foo;
4646
use foo::Foo as Bar;
47+
"#,
48+
);
49+
}
50+
51+
#[test]
52+
fn regression_panic_with_inner_attribute_in_presence_of_unresolved_crate() {
53+
check_diagnostics(
54+
r#"
55+
//- /lib.rs
56+
#[macro_use] extern crate doesnotexist;
57+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved extern crate
58+
mod _test_inner {
59+
#![empty_attr]
60+
//^^^^^^^^^^^^^^ error: unresolved macro `empty_attr`
61+
}
4762
"#,
4863
);
4964
}

0 commit comments

Comments
 (0)