| 1 | use synrust-analyzer cargo syn 1.0.109 crate/::{parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/, Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility#}; |
| 2 | |
| 3 | // If `vis` describes a visibility relative to some module scope, returns the |
| 4 | // same visibility as described from a module contained within that scope. |
| 5 | // |
| 6 | // quote! { |
| 7 | // #vis #A; |
| 8 | // mod #name { |
| 9 | // // Same visibility as super::A. |
| 10 | // #vis_super #B; |
| 11 | // } |
| 12 | // } |
| 13 | // |
| 14 | // Note if you are considering copying this implementation into another crate: |
| 15 | // please try not to. Visibilities in Rust are confusing and subtle, especially |
| 16 | // around visibility specifiers of items declared inside of a function body. |
| 17 | // This function is not a robust implementation of the transformation that it |
| 18 | // claims to implement. Always first try to restructure your code to avoid |
| 19 | // needing this logic. |
| 20 | pub fn vis_superrust-analyzer cargo ghost 0.1.5 visibility/vis_super().(vis: &Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility#) -> Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility# { |
| 21 | match vis { |
| 22 | Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility#::Publicrust-analyzer cargo syn 1.0.109 data/Visibility#Public#(vis) => { |
| 23 | // pub -> pub |
| 24 | parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/parse_quote!!(#vis) |
| 25 | } |
| 26 | Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility#::Craterust-analyzer cargo syn 1.0.109 data/Visibility#Crate#(vis) => { |
| 27 | // crate -> crate |
| 28 | parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/parse_quote!!(#vis) |
| 29 | } |
| 30 | Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility#::Restrictedrust-analyzer cargo syn 1.0.109 data/Visibility#Restricted#(vis) => { |
| 31 | if vis.pathrust-analyzer cargo syn 1.0.109 data/VisRestricted#path..segmentsrust-analyzer cargo syn 1.0.109 path/Path#segments.[rust-analyzer cargo syn 1.0.109 punctuated/impl#[`Punctuated<T, P>`][`Index<usize>`]index().0]rust-analyzer cargo syn 1.0.109 punctuated/impl#[`Punctuated<T, P>`][`Index<usize>`]index()..identrust-analyzer cargo syn 1.0.109 path/PathSegment#ident. rust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][`PartialEq<T>`]eq().==rust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][`PartialEq<T>`]eq(). rust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][`PartialEq<T>`]eq()."self" { |
| 32 | // pub(self) -> pub(in super) |
| 33 | // pub(in self::super) -> pub(in super::super) |
| 34 | let path = vis.pathrust-analyzer cargo syn 1.0.109 data/VisRestricted#path..segmentsrust-analyzer cargo syn 1.0.109 path/Path#segments..iterrust-analyzer cargo syn 1.0.109 punctuated/impl#[`Punctuated<T, P>`]iter().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1); |
| 35 | parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/parse_quote!!(pub(in super #(::#path)*)) |
| 36 | } else if vis.pathrust-analyzer cargo syn 1.0.109 data/VisRestricted#path..segmentsrust-analyzer cargo syn 1.0.109 path/Path#segments.[rust-analyzer cargo syn 1.0.109 punctuated/impl#[`Punctuated<T, P>`][`Index<usize>`]index().0]rust-analyzer cargo syn 1.0.109 punctuated/impl#[`Punctuated<T, P>`][`Index<usize>`]index()..identrust-analyzer cargo syn 1.0.109 path/PathSegment#ident. rust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][`PartialEq<T>`]eq().==rust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][`PartialEq<T>`]eq(). rust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][`PartialEq<T>`]eq()."super" { |
| 37 | // pub(super) -> pub(in super::super) |
| 38 | // pub(in super::super) -> pub(in super::super::super) |
| 39 | let path = &vis.pathrust-analyzer cargo syn 1.0.109 data/VisRestricted#path.; |
| 40 | parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/parse_quote!!(pub(in super::#path)) |
| 41 | } else { |
| 42 | // pub(crate) -> pub(crate) |
| 43 | // pub(in crate::path) -> pub(in crate::path) |
| 44 | parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/parse_quote!!(#vis) |
| 45 | } |
| 46 | } |
| 47 | Visibilityrust-analyzer cargo syn 1.0.109 data/Visibility#::Inheritedrust-analyzer cargo syn 1.0.109 data/Visibility#Inherited# => { |
| 48 | // private -> pub(super) |
| 49 | parse_quoterust-analyzer cargo syn 1.0.109 parse_quote/parse_quote!!(pub(super)) |
| 50 | } |
| 51 | } |
| 52 | } |