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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use marker_adapter::context::AstMapDriver;
use marker_api::{
    ast::{EnumVariant, ItemField},
    common::Level,
    prelude::*,
};

use super::RustcContext;

impl<'ast, 'tcx: 'ast> AstMapDriver<'ast> for RustcContext<'ast, 'tcx> {
    fn item(&'ast self, id: ItemId) -> Option<ItemKind<'ast>> {
        let rustc_id = self.rustc_converter.to_item_id(id);
        self.marker_converter.item(rustc_id)
    }

    fn variant(&'ast self, id: VariantId) -> Option<&'ast EnumVariant<'ast>> {
        self.marker_converter.variant(id)
    }

    fn field(&'ast self, id: FieldId) -> Option<&'ast ItemField<'ast>> {
        self.marker_converter.field(id)
    }

    fn body(&'ast self, id: BodyId) -> &'ast ast::Body<'ast> {
        let rustc_id = self.rustc_converter.to_body_id(id);
        self.marker_converter.body(rustc_id)
    }

    fn stmt(&'ast self, id: StmtId) -> StmtKind<'ast> {
        let rustc_id = self.rustc_converter.to_hir_id(id);
        match self.marker_converter.stmt(rustc_id) {
            Some(stmt) => stmt,
            None => unreachable!(
                "the `HirId` belongs to a valid statement, since it comes from a `StmtId`. (HirId: {rustc_id:?})"
            ),
        }
    }

    fn expr(&'ast self, id: ExprId) -> ExprKind<'ast> {
        let rustc_id = self.rustc_converter.to_hir_id(id);
        match self.marker_converter.expr(rustc_id) {
            Some(expr) => expr,
            None => unreachable!(
                "the `HirId` belongs to a valid expression, since it comes from a `ExprId`. (HirId: {rustc_id:?})"
            ),
        }
    }

    fn lint_level_at(&'ast self, api_lint: &'static Lint, node: NodeId) -> Level {
        if let Some(id) = self.rustc_converter.try_to_hir_id_from_emission_node(node) {
            let lint = self.rustc_converter.to_lint(api_lint);
            let level = self.rustc_cx.lint_level_at_node(lint, id).0;
            self.marker_converter.to_lint_level(level)
        } else {
            Level::Allow
        }
    }
}