Skip to main content

ExprCollector

Struct ExprCollector 

Source
pub struct ExprCollector<'db> {
Show 20 fields db: &'db dyn SourceDatabase, cfg_options: &'db CfgOptions, expander: Expander<'db>, def_map: &'db DefMap, local_def_map: &'db LocalDefMap, module: ModuleId, lowering_mode: LoweringMode, lang_items: OnceCell<&'db LangItems>, pub store: ExpressionStoreBuilder, pub named_lifetime_store: NamedLifetimeStore, outer_impl_trait: bool, is_lowering_coroutine: bool, for_type_binder: Option<ThinVec<Name>>, current_block_legacy_macro_defs_count: FxHashMap<Name, usize>, current_try_block: Option<TryBlock>, label_ribs: Vec<LabelRib>, unowned_bindings: Vec<BindingId>, awaitable_context: Option<Awaitable>, krate: Crate, name_generator_index: usize,
}

Fields§

§db: &'db dyn SourceDatabase§cfg_options: &'db CfgOptions§expander: Expander<'db>§def_map: &'db DefMap§local_def_map: &'db LocalDefMap§module: ModuleId§lowering_mode: LoweringMode§lang_items: OnceCell<&'db LangItems>§store: ExpressionStoreBuilder§named_lifetime_store: NamedLifetimeStore§outer_impl_trait: bool§is_lowering_coroutine: bool§for_type_binder: Option<ThinVec<Name>>§current_block_legacy_macro_defs_count: FxHashMap<Name, usize>

Legacy (macro_rules!) macros can have multiple definitions and shadow each other, and we need to find the current definition. So we track the number of definitions we saw.

§current_try_block: Option<TryBlock>§label_ribs: Vec<LabelRib>§unowned_bindings: Vec<BindingId>§awaitable_context: Option<Awaitable>§krate: Crate§name_generator_index: usize

Implementations§

Source§

impl ExprCollector<'_>

Source

pub(super) fn lower_inline_asm( &mut self, asm: AsmExpr, syntax_ptr: AstPtr<Expr>, ) -> ExprId

Source§

impl<'db> ExprCollector<'db>

Source

pub(super) fn collect_format_args( &mut self, f: FormatArgsExpr, syntax_ptr: AstPtr<Expr>, ) -> ExprId

Source

fn collect_format_args_impl( &mut self, syntax_ptr: AstPtr<Expr>, fmt: FormatArgs, ) -> ExprId

Source

fn make_count_after_1_93_0( &self, count: &FormatCount, argmap: &mut FxIndexSet<(usize, ArgumentType)>, ) -> (bool, u16)

Get the value for a width or precision field.

Returns the value and whether it is indirect (an indexed argument) or not.

Source

fn make_argument( &mut self, arg_ptr: Option<AstPtr<Expr>>, arg: ExprId, ty: ArgumentType, ) -> ExprId

Generate a hir expression representing an argument to a format_args invocation.

Generates:

    <core::fmt::Argument>::new_…(arg)
Source

fn ty_rel_lang_path_desugared_expr( &mut self, lang: Option<impl Into<LangItemTarget>>, relative_name: Symbol, ) -> ExprId

Source§

impl<'db> ExprCollector<'db>

Source

pub fn new( db: &dyn SourceDatabase, module: ModuleId, current_file_id: HirFileId, lowering_mode: LoweringMode, ) -> ExprCollector<'_>

Source

fn generate_new_name(&mut self) -> Name

Source

pub(crate) fn lang_items(&self) -> &'db LangItems

Source

pub(crate) fn span_map(&self) -> SpanMap<'_>

Source

pub(super) fn lower_lifetime_ref(&mut self, lifetime: Lifetime) -> LifetimeRefId

Source

pub(super) fn lower_lifetime_ref_opt( &mut self, lifetime: Option<Lifetime>, ) -> LifetimeRefId

Source

pub(super) fn lower_type_ref( &mut self, node: Type, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> TypeRefId

Converts an ast::TypeRef to a hir::TypeRef.

Source

pub(crate) fn lower_type_ref_disallow_impl_trait( &mut self, node: Type, ) -> TypeRefId

Source

pub(crate) fn lower_type_ref_opt( &mut self, node: Option<Type>, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> TypeRefId

Source

pub(crate) fn lower_type_ref_opt_disallow_impl_trait( &mut self, node: Option<Type>, ) -> TypeRefId

Source

fn alloc_type_ref(&mut self, type_ref: TypeRef, node: TypePtr) -> TypeRefId

Source

fn alloc_lifetime_ref( &mut self, lifetime_ref: LifetimeRef, node: LifetimePtr, ) -> LifetimeRefId

Source

fn alloc_type_ref_desugared(&mut self, type_ref: TypeRef) -> TypeRefId

Source

fn alloc_lifetime_ref_desugared( &mut self, lifetime_ref: LifetimeRef, ) -> LifetimeRefId

Source

fn alloc_error_type(&mut self) -> TypeRefId

Source

pub fn lower_path( &mut self, ast: Path, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> Option<Path>

Source

fn with_outer_impl_trait_scope<R>( &mut self, impl_trait: bool, f: impl FnOnce(&mut Self) -> R, ) -> R

Source

pub fn impl_trait_error_allocator( ec: &mut ExprCollector<'_>, ptr: TypePtr, _: ThinVec<TypeBound>, ) -> TypeRefId

Source

fn impl_trait_allocator( ec: &mut ExprCollector<'_>, ptr: TypePtr, bounds: ThinVec<TypeBound>, ) -> TypeRefId

Source

fn alloc_path(&mut self, path: Path, node: TypePtr) -> PathId

Source

pub(super) fn lower_generic_args_from_fn_path( &mut self, args: Option<ParenthesizedArgList>, ret_type: Option<RetType>, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> Option<GenericArgs>

Collect GenericArgs from the parts of a fn-like path, i.e. Fn(X, Y) -> Z (which desugars to Fn<(X, Y), Output=Z>).

Source

pub(super) fn lower_generic_args( &mut self, node: GenericArgList, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> Option<GenericArgs>

Source

fn lower_coroutine_body_with_moved_arguments( &mut self, self_param: &mut Option<Param<BindingId>>, params: &mut [Param<PatId>], body: ExprId, kind: CoroutineKind, coroutine_source: CoroutineSource, ) -> ExprId

Lowers a desugared coroutine body after moving all of the arguments into the body. This is to make sure that the future actually owns the arguments that are passed to the function, and to ensure things like drop order are stable.

Source

fn desugared_coroutine_expr( &mut self, kind: CoroutineKind, source: CoroutineSource, capture_by: CaptureBy, id: Option<BlockId>, statements: Box<[Statement]>, tail: Option<ExprId>, ) -> Expr

Source

fn collect( &mut self, self_param: &mut Option<Param<BindingId>>, params: &mut [Param<PatId>], expr: Option<Expr>, awaitable: Awaitable, is_async_fn: bool, is_gen_fn: bool, ) -> ExprId

Source

fn type_bounds_from_ast( &mut self, type_bounds_opt: Option<TypeBoundList>, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> ThinVec<TypeBound>

Source

fn lower_path_type( &mut self, path_type: &PathType, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> Option<Path>

Source

fn lower_type_bound( &mut self, node: TypeBound, impl_trait_lower_fn: &'_ mut dyn for<'ec, 'db> FnMut(&'ec mut ExprCollector<'db>, TypePtr, ThinVec<TypeBound>) -> TypeRefId, ) -> TypeBound

Source

fn lower_for_binder_opt(&mut self, binder: Option<ForBinder>) -> ThinVec<Name>

Source

fn lower_for_binder(&mut self, binder: ForBinder) -> ThinVec<Name>

Source

fn lower_const_arg_opt(&mut self, arg: Option<ConstArg>) -> ConstRef

Source

pub fn lower_const_arg(&mut self, arg: ConstArg) -> ConstRef

Source

fn collect_expr(&mut self, expr: Expr) -> ExprId

Source

pub(super) fn collect_expr_opt(&mut self, expr: Option<Expr>) -> ExprId

Source

fn maybe_collect_expr(&mut self, expr: Expr) -> Option<ExprId>

Returns None if and only if the expression is #[cfg]d out.

Source

fn collect_range_expr( &mut self, e: RangeExpr, syntax_ptr: AstPtr<Expr>, ) -> ExprId

Source

fn collect_inclusive_range( &mut self, syntax_ptr: AstPtr<Expr>, lang_items: &LangItems, lhs: ExprId, rhs: ExprId, ) -> ExprId

Source

fn collect_expr_path(&mut self, e: PathExpr) -> Option<(Path, HygieneId)>

Source

fn path_is_destructuring_assignment(&self, path: &ModPath) -> bool

Whether this path should be lowered as destructuring assignment, or as a normal assignment.

Source

fn collect_expr_as_pat_opt(&mut self, expr: Option<Expr>) -> PatId

Source

fn collect_expr_as_pat(&mut self, expr: Expr) -> PatId

Source

fn maybe_collect_expr_as_pat(&mut self, expr: &Expr) -> Option<PatId>

Source

fn with_binding_owner_and_return( &mut self, create_expr: impl FnOnce(&mut Self) -> (ExprId, ExprId), ) -> ExprId

The callback should return two exprs: the first is the bindings owner, the second is the expr to return.

Source

fn associate_unowned_bindings_with( &mut self, prev_unowned_bindings_len: usize, bindings_owner: ExprId, )

Source

fn with_binding_owner( &mut self, create_expr: impl FnOnce(&mut Self) -> ExprId, ) -> ExprId

Source

fn desugar_try_block( &mut self, e: BlockExpr, result_type: Option<Type>, ) -> ExprId

Desugar try { <stmts>; <expr> } into '<new_label>: { <stmts>; ::std::ops::Try::from_output(<expr>) }, try { <stmts>; } into '<new_label>: { <stmts>; ::std::ops::Try::from_output(()) } and save the <new_label> to use it as a break target for desugaring of the ? operator.

Source

fn collect_while_loop( &mut self, syntax_ptr: AstPtr<Expr>, e: WhileExpr, ) -> ExprId

Desugar ast::WhileExpr from: [opt_ident]: while <cond> <body> into:

ⓘ
[opt_ident]: loop {
  if <cond> {
    <body>
  }
  else {
    break;
  }
}

FIXME: Rustc wraps the condition in DropTemps – a construct equivalent to { let _t = <cond>; _t } – to preserve drop semantics. We should probably do the same in future.

Source

fn collect_for_loop(&mut self, syntax_ptr: AstPtr<Expr>, e: ForExpr) -> ExprId

Desugar ast::ForExpr from: [opt_ident]: for <pat> in <head> <body> into:

ⓘ
match IntoIterator::into_iter(<head>) {
    mut iter => {
        [opt_ident]: loop {
            match Iterator::next(&mut iter) {
                None => break,
                Some(<pat>) => <body>,
            };
        }
    }
}
Source

fn collect_try_operator( &mut self, syntax_ptr: AstPtr<Expr>, e: TryExpr, ) -> ExprId

Desugar ast::TryExpr from: <expr>? into:

ⓘ
match Try::branch(<expr>) {
    ControlFlow::Continue(val) => val,
    ControlFlow::Break(residual) =>
        // If there is an enclosing `try {...}`:
        break 'catch_target Residual::into_try_type(residual),
        // If there is an enclosing `try bikeshed Ty {...}`:
        break 'catch_target Try::from_residual(residual),
        // Otherwise:
        return Try::from_residual(residual),
}
Source

fn collect_macro_call<T, U>( &mut self, mcall: MacroCall, syntax_ptr: AstPtr<MacroCall>, record_diagnostics: bool, collector: impl FnOnce(&mut Self, Option<T>) -> U, ) -> U
where T: AstNode,

Source

fn collect_macro_as_stmt( &mut self, statements: &mut Vec<Statement>, mac: MacroExpr, ) -> Option<ExprId>

Source

fn collect_stmt(&mut self, statements: &mut Vec<Statement>, s: Stmt)

Source

fn collect_macro_def( &mut self, statements: &mut Vec<Statement>, macro_id: Option<MacroId>, )

Source

fn collect_block(&mut self, block: BlockExpr) -> ExprId

Source

fn collect_block_( &mut self, block: BlockExpr, mk_block: impl FnOnce(&mut Self, Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr, ) -> ExprId

Source

fn collect_block_opt(&mut self, expr: Option<BlockExpr>) -> ExprId

Source

fn collect_labelled_block_opt( &mut self, label: Option<(HygieneId, LabelId)>, expr: Option<BlockExpr>, ) -> ExprId

Source

fn collect_param_as_ident(&mut self, pat: Pat) -> PatId

Source

fn collect_pat_top(&mut self, pat: Option<Pat>) -> PatId

Source

fn collect_pat(&mut self, pat: Pat, binding_list: &mut BindingList) -> PatId

Source

fn collect_macro_pat_with( &mut self, mac: MacroPat, callback: impl FnOnce(&mut Self, Pat) -> PatId, ) -> PatId

Source

fn collect_pat_opt( &mut self, pat: Option<Pat>, binding_list: &mut BindingList, ) -> PatId

Source

fn collect_tuple_pat( &mut self, args: AstChildren<Pat>, has_leading_comma: bool, binding_list: &mut BindingList, ) -> (Box<[PatId]>, Option<u32>)

Source

fn collect_pat_possibly_rest( &mut self, pat: Pat, binding_list: &mut BindingList, ) -> Either<PatId, ()> ⓘ

Source

fn collect_ty_pat_opt(&mut self, pat: Option<Pat>) -> PatId

Source

fn collect_ty_pat(&mut self, pat: Pat) -> PatId

Source

fn lower_ty_pat_range_side(&mut self, pat: Pat) -> ExprId

Source

fn lower_ty_pat_range_end(&mut self, lang_item: Option<ConstId>) -> ExprId

When a range has no end specified (1.. or 1..=) or no start specified (..5 or ..=5), we instead use a constant of the MAX/MIN of the type. This way the type system does not have to handle the lack of a start/end.

Source

fn lower_excluded_range_end(&mut self, pat: Pat) -> ExprId

Lowers the range end of an exclusive range (2..5) to an inclusive range 2..=(5 - 1). This way the type system doesn’t have to handle the distinction between inclusive/exclusive ranges.

Source

fn check_cfg(&mut self, owner: &dyn HasAttrs) -> bool

Returns false (and emits diagnostics) when owner if #[cfg]d out, and true when not.

Source

fn check_cfg_pred(&self, pred: Option<CfgPredicate>) -> bool

Used for cfg!(), conducting imprecise checks

Source

fn add_definition_to_binding(&mut self, binding_id: BindingId, pat_id: PatId)

Source

fn collect_label(&mut self, ast_label: Label) -> LabelId

Source

fn resolve_label( &self, lifetime: Option<Lifetime>, ) -> Result<Option<LabelId>, ExpressionStoreDiagnostics>

Source

fn is_label_valid_from_rib(&self, rib_index: usize) -> bool

Source

fn pop_label_rib(&mut self)

Source

fn with_label_rib<T>( &mut self, kind: RibKind, f: impl FnOnce(&mut Self) -> T, ) -> T

Source

fn with_labeled_rib<T>( &mut self, label: LabelId, hygiene: HygieneId, f: impl FnOnce(&mut Self) -> T, ) -> T

Source

fn with_opt_labeled_rib<T>( &mut self, label: Option<(HygieneId, LabelId)>, f: impl FnOnce(&mut Self) -> T, ) -> T

Source

fn expand_macros_to_string(&mut self, expr: Expr) -> Option<(String, bool)>

While expr is a macro call, repeatedly expand it. If the end result is a string literal, return that, along with a boolean for whether it was a direct string literal, i.e. no macro calls were involved. In all other cases, return None.

Source

fn lang_path(&self, lang: Option<impl Into<LangItemTarget>>) -> Option<Path>

Source

fn lang_path_expr(&self, lang: Option<impl Into<LangItemTarget>>) -> Expr

Source

fn ty_rel_lang_path( &self, lang: Option<impl Into<LangItemTarget>>, relative_name: Symbol, ) -> Option<Path>

Source

fn ty_rel_lang_path_expr( &self, lang: Option<impl Into<LangItemTarget>>, relative_name: Symbol, ) -> Expr

Source§

impl<'db> ExprCollector<'db>

Source

fn features(&self) -> &'db UnstableFeatures

Source

fn with_fresh_binding_expr_root( &mut self, f: impl FnOnce(&mut Self) -> ExprId, ) -> ExprId

Source

fn with_expr_root(&mut self, f: impl FnOnce(&mut Self) -> ExprId) -> ExprId

Source

fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId

Source

fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId

Source

fn alloc_expr_desugared_with_ptr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId

Source

fn missing_expr(&mut self) -> ExprId

Source

fn alloc_binding( &mut self, name: Name, mode: BindingAnnotation, hygiene: HygieneId, ) -> BindingId

Source

fn alloc_pat_from_expr(&mut self, pat: Pat, ptr: ExprPtr) -> PatId

Source

fn alloc_expr_from_pat(&mut self, expr: Expr, ptr: PatPtr) -> ExprId

Source

fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId

Source

fn alloc_pat_desugared(&mut self, pat: Pat) -> PatId

Source

fn missing_pat(&mut self) -> PatId

Source

fn alloc_label(&mut self, label: Label, ptr: AstPtr<Label>) -> LabelId

Source

fn alloc_label_desugared(&mut self, label: Label, ptr: LabelPtr) -> LabelId

Source

fn is_lowering_awaitable_block(&self) -> &Awaitable

Source

fn with_awaitable_block<T>( &mut self, awaitable: Awaitable, f: impl FnOnce(&mut Self) -> T, ) -> T

Source

fn hygiene_id_for(&self, range: TextRange) -> HygieneId

Source

fn with_lifetime_bound_scope<T>( &mut self, bound_scope: LifetimeBoundScope, f: impl FnOnce(&mut Self) -> T, ) -> T

Source

fn for_path_type_projection<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T

Source

fn push_named_target_lifetime(&mut self, id: LifetimeRefId)

Source

fn is_argument_lt_bound_scope(&mut self) -> bool

Source

fn get_constrained_lifetimes_if_type_alias<'a>( &mut self, mod_path: &'a ModPath, generic_args: Option<&'a GenericArgs>, ) -> Option<impl Iterator<Item = LifetimeRefId> + use<'a, 'db>>

Auto Trait Implementations§

§

impl<'db> !Freeze for ExprCollector<'db>

§

impl<'db> !RefUnwindSafe for ExprCollector<'db>

§

impl<'db> !Send for ExprCollector<'db>

§

impl<'db> !Sync for ExprCollector<'db>

§

impl<'db> !UnwindSafe for ExprCollector<'db>

§

impl<'db> Unpin for ExprCollector<'db>

§

impl<'db> UnsafeUnpin for ExprCollector<'db>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 T
where 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.

§

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

§

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

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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