Skip to content

Commit e49dfe5

Browse files
committed
Add feature to set path-based visibility of macro_rules to pub by default
1 parent ee44706 commit e49dfe5

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ impl UnreachablePub {
12471247
let mut applicability = Applicability::MachineApplicable;
12481248
if cx.tcx.visibility(def_id).is_public() && !cx.effective_visibilities.is_reachable(def_id)
12491249
{
1250+
12501251
// prefer suggesting `pub(super)` instead of `pub(crate)` when possible,
12511252
// except when `pub(super) == pub(crate)`
12521253
let new_vis = if let Some(ty::Visibility::Restricted(restricted_did)) =
@@ -1288,6 +1289,12 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
12881289
if let hir::ItemKind::Use(_, hir::UseKind::ListStem) = &item.kind {
12891290
return;
12901291
}
1292+
// Do not warn for macro_rules definitions which are pub and unreachable by default,
1293+
// only check their associated use re-exports.
1294+
if let hir::ItemKind::Macro(_, _,_) = &item.kind {
1295+
// TODO: How do I differentiate between `macro` and `macro_rules!` definitions?
1296+
return;
1297+
}
12911298
self.perform_lint(cx, "item", item.owner_id.def_id, item.vis_span, true);
12921299
}
12931300

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
12991299
let ident = ident.normalize_to_macros_2_0();
13001300
self.r.macro_names.insert(ident);
13011301
let is_macro_export = ast::attr::contains_name(&item.attrs, sym::macro_export);
1302-
let vis = if is_macro_export {
1303-
Visibility::Public
1304-
} else {
1305-
Visibility::Restricted(CRATE_DEF_ID)
1306-
};
1302+
let vis = Visibility::Public;
13071303
let binding = self.r.arenas.new_res_binding(res, vis.to_def_id(), span, expansion);
13081304
self.r.set_binding_parent_module(binding, parent_scope.module);
13091305
self.r.all_macro_rules.insert(ident.name);

0 commit comments

Comments
 (0)