Skip to content

Commit 74adeda

Browse files
committed
Rollup merge of rust-lang#23400 - nrc:pub_use, r=eddyb
r? @eddyb
2 parents 285cb8e + 1fd38c1 commit 74adeda

15 files changed

+1177
-1103
lines changed

src/doc/reference.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1961,16 +1961,18 @@ module through the rules above. It essentially allows public access into the
19611961
re-exported item. For example, this program is valid:
19621962

19631963
```
1964-
pub use self::implementation as api;
1964+
pub use self::implementation::api;
19651965
19661966
mod implementation {
1967-
pub fn f() {}
1967+
pub mod api {
1968+
pub fn f() {}
1969+
}
19681970
}
19691971
19701972
# fn main() {}
19711973
```
19721974

1973-
This means that any external crate referencing `implementation::f` would
1975+
This means that any external crate referencing `implementation::api::f` would
19741976
receive a privacy violation, while the path `api::f` would be allowed.
19751977

19761978
When re-exporting a private item, it can be thought of as allowing the "privacy

src/librustc_resolve/build_reduced_graph.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
//! any imports resolved.
1515
1616
use {DefModifiers, PUBLIC, IMPORTABLE};
17-
use ImportDirective;
18-
use ImportDirectiveSubclass::{self, SingleImport, GlobImport};
19-
use ImportResolution;
17+
use resolve_imports::ImportDirective;
18+
use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
19+
use resolve_imports::ImportResolution;
2020
use Module;
2121
use ModuleKind::*;
2222
use Namespace::{TypeNS, ValueNS};
2323
use NameBindings;
24+
use {names_to_string, module_to_string};
2425
use ParentLink::{self, ModuleParentLink, BlockParentLink};
2526
use Resolver;
26-
use Shadowable;
27+
use resolve_imports::Shadowable;
2728
use TypeNsDef;
2829

2930
use self::DuplicateCheckingMode::*;
@@ -371,8 +372,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
371372

372373
ItemExternCrate(_) => {
373374
// n.b. we don't need to look at the path option here, because cstore already did
374-
for &crate_id in self.session.cstore
375-
.find_extern_mod_stmt_cnum(item.id).iter() {
375+
if let Some(crate_id) = self.session.cstore.find_extern_mod_stmt_cnum(item.id) {
376376
let def_id = DefId { krate: crate_id, node: 0 };
377377
self.external_exports.insert(def_id);
378378
let parent_link = ModuleParentLink(parent.downgrade(), name);
@@ -382,7 +382,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
382382
false,
383383
true));
384384
debug!("(build reduced graph for item) found extern `{}`",
385-
self.module_to_string(&*external_module));
385+
module_to_string(&*external_module));
386386
self.check_for_conflicts_between_external_crates(&**parent, name, sp);
387387
parent.external_module_children.borrow_mut()
388388
.insert(name, external_module.clone());
@@ -400,7 +400,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
400400
Some(def_id),
401401
NormalModuleKind,
402402
false,
403-
item.vis == ast::Public,
403+
is_public,
404404
sp);
405405

406406
name_bindings.get_module()
@@ -432,8 +432,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
432432
// These items live in the type namespace.
433433
ItemTy(..) => {
434434
let name_bindings =
435-
self.add_child(name, parent, ForbidDuplicateTypesAndModules,
436-
sp);
435+
self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
437436

438437
name_bindings.define_type(DefTy(local_def(item.id), false), sp,
439438
modifiers);
@@ -517,7 +516,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
517516
Some(local_def(item.id)),
518517
TraitModuleKind,
519518
false,
520-
item.vis == ast::Public,
519+
is_public,
521520
sp);
522521
let module_parent = name_bindings.get_module();
523522

@@ -636,8 +635,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
636635
name: Name,
637636
new_parent: &Rc<Module>) {
638637
debug!("(building reduced graph for \
639-
external crate) building external def, priv {:?}",
640-
vis);
638+
external crate) building external def {}, priv {:?}",
639+
final_ident, vis);
641640
let is_public = vis == ast::Public;
642641
let modifiers = if is_public { PUBLIC } else { DefModifiers::empty() } | IMPORTABLE;
643642
let is_exported = is_public && match new_parent.def_id.get() {
@@ -667,7 +666,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
667666
Some(_) | None => {
668667
debug!("(building reduced graph for \
669668
external crate) building module \
670-
{}", final_ident);
669+
{} {}", final_ident, is_public);
671670
let parent_link = self.get_parent_link(new_parent, name);
672671

673672
child_name_bindings.define_module(parent_link,
@@ -838,7 +837,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
838837
/// Builds the reduced graph rooted at the given external module.
839838
fn populate_external_module(&mut self, module: &Rc<Module>) {
840839
debug!("(populating external module) attempting to populate {}",
841-
self.module_to_string(&**module));
840+
module_to_string(&**module));
842841

843842
let def_id = match module.def_id.get() {
844843
None => {
@@ -904,18 +903,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
904903

905904
match subclass {
906905
SingleImport(target, _) => {
907-
debug!("(building import directive) building import \
908-
directive: {}::{}",
909-
self.names_to_string(&module_.imports.borrow().last().unwrap().
910-
module_path),
906+
debug!("(building import directive) building import directive: {}::{}",
907+
names_to_string(&module_.imports.borrow().last().unwrap().module_path),
911908
token::get_name(target));
912909

913-
let mut import_resolutions = module_.import_resolutions
914-
.borrow_mut();
910+
let mut import_resolutions = module_.import_resolutions.borrow_mut();
915911
match import_resolutions.get_mut(&target) {
916912
Some(resolution) => {
917-
debug!("(building import directive) bumping \
918-
reference");
913+
debug!("(building import directive) bumping reference");
919914
resolution.outstanding_references += 1;
920915

921916
// the source of this name is different now

src/librustc_resolve/diagnostics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ register_diagnostics! {
2424
E0258, // import conflicts with existing submodule
2525
E0259, // an extern crate has already been imported into this module
2626
E0260, // name conflicts with an external crate that has been imported into this module
27-
E0317 // user-defined types or type parameters cannot shadow the primitive types
27+
E0317, // user-defined types or type parameters cannot shadow the primitive types
28+
E0364, // item is private
29+
E0365 // item is private
2830
}
2931

3032
__build_diagnostic_array! { DIAGNOSTICS }

0 commit comments

Comments
 (0)