@@ -46,6 +46,7 @@ impl Error {
4646 ///
4747 pub fn new < S > (
4848 r#type : & str ,
49+ error_code : Option < isize > ,
4950 message : S ,
5051 source_location : Option < SourceLocation > ,
5152 sources : Option < & BTreeMap < String , StandardJsonInputSource > > ,
@@ -59,7 +60,7 @@ impl Error {
5960 let mut formatted_message = if message_trimmed. starts_with ( r#type) {
6061 message_trimmed. to_owned ( )
6162 } else {
62- format ! ( "{}: {}" , r#type , message_trimmed )
63+ format ! ( "{type }: {message_trimmed}" )
6364 } ;
6465 formatted_message. push ( '\n' ) ;
6566 if let Some ( ref source_location) = source_location {
@@ -76,7 +77,7 @@ impl Error {
7677
7778 Self {
7879 component : "general" . to_owned ( ) ,
79- error_code : None ,
80+ error_code : error_code . map ( |code| code . to_string ( ) ) ,
8081 formatted_message,
8182 message,
8283 severity : r#type. to_lowercase ( ) ,
@@ -89,28 +90,37 @@ impl Error {
8990 /// A shortcut constructor.
9091 ///
9192 pub fn new_error < S > (
93+ error_code : Option < isize > ,
9294 message : S ,
9395 source_location : Option < SourceLocation > ,
9496 sources : Option < & BTreeMap < String , StandardJsonInputSource > > ,
9597 ) -> Self
9698 where
9799 S : std:: fmt:: Display ,
98100 {
99- Self :: new ( "Error" , message, source_location, sources)
101+ Self :: new ( "Error" , error_code , message, source_location, sources)
100102 }
101103
102104 ///
103105 /// A shortcut constructor.
104106 ///
105107 pub fn new_warning < S > (
108+ error_code : Option < isize > ,
106109 message : S ,
107110 source_location : Option < SourceLocation > ,
108111 sources : Option < & BTreeMap < String , StandardJsonInputSource > > ,
109112 ) -> Self
110113 where
111114 S : std:: fmt:: Display ,
112115 {
113- Self :: new ( "Warning" , message, source_location, sources)
116+ Self :: new ( "Warning" , error_code, message, source_location, sources)
117+ }
118+ }
119+
120+ impl From < ( & str , & era_compiler_llvm_context:: EVMWarning ) > for Error {
121+ fn from ( ( path, warning) : ( & str , & era_compiler_llvm_context:: EVMWarning ) ) -> Self {
122+ let location = SourceLocation :: new ( path. to_owned ( ) ) ;
123+ Self :: new_warning ( warning. code ( ) , warning. to_string ( ) , Some ( location) , None )
114124 }
115125}
116126
0 commit comments