File tree 3 files changed +18
-11
lines changed
rustc_smir/src/rustc_smir
tests/ui-fulldeps/stable-mir
3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -31,11 +31,18 @@ impl<'tcx> Context for Tables<'tcx> {
31
31
self . tcx . crates ( ( ) ) . iter ( ) . map ( |crate_num| smir_crate ( self . tcx , * crate_num) ) . collect ( )
32
32
}
33
33
34
- fn find_crate ( & self , name : & str ) -> Option < stable_mir:: Crate > {
35
- [ LOCAL_CRATE ] . iter ( ) . chain ( self . tcx . crates ( ( ) ) . iter ( ) ) . find_map ( |crate_num| {
36
- let crate_name = self . tcx . crate_name ( * crate_num) . to_string ( ) ;
37
- ( name == crate_name) . then ( || smir_crate ( self . tcx , * crate_num) )
38
- } )
34
+ fn find_crates ( & self , name : & str ) -> Vec < stable_mir:: Crate > {
35
+ let crates: Vec < stable_mir:: Crate > = [ LOCAL_CRATE ]
36
+ . iter ( )
37
+ . chain ( self . tcx . crates ( ( ) ) . iter ( ) )
38
+ . map ( |crate_num| {
39
+ let crate_name = self . tcx . crate_name ( * crate_num) . to_string ( ) ;
40
+ ( name == crate_name) . then ( || smir_crate ( self . tcx , * crate_num) )
41
+ } )
42
+ . into_iter ( )
43
+ . filter_map ( |c| c)
44
+ . collect ( ) ;
45
+ crates
39
46
}
40
47
41
48
fn name_of_def_id ( & self , def_id : stable_mir:: DefId ) -> String {
Original file line number Diff line number Diff line change @@ -125,9 +125,9 @@ pub fn local_crate() -> Crate {
125
125
with ( |cx| cx. local_crate ( ) )
126
126
}
127
127
128
- /// Try to find a crate with the given name.
129
- pub fn find_crate ( name : & str ) -> Option < Crate > {
130
- with ( |cx| cx. find_crate ( name) )
128
+ /// Try to find a crate or crates if multiple crates exist from given name.
129
+ pub fn find_crates ( name : & str ) -> Vec < Crate > {
130
+ with ( |cx| cx. find_crates ( name) )
131
131
}
132
132
133
133
/// Try to find a crate with the given name.
@@ -174,7 +174,7 @@ pub trait Context {
174
174
fn external_crates ( & self ) -> Vec < Crate > ;
175
175
176
176
/// Find a crate with the given name.
177
- fn find_crate ( & self , name : & str ) -> Option < Crate > ;
177
+ fn find_crates ( & self , name : & str ) -> Vec < Crate > ;
178
178
179
179
/// Prints the name of given `DefId`
180
180
fn name_of_def_id ( & self , def_id : DefId ) -> String ;
Original file line number Diff line number Diff line change @@ -38,8 +38,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
38
38
let items = stable_mir:: all_local_items ( ) ;
39
39
assert ! ( get_item( & items, ( DefKind :: Fn , "foo::bar" ) ) . is_some( ) ) ;
40
40
41
- // Find the `std` crate.
42
- assert ! ( stable_mir:: find_crate ( "std" ) . is_some ( ) ) ;
41
+ // Find the `std` crate and assert that there is only one of it .
42
+ assert ! ( stable_mir:: find_crates ( "std" ) . len ( ) == 1 ) ;
43
43
44
44
let bar = get_item ( & items, ( DefKind :: Fn , "bar" ) ) . unwrap ( ) ;
45
45
let body = bar. body ( ) ;
You can’t perform that action at this time.
0 commit comments