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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! The failure type for an ahead-of-time compile.
use CodegenError;
use fmt;
use LinkError;
/// The reason an ahead-of-time compile could not be completed.
///
/// A compile runs two stages — lower each function to object code, then link the
/// objects into an image — and either stage can fail. The two variants keep the
/// origin of a failure visible instead of flattening both into one opaque message,
/// and each carries the underlying error so the exact cause can be inspected or
/// reported without guesswork.
///
/// `AotError` implements [`Display`](fmt::Display) and
/// [`core::error::Error`], with [`source`](core::error::Error::source) set to the
/// wrapped error, and converts from both underlying errors so `?` propagates them
/// directly. The enum is `#[non_exhaustive]`: a later stage that reports a new kind
/// of failure is an additive change, so a `match` on it must keep a wildcard arm.
///
/// # Examples
///
/// A malformed function is rejected during lowering, before any linking happens:
///
/// ```
/// use aot_lang::{compile, AotError};
/// use ir_lang::{Builder, Type};
///
/// // Declares an int return but never returns a value.
/// let func = Builder::new("bad", &[], Type::Int).finish();
///
/// assert!(matches!(compile(&func), Err(AotError::Codegen(_))));
/// ```
///
/// Inspect the source through the [`Error`](core::error::Error) trait:
///
/// ```
/// use aot_lang::compile;
/// use core::error::Error;
/// use ir_lang::{Builder, Type};
///
/// let func = Builder::new("bad", &[], Type::Int).finish();
/// let err = compile(&func).unwrap_err();
/// assert!(err.source().is_some());
/// ```