diff options
| author | Bryanskiy <ivakin.kir@gmail.com> | 2022-09-25 14:25:02 +0300 |
|---|---|---|
| committer | Bryanskiy <ivakin.kir@gmail.com> | 2022-10-16 21:47:14 +0300 |
| commit | 496ccd982ce155d8f4026eb69c6af1a2b6b5628a (patch) | |
| tree | 8f395156d2a217211f9959f6d4d74aaf8590cd2f /src | |
| parent | e20fabb0d04cb25fe3159d58920856533f1b5cf0 (diff) | |
| download | rust-496ccd982ce155d8f4026eb69c6af1a2b6b5628a.tar.gz rust-496ccd982ce155d8f4026eb69c6af1a2b6b5628a.zip | |
Populate effective visibilities in 'rustc_resolve'
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/visit_lib.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/privacy/access_levels.rs | 33 | ||||
| -rw-r--r-- | src/test/ui/privacy/access_levels.stderr | 40 |
4 files changed, 46 insertions, 45 deletions
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index e6cef4a326a..b8522ea5d8f 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -8,7 +8,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::Node; use rustc_hir::CRATE_HIR_ID; use rustc_middle::middle::privacy::AccessLevel; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{TyCtxt, Visibility}; use rustc_span::def_id::{CRATE_DEF_ID, LOCAL_CRATE}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; @@ -230,7 +230,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } else { // All items need to be handled here in case someone wishes to link // to them with intra-doc links - self.cx.cache.access_levels.set_access_level(did, AccessLevel::Public); + self.cx.cache.access_levels.set_access_level( + did, + || Visibility::Restricted(CRATE_DEF_ID), + AccessLevel::Public, + ); } } } diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 8221e0998d7..0511494668b 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -1,8 +1,8 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_ID}; use rustc_middle::middle::privacy::{AccessLevel, AccessLevels}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{TyCtxt, Visibility}; // FIXME: this may not be exhaustive, but is sufficient for rustdocs current uses @@ -41,7 +41,11 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> { let old_level = self.access_levels.get_access_level(did); // Accessibility levels can only grow if level > old_level && !is_hidden { - self.access_levels.set_access_level(did, level.unwrap()); + self.access_levels.set_access_level( + did, + || Visibility::Restricted(CRATE_DEF_ID), + level.unwrap(), + ); level } else { old_level diff --git a/src/test/ui/privacy/access_levels.rs b/src/test/ui/privacy/access_levels.rs index bf94d980678..cc074a4f958 100644 --- a/src/test/ui/privacy/access_levels.rs +++ b/src/test/ui/privacy/access_levels.rs @@ -1,44 +1,44 @@ #![feature(rustc_attrs)] #[rustc_effective_visibility] -mod outer { //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) +mod outer { //~ ERROR Public: pub(crate), Exported: pub(crate), Reachable: pub(crate), ReachableFromImplTrait: pub(crate) #[rustc_effective_visibility] - pub mod inner1 { //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + pub mod inner1 { //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - extern "C" {} //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + extern "C" {} //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - pub trait PubTrait { //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + pub trait PubTrait { //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - const A: i32; //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + const A: i32; //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - type B; //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + type B; //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub } #[rustc_effective_visibility] struct PrivStruct; //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) #[rustc_effective_visibility] - pub union PubUnion { //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + pub union PubUnion { //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] a: u8, //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) #[rustc_effective_visibility] - pub b: u8, //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + pub b: u8, //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub } #[rustc_effective_visibility] - pub enum Enum { //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + pub enum Enum { //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - A( //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + A( //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - PubUnion, //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + PubUnion, //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub ), } } #[rustc_effective_visibility] - macro_rules! none_macro { //~ Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) + macro_rules! none_macro { //~ Public: pub(crate), Exported: pub(crate), Reachable: pub(crate), ReachableFromImplTrait: pub(crate) () => {}; } @@ -49,9 +49,9 @@ mod outer { //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(sel } #[rustc_effective_visibility] - pub struct ReachableStruct { //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub, ReachableFromImplTrait: pub + pub struct ReachableStruct { //~ ERROR Public: pub(crate), Exported: pub(crate), Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] - pub a: u8, //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub, ReachableFromImplTrait: pub + pub a: u8, //~ ERROR Public: pub(crate), Exported: pub(crate), Reachable: pub, ReachableFromImplTrait: pub } } @@ -62,14 +62,13 @@ pub fn foo() -> outer::ReachableStruct { outer::ReachableStruct {a: 0} } mod half_public_import { #[rustc_effective_visibility] - pub type HalfPublicImport = u8; //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub + pub type HalfPublicImport = u8; //~ ERROR Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub #[rustc_effective_visibility] #[allow(non_upper_case_globals)] - pub(crate) const HalfPublicImport: u8 = 0; //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) + pub(crate) const HalfPublicImport: u8 = 0; //~ ERROR Public: pub(crate), Exported: pub(crate), Reachable: pub(crate), ReachableFromImplTrait: pub(crate) } #[rustc_effective_visibility] pub use half_public_import::HalfPublicImport; //~ ERROR Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub - //~^ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) fn main() {} diff --git a/src/test/ui/privacy/access_levels.stderr b/src/test/ui/privacy/access_levels.stderr index 81514d1fbab..19199a3eb87 100644 --- a/src/test/ui/privacy/access_levels.stderr +++ b/src/test/ui/privacy/access_levels.stderr @@ -1,22 +1,22 @@ -error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) +error: Public: pub(crate), Exported: pub(crate), Reachable: pub(crate), ReachableFromImplTrait: pub(crate) --> $DIR/access_levels.rs:4:1 | LL | mod outer { | ^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:6:5 | LL | pub mod inner1 { | ^^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:9:9 | LL | extern "C" {} | ^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:12:9 | LL | pub trait PubTrait { @@ -28,7 +28,7 @@ error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFr LL | struct PrivStruct; | ^^^^^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:23:9 | LL | pub union PubUnion { @@ -40,31 +40,31 @@ error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFr LL | a: u8, | ^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:27:13 | LL | pub b: u8, | ^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:31:9 | LL | pub enum Enum { | ^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:33:13 | LL | A( | ^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:35:17 | LL | PubUnion, | ^^^^^^^^ -error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) +error: Public: pub(crate), Exported: pub(crate), Reachable: pub(crate), ReachableFromImplTrait: pub(crate) --> $DIR/access_levels.rs:41:5 | LL | macro_rules! none_macro { @@ -76,13 +76,13 @@ error: Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub LL | macro_rules! public_macro { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub(self), Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub(crate), Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:52:5 | LL | pub struct ReachableStruct { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub(self), Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub(crate), Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:54:9 | LL | pub a: u8, @@ -94,13 +94,13 @@ error: Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub LL | pub use outer::inner1; | ^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:65:5 | LL | pub type HalfPublicImport = u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) +error: Public: pub(crate), Exported: pub(crate), Reachable: pub(crate), ReachableFromImplTrait: pub(crate) --> $DIR/access_levels.rs:68:5 | LL | pub(crate) const HalfPublicImport: u8 = 0; @@ -112,23 +112,17 @@ error: Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub LL | pub use half_public_import::HalfPublicImport; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self) - --> $DIR/access_levels.rs:72:9 - | -LL | pub use half_public_import::HalfPublicImport; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:14:13 | LL | const A: i32; | ^^^^^^^^^^^^ -error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub +error: Public: pub(crate), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub --> $DIR/access_levels.rs:16:13 | LL | type B; | ^^^^^^ -error: aborting due to 22 previous errors +error: aborting due to 21 previous errors |
