1
1
use crate :: ast;
2
- use crate :: ir_value:: IrValue ;
3
2
use crate :: unit_builder:: UnitBuilderError ;
4
- use crate :: { ParseError , ParseErrorKind , Spanned } ;
5
- use runestick:: { AccessError , CompileMeta , Item , SourceId , Span , TypeInfo , TypeOf } ;
3
+ use crate :: {
4
+ IrError , IrErrorKind , ParseError , ParseErrorKind , QueryError , QueryErrorKind , Spanned ,
5
+ } ;
6
+ use runestick:: { CompileMeta , Item , SourceId , Span } ;
6
7
use std:: error;
7
8
use std:: fmt;
8
9
use std:: io;
9
10
use std:: path:: PathBuf ;
10
11
use thiserror:: Error ;
11
12
12
13
/// A compile result.
13
- pub type CompileResult < T , E = CompileError > = std:: result:: Result < T , E > ;
14
+ pub type CompileResult < T > = std:: result:: Result < T , CompileError > ;
14
15
15
16
/// An error raised during compiling.
16
17
#[ derive( Debug ) ]
@@ -32,7 +33,7 @@ impl CompileError {
32
33
}
33
34
}
34
35
35
- /// Get the kind of the cmopile error.
36
+ /// Get the kind of the compile error.
36
37
pub fn kind ( & self ) -> & CompileErrorKind {
37
38
& self . kind
38
39
}
@@ -75,29 +76,6 @@ impl CompileError {
75
76
CompileError :: new ( spanned, CompileErrorKind :: ConstError { msg } )
76
77
}
77
78
78
- /// An error raised when we expect a certain constant value but get another.
79
- pub fn const_expected < S , E > ( spanned : S , actual : & IrValue ) -> Self
80
- where
81
- S : Spanned ,
82
- E : TypeOf ,
83
- {
84
- CompileError :: new (
85
- spanned,
86
- CompileErrorKind :: ConstExpectedValue {
87
- expected : E :: type_info ( ) ,
88
- actual : actual. type_info ( ) ,
89
- } ,
90
- )
91
- }
92
-
93
- /// Construct an access error.
94
- pub fn access < S > ( spanned : S , error : AccessError ) -> Self
95
- where
96
- S : Spanned ,
97
- {
98
- Self :: new ( spanned, CompileErrorKind :: AccessError { error } )
99
- }
100
-
101
79
/// Construct an experimental error.
102
80
///
103
81
/// This should be used when an experimental feature is used which hasn't
@@ -149,37 +127,57 @@ impl From<UnitBuilderError> for CompileError {
149
127
}
150
128
}
151
129
130
+ impl From < IrError > for CompileError {
131
+ fn from ( error : IrError ) -> Self {
132
+ CompileError {
133
+ span : error. span ( ) ,
134
+ kind : CompileErrorKind :: IrError {
135
+ error : error. into_kind ( ) ,
136
+ } ,
137
+ }
138
+ }
139
+ }
140
+
141
+ impl From < QueryError > for CompileError {
142
+ fn from ( error : QueryError ) -> Self {
143
+ CompileError {
144
+ span : error. span ( ) ,
145
+ kind : CompileErrorKind :: QueryError {
146
+ error : error. into_kind ( ) ,
147
+ } ,
148
+ }
149
+ }
150
+ }
151
+
152
152
/// Error when encoding AST.
153
153
#[ derive( Debug , Error ) ]
154
154
pub enum CompileErrorKind {
155
- /// An access error raised during compilation, usually happens during
156
- /// constant evaluation.
157
- #[ error( "access error: {error}" ) ]
158
- AccessError {
159
- /// The source error.
160
- #[ source]
161
- error : AccessError ,
162
- } ,
163
155
/// An internal encoder invariant was broken.
164
156
#[ error( "internal compiler error: {msg}" ) ]
165
157
Internal {
166
158
/// The message of the internal error.
167
159
msg : & ' static str ,
168
160
} ,
161
+ /// Encountered an ir error.
162
+ #[ error( "ir error: {error}" ) ]
163
+ IrError {
164
+ /// The source error.
165
+ #[ source]
166
+ error : IrErrorKind ,
167
+ } ,
168
+ /// Encountered a query error.
169
+ #[ error( "query error: {error}" ) ]
170
+ QueryError {
171
+ /// The source error.
172
+ #[ source]
173
+ error : QueryErrorKind ,
174
+ } ,
169
175
/// A constant evaluation errored.
170
176
#[ error( "error during constant evaluation: {msg}" ) ]
171
177
ConstError {
172
178
/// Message describing the error.
173
179
msg : & ' static str ,
174
180
} ,
175
- /// A constant evaluation errored.
176
- #[ error( "expected a value of type {expected} but got {actual}" ) ]
177
- ConstExpectedValue {
178
- /// The expected value.
179
- expected : TypeInfo ,
180
- /// The value we got instead.
181
- actual : TypeInfo ,
182
- } ,
183
181
/// Trying to use an experimental feature which was not enabled.
184
182
#[ error( "experimental feature: {msg}" ) ]
185
183
Experimental {
@@ -400,9 +398,6 @@ pub enum CompileErrorKind {
400
398
/// The pattern is not supported as a binding.
401
399
#[ error( "not a valid binding" ) ]
402
400
UnsupportedBinding ,
403
- /// Error raised when trying to use a break outside of a loop.
404
- #[ error( "break outside of supported loop" ) ]
405
- BreakOutsideOfLoop ,
406
401
/// Attempting to use a float in a match pattern.
407
402
#[ error( "floating point numbers cannot be used in patterns" ) ]
408
403
MatchFloatInPattern ,
@@ -442,10 +437,7 @@ pub enum CompileErrorKind {
442
437
/// The number that was an unsupported tuple index.
443
438
number : ast:: Number ,
444
439
} ,
445
- /// Trying to treat a non-constant expression as constant.
446
- #[ error( "not a constant expression" ) ]
447
- NotConst ,
448
- /// Trying to process a cycle of constants.
449
- #[ error( "constant cycle detected" ) ]
450
- ConstCycle ,
440
+ /// Error raised when trying to use a break outside of a loop.
441
+ #[ error( "break outside of loop" ) ]
442
+ BreakOutsideOfLoop ,
451
443
}
0 commit comments