pub struct Name {
pub name: Vec<PathElem>,
}
Expand description
An item name/path
A name really is a list of strings. However, we sometimes need to introduce unique indices to disambiguate. This mostly happens because of “impl” blocks:
impl<T> List<T> {
...
}
A type in Rust can have several “impl” blocks, and those blocks can contain items with similar names. For this reason, we need to disambiguate them with unique indices. Rustc calls those “disambiguators”. In rustc, this gives names like this:
betree_main::betree::NodeIdCounter{impl#0}::new
- note that impl blocks can be nested, and macros sometimes generate
weird names (which require disambiguation):
betree_main::betree_utils::_#1::{impl#0}::deserialize::{impl#0}
Finally, the paths used by rustc are a lot more precise and explicit than those we expose in LLBC: for instance, every identifier belongs to a specific namespace (value namespace, type namespace, etc.), and is coupled with a disambiguator.
On our side, we want to stay high-level and simple: we use string identifiers as much as possible, insert disambiguators only when necessary (whenever we find an “impl” block, typically) and check that the disambiguator is useless in the other situations (i.e., the disambiguator is always equal to 0).
Moreover, the items are uniquely disambiguated by their (integer) ids
(TypeDeclId
, etc.), and when extracting the code we have to deal with
name clashes anyway. Still, we might want to be more precise in the future.
Also note that the first path element in the name is always the crate name.
Fields§
§name: Vec<PathElem>
Implementations§
source§impl Name
impl Name
sourcepub(crate) fn from_path(path: &[&str]) -> Name
pub(crate) fn from_path(path: &[&str]) -> Name
Convert a path like ["std", "alloc", "Box"]
to a name. Needed on occasion when crafting
names that were not present in the original code.
pub fn len(&self) -> usize
sourcepub fn compare_with_ref_name(&self, equal: bool, ref_name: &[&str]) -> bool
pub fn compare_with_ref_name(&self, equal: bool, ref_name: &[&str]) -> bool
Compare the name to a constant array. This ignores disambiguators.
equal
: if true
, check that the name is equal to the ref. If false
:
only check if the ref is a prefix of the name.
sourcepub fn equals_ref_name(&self, ref_name: &[&str]) -> bool
pub fn equals_ref_name(&self, ref_name: &[&str]) -> bool
Compare the name to a constant array. This ignores disambiguators.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Name
impl<'de> Deserialize<'de> for Name
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<C: AstFormatter> FmtWithCtx<C> for Name
impl<C: AstFormatter> FmtWithCtx<C> for Name
impl Eq for Name
impl StructuralPartialEq for Name
Auto Trait Implementations§
impl Freeze for Name
impl RefUnwindSafe for Name
impl Send for Name
impl Sync for Name
impl Unpin for Name
impl UnwindSafe for Name
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more