pub struct HirFileId(/* private fields */);
Expand description

Input to the analyzer is a set of files, where each file is identified by FileId and contains source code. However, another source of source code in Rust are macros: each macro can be thought of as producing a “temporary file”. To assign an id to such a file, we use the id of the macro call that produced the file. So, a HirFileId is either a FileId (source code written by user), or a MacroCallId (source code produced by macro).

What is a MacroCallId? Simplifying, it’s a HirFileId of a file containing the call plus the offset of the macro call in the file. Note that this is a recursive definition! However, the size_of of HirFileId is finite (because everything bottoms out at the real FileId) and small (MacroCallId uses the location interning. You can check details here: https://en.wikipedia.org/wiki/String_interning).

The two variants are encoded in a single u32 which are differentiated by the MSB. If the MSB is 0, the value represents a FileId, otherwise the remaining 31 bits represent a MacroCallId.

Implementations§

source§

impl HirFileId

source

pub fn original_file(self, db: &dyn ExpandDatabase) -> FileId

For macro-expansion files, returns the file original source file the expansion originated from.

source

pub fn expansion_level(self, db: &dyn ExpandDatabase) -> u32

source

pub fn call_node(self, db: &dyn ExpandDatabase) -> Option<InFile<SyntaxNode>>

If this is a macro call, returns the syntax node of the call.

source

pub fn original_call_node( self, db: &dyn ExpandDatabase ) -> Option<(FileId, SyntaxNode)>

If this is a macro call, returns the syntax node of the very first macro call this file resides in.

source

pub fn expansion_info(self, db: &dyn ExpandDatabase) -> Option<ExpansionInfo>

Return expansion information if it is a macro-expansion file

source

pub fn as_builtin_derive_attr_node( &self, db: &dyn ExpandDatabase ) -> Option<InFile<Attr>>

source

pub fn is_custom_derive(&self, db: &dyn ExpandDatabase) -> bool

source

pub fn is_builtin_derive(&self, db: &dyn ExpandDatabase) -> bool

source

pub fn is_include_macro(&self, db: &dyn ExpandDatabase) -> bool

Return whether this file is an include macro

source

pub fn is_eager(&self, db: &dyn ExpandDatabase) -> bool

source

pub fn is_attr_macro(&self, db: &dyn ExpandDatabase) -> bool

Return whether this file is an attr macro

source

pub fn is_derive_attr_pseudo_expansion(&self, db: &dyn ExpandDatabase) -> bool

Return whether this file is the pseudo expansion of the derive attribute. See [crate::builtin_attr_macro::derive_attr_expand].

source

pub fn is_macro(self) -> bool

source

pub fn macro_file(self) -> Option<MacroFile>

source

pub fn file_id(self) -> Option<FileId>

Trait Implementations§

source§

impl Clone for HirFileId

source§

fn clone(&self) -> HirFileId

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HirFileId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<FileId> for HirFileId

source§

fn from(FileId: FileId) -> Self

Converts to this type from the input type.
source§

impl From<MacroFile> for HirFileId

source§

fn from(_: MacroFile) -> Self

Converts to this type from the input type.
source§

impl Hash for HirFileId

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for HirFileId

source§

fn eq(&self, other: &HirFileId) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for HirFileId

source§

impl Eq for HirFileId

source§

impl StructuralEq for HirFileId

source§

impl StructuralPartialEq for HirFileId

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoBox<dyn Any> for Twhere T: Any,

source§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
source§

impl<T> IntoBox<dyn Any + Send> for Twhere T: Any + Send,

source§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
source§

impl<T> IntoBox<dyn Any + Send + Sync> for Twhere T: Any + Send + Sync,

source§

fn into_box(self) -> Box<dyn Any + Send + Sync>

Convert self into the appropriate boxed form.
source§

impl<T> IntoBox<dyn CloneAny> for Twhere T: CloneAny,

source§

fn into_box(self) -> Box<dyn CloneAny>

Convert self into the appropriate boxed form.
source§

impl<T> IntoBox<dyn CloneAny + Send> for Twhere T: CloneAny + Send,

source§

fn into_box(self) -> Box<dyn CloneAny + Send>

Convert self into the appropriate boxed form.
source§

impl<T> IntoBox<dyn CloneAny + Send + Sync> for Twhere T: CloneAny + Send + Sync,

source§

fn into_box(self) -> Box<dyn CloneAny + Send + Sync>

Convert self into the appropriate boxed form.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> CloneAny for Twhere T: Any + Clone,