Skip to main content

rustc_middle/middle/
debugger_visualizer.rs

1use std::path::PathBuf;
2use std::sync::Arc;
3
4use rustc_hir::attrs::DebuggerVisualizerType;
5use rustc_macros::{Decodable, Encodable, HashStable};
6
7/// A single debugger visualizer file.
8#[derive(const _: () =
    {
        impl<'__ctx>
            ::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
            for DebuggerVisualizerFile {
            #[inline]
            fn hash_stable(&self,
                __hcx:
                    &mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    DebuggerVisualizerFile {
                        src: ref __binding_0,
                        visualizer_type: ref __binding_1,
                        path: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable)]
9#[derive(#[automatically_derived]
impl ::core::clone::Clone for DebuggerVisualizerFile {
    #[inline]
    fn clone(&self) -> DebuggerVisualizerFile {
        DebuggerVisualizerFile {
            src: ::core::clone::Clone::clone(&self.src),
            visualizer_type: ::core::clone::Clone::clone(&self.visualizer_type),
            path: ::core::clone::Clone::clone(&self.path),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for DebuggerVisualizerFile {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "DebuggerVisualizerFile", "src", &self.src, "visualizer_type",
            &self.visualizer_type, "path", &&self.path)
    }
}Debug, #[automatically_derived]
impl ::core::hash::Hash for DebuggerVisualizerFile {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.src, state);
        ::core::hash::Hash::hash(&self.visualizer_type, state);
        ::core::hash::Hash::hash(&self.path, state)
    }
}Hash, #[automatically_derived]
impl ::core::cmp::PartialEq for DebuggerVisualizerFile {
    #[inline]
    fn eq(&self, other: &DebuggerVisualizerFile) -> bool {
        self.src == other.src && self.visualizer_type == other.visualizer_type
            && self.path == other.path
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DebuggerVisualizerFile {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Arc<[u8]>>;
        let _: ::core::cmp::AssertParamIsEq<DebuggerVisualizerType>;
        let _: ::core::cmp::AssertParamIsEq<Option<PathBuf>>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for DebuggerVisualizerFile {
    #[inline]
    fn partial_cmp(&self, other: &DebuggerVisualizerFile)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match ::core::cmp::PartialOrd::partial_cmp(&self.src, &other.src) {
            ::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
                match ::core::cmp::PartialOrd::partial_cmp(&self.visualizer_type,
                        &other.visualizer_type) {
                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                        =>
                        ::core::cmp::PartialOrd::partial_cmp(&self.path,
                            &other.path),
                    cmp => cmp,
                },
            cmp => cmp,
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for DebuggerVisualizerFile {
    #[inline]
    fn cmp(&self, other: &DebuggerVisualizerFile) -> ::core::cmp::Ordering {
        match ::core::cmp::Ord::cmp(&self.src, &other.src) {
            ::core::cmp::Ordering::Equal =>
                match ::core::cmp::Ord::cmp(&self.visualizer_type,
                        &other.visualizer_type) {
                    ::core::cmp::Ordering::Equal =>
                        ::core::cmp::Ord::cmp(&self.path, &other.path),
                    cmp => cmp,
                },
            cmp => cmp,
        }
    }
}Ord, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DebuggerVisualizerFile {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    DebuggerVisualizerFile {
                        src: ref __binding_0,
                        visualizer_type: ref __binding_1,
                        path: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for DebuggerVisualizerFile {
            fn decode(__decoder: &mut __D) -> Self {
                DebuggerVisualizerFile {
                    src: ::rustc_serialize::Decodable::decode(__decoder),
                    visualizer_type: ::rustc_serialize::Decodable::decode(__decoder),
                    path: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable)]
10pub struct DebuggerVisualizerFile {
11    /// The complete debugger visualizer source.
12    pub src: Arc<[u8]>,
13    /// Indicates which visualizer type this targets.
14    pub visualizer_type: DebuggerVisualizerType,
15    /// The file path to the visualizer file. This is used for reporting
16    /// visualizer files in dep-info. Before it is written to crate metadata,
17    /// the path is erased to `None`, so as not to emit potentially privacy
18    /// sensitive data.
19    pub path: Option<PathBuf>,
20}
21
22impl DebuggerVisualizerFile {
23    pub fn new(src: Arc<[u8]>, visualizer_type: DebuggerVisualizerType, path: PathBuf) -> Self {
24        DebuggerVisualizerFile { src, visualizer_type, path: Some(path) }
25    }
26
27    pub fn path_erased(&self) -> Self {
28        DebuggerVisualizerFile {
29            src: Arc::clone(&self.src),
30            visualizer_type: self.visualizer_type,
31            path: None,
32        }
33    }
34}