pub struct Name { /* private fields */ }
Expand description
Name
is a wrapper around string, which is used in hir for both references
and declarations. In theory, names should also carry hygiene info, but we are
not there yet!
Note that the rawness (r#
) of names does not depend on whether they are written raw.
This is because we want to show (in completions etc.) names as raw depending on the needs
of the current crate, for example if it is edition 2021 complete gen
even if the defining
crate is in edition 2024 and wrote r#gen
, and the opposite holds as well.
Implementations§
§impl Name
impl Name
pub fn new(text: &str, ctx: SyntaxContextId) -> Name
pub fn new_tuple_field(idx: usize) -> Name
pub fn new_lifetime(lt: &Lifetime) -> Name
pub fn missing() -> Name
pub fn missing() -> Name
A fake name for things missing in the source code.
For example, impl Foo for {}
should be treated as a trait impl for a
type with a missing name. Similarly, struct S { : u32 }
should have a
single field with a missing name.
Ideally, we want a gensym
semantics for missing names – each missing
name is equal only to itself. It’s not clear how to implement this in
salsa though, so we punt on that bit for a moment.
pub fn is_missing(&self) -> bool
pub fn is_missing(&self) -> bool
Returns true if this is a fake name for things missing in the source code. See
missing()
for details.
Use this method instead of comparing with Self::missing()
as missing names
(ideally should) have a gensym
semantics.
pub fn generate_new_name(idx: usize) -> Name
pub fn generate_new_name(idx: usize) -> Name
Generates a new name that attempts to be unique. Should only be used when body lowering and creating desugared locals and labels. The caller is responsible for picking an index that is stable across re-executions
pub fn as_tuple_index(&self) -> Option<usize>
pub fn as_tuple_index(&self) -> Option<usize>
Returns the tuple index this name represents if it is a tuple field.
pub fn unescaped(&self) -> UnescapedName<'_>
pub fn is_escaped(&self, edition: Edition) -> bool
pub fn display<'a>( &'a self, db: &dyn ExpandDatabase, edition: Edition, ) -> impl Display + 'a
pub fn symbol(&self) -> &Symbol
pub const fn new_symbol(symbol: Symbol, ctx: SyntaxContextId) -> Name
pub const fn new_symbol_root(sym: Symbol) -> Name
pub fn eq_ident(&self, ident: &str) -> bool
Trait Implementations§
§impl Extend<Name> for ModPath
impl Extend<Name> for ModPath
§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Name>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Name>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)§impl Ord for Name
impl Ord for Name
§impl PartialOrd for Name
impl PartialOrd 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
§impl<T> Cast for T
impl<T> Cast for 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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§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<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