rustc_expand::base

Struct ExtCtxt

Source
pub struct ExtCtxt<'a> {
    pub sess: &'a Session,
    pub ecfg: ExpansionConfig<'a>,
    pub num_standard_library_imports: usize,
    pub reduced_recursion_limit: Option<(Limit, ErrorGuaranteed)>,
    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>§num_standard_library_imports: usize§reduced_recursion_limit: Option<(Limit, ErrorGuaranteed)>§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 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 macro_call( &self, span: Span, path: Path, delim: Delimiter, tokens: TokenStream, ) -> P<MacCall>

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, is_const: bool, ) -> PolyTraitRef

Source

pub fn trait_bound(&self, path: Path, is_const: bool) -> 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(&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_semi(&self, expr: P<Expr>) -> Stmt

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: ThinVec<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_macro_call(&self, span: Span, call: P<MacCall>) -> 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_method_call( &self, span: Span, expr: P<Expr>, ident: Ident, args: ThinVec<P<Expr>>, ) -> P<Expr>

Source

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

Source

pub fn expr_loop(&self, sp: Span, block: P<Block>) -> P<Expr>

Source

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

Source

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

Source

pub fn expr_call_global( &self, sp: Span, fn_path: Vec<Ident>, args: ThinVec<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: ThinVec<ExprField>, ) -> P<Expr>

Source

pub fn expr_struct_ident( &self, span: Span, id: Ident, fields: ThinVec<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_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<Expr>

Source

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

[expr1, expr2, ...]

Source

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

&[expr1, expr2, ...]

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: ThinVec<P<Expr>>) -> 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: BindingMode, ) -> 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: ThinVec<P<Pat>>, ) -> P<Pat>

Source

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

Source

pub fn pat_tuple(&self, span: Span, pats: ThinVec<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: ThinVec<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: ThinVec<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: ThinVec<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>, mutability: 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

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 dcx(&self) -> DiagCtxtHandle<'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 psess(&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 trace_macros_diag(&mut self)

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)

Auto Trait Implementations§

§

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

§

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

§

impl<'a> Freeze for ExtCtxt<'a>

§

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> Aligned for T

Source§

const ALIGN: Alignment = _

Alignment of Self.
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
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

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

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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: 296 bytes