@@ -8,10 +8,13 @@ use std::{
88
99use anyhow:: { ensure, Result } ;
1010use pretty:: PrettyPrintMirOptions ;
11- use rustc_data_structures:: { captures :: Captures , fx:: FxHashMap as HashMap } ;
11+ use rustc_data_structures:: fx:: FxHashMap as HashMap ;
1212use rustc_hir:: { def_id:: DefId , CoroutineDesugaring , CoroutineKind , HirId } ;
1313use rustc_middle:: {
14- mir:: { pretty:: write_mir_fn, * } ,
14+ mir:: {
15+ pretty, pretty:: write_mir_fn, BasicBlock , Body , Local , Location , Place , SourceInfo ,
16+ TerminatorKind , VarDebugInfoContents ,
17+ } ,
1518 ty:: { Region , Ty , TyCtxt } ,
1619} ;
1720use smallvec:: SmallVec ;
@@ -21,24 +24,14 @@ use crate::{PlaceExt, TyExt};
2124
2225/// Extension trait for [`Body`].
2326pub trait BodyExt < ' tcx > {
24- type AllReturnsIter < ' a > : Iterator < Item = Location >
25- where
26- Self : ' a ;
27-
2827 /// Returns an iterator over the locations of [`TerminatorKind::Return`] instructions in a body.
29- fn all_returns ( & self ) -> Self :: AllReturnsIter < ' _ > ;
30-
31- type AllLocationsIter < ' a > : Iterator < Item = Location >
32- where
33- Self : ' a ;
28+ fn all_returns ( & self ) -> impl Iterator < Item = Location > + ' _ ;
3429
3530 /// Returns an iterator over all the locations in a body.
36- fn all_locations ( & self ) -> Self :: AllLocationsIter < ' _ > ;
37-
38- type LocationsIter : Iterator < Item = Location > ;
31+ fn all_locations ( & self ) -> impl Iterator < Item = Location > + ' _ ;
3932
4033 /// Returns all the locations in a [`BasicBlock`].
41- fn locations_in_block ( & self , block : BasicBlock ) -> Self :: LocationsIter ;
34+ fn locations_in_block ( & self , block : BasicBlock ) -> impl Iterator < Item = Location > ;
4235
4336 /// Returns a mapping from source-level variable names to [`Local`]s.
4437 fn debug_info_name_map ( & self ) -> HashMap < String , Local > ;
@@ -64,32 +57,22 @@ pub trait BodyExt<'tcx> {
6457 /// locals across await calls.
6558 fn async_context ( & self , tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Option < Ty < ' tcx > > ;
6659
67- type PlacesIter < ' a > : Iterator < Item = Place < ' tcx > >
68- where
69- Self : ' a ;
70-
7160 /// Returns an iterator over all projections of all local variables in the body.
72- fn all_places ( & self , tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Self :: PlacesIter < ' _ > ;
73-
74- type ArgRegionsIter < ' a > : Iterator < Item = Region < ' tcx > >
75- where
76- Self : ' a ;
61+ fn all_places (
62+ & self ,
63+ tcx : TyCtxt < ' tcx > ,
64+ def_id : DefId ,
65+ ) -> impl Iterator < Item = Place < ' tcx > > + ' _ ;
7766
7867 /// Returns an iterator over all the regions that appear in argument types to the body.
79- fn regions_in_args ( & self ) -> Self :: ArgRegionsIter < ' _ > ;
80-
81- type ReturnRegionsIter : Iterator < Item = Region < ' tcx > > ;
68+ fn regions_in_args ( & self ) -> impl Iterator < Item = Region < ' tcx > > + ' _ ;
8269
8370 /// Returns an iterator over all the regions that appear in the body's return type.
84- fn regions_in_return ( & self ) -> Self :: ReturnRegionsIter ;
71+ fn regions_in_return ( & self ) -> impl Iterator < Item = Region < ' tcx > > + ' _ ;
8572}
8673
8774impl < ' tcx > BodyExt < ' tcx > for Body < ' tcx > {
88- type AllReturnsIter < ' a >
89- = impl Iterator < Item = Location > + Captures < ' tcx > + ' a
90- where
91- Self : ' a ;
92- fn all_returns ( & self ) -> Self :: AllReturnsIter < ' _ > {
75+ fn all_returns ( & self ) -> impl Iterator < Item = Location > + ' _ {
9376 self
9477 . basic_blocks
9578 . iter_enumerated ( )
@@ -102,24 +85,19 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
10285 } )
10386 }
10487
105- type AllLocationsIter < ' a >
106- = impl Iterator < Item = Location > + Captures < ' tcx > + ' a
107- where
108- Self : ' a ;
109- fn all_locations ( & self ) -> Self :: AllLocationsIter < ' _ > {
88+ fn all_locations ( & self ) -> impl Iterator < Item = Location > + ' _ {
11089 self
11190 . basic_blocks
11291 . iter_enumerated ( )
11392 . flat_map ( |( block, data) | {
114- ( 0 .. data. statements . len ( ) + 1 ) . map ( move |statement_index| Location {
93+ ( 0 ..= data. statements . len ( ) ) . map ( move |statement_index| Location {
11594 block,
11695 statement_index,
11796 } )
11897 } )
11998 }
12099
121- type LocationsIter = impl Iterator < Item = Location > ;
122- fn locations_in_block ( & self , block : BasicBlock ) -> Self :: LocationsIter {
100+ fn locations_in_block ( & self , block : BasicBlock ) -> impl Iterator < Item = Location > {
123101 let num_stmts = self . basic_blocks [ block] . statements . len ( ) ;
124102 ( 0 ..= num_stmts) . map ( move |statement_index| Location {
125103 block,
@@ -181,46 +159,38 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
181159 }
182160 }
183161
184- type ArgRegionsIter < ' a >
185- = impl Iterator < Item = Region < ' tcx > > + Captures < ' tcx > + ' a
186- where
187- Self : ' a ;
188-
189- type ReturnRegionsIter = impl Iterator < Item = Region < ' tcx > > ;
190-
191- type PlacesIter < ' a >
192- = impl Iterator < Item = Place < ' tcx > > + Captures < ' tcx > + ' a
193- where
194- Self : ' a ;
195-
196- fn regions_in_args ( & self ) -> Self :: ArgRegionsIter < ' _ > {
162+ fn regions_in_args ( & self ) -> impl Iterator < Item = Region < ' tcx > > + ' _ {
197163 self
198164 . args_iter ( )
199165 . flat_map ( |arg_local| self . local_decls [ arg_local] . ty . inner_regions ( ) )
200166 }
201167
202- fn regions_in_return ( & self ) -> Self :: ReturnRegionsIter {
168+ fn regions_in_return ( & self ) -> impl Iterator < Item = Region < ' tcx > > + ' _ {
203169 self
204170 . return_ty ( )
205171 . inner_regions ( )
206172 . collect :: < SmallVec < [ Region < ' tcx > ; 8 ] > > ( )
207173 . into_iter ( )
208174 }
209175
210- fn all_places ( & self , tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Self :: PlacesIter < ' _ > {
176+ fn all_places (
177+ & self ,
178+ tcx : TyCtxt < ' tcx > ,
179+ def_id : DefId ,
180+ ) -> impl Iterator < Item = Place < ' tcx > > + ' _ {
211181 self . local_decls . indices ( ) . flat_map ( move |local| {
212182 Place :: from_local ( local, tcx) . interior_paths ( tcx, self , def_id)
213183 } )
214184 }
215185}
216186
217- pub fn run_dot ( path : & Path , buf : Vec < u8 > ) -> Result < ( ) > {
187+ pub fn run_dot ( path : & Path , buf : & [ u8 ] ) -> Result < ( ) > {
218188 let mut p = Command :: new ( "dot" )
219189 . args ( [ "-Tpdf" , "-o" , & path. display ( ) . to_string ( ) ] )
220190 . stdin ( Stdio :: piped ( ) )
221191 . spawn ( ) ?;
222192
223- p. stdin . as_mut ( ) . unwrap ( ) . write_all ( & buf) ?;
193+ p. stdin . as_mut ( ) . unwrap ( ) . write_all ( buf) ?;
224194
225195 let status = p. wait ( ) ?;
226196 ensure ! ( status. success( ) , "dot for {} failed" , path. display( ) ) ;
0 commit comments