@@ -358,7 +358,7 @@ impl Segment {
358358 }
359359
360360 fn names_to_string ( segments : & [ Segment ] ) -> String {
361- names_to_string ( & segments. iter ( ) . map ( |seg| seg. ident . name ) . collect :: < Vec < _ > > ( ) )
361+ names_to_string ( segments. iter ( ) . map ( |seg| seg. ident . name ) )
362362 }
363363}
364364
@@ -2241,13 +2241,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22412241 }
22422242}
22432243
2244- fn names_to_string ( names : & [ Symbol ] ) -> String {
2244+ fn names_to_string ( names : impl Iterator < Item = Symbol > ) -> String {
22452245 let mut result = String :: new ( ) ;
2246- for ( i, name) in names. iter ( ) . filter ( |name| * * name != kw:: PathRoot ) . enumerate ( ) {
2246+ for ( i, name) in names. filter ( |name| * name != kw:: PathRoot ) . enumerate ( ) {
22472247 if i > 0 {
22482248 result. push_str ( "::" ) ;
22492249 }
2250- if Ident :: with_dummy_span ( * name) . is_raw_guess ( ) {
2250+ if Ident :: with_dummy_span ( name) . is_raw_guess ( ) {
22512251 result. push_str ( "r#" ) ;
22522252 }
22532253 result. push_str ( name. as_str ( ) ) ;
@@ -2256,31 +2256,32 @@ fn names_to_string(names: &[Symbol]) -> String {
22562256}
22572257
22582258fn path_names_to_string ( path : & Path ) -> String {
2259- names_to_string ( & path. segments . iter ( ) . map ( |seg| seg. ident . name ) . collect :: < Vec < _ > > ( ) )
2259+ names_to_string ( path. segments . iter ( ) . map ( |seg| seg. ident . name ) )
22602260}
22612261
22622262/// A somewhat inefficient routine to obtain the name of a module.
2263- fn module_to_string ( module : Module < ' _ > ) -> Option < String > {
2263+ fn module_to_string ( mut module : Module < ' _ > ) -> Option < String > {
22642264 let mut names = Vec :: new ( ) ;
2265-
2266- fn collect_mod ( names : & mut Vec < Symbol > , module : Module < ' _ > ) {
2265+ loop {
22672266 if let ModuleKind :: Def ( .., name) = module. kind {
22682267 if let Some ( parent) = module. parent {
22692268 names. push ( name) ;
2270- collect_mod ( names, parent) ;
2269+ module = parent
2270+ } else {
2271+ break ;
22712272 }
22722273 } else {
22732274 names. push ( sym:: opaque_module_name_placeholder) ;
2274- collect_mod ( names, module. parent . unwrap ( ) ) ;
2275+ let Some ( parent) = module. parent else {
2276+ return None ;
2277+ } ;
2278+ module = parent;
22752279 }
22762280 }
2277- collect_mod ( & mut names, module) ;
2278-
22792281 if names. is_empty ( ) {
22802282 return None ;
22812283 }
2282- names. reverse ( ) ;
2283- Some ( names_to_string ( & names) )
2284+ Some ( names_to_string ( names. iter ( ) . rev ( ) . copied ( ) ) )
22842285}
22852286
22862287#[ derive( Copy , Clone , Debug ) ]
0 commit comments