diff options
| author | bors <bors@rust-lang.org> | 2023-12-09 20:24:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-09 20:24:50 +0000 |
| commit | 9d87a23cdef6087c1a0c97980949e2310271a941 (patch) | |
| tree | 5728d0a6fc1eab9dad3980085f913d9d7c041686 | |
| parent | 19387d3077c4c81e4a89ecec62917221fed26541 (diff) | |
| parent | 9337519df5f35f7e093650592e380f301a63bce5 (diff) | |
| download | rust-9d87a23cdef6087c1a0c97980949e2310271a941.tar.gz rust-9d87a23cdef6087c1a0c97980949e2310271a941.zip | |
Auto merge of #16073 - HKalbasi:rustc-tests-fixup, r=HKalbasi
Replace `doc_comments_and_attrs` with `collect_attrs` fix #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?
| -rw-r--r-- | crates/hir/src/lib.rs | 14 | ||||
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs | 15 |
2 files changed, 21 insertions, 8 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index ca838c7a51e..eff98b21d2c 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -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}, @@ -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; @@ -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() @@ -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()) }); diff --git a/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs b/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs index f8265b63275..71c501a336b 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs @@ -47,4 +47,19 @@ 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` + } +"#, + ); + } } |
