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: usizeImplementations§
Source§impl ExprCollector<'_>
impl ExprCollector<'_>
pub(super) fn lower_inline_asm( &mut self, asm: AsmExpr, syntax_ptr: AstPtr<Expr>, ) -> ExprId
Source§impl<'db> ExprCollector<'db>
impl<'db> ExprCollector<'db>
pub(super) fn collect_format_args( &mut self, f: FormatArgsExpr, syntax_ptr: AstPtr<Expr>, ) -> ExprId
fn collect_format_args_impl( &mut self, syntax_ptr: AstPtr<Expr>, fmt: FormatArgs, ) -> ExprId
Sourcefn make_count_after_1_93_0(
&self,
count: &FormatCount,
argmap: &mut FxIndexSet<(usize, ArgumentType)>,
) -> (bool, u16)
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.
Sourcefn make_argument(
&mut self,
arg_ptr: Option<AstPtr<Expr>>,
arg: ExprId,
ty: ArgumentType,
) -> ExprId
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)fn ty_rel_lang_path_desugared_expr( &mut self, lang: Option<impl Into<LangItemTarget>>, relative_name: Symbol, ) -> ExprId
Source§impl<'db> ExprCollector<'db>
impl<'db> ExprCollector<'db>
pub fn new( db: &dyn SourceDatabase, module: ModuleId, current_file_id: HirFileId, lowering_mode: LoweringMode, ) -> ExprCollector<'_>
fn generate_new_name(&mut self) -> Name
pub(crate) fn lang_items(&self) -> &'db LangItems
pub(crate) fn span_map(&self) -> SpanMap<'_>
pub(super) fn lower_lifetime_ref(&mut self, lifetime: Lifetime) -> LifetimeRefId
pub(super) fn lower_lifetime_ref_opt( &mut self, lifetime: Option<Lifetime>, ) -> LifetimeRefId
Sourcepub(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
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.
pub(crate) fn lower_type_ref_disallow_impl_trait( &mut self, node: Type, ) -> TypeRefId
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
pub(crate) fn lower_type_ref_opt_disallow_impl_trait( &mut self, node: Option<Type>, ) -> TypeRefId
fn alloc_type_ref(&mut self, type_ref: TypeRef, node: TypePtr) -> TypeRefId
fn alloc_lifetime_ref( &mut self, lifetime_ref: LifetimeRef, node: LifetimePtr, ) -> LifetimeRefId
fn alloc_type_ref_desugared(&mut self, type_ref: TypeRef) -> TypeRefId
fn alloc_lifetime_ref_desugared( &mut self, lifetime_ref: LifetimeRef, ) -> LifetimeRefId
fn alloc_error_type(&mut self) -> TypeRefId
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>
fn with_outer_impl_trait_scope<R>( &mut self, impl_trait: bool, f: impl FnOnce(&mut Self) -> R, ) -> R
pub fn impl_trait_error_allocator( ec: &mut ExprCollector<'_>, ptr: TypePtr, _: ThinVec<TypeBound>, ) -> TypeRefId
fn impl_trait_allocator( ec: &mut ExprCollector<'_>, ptr: TypePtr, bounds: ThinVec<TypeBound>, ) -> TypeRefId
fn alloc_path(&mut self, path: Path, node: TypePtr) -> PathId
Sourcepub(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>
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>).
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>
Sourcefn 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
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.
fn desugared_coroutine_expr( &mut self, kind: CoroutineKind, source: CoroutineSource, capture_by: CaptureBy, id: Option<BlockId>, statements: Box<[Statement]>, tail: Option<ExprId>, ) -> Expr
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
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>
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>
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
fn lower_for_binder_opt(&mut self, binder: Option<ForBinder>) -> ThinVec<Name>
fn lower_for_binder(&mut self, binder: ForBinder) -> ThinVec<Name>
fn lower_const_arg_opt(&mut self, arg: Option<ConstArg>) -> ConstRef
pub fn lower_const_arg(&mut self, arg: ConstArg) -> ConstRef
fn collect_expr(&mut self, expr: Expr) -> ExprId
pub(super) fn collect_expr_opt(&mut self, expr: Option<Expr>) -> ExprId
Sourcefn maybe_collect_expr(&mut self, expr: Expr) -> Option<ExprId>
fn maybe_collect_expr(&mut self, expr: Expr) -> Option<ExprId>
Returns None if and only if the expression is #[cfg]d out.
fn collect_range_expr( &mut self, e: RangeExpr, syntax_ptr: AstPtr<Expr>, ) -> ExprId
fn collect_inclusive_range( &mut self, syntax_ptr: AstPtr<Expr>, lang_items: &LangItems, lhs: ExprId, rhs: ExprId, ) -> ExprId
fn collect_expr_path(&mut self, e: PathExpr) -> Option<(Path, HygieneId)>
Sourcefn path_is_destructuring_assignment(&self, path: &ModPath) -> bool
fn path_is_destructuring_assignment(&self, path: &ModPath) -> bool
Whether this path should be lowered as destructuring assignment, or as a normal assignment.
fn collect_expr_as_pat_opt(&mut self, expr: Option<Expr>) -> PatId
fn collect_expr_as_pat(&mut self, expr: Expr) -> PatId
fn maybe_collect_expr_as_pat(&mut self, expr: &Expr) -> Option<PatId>
Sourcefn with_binding_owner_and_return(
&mut self,
create_expr: impl FnOnce(&mut Self) -> (ExprId, ExprId),
) -> ExprId
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.
fn associate_unowned_bindings_with( &mut self, prev_unowned_bindings_len: usize, bindings_owner: ExprId, )
fn with_binding_owner( &mut self, create_expr: impl FnOnce(&mut Self) -> ExprId, ) -> ExprId
Sourcefn desugar_try_block(
&mut self,
e: BlockExpr,
result_type: Option<Type>,
) -> ExprId
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.
Sourcefn collect_while_loop(
&mut self,
syntax_ptr: AstPtr<Expr>,
e: WhileExpr,
) -> ExprId
fn collect_while_loop( &mut self, syntax_ptr: AstPtr<Expr>, e: WhileExpr, ) -> ExprId
Sourcefn collect_for_loop(&mut self, syntax_ptr: AstPtr<Expr>, e: ForExpr) -> ExprId
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>,
};
}
}
}Sourcefn collect_try_operator(
&mut self,
syntax_ptr: AstPtr<Expr>,
e: TryExpr,
) -> ExprId
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),
}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,
) -> Uwhere
T: AstNode,
fn collect_macro_as_stmt( &mut self, statements: &mut Vec<Statement>, mac: MacroExpr, ) -> Option<ExprId>
fn collect_stmt(&mut self, statements: &mut Vec<Statement>, s: Stmt)
fn collect_macro_def( &mut self, statements: &mut Vec<Statement>, macro_id: Option<MacroId>, )
fn collect_block(&mut self, block: BlockExpr) -> ExprId
fn collect_block_( &mut self, block: BlockExpr, mk_block: impl FnOnce(&mut Self, Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr, ) -> ExprId
fn collect_block_opt(&mut self, expr: Option<BlockExpr>) -> ExprId
fn collect_labelled_block_opt( &mut self, label: Option<(HygieneId, LabelId)>, expr: Option<BlockExpr>, ) -> ExprId
fn collect_param_as_ident(&mut self, pat: Pat) -> PatId
fn collect_pat_top(&mut self, pat: Option<Pat>) -> PatId
fn collect_pat(&mut self, pat: Pat, binding_list: &mut BindingList) -> PatId
fn collect_macro_pat_with( &mut self, mac: MacroPat, callback: impl FnOnce(&mut Self, Pat) -> PatId, ) -> PatId
fn collect_pat_opt( &mut self, pat: Option<Pat>, binding_list: &mut BindingList, ) -> PatId
fn collect_tuple_pat( &mut self, args: AstChildren<Pat>, has_leading_comma: bool, binding_list: &mut BindingList, ) -> (Box<[PatId]>, Option<u32>)
fn collect_pat_possibly_rest( &mut self, pat: Pat, binding_list: &mut BindingList, ) -> Either<PatId, ()> ⓘ
fn collect_ty_pat_opt(&mut self, pat: Option<Pat>) -> PatId
fn collect_ty_pat(&mut self, pat: Pat) -> PatId
fn lower_ty_pat_range_side(&mut self, pat: Pat) -> ExprId
Sourcefn lower_ty_pat_range_end(&mut self, lang_item: Option<ConstId>) -> ExprId
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.
Sourcefn lower_excluded_range_end(&mut self, pat: Pat) -> ExprId
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.
Sourcefn check_cfg(&mut self, owner: &dyn HasAttrs) -> bool
fn check_cfg(&mut self, owner: &dyn HasAttrs) -> bool
Returns false (and emits diagnostics) when owner if #[cfg]d out, and true when
not.
Sourcefn check_cfg_pred(&self, pred: Option<CfgPredicate>) -> bool
fn check_cfg_pred(&self, pred: Option<CfgPredicate>) -> bool
Used for cfg!(), conducting imprecise checks
fn add_definition_to_binding(&mut self, binding_id: BindingId, pat_id: PatId)
fn collect_label(&mut self, ast_label: Label) -> LabelId
fn resolve_label( &self, lifetime: Option<Lifetime>, ) -> Result<Option<LabelId>, ExpressionStoreDiagnostics>
fn is_label_valid_from_rib(&self, rib_index: usize) -> bool
fn pop_label_rib(&mut self)
fn with_label_rib<T>( &mut self, kind: RibKind, f: impl FnOnce(&mut Self) -> T, ) -> T
fn with_labeled_rib<T>( &mut self, label: LabelId, hygiene: HygieneId, f: impl FnOnce(&mut Self) -> T, ) -> T
fn with_opt_labeled_rib<T>( &mut self, label: Option<(HygieneId, LabelId)>, f: impl FnOnce(&mut Self) -> T, ) -> T
Sourcefn expand_macros_to_string(&mut self, expr: Expr) -> Option<(String, bool)>
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.
fn lang_path(&self, lang: Option<impl Into<LangItemTarget>>) -> Option<Path>
fn lang_path_expr(&self, lang: Option<impl Into<LangItemTarget>>) -> Expr
fn ty_rel_lang_path( &self, lang: Option<impl Into<LangItemTarget>>, relative_name: Symbol, ) -> Option<Path>
fn ty_rel_lang_path_expr( &self, lang: Option<impl Into<LangItemTarget>>, relative_name: Symbol, ) -> Expr
Source§impl<'db> ExprCollector<'db>
impl<'db> ExprCollector<'db>
fn features(&self) -> &'db UnstableFeatures
fn with_fresh_binding_expr_root( &mut self, f: impl FnOnce(&mut Self) -> ExprId, ) -> ExprId
fn with_expr_root(&mut self, f: impl FnOnce(&mut Self) -> ExprId) -> ExprId
fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId
fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId
fn alloc_expr_desugared_with_ptr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId
fn missing_expr(&mut self) -> ExprId
fn alloc_binding( &mut self, name: Name, mode: BindingAnnotation, hygiene: HygieneId, ) -> BindingId
fn alloc_pat_from_expr(&mut self, pat: Pat, ptr: ExprPtr) -> PatId
fn alloc_expr_from_pat(&mut self, expr: Expr, ptr: PatPtr) -> ExprId
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId
fn alloc_pat_desugared(&mut self, pat: Pat) -> PatId
fn missing_pat(&mut self) -> PatId
fn alloc_label(&mut self, label: Label, ptr: AstPtr<Label>) -> LabelId
fn alloc_label_desugared(&mut self, label: Label, ptr: LabelPtr) -> LabelId
fn is_lowering_awaitable_block(&self) -> &Awaitable
fn with_awaitable_block<T>( &mut self, awaitable: Awaitable, f: impl FnOnce(&mut Self) -> T, ) -> T
fn hygiene_id_for(&self, range: TextRange) -> HygieneId
fn with_lifetime_bound_scope<T>( &mut self, bound_scope: LifetimeBoundScope, f: impl FnOnce(&mut Self) -> T, ) -> T
fn for_path_type_projection<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T
fn push_named_target_lifetime(&mut self, id: LifetimeRefId)
fn is_argument_lt_bound_scope(&mut self) -> bool
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> 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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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