Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b4832b3

Browse files
committed
Auto merge of rust-lang#14056 - Veykril:allow_internal_unsafe, r=Veykril
Parse macros `allow_internal_unsafe` attribute We don't use it for anything yet but it might become part of hygiene
2 parents be76f35 + c65782e commit b4832b3

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

crates/hir-def/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub struct Macro2Loc {
290290
pub container: ModuleId,
291291
pub id: ItemTreeId<MacroDef>,
292292
pub expander: MacroExpander,
293+
pub allow_internal_unsafe: bool,
293294
}
294295
impl_intern!(Macro2Id, Macro2Loc, intern_macro2, lookup_intern_macro2);
295296

@@ -299,8 +300,9 @@ pub struct MacroRulesId(salsa::InternId);
299300
pub struct MacroRulesLoc {
300301
pub container: ModuleId,
301302
pub id: ItemTreeId<MacroRules>,
302-
pub local_inner: bool,
303303
pub expander: MacroExpander,
304+
pub allow_internal_unsafe: bool,
305+
pub local_inner: bool,
304306
}
305307
impl_intern!(MacroRulesId, MacroRulesLoc, intern_macro_rules, lookup_intern_macro_rules);
306308

@@ -894,6 +896,7 @@ pub fn macro_id_to_def_id(db: &dyn db::DefDatabase, id: MacroId) -> MacroDefId {
894896
}
895897
},
896898
local_inner: false,
899+
allow_internal_unsafe: loc.allow_internal_unsafe,
897900
}
898901
}
899902
MacroId::MacroRulesId(it) => {
@@ -918,6 +921,7 @@ pub fn macro_id_to_def_id(db: &dyn db::DefDatabase, id: MacroId) -> MacroDefId {
918921
}
919922
},
920923
local_inner: loc.local_inner,
924+
allow_internal_unsafe: loc.allow_internal_unsafe,
921925
}
922926
}
923927
MacroId::ProcMacroId(it) => {
@@ -933,6 +937,7 @@ pub fn macro_id_to_def_id(db: &dyn db::DefDatabase, id: MacroId) -> MacroDefId {
933937
InFile::new(loc.id.file_id(), makro.ast_id),
934938
),
935939
local_inner: false,
940+
allow_internal_unsafe: false,
936941
}
937942
}
938943
}

crates/hir-def/src/macro_expansion_tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
9797
let ast_id = AstId::new(source.file_id, file_ast_id.upcast());
9898
let kind = MacroDefKind::Declarative(ast_id);
9999

100-
let macro_def = db.macro_def(MacroDefId { krate, kind, local_inner: false }).unwrap();
100+
let macro_def = db
101+
.macro_def(MacroDefId { krate, kind, local_inner: false, allow_internal_unsafe: false })
102+
.unwrap();
101103
if let TokenExpander::DeclarativeMacro { mac, def_site_token_map } = &*macro_def {
102104
let tt = match &macro_ {
103105
ast::Macro::MacroRules(mac) => mac.token_tree().unwrap(),

crates/hir-def/src/nameres/collector.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,11 +1982,13 @@ impl ModCollector<'_, '_> {
19821982
// Case 2: normal `macro_rules!` macro
19831983
MacroExpander::Declarative
19841984
};
1985+
let allow_internal_unsafe = attrs.by_key("allow_internal_unsafe").exists();
19851986

19861987
let macro_id = MacroRulesLoc {
19871988
container: module,
19881989
id: ItemTreeId::new(self.tree_id, id),
19891990
local_inner,
1991+
allow_internal_unsafe,
19901992
expander,
19911993
}
19921994
.intern(self.def_collector.db);
@@ -2046,10 +2048,15 @@ impl ModCollector<'_, '_> {
20462048
// Case 2: normal `macro`
20472049
MacroExpander::Declarative
20482050
};
2051+
let allow_internal_unsafe = attrs.by_key("allow_internal_unsafe").exists();
20492052

2050-
let macro_id =
2051-
Macro2Loc { container: module, id: ItemTreeId::new(self.tree_id, id), expander }
2052-
.intern(self.def_collector.db);
2053+
let macro_id = Macro2Loc {
2054+
container: module,
2055+
id: ItemTreeId::new(self.tree_id, id),
2056+
expander,
2057+
allow_internal_unsafe,
2058+
}
2059+
.intern(self.def_collector.db);
20532060
self.def_collector.define_macro_def(
20542061
self.module_id,
20552062
mac.name.clone(),

crates/hir-expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct MacroDefId {
116116
pub krate: CrateId,
117117
pub kind: MacroDefKind,
118118
pub local_inner: bool,
119+
pub allow_internal_unsafe: bool,
119120
}
120121

121122
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)