Skip to main content

create_anon_const

Function create_anon_const 

Source
pub(crate) fn create_anon_const<'a, 'db>(
    interner: DbInterner<'db>,
    owner: ExpressionStoreOwnerId,
    store: &ExpressionStore,
    expr_id: ExprId,
    resolver: &Resolver<'db>,
    expected_ty: Ty<'db>,
    generics: &dyn Fn() -> &'a Generics<'db>,
    create_var: Option<&mut dyn FnMut(Span) -> Const<'db>>,
    lowering_mode: LoweringMode,
    forbid_params_after: Option<u32>,
    allow_anon_const_using_generic_params: bool,
) -> Result<Const<'db>, CreateConstError<'db>>
Expand description

forbid_params_after and allow_anon_const_using_generic_params fill a similar role, but are not the same.

forbid_params_after is only respected if an anon const is not created, that is, we directly resolve to a const param. allow_anon_const_using_generic_params is only respected if an anon const is created.

For example, inside types, you are allowed to refer to const params in bare paths (but might be forbidden from referring to some, in param defaults), but not allowed to do so in anon consts (e.g. { {}; N } is forbidden, because it creates an anon const). Inside field defaults, you are allowed to refer to them even inside anon consts.

There’s also generic_const_exprs, min_generic_const_args, and generic_const_args, all of which we don’t implement yet.