about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/assert/context.rs
blob: 8d187a4be8aee93be6fca8f36fb215ea929c9e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use rustc_ast::{ptr::P, Expr, Path};
use rustc_expand::base::ExtCtxt;
use rustc_span::Span;

pub(super) struct Context<'cx, 'a> {
    cx: &'cx ExtCtxt<'a>,
    span: Span,
}

impl<'cx, 'a> Context<'cx, 'a> {
    pub(super) fn new(cx: &'cx ExtCtxt<'a>, span: Span) -> Self {
        Self { cx, span }
    }

    /// Builds the whole `assert!` expression.
    ///
    /// {
    ///    use ::core::asserting::{ ... };
    ///
    ///    let mut __capture0 = Capture::new();
    ///    ...
    ///    ...
    ///    ...
    ///
    ///    if !{
    ///       ...
    ///       ...
    ///       ...
    ///    } {
    ///        panic!(
    ///            "Assertion failed: ... \n With expansion: ...",
    ///            __capture0,
    ///            ...
    ///            ...
    ///            ...
    ///        );
    ///    }
    /// }
    pub(super) fn build(self, _cond_expr: P<Expr>, _panic_path: Path) -> P<Expr> {
        let Self { cx, span, .. } = self;
        let stmts = Vec::new();
        cx.expr_block(cx.block(span, stmts))
    }
}