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

Commit cee5521

Browse files
committedOct 19, 2020
Calculate visibilities once in resolve
Then use them through a query based on resolver outputs
1 parent cb2462c commit cee5521

26 files changed

+322
-408
lines changed
 

‎compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,15 +2381,6 @@ impl VisibilityKind<'_> {
23812381
VisibilityKind::Crate(..) | VisibilityKind::Restricted { .. } => true,
23822382
}
23832383
}
2384-
2385-
pub fn descr(&self) -> &'static str {
2386-
match *self {
2387-
VisibilityKind::Public => "public",
2388-
VisibilityKind::Inherited => "private",
2389-
VisibilityKind::Crate(..) => "crate-visible",
2390-
VisibilityKind::Restricted { .. } => "restricted",
2391-
}
2392-
}
23932384
}
23942385

23952386
#[derive(Debug, HashStable_Generic)]

‎compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
2828
use rustc_serialize::{opaque, Encodable, Encoder};
2929
use rustc_session::config::CrateType;
3030
use rustc_span::hygiene::{ExpnDataEncodeMode, HygieneEncodeContext};
31-
use rustc_span::source_map::Spanned;
3231
use rustc_span::symbol::{sym, Ident, Symbol};
3332
use rustc_span::{self, ExternalSource, FileName, SourceFile, Span, SyntaxContext};
3433
use rustc_target::abi::VariantIdx;
@@ -436,8 +435,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
436435

437436
fn encode_info_for_items(&mut self) {
438437
let krate = self.tcx.hir().krate();
439-
let vis = Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Public };
440-
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.item.module, &krate.item.attrs, &vis);
438+
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.item.module, &krate.item.attrs);
441439

442440
// Proc-macro crates only export proc-macro items, which are looked
443441
// up using `proc_macro_data`
@@ -739,12 +737,8 @@ impl EncodeContext<'a, 'tcx> {
739737
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
740738
};
741739

742-
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
743-
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
744-
745740
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
746-
record!(self.tables.visibility[def_id] <-
747-
ty::Visibility::from_hir(enum_vis, enum_id, self.tcx));
741+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
748742
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
749743
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
750744
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
@@ -785,17 +779,8 @@ impl EncodeContext<'a, 'tcx> {
785779
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
786780
};
787781

788-
// Variant constructors have the same visibility as the parent enums, unless marked as
789-
// non-exhaustive, in which case they are lowered to `pub(crate)`.
790-
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
791-
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
792-
let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx);
793-
if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public {
794-
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
795-
}
796-
797782
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
798-
record!(self.tables.visibility[def_id] <- ctor_vis);
783+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
799784
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
800785
self.encode_stability(def_id);
801786
self.encode_deprecation(def_id);
@@ -811,13 +796,7 @@ impl EncodeContext<'a, 'tcx> {
811796
self.encode_promoted_mir(def_id.expect_local());
812797
}
813798

814-
fn encode_info_for_mod(
815-
&mut self,
816-
id: hir::HirId,
817-
md: &hir::Mod<'_>,
818-
attrs: &[ast::Attribute],
819-
vis: &hir::Visibility<'_>,
820-
) {
799+
fn encode_info_for_mod(&mut self, id: hir::HirId, md: &hir::Mod<'_>, attrs: &[ast::Attribute]) {
821800
let tcx = self.tcx;
822801
let local_def_id = tcx.hir().local_def_id(id);
823802
let def_id = local_def_id.to_def_id();
@@ -850,7 +829,7 @@ impl EncodeContext<'a, 'tcx> {
850829
};
851830

852831
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
853-
record!(self.tables.visibility[def_id] <- ty::Visibility::from_hir(vis, id, self.tcx));
832+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
854833
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
855834
record!(self.tables.attributes[def_id] <- attrs);
856835
if self.is_proc_macro {
@@ -881,7 +860,7 @@ impl EncodeContext<'a, 'tcx> {
881860
let variant_data = tcx.hir().expect_variant_data(variant_id);
882861

883862
record!(self.tables.kind[def_id] <- EntryKind::Field);
884-
record!(self.tables.visibility[def_id] <- field.vis);
863+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
885864
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
886865
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
887866
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
@@ -906,25 +885,8 @@ impl EncodeContext<'a, 'tcx> {
906885
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
907886
};
908887

909-
let struct_id = tcx.hir().local_def_id_to_hir_id(adt_def.did.expect_local());
910-
let struct_vis = &tcx.hir().expect_item(struct_id).vis;
911-
let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx);
912-
for field in &variant.fields {
913-
if ctor_vis.is_at_least(field.vis, tcx) {
914-
ctor_vis = field.vis;
915-
}
916-
}
917-
918-
// If the structure is marked as non_exhaustive then lower the visibility
919-
// to within the crate.
920-
if adt_def.non_enum_variant().is_field_list_non_exhaustive()
921-
&& ctor_vis == ty::Visibility::Public
922-
{
923-
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
924-
}
925-
926888
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr));
927-
record!(self.tables.visibility[def_id] <- ctor_vis);
889+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
928890
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
929891
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
930892
self.encode_stability(def_id);
@@ -1030,7 +992,7 @@ impl EncodeContext<'a, 'tcx> {
1030992
EntryKind::AssocType(container)
1031993
}
1032994
});
1033-
record!(self.tables.visibility[def_id] <- trait_item.vis);
995+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
1034996
record!(self.tables.span[def_id] <- ast_item.span);
1035997
record!(self.tables.attributes[def_id] <- ast_item.attrs);
1036998
self.encode_ident_span(def_id, ast_item.ident);
@@ -1112,7 +1074,7 @@ impl EncodeContext<'a, 'tcx> {
11121074
}
11131075
ty::AssocKind::Type => EntryKind::AssocType(container)
11141076
});
1115-
record!(self.tables.visibility[def_id] <- impl_item.vis);
1077+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
11161078
record!(self.tables.span[def_id] <- ast_item.span);
11171079
record!(self.tables.attributes[def_id] <- ast_item.attrs);
11181080
self.encode_ident_span(def_id, impl_item.ident);
@@ -1261,7 +1223,7 @@ impl EncodeContext<'a, 'tcx> {
12611223
EntryKind::Fn(self.lazy(data))
12621224
}
12631225
hir::ItemKind::Mod(ref m) => {
1264-
return self.encode_info_for_mod(item.hir_id, m, &item.attrs, &item.vis);
1226+
return self.encode_info_for_mod(item.hir_id, m, &item.attrs);
12651227
}
12661228
hir::ItemKind::ForeignMod(_) => EntryKind::ForeignMod,
12671229
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
@@ -1352,8 +1314,7 @@ impl EncodeContext<'a, 'tcx> {
13521314
hir::ItemKind::ExternCrate(_) |
13531315
hir::ItemKind::Use(..) => bug!("cannot encode info for item {:?}", item),
13541316
});
1355-
record!(self.tables.visibility[def_id] <-
1356-
ty::Visibility::from_hir(&item.vis, item.hir_id, tcx));
1317+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
13571318
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
13581319
record!(self.tables.attributes[def_id] <- item.attrs);
13591320
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
@@ -1470,7 +1431,7 @@ impl EncodeContext<'a, 'tcx> {
14701431
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
14711432
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id).to_def_id();
14721433
record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone())));
1473-
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
1434+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
14741435
record!(self.tables.span[def_id] <- macro_def.span);
14751436
record!(self.tables.attributes[def_id] <- macro_def.attrs);
14761437
self.encode_ident_span(def_id, macro_def.ident);
@@ -1480,7 +1441,6 @@ impl EncodeContext<'a, 'tcx> {
14801441

14811442
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) {
14821443
record!(self.tables.kind[def_id] <- kind);
1483-
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
14841444
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
14851445
if encode_type {
14861446
self.encode_item_type(def_id);
@@ -1505,7 +1465,6 @@ impl EncodeContext<'a, 'tcx> {
15051465

15061466
_ => bug!("closure that is neither generator nor closure"),
15071467
});
1508-
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
15091468
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
15101469
record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
15111470
self.encode_item_type(def_id.to_def_id());
@@ -1525,7 +1484,6 @@ impl EncodeContext<'a, 'tcx> {
15251484
let qualifs = self.tcx.mir_const_qualif(def_id);
15261485

15271486
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data));
1528-
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
15291487
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
15301488
self.encode_item_type(def_id.to_def_id());
15311489
self.encode_generics(def_id.to_def_id());
@@ -1762,8 +1720,7 @@ impl EncodeContext<'a, 'tcx> {
17621720
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => EntryKind::ForeignImmStatic,
17631721
hir::ForeignItemKind::Type => EntryKind::ForeignType,
17641722
});
1765-
record!(self.tables.visibility[def_id] <-
1766-
ty::Visibility::from_hir(&nitem.vis, nitem.hir_id, self.tcx));
1723+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
17671724
record!(self.tables.span[def_id] <- nitem.span);
17681725
record!(self.tables.attributes[def_id] <- nitem.attrs);
17691726
self.encode_ident_span(def_id, nitem.ident);

‎compiler/rustc_middle/src/middle/stability.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,12 @@ pub enum EvalResult {
256256
}
257257

258258
// See issue #38412.
259-
fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, mut def_id: DefId) -> bool {
260-
// Check if `def_id` is a trait method.
261-
match tcx.def_kind(def_id) {
262-
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
263-
if let ty::TraitContainer(trait_def_id) = tcx.associated_item(def_id).container {
264-
// Trait methods do not declare visibility (even
265-
// for visibility info in cstore). Use containing
266-
// trait instead, so methods of `pub` traits are
267-
// themselves considered `pub`.
268-
def_id = trait_def_id;
269-
}
270-
}
271-
_ => {}
259+
fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
260+
if tcx.def_kind(def_id) == DefKind::TyParam {
261+
// Have no visibility, considered public for the purpose of this check.
262+
return false;
272263
}
273-
274-
let visibility = tcx.visibility(def_id);
275-
276-
match visibility {
264+
match tcx.visibility(def_id) {
277265
// Must check stability for `pub` items.
278266
ty::Visibility::Public => false,
279267

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@ rustc_queries! {
12671267

12681268
TypeChecking {
12691269
query visibility(def_id: DefId) -> ty::Visibility {
1270+
eval_always
12701271
desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
12711272
}
12721273
}

‎compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::ty::{
2222
ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntVar,
2323
IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
2424
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
25-
TyVid, TypeAndMut,
25+
TyVid, TypeAndMut, Visibility,
2626
};
2727
use rustc_ast as ast;
2828
use rustc_ast::expand::allocator::AllocatorKind;
@@ -911,6 +911,9 @@ pub struct GlobalCtxt<'tcx> {
911911
/// Common consts, pre-interned for your convenience.
912912
pub consts: CommonConsts<'tcx>,
913913

914+
/// Visibilities produced by resolver.
915+
pub visibilities: FxHashMap<LocalDefId, Visibility>,
916+
914917
/// Resolutions of `extern crate` items produced by resolver.
915918
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
916919

@@ -1124,6 +1127,7 @@ impl<'tcx> TyCtxt<'tcx> {
11241127
types: common_types,
11251128
lifetimes: common_lifetimes,
11261129
consts: common_consts,
1130+
visibilities: resolutions.visibilities,
11271131
extern_crate_map: resolutions.extern_crate_map,
11281132
trait_map,
11291133
export_map: resolutions.export_map,

‎compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ mod sty;
125125
pub struct ResolverOutputs {
126126
pub definitions: rustc_hir::definitions::Definitions,
127127
pub cstore: Box<CrateStoreDyn>,
128+
pub visibilities: FxHashMap<LocalDefId, Visibility>,
128129
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
129130
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
130131
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,

‎compiler/rustc_privacy/src/lib.rs

Lines changed: 81 additions & 138 deletions
Large diffs are not rendered by default.

‎compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 114 additions & 72 deletions
Large diffs are not rendered by default.

‎compiler/rustc_resolve/src/def_collector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
7676
let def_data = match &i.kind {
7777
ItemKind::Impl { .. } => DefPathData::Impl,
7878
ItemKind::Mod(..) if i.ident.name == kw::Invalid => {
79+
// Fake crate root item from expand.
7980
return visit::walk_item(self, i);
8081
}
8182
ItemKind::Mod(..)

‎compiler/rustc_resolve/src/lib.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,8 @@ pub struct Resolver<'a> {
944944

945945
/// Maps glob imports to the names of items actually imported.
946946
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
947-
947+
/// Visibilities in "lowered" form, for all entities that have them.
948+
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
948949
used_imports: FxHashSet<(NodeId, Namespace)>,
949950
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
950951
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
@@ -1008,10 +1009,6 @@ pub struct Resolver<'a> {
10081009
/// Features enabled for this crate.
10091010
active_features: FxHashSet<Symbol>,
10101011

1011-
/// Stores enum visibilities to properly build a reduced graph
1012-
/// when visiting the correspondent variants.
1013-
variant_vis: DefIdMap<ty::Visibility>,
1014-
10151012
lint_buffer: LintBuffer,
10161013

10171014
next_node_id: NodeId,
@@ -1028,6 +1025,9 @@ pub struct Resolver<'a> {
10281025
invocation_parents: FxHashMap<ExpnId, LocalDefId>,
10291026

10301027
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
1028+
/// Some way to know that we are in a *trait* impl in `visit_assoc_item`.
1029+
/// FIXME: Replace with a more general AST map (together with some other fields).
1030+
trait_impl_items: FxHashSet<LocalDefId>,
10311031
}
10321032

10331033
/// Nothing really interesting here; it just provides memory for the rest of the crate.
@@ -1195,7 +1195,8 @@ impl<'a> Resolver<'a> {
11951195
metadata_loader: &'a MetadataLoaderDyn,
11961196
arenas: &'a ResolverArenas<'a>,
11971197
) -> Resolver<'a> {
1198-
let root_def_id = DefId::local(CRATE_DEF_INDEX);
1198+
let root_local_def_id = LocalDefId { local_def_index: CRATE_DEF_INDEX };
1199+
let root_def_id = root_local_def_id.to_def_id();
11991200
let root_module_kind = ModuleKind::Def(DefKind::Mod, root_def_id, kw::Invalid);
12001201
let graph_root = arenas.alloc_module(ModuleData {
12011202
no_implicit_prelude: session.contains_name(&krate.attrs, sym::no_implicit_prelude),
@@ -1213,11 +1214,14 @@ impl<'a> Resolver<'a> {
12131214
)
12141215
});
12151216
let mut module_map = FxHashMap::default();
1216-
module_map.insert(LocalDefId { local_def_index: CRATE_DEF_INDEX }, graph_root);
1217+
module_map.insert(root_local_def_id, graph_root);
12171218

12181219
let definitions = Definitions::new(crate_name, session.local_crate_disambiguator());
12191220
let root = definitions.get_root_def();
12201221

1222+
let mut visibilities = FxHashMap::default();
1223+
visibilities.insert(root_local_def_id, ty::Visibility::Public);
1224+
12211225
let mut def_id_to_span = IndexVec::default();
12221226
assert_eq!(def_id_to_span.push(rustc_span::DUMMY_SP), root);
12231227
let mut def_id_to_node_id = IndexVec::default();
@@ -1290,7 +1294,7 @@ impl<'a> Resolver<'a> {
12901294
ast_transform_scopes: FxHashMap::default(),
12911295

12921296
glob_map: Default::default(),
1293-
1297+
visibilities,
12941298
used_imports: FxHashSet::default(),
12951299
maybe_unused_trait_imports: Default::default(),
12961300
maybe_unused_extern_crates: Vec::new(),
@@ -1339,7 +1343,6 @@ impl<'a> Resolver<'a> {
13391343
.map(|(feat, ..)| *feat)
13401344
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
13411345
.collect(),
1342-
variant_vis: Default::default(),
13431346
lint_buffer: LintBuffer::default(),
13441347
next_node_id: NodeId::from_u32(1),
13451348
def_id_to_span,
@@ -1348,6 +1351,7 @@ impl<'a> Resolver<'a> {
13481351
placeholder_field_indices: Default::default(),
13491352
invocation_parents,
13501353
next_disambiguator: Default::default(),
1354+
trait_impl_items: Default::default(),
13511355
}
13521356
}
13531357

@@ -1371,6 +1375,7 @@ impl<'a> Resolver<'a> {
13711375

13721376
pub fn into_outputs(self) -> ResolverOutputs {
13731377
let definitions = self.definitions;
1378+
let visibilities = self.visibilities;
13741379
let extern_crate_map = self.extern_crate_map;
13751380
let export_map = self.export_map;
13761381
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
@@ -1379,6 +1384,7 @@ impl<'a> Resolver<'a> {
13791384
ResolverOutputs {
13801385
definitions: definitions,
13811386
cstore: Box::new(self.crate_loader.into_cstore()),
1387+
visibilities,
13821388
extern_crate_map,
13831389
export_map,
13841390
glob_map,
@@ -1396,6 +1402,7 @@ impl<'a> Resolver<'a> {
13961402
ResolverOutputs {
13971403
definitions: self.definitions.clone(),
13981404
cstore: Box::new(self.cstore().clone()),
1405+
visibilities: self.visibilities.clone(),
13991406
extern_crate_map: self.extern_crate_map.clone(),
14001407
export_map: self.export_map.clone(),
14011408
glob_map: self.glob_map.clone(),

‎compiler/rustc_ty/src/ty.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ fn sized_constraint_for_ty<'tcx>(
8080
fn associated_item_from_trait_item_ref(
8181
tcx: TyCtxt<'_>,
8282
parent_def_id: LocalDefId,
83-
parent_vis: &hir::Visibility<'_>,
8483
trait_item_ref: &hir::TraitItemRef,
8584
) -> ty::AssocItem {
8685
let def_id = tcx.hir().local_def_id(trait_item_ref.id.hir_id);
@@ -93,8 +92,7 @@ fn associated_item_from_trait_item_ref(
9392
ty::AssocItem {
9493
ident: trait_item_ref.ident,
9594
kind,
96-
// Visibility of trait items is inherited from their traits.
97-
vis: ty::Visibility::from_hir(parent_vis, trait_item_ref.id.hir_id, tcx),
95+
vis: tcx.visibility(def_id),
9896
defaultness: trait_item_ref.defaultness,
9997
def_id: def_id.to_def_id(),
10098
container: ty::TraitContainer(parent_def_id.to_def_id()),
@@ -117,8 +115,7 @@ fn associated_item_from_impl_item_ref(
117115
ty::AssocItem {
118116
ident: impl_item_ref.ident,
119117
kind,
120-
// Visibility of trait impl items doesn't matter.
121-
vis: ty::Visibility::from_hir(&impl_item_ref.vis, impl_item_ref.id.hir_id, tcx),
118+
vis: tcx.visibility(def_id),
122119
defaultness: impl_item_ref.defaultness,
123120
def_id: def_id.to_def_id(),
124121
container: ty::ImplContainer(parent_def_id.to_def_id()),
@@ -143,12 +140,8 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
143140

144141
hir::ItemKind::Trait(.., ref trait_item_refs) => {
145142
if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.hir_id == id) {
146-
let assoc_item = associated_item_from_trait_item_ref(
147-
tcx,
148-
parent_def_id,
149-
&parent_item.vis,
150-
trait_item_ref,
151-
);
143+
let assoc_item =
144+
associated_item_from_trait_item_ref(tcx, parent_def_id, trait_item_ref);
152145
debug_assert_eq!(assoc_item.def_id, def_id);
153146
return assoc_item;
154147
}

‎compiler/rustc_typeck/src/collect.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ fn convert_variant(
851851
parent_did: LocalDefId,
852852
) -> ty::VariantDef {
853853
let mut seen_fields: FxHashMap<Ident, Span> = Default::default();
854-
let hir_id = tcx.hir().local_def_id_to_hir_id(variant_did.unwrap_or(parent_did));
855854
let fields = def
856855
.fields()
857856
.iter()
@@ -868,11 +867,7 @@ fn convert_variant(
868867
seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span);
869868
}
870869

871-
ty::FieldDef {
872-
did: fid.to_def_id(),
873-
ident: f.ident,
874-
vis: ty::Visibility::from_hir(&f.vis, hir_id, tcx),
875-
}
870+
ty::FieldDef { did: fid.to_def_id(), ident: f.ident, vis: tcx.visibility(fid) }
876871
})
877872
.collect();
878873
let recovered = match def {

‎src/test/ui/error-codes/E0445.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
error[E0445]: private trait `Foo` in public interface
22
--> $DIR/E0445.rs:5:1
33
|
4+
LL | trait Foo {
5+
| --------- `Foo` declared as private
6+
...
47
LL | pub trait Bar : Foo {}
58
| ^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
69

710
error[E0445]: private trait `Foo` in public interface
811
--> $DIR/E0445.rs:7:1
912
|
13+
LL | trait Foo {
14+
| --------- `Foo` declared as private
15+
...
1016
LL | pub struct Bar2<T: Foo>(pub T);
1117
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
1218

1319
error[E0445]: private trait `Foo` in public interface
1420
--> $DIR/E0445.rs:9:1
1521
|
22+
LL | trait Foo {
23+
| --------- `Foo` declared as private
24+
...
1625
LL | pub fn foo<T: Foo> (t: T) {}
1726
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
1827

‎src/test/ui/error-codes/E0446.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0446]: private type `Bar` in public interface
22
--> $DIR/E0446.rs:4:5
33
|
44
LL | struct Bar(u32);
5-
| - `Bar` declared as private
5+
| ---------------- `Bar` declared as private
66
LL |
77
LL | pub fn bar() -> Bar {
88
| ^^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/issues/issue-18389.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>`
22
--> $DIR/issue-18389.rs:7:1
33
|
44
LL | trait Private<P, R> {
5-
| - `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
5+
| ------------------- `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
66
...
77
LL | / pub trait Public: Private<
88
LL | |

‎src/test/ui/issues/issue-30079.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0446]: private type `m2::Priv` in public interface
1212
--> $DIR/issue-30079.rs:18:9
1313
|
1414
LL | struct Priv;
15-
| - `m2::Priv` declared as private
15+
| ------------ `m2::Priv` declared as private
1616
LL | impl ::std::ops::Deref for ::SemiPriv {
1717
LL | type Target = Priv;
1818
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -21,7 +21,7 @@ error[E0446]: private type `m3::Priv` in public interface
2121
--> $DIR/issue-30079.rs:35:9
2222
|
2323
LL | struct Priv;
24-
| - `m3::Priv` declared as private
24+
| ------------ `m3::Priv` declared as private
2525
LL | impl ::SemiPrivTrait for () {
2626
LL | type Assoc = Priv;
2727
| ^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/privacy/private-in-public-assoc-ty.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0446]: private type `Priv` in public interface
22
--> $DIR/private-in-public-assoc-ty.rs:17:9
33
|
44
LL | struct Priv;
5-
| - `Priv` declared as private
5+
| ------------ `Priv` declared as private
66
...
77
LL | type A = Priv;
88
| ^^^^^^^^^^^^^^ can't leak private type
@@ -39,7 +39,7 @@ error[E0446]: private type `Priv` in public interface
3939
--> $DIR/private-in-public-assoc-ty.rs:34:9
4040
|
4141
LL | struct Priv;
42-
| - `Priv` declared as private
42+
| ------------ `Priv` declared as private
4343
...
4444
LL | type Alias4 = Priv;
4545
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -48,7 +48,7 @@ error[E0446]: private type `Priv` in public interface
4848
--> $DIR/private-in-public-assoc-ty.rs:41:9
4949
|
5050
LL | struct Priv;
51-
| - `Priv` declared as private
51+
| ------------ `Priv` declared as private
5252
...
5353
LL | type Alias1 = Priv;
5454
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -57,7 +57,7 @@ error[E0445]: private trait `PrivTr` in public interface
5757
--> $DIR/private-in-public-assoc-ty.rs:44:9
5858
|
5959
LL | trait PrivTr {}
60-
| - `PrivTr` declared as private
60+
| ------------ `PrivTr` declared as private
6161
...
6262
LL | type Exist = impl PrivTr;
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

‎src/test/ui/privacy/private-in-public-lint.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0446]: private type `m1::Priv` in public interface
22
--> $DIR/private-in-public-lint.rs:6:9
33
|
44
LL | struct Priv;
5-
| - `m1::Priv` declared as private
5+
| ------------ `m1::Priv` declared as private
66
...
77
LL | pub fn f() -> Priv {Priv}
88
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -11,7 +11,7 @@ error[E0446]: private type `m2::Priv` in public interface
1111
--> $DIR/private-in-public-lint.rs:15:9
1212
|
1313
LL | struct Priv;
14-
| - `m2::Priv` declared as private
14+
| ------------ `m2::Priv` declared as private
1515
...
1616
LL | pub fn f() -> Priv {Priv}
1717
| ^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/privacy/private-in-public-warn.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ error[E0446]: private type `types::Priv` in public interface
4343
--> $DIR/private-in-public-warn.rs:26:9
4444
|
4545
LL | struct Priv;
46-
| - `types::Priv` declared as private
46+
| ------------ `types::Priv` declared as private
4747
...
4848
LL | type Alias = Priv;
4949
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -97,7 +97,7 @@ error[E0446]: private type `types::Priv` in public interface
9797
--> $DIR/private-in-public-warn.rs:41:9
9898
|
9999
LL | struct Priv;
100-
| - `types::Priv` declared as private
100+
| ------------ `types::Priv` declared as private
101101
...
102102
LL | type Alias = Priv;
103103
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -250,7 +250,7 @@ error[E0446]: private type `impls::Priv` in public interface
250250
--> $DIR/private-in-public-warn.rs:135:9
251251
|
252252
LL | struct Priv;
253-
| - `impls::Priv` declared as private
253+
| ------------ `impls::Priv` declared as private
254254
...
255255
LL | type Alias = Priv;
256256
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -268,7 +268,7 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
268268
--> $DIR/private-in-public-warn.rs:210:9
269269
|
270270
LL | struct Priv;
271-
| - `aliases_pub::Priv` declared as private
271+
| ------------ `aliases_pub::Priv` declared as private
272272
...
273273
LL | type Check = Priv;
274274
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -277,7 +277,7 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
277277
--> $DIR/private-in-public-warn.rs:213:9
278278
|
279279
LL | struct Priv;
280-
| - `aliases_pub::Priv` declared as private
280+
| ------------ `aliases_pub::Priv` declared as private
281281
...
282282
LL | type Check = Priv;
283283
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -286,7 +286,7 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
286286
--> $DIR/private-in-public-warn.rs:216:9
287287
|
288288
LL | struct Priv;
289-
| - `aliases_pub::Priv` declared as private
289+
| ------------ `aliases_pub::Priv` declared as private
290290
...
291291
LL | type Check = Priv;
292292
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -295,7 +295,7 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
295295
--> $DIR/private-in-public-warn.rs:219:9
296296
|
297297
LL | struct Priv;
298-
| - `aliases_pub::Priv` declared as private
298+
| ------------ `aliases_pub::Priv` declared as private
299299
...
300300
LL | type Check = Priv;
301301
| ^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/privacy/private-in-public.stderr

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0446]: private type `types::Priv` in public interface
22
--> $DIR/private-in-public.rs:13:5
33
|
44
LL | struct Priv;
5-
| - `types::Priv` declared as private
5+
| ------------ `types::Priv` declared as private
66
...
77
LL | pub const C: Priv = Priv;
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -11,7 +11,7 @@ error[E0446]: private type `types::Priv` in public interface
1111
--> $DIR/private-in-public.rs:14:5
1212
|
1313
LL | struct Priv;
14-
| - `types::Priv` declared as private
14+
| ------------ `types::Priv` declared as private
1515
...
1616
LL | pub static S: Priv = Priv;
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -20,7 +20,7 @@ error[E0446]: private type `types::Priv` in public interface
2020
--> $DIR/private-in-public.rs:15:5
2121
|
2222
LL | struct Priv;
23-
| - `types::Priv` declared as private
23+
| ------------ `types::Priv` declared as private
2424
...
2525
LL | pub fn f1(arg: Priv) {}
2626
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -29,7 +29,7 @@ error[E0446]: private type `types::Priv` in public interface
2929
--> $DIR/private-in-public.rs:16:5
3030
|
3131
LL | struct Priv;
32-
| - `types::Priv` declared as private
32+
| ------------ `types::Priv` declared as private
3333
...
3434
LL | pub fn f2() -> Priv { panic!() }
3535
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -38,7 +38,7 @@ error[E0446]: private type `types::Priv` in public interface
3838
--> $DIR/private-in-public.rs:17:19
3939
|
4040
LL | struct Priv;
41-
| - `types::Priv` declared as private
41+
| ------------ `types::Priv` declared as private
4242
...
4343
LL | pub struct S1(pub Priv);
4444
| ^^^^^^^^ can't leak private type
@@ -47,7 +47,7 @@ error[E0446]: private type `types::Priv` in public interface
4747
--> $DIR/private-in-public.rs:18:21
4848
|
4949
LL | struct Priv;
50-
| - `types::Priv` declared as private
50+
| ------------ `types::Priv` declared as private
5151
...
5252
LL | pub struct S2 { pub field: Priv }
5353
| ^^^^^^^^^^^^^^^ can't leak private type
@@ -56,7 +56,7 @@ error[E0446]: private type `types::Priv` in public interface
5656
--> $DIR/private-in-public.rs:20:9
5757
|
5858
LL | struct Priv;
59-
| - `types::Priv` declared as private
59+
| ------------ `types::Priv` declared as private
6060
...
6161
LL | pub const C: Priv = Priv;
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -65,7 +65,7 @@ error[E0446]: private type `types::Priv` in public interface
6565
--> $DIR/private-in-public.rs:21:9
6666
|
6767
LL | struct Priv;
68-
| - `types::Priv` declared as private
68+
| ------------ `types::Priv` declared as private
6969
...
7070
LL | pub fn f1(arg: Priv) {}
7171
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -74,7 +74,7 @@ error[E0446]: private type `types::Priv` in public interface
7474
--> $DIR/private-in-public.rs:22:9
7575
|
7676
LL | struct Priv;
77-
| - `types::Priv` declared as private
77+
| ------------ `types::Priv` declared as private
7878
...
7979
LL | pub fn f2() -> Priv { panic!() }
8080
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -83,7 +83,7 @@ error[E0445]: private trait `traits::PrivTr` in public interface
8383
--> $DIR/private-in-public.rs:31:5
8484
|
8585
LL | trait PrivTr {}
86-
| - `traits::PrivTr` declared as private
86+
| ------------ `traits::PrivTr` declared as private
8787
...
8888
LL | pub enum E<T: PrivTr> { V(T) }
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -92,7 +92,7 @@ error[E0445]: private trait `traits::PrivTr` in public interface
9292
--> $DIR/private-in-public.rs:32:5
9393
|
9494
LL | trait PrivTr {}
95-
| - `traits::PrivTr` declared as private
95+
| ------------ `traits::PrivTr` declared as private
9696
...
9797
LL | pub fn f<T: PrivTr>(arg: T) {}
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -101,7 +101,7 @@ error[E0445]: private trait `traits::PrivTr` in public interface
101101
--> $DIR/private-in-public.rs:33:5
102102
|
103103
LL | trait PrivTr {}
104-
| - `traits::PrivTr` declared as private
104+
| ------------ `traits::PrivTr` declared as private
105105
...
106106
LL | pub struct S1<T: PrivTr>(T);
107107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -110,7 +110,7 @@ error[E0445]: private trait `traits::PrivTr` in public interface
110110
--> $DIR/private-in-public.rs:34:5
111111
|
112112
LL | trait PrivTr {}
113-
| - `traits::PrivTr` declared as private
113+
| ------------ `traits::PrivTr` declared as private
114114
...
115115
LL | / impl<T: PrivTr> Pub<T> {
116116
LL | | pub fn f<U: PrivTr>(arg: U) {}
@@ -121,7 +121,7 @@ error[E0445]: private trait `traits::PrivTr` in public interface
121121
--> $DIR/private-in-public.rs:35:9
122122
|
123123
LL | trait PrivTr {}
124-
| - `traits::PrivTr` declared as private
124+
| ------------ `traits::PrivTr` declared as private
125125
...
126126
LL | pub fn f<U: PrivTr>(arg: U) {}
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -130,7 +130,7 @@ error[E0445]: private trait `traits_where::PrivTr` in public interface
130130
--> $DIR/private-in-public.rs:44:5
131131
|
132132
LL | trait PrivTr {}
133-
| - `traits_where::PrivTr` declared as private
133+
| ------------ `traits_where::PrivTr` declared as private
134134
...
135135
LL | pub enum E<T> where T: PrivTr { V(T) }
136136
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -139,7 +139,7 @@ error[E0445]: private trait `traits_where::PrivTr` in public interface
139139
--> $DIR/private-in-public.rs:46:5
140140
|
141141
LL | trait PrivTr {}
142-
| - `traits_where::PrivTr` declared as private
142+
| ------------ `traits_where::PrivTr` declared as private
143143
...
144144
LL | pub fn f<T>(arg: T) where T: PrivTr {}
145145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -148,7 +148,7 @@ error[E0445]: private trait `traits_where::PrivTr` in public interface
148148
--> $DIR/private-in-public.rs:48:5
149149
|
150150
LL | trait PrivTr {}
151-
| - `traits_where::PrivTr` declared as private
151+
| ------------ `traits_where::PrivTr` declared as private
152152
...
153153
LL | pub struct S1<T>(T) where T: PrivTr;
154154
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -157,7 +157,7 @@ error[E0445]: private trait `traits_where::PrivTr` in public interface
157157
--> $DIR/private-in-public.rs:50:5
158158
|
159159
LL | trait PrivTr {}
160-
| - `traits_where::PrivTr` declared as private
160+
| ------------ `traits_where::PrivTr` declared as private
161161
...
162162
LL | / impl<T> Pub<T> where T: PrivTr {
163163
LL | |
@@ -170,7 +170,7 @@ error[E0445]: private trait `traits_where::PrivTr` in public interface
170170
--> $DIR/private-in-public.rs:52:9
171171
|
172172
LL | trait PrivTr {}
173-
| - `traits_where::PrivTr` declared as private
173+
| ------------ `traits_where::PrivTr` declared as private
174174
...
175175
LL | pub fn f<U>(arg: U) where U: PrivTr {}
176176
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -179,7 +179,7 @@ error[E0446]: private type `generics::Priv` in public interface
179179
--> $DIR/private-in-public.rs:63:5
180180
|
181181
LL | struct Priv<T = u8>(T);
182-
| - `generics::Priv` declared as private
182+
| ----------------------- `generics::Priv` declared as private
183183
...
184184
LL | pub fn f1(arg: [Priv; 1]) {}
185185
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -188,7 +188,7 @@ error[E0446]: private type `generics::Priv` in public interface
188188
--> $DIR/private-in-public.rs:64:5
189189
|
190190
LL | struct Priv<T = u8>(T);
191-
| - `generics::Priv` declared as private
191+
| ----------------------- `generics::Priv` declared as private
192192
...
193193
LL | pub fn f2(arg: Pub<Priv>) {}
194194
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -197,7 +197,7 @@ error[E0446]: private type `generics::Priv<generics::Pub>` in public interface
197197
--> $DIR/private-in-public.rs:65:5
198198
|
199199
LL | struct Priv<T = u8>(T);
200-
| - `generics::Priv<generics::Pub>` declared as private
200+
| ----------------------- `generics::Priv<generics::Pub>` declared as private
201201
...
202202
LL | pub fn f3(arg: Priv<Pub>) {}
203203
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -206,7 +206,7 @@ error[E0446]: private type `impls::Priv` in public interface
206206
--> $DIR/private-in-public.rs:80:9
207207
|
208208
LL | struct Priv;
209-
| - `impls::Priv` declared as private
209+
| ------------ `impls::Priv` declared as private
210210
...
211211
LL | pub fn f(arg: Priv) {}
212212
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -215,7 +215,7 @@ error[E0445]: private trait `aliases_pub::PrivTr` in public interface
215215
--> $DIR/private-in-public.rs:104:5
216216
|
217217
LL | trait PrivTr {
218-
| - `aliases_pub::PrivTr` declared as private
218+
| ------------ `aliases_pub::PrivTr` declared as private
219219
...
220220
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
221221
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -224,7 +224,7 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
224224
--> $DIR/private-in-public.rs:104:5
225225
|
226226
LL | struct Priv;
227-
| - `aliases_pub::Priv` declared as private
227+
| ------------ `aliases_pub::Priv` declared as private
228228
...
229229
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
230230
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -233,7 +233,7 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
233233
--> $DIR/private-in-public.rs:109:9
234234
|
235235
LL | struct Priv;
236-
| - `aliases_pub::Priv` declared as private
236+
| ------------ `aliases_pub::Priv` declared as private
237237
...
238238
LL | pub fn f(arg: Priv) {}
239239
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -242,7 +242,7 @@ error[E0446]: private type `Priv1` in public interface
242242
--> $DIR/private-in-public.rs:131:5
243243
|
244244
LL | struct Priv1;
245-
| - `Priv1` declared as private
245+
| ------------- `Priv1` declared as private
246246
...
247247
LL | pub fn f1(arg: PrivUseAlias) {}
248248
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -251,7 +251,7 @@ error[E0446]: private type `Priv2` in public interface
251251
--> $DIR/private-in-public.rs:132:5
252252
|
253253
LL | struct Priv2;
254-
| - `Priv2` declared as private
254+
| ------------- `Priv2` declared as private
255255
...
256256
LL | pub fn f2(arg: PrivAlias) {}
257257
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -260,7 +260,7 @@ error[E0445]: private trait `aliases_priv::PrivTr` in public interface
260260
--> $DIR/private-in-public.rs:133:5
261261
|
262262
LL | trait PrivTr {
263-
| - `aliases_priv::PrivTr` declared as private
263+
| ------------ `aliases_priv::PrivTr` declared as private
264264
...
265265
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
266266
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
@@ -269,7 +269,7 @@ error[E0446]: private type `aliases_priv::Priv` in public interface
269269
--> $DIR/private-in-public.rs:133:5
270270
|
271271
LL | struct Priv;
272-
| - `aliases_priv::Priv` declared as private
272+
| ------------ `aliases_priv::Priv` declared as private
273273
...
274274
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
275275
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -278,7 +278,7 @@ error[E0446]: private type `aliases_params::Priv` in public interface
278278
--> $DIR/private-in-public.rs:143:5
279279
|
280280
LL | struct Priv;
281-
| - `aliases_params::Priv` declared as private
281+
| ------------ `aliases_params::Priv` declared as private
282282
...
283283
LL | pub fn f2(arg: PrivAliasGeneric) {}
284284
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -287,7 +287,7 @@ error[E0446]: private type `aliases_params::Priv` in public interface
287287
--> $DIR/private-in-public.rs:145:5
288288
|
289289
LL | struct Priv;
290-
| - `aliases_params::Priv` declared as private
290+
| ------------ `aliases_params::Priv` declared as private
291291
...
292292
LL | pub fn f3(arg: Result<u8>) {}
293293
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/privacy/private-inferred-type.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0446]: private type `Priv` in public interface
22
--> $DIR/private-inferred-type.rs:61:36
33
|
44
LL | struct Priv;
5-
| - `Priv` declared as private
5+
| ------------ `Priv` declared as private
66
...
77
LL | impl TraitWithAssocTy for u8 { type AssocTy = Priv; }
88
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -11,7 +11,7 @@ error[E0446]: private type `S2` in public interface
1111
--> $DIR/private-inferred-type.rs:83:9
1212
|
1313
LL | struct S2;
14-
| - `S2` declared as private
14+
| ---------- `S2` declared as private
1515
...
1616
LL | type Target = S2Alias;
1717
| ^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/privacy/restricted/private-in-public.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0446]: private type `Priv` in public interface
22
--> $DIR/private-in-public.rs:8:9
33
|
44
LL | struct Priv;
5-
| - `Priv` declared as private
5+
| ------------ `Priv` declared as private
66
...
77
LL | pub(crate) fn g(_: Priv) {}
88
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -11,7 +11,7 @@ error[E0446]: private type `Priv` in public interface
1111
--> $DIR/private-in-public.rs:9:9
1212
|
1313
LL | struct Priv;
14-
| - `Priv` declared as private
14+
| ------------ `Priv` declared as private
1515
...
1616
LL | crate fn h(_: Priv) {}
1717
| ^^^^^^^^^^^^^^^^^^^ can't leak private type

‎src/test/ui/proc-macro/issue-50493.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#[macro_use]
44
extern crate issue_50493;
55

6-
#[derive(Derive)] //~ ERROR field `field` of struct `Restricted` is private
7-
//~| ERROR field `field` of struct `Restricted` is private
6+
#[derive(Derive)]
87
struct Restricted {
98
pub(in restricted) field: usize, //~ visibilities can only be restricted to ancestor modules
109
}
Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
error[E0742]: visibilities can only be restricted to ancestor modules
2-
--> $DIR/issue-50493.rs:9:12
2+
--> $DIR/issue-50493.rs:8:12
33
|
44
LL | pub(in restricted) field: usize,
55
| ^^^^^^^^^^
66

7-
error[E0616]: field `field` of struct `Restricted` is private
8-
--> $DIR/issue-50493.rs:6:10
9-
|
10-
LL | #[derive(Derive)]
11-
| ^^^^^^ private field
12-
|
13-
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
14-
15-
error[E0616]: field `field` of struct `Restricted` is private
16-
--> $DIR/issue-50493.rs:6:10
17-
|
18-
LL | #[derive(Derive)]
19-
| ^^^^^^ private field
20-
|
21-
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
22-
23-
error: aborting due to 3 previous errors
7+
error: aborting due to previous error
248

25-
Some errors have detailed explanations: E0616, E0742.
26-
For more information about an error, try `rustc --explain E0616`.
9+
For more information about this error, try `rustc --explain E0742`.

‎src/test/ui/pub/issue-33174-restricted-type-in-public-interface.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#![allow(non_camel_case_types)] // genus is always capitalized
1+
#![allow(non_camel_case_types)] // genus is always capitalized
22

33
pub(crate) struct Snail;
4-
//~^ NOTE `Snail` declared as crate-visible
4+
//~^ NOTE `Snail` declared as private
55

66
mod sea {
77
pub(super) struct Turtle;
8-
//~^ NOTE `Turtle` declared as restricted
8+
//~^ NOTE `Turtle` declared as crate-private
99
}
1010

1111
struct Tortoise;
@@ -16,11 +16,11 @@ pub struct Shell<T> {
1616
}
1717

1818
pub type Helix_pomatia = Shell<Snail>;
19-
//~^ ERROR crate-visible type `Snail` in public interface
20-
//~| NOTE can't leak crate-visible type
19+
//~^ ERROR private type `Snail` in public interface
20+
//~| NOTE can't leak private type
2121
pub type Dermochelys_coriacea = Shell<sea::Turtle>;
22-
//~^ ERROR restricted type `Turtle` in public interface
23-
//~| NOTE can't leak restricted type
22+
//~^ ERROR crate-private type `Turtle` in public interface
23+
//~| NOTE can't leak crate-private type
2424
pub type Testudo_graeca = Shell<Tortoise>;
2525
//~^ ERROR private type `Tortoise` in public interface
2626
//~| NOTE can't leak private type

‎src/test/ui/pub/issue-33174-restricted-type-in-public-interface.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
error[E0446]: crate-visible type `Snail` in public interface
1+
error[E0446]: private type `Snail` in public interface
22
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:18:1
33
|
44
LL | pub(crate) struct Snail;
5-
| ---------- `Snail` declared as crate-visible
5+
| ------------------------ `Snail` declared as private
66
...
77
LL | pub type Helix_pomatia = Shell<Snail>;
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-visible type
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
99

10-
error[E0446]: restricted type `Turtle` in public interface
10+
error[E0446]: crate-private type `Turtle` in public interface
1111
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:21:1
1212
|
1313
LL | pub(super) struct Turtle;
14-
| ---------- `Turtle` declared as restricted
14+
| ------------------------- `Turtle` declared as crate-private
1515
...
1616
LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>;
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak restricted type
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-private type
1818

1919
error[E0446]: private type `Tortoise` in public interface
2020
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:24:1
2121
|
2222
LL | struct Tortoise;
23-
| - `Tortoise` declared as private
23+
| ---------------- `Tortoise` declared as private
2424
...
2525
LL | pub type Testudo_graeca = Shell<Tortoise>;
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

0 commit comments

Comments
 (0)
This repository has been archived.