Struct syntax::ext::base::ExtCtxtUnstable
[-] [+]
[src]
pub struct ExtCtxt<'a> { pub parse_sess: &'a ParseSess, pub cfg: CrateConfig, pub backtrace: ExpnId, pub ecfg: ExpansionConfig<'a>, pub use_std: bool, pub mod_path: Vec<Ident>, pub trace_mac: bool, pub exported_macros: Vec<MacroDef>, pub syntax_env: SyntaxEnv, pub recursion_count: usize, }
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_info of their expansion context stored into their span.
Fields
parse_sess | |
cfg | |
backtrace | |
ecfg | |
use_std | |
mod_path | |
trace_mac | |
exported_macros | |
syntax_env | |
recursion_count |
Methods
impl<'a> ExtCtxt<'a>
fn new(parse_sess: &'a ParseSess, cfg: CrateConfig, ecfg: ExpansionConfig<'a>) -> ExtCtxt<'a>
fn expand_expr(&mut self, e: P<Expr>) -> P<Expr>
fn expander<'b>(&'b mut self) -> MacroExpander<'b, 'a>
Returns a Folder
for deeply expanding all macros in a AST node.
fn new_parser_from_tts(&self, tts: &[TokenTree]) -> Parser<'a>
fn codemap(&self) -> &'a CodeMap
fn parse_sess(&self) -> &'a ParseSess
fn cfg(&self) -> CrateConfig
fn call_site(&self) -> Span
fn print_backtrace(&self)
fn backtrace(&self) -> ExpnId
fn original_span(&self) -> Span
fn original_span_in_file(&self) -> Span
fn mod_push(&mut self, i: Ident)
fn mod_pop(&mut self)
fn mod_path(&self) -> Vec<Ident>
fn bt_push(&mut self, ei: ExpnInfo)
fn bt_pop(&mut self)
fn insert_macro(&mut self, def: MacroDef)
fn span_fatal(&self, sp: Span, msg: &str) -> !
Emit msg
attached to sp
, and stop compilation immediately.
span_err
should be strongly preferred where-ever possible:
this should only be used when
- continuing has a high risk of flow-on errors (e.g. errors in
declaring a macro would cause all uses of that macro to
complain about "undefined macro"), or
- there is literally nothing else that can be done (however,
in most cases one can construct a dummy expression/item to
substitute; we never hit resolve/type-checking so the dummy
value doesn't have to match anything)
fn span_err(&self, sp: Span, 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).
fn span_warn(&self, sp: Span, msg: &str)
fn span_unimpl(&self, sp: Span, msg: &str) -> !
fn span_bug(&self, sp: Span, msg: &str) -> !
fn span_note(&self, sp: Span, msg: &str)
fn span_help(&self, sp: Span, msg: &str)
fn bug(&self, msg: &str) -> !
fn trace_macros(&self) -> bool
fn set_trace_macros(&mut self, x: bool)
fn ident_of(&self, st: &str) -> Ident
fn ident_of_std(&self, st: &str) -> Ident
fn name_of(&self, st: &str) -> Name
Trait Implementations
impl<'a> AstBuilder for ExtCtxt<'a>
fn path(&self, span: Span, strs: Vec<Ident>) -> Path
fn path_ident(&self, span: Span, id: Ident) -> Path
fn path_global(&self, span: Span, strs: Vec<Ident>) -> Path
fn path_all(&self, sp: Span, global: bool, idents: Vec<Ident>, lifetimes: Vec<Lifetime>, types: Vec<P<Ty>>, bindings: Vec<P<TypeBinding>>) -> Path
fn qpath(&self, self_type: P<Ty>, trait_ref: P<TraitRef>, ident: Ident) -> P<QPath>
Constructs a qualified path.
Constructs a path like <self_type as trait_ref>::ident
.
fn qpath_all(&self, self_type: P<Ty>, trait_ref: P<TraitRef>, ident: Ident, lifetimes: Vec<Lifetime>, types: Vec<P<Ty>>, bindings: Vec<P<TypeBinding>>) -> P<QPath>
Constructs a qualified path.
Constructs a path like <self_type as trait_ref>::ident<a, T, A=Bar>
.
fn ty_mt(&self, ty: P<Ty>, mutbl: Mutability) -> MutTy
fn ty(&self, span: Span, ty: Ty_) -> P<Ty>
fn ty_path(&self, path: Path) -> P<Ty>
fn ty_sum(&self, path: Path, bounds: OwnedSlice<TyParamBound>) -> P<Ty>
fn ty_ident(&self, span: Span, ident: Ident) -> P<Ty>
fn ty_rptr(&self, span: Span, ty: P<Ty>, lifetime: Option<Lifetime>, mutbl: Mutability) -> P<Ty>
fn ty_ptr(&self, span: Span, ty: P<Ty>, mutbl: Mutability) -> P<Ty>
fn ty_option(&self, ty: P<Ty>) -> P<Ty>
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<Ty>) -> TypeField
fn ty_infer(&self, span: Span) -> P<Ty>
fn typaram(&self, span: Span, id: Ident, bounds: OwnedSlice<TyParamBound>, default: Option<P<Ty>>) -> TyParam
fn ty_vars(&self, ty_params: &OwnedSlice<TyParam>) -> Vec<P<Ty>>
fn ty_vars_global(&self, ty_params: &OwnedSlice<TyParam>) -> Vec<P<Ty>>
fn trait_ref(&self, path: Path) -> TraitRef
fn poly_trait_ref(&self, span: Span, path: Path) -> PolyTraitRef
fn typarambound(&self, path: Path) -> TyParamBound
fn lifetime(&self, span: Span, name: Name) -> Lifetime
fn lifetime_def(&self, span: Span, name: Name, bounds: Vec<Lifetime>) -> LifetimeDef
fn stmt_expr(&self, expr: P<Expr>) -> P<Stmt>
fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<Expr>) -> P<Stmt>
fn stmt_let_typed(&self, sp: Span, mutbl: bool, ident: Ident, typ: P<Ty>, ex: P<Expr>) -> P<Stmt>
fn block(&self, span: Span, stmts: Vec<P<Stmt>>, expr: Option<P<Expr>>) -> P<Block>
fn stmt_item(&self, sp: Span, item: P<Item>) -> P<Stmt>
fn block_expr(&self, expr: P<Expr>) -> P<Block>
fn block_all(&self, span: Span, stmts: Vec<P<Stmt>>, expr: Option<P<Expr>>) -> P<Block>
fn expr(&self, span: Span, node: Expr_) -> P<Expr>
fn expr_path(&self, path: Path) -> P<Expr>
fn expr_qpath(&self, span: Span, qpath: P<QPath>) -> P<Expr>
Constructs a QPath expression.