11use super :: {
22 data:: { ContractData , PreprocessorData } ,
3- SourceMapLocation ,
3+ span_to_range ,
44} ;
55use crate :: Updates ;
66use itertools:: Itertools ;
@@ -11,7 +11,7 @@ use solar_sema::{
1111} ;
1212use std:: {
1313 collections:: { BTreeMap , BTreeSet , HashSet } ,
14- ops:: ControlFlow ,
14+ ops:: { ControlFlow , Range } ,
1515 path:: { Path , PathBuf } ,
1616} ;
1717
@@ -104,7 +104,7 @@ pub(crate) struct BytecodeDependency {
104104 /// Dependency kind.
105105 kind : BytecodeDependencyKind ,
106106 /// Source map location of this dependency.
107- loc : SourceMapLocation ,
107+ loc : Range < usize > ,
108108 /// HIR id of referenced contract.
109109 referenced_contract : ContractId ,
110110}
@@ -176,9 +176,8 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
176176 if let ExprKind :: New ( ty_new) = & ty. kind {
177177 if let TypeKind :: Custom ( item_id) = ty_new. kind {
178178 if let Some ( contract_id) = item_id. as_contract ( ) {
179- let name_loc =
180- SourceMapLocation :: from_span ( self . source_map , ty_new. span ) ;
181- let name = & self . src [ name_loc. start ..name_loc. end ] ;
179+ let name_loc = span_to_range ( self . source_map , ty_new. span ) ;
180+ let name = & self . src [ name_loc] ;
182181
183182 // Calculate offset to remove named args, e.g. for an expression like
184183 // `new Counter {value: 333} ( address(this))`
@@ -199,7 +198,7 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
199198 named_arg ( self . src , named_args, "value" , self . source_map ) ,
200199 named_arg ( self . src , named_args, "salt" , self . source_map ) ,
201200 ) ,
202- loc : SourceMapLocation :: from_span ( self . source_map , ty. span ) ,
201+ loc : span_to_range ( self . source_map , ty. span ) ,
203202 referenced_contract : contract_id,
204203 } ) ;
205204 }
@@ -213,7 +212,7 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
213212 if let Some ( contract_id) = contract_id. as_contract ( ) {
214213 self . collect_dependency ( BytecodeDependency {
215214 kind : BytecodeDependencyKind :: CreationCode ,
216- loc : SourceMapLocation :: from_span ( self . source_map , expr. span ) ,
215+ loc : span_to_range ( self . source_map , expr. span ) ,
217216 referenced_contract : contract_id,
218217 } ) ;
219218 }
@@ -236,8 +235,8 @@ fn named_arg(
236235) -> Option < String > {
237236 named_args. unwrap_or_default ( ) . iter ( ) . find ( |named_arg| named_arg. name . as_str ( ) == arg) . map (
238237 |named_arg| {
239- let named_arg_loc = SourceMapLocation :: from_span ( source_map, named_arg. value . span ) ;
240- src[ named_arg_loc. start ..named_arg_loc . end ] . to_string ( )
238+ let named_arg_loc = span_to_range ( source_map, named_arg. value . span ) ;
239+ src[ named_arg_loc] . to_string ( )
241240 } ,
242241 )
243242}
0 commit comments