Struct hir_def::body::BodySourceMap
source · pub struct BodySourceMap { /* private fields */ }
Expand description
An item body together with the mapping from syntax nodes to HIR expression IDs. This is needed to go from e.g. a position in a file to the HIR expression containing it; but for type inference etc., we want to operate on a structure that is agnostic to the actual positions of expressions in the file, so that we don’t recompute types whenever some whitespace is typed.
One complication here is that, due to macro expansion, a single Body
might
be spread across several files. So, for each ExprId and PatId, we record
both the HirFileId and the position inside the file. However, we only store
AST -> ExprId mapping for non-macro files, as it is not clear how to handle
this properly for macros.
Implementations§
source§impl BodySourceMap
impl BodySourceMap
pub fn expr_or_pat_syntax( &self, id: ExprOrPatId, ) -> Result<ExprOrPatSource, SyntheticSyntax>
pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax>
pub fn node_expr(&self, node: InFile<&Expr>) -> Option<ExprOrPatId>
pub fn node_macro_file(&self, node: InFile<&MacroCall>) -> Option<MacroFileId>
pub fn macro_calls( &self, ) -> impl Iterator<Item = (InFile<AstPtr<MacroCall>>, MacroFileId)> + '_
pub fn pat_syntax(&self, pat: PatId) -> Result<ExprOrPatSource, SyntheticSyntax>
pub fn self_param_syntax(&self) -> Option<InFile<AstPtr<SelfParam>>>
pub fn node_pat(&self, node: InFile<&Pat>) -> Option<PatId>
pub fn label_syntax(&self, label: LabelId) -> LabelSource
pub fn patterns_for_binding(&self, binding: BindingId) -> &[PatId]
pub fn node_label(&self, node: InFile<&Label>) -> Option<LabelId>
pub fn field_syntax(&self, expr: ExprId) -> FieldSource
pub fn pat_field_syntax(&self, pat: PatId) -> PatFieldSource
pub fn macro_expansion_expr( &self, node: InFile<&MacroExpr>, ) -> Option<ExprOrPatId>
pub fn expansions( &self, ) -> impl Iterator<Item = (&InFile<AstPtr<MacroCall>>, &MacroFileId)>
pub fn implicit_format_args( &self, node: InFile<&FormatArgsExpr>, ) -> Option<(HygieneId, &[(TextRange, Name)])>
pub fn asm_template_args( &self, node: InFile<&AsmExpr>, ) -> Option<(ExprId, &[Vec<(TextRange, usize)>])>
sourcepub fn diagnostics(&self) -> &[BodyDiagnostic]
pub fn diagnostics(&self) -> &[BodyDiagnostic]
Get a reference to the body source map’s diagnostics.
Trait Implementations§
source§impl Debug for BodySourceMap
impl Debug for BodySourceMap
source§impl Default for BodySourceMap
impl Default for BodySourceMap
source§fn default() -> BodySourceMap
fn default() -> BodySourceMap
Returns the “default value” for a type. Read more
source§impl PartialEq for BodySourceMap
impl PartialEq for BodySourceMap
impl Eq for BodySourceMap
impl StructuralPartialEq for BodySourceMap
Auto Trait Implementations§
impl Freeze for BodySourceMap
impl RefUnwindSafe for BodySourceMap
impl Send for BodySourceMap
impl Sync for BodySourceMap
impl Unpin for BodySourceMap
impl UnwindSafe for BodySourceMap
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
Mutably borrows from an owned value. Read more
§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
Checks if this value is equivalent to the given key. Read more
§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
Compare self to
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>
Converts
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>
Converts
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