Skip to content

Commit accd64e

Browse files
committed
make eiiid map
1 parent a8aeac0 commit accd64e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) mod allow_unstable;
2727
pub(crate) mod cfg;
2828
pub(crate) mod confusables;
2929
pub(crate) mod deprecation;
30+
pub(crate) mod eii;
3031
pub(crate) mod repr;
3132
pub(crate) mod rustc;
3233
pub(crate) mod stability;

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use rustc_expand::expand::AstFragment;
88
use rustc_hir as hir;
99
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
1010
use rustc_hir::def_id::LocalDefId;
11+
use rustc_middle::bug;
1112
use rustc_span::hygiene::LocalExpnId;
12-
use rustc_span::{Span, Symbol, sym};
13+
use rustc_span::{EiiId, Span, Symbol, sym};
1314
use tracing::debug;
1415

1516
use crate::{ImplTraitContext, InvocationParent, Resolver};
@@ -256,6 +257,22 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
256257

257258
let def = self.create_def(fi.id, Some(fi.ident.name), def_kind, fi.span);
258259

260+
if let ForeignItemKind::Fn(_) = fi.kind {
261+
for attr in &fi.attrs {
262+
if attr.has_name(sym::eii)
263+
&& let Some([arg]) = attr.meta_item_list().as_deref()
264+
&& let Some(lit) = arg.lit()
265+
&& let LitKind::Int(i, _) = lit.kind
266+
&& let Ok(id) = u32::try_from(i.get())
267+
{
268+
let id = EiiId::from(id);
269+
if let Some(other) = self.resolver.eii.insert(id, def) {
270+
bug!("{def:?}: {id:?} used more than once (used first on {other:?})");
271+
}
272+
}
273+
}
274+
}
275+
259276
self.with_parent(def, |this| visit::walk_item(this, fi));
260277
}
261278

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::cell::{Cell, RefCell};
2525
use std::collections::BTreeSet;
2626
use std::fmt;
2727
use std::sync::Arc;
28-
use rustc_span::EiiId,
2928

3029
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
3130
use effective_visibilities::EffectiveVisibilitiesVisitor;
@@ -71,7 +70,7 @@ use rustc_query_system::ich::StableHashingContext;
7170
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
7271
use rustc_session::lint::{BuiltinLintDiag, LintBuffer};
7372
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
74-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
73+
use rustc_span::{DUMMY_SP, EiiId, Ident, Span, Symbol, kw, sym};
7574
use smallvec::{SmallVec, smallvec};
7675
use tracing::debug;
7776

@@ -1230,7 +1229,7 @@ pub struct Resolver<'ra, 'tcx> {
12301229
mods_with_parse_errors: FxHashSet<DefId>,
12311230

12321231
/// Map of defids for all items marked with #[eii(<eii id>)].
1233-
eii: FxHashMap<EiiId, DefId>,
1232+
eii: FxHashMap<EiiId, LocalDefId>,
12341233
}
12351234

12361235
/// This provides memory for the rest of the crate. The `'ra` lifetime that is
@@ -1576,6 +1575,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15761575
impl_binding_keys: Default::default(),
15771576
current_crate_outer_attr_insert_span,
15781577
mods_with_parse_errors: Default::default(),
1578+
eii: Default::default(),
15791579
};
15801580

15811581
let root_parent_scope = ParentScope::module(graph_root, &resolver);

0 commit comments

Comments
 (0)