Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/assoc.rs')
-rw-r--r--crates/hir-def/src/nameres/assoc.rs55
1 files changed, 32 insertions, 23 deletions
diff --git a/crates/hir-def/src/nameres/assoc.rs b/crates/hir-def/src/nameres/assoc.rs
index 8d2a386de8..9d2b2109fb 100644
--- a/crates/hir-def/src/nameres/assoc.rs
+++ b/crates/hir-def/src/nameres/assoc.rs
@@ -4,7 +4,8 @@ use std::mem;
use cfg::CfgOptions;
use hir_expand::{
- AstId, ExpandTo, HirFileId, InFile, Intern, Lookup, MacroCallKind, MacroDefKind,
+ AstId, AttrMacroAttrIds, ExpandTo, HirFileId, InFile, Intern, Lookup, MacroCallKind,
+ MacroDefKind,
mod_path::ModPath,
name::{AsName, Name},
span_map::SpanMap,
@@ -21,8 +22,8 @@ use triomphe::Arc;
use crate::{
AssocItemId, AstIdWithPath, ConstLoc, FunctionId, FunctionLoc, ImplId, ItemContainerId,
ItemLoc, MacroCallId, ModuleId, TraitId, TypeAliasId, TypeAliasLoc,
- attr::Attrs,
db::DefDatabase,
+ item_tree::AttrsOrCfg,
macro_call_as_call_id,
nameres::{
DefMap, LocalDefMap, MacroSubNs,
@@ -164,7 +165,7 @@ impl<'a> AssocItemCollector<'a> {
local_def_map,
ast_id_map: db.ast_id_map(file_id),
span_map: db.span_map(file_id),
- cfg_options: module_id.krate.cfg_options(db),
+ cfg_options: module_id.krate(db).cfg_options(db),
file_id,
container,
items: Vec::new(),
@@ -191,27 +192,31 @@ impl<'a> AssocItemCollector<'a> {
fn collect_item(&mut self, item: ast::AssocItem) {
let ast_id = self.ast_id_map.ast_id(&item);
- let attrs = Attrs::new(self.db, &item, self.span_map.as_ref(), self.cfg_options);
- if let Err(cfg) = attrs.is_cfg_enabled(self.cfg_options) {
- self.diagnostics.push(DefDiagnostic::unconfigured_code(
- self.module_id.local_id,
- InFile::new(self.file_id, ast_id.erase()),
- cfg,
- self.cfg_options.clone(),
- ));
- return;
- }
+ let attrs =
+ match AttrsOrCfg::lower(self.db, &item, &|| self.cfg_options, self.span_map.as_ref()) {
+ AttrsOrCfg::Enabled { attrs } => attrs,
+ AttrsOrCfg::CfgDisabled(cfg) => {
+ self.diagnostics.push(DefDiagnostic::unconfigured_code(
+ self.module_id,
+ InFile::new(self.file_id, ast_id.erase()),
+ cfg.0,
+ self.cfg_options.clone(),
+ ));
+ return;
+ }
+ };
let ast_id = InFile::new(self.file_id, ast_id.upcast());
- 'attrs: for attr in &*attrs {
+ 'attrs: for (attr_id, attr) in attrs.as_ref().iter() {
let ast_id_with_path = AstIdWithPath { path: attr.path.clone(), ast_id };
match self.def_map.resolve_attr_macro(
self.local_def_map,
self.db,
- self.module_id.local_id,
+ self.module_id,
ast_id_with_path,
attr,
+ attr_id,
) {
Ok(ResolvedAttr::Macro(call_id)) => {
let loc = self.db.lookup_intern_macro_call(call_id);
@@ -221,9 +226,9 @@ impl<'a> AssocItemCollector<'a> {
// crate failed), skip expansion like we would if it was
// disabled. This is analogous to the handling in
// `DefCollector::collect_macros`.
- if let Some(err) = exp.as_expand_error(self.module_id.krate) {
+ if let Some(err) = exp.as_expand_error(self.module_id.krate(self.db)) {
self.diagnostics.push(DefDiagnostic::macro_error(
- self.module_id.local_id,
+ self.module_id,
ast_id,
(*attr.path).clone(),
err,
@@ -239,9 +244,13 @@ impl<'a> AssocItemCollector<'a> {
Ok(_) => (),
Err(_) => {
self.diagnostics.push(DefDiagnostic::unresolved_macro_call(
- self.module_id.local_id,
- MacroCallKind::Attr { ast_id, attr_args: None, invoc_attr_index: attr.id },
- attr.path().clone(),
+ self.module_id,
+ MacroCallKind::Attr {
+ ast_id,
+ attr_args: None,
+ censored_attr_ids: AttrMacroAttrIds::from_one(attr_id),
+ },
+ (*attr.path).clone(),
));
}
}
@@ -298,7 +307,7 @@ impl<'a> AssocItemCollector<'a> {
.resolve_path(
self.local_def_map,
self.db,
- self.module_id.local_id,
+ self.module_id,
path,
crate::item_scope::BuiltinShadowMode::Other,
Some(MacroSubNs::Bang),
@@ -313,7 +322,7 @@ impl<'a> AssocItemCollector<'a> {
&path,
ctxt,
ExpandTo::Items,
- self.module_id.krate(),
+ self.module_id.krate(self.db),
resolver,
&mut |ptr, call_id| {
self.macro_calls.push((ptr.map(|(_, it)| it.upcast()), call_id))
@@ -329,7 +338,7 @@ impl<'a> AssocItemCollector<'a> {
},
Err(_) => {
self.diagnostics.push(DefDiagnostic::unresolved_macro_call(
- self.module_id.local_id,
+ self.module_id,
MacroCallKind::FnLike {
ast_id,
expand_to: ExpandTo::Items,