/// Return the visibility that should be used for expectation!, given the
/// original method's visibility.
///
/// # Arguments
/// - `vis`:    Original visibility of the item
/// - `levels`: How many modules will the mock item be nested in?
Return the visibility that should be used for expectation!, given the
original method's visibility.
Return the visibility that should be used for expectation! given the original method ' s visibility .
fn expectation_visibility(vis: &Visibility, levels: u32)
    -> Visibility
{
    debug_assert!(levels > 0);
    let in_token = Token![in](vis.span());
    let super_token = Token![super](vis.span());
    match vis {
        Visibility::Inherited => {
            // Private items need pub(in super::[...]) for each level
            let mut path = Path::from(super_token);
            for _ in 1..levels {
                path.segments.push(super_token.into());
            }
            Visibility::Restricted(VisRestricted{
                pub_token: Token![pub](vis.span()),
                paren_token: token::Paren::default(),
                in_token: Some(in_token),
                path: Box::new(path)
            })
        },
        Visibility::Restricted(vr) => {
            // crate => don't change
            // in crate::* => don't change
            // super => in super::super::super
            // self => in super::super
            // in anything_else => super::super::anything_else
            if vr.path.segments.first().unwrap().ident == "crate" {
                vr.clone().into()
            } else {
                let mut out = vr.clone();
                out.in_token = Some(in_token);
                for _ in 0..levels {
                    out.path.segments.insert(0, super_token.into());
                }
                out.into()
            }
        },
        _ => vis.clone()
    }
}
fn expectation_visibility ( vis : & Visibility , levels : u32 ) -> Visibility { debug_assert ! ( levels 0 ) ; let in_token = Token ! [ in ] ( vis . span ( ) ) ; let super_token = Token ! [ super ] ( vis . span ( ) ) ; match vis { Visibility :: Inherited => { // Private items need pub(in super::[...]) for each level let mut path = Path :: from ( super_token ) ; for _ in 1 .. levels { path . segments . push ( super_token . into ( ) ) ; } Visibility :: Restricted ( VisRestricted { pub_token : Token ! [ pub ] ( vis . span ( ) ) , paren_token : token :: Paren :: default ( ) , in_token : Some ( in_token ) , path : Box :: new ( path ) } ) } , Visibility :: Restricted ( vr ) => { // crate => don't change // in crate::* => don't change // super => in super::super::super // self => in super::super // in anything_else => super::super::anything_else if vr . path . segments . first ( ) . unwrap ( ) . ident == " " { vr . clone ( ) . into ( ) } else { let mut out = vr . clone ( ) ; out . in_token = Some ( in_token ) ; for _ in 0 .. levels { out . path . segments . insert ( 0 , super_token . into ( ) ) ; } out . into ( ) } } , _ => vis . clone ( ) } }
Return the visibility that should be used for expectation!, given the
original method's visibility.
Return the visibility that should be used for expectation! given the original method ' s visibility .
vis
&Visibility
Original visibility of the item
Original visibility of the item
levels
u32
None