sway_core/
marker_traits.rs

1use sway_types::{Ident, SourceEngine};
2
3use crate::{
4    language::{parsed::ImplSelfOrTrait, ty::TyTraitDecl, CallPathType},
5    namespace::Module,
6};
7
8impl TyTraitDecl {
9    pub(crate) fn is_marker_trait(&self) -> bool {
10        assert!(
11            matches!(self.call_path.callpath_type, CallPathType::Full),
12            "call paths of trait declarations must always be full paths"
13        );
14
15        is_std_marker_module_path(&self.call_path.prefixes)
16    }
17}
18
19impl Module {
20    pub(crate) fn is_std_marker_module(&self) -> bool {
21        is_std_marker_module_path(self.mod_path())
22    }
23}
24
25impl ImplSelfOrTrait {
26    pub(crate) fn is_autogenerated(&self, source_engine: &SourceEngine) -> bool {
27        source_engine
28            .is_span_in_autogenerated(&self.block_span)
29            .unwrap_or(false)
30    }
31}
32
33fn is_std_marker_module_path(path: &[Ident]) -> bool {
34    path.len() == 2 && path[0].as_str() == "std" && path[1].as_str() == "marker"
35}