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
sourceimpl<'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>
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 parse_sess(&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 struct_span_err<S: Into<MultiSpan>>(
&self,
sp: S,
msg: &str
) -> DiagnosticBuilder<'a, ErrorGuaranteed>
pub fn create_err(
&self,
err: impl SessionDiagnostic<'a>
) -> DiagnosticBuilder<'a, ErrorGuaranteed>
pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed
sourcepub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str)
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).
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str)
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> !
pub fn trace_macros_diag(&mut self)
pub fn bug(&self, msg: &str) -> !
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)
sourceimpl<'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 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_rptr(
&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) -> 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_pat(&self, sp: Span, pat: P<Pat>, ex: 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
pub fn stmt_let_type_only(&self, span: Span, ty: P<Ty>) -> Stmt
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: Vec<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_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_call(&self, span: Span, expr: P<Expr>, args: Vec<P<Expr>>) -> P<Expr>
pub fn expr_call_ident(&self, span: Span, id: Ident, args: Vec<P<Expr>>) -> P<Expr>
pub fn expr_call_global(
&self,
sp: Span,
fn_path: Vec<Ident>,
args: Vec<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: Vec<ExprField>
) -> P<Expr>
pub fn expr_struct_ident(
&self,
span: Span,
id: Ident,
fields: Vec<ExprField>
) -> P<Expr>
fn expr_lit(&self, span: Span, lit_kind: LitKind) -> P<Expr>
pub fn expr_usize(&self, span: Span, i: usize) -> P<Expr>
pub fn expr_u32(&self, sp: Span, u: u32) -> P<Expr>
pub fn expr_bool(&self, sp: Span, value: bool) -> P<Expr>
pub fn expr_str(&self, sp: Span, s: Symbol) -> P<Expr>
pub fn expr_char(&self, sp: Span, ch: char) -> P<Expr>
pub fn expr_byte_str(&self, sp: Span, bytes: Vec<u8>) -> P<Expr>
pub fn expr_cast(&self, sp: Span, expr: P<Expr>, ty: P<Ty>) -> P<Expr>
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: Vec<P<Expr>>) -> P<Expr>
pub fn expr_fail(&self, span: Span, msg: Symbol) -> 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: BindingAnnotation
) -> P<Pat>
pub fn pat_path(&self, span: Span, path: Path) -> P<Pat>
pub fn pat_tuple_struct(
&self,
span: Span,
path: Path,
subpats: Vec<P<Pat>>
) -> P<Pat>
pub fn pat_struct(
&self,
span: Span,
path: Path,
field_pats: Vec<PatField>
) -> P<Pat>
pub fn pat_tuple(&self, span: Span, pats: Vec<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: Vec<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: Vec<Stmt>, ident: Ident) -> P<Expr>
pub fn param(&self, span: Span, ident: Ident, ty: P<Ty>) -> Param
pub fn fn_decl(&self, inputs: Vec<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>,
mutbl: 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 attribute(&self, mi: MetaItem) -> Attribute
pub fn meta_word(&self, sp: Span, w: Symbol) -> MetaItem
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut 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: 304 bytes