Skip to content

Commit d7795d3

Browse files
committed
Do not store visibility in *ItemRef.
1 parent 5ecc8ad commit d7795d3

File tree

16 files changed

+49
-70
lines changed

16 files changed

+49
-70
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
5555
0,
5656
ParenthesizedGenericArgs::Err,
5757
ImplTraitContext::disallowed(),
58-
None,
5958
));
6059
let args = self.lower_exprs(args);
6160
hir::ExprKind::MethodCall(

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
188188

189189
pub fn lower_item(&mut self, i: &Item) -> hir::Item<'hir> {
190190
let mut ident = i.ident;
191-
let mut vis = self.lower_visibility(&i.vis, None);
191+
let mut vis = self.lower_visibility(&i.vis);
192192
let hir_id = self.lower_node_id(i.id);
193193
let attrs = self.lower_attrs(hir_id, &i.attrs);
194194
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
@@ -493,7 +493,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
493493

494494
self.with_hir_id_owner(new_node_id, |this| {
495495
let res = this.lower_res(res);
496-
let path = this.lower_path_extra(res, &path, ParamMode::Explicit, None);
496+
let path = this.lower_path_extra(res, &path, ParamMode::Explicit);
497497
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
498498
let vis = this.rebuild_vis(&vis);
499499
if let Some(attrs) = attrs {
@@ -510,7 +510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
510510
});
511511
}
512512

513-
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None);
513+
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit);
514514
hir::ItemKind::Use(path, hir::UseKind::Single)
515515
}
516516
UseTreeKind::Glob => {
@@ -610,7 +610,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
610610

611611
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
612612
let res = self.lower_res(res);
613-
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit, None);
613+
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit);
614614
hir::ItemKind::Use(path, hir::UseKind::ListStem)
615615
}
616616
}
@@ -679,17 +679,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
679679
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
680680
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
681681
},
682-
vis: self.lower_visibility(&i.vis, None),
682+
vis: self.lower_visibility(&i.vis),
683683
span: self.lower_span(i.span),
684684
}
685685
}
686686

687-
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> {
687+
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
688688
hir::ForeignItemRef {
689689
id: hir::ForeignItemId { def_id: self.allocate_hir_id_counter(i.id) },
690690
ident: self.lower_ident(i.ident),
691691
span: self.lower_span(i.span),
692-
vis: self.lower_visibility(&i.vis, Some(i.id)),
693692
}
694693
}
695694

@@ -757,7 +756,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
757756
// FIXME(jseyfried): positional field hygiene.
758757
None => Ident::new(sym::integer(index), self.lower_span(f.span)),
759758
},
760-
vis: self.lower_visibility(&f.vis, None),
759+
vis: self.lower_visibility(&f.vis),
761760
ty,
762761
}
763762
}
@@ -899,22 +898,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
899898
def_id: hir_id.expect_owner(),
900899
ident: self.lower_ident(i.ident),
901900
generics,
902-
vis: self.lower_visibility(&i.vis, None),
901+
vis: self.lower_visibility(&i.vis),
903902
defaultness,
904903
kind,
905904
span: self.lower_span(i.span),
906905
}
907906
}
908907

909-
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef<'hir> {
908+
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
910909
// Since `default impl` is not yet implemented, this is always true in impls.
911910
let has_value = true;
912911
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
913912
hir::ImplItemRef {
914913
id: hir::ImplItemId { def_id: self.allocate_hir_id_counter(i.id) },
915914
ident: self.lower_ident(i.ident),
916915
span: self.lower_span(i.span),
917-
vis: self.lower_visibility(&i.vis, Some(i.id)),
918916
defaultness,
919917
kind: match &i.kind {
920918
AssocItemKind::Const(..) => hir::AssocItemKind::Const,
@@ -932,25 +930,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
932930
/// lowered. This can happen during `lower_impl_item_ref()` where we need to
933931
/// lower a `Visibility` value although we haven't lowered the owning
934932
/// `ImplItem` in question yet.
935-
fn lower_visibility(
936-
&mut self,
937-
v: &Visibility,
938-
explicit_owner: Option<NodeId>,
939-
) -> hir::Visibility<'hir> {
933+
fn lower_visibility(&mut self, v: &Visibility) -> hir::Visibility<'hir> {
940934
let node = match v.kind {
941935
VisibilityKind::Public => hir::VisibilityKind::Public,
942936
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
943937
VisibilityKind::Restricted { ref path, id } => {
944938
debug!("lower_visibility: restricted path id = {:?}", id);
945-
let lowered_id = if let Some(owner) = explicit_owner {
946-
self.lower_node_id_with_owner(id, owner)
947-
} else {
948-
self.lower_node_id(id)
949-
};
950-
let res = self.expect_full_res(id);
951-
let res = self.lower_res(res);
939+
let lowered_id = self.lower_node_id(id);
952940
hir::VisibilityKind::Restricted {
953-
path: self.lower_path_extra(res, path, ParamMode::Explicit, explicit_owner),
941+
path: self.lower_path(id, path, ParamMode::Explicit),
954942
hir_id: lowered_id,
955943
}
956944
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
9999
num_lifetimes,
100100
parenthesized_generic_args,
101101
itctx.reborrow(),
102-
None,
103102
)
104103
},
105104
)),
@@ -147,7 +146,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
147146
0,
148147
ParenthesizedGenericArgs::Err,
149148
itctx.reborrow(),
150-
None,
151149
));
152150
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
153151

@@ -178,7 +176,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
178176
res: Res,
179177
p: &Path,
180178
param_mode: ParamMode,
181-
explicit_owner: Option<NodeId>,
182179
) -> &'hir hir::Path<'hir> {
183180
self.arena.alloc(hir::Path {
184181
res,
@@ -190,7 +187,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
190187
0,
191188
ParenthesizedGenericArgs::Err,
192189
ImplTraitContext::disallowed(),
193-
explicit_owner,
194190
)
195191
})),
196192
span: self.lower_span(p.span),
@@ -205,7 +201,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
205201
) -> &'hir hir::Path<'hir> {
206202
let res = self.expect_full_res(id);
207203
let res = self.lower_res(res);
208-
self.lower_path_extra(res, p, param_mode, None)
204+
self.lower_path_extra(res, p, param_mode)
209205
}
210206

211207
crate fn lower_path_segment(
@@ -216,7 +212,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
216212
expected_lifetimes: usize,
217213
parenthesized_generic_args: ParenthesizedGenericArgs,
218214
itctx: ImplTraitContext<'_, 'hir>,
219-
explicit_owner: Option<NodeId>,
220215
) -> hir::PathSegment<'hir> {
221216
debug!(
222217
"path_span: {:?}, lower_path_segment(segment: {:?}, expected_lifetimes: {:?})",
@@ -354,11 +349,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
354349
}
355350

356351
let res = self.expect_full_res(segment.id);
357-
let id = if let Some(owner) = explicit_owner {
358-
self.lower_node_id_with_owner(segment.id, owner)
359-
} else {
360-
self.lower_node_id(segment.id)
361-
};
352+
let id = self.lower_node_id(segment.id);
362353
debug!(
363354
"lower_path_segment: ident={:?} original-id={:?} new-id={:?}",
364355
segment.ident, segment.id, id,

compiler/rustc_hir/src/arena.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ macro_rules! arena_types {
2828
[] pat_field: rustc_hir::PatField<$tcx>,
2929
[] fn_decl: rustc_hir::FnDecl<$tcx>,
3030
[] foreign_item: rustc_hir::ForeignItem<$tcx>,
31-
[few] foreign_item_ref: rustc_hir::ForeignItemRef<$tcx>,
31+
[few] foreign_item_ref: rustc_hir::ForeignItemRef,
3232
[] impl_item: rustc_hir::ImplItem<$tcx>,
33-
[] impl_item_ref: rustc_hir::ImplItemRef<$tcx>,
33+
[] impl_item_ref: rustc_hir::ImplItemRef,
3434
[] item: rustc_hir::Item<$tcx>,
3535
[few] inline_asm: rustc_hir::InlineAsm<$tcx>,
3636
[few] llvm_inline_asm: rustc_hir::LlvmInlineAsm<$tcx>,

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@ pub enum ItemKind<'hir> {
27452745
/// A module.
27462746
Mod(Mod<'hir>),
27472747
/// An external module, e.g. `extern { .. }`.
2748-
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef<'hir>] },
2748+
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef] },
27492749
/// Module-level inline assembly (from `global_asm!`).
27502750
GlobalAsm(&'hir InlineAsm<'hir>),
27512751
/// A type alias, e.g., `type Foo = Bar<u8>`.
@@ -2782,7 +2782,7 @@ pub struct Impl<'hir> {
27822782
pub of_trait: Option<TraitRef<'hir>>,
27832783

27842784
pub self_ty: &'hir Ty<'hir>,
2785-
pub items: &'hir [ImplItemRef<'hir>],
2785+
pub items: &'hir [ImplItemRef],
27862786
}
27872787

27882788
impl ItemKind<'_> {
@@ -2846,13 +2846,12 @@ pub struct TraitItemRef {
28462846
/// passes to find the impl they want without loading the ID (which
28472847
/// means fewer edges in the incremental compilation graph).
28482848
#[derive(Debug, HashStable_Generic)]
2849-
pub struct ImplItemRef<'hir> {
2849+
pub struct ImplItemRef {
28502850
pub id: ImplItemId,
28512851
#[stable_hasher(project(name))]
28522852
pub ident: Ident,
28532853
pub kind: AssocItemKind,
28542854
pub span: Span,
2855-
pub vis: Visibility<'hir>,
28562855
pub defaultness: Defaultness,
28572856
}
28582857

@@ -2886,12 +2885,11 @@ impl ForeignItemId {
28862885
/// passes to find the impl they want without loading the ID (which
28872886
/// means fewer edges in the incremental compilation graph).
28882887
#[derive(Debug, HashStable_Generic)]
2889-
pub struct ForeignItemRef<'hir> {
2888+
pub struct ForeignItemRef {
28902889
pub id: ForeignItemId,
28912890
#[stable_hasher(project(name))]
28922891
pub ident: Ident,
28932892
pub span: Span,
2894-
pub vis: Visibility<'hir>,
28952893
}
28962894

28972895
#[derive(Debug)]

compiler/rustc_hir/src/intravisit.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ pub trait Visitor<'v>: Sized {
392392
fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) {
393393
walk_impl_item(self, ii)
394394
}
395-
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef<'v>) {
395+
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) {
396396
walk_foreign_item_ref(self, ii)
397397
}
398-
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef<'v>) {
398+
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) {
399399
walk_impl_item_ref(self, ii)
400400
}
401401
fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) {
@@ -1042,22 +1042,20 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
10421042

10431043
pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(
10441044
visitor: &mut V,
1045-
foreign_item_ref: &'v ForeignItemRef<'v>,
1045+
foreign_item_ref: &'v ForeignItemRef,
10461046
) {
10471047
// N.B., deliberately force a compilation error if/when new fields are added.
1048-
let ForeignItemRef { id, ident, span: _, ref vis } = *foreign_item_ref;
1048+
let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref;
10491049
visitor.visit_nested_foreign_item(id);
10501050
visitor.visit_ident(ident);
1051-
visitor.visit_vis(vis);
10521051
}
10531052

1054-
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef<'v>) {
1053+
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
10551054
// N.B., deliberately force a compilation error if/when new fields are added.
1056-
let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref;
1055+
let ImplItemRef { id, ident, ref kind, span: _, ref defaultness } = *impl_item_ref;
10571056
visitor.visit_nested_impl_item(id);
10581057
visitor.visit_ident(ident);
10591058
visitor.visit_associated_item_kind(kind);
1060-
visitor.visit_vis(vis);
10611059
visitor.visit_defaultness(defaultness);
10621060
}
10631061

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl Collector<'tcx> {
382382
}
383383
}
384384

385-
fn i686_arg_list_size(&self, item: &hir::ForeignItemRef<'_>) -> usize {
385+
fn i686_arg_list_size(&self, item: &hir::ForeignItemRef) -> usize {
386386
let argument_types: &List<Ty<'_>> = self.tcx.erase_late_bound_regions(
387387
self.tcx
388388
.type_of(item.id.def_id)
@@ -406,7 +406,7 @@ impl Collector<'tcx> {
406406
.sum()
407407
}
408408

409-
fn build_dll_import(&self, abi: Abi, item: &hir::ForeignItemRef<'_>) -> DllImport {
409+
fn build_dll_import(&self, abi: Abi, item: &hir::ForeignItemRef) -> DllImport {
410410
let calling_convention = if self.tcx.sess.target.arch == "x86" {
411411
match abi {
412412
Abi::C { .. } | Abi::Cdecl => DllCallingConvention::C,

compiler/rustc_middle/src/hir/map/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,18 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
413413
self.visit_nested_trait_item(id);
414414
}
415415

416-
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef<'hir>) {
416+
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) {
417417
// Do not visit the duplicate information in ImplItemRef. We want to
418418
// map the actual nodes, not the duplicate ones in the *Ref.
419-
let ImplItemRef { id, ident: _, kind: _, span: _, vis: _, defaultness: _ } = *ii;
419+
let ImplItemRef { id, ident: _, kind: _, span: _, defaultness: _ } = *ii;
420420

421421
self.visit_nested_impl_item(id);
422422
}
423423

424-
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef<'hir>) {
424+
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef) {
425425
// Do not visit the duplicate information in ForeignItemRef. We want to
426426
// map the actual nodes, not the duplicate ones in the *Ref.
427-
let ForeignItemRef { id, ident: _, span: _, vis: _ } = *fi;
427+
let ForeignItemRef { id, ident: _, span: _ } = *fi;
428428

429429
self.visit_nested_foreign_item(id);
430430
}

compiler/rustc_passes/src/hir_id_validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
163163
self.hir_ids_seen.insert(hir_id.local_id);
164164
}
165165

166-
fn visit_impl_item_ref(&mut self, _: &'hir hir::ImplItemRef<'hir>) {
166+
fn visit_impl_item_ref(&mut self, _: &'hir hir::ImplItemRef) {
167167
// Explicitly do nothing here. ImplItemRefs contain hir::Visibility
168168
// values that actually belong to an ImplItem instead of the ItemKind::Impl
169169
// we are currently in. So for those it's correct that they have a
170170
// different owner.
171171
}
172172

173-
fn visit_foreign_item_ref(&mut self, _: &'hir hir::ForeignItemRef<'hir>) {
173+
fn visit_foreign_item_ref(&mut self, _: &'hir hir::ForeignItemRef) {
174174
// Explicitly do nothing here. ForeignItemRefs contain hir::Visibility
175175
// values that actually belong to an ForeignItem instead of the ItemKind::ForeignMod
176176
// we are currently in. So for those it's correct that they have a

compiler/rustc_privacy/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
743743
}
744744
hir::ItemKind::Impl(ref impl_) => {
745745
for impl_item_ref in impl_.items {
746-
if impl_.of_trait.is_some() || impl_item_ref.vis.node.is_pub() {
746+
if impl_.of_trait.is_some()
747+
|| self.tcx.visibility(impl_item_ref.id.def_id) == ty::Visibility::Public
748+
{
747749
self.update(impl_item_ref.id.def_id, item_level);
748750
}
749751
}
@@ -768,7 +770,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
768770
}
769771
hir::ItemKind::ForeignMod { items, .. } => {
770772
for foreign_item in items {
771-
if foreign_item.vis.node.is_pub() {
773+
if self.tcx.visibility(foreign_item.id.def_id) == ty::Visibility::Public {
772774
self.update(foreign_item.id.def_id, item_level);
773775
}
774776
}
@@ -1678,7 +1680,10 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
16781680
// methods will be visible as `Public::foo`.
16791681
let mut found_pub_static = false;
16801682
for impl_item_ref in impl_.items {
1681-
if self.item_is_public(impl_item_ref.id.def_id, &impl_item_ref.vis) {
1683+
if self.access_levels.is_reachable(impl_item_ref.id.def_id)
1684+
|| self.tcx.visibility(impl_item_ref.id.def_id)
1685+
== ty::Visibility::Public
1686+
{
16821687
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
16831688
match impl_item_ref.kind {
16841689
AssocItemKind::Const => {

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
209209
_ => return,
210210
};
211211
let fix_span =
212-
|impl_item_ref: &hir::ImplItemRef<'_>| match tcx.hir().impl_item(impl_item_ref.id).kind {
212+
|impl_item_ref: &hir::ImplItemRef| match tcx.hir().impl_item(impl_item_ref.id).kind {
213213
hir::ImplItemKind::Const(ty, _) | hir::ImplItemKind::TyAlias(ty) => ty.span,
214214
_ => impl_item_ref.span,
215215
};

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn associated_item_from_trait_item_ref(
100100
fn associated_item_from_impl_item_ref(
101101
tcx: TyCtxt<'_>,
102102
parent_def_id: LocalDefId,
103-
impl_item_ref: &hir::ImplItemRef<'_>,
103+
impl_item_ref: &hir::ImplItemRef,
104104
) -> ty::AssocItem {
105105
let def_id = impl_item_ref.id.def_id;
106106
let (kind, has_self) = match impl_item_ref.kind {

0 commit comments

Comments
 (0)