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>
impl<'a> ExtCtxt<'a>
pub fn path(&self, span: Span, strs: Vec<Ident>) -> Path
pub fn path_ident(&self, span: Span, id: Ident) -> Path
pub fn path_global(&self, span: Span, strs: Vec<Ident>) -> Path
pub fn path_all( &self, span: Span, global: bool, idents: Vec<Ident>, args: Vec<GenericArg>, ) -> Path
pub fn macro_call( &self, span: Span, path: Path, delim: Delimiter, tokens: TokenStream, ) -> P<MacCall>
pub fn ty_mt(&self, ty: P<Ty>, mutbl: Mutability) -> MutTy
pub fn ty(&self, span: Span, kind: TyKind) -> P<Ty>
pub fn ty_infer(&self, span: Span) -> P<Ty>
pub fn ty_path(&self, path: Path) -> P<Ty>
pub fn ty_ident(&self, span: Span, ident: Ident) -> P<Ty>
pub fn anon_const(&self, span: Span, kind: ExprKind) -> AnonConst
pub fn const_ident(&self, span: Span, ident: Ident) -> AnonConst
pub fn ty_ref( &self, span: Span, ty: P<Ty>, lifetime: Option<Lifetime>, mutbl: Mutability, ) -> P<Ty>
pub fn ty_ptr(&self, span: Span, ty: P<Ty>, mutbl: Mutability) -> P<Ty>
pub fn typaram( &self, span: Span, ident: Ident, bounds: GenericBounds, default: Option<P<Ty>>, ) -> GenericParam
pub fn trait_ref(&self, path: Path) -> TraitRef
pub fn poly_trait_ref(&self, span: Span, path: Path) -> PolyTraitRef
pub fn trait_bound(&self, path: Path, is_const: bool) -> GenericBound
pub fn lifetime(&self, span: Span, ident: Ident) -> Lifetime
pub fn lifetime_static(&self, span: Span) -> Lifetime
pub fn stmt_expr(&self, expr: P<Expr>) -> Stmt
pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<Expr>) -> Stmt
pub fn stmt_let_ty( &self, sp: Span, mutbl: bool, ident: Ident, ty: Option<P<Ty>>, ex: P<Expr>, ) -> Stmt
sourcepub fn stmt_let_type_only(&self, span: Span, ty: P<Ty>) -> Stmt
pub fn stmt_let_type_only(&self, span: Span, ty: P<Ty>) -> Stmt
Generates let _: Type;
, which is usually used for type assertions.
pub fn stmt_local(&self, local: P<Local>, span: Span) -> Stmt
pub fn stmt_item(&self, sp: Span, item: P<Item>) -> Stmt
pub fn block_expr(&self, expr: P<Expr>) -> P<Block>
pub fn block(&self, span: Span, stmts: ThinVec<Stmt>) -> P<Block>
pub fn expr(&self, span: Span, kind: ExprKind) -> P<Expr>
pub fn expr_path(&self, path: Path) -> P<Expr>
pub fn expr_ident(&self, span: Span, id: Ident) -> P<Expr>
pub fn expr_self(&self, span: Span) -> P<Expr>
pub fn expr_macro_call(&self, span: Span, call: P<MacCall>) -> P<Expr>
pub fn expr_binary( &self, sp: Span, op: BinOpKind, lhs: P<Expr>, rhs: P<Expr>, ) -> P<Expr>
pub fn expr_deref(&self, sp: Span, e: P<Expr>) -> P<Expr>
pub fn expr_addr_of(&self, sp: Span, e: P<Expr>) -> P<Expr>
pub fn expr_paren(&self, sp: Span, e: P<Expr>) -> P<Expr>
pub fn expr_call( &self, span: Span, expr: P<Expr>, args: ThinVec<P<Expr>>, ) -> P<Expr>
pub fn expr_call_ident( &self, span: Span, id: Ident, args: ThinVec<P<Expr>>, ) -> P<Expr>
pub fn expr_call_global( &self, sp: Span, fn_path: Vec<Ident>, args: ThinVec<P<Expr>>, ) -> P<Expr>
pub fn expr_block(&self, b: P<Block>) -> P<Expr>
pub fn field_imm(&self, span: Span, ident: Ident, e: P<Expr>) -> ExprField
pub fn expr_struct( &self, span: Span, path: Path, fields: ThinVec<ExprField>, ) -> P<Expr>
pub fn expr_struct_ident( &self, span: Span, id: Ident, fields: ThinVec<ExprField>, ) -> P<Expr>
pub fn expr_usize(&self, span: Span, n: usize) -> P<Expr>
pub fn expr_u32(&self, span: Span, n: u32) -> P<Expr>
pub fn expr_bool(&self, span: Span, value: bool) -> P<Expr>
pub fn expr_str(&self, span: Span, s: Symbol) -> P<Expr>
pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<Expr>
sourcepub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<P<Expr>>) -> P<Expr>
pub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<P<Expr>>) -> P<Expr>
&[expr1, expr2, ...]
pub fn expr_some(&self, sp: Span, expr: P<Expr>) -> P<Expr>
pub fn expr_none(&self, sp: Span) -> P<Expr>
pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<P<Expr>>) -> P<Expr>
pub fn expr_unreachable(&self, span: Span) -> P<Expr>
pub fn expr_ok(&self, sp: Span, expr: P<Expr>) -> P<Expr>
pub fn expr_try(&self, sp: Span, head: P<Expr>) -> P<Expr>
pub fn pat(&self, span: Span, kind: PatKind) -> P<Pat>
pub fn pat_wild(&self, span: Span) -> P<Pat>
pub fn pat_lit(&self, span: Span, expr: P<Expr>) -> P<Pat>
pub fn pat_ident(&self, span: Span, ident: Ident) -> P<Pat>
pub fn pat_ident_binding_mode( &self, span: Span, ident: Ident, ann: BindingMode, ) -> P<Pat>
pub fn pat_path(&self, span: Span, path: Path) -> P<Pat>
pub fn pat_tuple_struct( &self, span: Span, path: Path, subpats: ThinVec<P<Pat>>, ) -> P<Pat>
pub fn pat_struct( &self, span: Span, path: Path, field_pats: ThinVec<PatField>, ) -> P<Pat>
pub fn pat_tuple(&self, span: Span, pats: ThinVec<P<Pat>>) -> P<Pat>
pub fn pat_some(&self, span: Span, pat: P<Pat>) -> P<Pat>
pub fn arm(&self, span: Span, pat: P<Pat>, expr: P<Expr>) -> Arm
pub fn arm_unreachable(&self, span: Span) -> Arm
pub fn expr_match( &self, span: Span, arg: P<Expr>, arms: ThinVec<Arm>, ) -> P<Expr>
pub fn expr_if( &self, span: Span, cond: P<Expr>, then: P<Expr>, els: Option<P<Expr>>, ) -> P<Expr>
pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: P<Expr>) -> P<Expr>
pub fn lambda0(&self, span: Span, body: P<Expr>) -> P<Expr>
pub fn lambda1(&self, span: Span, body: P<Expr>, ident: Ident) -> P<Expr>
pub fn lambda_stmts_1( &self, span: Span, stmts: ThinVec<Stmt>, ident: Ident, ) -> P<Expr>
pub fn param(&self, span: Span, ident: Ident, ty: P<Ty>) -> Param
pub fn fn_decl(&self, inputs: ThinVec<Param>, output: FnRetTy) -> P<FnDecl>
pub fn item( &self, span: Span, name: Ident, attrs: AttrVec, kind: ItemKind, ) -> P<Item>
pub fn item_static( &self, span: Span, name: Ident, ty: P<Ty>, mutability: Mutability, expr: P<Expr>, ) -> P<Item>
pub fn item_const( &self, span: Span, name: Ident, ty: P<Ty>, expr: P<Expr>, ) -> P<Item>
pub fn attr_word(&self, name: Symbol, span: Span) -> Attribute
pub fn attr_name_value_str( &self, name: Symbol, val: Symbol, span: Span, ) -> Attribute
pub fn attr_nested_word( &self, outer: Symbol, inner: Symbol, span: Span, ) -> Attribute
source§impl<'a> ExtCtxt<'a>
impl<'a> ExtCtxt<'a>
pub fn new( sess: &'a Session, ecfg: ExpansionConfig<'a>, resolver: &'a mut dyn ResolverExpand, lint_store: Option<&'a (dyn LintStoreExpand + 'a)>, ) -> ExtCtxt<'a>
pub fn dcx(&self) -> DiagCtxtHandle<'a>
sourcepub fn expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>
pub fn expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>
Returns a Folder
for deeply expanding all macros in an AST node.
sourcepub fn monotonic_expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>
pub fn monotonic_expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>
Returns a Folder
that deeply expands all macros and assigns all NodeId
s in an AST node.
Once NodeId
s are assigned, the node may not be expanded, removed, or otherwise modified.
pub fn new_parser_from_tts(&self, stream: TokenStream) -> Parser<'a>
pub fn source_map(&self) -> &'a SourceMap
pub fn psess(&self) -> &'a ParseSess
pub fn call_site(&self) -> Span
sourcepub(crate) fn expansion_descr(&self) -> String
pub(crate) fn expansion_descr(&self) -> String
Returns the current expansion kind’s description.
sourcepub fn with_def_site_ctxt(&self, span: Span) -> Span
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.
sourcepub fn with_call_site_ctxt(&self, span: Span) -> Span
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.
sourcepub fn with_mixed_site_ctxt(&self, span: Span) -> Span
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.
sourcepub fn expansion_cause(&self) -> Option<Span>
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.
pub fn trace_macros_diag(&mut self)
pub fn trace_macros(&self) -> bool
pub fn set_trace_macros(&mut self, x: bool)
pub fn std_path(&self, components: &[Symbol]) -> Vec<Ident>
pub fn def_site_path(&self, components: &[Symbol]) -> Vec<Ident>
pub fn check_unused_macros(&mut self)
Auto Trait Implementations§
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> 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
source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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 moresource§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
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