@@ -87,7 +87,15 @@ impl Default for ClientOptions {
8787}
8888
8989lazy_static ! {
90- static ref CRATE_RE : Regex = Regex :: new( r"^([a-zA-Z0-9_]+?)::" ) . unwrap( ) ;
90+ static ref CRATE_RE : Regex = Regex :: new( r"^(?:_<)?([a-zA-Z0-9_]+?)(?:\.\.|::)" ) . unwrap( ) ;
91+ }
92+
93+ /// Tries to parse the rust crate from a function name.
94+ fn parse_crate_name ( func_name : & str ) -> Option < String > {
95+ CRATE_RE
96+ . captures ( func_name)
97+ . and_then ( |caps| caps. get ( 1 ) )
98+ . map ( |cr| cr. as_str ( ) . into ( ) )
9199}
92100
93101/// Helper trait to convert an object into a client config
@@ -356,10 +364,7 @@ impl Client {
356364
357365 // set package if missing to crate prefix
358366 if frame. package . is_none ( ) {
359- frame. package = CRATE_RE
360- . captures ( func_name)
361- . and_then ( |caps| caps. get ( 1 ) )
362- . map ( |cr| cr. as_str ( ) . into ( ) ) ;
367+ frame. package = parse_crate_name ( func_name) ;
363368 }
364369
365370 match frame. in_app {
@@ -499,3 +504,32 @@ pub fn init<C: IntoClientConfig>(cfg: C) -> ClientInitGuard {
499504 client
500505 } ) )
501506}
507+
508+ #[ cfg( test) ]
509+ mod tests {
510+ use super :: * ;
511+
512+ #[ test]
513+ fn test_parse_crate_name ( ) {
514+ assert_eq ! (
515+ parse_crate_name( "futures::task_impl::std::set" ) ,
516+ Some ( "futures" . into( ) )
517+ ) ;
518+ }
519+
520+ #[ test]
521+ fn test_parse_crate_name_impl ( ) {
522+ assert_eq ! (
523+ parse_crate_name( "_<futures..task_impl..Spawn<T>>::enter::_{{closure}}" ) ,
524+ Some ( "futures" . into( ) )
525+ ) ;
526+ }
527+
528+ #[ test]
529+ fn test_parse_crate_name_unknown ( ) {
530+ assert_eq ! (
531+ parse_crate_name( "_<F as alloc..boxed..FnBox<A>>::call_box" ) ,
532+ None
533+ ) ;
534+ }
535+ }
0 commit comments