Struct rustc_expand::base::ExtCtxt

source ·
pub struct ExtCtxt<'a> {
    pub sess: &'a Session,
    pub ecfg: ExpansionConfig<'a>,
    pub reduced_recursion_limit: Option<Limit>,
    pub root_path: PathBuf,
    pub resolver: &'a mut dyn ResolverExpand,
    pub current_expansion: ExpansionData,
    pub force_mode: bool,
    pub expansions: FxIndexMap<Span, Vec<String>>,
    pub(crate) lint_store: Option<&'a (dyn LintStoreExpand + 'a)>,
    pub buffered_early_lint: Vec<BufferedEarlyLint>,
    pub(crate) expanded_inert_attrs: MarkedAttrs,
}
Expand description

One of these is made during expansion and incrementally updated as we go; when a macro expansion occurs, the resulting nodes have the backtrace() -> expn_data of their expansion context stored into their span.

Fields§

§sess: &'a Session§ecfg: ExpansionConfig<'a>§reduced_recursion_limit: Option<Limit>§root_path: PathBuf§resolver: &'a mut dyn ResolverExpand§current_expansion: ExpansionData§force_mode: bool

Error recovery mode entered when expansion is stuck (or during eager expansion, but that’s a hack).

§expansions: FxIndexMap<Span, Vec<String>>§lint_store: Option<&'a (dyn LintStoreExpand + 'a)>

Used for running pre-expansion lints on freshly loaded modules.

§buffered_early_lint: Vec<BufferedEarlyLint>

Used for storing lints generated during expansion, like NAMED_ARGUMENTS_USED_POSITIONALLY

§expanded_inert_attrs: MarkedAttrs

When we ‘expand’ an inert attribute, we leave it in the AST, but insert it here so that we know not to expand it again.

Implementations§

source§

impl<'a> ExtCtxt<'a>

source

pub fn new(
    sess: &'a Session,
    ecfg: ExpansionConfig<'a>,
    resolver: &'a mut dyn ResolverExpand,
    lint_store: Option<&'a (dyn LintStoreExpand + 'a)>
) -> ExtCtxt<'a>

source

pub fn expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>

Returns a Folder for deeply expanding all macros in an AST node.

source

pub fn monotonic_expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>

Returns a Folder that deeply expands all macros and assigns all NodeIds in an AST node. Once NodeIds are assigned, the node may not be expanded, removed, or otherwise modified.

source

pub fn new_parser_from_tts(&self, stream: TokenStream) -> Parser<'a>

source

pub fn source_map(&self) -> &'a SourceMap

source

pub fn parse_sess(&self) -> &'a ParseSess

source

pub fn call_site(&self) -> Span

source

pub(crate) fn expansion_descr(&self) -> String

Returns the current expansion kind’s description.

source

pub fn with_def_site_ctxt(&self, span: Span) -> Span

Equivalent of Span::def_site from the proc macro API, except that the location is taken from the span passed as an argument.

source

pub fn with_call_site_ctxt(&self, span: Span) -> Span

Equivalent of Span::call_site from the proc macro API, except that the location is taken from the span passed as an argument.

source

pub fn with_mixed_site_ctxt(&self, span: Span) -> Span

Equivalent of Span::mixed_site from the proc macro API, except that the location is taken from the span passed as an argument.

source

pub fn expansion_cause(&self) -> Option<Span>

Returns span for the macro which originally caused the current expansion to happen.

Stops backtracing at include! boundary.

source

pub fn struct_span_err<S: Into<MultiSpan>>(
    &self,
    sp: S,
    msg: &str
) -> DiagnosticBuilder<'a, ErrorGuaranteed>

source

pub fn create_err(
    &self,
    err: impl IntoDiagnostic<'a>
) -> DiagnosticBuilder<'a, ErrorGuaranteed>

source

pub fn emit_err(&self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed

source

pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str)

Emit msg attached to sp, without immediately stopping compilation.

Compilation will be stopped in the near future (at the end of the macro expansion phase).

source

pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str)

source

pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> !

source

pub fn trace_macros_diag(&mut self)

source

pub fn bug(&self, msg: &str) -> !

source

pub fn trace_macros(&self) -> bool

source

pub fn set_trace_macros(&mut self, x: bool)

source

pub fn std_path(&self, components: &[Symbol]) -> Vec<Ident>

source

pub fn def_site_path(&self, components: &[Symbol]) -> Vec<Ident>

source

pub fn check_unused_macros(&mut self)

source§

impl<'a> ExtCtxt<'a>

source

pub fn path(&self, span: Span, strs: Vec<Ident>) -> Path

source

pub fn path_ident(&self, span: Span, id: Ident) -> Path

source

pub fn path_global(&self, span: Span, strs: Vec<Ident>) -> Path

source

pub fn path_all(
    &self,
    span: Span,
    global: bool,
    idents: Vec<Ident>,
    args: Vec<GenericArg>
) -> Path

source

pub fn ty_mt(&self, ty: P<Ty>, mutbl: Mutability) -> MutTy

source

pub fn ty(&self, span: Span, kind: TyKind) -> P<Ty>

source

pub fn ty_infer(&self, span: Span) -> P<Ty>

source

pub fn ty_path(&self, path: Path) -> P<Ty>

source

pub fn ty_ident(&self, span: Span, ident: Ident) -> P<Ty>

source

pub fn anon_const(&self, span: Span, kind: ExprKind) -> AnonConst

source

pub fn const_ident(&self, span: Span, ident: Ident) -> AnonConst

source

pub fn ty_ref(
    &self,
    span: Span,
    ty: P<Ty>,
    lifetime: Option<Lifetime>,
    mutbl: Mutability
) -> P<Ty>

source

pub fn ty_ptr(&self, span: Span, ty: P<Ty>, mutbl: Mutability) -> P<Ty>

source

pub fn typaram(
    &self,
    span: Span,
    ident: Ident,
    bounds: GenericBounds,
    default: Option<P<Ty>>
) -> GenericParam

source

pub fn trait_ref(&self, path: Path) -> TraitRef

source

pub fn poly_trait_ref(&self, span: Span, path: Path) -> PolyTraitRef

source

pub fn trait_bound(&self, path: Path) -> GenericBound

source

pub fn lifetime(&self, span: Span, ident: Ident) -> Lifetime

source

pub fn lifetime_static(&self, span: Span) -> Lifetime

source

pub fn stmt_expr(&self, expr: P<Expr>) -> Stmt

source

pub fn stmt_let_pat(&self, sp: Span, pat: P<Pat>, ex: P<Expr>) -> Stmt

source

pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<Expr>) -> Stmt

source

pub fn stmt_let_ty(
    &self,
    sp: Span,
    mutbl: bool,
    ident: Ident,
    ty: Option<P<Ty>>,
    ex: P<Expr>
) -> Stmt

source

pub fn stmt_let_type_only(&self, span: Span, ty: P<Ty>) -> Stmt

Generates let _: Type;, which is usually used for type assertions.

source

pub fn stmt_local(&self, local: P<Local>, span: Span) -> Stmt

source

pub fn stmt_item(&self, sp: Span, item: P<Item>) -> Stmt

source

pub fn block_expr(&self, expr: P<Expr>) -> P<Block>

source

pub fn block(&self, span: Span, stmts: Vec<Stmt>) -> P<Block>

source

pub fn expr(&self, span: Span, kind: ExprKind) -> P<Expr>

source

pub fn expr_path(&self, path: Path) -> P<Expr>

source

pub fn expr_ident(&self, span: Span, id: Ident) -> P<Expr>

source

pub fn expr_self(&self, span: Span) -> P<Expr>

source

pub fn expr_field(&self, span: Span, expr: P<Expr>, field: Ident) -> P<Expr>

source

pub fn expr_binary(
    &self,
    sp: Span,
    op: BinOpKind,
    lhs: P<Expr>,
    rhs: P<Expr>
) -> P<Expr>

source

pub fn expr_deref(&self, sp: Span, e: P<Expr>) -> P<Expr>

source

pub fn expr_addr_of(&self, sp: Span, e: P<Expr>) -> P<Expr>

source

pub fn expr_paren(&self, sp: Span, e: P<Expr>) -> P<Expr>

source

pub fn expr_call(&self, span: Span, expr: P<Expr>, args: Vec<P<Expr>>) -> P<Expr>

source

pub fn expr_call_ident(&self, span: Span, id: Ident, args: Vec<P<Expr>>) -> P<Expr>

source

pub fn expr_call_global(
    &self,
    sp: Span,
    fn_path: Vec<Ident>,
    args: Vec<P<Expr>>
) -> P<Expr>

source

pub fn expr_block(&self, b: P<Block>) -> P<Expr>

source

pub fn field_imm(&self, span: Span, ident: Ident, e: P<Expr>) -> ExprField

source

pub fn expr_struct(
    &self,
    span: Span,
    path: Path,
    fields: Vec<ExprField>
) -> P<Expr>

source

pub fn expr_struct_ident(
    &self,
    span: Span,
    id: Ident,
    fields: Vec<ExprField>
) -> P<Expr>

source

pub fn expr_usize(&self, span: Span, n: usize) -> P<Expr>

source

pub fn expr_u32(&self, span: Span, n: u32) -> P<Expr>

source

pub fn expr_bool(&self, span: Span, value: bool) -> P<Expr>

source

pub fn expr_str(&self, span: Span, s: Symbol) -> P<Expr>

source

pub fn expr_char(&self, span: Span, ch: char) -> P<Expr>

source

pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<Expr>

source

pub fn expr_array(&self, sp: Span, exprs: Vec<P<Expr>>) -> P<Expr>

[expr1, expr2, ...]

source

pub fn expr_array_ref(&self, sp: Span, exprs: Vec<P<Expr>>) -> P<Expr>

&[expr1, expr2, ...]

source

pub fn expr_cast(&self, sp: Span, expr: P<Expr>, ty: P<Ty>) -> P<Expr>

source

pub fn expr_some(&self, sp: Span, expr: P<Expr>) -> P<Expr>

source

pub fn expr_none(&self, sp: Span) -> P<Expr>

source

pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<Expr>>) -> P<Expr>

source

pub fn expr_fail(&self, span: Span, msg: Symbol) -> P<Expr>

source

pub fn expr_unreachable(&self, span: Span) -> P<Expr>

source

pub fn expr_ok(&self, sp: Span, expr: P<Expr>) -> P<Expr>

source

pub fn expr_try(&self, sp: Span, head: P<Expr>) -> P<Expr>

source

pub fn pat(&self, span: Span, kind: PatKind) -> P<Pat>

source

pub fn pat_wild(&self, span: Span) -> P<Pat>

source

pub fn pat_lit(&self, span: Span, expr: P<Expr>) -> P<Pat>

source

pub fn pat_ident(&self, span: Span, ident: Ident) -> P<Pat>

source

pub fn pat_ident_binding_mode(
    &self,
    span: Span,
    ident: Ident,
    ann: BindingAnnotation
) -> P<Pat>

source

pub fn pat_path(&self, span: Span, path: Path) -> P<Pat>

source

pub fn pat_tuple_struct(
    &self,
    span: Span,
    path: Path,
    subpats: Vec<P<Pat>>
) -> P<Pat>

source

pub fn pat_struct(
    &self,
    span: Span,
    path: Path,
    field_pats: Vec<PatField>
) -> P<Pat>

source

pub fn pat_tuple(&self, span: Span, pats: Vec<P<Pat>>) -> P<Pat>

source

pub fn pat_some(&self, span: Span, pat: P<Pat>) -> P<Pat>

source

pub fn arm(&self, span: Span, pat: P<Pat>, expr: P<Expr>) -> Arm

source

pub fn arm_unreachable(&self, span: Span) -> Arm

source

pub fn expr_match(&self, span: Span, arg: P<Expr>, arms: Vec<Arm>) -> P<Expr>

source

pub fn expr_if(
    &self,
    span: Span,
    cond: P<Expr>,
    then: P<Expr>,
    els: Option<P<Expr>>
) -> P<Expr>

source

pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: P<Expr>) -> P<Expr>

source

pub fn lambda0(&self, span: Span, body: P<Expr>) -> P<Expr>

source

pub fn lambda1(&self, span: Span, body: P<Expr>, ident: Ident) -> P<Expr>

source

pub fn lambda_stmts_1(&self, span: Span, stmts: Vec<Stmt>, ident: Ident) -> P<Expr>

source

pub fn param(&self, span: Span, ident: Ident, ty: P<Ty>) -> Param

source

pub fn fn_decl(&self, inputs: Vec<Param>, output: FnRetTy) -> P<FnDecl>

source

pub fn item(
    &self,
    span: Span,
    name: Ident,
    attrs: AttrVec,
    kind: ItemKind
) -> P<Item>

source

pub fn item_static(
    &self,
    span: Span,
    name: Ident,
    ty: P<Ty>,
    mutbl: Mutability,
    expr: P<Expr>
) -> P<Item>

source

pub fn item_const(
    &self,
    span: Span,
    name: Ident,
    ty: P<Ty>,
    expr: P<Expr>
) -> P<Item>

source

pub fn attr_word(&self, name: Symbol, span: Span) -> Attribute

source

pub fn attr_name_value_str(
    &self,
    name: Symbol,
    val: Symbol,
    span: Span
) -> Attribute

source

pub fn attr_nested_word(
    &self,
    outer: Symbol,
    inner: Symbol,
    span: Span
) -> Attribute

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ExtCtxt<'a>

§

impl<'a> !Send for ExtCtxt<'a>

§

impl<'a> !Sync for ExtCtxt<'a>

§

impl<'a> Unpin for ExtCtxt<'a>

§

impl<'a> !UnwindSafe for ExtCtxt<'a>

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 304 bytes